dev-wrapped 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,288 @@
1
+ import { WEEKDAYS } from './stats.js';
2
+
3
+ const out = process.stdout;
4
+ const COLOR = !process.env.NO_COLOR && (out.isTTY || process.env.FORCE_COLOR);
5
+
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+ const hex = (h) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16));
8
+ const fg = ([r, g, b]) => (COLOR ? `\x1b[38;2;${r};${g};${b}m` : '');
9
+ const RESET = COLOR ? '\x1b[0m' : '';
10
+ const BOLD = COLOR ? '\x1b[1m' : '';
11
+ const DIM = COLOR ? '\x1b[2m' : '';
12
+ const ITALIC = COLOR ? '\x1b[3m' : '';
13
+ const fmt = (n) => Math.round(n).toLocaleString('en-US');
14
+
15
+ function lerp(stops, t) {
16
+ t = Math.min(1, Math.max(0, t));
17
+ const seg = t * (stops.length - 1);
18
+ const i = Math.min(stops.length - 2, Math.floor(seg));
19
+ const k = seg - i;
20
+ return stops[i].map((v, j) => Math.round(v + (stops[i + 1][j] - v) * k));
21
+ }
22
+
23
+ function gradient(text, stops, offset = 0) {
24
+ if (!COLOR) return text;
25
+ const chars = [...text];
26
+ return (
27
+ chars.map((ch, i) => (ch === ' ' ? ch : fg(lerp(stops, (i / Math.max(1, chars.length - 1) + offset) % 1.0001)) + ch)).join('') + RESET
28
+ );
29
+ }
30
+
31
+ // ---------- big block font ----------
32
+ const FONT = {
33
+ G: [' ███ ', '█ ', '█ ██', '█ █', ' ███ '],
34
+ I: ['███', ' █ ', ' █ ', ' █ ', '███'],
35
+ T: ['█████', ' █ ', ' █ ', ' █ ', ' █ '],
36
+ W: ['█ █', '█ █', '█ █ █', '██ ██', '█ █'],
37
+ R: ['████ ', '█ █', '████ ', '█ █ ', '█ █'],
38
+ A: [' ███ ', '█ █', '█████', '█ █', '█ █'],
39
+ P: ['████ ', '█ █', '████ ', '█ ', '█ '],
40
+ E: ['█████', '█ ', '████ ', '█ ', '█████'],
41
+ D: ['████ ', '█ █', '█ █', '█ █', '████ '],
42
+ 0: [' ███ ', '█ █', '█ █', '█ █', ' ███ '],
43
+ 1: [' █ ', ' ██ ', ' █ ', ' █ ', ' ███ '],
44
+ 2: [' ███ ', '█ █', ' ██ ', ' █ ', '█████'],
45
+ 3: ['████ ', ' █', ' ███ ', ' █', '████ '],
46
+ 4: ['█ █', '█ █', '█████', ' █', ' █'],
47
+ 5: ['█████', '█ ', '████ ', ' █', '████ '],
48
+ 6: [' ███ ', '█ ', '████ ', '█ █', ' ███ '],
49
+ 7: ['█████', ' █', ' █ ', ' █ ', ' █ '],
50
+ 8: [' ███ ', '█ █', ' ███ ', '█ █', ' ███ '],
51
+ 9: [' ███ ', '█ █', ' ████', ' █', ' ███ '],
52
+ ',': [' ', ' ', ' ', ' █', '█ '],
53
+ ' ': [' ', ' ', ' ', ' ', ' '],
54
+ };
55
+ function big(text) {
56
+ const rows = ['', '', '', '', ''];
57
+ for (const ch of text.toUpperCase()) {
58
+ const g = FONT[ch] || FONT[' '];
59
+ for (let r = 0; r < 5; r++) rows[r] += g[r] + ' ';
60
+ }
61
+ return rows;
62
+ }
63
+
64
+ // ---------- helpers ----------
65
+ function makeWriter(anim) {
66
+ const pause = (ms) => (anim ? sleep(ms) : Promise.resolve());
67
+ const line = (s = '') => out.write(s + '\n');
68
+ async function type(s, speed = 12) {
69
+ if (!anim) return line(s);
70
+ // type visible characters, keep ANSI codes intact
71
+ const parts = s.split(/(\x1b\[[0-9;]*m)/);
72
+ for (const p of parts) {
73
+ if (p.startsWith('\x1b[')) out.write(p);
74
+ else
75
+ for (const ch of p) {
76
+ out.write(ch);
77
+ await sleep(speed);
78
+ }
79
+ }
80
+ out.write('\n');
81
+ }
82
+ return { pause, line, type };
83
+ }
84
+
85
+ function heading(title, pal) {
86
+ return `\n ${gradient('━━ ' + title.toUpperCase() + ' ', pal)}${fg(pal[1])}${'━'.repeat(Math.max(4, 54 - title.length))}${RESET}\n`;
87
+ }
88
+
89
+ function heatmap(calendar, year, pal) {
90
+ const firstDow = (new Date(Date.UTC(year, 0, 1)).getUTCDay() + 6) % 7; // Monday = 0
91
+ const max = Math.max(1, ...calendar);
92
+ const weeks = Math.ceil((calendar.length + firstDow) / 7);
93
+ const levels = [[40, 40, 48], ...[0.25, 0.5, 0.75, 1].map((t) => lerp(pal.slice(1), t))];
94
+ const rows = [];
95
+ const labels = ['Mon', ' ', 'Wed', ' ', 'Fri', ' ', 'Sun'];
96
+ for (let d = 0; d < 7; d++) {
97
+ let row = ` ${DIM}${labels[d]}${RESET} `;
98
+ for (let w = 0; w < weeks; w++) {
99
+ const idx = w * 7 + d - firstDow;
100
+ if (idx < 0 || idx >= calendar.length) {
101
+ row += ' ';
102
+ continue;
103
+ }
104
+ const v = calendar[idx];
105
+ const lvl = v === 0 ? 0 : Math.min(4, 1 + Math.floor((v / max) * 3.999));
106
+ row += COLOR ? fg(levels[lvl]) + '■' : v ? '■' : '·';
107
+ }
108
+ rows.push(row + RESET);
109
+ }
110
+ const names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
111
+ let months = ' '.repeat(weeks + 3);
112
+ for (let m = 0; m < 12; m++) {
113
+ const idx = (Date.UTC(year, m, 1) - Date.UTC(year, 0, 1)) / 86400000;
114
+ const col = Math.floor((idx + firstDow) / 7);
115
+ if (months.slice(col, col + 4).trim() === '') months = months.slice(0, col) + names[m] + months.slice(col + 3);
116
+ }
117
+ rows.unshift(` ${DIM}${months.trimEnd()}${RESET}`);
118
+ return rows;
119
+ }
120
+
121
+ function hourChart(hours, pal) {
122
+ const blocks = ' ▁▂▃▄▅▆▇█';
123
+ const max = Math.max(1, ...hours);
124
+ let bars = '';
125
+ hours.forEach((h, i) => {
126
+ const b = blocks[Math.round((h / max) * 8)];
127
+ bars += fg(lerp(pal.slice(1), i / 23)) + b + b;
128
+ });
129
+ return [` ${bars}${RESET}`, ` ${DIM}00 04 08 12 16 20 23${RESET}`];
130
+ }
131
+
132
+ function barRow(label, value, max, width, color, suffix = '') {
133
+ const len = Math.max(value > 0 ? 1 : 0, Math.round((value / Math.max(1, max)) * width));
134
+ return ` ${label.padEnd(12)} ${fg(color)}${'█'.repeat(len)}${RESET}${DIM}${'░'.repeat(width - len)}${RESET} ${suffix}`;
135
+ }
136
+
137
+ async function countUp(n, pal, anim) {
138
+ const steps = anim ? 28 : 1;
139
+ for (let s = 1; s <= steps; s++) {
140
+ const v = Math.round(n * (1 - Math.pow(1 - s / steps, 3)));
141
+ const rows = big(fmt(v));
142
+ if (s > 1) out.write(`\x1b[${rows.length}A`);
143
+ for (const r of rows) out.write((anim ? '\x1b[2K' : '') + ' ' + gradient(r, pal.slice(1).map(hex)) + '\n');
144
+ if (anim) await sleep(35);
145
+ }
146
+ }
147
+
148
+ const pad2 = (n) => String(n).padStart(2, '0');
149
+
150
+ // ---------- main render ----------
151
+ export async function render(stats, { anim = true } = {}) {
152
+ const A = stats.archetype;
153
+ const pal = A.palette;
154
+ const P = pal.map(hex);
155
+ const { pause, line, type } = makeWriter(anim && out.isTTY);
156
+ const accent = fg(P[2]);
157
+ const hot = fg(P[3]);
158
+ const MK = `${accent}◆${RESET}`;
159
+
160
+ line();
161
+ const title = big('GIT WRAPPED');
162
+ const titleStops = [hex('#f472b6'), hex('#a78bfa'), hex('#60a5fa'), hex('#34d399')];
163
+ for (const r of title) {
164
+ line(' ' + gradient(r, titleStops));
165
+ await pause(60);
166
+ }
167
+ line(` ${DIM}${'─'.repeat(title[0].length)}${RESET}`);
168
+ await type(` ${BOLD}${stats.year}${RESET} ${DIM}·${RESET} ${stats.name}${stats.github ? ` ${DIM}(@${stats.github.login})${RESET}` : ''} ${DIM}· ${stats.repos} repo${stats.repos > 1 ? 's' : ''}${RESET}`);
169
+ await pause(500);
170
+
171
+ // commits
172
+ line(heading('Your year in commits', P));
173
+ await countUp(stats.commits, pal, anim && out.isTTY);
174
+ line(` ${DIM}commits on${RESET} ${BOLD}${stats.activeDays}${RESET} ${DIM}different days ·${RESET} ~${BOLD}${fmt(stats.hoursCoding)}h${RESET} ${DIM}of coding${RESET}`);
175
+ await pause(400);
176
+ line();
177
+ await type(` ${fg(hex('#4ade80'))}+${fmt(stats.added)}${RESET} lines added ${fg(hex('#f87171'))}-${fmt(stats.removed)}${RESET} lines removed`);
178
+ const b = stats.book;
179
+ if (stats.added > 0) {
180
+ await type(
181
+ ` ${ITALIC}${DIM}That's ~${fmt(b.pages)} printed pages: ${RESET}${ITALIC}${hot}${b.times >= 1 ? b.times.toFixed(1) + '×' : Math.round(b.times * 100) + '% of'} ${b.title}${RESET}`
182
+ );
183
+ }
184
+ await pause(700);
185
+
186
+ // GitHub extras
187
+ const G = stats.github;
188
+ if (G) {
189
+ line(heading('Your year on GitHub', P));
190
+ await type(` ${BOLD}${hot}${fmt(G.contributions)}${RESET} ${DIM}contributions on your profile${RESET}`);
191
+ await type(` ${MK} ${BOLD}${fmt(G.prs)}${RESET} pull requests ${MK} ${BOLD}${fmt(G.reviews)}${RESET} reviews ${MK} ${BOLD}${fmt(G.issues)}${RESET} issues`);
192
+ if (G.privateContributions) await type(` ${MK} ${BOLD}${fmt(G.privateContributions)}${RESET} ${DIM}private contributions (top secret)${RESET}`);
193
+ if (G.topRepos.length) {
194
+ line();
195
+ const maxR = G.topRepos[0].count;
196
+ for (let i = 0; i < G.topRepos.length; i++) {
197
+ const r = G.topRepos[i];
198
+ const label = r.name.length > 26 ? '…' + r.name.slice(-25) : r.name;
199
+ line(barRow(label.padEnd(26), r.count, maxR, 18, lerp(P.slice(1), 1 - i / 5), `${DIM}${r.count} commits${r.stars ? ` · ${MK} ${fmt(r.stars)}` : ''}${RESET}`));
200
+ await pause(60);
201
+ }
202
+ }
203
+ await pause(700);
204
+ }
205
+
206
+ // calendar
207
+ line(heading('Your year at a glance', P));
208
+ for (const r of heatmap(stats.calendar, stats.year, P)) {
209
+ line(r);
210
+ await pause(45);
211
+ }
212
+ line();
213
+ if (stats.longestStreak.length)
214
+ await type(` ${MK} Longest streak ${BOLD}${hot}${stats.longestStreak.length} days${RESET} ${DIM}(${stats.longestStreak.from} → ${stats.longestStreak.to})${RESET}`);
215
+ if (stats.busiest) await type(` ${MK} Busiest day ${BOLD}${hot}${stats.busiest.count} commits${RESET} ${DIM}on ${stats.busiest.day}${RESET}`);
216
+ await pause(700);
217
+
218
+ // time
219
+ line(heading('When you code', P));
220
+ for (const r of hourChart(stats.hours, P)) line(r);
221
+ line();
222
+ const maxW = Math.max(...stats.weekdays);
223
+ for (let i = 0; i < 7; i++) {
224
+ line(barRow(WEEKDAYS[i], stats.weekdays[i], maxW, 30, lerp(P.slice(1), i / 6), `${DIM}${stats.weekdays[i]}${RESET}`));
225
+ await pause(40);
226
+ }
227
+ line();
228
+ await type(` ⏰ Peak hour ${BOLD}${accent}${pad2(stats.peakHour)}:00${RESET} ${MK} Favorite day ${BOLD}${accent}${stats.peakWeekday}${RESET}`);
229
+ if (stats.latest && (stats.latest.hour < 5 || stats.latest.hour >= 23)) {
230
+ await type(
231
+ ` ${MK} Latest commit ${BOLD}${hot}${pad2(stats.latest.hour)}:${pad2(stats.latest.minute)}${RESET} ${DIM}on ${stats.latest.day} —${RESET} ${ITALIC}"${stats.latest.subject.slice(0, 50)}"${RESET}`
232
+ );
233
+ }
234
+ await pause(700);
235
+
236
+ // languages
237
+ if (stats.languages.length) {
238
+ line(heading('Your languages', P));
239
+ const top = stats.languages[0].share;
240
+ for (let i = 0; i < stats.languages.length; i++) {
241
+ const l = stats.languages[i];
242
+ line(barRow(l.name, l.share, top, 30, lerp(P.slice(1), 1 - i / 6), `${BOLD}${Math.round(l.share * 100)}%${RESET}`));
243
+ await pause(70);
244
+ }
245
+ }
246
+
247
+ // words & confessions
248
+ line(heading('Your commit messages', P));
249
+ if (stats.words.length) {
250
+ await type(` ${DIM}Your favorite words:${RESET} ${stats.words.slice(0, 6).map((w, i) => `${fg(lerp(P.slice(1), 1 - i / 6))}${BOLD}${w.word}${RESET}${DIM}×${w.count}${RESET}`).join(' ')}`);
251
+ }
252
+ await type(` ${MK} You fixed things ${BOLD}${stats.fixes}${RESET} times${stats.wip ? ` · ${MK} ${BOLD}${stats.wip}${RESET} WIP commits` : ''}${stats.rage ? ` · ${MK} ${BOLD}${stats.rage}${RESET} rage commits` : ''}`);
253
+ if (stats.shortestMsg && stats.shortestMsg.subject.length <= 4)
254
+ await type(` ${MK} Most eloquent message: ${ITALIC}${hot}"${stats.shortestMsg.subject}"${RESET}`);
255
+ if (stats.topFiles[0]) await type(` ${MK} Most edited file: ${BOLD}${stats.topFiles[0].name}${RESET} ${DIM}(${stats.topFiles[0].count}×)${RESET}`);
256
+ if (stats.teammates[0]) await type(` ${MK} Partner in crime: ${BOLD}${stats.teammates[0].name}${RESET} ${DIM}(${stats.teammates[0].count} commits alongside you)${RESET}`);
257
+ await pause(900);
258
+
259
+ // archetype reveal
260
+ line(heading('Your developer personality', P));
261
+ if (anim && out.isTTY) {
262
+ const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
263
+ for (let i = 0; i < 24; i++) {
264
+ out.write(`\r ${accent}${frames[i % frames.length]}${RESET} ${DIM}analyzing ${fmt(stats.commits)} commits...${RESET} `);
265
+ await sleep(70);
266
+ }
267
+ out.write('\r\x1b[2K');
268
+ }
269
+ const nameRow = `◆ ${A.name.toUpperCase()}`;
270
+ const nameW = 3 + A.name.length;
271
+ const boxW = Math.max(nameW, A.tagline.length, A.description.length) + 6;
272
+ const border = (l, r) => ' ' + gradient(l + '─'.repeat(boxW) + r, P.slice(1));
273
+ const inner = (s, style = '', w = s.length) => ` ${fg(P[1])}│${RESET} ${style}${s}${RESET}${' '.repeat(Math.max(0, boxW - w - 3))}${fg(P[3])}│${RESET}`;
274
+ line(border('╭', '╮'));
275
+ line(inner('', '', 0));
276
+ line(inner(nameRow, BOLD + hot, nameW));
277
+ line(inner(A.tagline, ITALIC + accent));
278
+ line(inner('', '', 0));
279
+ line(inner(A.description, DIM));
280
+ line(inner('', '', 0));
281
+ line(border('╰', '╯'));
282
+ line();
283
+ }
284
+
285
+ export function rawLine(s = '') {
286
+ out.write(s + '\n');
287
+ }
288
+ export const style = { DIM, BOLD, RESET, ITALIC, fg, hex, gradient };