-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.js
More file actions
71 lines (59 loc) · 2.22 KB
/
demo.js
File metadata and controls
71 lines (59 loc) · 2.22 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
#!/usr/bin/env node
/**
* Demo script showing how to use Commit Coach programmatically
*/
import { GitAnalyzer } from '../src/core/git.js';
import { InsightGenerator } from '../src/insights/generator.js';
import { ConfigLoader } from '../src/config/loader.js';
import { ConsoleFormatter } from '../src/output/formatters.js';
async function runDemo() {
console.log('🚀 Commit Coach Demo\n');
try {
// Load configuration
const config = ConfigLoader.getDefaultConfig();
console.log('✅ Loaded default configuration');
// Initialize components
const gitAnalyzer = new GitAnalyzer('.');
const insightGenerator = new InsightGenerator(config);
const formatter = new ConsoleFormatter(config.output, true);
// Check if we're in a git repository
if (!(await gitAnalyzer.isRepository())) {
console.log(
'❌ Not a git repository. Please run from a git repository root.'
);
return;
}
// Get the latest commit
console.log('📊 Analyzing latest commit...');
const commitInfo = await gitAnalyzer.getCurrentCommit();
console.log(` Commit: ${commitInfo.hash.substring(0, 8)}`);
console.log(` Author: ${commitInfo.author}`);
console.log(` Message: ${commitInfo.message}`);
console.log(` Files: ${commitInfo.files.length}`);
// Generate insights
console.log('\n🔍 Generating insights...');
const result = insightGenerator.generateInsights(commitInfo);
// Display results
console.log('\n' + formatter.format(result));
// Show some statistics
console.log('\n📈 Analysis Statistics:');
console.log(` Total insights generated: ${result.insights.length}`);
console.log(
` Error insights: ${result.insights.filter(i => i.type === 'error').length}`
);
console.log(
` Warning insights: ${result.insights.filter(i => i.type === 'warning').length}`
);
console.log(
` Suggestion insights: ${result.insights.filter(i => i.type === 'suggestion').length}`
);
console.log(
` Info insights: ${result.insights.filter(i => i.type === 'info').length}`
);
} catch (error) {
console.error('❌ Demo failed:', error.message);
process.exit(1);
}
}
// Run the demo
runDemo();