@kaynooo/cli-workspace 0.6.0 → 0.7.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/dist/audit-cli.js +60 -8
- package/dist/cli.js +128 -29
- package/dist/repos-cli.js +73 -18
- package/dist/sweep-cli.js +107 -11
- package/package.json +2 -2
package/dist/audit-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/audit-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -1466,11 +1466,63 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1466
1466
|
const suffix = match[2].toLowerCase();
|
|
1467
1467
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1468
1468
|
}
|
|
1469
|
+
// ../kit/src/watch.ts
|
|
1470
|
+
import process14 from "process";
|
|
1471
|
+
import { format } from "util";
|
|
1472
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1473
|
+
var DEFAULT_SECONDS = 2;
|
|
1474
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1475
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1476
|
+
function watchOption(what) {
|
|
1477
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1478
|
+
}
|
|
1479
|
+
function withoutWatch(args) {
|
|
1480
|
+
const rest = [];
|
|
1481
|
+
for (let at = 0;at < args.length; at++) {
|
|
1482
|
+
const arg = args[at];
|
|
1483
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1484
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1485
|
+
at++;
|
|
1486
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1487
|
+
rest.push(arg);
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
return rest;
|
|
1491
|
+
}
|
|
1492
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1493
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1494
|
+
if (!takesControlCodes(stream))
|
|
1495
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1496
|
+
let code = 0;
|
|
1497
|
+
for (let round = 0;round < rounds; round++) {
|
|
1498
|
+
const held = [];
|
|
1499
|
+
const { log, info } = console;
|
|
1500
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1501
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1502
|
+
`);
|
|
1503
|
+
console.log = hold;
|
|
1504
|
+
console.info = hold;
|
|
1505
|
+
process14.stdout.write = (text) => {
|
|
1506
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1507
|
+
return true;
|
|
1508
|
+
};
|
|
1509
|
+
try {
|
|
1510
|
+
code = await step();
|
|
1511
|
+
} finally {
|
|
1512
|
+
console.log = log;
|
|
1513
|
+
console.info = info;
|
|
1514
|
+
process14.stdout.write = write;
|
|
1515
|
+
}
|
|
1516
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1517
|
+
await sleep(interval);
|
|
1518
|
+
}
|
|
1519
|
+
return code;
|
|
1520
|
+
}
|
|
1469
1521
|
// ../kit/src/workspace-root.ts
|
|
1470
1522
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1471
1523
|
import { homedir as homedir4 } from "os";
|
|
1472
1524
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1473
|
-
import
|
|
1525
|
+
import process15 from "process";
|
|
1474
1526
|
function expandHome(path, home) {
|
|
1475
1527
|
if (path === "~")
|
|
1476
1528
|
return home;
|
|
@@ -1488,7 +1540,7 @@ function configured(env, home) {
|
|
|
1488
1540
|
return;
|
|
1489
1541
|
}
|
|
1490
1542
|
}
|
|
1491
|
-
function workspaceRoot({ given, env =
|
|
1543
|
+
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1492
1544
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1493
1545
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1494
1546
|
}
|
|
@@ -1496,7 +1548,7 @@ function workspaceRoot({ given, env = process14.env, home = homedir4() } = {}) {
|
|
|
1496
1548
|
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
|
|
1497
1549
|
import { readdir } from "fs/promises";
|
|
1498
1550
|
import { join as join8, relative, resolve as resolve4 } from "path";
|
|
1499
|
-
import
|
|
1551
|
+
import process17 from "process";
|
|
1500
1552
|
|
|
1501
1553
|
// src/report.ts
|
|
1502
1554
|
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
@@ -1708,7 +1760,7 @@ function failure(ran) {
|
|
|
1708
1760
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1709
1761
|
}
|
|
1710
1762
|
function tint(severity) {
|
|
1711
|
-
const colors = paint(
|
|
1763
|
+
const colors = paint(process17.stdout);
|
|
1712
1764
|
if (severity === "critical" || severity === "high")
|
|
1713
1765
|
return colors.red;
|
|
1714
1766
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1743,8 +1795,8 @@ async function audit(args) {
|
|
|
1743
1795
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1744
1796
|
}
|
|
1745
1797
|
function show(audits, total) {
|
|
1746
|
-
const label = role("label",
|
|
1747
|
-
const path = role("path",
|
|
1798
|
+
const label = role("label", process17.stdout);
|
|
1799
|
+
const path = role("path", process17.stdout);
|
|
1748
1800
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1749
1801
|
if (flagged.length === 0) {
|
|
1750
1802
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1764,4 +1816,4 @@ function show(audits, total) {
|
|
|
1764
1816
|
}
|
|
1765
1817
|
|
|
1766
1818
|
// src/audit-cli.ts
|
|
1767
|
-
|
|
1819
|
+
process18.exitCode = await runMain({ name: "audit", run: audit });
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process21 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -1477,11 +1477,63 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1477
1477
|
const suffix = match[2].toLowerCase();
|
|
1478
1478
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1479
1479
|
}
|
|
1480
|
+
// ../kit/src/watch.ts
|
|
1481
|
+
import process14 from "process";
|
|
1482
|
+
import { format } from "util";
|
|
1483
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1484
|
+
var DEFAULT_SECONDS = 2;
|
|
1485
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1486
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1487
|
+
function watchOption(what) {
|
|
1488
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1489
|
+
}
|
|
1490
|
+
function withoutWatch(args) {
|
|
1491
|
+
const rest = [];
|
|
1492
|
+
for (let at = 0;at < args.length; at++) {
|
|
1493
|
+
const arg = args[at];
|
|
1494
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1495
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1496
|
+
at++;
|
|
1497
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1498
|
+
rest.push(arg);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
return rest;
|
|
1502
|
+
}
|
|
1503
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1504
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1505
|
+
if (!takesControlCodes(stream))
|
|
1506
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1507
|
+
let code = 0;
|
|
1508
|
+
for (let round = 0;round < rounds; round++) {
|
|
1509
|
+
const held = [];
|
|
1510
|
+
const { log, info } = console;
|
|
1511
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1512
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1513
|
+
`);
|
|
1514
|
+
console.log = hold;
|
|
1515
|
+
console.info = hold;
|
|
1516
|
+
process14.stdout.write = (text) => {
|
|
1517
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1518
|
+
return true;
|
|
1519
|
+
};
|
|
1520
|
+
try {
|
|
1521
|
+
code = await step();
|
|
1522
|
+
} finally {
|
|
1523
|
+
console.log = log;
|
|
1524
|
+
console.info = info;
|
|
1525
|
+
process14.stdout.write = write;
|
|
1526
|
+
}
|
|
1527
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1528
|
+
await sleep(interval);
|
|
1529
|
+
}
|
|
1530
|
+
return code;
|
|
1531
|
+
}
|
|
1480
1532
|
// ../kit/src/workspace-root.ts
|
|
1481
1533
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1482
1534
|
import { homedir as homedir4 } from "os";
|
|
1483
1535
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1484
|
-
import
|
|
1536
|
+
import process15 from "process";
|
|
1485
1537
|
function expandHome(path, home) {
|
|
1486
1538
|
if (path === "~")
|
|
1487
1539
|
return home;
|
|
@@ -1499,7 +1551,7 @@ function configured(env, home) {
|
|
|
1499
1551
|
return;
|
|
1500
1552
|
}
|
|
1501
1553
|
}
|
|
1502
|
-
function workspaceRoot({ given, env =
|
|
1554
|
+
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1503
1555
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1504
1556
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1505
1557
|
}
|
|
@@ -1507,7 +1559,7 @@ function workspaceRoot({ given, env = process14.env, home = homedir4() } = {}) {
|
|
|
1507
1559
|
import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
|
|
1508
1560
|
import { readdir } from "fs/promises";
|
|
1509
1561
|
import { join as join8, relative, resolve as resolve4 } from "path";
|
|
1510
|
-
import
|
|
1562
|
+
import process17 from "process";
|
|
1511
1563
|
|
|
1512
1564
|
// src/report.ts
|
|
1513
1565
|
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
@@ -1719,7 +1771,7 @@ function failure(ran) {
|
|
|
1719
1771
|
`).at(-1) ?? `exit ${ran.code}`;
|
|
1720
1772
|
}
|
|
1721
1773
|
function tint(severity) {
|
|
1722
|
-
const colors = paint(
|
|
1774
|
+
const colors = paint(process17.stdout);
|
|
1723
1775
|
if (severity === "critical" || severity === "high")
|
|
1724
1776
|
return colors.red;
|
|
1725
1777
|
return severity === "moderate" ? colors.yellow : colors.dim;
|
|
@@ -1754,8 +1806,8 @@ async function audit(args) {
|
|
|
1754
1806
|
return kept.some((each) => each.findings.length > 0) ? 1 : 0;
|
|
1755
1807
|
}
|
|
1756
1808
|
function show(audits, total) {
|
|
1757
|
-
const label = role("label",
|
|
1758
|
-
const path = role("path",
|
|
1809
|
+
const label = role("label", process17.stdout);
|
|
1810
|
+
const path = role("path", process17.stdout);
|
|
1759
1811
|
const flagged = audits.filter((each) => each.error !== undefined || each.findings.length > 0);
|
|
1760
1812
|
if (flagged.length === 0) {
|
|
1761
1813
|
console.log(label(`no advisory in ${total} ${total === 1 ? "repository" : "repositories"}`));
|
|
@@ -1777,13 +1829,13 @@ function show(audits, total) {
|
|
|
1777
1829
|
// src/repos.ts
|
|
1778
1830
|
import { existsSync as existsSync8, statSync as statSync3 } from "fs";
|
|
1779
1831
|
import { relative as relative2 } from "path";
|
|
1780
|
-
import
|
|
1832
|
+
import process19 from "process";
|
|
1781
1833
|
|
|
1782
1834
|
// src/repos-scan.ts
|
|
1783
1835
|
import { existsSync as existsSync7 } from "fs";
|
|
1784
1836
|
import { readdir as readdir2 } from "fs/promises";
|
|
1785
1837
|
import { basename, join as join9 } from "path";
|
|
1786
|
-
import
|
|
1838
|
+
import process18 from "process";
|
|
1787
1839
|
var MAX_DEPTH2 = 3;
|
|
1788
1840
|
var CONCURRENCY2 = 8;
|
|
1789
1841
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1830,7 +1882,7 @@ async function findRepos2(root, skip) {
|
|
|
1830
1882
|
}
|
|
1831
1883
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1832
1884
|
try {
|
|
1833
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
1885
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process18.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
1834
1886
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1835
1887
|
} catch {
|
|
1836
1888
|
return;
|
|
@@ -1907,7 +1959,7 @@ function firstLine(text) {
|
|
|
1907
1959
|
}
|
|
1908
1960
|
async function fastForward(path) {
|
|
1909
1961
|
try {
|
|
1910
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
1962
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process18.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
1911
1963
|
if (ran.timedOut)
|
|
1912
1964
|
return "timed out";
|
|
1913
1965
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1928,8 +1980,9 @@ var EXITS2 = [[0, "it listed the repositories, including when none needs attenti
|
|
|
1928
1980
|
var OPTIONS2 = {
|
|
1929
1981
|
all: { type: "boolean", short: "a", description: "list the repositories with nothing to report too" },
|
|
1930
1982
|
only: { type: "string", choices: REASONS, description: "only the repositories with this reason: dirty, unpushed, unreleased or behind" },
|
|
1931
|
-
|
|
1932
|
-
|
|
1983
|
+
watch: watchOption("the repositories"),
|
|
1984
|
+
fetch: { type: "boolean", conflicts: ["watch"], description: "refresh the upstreams first (reaches the remote)" },
|
|
1985
|
+
pull: { type: "boolean", conflicts: ["watch"], description: "fetch, then fast-forward the clean repositories listed that are only behind their upstream (reaches the remote)" },
|
|
1933
1986
|
path: { type: "boolean", conflicts: ["json"], description: "print only the paths of the repositories listed, one per line" },
|
|
1934
1987
|
json: jsonOption("[{name, path, branch, upstream, dirty, ahead, behind, worktrees, tag, unreleased, packages, reasons, fetchFailed, unreadable}]")
|
|
1935
1988
|
};
|
|
@@ -1949,7 +2002,7 @@ function releasedCell(repo) {
|
|
|
1949
2002
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1950
2003
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1951
2004
|
}
|
|
1952
|
-
function syncCell(repo, stream =
|
|
2005
|
+
function syncCell(repo, stream = process19.stdout) {
|
|
1953
2006
|
const colors = paint(stream);
|
|
1954
2007
|
const ahead = repo.ahead ?? 0;
|
|
1955
2008
|
const behind = repo.behind ?? 0;
|
|
@@ -1960,7 +2013,7 @@ function syncCell(repo, stream = process18.stdout) {
|
|
|
1960
2013
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1961
2014
|
}
|
|
1962
2015
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1963
|
-
function branchCell(repo, stream =
|
|
2016
|
+
function branchCell(repo, stream = process19.stdout) {
|
|
1964
2017
|
const colors = paint(stream);
|
|
1965
2018
|
if (repo.unreadable)
|
|
1966
2019
|
return colors.red("? (unreadable)");
|
|
@@ -1969,8 +2022,8 @@ function branchCell(repo, stream = process18.stdout) {
|
|
|
1969
2022
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1970
2023
|
}
|
|
1971
2024
|
function row(repo, shown) {
|
|
1972
|
-
const colors = paint(
|
|
1973
|
-
const tint = role("path",
|
|
2025
|
+
const colors = paint(process19.stdout);
|
|
2026
|
+
const tint = role("path", process19.stdout);
|
|
1974
2027
|
const unreleased = releasedCell(repo);
|
|
1975
2028
|
return [
|
|
1976
2029
|
tint(shown),
|
|
@@ -1983,6 +2036,8 @@ function row(repo, shown) {
|
|
|
1983
2036
|
}
|
|
1984
2037
|
async function repos(args) {
|
|
1985
2038
|
const { values, positionals } = parse(args, USAGE2, OPTIONS2, { positionals: ["[root]"], exits: EXITS2, replaces: "a cd, git status, git log and git tag loop over each repository of the workspace", examples: ["repos", "repos ~/Workspace --only unreleased --fetch", ["repos --only behind --pull", "fast-forward what is behind and clean"], ["repos --only dirty --path", "the paths, for xargs"]] });
|
|
2039
|
+
if (values.watch !== undefined)
|
|
2040
|
+
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
1986
2041
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1987
2042
|
if (!existsSync8(root) || !statSync3(root).isDirectory())
|
|
1988
2043
|
fail(`no folder ${root}`);
|
|
@@ -2002,12 +2057,12 @@ async function repos(args) {
|
|
|
2002
2057
|
const blocker = pullBlocker(repo);
|
|
2003
2058
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
2004
2059
|
if (blocker !== undefined) {
|
|
2005
|
-
log(marked("note", `${repo.name} skipped`,
|
|
2060
|
+
log(marked("note", `${repo.name} skipped`, process19.stdout, blocker));
|
|
2006
2061
|
} else if (refused !== undefined) {
|
|
2007
2062
|
failedPulls++;
|
|
2008
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
2063
|
+
log(marked("problem", `${repo.name} not pulled`, process19.stdout, refused));
|
|
2009
2064
|
} else {
|
|
2010
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
2065
|
+
log(marked("ok", `${repo.name} pulled`, process19.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
2011
2066
|
states[index] = await inspect(repo.path, false);
|
|
2012
2067
|
}
|
|
2013
2068
|
}
|
|
@@ -2022,7 +2077,7 @@ async function repos(args) {
|
|
|
2022
2077
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
2023
2078
|
return failedPulls > 0 ? 1 : 0;
|
|
2024
2079
|
}
|
|
2025
|
-
const label = role("label",
|
|
2080
|
+
const label = role("label", process19.stdout);
|
|
2026
2081
|
if (kept.length === 0) {
|
|
2027
2082
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
2028
2083
|
return failedPulls > 0 ? 1 : 0;
|
|
@@ -2042,14 +2097,50 @@ import { homedir as homedir6 } from "os";
|
|
|
2042
2097
|
import { relative as relative3 } from "path";
|
|
2043
2098
|
|
|
2044
2099
|
// ../kit/src/prompt.ts
|
|
2045
|
-
import
|
|
2046
|
-
|
|
2047
|
-
|
|
2100
|
+
import process20 from "process";
|
|
2101
|
+
|
|
2102
|
+
// ../kit/src/picker/score.ts
|
|
2103
|
+
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
2104
|
+
var NONE = Number.NEGATIVE_INFINITY;
|
|
2105
|
+
|
|
2106
|
+
// ../kit/src/picker/state.ts
|
|
2107
|
+
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
2048
2108
|
var PASTE_START = "\x1B[200~";
|
|
2049
2109
|
var PASTE_END = "\x1B[201~";
|
|
2050
|
-
var
|
|
2051
|
-
|
|
2110
|
+
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
2111
|
+
var KEYS = {
|
|
2112
|
+
"\x1B[A": "up",
|
|
2113
|
+
"\x1BOA": "up",
|
|
2114
|
+
"\x10": "up",
|
|
2115
|
+
"\x1B[B": "down",
|
|
2116
|
+
"\x1BOB": "down",
|
|
2117
|
+
"\x0E": "down",
|
|
2118
|
+
"\x1B[5~": "pageup",
|
|
2119
|
+
"\x1B[6~": "pagedown",
|
|
2120
|
+
"\x1B[H": "home",
|
|
2121
|
+
"\x1B[1~": "home",
|
|
2122
|
+
"\x1BOH": "home",
|
|
2123
|
+
"\x1B[F": "end",
|
|
2124
|
+
"\x1B[4~": "end",
|
|
2125
|
+
"\x1BOF": "end",
|
|
2126
|
+
"\r": "enter",
|
|
2127
|
+
"\n": "enter",
|
|
2128
|
+
"\x03": "cancel",
|
|
2129
|
+
"\x1B": "cancel",
|
|
2130
|
+
"\x7F": "erase",
|
|
2131
|
+
"\b": "erase",
|
|
2132
|
+
"\x15": "clear",
|
|
2133
|
+
"\x17": "word",
|
|
2134
|
+
"\t": "tab",
|
|
2135
|
+
"\x1F": "help",
|
|
2136
|
+
"\x1BOP": "help",
|
|
2137
|
+
"\x1B[11~": "help"
|
|
2138
|
+
};
|
|
2139
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
2140
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
2052
2141
|
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
2142
|
+
const named = codes.get(sequence);
|
|
2143
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
2053
2144
|
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
2054
2145
|
paste.active = sequence === PASTE_START;
|
|
2055
2146
|
return [];
|
|
@@ -2057,9 +2148,17 @@ function readKeys(input, paste = { active: false }) {
|
|
|
2057
2148
|
if (paste.active && (sequence === "\r" || sequence === `
|
|
2058
2149
|
`))
|
|
2059
2150
|
return [];
|
|
2060
|
-
|
|
2151
|
+
if (key !== undefined)
|
|
2152
|
+
return [key];
|
|
2153
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
2061
2154
|
});
|
|
2062
2155
|
}
|
|
2156
|
+
|
|
2157
|
+
// ../kit/src/prompt.ts
|
|
2158
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "erase"]);
|
|
2159
|
+
function readKeys(input, paste = { active: false }) {
|
|
2160
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
2161
|
+
}
|
|
2063
2162
|
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
2064
2163
|
let answered = fallback;
|
|
2065
2164
|
const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
|
|
@@ -2082,7 +2181,7 @@ function asking(colors, question, typed, keys) {
|
|
|
2082
2181
|
function answer(colors, question, state, picked) {
|
|
2083
2182
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2084
2183
|
}
|
|
2085
|
-
async function ask(question, { hint, terminal =
|
|
2184
|
+
async function ask(question, { hint, terminal = process20 }, render, press) {
|
|
2086
2185
|
const { stdin, stderr } = terminal;
|
|
2087
2186
|
if (!isInteractive(terminal))
|
|
2088
2187
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -2563,7 +2662,7 @@ ${$e(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2563
2662
|
}
|
|
2564
2663
|
|
|
2565
2664
|
// src/cli.ts
|
|
2566
|
-
|
|
2665
|
+
process21.exitCode = await runCli({
|
|
2567
2666
|
name: "ws",
|
|
2568
2667
|
about: "the repositories under a root: the ones needing attention, the folders worth reclaiming and their known vulnerabilities",
|
|
2569
2668
|
replaces: "a cd, git status and du loop over each repository of the workspace, and a bun audit run in each",
|
package/dist/repos-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/repos-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process19 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -1466,11 +1466,63 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1466
1466
|
const suffix = match[2].toLowerCase();
|
|
1467
1467
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1468
1468
|
}
|
|
1469
|
+
// ../kit/src/watch.ts
|
|
1470
|
+
import process14 from "process";
|
|
1471
|
+
import { format } from "util";
|
|
1472
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1473
|
+
var DEFAULT_SECONDS = 2;
|
|
1474
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1475
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1476
|
+
function watchOption(what) {
|
|
1477
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1478
|
+
}
|
|
1479
|
+
function withoutWatch(args) {
|
|
1480
|
+
const rest = [];
|
|
1481
|
+
for (let at = 0;at < args.length; at++) {
|
|
1482
|
+
const arg = args[at];
|
|
1483
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1484
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1485
|
+
at++;
|
|
1486
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1487
|
+
rest.push(arg);
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
return rest;
|
|
1491
|
+
}
|
|
1492
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1493
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1494
|
+
if (!takesControlCodes(stream))
|
|
1495
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1496
|
+
let code = 0;
|
|
1497
|
+
for (let round = 0;round < rounds; round++) {
|
|
1498
|
+
const held = [];
|
|
1499
|
+
const { log, info } = console;
|
|
1500
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1501
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1502
|
+
`);
|
|
1503
|
+
console.log = hold;
|
|
1504
|
+
console.info = hold;
|
|
1505
|
+
process14.stdout.write = (text) => {
|
|
1506
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1507
|
+
return true;
|
|
1508
|
+
};
|
|
1509
|
+
try {
|
|
1510
|
+
code = await step();
|
|
1511
|
+
} finally {
|
|
1512
|
+
console.log = log;
|
|
1513
|
+
console.info = info;
|
|
1514
|
+
process14.stdout.write = write;
|
|
1515
|
+
}
|
|
1516
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1517
|
+
await sleep(interval);
|
|
1518
|
+
}
|
|
1519
|
+
return code;
|
|
1520
|
+
}
|
|
1469
1521
|
// ../kit/src/workspace-root.ts
|
|
1470
1522
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1471
1523
|
import { homedir as homedir4 } from "os";
|
|
1472
1524
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1473
|
-
import
|
|
1525
|
+
import process15 from "process";
|
|
1474
1526
|
function expandHome(path, home) {
|
|
1475
1527
|
if (path === "~")
|
|
1476
1528
|
return home;
|
|
@@ -1488,20 +1540,20 @@ function configured(env, home) {
|
|
|
1488
1540
|
return;
|
|
1489
1541
|
}
|
|
1490
1542
|
}
|
|
1491
|
-
function workspaceRoot({ given, env =
|
|
1543
|
+
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1492
1544
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1493
1545
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1494
1546
|
}
|
|
1495
1547
|
// src/repos.ts
|
|
1496
1548
|
import { existsSync as existsSync6, statSync as statSync2 } from "fs";
|
|
1497
1549
|
import { relative } from "path";
|
|
1498
|
-
import
|
|
1550
|
+
import process18 from "process";
|
|
1499
1551
|
|
|
1500
1552
|
// src/repos-scan.ts
|
|
1501
1553
|
import { existsSync as existsSync5 } from "fs";
|
|
1502
1554
|
import { readdir } from "fs/promises";
|
|
1503
1555
|
import { basename, join as join7 } from "path";
|
|
1504
|
-
import
|
|
1556
|
+
import process17 from "process";
|
|
1505
1557
|
var MAX_DEPTH = 3;
|
|
1506
1558
|
var CONCURRENCY = 8;
|
|
1507
1559
|
var PACKAGE_CONCURRENCY = 4;
|
|
@@ -1548,7 +1600,7 @@ async function findRepos(root, skip) {
|
|
|
1548
1600
|
}
|
|
1549
1601
|
async function read(path, args, timeoutMs = GIT_MS) {
|
|
1550
1602
|
try {
|
|
1551
|
-
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...
|
|
1603
|
+
const ran = await runCommand(["git", "--no-optional-locks", ...args], { cwd: path, env: { ...process17.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs });
|
|
1552
1604
|
return ran.code === 0 && !ran.timedOut ? ran.text.trim() : undefined;
|
|
1553
1605
|
} catch {
|
|
1554
1606
|
return;
|
|
@@ -1625,7 +1677,7 @@ function firstLine(text) {
|
|
|
1625
1677
|
}
|
|
1626
1678
|
async function fastForward(path) {
|
|
1627
1679
|
try {
|
|
1628
|
-
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...
|
|
1680
|
+
const ran = await runCommand(["git", "--no-optional-locks", "merge", "--ff-only", "--quiet", "@{upstream}"], { cwd: path, env: { ...process17.env, GIT_TERMINAL_PROMPT: "0" }, timeoutMs: GIT_MS });
|
|
1629
1681
|
if (ran.timedOut)
|
|
1630
1682
|
return "timed out";
|
|
1631
1683
|
return ran.code === 0 ? undefined : firstLine(ran.text.trim()) || `exit ${ran.code}`;
|
|
@@ -1646,8 +1698,9 @@ var EXITS = [[0, "it listed the repositories, including when none needs attentio
|
|
|
1646
1698
|
var OPTIONS = {
|
|
1647
1699
|
all: { type: "boolean", short: "a", description: "list the repositories with nothing to report too" },
|
|
1648
1700
|
only: { type: "string", choices: REASONS, description: "only the repositories with this reason: dirty, unpushed, unreleased or behind" },
|
|
1649
|
-
|
|
1650
|
-
|
|
1701
|
+
watch: watchOption("the repositories"),
|
|
1702
|
+
fetch: { type: "boolean", conflicts: ["watch"], description: "refresh the upstreams first (reaches the remote)" },
|
|
1703
|
+
pull: { type: "boolean", conflicts: ["watch"], description: "fetch, then fast-forward the clean repositories listed that are only behind their upstream (reaches the remote)" },
|
|
1651
1704
|
path: { type: "boolean", conflicts: ["json"], description: "print only the paths of the repositories listed, one per line" },
|
|
1652
1705
|
json: jsonOption("[{name, path, branch, upstream, dirty, ahead, behind, worktrees, tag, unreleased, packages, reasons, fetchFailed, unreadable}]")
|
|
1653
1706
|
};
|
|
@@ -1667,7 +1720,7 @@ function releasedCell(repo) {
|
|
|
1667
1720
|
return repo.packages.filter((release) => release.unreleased > 0).map((release) => `${release.name} ${release.unreleased}`).join(", ") || "-";
|
|
1668
1721
|
return repo.tag === null || repo.unreleased === 0 ? "-" : `${repo.unreleased} since ${repo.tag}`;
|
|
1669
1722
|
}
|
|
1670
|
-
function syncCell(repo, stream =
|
|
1723
|
+
function syncCell(repo, stream = process18.stdout) {
|
|
1671
1724
|
const colors = paint(stream);
|
|
1672
1725
|
const ahead = repo.ahead ?? 0;
|
|
1673
1726
|
const behind = repo.behind ?? 0;
|
|
@@ -1678,7 +1731,7 @@ function syncCell(repo, stream = process17.stdout) {
|
|
|
1678
1731
|
return parts.length === 0 ? colors.dim("-") : `${parts.join(" ")}${diverged ? colors.yellow(" diverged") : ""}`;
|
|
1679
1732
|
}
|
|
1680
1733
|
var DEFAULT_BRANCHES = new Set(["main", "master"]);
|
|
1681
|
-
function branchCell(repo, stream =
|
|
1734
|
+
function branchCell(repo, stream = process18.stdout) {
|
|
1682
1735
|
const colors = paint(stream);
|
|
1683
1736
|
if (repo.unreadable)
|
|
1684
1737
|
return colors.red("? (unreadable)");
|
|
@@ -1687,8 +1740,8 @@ function branchCell(repo, stream = process17.stdout) {
|
|
|
1687
1740
|
return DEFAULT_BRANCHES.has(repo.branch) ? repo.branch : role("accent", stream)(repo.branch);
|
|
1688
1741
|
}
|
|
1689
1742
|
function row(repo, shown) {
|
|
1690
|
-
const colors = paint(
|
|
1691
|
-
const tint = role("path",
|
|
1743
|
+
const colors = paint(process18.stdout);
|
|
1744
|
+
const tint = role("path", process18.stdout);
|
|
1692
1745
|
const unreleased = releasedCell(repo);
|
|
1693
1746
|
return [
|
|
1694
1747
|
tint(shown),
|
|
@@ -1701,6 +1754,8 @@ function row(repo, shown) {
|
|
|
1701
1754
|
}
|
|
1702
1755
|
async function repos(args) {
|
|
1703
1756
|
const { values, positionals } = parse(args, USAGE, OPTIONS, { positionals: ["[root]"], exits: EXITS, replaces: "a cd, git status, git log and git tag loop over each repository of the workspace", examples: ["repos", "repos ~/Workspace --only unreleased --fetch", ["repos --only behind --pull", "fast-forward what is behind and clean"], ["repos --only dirty --path", "the paths, for xargs"]] });
|
|
1757
|
+
if (values.watch !== undefined)
|
|
1758
|
+
return watching(values.watch, async () => repos(withoutWatch(args)));
|
|
1704
1759
|
const root = workspaceRoot({ given: positionals[0] });
|
|
1705
1760
|
if (!existsSync6(root) || !statSync2(root).isDirectory())
|
|
1706
1761
|
fail(`no folder ${root}`);
|
|
@@ -1720,12 +1775,12 @@ async function repos(args) {
|
|
|
1720
1775
|
const blocker = pullBlocker(repo);
|
|
1721
1776
|
const refused = blocker === undefined ? await fastForward(repo.path) : undefined;
|
|
1722
1777
|
if (blocker !== undefined) {
|
|
1723
|
-
log(marked("note", `${repo.name} skipped`,
|
|
1778
|
+
log(marked("note", `${repo.name} skipped`, process18.stdout, blocker));
|
|
1724
1779
|
} else if (refused !== undefined) {
|
|
1725
1780
|
failedPulls++;
|
|
1726
|
-
log(marked("problem", `${repo.name} not pulled`,
|
|
1781
|
+
log(marked("problem", `${repo.name} not pulled`, process18.stdout, refused));
|
|
1727
1782
|
} else {
|
|
1728
|
-
log(marked("ok", `${repo.name} pulled`,
|
|
1783
|
+
log(marked("ok", `${repo.name} pulled`, process18.stdout, `${repo.behind} ${repo.behind === 1 ? "commit" : "commits"}`));
|
|
1729
1784
|
states[index] = await inspect(repo.path, false);
|
|
1730
1785
|
}
|
|
1731
1786
|
}
|
|
@@ -1740,7 +1795,7 @@ async function repos(args) {
|
|
|
1740
1795
|
printJson(kept.map((repo) => ({ ...repo, reasons: reasonsOf(repo) })));
|
|
1741
1796
|
return failedPulls > 0 ? 1 : 0;
|
|
1742
1797
|
}
|
|
1743
|
-
const label = role("label",
|
|
1798
|
+
const label = role("label", process18.stdout);
|
|
1744
1799
|
if (kept.length === 0) {
|
|
1745
1800
|
console.log(label(`nothing needs attention in ${states.length} repositories`));
|
|
1746
1801
|
return failedPulls > 0 ? 1 : 0;
|
|
@@ -1755,4 +1810,4 @@ async function repos(args) {
|
|
|
1755
1810
|
}
|
|
1756
1811
|
|
|
1757
1812
|
// src/repos-cli.ts
|
|
1758
|
-
|
|
1813
|
+
process19.exitCode = await runMain({ name: "repos", run: repos });
|
package/dist/sweep-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/sweep-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/advisory.ts
|
|
8
8
|
var SEVERITIES = ["low", "moderate", "high", "critical"];
|
|
@@ -1477,11 +1477,63 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1477
1477
|
const suffix = match[2].toLowerCase();
|
|
1478
1478
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1479
1479
|
}
|
|
1480
|
+
// ../kit/src/watch.ts
|
|
1481
|
+
import process14 from "process";
|
|
1482
|
+
import { format } from "util";
|
|
1483
|
+
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1484
|
+
var DEFAULT_SECONDS = 2;
|
|
1485
|
+
var ATTACHED_SHORT = /^-w./;
|
|
1486
|
+
var INTERVAL = /^\d+(?:\.\d+)?(?:ms|[smh])?$/;
|
|
1487
|
+
function watchOption(what) {
|
|
1488
|
+
return { type: "string", short: "w", optional: { bare: "", accepts: INTERVAL }, description: `redraw ${what} every 2s, or every interval given (500ms, 5s), until ctrl-c` };
|
|
1489
|
+
}
|
|
1490
|
+
function withoutWatch(args) {
|
|
1491
|
+
const rest = [];
|
|
1492
|
+
for (let at = 0;at < args.length; at++) {
|
|
1493
|
+
const arg = args[at];
|
|
1494
|
+
if (arg === "--watch" || arg === "-w") {
|
|
1495
|
+
if (args[at + 1] !== undefined && INTERVAL.test(args[at + 1]))
|
|
1496
|
+
at++;
|
|
1497
|
+
} else if (!arg.startsWith("--watch=") && !ATTACHED_SHORT.test(arg)) {
|
|
1498
|
+
rest.push(arg);
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
return rest;
|
|
1502
|
+
}
|
|
1503
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1504
|
+
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1505
|
+
if (!takesControlCodes(stream))
|
|
1506
|
+
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
1507
|
+
let code = 0;
|
|
1508
|
+
for (let round = 0;round < rounds; round++) {
|
|
1509
|
+
const held = [];
|
|
1510
|
+
const { log, info } = console;
|
|
1511
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1512
|
+
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1513
|
+
`);
|
|
1514
|
+
console.log = hold;
|
|
1515
|
+
console.info = hold;
|
|
1516
|
+
process14.stdout.write = (text) => {
|
|
1517
|
+
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1518
|
+
return true;
|
|
1519
|
+
};
|
|
1520
|
+
try {
|
|
1521
|
+
code = await step();
|
|
1522
|
+
} finally {
|
|
1523
|
+
console.log = log;
|
|
1524
|
+
console.info = info;
|
|
1525
|
+
process14.stdout.write = write;
|
|
1526
|
+
}
|
|
1527
|
+
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1528
|
+
await sleep(interval);
|
|
1529
|
+
}
|
|
1530
|
+
return code;
|
|
1531
|
+
}
|
|
1480
1532
|
// ../kit/src/workspace-root.ts
|
|
1481
1533
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
1482
1534
|
import { homedir as homedir4 } from "os";
|
|
1483
1535
|
import { dirname as dirname4, join as join6, resolve as resolve3 } from "path";
|
|
1484
|
-
import
|
|
1536
|
+
import process15 from "process";
|
|
1485
1537
|
function expandHome(path, home) {
|
|
1486
1538
|
if (path === "~")
|
|
1487
1539
|
return home;
|
|
@@ -1499,7 +1551,7 @@ function configured(env, home) {
|
|
|
1499
1551
|
return;
|
|
1500
1552
|
}
|
|
1501
1553
|
}
|
|
1502
|
-
function workspaceRoot({ given, env =
|
|
1554
|
+
function workspaceRoot({ given, env = process15.env, home = homedir4() } = {}) {
|
|
1503
1555
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1504
1556
|
return resolve3(expandHome(given ?? fromEnv ?? configured(env, home) ?? join6(home, "Workspace"), home));
|
|
1505
1557
|
}
|
|
@@ -1509,14 +1561,50 @@ import { homedir as homedir6 } from "os";
|
|
|
1509
1561
|
import { relative } from "path";
|
|
1510
1562
|
|
|
1511
1563
|
// ../kit/src/prompt.ts
|
|
1512
|
-
import
|
|
1513
|
-
|
|
1514
|
-
|
|
1564
|
+
import process17 from "process";
|
|
1565
|
+
|
|
1566
|
+
// ../kit/src/picker/score.ts
|
|
1567
|
+
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1568
|
+
var NONE = Number.NEGATIVE_INFINITY;
|
|
1569
|
+
|
|
1570
|
+
// ../kit/src/picker/state.ts
|
|
1571
|
+
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1515
1572
|
var PASTE_START = "\x1B[200~";
|
|
1516
1573
|
var PASTE_END = "\x1B[201~";
|
|
1517
|
-
var
|
|
1518
|
-
|
|
1574
|
+
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1575
|
+
var KEYS = {
|
|
1576
|
+
"\x1B[A": "up",
|
|
1577
|
+
"\x1BOA": "up",
|
|
1578
|
+
"\x10": "up",
|
|
1579
|
+
"\x1B[B": "down",
|
|
1580
|
+
"\x1BOB": "down",
|
|
1581
|
+
"\x0E": "down",
|
|
1582
|
+
"\x1B[5~": "pageup",
|
|
1583
|
+
"\x1B[6~": "pagedown",
|
|
1584
|
+
"\x1B[H": "home",
|
|
1585
|
+
"\x1B[1~": "home",
|
|
1586
|
+
"\x1BOH": "home",
|
|
1587
|
+
"\x1B[F": "end",
|
|
1588
|
+
"\x1B[4~": "end",
|
|
1589
|
+
"\x1BOF": "end",
|
|
1590
|
+
"\r": "enter",
|
|
1591
|
+
"\n": "enter",
|
|
1592
|
+
"\x03": "cancel",
|
|
1593
|
+
"\x1B": "cancel",
|
|
1594
|
+
"\x7F": "erase",
|
|
1595
|
+
"\b": "erase",
|
|
1596
|
+
"\x15": "clear",
|
|
1597
|
+
"\x17": "word",
|
|
1598
|
+
"\t": "tab",
|
|
1599
|
+
"\x1F": "help",
|
|
1600
|
+
"\x1BOP": "help",
|
|
1601
|
+
"\x1B[11~": "help"
|
|
1602
|
+
};
|
|
1603
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1604
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1519
1605
|
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1606
|
+
const named = codes.get(sequence);
|
|
1607
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1520
1608
|
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1521
1609
|
paste.active = sequence === PASTE_START;
|
|
1522
1610
|
return [];
|
|
@@ -1524,9 +1612,17 @@ function readKeys(input, paste = { active: false }) {
|
|
|
1524
1612
|
if (paste.active && (sequence === "\r" || sequence === `
|
|
1525
1613
|
`))
|
|
1526
1614
|
return [];
|
|
1527
|
-
|
|
1615
|
+
if (key !== undefined)
|
|
1616
|
+
return [key];
|
|
1617
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1528
1618
|
});
|
|
1529
1619
|
}
|
|
1620
|
+
|
|
1621
|
+
// ../kit/src/prompt.ts
|
|
1622
|
+
var PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "erase"]);
|
|
1623
|
+
function readKeys(input, paste = { active: false }) {
|
|
1624
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key));
|
|
1625
|
+
}
|
|
1530
1626
|
async function confirm(question, { default: fallback, ...settings } = {}) {
|
|
1531
1627
|
let answered = fallback;
|
|
1532
1628
|
const choices = { true: "Y/n", false: "y/N", undefined: "y/n" }[String(fallback)];
|
|
@@ -1549,7 +1645,7 @@ function asking(colors, question, typed, keys) {
|
|
|
1549
1645
|
function answer(colors, question, state, picked) {
|
|
1550
1646
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1551
1647
|
}
|
|
1552
|
-
async function ask(question, { hint, terminal =
|
|
1648
|
+
async function ask(question, { hint, terminal = process17 }, render, press) {
|
|
1553
1649
|
const { stdin, stderr } = terminal;
|
|
1554
1650
|
if (!isInteractive(terminal))
|
|
1555
1651
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -2030,4 +2126,4 @@ ${$e(reclaimable)} reclaimable${skipped === 0 ? "" : `, ${skipped} skipped (syml
|
|
|
2030
2126
|
}
|
|
2031
2127
|
|
|
2032
2128
|
// src/sweep-cli.ts
|
|
2033
|
-
|
|
2129
|
+
process18.exitCode = await runMain({ name: "sweep", run: sweep });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-workspace",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"description": "ws, repos, sweep, audit: the repositories of the workspace that need attention, the folders worth reclaiming and their known vulnerabilities.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"audit": "$npm_execpath src/audit-cli.ts"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@kaynooo/cli-kit": "0.
|
|
37
|
+
"@kaynooo/cli-kit": "0.26.0"
|
|
38
38
|
}
|
|
39
39
|
}
|