@kaynooo/cli-git 0.13.1 → 0.15.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.
- package/README.md +12 -1
- package/dist/gb.js +372 -51
- package/dist/gc.js +359 -38
- package/dist/gp.js +1596 -0
- package/dist/gst.js +466 -60
- package/package.json +8 -6
package/dist/gst.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gst.ts
|
|
5
|
-
import
|
|
5
|
+
import process19 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -10,6 +10,24 @@ import { parseArgs } from "util";
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
11
|
import process7 from "process";
|
|
12
12
|
|
|
13
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
14
|
+
var N = new Map;
|
|
15
|
+
var Nt = /\s+\S*$/;
|
|
16
|
+
var Y = /\s/;
|
|
17
|
+
function ko(t, e, r = "...") {
|
|
18
|
+
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
19
|
+
if (t.length <= e)
|
|
20
|
+
return t;
|
|
21
|
+
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
22
|
+
if (o && !Y.test(t[c.length] ?? " "))
|
|
23
|
+
c = c.replace(Nt, "") || c;
|
|
24
|
+
if (o)
|
|
25
|
+
c = c.trimEnd();
|
|
26
|
+
return s ? (c + n).slice(0, l) : c + n;
|
|
27
|
+
}
|
|
28
|
+
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
29
|
+
var z = new Map;
|
|
30
|
+
|
|
13
31
|
// ../kit/src/mode.ts
|
|
14
32
|
import process2 from "process";
|
|
15
33
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -35,10 +53,10 @@ function isInteractive(streams = process2) {
|
|
|
35
53
|
import process6 from "process";
|
|
36
54
|
|
|
37
55
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
38
|
-
var
|
|
56
|
+
var G2 = /^[a-f0-9]+$/i;
|
|
39
57
|
function b(r) {
|
|
40
58
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
41
|
-
if (!
|
|
59
|
+
if (!G2.test(e))
|
|
42
60
|
return [0, 0, 0];
|
|
43
61
|
if (e.length === 3 || e.length === 4)
|
|
44
62
|
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
@@ -46,7 +64,7 @@ function b(r) {
|
|
|
46
64
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
47
65
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
48
66
|
}
|
|
49
|
-
var
|
|
67
|
+
var B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
50
68
|
let [l, n, c] = b(r);
|
|
51
69
|
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
52
70
|
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
@@ -64,7 +82,7 @@ function f(r, e = []) {
|
|
|
64
82
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
65
83
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
66
84
|
return new Proxy(c, { get(t, i) {
|
|
67
|
-
let a =
|
|
85
|
+
let a = B2[i];
|
|
68
86
|
if (Array.isArray(a)) {
|
|
69
87
|
let s = g.get(i);
|
|
70
88
|
if (s === undefined)
|
|
@@ -123,7 +141,39 @@ function userConfigPath(bin, where = {}) {
|
|
|
123
141
|
}
|
|
124
142
|
|
|
125
143
|
// ../kit/src/theme.ts
|
|
144
|
+
function toLinear(channel) {
|
|
145
|
+
const value = channel / 255;
|
|
146
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
147
|
+
}
|
|
148
|
+
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055)));
|
|
149
|
+
function toOklab(hex) {
|
|
150
|
+
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
151
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
152
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
153
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
154
|
+
return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
|
|
155
|
+
}
|
|
156
|
+
function fromOklab([lightness, a, b]) {
|
|
157
|
+
const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
158
|
+
const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
159
|
+
const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
160
|
+
const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
|
|
161
|
+
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
162
|
+
}
|
|
126
163
|
var ENDS = new Map;
|
|
164
|
+
function gradientAt(theme, ratio) {
|
|
165
|
+
if (theme.gradient === undefined)
|
|
166
|
+
return;
|
|
167
|
+
const key = theme.gradient.join();
|
|
168
|
+
let ends = ENDS.get(key);
|
|
169
|
+
if (ends === undefined) {
|
|
170
|
+
ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
|
|
171
|
+
ENDS.set(key, ends);
|
|
172
|
+
}
|
|
173
|
+
const at = Math.min(1, Math.max(0, ratio));
|
|
174
|
+
const [from, to] = ends;
|
|
175
|
+
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
176
|
+
}
|
|
127
177
|
var DEFAULT = {
|
|
128
178
|
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
129
179
|
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
@@ -175,6 +225,9 @@ function tinted(colors, spec, env = process5.env) {
|
|
|
175
225
|
return chain[token] ?? chain;
|
|
176
226
|
}, colors);
|
|
177
227
|
}
|
|
228
|
+
function shaded(theme, colors, glyph, cells, width, env = process5.env) {
|
|
229
|
+
return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
|
|
230
|
+
}
|
|
178
231
|
function isRecord(value) {
|
|
179
232
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
180
233
|
}
|
|
@@ -304,12 +357,22 @@ function activeTheme() {
|
|
|
304
357
|
}
|
|
305
358
|
|
|
306
359
|
// ../kit/src/style.ts
|
|
360
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
307
361
|
function takesControlCodes(stream, env = process6.env) {
|
|
308
362
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
309
363
|
}
|
|
310
364
|
function paint(stream, env = process6.env) {
|
|
311
365
|
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
312
366
|
}
|
|
367
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
368
|
+
const colors = paint(stream, env);
|
|
369
|
+
let head = MARK_WORDS[mark];
|
|
370
|
+
if (takesControlCodes(stream, env)) {
|
|
371
|
+
const { theme } = activeTheme();
|
|
372
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
373
|
+
}
|
|
374
|
+
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
375
|
+
}
|
|
313
376
|
function role(name, stream, env = process6.env) {
|
|
314
377
|
const colors = paint(stream, env);
|
|
315
378
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
@@ -338,6 +401,12 @@ function formatSeconds(total) {
|
|
|
338
401
|
const next = amounts[first + 1];
|
|
339
402
|
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
340
403
|
}
|
|
404
|
+
function formatDuration(ms) {
|
|
405
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
406
|
+
}
|
|
407
|
+
function formatElapsed(ms) {
|
|
408
|
+
return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
|
|
409
|
+
}
|
|
341
410
|
function upTo(text, separator) {
|
|
342
411
|
const end = text.indexOf(separator);
|
|
343
412
|
return end === -1 ? text : text.slice(0, end);
|
|
@@ -349,7 +418,53 @@ function formatAge(date, now = Date.now()) {
|
|
|
349
418
|
const seconds = (now - at) / 1000;
|
|
350
419
|
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
351
420
|
}
|
|
421
|
+
function truncate(text, width) {
|
|
422
|
+
return ko(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
423
|
+
}
|
|
424
|
+
var LINE_BREAKS = /\s*\n\s*/g;
|
|
352
425
|
var ESCAPE = String.fromCharCode(27);
|
|
426
|
+
function textWidth(text) {
|
|
427
|
+
return Bun.stringWidth(text);
|
|
428
|
+
}
|
|
429
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
430
|
+
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
431
|
+
if (outputMode(stream, env) === "agent")
|
|
432
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
433
|
+
`);
|
|
434
|
+
const widths = [];
|
|
435
|
+
for (const row of cells) {
|
|
436
|
+
for (const [index, cell] of row.entries())
|
|
437
|
+
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
438
|
+
}
|
|
439
|
+
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
440
|
+
const colors = paint(stream);
|
|
441
|
+
const lines = shown.map((row) => row.map((cell, index) => {
|
|
442
|
+
const width = widths[index] ?? 0;
|
|
443
|
+
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
444
|
+
if (align[index] === "right")
|
|
445
|
+
return `${gap}${cell}`;
|
|
446
|
+
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
447
|
+
}).join(" ").trimEnd());
|
|
448
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
449
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
450
|
+
`);
|
|
451
|
+
}
|
|
452
|
+
function narrow(rows, widths, limit) {
|
|
453
|
+
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
454
|
+
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
455
|
+
const floor = 8;
|
|
456
|
+
while (used() > limit) {
|
|
457
|
+
let widest = -1;
|
|
458
|
+
for (const [index, width] of widths.entries()) {
|
|
459
|
+
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
460
|
+
widest = index;
|
|
461
|
+
}
|
|
462
|
+
if (widest === -1)
|
|
463
|
+
break;
|
|
464
|
+
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
465
|
+
}
|
|
466
|
+
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
467
|
+
}
|
|
353
468
|
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
354
469
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
355
470
|
}
|
|
@@ -672,9 +787,36 @@ function nearestOption(message, options, allowNegative) {
|
|
|
672
787
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
673
788
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
674
789
|
}
|
|
790
|
+
// ../kit/src/argv.ts
|
|
791
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
792
|
+
import { resolve as resolve3 } from "path";
|
|
793
|
+
import process10 from "process";
|
|
794
|
+
function commandLine() {
|
|
795
|
+
try {
|
|
796
|
+
return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
797
|
+
} catch {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function realPath(word) {
|
|
802
|
+
try {
|
|
803
|
+
return realpathSync(resolve3(word));
|
|
804
|
+
} catch {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
809
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
810
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
811
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
812
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
813
|
+
}
|
|
814
|
+
// ../kit/src/progress.ts
|
|
815
|
+
import process12 from "process";
|
|
816
|
+
|
|
675
817
|
// ../kit/src/process.ts
|
|
676
818
|
import { constants } from "os";
|
|
677
|
-
import
|
|
819
|
+
import process11 from "process";
|
|
678
820
|
var KILL_GRACE_MS = 2000;
|
|
679
821
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
680
822
|
function exitCodeOf(code, signal) {
|
|
@@ -696,7 +838,7 @@ function holdSignals(cleanup) {
|
|
|
696
838
|
},
|
|
697
839
|
release: () => {
|
|
698
840
|
for (const signal of SIGNALS)
|
|
699
|
-
|
|
841
|
+
process11.off(signal, onSignal);
|
|
700
842
|
}
|
|
701
843
|
};
|
|
702
844
|
function onSignal(signal) {
|
|
@@ -709,10 +851,10 @@ function holdSignals(cleanup) {
|
|
|
709
851
|
return;
|
|
710
852
|
held.release();
|
|
711
853
|
cleanup(signal);
|
|
712
|
-
|
|
854
|
+
process11.kill(process11.pid, signal);
|
|
713
855
|
}
|
|
714
856
|
for (const signal of SIGNALS)
|
|
715
|
-
|
|
857
|
+
process11.on(signal, onSignal);
|
|
716
858
|
return held;
|
|
717
859
|
}
|
|
718
860
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -726,7 +868,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
726
868
|
return;
|
|
727
869
|
try {
|
|
728
870
|
if (grouped)
|
|
729
|
-
|
|
871
|
+
process11.kill(-proc.pid, killing);
|
|
730
872
|
else
|
|
731
873
|
proc.kill(killing);
|
|
732
874
|
} catch {}
|
|
@@ -795,20 +937,199 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
795
937
|
}
|
|
796
938
|
|
|
797
939
|
// ../kit/src/progress.ts
|
|
940
|
+
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
941
|
+
var FRAME_MS = 200;
|
|
942
|
+
var BAR_WIDTH = 20;
|
|
943
|
+
var CLEAR_BELOW = "\r\x1B[J";
|
|
798
944
|
var ESC = String.fromCharCode(27);
|
|
799
945
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
800
946
|
var RESET_STYLE = `${ESC}[0m`;
|
|
947
|
+
var CTRL_C = 3;
|
|
801
948
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
949
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
950
|
+
function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
951
|
+
if (!takesControlCodes(stream, env))
|
|
952
|
+
return { redraw: () => {
|
|
953
|
+
return;
|
|
954
|
+
}, print: (text) => void stream.write(`${text}
|
|
955
|
+
`), stop: () => {
|
|
956
|
+
return;
|
|
957
|
+
} };
|
|
958
|
+
const write = stream.write.bind(stream);
|
|
959
|
+
let frame = 0;
|
|
960
|
+
let drawn = false;
|
|
961
|
+
const columns = () => {
|
|
962
|
+
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
963
|
+
return now === undefined || now === 0 ? 80 : now;
|
|
964
|
+
};
|
|
965
|
+
const clear = () => {
|
|
966
|
+
if (drawn)
|
|
967
|
+
write(CLEAR_BELOW);
|
|
968
|
+
drawn = false;
|
|
969
|
+
};
|
|
970
|
+
const draw = () => {
|
|
971
|
+
const width = columns() - 1;
|
|
972
|
+
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
973
|
+
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
974
|
+
if (lines.length === 0) {
|
|
975
|
+
clear();
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
write(`${CLEAR_BELOW}${lines.join(`
|
|
979
|
+
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
980
|
+
drawn = true;
|
|
981
|
+
};
|
|
982
|
+
const timer = setInterval(draw, FRAME_MS);
|
|
983
|
+
stream.on?.("resize", draw);
|
|
984
|
+
const restore = interceptOutput(clear);
|
|
985
|
+
const release = swallowInput();
|
|
986
|
+
const onExit = () => {
|
|
987
|
+
clear();
|
|
988
|
+
release();
|
|
989
|
+
};
|
|
990
|
+
const signals = holdSignals(stop);
|
|
991
|
+
function stop() {
|
|
992
|
+
clearInterval(timer);
|
|
993
|
+
stream.off?.("resize", draw);
|
|
994
|
+
clear();
|
|
995
|
+
restore();
|
|
996
|
+
release();
|
|
997
|
+
process12.off("exit", onExit);
|
|
998
|
+
signals.release();
|
|
999
|
+
}
|
|
1000
|
+
timer.unref();
|
|
1001
|
+
process12.on("exit", onExit);
|
|
1002
|
+
return {
|
|
1003
|
+
redraw: draw,
|
|
1004
|
+
print: (text) => {
|
|
1005
|
+
clear();
|
|
1006
|
+
write(`${text}
|
|
1007
|
+
`);
|
|
1008
|
+
draw();
|
|
1009
|
+
},
|
|
1010
|
+
stop
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
1014
|
+
const colors = paint(stream, env);
|
|
1015
|
+
const write = stream.write.bind(stream);
|
|
1016
|
+
const begun = performance.now();
|
|
1017
|
+
let started = begun;
|
|
1018
|
+
let current;
|
|
1019
|
+
const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
|
|
1020
|
+
const end = (line) => {
|
|
1021
|
+
region.stop();
|
|
1022
|
+
write(`${line}
|
|
1023
|
+
`);
|
|
1024
|
+
};
|
|
1025
|
+
return {
|
|
1026
|
+
update: (progress) => {
|
|
1027
|
+
const step = current?.step;
|
|
1028
|
+
current = progress;
|
|
1029
|
+
if (progress.step !== step) {
|
|
1030
|
+
started = performance.now();
|
|
1031
|
+
region.redraw();
|
|
1032
|
+
}
|
|
1033
|
+
},
|
|
1034
|
+
stop: region.stop,
|
|
1035
|
+
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1036
|
+
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
function progressParts({ step, done, total, unit }, spinner, ms) {
|
|
1040
|
+
const { theme } = activeTheme();
|
|
1041
|
+
const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
|
|
1042
|
+
if (total !== undefined && total > 0) {
|
|
1043
|
+
const counted = Math.min(done ?? 0, total);
|
|
1044
|
+
const filled = Math.round(counted / total * BAR_WIDTH);
|
|
1045
|
+
parts.push({ text: " ", tint: () => plain }, { text: theme.glyphs.bar.repeat(filled), tint: (colors) => () => shaded(theme, colors, theme.glyphs.bar, filled, BAR_WIDTH) }, { text: theme.glyphs.bar.repeat(BAR_WIDTH - filled), tint: (colors) => colors.dim }, { text: ` ${counted}/${total}${unit === undefined ? "" : ` ${unit}`}`, tint: (colors) => colors.dim });
|
|
1046
|
+
}
|
|
1047
|
+
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1048
|
+
return parts;
|
|
1049
|
+
}
|
|
1050
|
+
function plain(text) {
|
|
1051
|
+
return text;
|
|
1052
|
+
}
|
|
1053
|
+
function tintedParts(parts, colors) {
|
|
1054
|
+
return parts.map(({ text, tint }) => tint(colors)(text)).join("");
|
|
1055
|
+
}
|
|
1056
|
+
function cutToWidth(line, width) {
|
|
1057
|
+
if (Bun.stringWidth(line) <= width)
|
|
1058
|
+
return line;
|
|
1059
|
+
let room = width;
|
|
1060
|
+
let kept = "";
|
|
1061
|
+
let index = 0;
|
|
1062
|
+
let linked = false;
|
|
1063
|
+
while (index < line.length) {
|
|
1064
|
+
ESCAPE_CODE.lastIndex = index;
|
|
1065
|
+
const escape = ESCAPE_CODE.exec(line);
|
|
1066
|
+
if (escape !== null) {
|
|
1067
|
+
kept += escape[0];
|
|
1068
|
+
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
1069
|
+
index = ESCAPE_CODE.lastIndex;
|
|
1070
|
+
continue;
|
|
1071
|
+
}
|
|
1072
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1073
|
+
const columns = Bun.stringWidth(char);
|
|
1074
|
+
if (columns > room)
|
|
1075
|
+
break;
|
|
1076
|
+
kept += char;
|
|
1077
|
+
room -= columns;
|
|
1078
|
+
index += char.length;
|
|
1079
|
+
}
|
|
1080
|
+
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1081
|
+
}
|
|
1082
|
+
function swallowInput() {
|
|
1083
|
+
const input = process12.stdin;
|
|
1084
|
+
if (!input.isTTY)
|
|
1085
|
+
return () => {
|
|
1086
|
+
return;
|
|
1087
|
+
};
|
|
1088
|
+
const onData = (data) => {
|
|
1089
|
+
if (data.includes(CTRL_C))
|
|
1090
|
+
process12.kill(process12.pid, "SIGINT");
|
|
1091
|
+
};
|
|
1092
|
+
input.setRawMode(true);
|
|
1093
|
+
input.on("data", onData);
|
|
1094
|
+
input.resume();
|
|
1095
|
+
let released = false;
|
|
1096
|
+
return () => {
|
|
1097
|
+
if (released)
|
|
1098
|
+
return;
|
|
1099
|
+
released = true;
|
|
1100
|
+
input.off("data", onData);
|
|
1101
|
+
input.pause();
|
|
1102
|
+
input.setRawMode(false);
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
function interceptOutput(clear) {
|
|
1106
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
|
|
1107
|
+
const wrapped = targets.map(([target, name]) => {
|
|
1108
|
+
const original = Reflect.get(target, name);
|
|
1109
|
+
const wrapper = (...args) => {
|
|
1110
|
+
clear();
|
|
1111
|
+
return original.apply(target, args);
|
|
1112
|
+
};
|
|
1113
|
+
Reflect.set(target, name, wrapper);
|
|
1114
|
+
return { target, name, original, wrapper };
|
|
1115
|
+
});
|
|
1116
|
+
return () => {
|
|
1117
|
+
for (const { target, name, original, wrapper } of wrapped) {
|
|
1118
|
+
if (Reflect.get(target, name) === wrapper)
|
|
1119
|
+
Reflect.set(target, name, original);
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
802
1123
|
// ../kit/src/cli.ts
|
|
803
|
-
import { readFileSync as
|
|
1124
|
+
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
804
1125
|
import { dirname as dirname3, join as join5 } from "path";
|
|
805
|
-
import
|
|
1126
|
+
import process14 from "process";
|
|
806
1127
|
|
|
807
1128
|
// ../kit/src/usage.ts
|
|
808
1129
|
import { appendFileSync, mkdirSync } from "fs";
|
|
809
1130
|
import { homedir as homedir3 } from "os";
|
|
810
1131
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
811
|
-
import
|
|
1132
|
+
import process13 from "process";
|
|
812
1133
|
|
|
813
1134
|
// ../kit/src/logs.ts
|
|
814
1135
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -822,14 +1143,14 @@ var usageError;
|
|
|
822
1143
|
function noteUsageError(message) {
|
|
823
1144
|
usageError = message;
|
|
824
1145
|
}
|
|
825
|
-
function stateHome(env =
|
|
1146
|
+
function stateHome(env = process13.env) {
|
|
826
1147
|
const dir = env.XDG_STATE_HOME;
|
|
827
1148
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
828
1149
|
}
|
|
829
|
-
function usagePath(env =
|
|
1150
|
+
function usagePath(env = process13.env) {
|
|
830
1151
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
831
1152
|
}
|
|
832
|
-
function usageRecorded(env =
|
|
1153
|
+
function usageRecorded(env = process13.env) {
|
|
833
1154
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
834
1155
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
835
1156
|
}
|
|
@@ -843,7 +1164,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
843
1164
|
usageError = undefined;
|
|
844
1165
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
845
1166
|
}
|
|
846
|
-
function recordUsage(entry, env =
|
|
1167
|
+
function recordUsage(entry, env = process13.env) {
|
|
847
1168
|
if (!usageRecorded(env))
|
|
848
1169
|
return;
|
|
849
1170
|
try {
|
|
@@ -861,8 +1182,8 @@ var LEVEL_OPTIONS = {
|
|
|
861
1182
|
};
|
|
862
1183
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
863
1184
|
function printError(prefix, message, hint, cause) {
|
|
864
|
-
const colors = paint(
|
|
865
|
-
const styled = takesControlCodes(
|
|
1185
|
+
const colors = paint(process14.stderr);
|
|
1186
|
+
const styled = takesControlCodes(process14.stderr);
|
|
866
1187
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
867
1188
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
868
1189
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -909,24 +1230,24 @@ function candidateLine(candidate) {
|
|
|
909
1230
|
}
|
|
910
1231
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
911
1232
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
912
|
-
|
|
1233
|
+
const typed = [];
|
|
913
1234
|
let at = 0;
|
|
914
1235
|
while (at < before.length) {
|
|
915
1236
|
const word = before[at];
|
|
916
1237
|
if (word === "--") {
|
|
917
|
-
|
|
1238
|
+
typed.push(...before.slice(at + 1));
|
|
918
1239
|
break;
|
|
919
1240
|
}
|
|
920
1241
|
if (!word.startsWith("-"))
|
|
921
|
-
|
|
1242
|
+
typed.push(word);
|
|
922
1243
|
else if (takesValue(word))
|
|
923
1244
|
at++;
|
|
924
1245
|
at++;
|
|
925
1246
|
}
|
|
926
1247
|
const last = positionals.at(-1);
|
|
927
|
-
if (
|
|
928
|
-
return positionals[
|
|
929
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1248
|
+
if (typed.length < positionals.length)
|
|
1249
|
+
return { name: positionals[typed.length], typed };
|
|
1250
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
930
1251
|
}
|
|
931
1252
|
async function leafCandidates(run, words) {
|
|
932
1253
|
const completing = await completingOf(run);
|
|
@@ -934,12 +1255,12 @@ async function leafCandidates(run, words) {
|
|
|
934
1255
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
935
1256
|
const flag = words.at(-2);
|
|
936
1257
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1258
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
937
1259
|
if (option?.type === "string") {
|
|
938
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1260
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
939
1261
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
940
1262
|
}
|
|
941
|
-
const
|
|
942
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1263
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
943
1264
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
944
1265
|
}
|
|
945
1266
|
async function printCandidates(found) {
|
|
@@ -948,9 +1269,9 @@ async function printCandidates(found) {
|
|
|
948
1269
|
return 0;
|
|
949
1270
|
}
|
|
950
1271
|
function packageVersion(entry = Bun.main) {
|
|
951
|
-
for (let dir = dirname3(
|
|
1272
|
+
for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
|
|
952
1273
|
try {
|
|
953
|
-
const { version } = JSON.parse(
|
|
1274
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
954
1275
|
if (typeof version === "string")
|
|
955
1276
|
return version;
|
|
956
1277
|
} catch {}
|
|
@@ -958,7 +1279,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
958
1279
|
return "0.0.0";
|
|
959
1280
|
}
|
|
960
1281
|
}
|
|
961
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1282
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
962
1283
|
if (argv[0] === COMPLETE)
|
|
963
1284
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
964
1285
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -987,7 +1308,7 @@ var {Glob } = globalThis.Bun;
|
|
|
987
1308
|
var SESSION_FILES = new Glob("*.json");
|
|
988
1309
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
989
1310
|
// ../kit/src/watch.ts
|
|
990
|
-
import
|
|
1311
|
+
import process15 from "process";
|
|
991
1312
|
import { format } from "util";
|
|
992
1313
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
993
1314
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1009,7 +1330,7 @@ function withoutWatch(args) {
|
|
|
1009
1330
|
}
|
|
1010
1331
|
return rest;
|
|
1011
1332
|
}
|
|
1012
|
-
async function watching(value, step, stream =
|
|
1333
|
+
async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1013
1334
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1014
1335
|
if (!takesControlCodes(stream))
|
|
1015
1336
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1017,12 +1338,12 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1017
1338
|
for (let round = 0;round < rounds; round++) {
|
|
1018
1339
|
const held = [];
|
|
1019
1340
|
const { log, info } = console;
|
|
1020
|
-
const write =
|
|
1341
|
+
const write = process15.stdout.write.bind(process15.stdout);
|
|
1021
1342
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1022
1343
|
`);
|
|
1023
1344
|
console.log = hold;
|
|
1024
1345
|
console.info = hold;
|
|
1025
|
-
|
|
1346
|
+
process15.stdout.write = (text) => {
|
|
1026
1347
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1027
1348
|
return true;
|
|
1028
1349
|
};
|
|
@@ -1031,7 +1352,7 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1031
1352
|
} finally {
|
|
1032
1353
|
console.log = log;
|
|
1033
1354
|
console.info = info;
|
|
1034
|
-
|
|
1355
|
+
process15.stdout.write = write;
|
|
1035
1356
|
}
|
|
1036
1357
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1037
1358
|
await sleep(interval);
|
|
@@ -1039,8 +1360,8 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1039
1360
|
return code;
|
|
1040
1361
|
}
|
|
1041
1362
|
// src/colour.ts
|
|
1042
|
-
import
|
|
1043
|
-
function letter(status, stream =
|
|
1363
|
+
import process17 from "process";
|
|
1364
|
+
function letter(status, stream = process17.stdout) {
|
|
1044
1365
|
const colors = paint(stream);
|
|
1045
1366
|
const tint = { A: colors.green, M: colors.yellow, D: colors.red, U: colors.red, R: colors.cyan, C: colors.cyan }[status] ?? colors.dim;
|
|
1046
1367
|
return tint(status);
|
|
@@ -1053,6 +1374,11 @@ async function git2(args, env) {
|
|
|
1053
1374
|
return { code: ran.code, stdout: text("stdout"), stderr: text("stderr") };
|
|
1054
1375
|
}
|
|
1055
1376
|
|
|
1377
|
+
// src/repos.ts
|
|
1378
|
+
import { readdir } from "fs/promises";
|
|
1379
|
+
import { join as join6, relative, resolve as resolve4 } from "path";
|
|
1380
|
+
import process18 from "process";
|
|
1381
|
+
|
|
1056
1382
|
// src/status.ts
|
|
1057
1383
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
1058
1384
|
var OCTAL = /[0-7]/;
|
|
@@ -1125,30 +1451,122 @@ function summary(status, head) {
|
|
|
1125
1451
|
return `${on}, ${tracking}; ${files} files${last}`;
|
|
1126
1452
|
}
|
|
1127
1453
|
|
|
1454
|
+
// src/repos.ts
|
|
1455
|
+
var SKIPPED = new Set(["node_modules", "vendor", "dist"]);
|
|
1456
|
+
var DEPTH = 4;
|
|
1457
|
+
async function reposUnder(root, depth = DEPTH) {
|
|
1458
|
+
const found = [];
|
|
1459
|
+
async function walk(dir, left) {
|
|
1460
|
+
let entries;
|
|
1461
|
+
try {
|
|
1462
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
1463
|
+
} catch {
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
if (entries.some((entry) => entry.name === ".git"))
|
|
1467
|
+
found.push(dir);
|
|
1468
|
+
if (left === 0)
|
|
1469
|
+
return;
|
|
1470
|
+
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join6(dir, entry.name), left - 1)));
|
|
1471
|
+
}
|
|
1472
|
+
await walk(resolve4(root), depth);
|
|
1473
|
+
return found.sort();
|
|
1474
|
+
}
|
|
1475
|
+
async function toplevelOf(dir) {
|
|
1476
|
+
const read = await git2(["-C", dir, "rev-parse", "--show-toplevel"]);
|
|
1477
|
+
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1478
|
+
}
|
|
1479
|
+
async function reposOf(roots) {
|
|
1480
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process18.cwd()];
|
|
1481
|
+
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1482
|
+
return [...new Set(found.flat())].sort();
|
|
1483
|
+
}
|
|
1484
|
+
async function repoState(dir) {
|
|
1485
|
+
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1486
|
+
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1487
|
+
return { path: relative(process18.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1488
|
+
}
|
|
1489
|
+
function trackingOf(status) {
|
|
1490
|
+
if (status.upstream === null)
|
|
1491
|
+
return "no upstream";
|
|
1492
|
+
if (status.aheadBehind === null)
|
|
1493
|
+
return "upstream gone";
|
|
1494
|
+
const { ahead, behind } = status.aheadBehind;
|
|
1495
|
+
const parts = [ahead > 0 ? `${ahead} ahead` : "", behind > 0 ? `${behind} behind` : ""].filter(Boolean);
|
|
1496
|
+
return parts.length === 0 ? "up to date" : parts.join(", ");
|
|
1497
|
+
}
|
|
1498
|
+
function changesOf(status) {
|
|
1499
|
+
const { changes, untracked, conflicted } = status;
|
|
1500
|
+
const parts = [changes.length > 0 ? `${changes.length} changed` : "", untracked.length > 0 ? `${untracked.length} untracked` : "", conflicted.length > 0 ? `${conflicted.length} conflicted` : ""].filter(Boolean);
|
|
1501
|
+
return parts.length === 0 ? "clean" : parts.join(", ");
|
|
1502
|
+
}
|
|
1503
|
+
function branchOf(status) {
|
|
1504
|
+
return status.branch === "(detached)" ? `detached at ${status.oid.slice(0, 7)}` : status.branch;
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1128
1507
|
// src/gst.ts
|
|
1129
1508
|
var USAGE = `gst [-n N]: the repository's branch, upstream, changed files and HEAD in one line, then the changed paths by staged, unstaged and untracked
|
|
1130
1509
|
|
|
1510
|
+
gst --repos [dir]... lists every repository at and below the current one's toplevel (or below each dir given, the current directory outside a repository), four levels down, past node_modules, vendor, dist and hidden folders: one line each with its path, branch, how it stands against its upstream as of the last fetch, and the files left to commit.
|
|
1511
|
+
|
|
1131
1512
|
Exits 0 when it printed the status, 2 outside a git repository or on a usage error.`;
|
|
1132
1513
|
var OPTIONS = {
|
|
1133
1514
|
limit: { type: "string", short: "n", description: "add the last N commits as <sha7> <title>" },
|
|
1134
1515
|
log: { type: "string", short: "l", description: "the former spelling of --limit" },
|
|
1516
|
+
repos: { type: "boolean", short: "r", description: "one line for each repository nested below, the current one included", conflicts: ["limit", "log"] },
|
|
1135
1517
|
watch: watchOption("the status"),
|
|
1136
|
-
json: jsonOption("{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}")
|
|
1518
|
+
json: jsonOption("{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}; with --repos an array of them, each with its path and no commits, a repository git cannot read being {path, error}")
|
|
1137
1519
|
};
|
|
1520
|
+
function jsonOf(status, head, commits) {
|
|
1521
|
+
return {
|
|
1522
|
+
branch: status.branch,
|
|
1523
|
+
oid: status.oid,
|
|
1524
|
+
upstream: status.upstream,
|
|
1525
|
+
ahead: status.aheadBehind?.ahead ?? null,
|
|
1526
|
+
behind: status.aheadBehind?.behind ?? null,
|
|
1527
|
+
head,
|
|
1528
|
+
staged: status.changes.filter((change) => change.index !== ".").map(({ index, path, from }) => ({ status: index, path, ...from === undefined ? {} : { from } })),
|
|
1529
|
+
unstaged: status.changes.filter((change) => change.worktree !== ".").map(({ worktree, path }) => ({ status: worktree, path })),
|
|
1530
|
+
untracked: status.untracked,
|
|
1531
|
+
conflicted: status.conflicted,
|
|
1532
|
+
...commits === undefined ? {} : { commits: commits.map(([commitSha = "", commitTitle = ""]) => ({ sha: commitSha, title: commitTitle })) }
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
async function listRepos(roots, json) {
|
|
1536
|
+
const dirs = await reposOf(roots);
|
|
1537
|
+
if (dirs.length === 0)
|
|
1538
|
+
fail(`no git repository at or below ${roots.length === 0 ? "the current directory" : roots.join(", ")}`);
|
|
1539
|
+
const repos = await Promise.all(dirs.map(repoState));
|
|
1540
|
+
if (json) {
|
|
1541
|
+
printJson(repos.map(({ path, status, head }) => status === null ? { path, error: "git could not read it" } : { path, ...jsonOf(status, head) }));
|
|
1542
|
+
return 0;
|
|
1543
|
+
}
|
|
1544
|
+
const dim = paint(process19.stdout).dim;
|
|
1545
|
+
const cells = (repo) => {
|
|
1546
|
+
if (repo.status === null)
|
|
1547
|
+
return [role("path", process19.stdout)(repo.path), "", "", "git could not read it"];
|
|
1548
|
+
const changes = changesOf(repo.status);
|
|
1549
|
+
return [role("path", process19.stdout)(repo.path), branchOf(repo.status), trackingOf(repo.status), changes === "clean" ? dim(changes) : changes];
|
|
1550
|
+
};
|
|
1551
|
+
console.log(table(repos.map(cells)));
|
|
1552
|
+
return 0;
|
|
1553
|
+
}
|
|
1138
1554
|
function group(title, lines) {
|
|
1139
|
-
return lines.length === 0 ? [] : [paint(
|
|
1555
|
+
return lines.length === 0 ? [] : [paint(process19.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
|
|
1140
1556
|
}
|
|
1141
1557
|
function staged({ index, from, path }) {
|
|
1142
1558
|
return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
|
|
1143
1559
|
}
|
|
1144
1560
|
async function main(argv) {
|
|
1145
|
-
const parsed = parse(argv, USAGE, OPTIONS, { replaces: "git status --short
|
|
1146
|
-
if (parsed.positionals.length > 0)
|
|
1147
|
-
fail(`gst takes
|
|
1561
|
+
const parsed = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], replaces: "git status --short, git log --oneline and a git -C <repo> status per nested repository", examples: ["gst", ["gst -n 5", "with the last five commits"], ["gst --repos", "the repositories nested in this one"]] });
|
|
1562
|
+
if (parsed.positionals.length > 0 && parsed.values.repos !== true)
|
|
1563
|
+
fail(`gst takes dirs with --repos alone
|
|
1148
1564
|
|
|
1149
1565
|
${USAGE}`);
|
|
1150
1566
|
if (parsed.values.watch !== undefined)
|
|
1151
1567
|
return watching(parsed.values.watch, async () => main(withoutWatch(argv)));
|
|
1568
|
+
if (parsed.values.repos === true)
|
|
1569
|
+
return listRepos(parsed.positionals, parsed.values.json === true);
|
|
1152
1570
|
if (parsed.values.limit !== undefined && parsed.values.log !== undefined)
|
|
1153
1571
|
fail("--limit and --log are the same flag, give one");
|
|
1154
1572
|
const asked = parsed.values.limit ?? parsed.values.log;
|
|
@@ -1165,31 +1583,19 @@ ${USAGE}`);
|
|
|
1165
1583
|
`).filter(Boolean).map((line) => line.split("\x00")) : [];
|
|
1166
1584
|
if (parsed.values.json === true) {
|
|
1167
1585
|
const [sha, title] = head.code === 0 && head.stdout.trim() !== "" ? head.stdout.trim().split("\x00") : [];
|
|
1168
|
-
printJson({
|
|
1169
|
-
branch: status.branch,
|
|
1170
|
-
oid: status.oid,
|
|
1171
|
-
upstream: status.upstream,
|
|
1172
|
-
ahead: status.aheadBehind?.ahead ?? null,
|
|
1173
|
-
behind: status.aheadBehind?.behind ?? null,
|
|
1174
|
-
head: sha === undefined ? null : { sha, title: title ?? "" },
|
|
1175
|
-
staged: status.changes.filter((change) => change.index !== ".").map(({ index, path, from }) => ({ status: index, path, ...from === undefined ? {} : { from } })),
|
|
1176
|
-
unstaged: status.changes.filter((change) => change.worktree !== ".").map(({ worktree, path }) => ({ status: worktree, path })),
|
|
1177
|
-
untracked: status.untracked,
|
|
1178
|
-
conflicted: status.conflicted,
|
|
1179
|
-
commits: commits.map(([commitSha = "", commitTitle = ""]) => ({ sha: commitSha, title: commitTitle }))
|
|
1180
|
-
});
|
|
1586
|
+
printJson(jsonOf(status, sha === undefined ? null : { sha, title: title ?? "" }, commits));
|
|
1181
1587
|
return 0;
|
|
1182
1588
|
}
|
|
1183
1589
|
const lines = [
|
|
1184
1590
|
summary(status, head.code === 0 ? head.stdout : ""),
|
|
1185
1591
|
...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
|
|
1186
1592
|
...group("unstaged", status.changes.filter((change) => change.worktree !== ".").map((change) => `${letter(change.worktree)} ${change.path}`)),
|
|
1187
|
-
...group("untracked", status.untracked.map((file) => paint(
|
|
1188
|
-
...group("conflicted", status.conflicted.map((file) => paint(
|
|
1189
|
-
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id",
|
|
1593
|
+
...group("untracked", status.untracked.map((file) => paint(process19.stdout).dim(file))),
|
|
1594
|
+
...group("conflicted", status.conflicted.map((file) => paint(process19.stdout).red(file))),
|
|
1595
|
+
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process19.stdout)(commitSha)} ${commitTitle}`))
|
|
1190
1596
|
];
|
|
1191
1597
|
console.log(lines.join(`
|
|
1192
1598
|
`));
|
|
1193
1599
|
return 0;
|
|
1194
1600
|
}
|
|
1195
|
-
|
|
1601
|
+
process19.exitCode = await runMain({ name: "gst", run: main });
|