@kaynooo/cli-git 0.14.0 → 0.15.1
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 +34 -1
- package/dist/gb.js +302 -43
- package/dist/gc.js +290 -31
- package/dist/gcl.js +1662 -0
- package/dist/gd.js +1642 -0
- package/dist/gf.js +1624 -0
- package/dist/gp.js +320 -52
- package/dist/gst.js +322 -49
- package/dist/gu.js +1484 -0
- package/package.json +14 -6
package/dist/gp.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gp.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";
|
|
@@ -108,7 +108,7 @@ function Fe(r = {}) {
|
|
|
108
108
|
var o = Fe();
|
|
109
109
|
|
|
110
110
|
// ../kit/src/theme.ts
|
|
111
|
-
import { existsSync as
|
|
111
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
112
112
|
import { homedir as homedir2 } from "os";
|
|
113
113
|
import { join as join3, resolve as resolve2 } from "path";
|
|
114
114
|
import process5 from "process";
|
|
@@ -129,6 +129,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
// ../kit/src/user-config.ts
|
|
132
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
132
133
|
import { homedir } from "os";
|
|
133
134
|
import { join as join2 } from "path";
|
|
134
135
|
import process4 from "process";
|
|
@@ -139,9 +140,59 @@ function configBase(where = {}) {
|
|
|
139
140
|
function userConfigPath(bin, where = {}) {
|
|
140
141
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
141
142
|
}
|
|
143
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
144
|
+
const current = userConfigPath(bin, where);
|
|
145
|
+
if (existsSync2(current))
|
|
146
|
+
return current;
|
|
147
|
+
const base = configBase(where);
|
|
148
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
149
|
+
}
|
|
150
|
+
function readUserConfig(bin, where = {}, legacy = []) {
|
|
151
|
+
const path = userConfigReadPath(bin, legacy, where);
|
|
152
|
+
if (!existsSync2(path))
|
|
153
|
+
return {};
|
|
154
|
+
try {
|
|
155
|
+
const parsed = Bun.JSONC.parse(readFileSync(path, "utf8"));
|
|
156
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
157
|
+
} catch {
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
142
161
|
|
|
143
162
|
// ../kit/src/theme.ts
|
|
163
|
+
function toLinear(channel) {
|
|
164
|
+
const value = channel / 255;
|
|
165
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
166
|
+
}
|
|
167
|
+
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)));
|
|
168
|
+
function toOklab(hex) {
|
|
169
|
+
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
170
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
171
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
172
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
173
|
+
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];
|
|
174
|
+
}
|
|
175
|
+
function fromOklab([lightness, a, b]) {
|
|
176
|
+
const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
177
|
+
const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
178
|
+
const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
179
|
+
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];
|
|
180
|
+
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
181
|
+
}
|
|
144
182
|
var ENDS = new Map;
|
|
183
|
+
function gradientAt(theme, ratio) {
|
|
184
|
+
if (theme.gradient === undefined)
|
|
185
|
+
return;
|
|
186
|
+
const key = theme.gradient.join();
|
|
187
|
+
let ends = ENDS.get(key);
|
|
188
|
+
if (ends === undefined) {
|
|
189
|
+
ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
|
|
190
|
+
ENDS.set(key, ends);
|
|
191
|
+
}
|
|
192
|
+
const at = Math.min(1, Math.max(0, ratio));
|
|
193
|
+
const [from, to] = ends;
|
|
194
|
+
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
195
|
+
}
|
|
145
196
|
var DEFAULT = {
|
|
146
197
|
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" },
|
|
147
198
|
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" },
|
|
@@ -193,6 +244,9 @@ function tinted(colors, spec, env = process5.env) {
|
|
|
193
244
|
return chain[token] ?? chain;
|
|
194
245
|
}, colors);
|
|
195
246
|
}
|
|
247
|
+
function shaded(theme, colors, glyph, cells, width, env = process5.env) {
|
|
248
|
+
return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
|
|
249
|
+
}
|
|
196
250
|
function isRecord(value) {
|
|
197
251
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
198
252
|
}
|
|
@@ -205,7 +259,7 @@ function readThemeFile(path, warn) {
|
|
|
205
259
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
206
260
|
return;
|
|
207
261
|
}
|
|
208
|
-
const parsed = JSON.parse(
|
|
262
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
209
263
|
if (isRecord(parsed))
|
|
210
264
|
return parsed;
|
|
211
265
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -271,7 +325,7 @@ function applyFile(theme, file, where, warn) {
|
|
|
271
325
|
}
|
|
272
326
|
}
|
|
273
327
|
function endsWalk(home) {
|
|
274
|
-
return (dir) => dir === resolve2(home) ||
|
|
328
|
+
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
275
329
|
}
|
|
276
330
|
var warned = new Set;
|
|
277
331
|
function warnOnce(message) {
|
|
@@ -366,6 +420,12 @@ function formatSeconds(total) {
|
|
|
366
420
|
const next = amounts[first + 1];
|
|
367
421
|
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
368
422
|
}
|
|
423
|
+
function formatDuration(ms) {
|
|
424
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
425
|
+
}
|
|
426
|
+
function formatElapsed(ms) {
|
|
427
|
+
return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
|
|
428
|
+
}
|
|
369
429
|
function upTo(text, separator) {
|
|
370
430
|
const end = text.indexOf(separator);
|
|
371
431
|
return end === -1 ? text : text.slice(0, end);
|
|
@@ -439,18 +499,14 @@ var FULL_STOP = /\.$/;
|
|
|
439
499
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
440
500
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
441
501
|
}
|
|
442
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
443
|
-
return [usageLine(usage, colors),
|
|
502
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
503
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
444
504
|
`);
|
|
445
505
|
}
|
|
446
506
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
447
507
|
if (exits.length === 0)
|
|
448
508
|
return [];
|
|
449
|
-
|
|
450
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
451
|
-
}
|
|
452
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
453
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
509
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
454
510
|
}
|
|
455
511
|
function wantsHelpJson(env = process8.env) {
|
|
456
512
|
return env.KIT_HELP === "json";
|
|
@@ -747,12 +803,12 @@ function nearestOption(message, options, allowNegative) {
|
|
|
747
803
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
748
804
|
}
|
|
749
805
|
// ../kit/src/argv.ts
|
|
750
|
-
import { readFileSync as
|
|
806
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
751
807
|
import { resolve as resolve3 } from "path";
|
|
752
808
|
import process10 from "process";
|
|
753
809
|
function commandLine() {
|
|
754
810
|
try {
|
|
755
|
-
return
|
|
811
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
756
812
|
} catch {
|
|
757
813
|
return;
|
|
758
814
|
}
|
|
@@ -770,6 +826,9 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
770
826
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
771
827
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
772
828
|
}
|
|
829
|
+
// ../kit/src/progress.ts
|
|
830
|
+
import process12 from "process";
|
|
831
|
+
|
|
773
832
|
// ../kit/src/process.ts
|
|
774
833
|
import { constants } from "os";
|
|
775
834
|
import process11 from "process";
|
|
@@ -893,20 +952,199 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
893
952
|
}
|
|
894
953
|
|
|
895
954
|
// ../kit/src/progress.ts
|
|
955
|
+
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
956
|
+
var FRAME_MS = 200;
|
|
957
|
+
var BAR_WIDTH = 20;
|
|
958
|
+
var CLEAR_BELOW = "\r\x1B[J";
|
|
896
959
|
var ESC = String.fromCharCode(27);
|
|
897
960
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
898
961
|
var RESET_STYLE = `${ESC}[0m`;
|
|
962
|
+
var CTRL_C = 3;
|
|
899
963
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
964
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
965
|
+
function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
966
|
+
if (!takesControlCodes(stream, env))
|
|
967
|
+
return { redraw: () => {
|
|
968
|
+
return;
|
|
969
|
+
}, print: (text) => void stream.write(`${text}
|
|
970
|
+
`), stop: () => {
|
|
971
|
+
return;
|
|
972
|
+
} };
|
|
973
|
+
const write = stream.write.bind(stream);
|
|
974
|
+
let frame = 0;
|
|
975
|
+
let drawn = false;
|
|
976
|
+
const columns = () => {
|
|
977
|
+
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
978
|
+
return now === undefined || now === 0 ? 80 : now;
|
|
979
|
+
};
|
|
980
|
+
const clear = () => {
|
|
981
|
+
if (drawn)
|
|
982
|
+
write(CLEAR_BELOW);
|
|
983
|
+
drawn = false;
|
|
984
|
+
};
|
|
985
|
+
const draw = () => {
|
|
986
|
+
const width = columns() - 1;
|
|
987
|
+
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
988
|
+
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
989
|
+
if (lines.length === 0) {
|
|
990
|
+
clear();
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
write(`${CLEAR_BELOW}${lines.join(`
|
|
994
|
+
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
995
|
+
drawn = true;
|
|
996
|
+
};
|
|
997
|
+
const timer = setInterval(draw, FRAME_MS);
|
|
998
|
+
stream.on?.("resize", draw);
|
|
999
|
+
const restore = interceptOutput(clear);
|
|
1000
|
+
const release = swallowInput();
|
|
1001
|
+
const onExit = () => {
|
|
1002
|
+
clear();
|
|
1003
|
+
release();
|
|
1004
|
+
};
|
|
1005
|
+
const signals = holdSignals(stop);
|
|
1006
|
+
function stop() {
|
|
1007
|
+
clearInterval(timer);
|
|
1008
|
+
stream.off?.("resize", draw);
|
|
1009
|
+
clear();
|
|
1010
|
+
restore();
|
|
1011
|
+
release();
|
|
1012
|
+
process12.off("exit", onExit);
|
|
1013
|
+
signals.release();
|
|
1014
|
+
}
|
|
1015
|
+
timer.unref();
|
|
1016
|
+
process12.on("exit", onExit);
|
|
1017
|
+
return {
|
|
1018
|
+
redraw: draw,
|
|
1019
|
+
print: (text) => {
|
|
1020
|
+
clear();
|
|
1021
|
+
write(`${text}
|
|
1022
|
+
`);
|
|
1023
|
+
draw();
|
|
1024
|
+
},
|
|
1025
|
+
stop
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
1029
|
+
const colors = paint(stream, env);
|
|
1030
|
+
const write = stream.write.bind(stream);
|
|
1031
|
+
const begun = performance.now();
|
|
1032
|
+
let started = begun;
|
|
1033
|
+
let current;
|
|
1034
|
+
const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
|
|
1035
|
+
const end = (line) => {
|
|
1036
|
+
region.stop();
|
|
1037
|
+
write(`${line}
|
|
1038
|
+
`);
|
|
1039
|
+
};
|
|
1040
|
+
return {
|
|
1041
|
+
update: (progress) => {
|
|
1042
|
+
const step = current?.step;
|
|
1043
|
+
current = progress;
|
|
1044
|
+
if (progress.step !== step) {
|
|
1045
|
+
started = performance.now();
|
|
1046
|
+
region.redraw();
|
|
1047
|
+
}
|
|
1048
|
+
},
|
|
1049
|
+
stop: region.stop,
|
|
1050
|
+
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1051
|
+
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
function progressParts({ step, done, total, unit }, spinner, ms) {
|
|
1055
|
+
const { theme } = activeTheme();
|
|
1056
|
+
const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
|
|
1057
|
+
if (total !== undefined && total > 0) {
|
|
1058
|
+
const counted = Math.min(done ?? 0, total);
|
|
1059
|
+
const filled = Math.round(counted / total * BAR_WIDTH);
|
|
1060
|
+
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 });
|
|
1061
|
+
}
|
|
1062
|
+
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1063
|
+
return parts;
|
|
1064
|
+
}
|
|
1065
|
+
function plain(text) {
|
|
1066
|
+
return text;
|
|
1067
|
+
}
|
|
1068
|
+
function tintedParts(parts, colors) {
|
|
1069
|
+
return parts.map(({ text, tint }) => tint(colors)(text)).join("");
|
|
1070
|
+
}
|
|
1071
|
+
function cutToWidth(line, width) {
|
|
1072
|
+
if (Bun.stringWidth(line) <= width)
|
|
1073
|
+
return line;
|
|
1074
|
+
let room = width;
|
|
1075
|
+
let kept = "";
|
|
1076
|
+
let index = 0;
|
|
1077
|
+
let linked = false;
|
|
1078
|
+
while (index < line.length) {
|
|
1079
|
+
ESCAPE_CODE.lastIndex = index;
|
|
1080
|
+
const escape = ESCAPE_CODE.exec(line);
|
|
1081
|
+
if (escape !== null) {
|
|
1082
|
+
kept += escape[0];
|
|
1083
|
+
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
1084
|
+
index = ESCAPE_CODE.lastIndex;
|
|
1085
|
+
continue;
|
|
1086
|
+
}
|
|
1087
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1088
|
+
const columns = Bun.stringWidth(char);
|
|
1089
|
+
if (columns > room)
|
|
1090
|
+
break;
|
|
1091
|
+
kept += char;
|
|
1092
|
+
room -= columns;
|
|
1093
|
+
index += char.length;
|
|
1094
|
+
}
|
|
1095
|
+
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1096
|
+
}
|
|
1097
|
+
function swallowInput() {
|
|
1098
|
+
const input = process12.stdin;
|
|
1099
|
+
if (!input.isTTY)
|
|
1100
|
+
return () => {
|
|
1101
|
+
return;
|
|
1102
|
+
};
|
|
1103
|
+
const onData = (data) => {
|
|
1104
|
+
if (data.includes(CTRL_C))
|
|
1105
|
+
process12.kill(process12.pid, "SIGINT");
|
|
1106
|
+
};
|
|
1107
|
+
input.setRawMode(true);
|
|
1108
|
+
input.on("data", onData);
|
|
1109
|
+
input.resume();
|
|
1110
|
+
let released = false;
|
|
1111
|
+
return () => {
|
|
1112
|
+
if (released)
|
|
1113
|
+
return;
|
|
1114
|
+
released = true;
|
|
1115
|
+
input.off("data", onData);
|
|
1116
|
+
input.pause();
|
|
1117
|
+
input.setRawMode(false);
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
function interceptOutput(clear) {
|
|
1121
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
|
|
1122
|
+
const wrapped = targets.map(([target, name]) => {
|
|
1123
|
+
const original = Reflect.get(target, name);
|
|
1124
|
+
const wrapper = (...args) => {
|
|
1125
|
+
clear();
|
|
1126
|
+
return original.apply(target, args);
|
|
1127
|
+
};
|
|
1128
|
+
Reflect.set(target, name, wrapper);
|
|
1129
|
+
return { target, name, original, wrapper };
|
|
1130
|
+
});
|
|
1131
|
+
return () => {
|
|
1132
|
+
for (const { target, name, original, wrapper } of wrapped) {
|
|
1133
|
+
if (Reflect.get(target, name) === wrapper)
|
|
1134
|
+
Reflect.set(target, name, original);
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
900
1138
|
// ../kit/src/cli.ts
|
|
901
|
-
import { readFileSync as
|
|
1139
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
902
1140
|
import { dirname as dirname3, join as join5 } from "path";
|
|
903
|
-
import
|
|
1141
|
+
import process14 from "process";
|
|
904
1142
|
|
|
905
1143
|
// ../kit/src/usage.ts
|
|
906
1144
|
import { appendFileSync, mkdirSync } from "fs";
|
|
907
1145
|
import { homedir as homedir3 } from "os";
|
|
908
1146
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
909
|
-
import
|
|
1147
|
+
import process13 from "process";
|
|
910
1148
|
|
|
911
1149
|
// ../kit/src/logs.ts
|
|
912
1150
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -920,14 +1158,14 @@ var usageError;
|
|
|
920
1158
|
function noteUsageError(message) {
|
|
921
1159
|
usageError = message;
|
|
922
1160
|
}
|
|
923
|
-
function stateHome(env =
|
|
1161
|
+
function stateHome(env = process13.env) {
|
|
924
1162
|
const dir = env.XDG_STATE_HOME;
|
|
925
1163
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
926
1164
|
}
|
|
927
|
-
function usagePath(env =
|
|
1165
|
+
function usagePath(env = process13.env) {
|
|
928
1166
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
929
1167
|
}
|
|
930
|
-
function usageRecorded(env =
|
|
1168
|
+
function usageRecorded(env = process13.env) {
|
|
931
1169
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
932
1170
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
933
1171
|
}
|
|
@@ -941,7 +1179,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
941
1179
|
usageError = undefined;
|
|
942
1180
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
943
1181
|
}
|
|
944
|
-
function recordUsage(entry, env =
|
|
1182
|
+
function recordUsage(entry, env = process13.env) {
|
|
945
1183
|
if (!usageRecorded(env))
|
|
946
1184
|
return;
|
|
947
1185
|
try {
|
|
@@ -959,8 +1197,8 @@ var LEVEL_OPTIONS = {
|
|
|
959
1197
|
};
|
|
960
1198
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
961
1199
|
function printError(prefix, message, hint, cause) {
|
|
962
|
-
const colors = paint(
|
|
963
|
-
const styled = takesControlCodes(
|
|
1200
|
+
const colors = paint(process14.stderr);
|
|
1201
|
+
const styled = takesControlCodes(process14.stderr);
|
|
964
1202
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
965
1203
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
966
1204
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1046,9 +1284,13 @@ async function printCandidates(found) {
|
|
|
1046
1284
|
return 0;
|
|
1047
1285
|
}
|
|
1048
1286
|
function packageVersion(entry = Bun.main) {
|
|
1049
|
-
|
|
1287
|
+
let resolved = entry;
|
|
1288
|
+
try {
|
|
1289
|
+
resolved = realpathSync2(entry);
|
|
1290
|
+
} catch {}
|
|
1291
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1050
1292
|
try {
|
|
1051
|
-
const { version } = JSON.parse(
|
|
1293
|
+
const { version } = JSON.parse(readFileSync4(join5(dir, "package.json"), "utf8"));
|
|
1052
1294
|
if (typeof version === "string")
|
|
1053
1295
|
return version;
|
|
1054
1296
|
} catch {}
|
|
@@ -1085,7 +1327,7 @@ var {Glob } = globalThis.Bun;
|
|
|
1085
1327
|
var SESSION_FILES = new Glob("*.json");
|
|
1086
1328
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1087
1329
|
// ../kit/src/watch.ts
|
|
1088
|
-
import
|
|
1330
|
+
import process15 from "process";
|
|
1089
1331
|
import { format } from "util";
|
|
1090
1332
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1091
1333
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1107,7 +1349,7 @@ function withoutWatch(args) {
|
|
|
1107
1349
|
}
|
|
1108
1350
|
return rest;
|
|
1109
1351
|
}
|
|
1110
|
-
async function watching(value, step, stream =
|
|
1352
|
+
async function watching(value, step, stream = process15.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1111
1353
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1112
1354
|
if (!takesControlCodes(stream))
|
|
1113
1355
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1115,12 +1357,12 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1115
1357
|
for (let round = 0;round < rounds; round++) {
|
|
1116
1358
|
const held = [];
|
|
1117
1359
|
const { log, info } = console;
|
|
1118
|
-
const write =
|
|
1360
|
+
const write = process15.stdout.write.bind(process15.stdout);
|
|
1119
1361
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1120
1362
|
`);
|
|
1121
1363
|
console.log = hold;
|
|
1122
1364
|
console.info = hold;
|
|
1123
|
-
|
|
1365
|
+
process15.stdout.write = (text) => {
|
|
1124
1366
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1125
1367
|
return true;
|
|
1126
1368
|
};
|
|
@@ -1129,13 +1371,30 @@ async function watching(value, step, stream = process14.stdout, sleep = Bun.slee
|
|
|
1129
1371
|
} finally {
|
|
1130
1372
|
console.log = log;
|
|
1131
1373
|
console.info = info;
|
|
1132
|
-
|
|
1374
|
+
process15.stdout.write = write;
|
|
1133
1375
|
}
|
|
1134
1376
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1135
1377
|
await sleep(interval);
|
|
1136
1378
|
}
|
|
1137
1379
|
return code;
|
|
1138
1380
|
}
|
|
1381
|
+
// ../kit/src/workspace-root.ts
|
|
1382
|
+
import { homedir as homedir4 } from "os";
|
|
1383
|
+
import { dirname as dirname4, join as join6, resolve as resolve4 } from "path";
|
|
1384
|
+
import process16 from "process";
|
|
1385
|
+
function expandHome(path, home) {
|
|
1386
|
+
if (path === "~")
|
|
1387
|
+
return home;
|
|
1388
|
+
return path.startsWith("~/") ? join6(home, path.slice(2)) : path;
|
|
1389
|
+
}
|
|
1390
|
+
function configured(env, home) {
|
|
1391
|
+
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1392
|
+
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1393
|
+
}
|
|
1394
|
+
function workspaceRoot({ given, env = process16.env, home = homedir4() } = {}) {
|
|
1395
|
+
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1396
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1397
|
+
}
|
|
1139
1398
|
// src/git.ts
|
|
1140
1399
|
async function git2(args, env) {
|
|
1141
1400
|
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
@@ -1145,8 +1404,8 @@ async function git2(args, env) {
|
|
|
1145
1404
|
|
|
1146
1405
|
// src/repos.ts
|
|
1147
1406
|
import { readdir } from "fs/promises";
|
|
1148
|
-
import { join as
|
|
1149
|
-
import
|
|
1407
|
+
import { join as join7, relative, resolve as resolve5 } from "path";
|
|
1408
|
+
import process18 from "process";
|
|
1150
1409
|
|
|
1151
1410
|
// src/status.ts
|
|
1152
1411
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -1236,9 +1495,9 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
1236
1495
|
found.push(dir);
|
|
1237
1496
|
if (left === 0)
|
|
1238
1497
|
return;
|
|
1239
|
-
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(
|
|
1498
|
+
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join7(dir, entry.name), left - 1)));
|
|
1240
1499
|
}
|
|
1241
|
-
await walk(
|
|
1500
|
+
await walk(resolve5(root), depth);
|
|
1242
1501
|
return found.sort();
|
|
1243
1502
|
}
|
|
1244
1503
|
async function toplevelOf(dir) {
|
|
@@ -1246,14 +1505,14 @@ async function toplevelOf(dir) {
|
|
|
1246
1505
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1247
1506
|
}
|
|
1248
1507
|
async function reposOf(roots) {
|
|
1249
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
1508
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process18.cwd()];
|
|
1250
1509
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1251
1510
|
return [...new Set(found.flat())].sort();
|
|
1252
1511
|
}
|
|
1253
1512
|
async function repoState(dir) {
|
|
1254
1513
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1255
1514
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1256
|
-
return { path: relative(
|
|
1515
|
+
return { path: relative(process18.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1257
1516
|
}
|
|
1258
1517
|
function trackingOf(status) {
|
|
1259
1518
|
if (status.upstream === null)
|
|
@@ -1272,6 +1531,21 @@ function changesOf(status) {
|
|
|
1272
1531
|
function branchOf(status) {
|
|
1273
1532
|
return status.branch === "(detached)" ? `detached at ${status.oid.slice(0, 7)}` : status.branch;
|
|
1274
1533
|
}
|
|
1534
|
+
async function dirsOf(positionals, all) {
|
|
1535
|
+
const asked = positionals.length > 0 ? positionals : ["."];
|
|
1536
|
+
let dirs;
|
|
1537
|
+
if (all) {
|
|
1538
|
+
dirs = await reposOf(positionals);
|
|
1539
|
+
} else {
|
|
1540
|
+
const found = await Promise.all(asked.map(async (dir) => toplevelOf(dir)));
|
|
1541
|
+
if (found.includes(undefined))
|
|
1542
|
+
fail(`not inside a git repository: ${asked.filter((_, at) => found[at] === undefined).join(", ")}`);
|
|
1543
|
+
dirs = [...new Set(found)];
|
|
1544
|
+
}
|
|
1545
|
+
if (dirs.length === 0)
|
|
1546
|
+
fail(`no git repository at or below ${positionals.length === 0 ? "the current directory" : positionals.join(", ")}`);
|
|
1547
|
+
return dirs;
|
|
1548
|
+
}
|
|
1275
1549
|
|
|
1276
1550
|
// src/gp.ts
|
|
1277
1551
|
var USAGE = `gp [dir]...: pushes the current branch of the repository, or of each dir's, when it is ahead of its upstream as of the last fetch or has none yet, the latter with -u to origin (the only remote when there is no origin)
|
|
@@ -1332,38 +1606,32 @@ async function push(repo, { dryRun, extra }) {
|
|
|
1332
1606
|
return pushed.code === 0 ? { path, branch, remote, commits, outcome: "pushed" } : { path, branch, remote, commits, outcome: "refused", reason: whyRefused(pushed.stderr) };
|
|
1333
1607
|
}
|
|
1334
1608
|
function line(result) {
|
|
1335
|
-
const { dim } = paint(
|
|
1609
|
+
const { dim } = paint(process19.stdout);
|
|
1336
1610
|
const sent = result.commits === null ? "" : `, ${result.commits} ${result.commits === 1 ? "commit" : "commits"}`;
|
|
1337
1611
|
const what = `${result.branch} -> ${result.remote}${sent}`;
|
|
1338
1612
|
const said = {
|
|
1339
|
-
pushed: () => marked("ok", `pushed ${what}`,
|
|
1613
|
+
pushed: () => marked("ok", `pushed ${what}`, process19.stdout),
|
|
1340
1614
|
"would-push": () => `would push ${what}`,
|
|
1341
1615
|
skipped: () => dim(result.reason ?? "skipped"),
|
|
1342
|
-
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`,
|
|
1616
|
+
refused: () => marked("problem", `${result.branch === null ? "" : `${result.branch}: `}${result.reason ?? "refused"}`, process19.stdout)
|
|
1343
1617
|
}[result.outcome];
|
|
1344
|
-
return [role("path",
|
|
1618
|
+
return [role("path", process19.stdout)(result.path), said()];
|
|
1345
1619
|
}
|
|
1346
1620
|
async function main(argv) {
|
|
1347
1621
|
const { values, positionals, rest = [] } = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], rest: true, exits: EXITS, replaces: "git push, git push -u origin <branch> and a git -C <repo> push per nested repository", examples: ["gp", ["gp --repos", "every repository nested in this one"], ["gp --repos --dry-run", "what would go out"], ["gp . ../other", "this repository and a sibling"], ["gp -- --force-with-lease", "flags for git push"]] });
|
|
1348
|
-
|
|
1349
|
-
if (values.repos === true) {
|
|
1350
|
-
dirs = await reposOf(positionals);
|
|
1351
|
-
} else {
|
|
1352
|
-
const found = await Promise.all((positionals.length > 0 ? positionals : ["."]).map(async (dir) => toplevelOf(dir)));
|
|
1353
|
-
if (found.includes(undefined))
|
|
1354
|
-
fail(`not inside a git repository: ${(positionals.length > 0 ? positionals : ["."]).filter((_, at) => found[at] === undefined).join(", ")}`);
|
|
1355
|
-
dirs = [...new Set(found)];
|
|
1356
|
-
}
|
|
1357
|
-
if (dirs.length === 0)
|
|
1358
|
-
fail(`no git repository at or below ${positionals.length === 0 ? "the current directory" : positionals.join(", ")}`);
|
|
1622
|
+
const dirs = await dirsOf(positionals, values.repos === true);
|
|
1359
1623
|
const repos = await Promise.all(dirs.map(repoState));
|
|
1360
1624
|
const results = [];
|
|
1361
|
-
|
|
1625
|
+
const progress = progressLine();
|
|
1626
|
+
for (const [at, repo] of repos.entries()) {
|
|
1627
|
+
progress.update(repos.length > 1 ? { step: `pushing ${repo.path}`, done: at, total: repos.length, unit: "repositories" } : { step: `pushing ${repo.path}` });
|
|
1362
1628
|
results.push(await push(repo, { dryRun: values["dry-run"] === true, extra: rest }));
|
|
1629
|
+
}
|
|
1630
|
+
progress.stop();
|
|
1363
1631
|
if (values.json === true)
|
|
1364
1632
|
printJson(results);
|
|
1365
1633
|
else
|
|
1366
1634
|
console.log(table(results.map(line)));
|
|
1367
1635
|
return results.some((result) => result.outcome === "refused") ? 1 : 0;
|
|
1368
1636
|
}
|
|
1369
|
-
|
|
1637
|
+
process19.exitCode = await runMain({ name: "gp", run: main });
|