Created
April 30, 2021 05:04
-
-
Save GeKiStolyarov/fe5f8c2afb926685ffdee7badfc994db to your computer and use it in GitHub Desktop.
Find files recursive using only node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { resolve, extname, basename } from 'path'; | |
import fsPromises from 'fs/promises'; | |
// @ts-ignore | |
async function* getFiles(dir: string) { | |
const dirents = await fsPromises.readdir(dir, { withFileTypes: true }); | |
for (const dirent of dirents) { | |
const res = resolve(dir, dirent.name); | |
if (dirent.isDirectory()) { | |
yield* getFiles(res); | |
} else { | |
yield res; | |
} | |
} | |
} | |
(async () => { | |
for await (const f of getFiles('./packages/')) { | |
const isNotNodeModules = !f.includes('node_modules'); | |
const isMDFiles = extname(f) === '.md' || extname(f) === '.MD'; | |
const isChangelogFile = basename(f).toUpperCase() === 'CHANGELOG.MD'; | |
if (isNotNodeModules && isMDFiles && isChangelogFile) { | |
console.log(f); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment