mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 22:34:56 +00:00
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { readdirSync, statSync } from 'fs'
|
|
import { join } from 'path'
|
|
import { analyzeFileContent } from './analyze-file'
|
|
import { ComponentAnalysis } from './types'
|
|
|
|
const IGNORED_DIRECTORIES = new Set(['node_modules', '.next', 'dist', 'build', '.git'])
|
|
|
|
export function analyzeImplementations(srcDir = 'src'): ComponentAnalysis[] {
|
|
const results: ComponentAnalysis[] = []
|
|
walkDir(srcDir, results)
|
|
return results
|
|
}
|
|
|
|
function walkDir(dir: string, results: ComponentAnalysis[]): void {
|
|
const files = safeReadDir(dir)
|
|
if (!files) return
|
|
|
|
for (const file of files) {
|
|
const fullPath = join(dir, file)
|
|
const stats = safeStat(fullPath)
|
|
|
|
if (!stats) continue
|
|
|
|
if (stats.isDirectory()) {
|
|
if (!IGNORED_DIRECTORIES.has(file)) {
|
|
walkDir(fullPath, results)
|
|
}
|
|
continue
|
|
}
|
|
|
|
const analyses = analyzeFileContent(fullPath)
|
|
if (analyses.length > 0) {
|
|
results.push(...analyses)
|
|
}
|
|
}
|
|
}
|
|
|
|
function safeReadDir(dir: string): string[] | null {
|
|
try {
|
|
return readdirSync(dir)
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
function safeStat(filePath: string): ReturnType<typeof statSync> | null {
|
|
try {
|
|
return statSync(filePath)
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|