-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.js
More file actions
131 lines (110 loc) · 4.16 KB
/
run.js
File metadata and controls
131 lines (110 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env node
import { CodeKnowledgeMapGenerator } from './dist/index.js';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
async function main() {
const args = process.argv.slice(2);
if (args.length === 0) {
console.log('用法:');
console.log(' node run.js generate <path> [options]');
console.log(' node run.js analyze <path> [options]');
console.log('');
console.log('选项:');
console.log(' --output <path> 输出目录 (默认: ./knowledge-map)');
console.log(' --format <format> 输出格式: markdown|json|html (默认: markdown)');
console.log(' --help 显示帮助');
return;
}
const command = args[0];
if (command === 'generate') {
if (args.length < 2) {
console.error('错误: 需要指定目标路径');
console.log('用法: node run.js generate <path> [options]');
process.exit(1);
}
const targetPath = args[1];
const outputPath = args.find(arg => arg.startsWith('--output'))?.split('=')[1] || './knowledge-map';
const format = args.find(arg => arg.startsWith('--format'))?.split('=')[1] || 'markdown';
const config = {
targetPath,
outputPath,
format: format,
includeTests: false,
excludePatterns: ['node_modules', '.git', 'dist', 'build'],
aiModel: 'gpt-4'
};
try {
console.log('🚀 开始生成代码库知识地图...');
console.log(`目标路径: ${targetPath}`);
console.log(`输出格式: ${format}`);
console.log(`输出目录: ${outputPath}`);
console.log('');
const generator = new CodeKnowledgeMapGenerator(config);
const result = await generator.generate();
console.log('✅ 生成完成!');
console.log(`📄 生成了 ${result.generatedFiles.length} 个文件`);
console.log(`⏱️ 处理时间: ${result.processingTime}ms`);
console.log('');
if (result.insights.length > 0) {
console.log('🔍 AI洞察:');
result.insights.forEach(insight => console.log(` • ${insight}`));
console.log('');
}
if (result.recommendations.length > 0) {
console.log('💡 改进建议:');
result.recommendations.forEach(rec => console.log(` • ${rec}`));
console.log('');
}
} catch (error) {
console.error('❌ 生成失败:', error.message);
process.exit(1);
}
} else if (command === 'analyze') {
if (args.length < 2) {
console.error('错误: 需要指定目标路径');
console.log('用法: node run.js analyze <path> [options]');
process.exit(1);
}
const targetPath = args[1];
const config = {
targetPath,
outputPath: './analysis-output',
format: 'json',
includeTests: false,
excludePatterns: ['node_modules', '.git', 'dist', 'build'],
aiModel: 'gpt-4'
};
try {
console.log('🔍 开始代码分析...');
console.log(`目标路径: ${targetPath}`);
console.log('');
const generator = new CodeKnowledgeMapGenerator(config);
const result = await generator.analyze();
console.log('✅ 分析完成!');
console.log(`📊 总文件数: ${result.metrics.totalFiles}`);
console.log(`📈 总代码行数: ${result.metrics.totalLines.toLocaleString()}`);
console.log(`🔧 函数总数: ${result.metrics.totalFunctions}`);
console.log(`🏗️ 类总数: ${result.metrics.totalClasses}`);
console.log(`📊 平均复杂度: ${result.metrics.averageComplexity.toFixed(2)}`);
console.log('');
if (result.insights.length > 0) {
console.log('🔍 AI洞察:');
result.insights.forEach(insight => console.log(` • ${insight}`));
console.log('');
}
} catch (error) {
console.error('❌ 分析失败:', error.message);
process.exit(1);
}
} else {
console.error(`未知命令: ${command}`);
console.log('可用命令: generate, analyze');
process.exit(1);
}
}
main().catch(error => {
console.error('❌ 运行失败:', error.message);
process.exit(1);
});