mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 22:34:56 +00:00
45 lines
923 B
TypeScript
45 lines
923 B
TypeScript
import { readdirSync, statSync } from 'fs'
|
|
import { extname, join } from 'path'
|
|
import { SKIP_DIRS, TARGET_EXTENSIONS } from '../constants'
|
|
|
|
export function walkDir(dir: string, files: string[]): void {
|
|
let entries: string[]
|
|
try {
|
|
entries = readdirSync(dir)
|
|
} catch {
|
|
return
|
|
}
|
|
|
|
for (const entry of entries) {
|
|
const fullPath = join(dir, entry)
|
|
let stats
|
|
try {
|
|
stats = statSync(fullPath)
|
|
} catch {
|
|
continue
|
|
}
|
|
|
|
if (stats.isDirectory()) {
|
|
if (SKIP_DIRS.has(entry)) {
|
|
continue
|
|
}
|
|
walkDir(fullPath, files)
|
|
continue
|
|
}
|
|
|
|
if (!stats.isFile()) {
|
|
continue
|
|
}
|
|
|
|
if (!TARGET_EXTENSIONS.has(extname(entry))) {
|
|
continue
|
|
}
|
|
|
|
if (entry.endsWith('.test.tsx') || entry.endsWith('.spec.tsx') || entry.endsWith('.stories.tsx')) {
|
|
continue
|
|
}
|
|
|
|
files.push(fullPath)
|
|
}
|
|
}
|