1
0
mirror of synced 2025-12-20 02:19:14 -05:00
Files
docs/script/helpers/walk-files.js
2022-06-06 18:08:03 -04:00

21 lines
660 B
JavaScript

#!/usr/bin/env node
// [start-readme]
//
// A helper that returns an array of files for a given path and file extension.
//
// [end-readme]
import path from 'path'
import walk from 'walk-sync'
export default function walkFiles(dir, ext, opts = {}) {
const extensions = Array.isArray(ext) ? ext : [ext]
const dirPath = path.posix.join(process.cwd(), dir)
const walkSyncOpts = { includeBasePath: true, directories: false }
return walk(dirPath, walkSyncOpts)
.filter((file) => extensions.some((ext) => file.endsWith(ext)) && !file.endsWith('README.md'))
.filter((file) => (opts.includeEarlyAccess ? file : !file.includes('/early-access/')))
}