code: async function getFiles(dir) {
    const subdirs = await readdir(dir);
    const files = await Promise.all(
      subdirs.map(async subdir => {
        const res = resolve(dir, subdir);
        return (await stat(res)).isDirectory() ? getFiles(res) : res;
      }),
    );
    return files.reduce((a, f) => a.concat(f), []);
  }
docs: <https://stackoverflow.com/a/45130990/870615>