sourceFiles
uses node:fs
import { FILES_MARK, SKIP_DIRS, TEST_DIRS } from "#codebase/tcmts/cli/mirror"; import fs from "node:fs"; import path from "node:path"; export function sourceFiles(dir: string, exclude: Set<string>, tests: boolean): string[] { return fs.readdirSync(dir, { withFileTypes: true }).flatMap((e) => { const p = path.join(dir, e.name); if (exclude.has(path.resolve(p))) return []; // (a directory marked as holding files is files of the codebase, not code) // (nor another codebase, inside this one's directory) if (e.isDirectory()) return e.name.startsWith(".") || (SKIP_DIRS.has(e.name) && !(tests && TEST_DIRS.has(e.name))) || fs.existsSync(path.join(p, FILES_MARK)) || fs.existsSync(path.join(p, ".tcm")) ? [] : sourceFiles(p, exclude, tests); return /\.(m|c)?tsx?$/.test(e.name) && !/\.d\.(m|c)?ts$|\.(test|spec)(-d)?\.(m|c)?tsx?$/.test(e.name) ? [p] : []; }); }