-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·237 lines (206 loc) · 6.04 KB
/
index.js
File metadata and controls
executable file
·237 lines (206 loc) · 6.04 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env node
import chalk from "chalk";
import { parseCliArgs, getRepositoryName } from "./src/utils.js";
import {
getBasicStats,
getLineStats,
getContributorStats,
getTimeBasedStats,
getCommitFrequencyStats,
getCommitSizeStats,
getLanguageStats,
getFileChurnStats,
getBranchStats,
} from "./src/stats.js";
import { getStreakStats } from "./src/streaks.js";
import {
displayBanner,
displayRepositoryOverview,
displayTimeline,
displayContributors,
displayCodeStats,
displayCommitFrequency,
displayTimeAnalysis,
displayStreakStats,
displayCommitSizeStats,
displayFileChurn,
displayBranchStats,
displayFunFacts,
displayFooter,
createSpinner,
} from "./src/display.js";
/**
* Main function to run Git Wrapped
*/
async function main() {
try {
// Parse command line arguments
const options = parseCliArgs();
const verbose = options.verbose;
// Show help if requested
if (process.argv.includes("--help") || process.argv.includes("-h")) {
displayHelp();
return;
}
// Display banner
const repoName = getRepositoryName(verbose);
displayBanner(repoName, options);
// Create spinner for loading
const spinner = createSpinner("Gathering repository statistics...");
if (!options.minimal) {
spinner.start();
}
// Collect all statistics
const allStats = {};
try {
// Basic stats
allStats.basicStats = getBasicStats(options, verbose);
// Line stats
allStats.lineStats = getLineStats(verbose);
// Contributor stats
allStats.contributors = getContributorStats(options, verbose);
// Time-based stats
allStats.timeStats = getTimeBasedStats(options, verbose);
// Commit frequency stats
allStats.frequencyStats = getCommitFrequencyStats(options, verbose);
// Commit size stats
allStats.sizeStats = getCommitSizeStats(options, verbose);
// Language stats
allStats.languageStats = getLanguageStats(verbose);
// File churn stats
allStats.fileChurn = getFileChurnStats(options, verbose);
// Branch stats
allStats.branchStats = getBranchStats(options, verbose);
// Streak stats
allStats.streakStats = getStreakStats(options, verbose);
if (!options.minimal) {
spinner.succeed("Statistics gathered successfully!");
}
} catch (error) {
if (!options.minimal) {
spinner.fail("Failed to gather some statistics");
}
if (verbose) {
console.error(chalk.red("Error:", error.message));
}
}
// Display results in CLI
displayResults(allStats, options);
} catch (error) {
console.error(chalk.red("\n❌ Error running Git Wrapped:"));
console.error(chalk.red(error.message));
if (options && options.verbose) {
console.error(error.stack);
}
process.exit(1);
}
}
/**
* Display all results in CLI format
* @param {Object} allStats - All collected statistics
* @param {Object} options - Display options
*/
function displayResults(allStats, options) {
// Repository Overview
if (allStats.basicStats) {
displayRepositoryOverview(allStats.basicStats, options);
}
// Timeline
if (
allStats.basicStats &&
allStats.basicStats.firstCommitDate &&
allStats.basicStats.lastCommitDate
) {
displayTimeline(
allStats.basicStats.firstCommitDate,
allStats.basicStats.lastCommitDate,
options
);
}
// Contributors
if (allStats.contributors && allStats.contributors.length > 0) {
displayContributors(allStats.contributors, options);
}
// Code Statistics
if (allStats.lineStats) {
displayCodeStats(allStats.lineStats, allStats.languageStats, options);
}
// Commit Frequency
if (allStats.frequencyStats) {
displayCommitFrequency(allStats.frequencyStats, options);
}
// Time-based Analysis
if (allStats.timeStats) {
displayTimeAnalysis(allStats.timeStats, options);
}
// Streak Statistics
if (allStats.streakStats) {
displayStreakStats(allStats.streakStats, options);
}
// Commit Size Statistics
if (allStats.sizeStats && !options.minimal) {
displayCommitSizeStats(allStats.sizeStats, options);
}
// File Churn
if (allStats.fileChurn && allStats.fileChurn.length > 0 && !options.minimal) {
displayFileChurn(allStats.fileChurn, options);
}
// Branch Statistics
if (allStats.branchStats && allStats.branchStats.totalBranches > 0) {
displayBranchStats(allStats.branchStats, options);
}
// Fun Facts
if (!options.minimal) {
displayFunFacts(allStats, options);
}
// Footer
displayFooter();
}
/**
* Display help information
*/
function displayHelp() {
console.log(
chalk.cyan.bold("\nGit Wrapped - Your Repository's Year in Review\n")
);
console.log(chalk.white("Usage: gitwrapped [options]\n"));
console.log(chalk.white("Options:"));
console.log(
chalk.white(
" --year <YYYY> Filter statistics by specific year (e.g., --year 2025)"
)
);
console.log(
chalk.white(" --all-time Show all-time statistics (default)")
);
console.log(
chalk.white(
" --current-branch-only Analyze only the current branch (default: all)"
)
);
console.log(
chalk.white(" --no-emoji Disable emojis in output")
);
console.log(chalk.white(" --minimal Show condensed output"));
console.log(chalk.white(" --verbose Show debug information"));
console.log(chalk.white(" --help, -h Show this help message"));
console.log(chalk.white("\nExamples:"));
console.log(
chalk.gray(" gitwrapped # All branches (default)")
);
console.log(
chalk.gray(
" gitwrapped --year 2025 # 2025 stats, all branches"
)
);
console.log(
chalk.gray(" gitwrapped --current-branch-only # Only current branch")
);
console.log(
chalk.gray(" gitwrapped --minimal # Condensed output")
);
console.log(chalk.gray(" gitwrapped --year 2024 --no-emoji"));
console.log();
}
// Run the main function
main();