diff --git a/scripts/arch-scan/scanners/ts-scanner.ts b/scripts/arch-scan/scanners/ts-scanner.ts index db01dc7..c03679f 100644 --- a/scripts/arch-scan/scanners/ts-scanner.ts +++ b/scripts/arch-scan/scanners/ts-scanner.ts @@ -70,6 +70,11 @@ export function scanTypeScript(db: DBType, root: string): ScanStats { const hasSrc = fs.existsSync(path.join(servicePath, "src")); const hasPkg = fs.existsSync(path.join(servicePath, "package.json")); if (!hasSrc && !hasPkg) continue; + // 跳过纯 Python 服务(有 pyproject.toml 且无 package.json) + const hasPyproject = fs.existsSync( + path.join(servicePath, "pyproject.toml"), + ); + if (hasPyproject && !hasPkg) continue; const moduleName = serviceName; insertModule.run(moduleName, servicePath, "ts", serviceName, "service"); @@ -97,6 +102,11 @@ export function scanTypeScript(db: DBType, root: string): ScanStats { const hasPkg = fs.existsSync(path.join(pkgPath, "package.json")); const hasProto = fs.existsSync(path.join(pkgPath, "proto")); if (!hasSrc && !hasPkg && !hasProto) continue; + // 跳过纯 Python 包(有 pyproject.toml 且无 package.json) + const hasPyprojectPkg = fs.existsSync( + path.join(pkgPath, "pyproject.toml"), + ); + if (hasPyprojectPkg && !hasPkg) continue; const moduleName = pkgName; insertModule.run(moduleName, pkgPath, "ts", pkgName, "package"); const row = getModuleId.get(moduleName); @@ -111,7 +121,12 @@ export function scanTypeScript(db: DBType, root: string): ScanStats { const TS_FUNC_RE = /(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(/g; const TS_CLASS_RE = /(?:export\s+)?(?:abstract\s+)?class\s+(\w+)/g; const TS_INTERFACE_RE = /(?:export\s+)?interface\s+(\w+)/g; - const TS_CONST_RE = /(?:export\s+)?const\s+([A-Z][A-Z0-9_]+)\s*=/g; + // 全大写常量(如 MAX_RETRY_COUNT) + const TS_CONST_UPPER_RE = /(?:export\s+)?const\s+([A-Z][A-Z0-9_]+)\s*=/g; + // 导出的 camelCase / PascalCase 常量(如 colors、fontSizes) + const TS_CONST_EXPORT_RE = /export\s+const\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=/g; + // 导出的 type alias(如 ColorScheme) + const TS_TYPE_RE = /export\s+type\s+(\w+)\s*=/g; for (const mod of moduleList) { const srcDir = path.join(mod.path, "src"); @@ -187,7 +202,7 @@ export function scanTypeScript(db: DBType, root: string): ScanStats { } // 常量(UPPER_CASE) - const constRe = new RegExp(TS_CONST_RE); + const constRe = new RegExp(TS_CONST_UPPER_RE); while ((match = constRe.exec(content)) !== null) { const name = match[1]; const lineNum = content.slice(0, match.index).split("\n").length; @@ -204,6 +219,44 @@ export function scanTypeScript(db: DBType, root: string): ScanStats { ); symbols++; } + + // 导出的 camelCase / PascalCase 常量(去重:已被 UPPER_CASE 匹配的跳过) + const constExportRe = new RegExp(TS_CONST_EXPORT_RE); + while ((match = constExportRe.exec(content)) !== null) { + const name = match[1]; + // 跳过已被 UPPER_CASE 匹配的 + if (/^[A-Z][A-Z0-9_]+$/.test(name)) continue; + const lineNum = content.slice(0, match.index).split("\n").length; + insertSymbol.run( + modRow.id, + name, + "const", + "ts", + filePath, + lineNum, + lineNum, + 1, + ); + symbols++; + } + + // 导出的 type alias + const typeRe = new RegExp(TS_TYPE_RE); + while ((match = typeRe.exec(content)) !== null) { + const name = match[1]; + const lineNum = content.slice(0, match.index).split("\n").length; + insertSymbol.run( + modRow.id, + name, + "type", + "ts", + filePath, + lineNum, + lineNum, + 1, + ); + symbols++; + } } }