import { Project, SyntaxKind } from 'ts-morph'; import path from 'node:path'; import type { Database as DBType } from 'better-sqlite3'; interface ScanStats { modules: number; symbols: number; } export function scanTypeScript(db: DBType, root: string): ScanStats { const project = new Project({ tsConfigFilePath: undefined, skipAddingFilesFromTsConfig: true, compilerOptions: { allowJs: true, declaration: false, resolveJsonModule: true, }, }); const patterns = ['services/*/src/**/*.ts', 'apps/*/src/**/*.ts', 'packages/*/src/**/*.ts']; let modules = 0; let symbols = 0; const insertModule = db.prepare( 'INSERT OR IGNORE INTO modules (name, path, language, service, type) VALUES (?, ?, ?, ?, ?)' ); const insertSymbol = db.prepare( 'INSERT INTO symbols (module_id, name, kind, language, file_path, line_start, line_end, is_exported) VALUES (?, ?, ?, ?, ?, ?, ?, ?)' ); // 简化实现:扫描 services/*/src 目录作为模块 const servicesDir = path.join(root, 'services'); // 实际实现用 fast-glob 模式匹配 // 此处为骨架,P1 后期补全 return { modules, symbols }; }