@kaynooo/cli-stack 0.4.1 → 0.5.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/dist/cli.js +112 -71
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
1
|
+
#!/usr/bin/env -S bun --no-env-file
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
5
|
import process10 from "process";
|
|
6
|
-
|
|
7
6
|
// ../kit/src/args.ts
|
|
8
|
-
import
|
|
7
|
+
import process4 from "process";
|
|
9
8
|
import { parseArgs } from "util";
|
|
10
9
|
|
|
11
10
|
// ../kit/src/style.ts
|
|
12
|
-
import
|
|
11
|
+
import process2 from "process";
|
|
13
12
|
|
|
14
13
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
15
14
|
function x(s) {
|
|
@@ -279,13 +278,13 @@ var MARKS = {
|
|
|
279
278
|
problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
|
|
280
279
|
note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
|
|
281
280
|
};
|
|
282
|
-
function takesControlCodes(stream, env =
|
|
281
|
+
function takesControlCodes(stream, env = process2.env) {
|
|
283
282
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
284
283
|
}
|
|
285
|
-
function paint(stream, env =
|
|
284
|
+
function paint(stream, env = process2.env) {
|
|
286
285
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
287
286
|
}
|
|
288
|
-
function marked(mark, text, stream, detail, env =
|
|
287
|
+
function marked(mark, text, stream, detail, env = process2.env) {
|
|
289
288
|
const colors = paint(stream, env);
|
|
290
289
|
const { symbol, word, paint: tint } = MARKS[mark];
|
|
291
290
|
const head = takesControlCodes(stream, env) ? tint(colors)(symbol) : word;
|
|
@@ -311,24 +310,30 @@ function printJson(value) {
|
|
|
311
310
|
}
|
|
312
311
|
|
|
313
312
|
// ../kit/src/help.ts
|
|
314
|
-
import
|
|
313
|
+
import process3 from "process";
|
|
315
314
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
316
315
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
317
316
|
var FULL_STOP = /\.$/;
|
|
318
|
-
function usageLine(usage, colors = paint(
|
|
317
|
+
function usageLine(usage, colors = paint(process3.stdout)) {
|
|
319
318
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
320
319
|
}
|
|
321
|
-
function helpText(usage, options, colors = paint(
|
|
322
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
320
|
+
function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
321
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
323
322
|
`);
|
|
324
323
|
}
|
|
325
|
-
function
|
|
324
|
+
function exitRows(exits, colors = paint(process3.stdout)) {
|
|
325
|
+
if (exits.length === 0)
|
|
326
|
+
return [];
|
|
327
|
+
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
328
|
+
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
329
|
+
}
|
|
330
|
+
function replacesRows(replaces, colors = paint(process3.stdout)) {
|
|
326
331
|
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
327
332
|
}
|
|
328
|
-
function wantsHelpJson(env =
|
|
333
|
+
function wantsHelpJson(env = process3.env) {
|
|
329
334
|
return env.KIT_HELP === "json";
|
|
330
335
|
}
|
|
331
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
336
|
+
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
332
337
|
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
333
338
|
`);
|
|
334
339
|
const first = lines[0];
|
|
@@ -339,15 +344,17 @@ function description(usage, { examples = [], replaces } = {}) {
|
|
|
339
344
|
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
340
345
|
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
341
346
|
...replaces === undefined ? {} : { replaces },
|
|
342
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
347
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
348
|
+
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
349
|
+
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
343
350
|
};
|
|
344
351
|
}
|
|
345
|
-
function exampleRows(examples, colors = paint(
|
|
352
|
+
function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
346
353
|
if (examples.length === 0)
|
|
347
354
|
return [];
|
|
348
355
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
349
356
|
}
|
|
350
|
-
function optionRows(options, colors = paint(
|
|
357
|
+
function optionRows(options, colors = paint(process3.stdout)) {
|
|
351
358
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
352
359
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
353
360
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -438,7 +445,7 @@ var OUTPUT_OPTIONS = {
|
|
|
438
445
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
439
446
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
440
447
|
};
|
|
441
|
-
function applyOutput(color, plain, env =
|
|
448
|
+
function applyOutput(color, plain, env = process4.env) {
|
|
442
449
|
const when = plain === true ? "never" : color ?? "auto";
|
|
443
450
|
if (when === "auto")
|
|
444
451
|
return;
|
|
@@ -461,7 +468,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
461
468
|
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
462
469
|
let parsed;
|
|
463
470
|
try {
|
|
464
|
-
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
471
|
+
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
465
472
|
} catch (error) {
|
|
466
473
|
const message = parseError(error);
|
|
467
474
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -469,7 +476,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
469
476
|
const values = parsed.values;
|
|
470
477
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
471
478
|
if (values.help === true) {
|
|
472
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
479
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
473
480
|
throw new HelpShown;
|
|
474
481
|
}
|
|
475
482
|
checkChoices(parsed.values, all);
|
|
@@ -511,6 +518,18 @@ function listed(options, allowNegative) {
|
|
|
511
518
|
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
512
519
|
}));
|
|
513
520
|
}
|
|
521
|
+
function withAliases(args, options) {
|
|
522
|
+
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
523
|
+
if (named.size === 0)
|
|
524
|
+
return args;
|
|
525
|
+
const separator = args.indexOf("--");
|
|
526
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
527
|
+
return [...own.map((arg) => {
|
|
528
|
+
const at = arg.indexOf("=");
|
|
529
|
+
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
530
|
+
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
531
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
532
|
+
}
|
|
514
533
|
function withBare(args, options) {
|
|
515
534
|
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
516
535
|
if (bare.size === 0)
|
|
@@ -601,13 +620,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
601
620
|
var RESET_STYLE = `${ESC}[0m`;
|
|
602
621
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
603
622
|
// ../kit/src/cli.ts
|
|
604
|
-
import
|
|
623
|
+
import { readFileSync, realpathSync } from "fs";
|
|
624
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
625
|
+
import process6 from "process";
|
|
605
626
|
|
|
606
627
|
// ../kit/src/usage.ts
|
|
607
628
|
import { appendFileSync, mkdirSync } from "fs";
|
|
608
629
|
import { homedir } from "os";
|
|
609
630
|
import { dirname, isAbsolute, join } from "path";
|
|
610
|
-
import
|
|
631
|
+
import process5 from "process";
|
|
611
632
|
|
|
612
633
|
// ../kit/src/logs.ts
|
|
613
634
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -621,14 +642,14 @@ var usageError;
|
|
|
621
642
|
function noteUsageError(message) {
|
|
622
643
|
usageError = message;
|
|
623
644
|
}
|
|
624
|
-
function stateHome(env =
|
|
645
|
+
function stateHome(env = process5.env) {
|
|
625
646
|
const dir = env.XDG_STATE_HOME;
|
|
626
647
|
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
627
648
|
}
|
|
628
|
-
function usagePath(env =
|
|
649
|
+
function usagePath(env = process5.env) {
|
|
629
650
|
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
630
651
|
}
|
|
631
|
-
function usageRecorded(env =
|
|
652
|
+
function usageRecorded(env = process5.env) {
|
|
632
653
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
633
654
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
634
655
|
}
|
|
@@ -642,7 +663,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
642
663
|
usageError = undefined;
|
|
643
664
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
644
665
|
}
|
|
645
|
-
function recordUsage(entry, env =
|
|
666
|
+
function recordUsage(entry, env = process5.env) {
|
|
646
667
|
if (!usageRecorded(env))
|
|
647
668
|
return;
|
|
648
669
|
try {
|
|
@@ -733,8 +754,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
733
754
|
`);
|
|
734
755
|
}
|
|
735
756
|
function printError(prefix, message, hint, cause) {
|
|
736
|
-
const colors = paint(
|
|
737
|
-
const styled = takesControlCodes(
|
|
757
|
+
const colors = paint(process6.stderr);
|
|
758
|
+
const styled = takesControlCodes(process6.stderr);
|
|
738
759
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
739
760
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
740
761
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -777,11 +798,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
777
798
|
}
|
|
778
799
|
}
|
|
779
800
|
if (name === undefined && level.path.length > 1) {
|
|
780
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
801
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process6.stderr));
|
|
781
802
|
return 2;
|
|
782
803
|
}
|
|
783
804
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
784
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
805
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process6.stdout));
|
|
785
806
|
return 0;
|
|
786
807
|
}
|
|
787
808
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -897,10 +918,22 @@ async function printCandidates(found) {
|
|
|
897
918
|
console.log(line);
|
|
898
919
|
return 0;
|
|
899
920
|
}
|
|
900
|
-
|
|
921
|
+
function packageVersion(entry = Bun.main) {
|
|
922
|
+
for (let dir = dirname2(realpathSync(entry));; dir = dirname2(dir)) {
|
|
923
|
+
try {
|
|
924
|
+
const { version } = JSON.parse(readFileSync(join2(dir, "package.json"), "utf8"));
|
|
925
|
+
if (typeof version === "string")
|
|
926
|
+
return version;
|
|
927
|
+
} catch {}
|
|
928
|
+
if (dirname2(dir) === dir)
|
|
929
|
+
return "0.0.0";
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
async function runCli(cli, argv = process6.argv.slice(2)) {
|
|
933
|
+
const version = cli.version ?? packageVersion();
|
|
901
934
|
if (argv[0] === COMPLETE)
|
|
902
935
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
903
|
-
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(
|
|
936
|
+
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
|
|
904
937
|
if (cli.usage !== false) {
|
|
905
938
|
try {
|
|
906
939
|
recordUsage(usageEntry(cli.name, commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv), argv, code));
|
|
@@ -923,6 +956,20 @@ function commandPath(scope, argv) {
|
|
|
923
956
|
}
|
|
924
957
|
return path.length === 0 ? undefined : path.join(" ");
|
|
925
958
|
}
|
|
959
|
+
// ../kit/src/compose.ts
|
|
960
|
+
async function captureOutput(argv, { cwd, env } = {}) {
|
|
961
|
+
const run = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, env: { ...process.env, ...env }, stdin: "ignore", stdout: "pipe", stderr: "pipe" });
|
|
962
|
+
const [stdout, stderr, code] = await Promise.all([run.stdout.text(), run.stderr.text(), run.exited]);
|
|
963
|
+
return { code, stdout, stderr };
|
|
964
|
+
}
|
|
965
|
+
async function compose(args, { flags = [], ...options } = {}) {
|
|
966
|
+
return captureOutput(["docker", "compose", ...flags, ...args], options);
|
|
967
|
+
}
|
|
968
|
+
function composeError({ code, stderr }) {
|
|
969
|
+
const last = stderr.trim().split(`
|
|
970
|
+
`).at(-1) ?? "";
|
|
971
|
+
return last === "" ? `exit ${code}` : last;
|
|
972
|
+
}
|
|
926
973
|
// ../kit/src/limit.ts
|
|
927
974
|
function limitOptions(fallback) {
|
|
928
975
|
return {
|
|
@@ -950,26 +997,18 @@ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "ses
|
|
|
950
997
|
var {Glob } = globalThis.Bun;
|
|
951
998
|
var SESSION_FILES = new Glob("*.json");
|
|
952
999
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
953
|
-
// package.json
|
|
954
|
-
var version = "0.4.1";
|
|
955
|
-
|
|
956
1000
|
// src/commands/audit.ts
|
|
957
1001
|
import { homedir as homedir2 } from "os";
|
|
958
1002
|
import { resolve as resolve2 } from "path";
|
|
959
1003
|
import process9 from "process";
|
|
960
1004
|
|
|
961
1005
|
// src/audit/compose.ts
|
|
962
|
-
import { join as
|
|
963
|
-
import process7 from "process";
|
|
1006
|
+
import { join as join3 } from "path";
|
|
964
1007
|
var dockerCompose = async (root, files) => {
|
|
965
|
-
const
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
`).at(-1) ?? "";
|
|
970
|
-
if (code !== 0)
|
|
971
|
-
throw new Error(last !== "" ? last : `exited with ${code}`);
|
|
972
|
-
return JSON.parse(out);
|
|
1008
|
+
const result = await compose(["config", "--no-interpolate", "--format", "json"], { flags: ["--project-directory", root, ...files.flatMap((file) => ["-f", join3(root, file)])], env: { COMPOSE_FILE: "" } });
|
|
1009
|
+
if (result.code !== 0)
|
|
1010
|
+
throw new Error(composeError(result));
|
|
1011
|
+
return JSON.parse(result.stdout);
|
|
973
1012
|
};
|
|
974
1013
|
|
|
975
1014
|
// src/audit/render.ts
|
|
@@ -998,11 +1037,11 @@ function render(result, limit = Number.POSITIVE_INFINITY) {
|
|
|
998
1037
|
|
|
999
1038
|
// src/audit/run.ts
|
|
1000
1039
|
import { existsSync as existsSync3 } from "fs";
|
|
1001
|
-
import { join as
|
|
1040
|
+
import { join as join6 } from "path";
|
|
1002
1041
|
|
|
1003
1042
|
// src/audit/checks.ts
|
|
1004
|
-
import { existsSync, readFileSync } from "fs";
|
|
1005
|
-
import { isAbsolute as isAbsolute2, join as
|
|
1043
|
+
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
1044
|
+
import { isAbsolute as isAbsolute2, join as join4, relative, resolve } from "path";
|
|
1006
1045
|
var ENV_REF = /(?<!\$)\$(?:\{([A-Z_]\w*)(\s*:?[-?+][^}]*)?\}|([A-Z_]\w*))/gi;
|
|
1007
1046
|
var REQUIRED_OPERATOR = /^\s*:?\?/;
|
|
1008
1047
|
var COMMENT_START = /(?:^|\s)#.*$/;
|
|
@@ -1018,18 +1057,18 @@ function before(text, separator) {
|
|
|
1018
1057
|
}
|
|
1019
1058
|
var stripDotSlash = (file) => file.replace(LEADING_DOT_SLASH, "");
|
|
1020
1059
|
function composeLayout(root, config) {
|
|
1021
|
-
const composeFiles = (config.deploySyncFiles ?? []).map(stripDotSlash).filter((file) => YAML_FILE.test(file) && existsSync(
|
|
1060
|
+
const composeFiles = (config.deploySyncFiles ?? []).map(stripDotSlash).filter((file) => YAML_FILE.test(file) && existsSync(join4(root, file)));
|
|
1022
1061
|
const [base] = composeFiles.toSorted((a, b) => a.length - b.length);
|
|
1023
1062
|
return { composeFiles, base, overlays: composeFiles.filter((file) => file !== base) };
|
|
1024
1063
|
}
|
|
1025
1064
|
function syncFindings(root, config) {
|
|
1026
|
-
return (config.deploySyncFiles ?? []).filter((file) => !existsSync(
|
|
1065
|
+
return (config.deploySyncFiles ?? []).filter((file) => !existsSync(join4(root, stripDotSlash(file)))).map((file) => ({ level: "error", check: "sync", message: `deploySyncFiles entry does not exist: ${file}` }));
|
|
1027
1066
|
}
|
|
1028
1067
|
function buildFindings(root, releases, env, home) {
|
|
1029
1068
|
const findings = [];
|
|
1030
1069
|
const missing = (release, key) => {
|
|
1031
1070
|
const path = release[key];
|
|
1032
|
-
if (path !== undefined && path !== "" && !existsSync(
|
|
1071
|
+
if (path !== undefined && path !== "" && !existsSync(join4(root, path)))
|
|
1033
1072
|
findings.push({ level: "error", check: "build", message: `${release.slug}: ${key} does not exist: ${path}` });
|
|
1034
1073
|
};
|
|
1035
1074
|
for (const release of releases) {
|
|
@@ -1038,7 +1077,7 @@ function buildFindings(root, releases, env, home) {
|
|
|
1038
1077
|
missing(release, "dockerfile");
|
|
1039
1078
|
for (const secret of release.buildSecrets ?? []) {
|
|
1040
1079
|
if (secret.src !== undefined && secret.src !== "") {
|
|
1041
|
-
const path = secret.src.startsWith("~") ?
|
|
1080
|
+
const path = secret.src.startsWith("~") ? join4(home, secret.src.slice(1)) : resolve(root, secret.src);
|
|
1042
1081
|
if (!existsSync(path))
|
|
1043
1082
|
findings.push({ level: "error", check: "build", message: `${release.slug}: buildSecret "${secret.id}" src does not exist: ${secret.src}` });
|
|
1044
1083
|
}
|
|
@@ -1056,7 +1095,7 @@ function withoutComment(line) {
|
|
|
1056
1095
|
}
|
|
1057
1096
|
function envRefs(root, composeFiles) {
|
|
1058
1097
|
return composeFiles.flatMap((file) => {
|
|
1059
|
-
const text =
|
|
1098
|
+
const text = readFileSync2(join4(root, file), "utf8").split(`
|
|
1060
1099
|
`).map(withoutComment).join(`
|
|
1061
1100
|
`);
|
|
1062
1101
|
return [...text.matchAll(ENV_REF)].map((match) => ({ name: match[1] ?? match[3], defaulted: match[2] !== undefined && !REQUIRED_OPERATOR.test(match[2]), file }));
|
|
@@ -1103,7 +1142,9 @@ function imageFindings(config, releases, model) {
|
|
|
1103
1142
|
return findings;
|
|
1104
1143
|
}
|
|
1105
1144
|
function restartFindings(config, releases, model, base) {
|
|
1106
|
-
|
|
1145
|
+
if (model === undefined)
|
|
1146
|
+
return [];
|
|
1147
|
+
const known = new Set(Object.keys(model.services ?? {}));
|
|
1107
1148
|
const findings = [];
|
|
1108
1149
|
for (const release of releases) {
|
|
1109
1150
|
for (const service of release.restartServices ?? []) {
|
|
@@ -1122,7 +1163,9 @@ function restartFindings(config, releases, model, base) {
|
|
|
1122
1163
|
return findings;
|
|
1123
1164
|
}
|
|
1124
1165
|
function postDeployFindings(releases, model, base) {
|
|
1125
|
-
|
|
1166
|
+
if (model === undefined)
|
|
1167
|
+
return [];
|
|
1168
|
+
const known = new Set(Object.keys(model.services ?? {}));
|
|
1126
1169
|
const findings = [];
|
|
1127
1170
|
for (const release of releases) {
|
|
1128
1171
|
for (const command of release.postDeployCommands ?? []) {
|
|
@@ -1173,7 +1216,7 @@ function relativeSource(root, source) {
|
|
|
1173
1216
|
function layoutFindings(root, base, model) {
|
|
1174
1217
|
if (base === undefined)
|
|
1175
1218
|
return [];
|
|
1176
|
-
const header =
|
|
1219
|
+
const header = readFileSync2(join4(root, base), "utf8").split(SERVICES_KEY)[0] ?? "";
|
|
1177
1220
|
const findings = [];
|
|
1178
1221
|
for (const [name, service] of services(model)) {
|
|
1179
1222
|
for (const volume of service.volumes ?? []) {
|
|
@@ -1185,14 +1228,14 @@ function layoutFindings(root, base, model) {
|
|
|
1185
1228
|
return findings;
|
|
1186
1229
|
}
|
|
1187
1230
|
function gitignoreFindings(root) {
|
|
1188
|
-
const path =
|
|
1189
|
-
const text = existsSync(path) ?
|
|
1231
|
+
const path = join4(root, ".gitignore");
|
|
1232
|
+
const text = existsSync(path) ? readFileSync2(path, "utf8") : "";
|
|
1190
1233
|
return [".release-logs", ".release-worktrees"].filter((entry) => !text.includes(entry)).map((entry) => ({ level: "warn", check: "gitignore", message: `${entry}/ is not in .gitignore` }));
|
|
1191
1234
|
}
|
|
1192
1235
|
|
|
1193
1236
|
// src/audit/nuxt.ts
|
|
1194
|
-
import { existsSync as existsSync2, readFileSync as
|
|
1195
|
-
import { basename as basename2, join as
|
|
1237
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "fs";
|
|
1238
|
+
import { basename as basename2, join as join5 } from "path";
|
|
1196
1239
|
var CAMEL_BOUNDARY = /([a-z0-9])([A-Z])/g;
|
|
1197
1240
|
var KEY = /([A-Z_]\w*)\s*(?:\?\s*)?:/gi;
|
|
1198
1241
|
var OPENS_BRACE = /^\s*\{/;
|
|
@@ -1235,21 +1278,21 @@ function schemaEnvNames(schema, iface, prefix) {
|
|
|
1235
1278
|
}
|
|
1236
1279
|
function nuxtFindings(root, releases, model) {
|
|
1237
1280
|
const findings = [];
|
|
1238
|
-
const dirs = [...new Set(releases.map((release) => release.buildContext).filter((context) => context !== undefined && context !== ""))].map((dir) =>
|
|
1281
|
+
const dirs = [...new Set(releases.map((release) => release.buildContext).filter((context) => context !== undefined && context !== ""))].map((dir) => join5(root, dir)).filter((dir) => existsSync2(join5(dir, "nuxt.config.ts")));
|
|
1239
1282
|
for (const dir of dirs) {
|
|
1240
|
-
const schemaPath = [
|
|
1283
|
+
const schemaPath = [join5(dir, ".nuxt/types/schema.d.ts"), join5(dir, ".nuxt/types/runtime-config.d.ts")].find((path) => existsSync2(path));
|
|
1241
1284
|
let allowed;
|
|
1242
1285
|
let level = "error";
|
|
1243
1286
|
let source;
|
|
1244
1287
|
if (schemaPath !== undefined) {
|
|
1245
|
-
const schema =
|
|
1288
|
+
const schema = readFileSync3(schemaPath, "utf8");
|
|
1246
1289
|
allowed = new Set([
|
|
1247
1290
|
...schemaEnvNames(schema, "SharedRuntimeConfig", "NUXT_"),
|
|
1248
1291
|
...schemaEnvNames(schema, "SharedPublicRuntimeConfig", "NUXT_PUBLIC_")
|
|
1249
1292
|
]);
|
|
1250
1293
|
source = `${basename2(dir)}/${schemaPath.slice(dir.length + 1)}`;
|
|
1251
1294
|
} else {
|
|
1252
|
-
const config =
|
|
1295
|
+
const config = readFileSync3(join5(dir, "nuxt.config.ts"), "utf8");
|
|
1253
1296
|
const at = config.indexOf("runtimeConfig:");
|
|
1254
1297
|
const block = at < 0 ? undefined : braceBody(config, at);
|
|
1255
1298
|
if (block === undefined)
|
|
@@ -1280,7 +1323,7 @@ function installed(specifier, root) {
|
|
|
1280
1323
|
}
|
|
1281
1324
|
}
|
|
1282
1325
|
async function loadConfig(root) {
|
|
1283
|
-
const specifier = DEFINE_CONFIG_IMPORT.exec(await Bun.file(
|
|
1326
|
+
const specifier = DEFINE_CONFIG_IMPORT.exec(await Bun.file(join6(root, CONFIG_FILE)).text())?.[1];
|
|
1284
1327
|
if (specifier !== undefined && !installed(specifier, root)) {
|
|
1285
1328
|
Bun.plugin({
|
|
1286
1329
|
name: "release-stand-in",
|
|
@@ -1289,7 +1332,7 @@ async function loadConfig(root) {
|
|
|
1289
1332
|
}
|
|
1290
1333
|
});
|
|
1291
1334
|
}
|
|
1292
|
-
const config = (await import(
|
|
1335
|
+
const config = (await import(join6(root, CONFIG_FILE))).default;
|
|
1293
1336
|
if (config === undefined)
|
|
1294
1337
|
fail(`${CONFIG_FILE} has no default export`);
|
|
1295
1338
|
return config;
|
|
@@ -1338,7 +1381,7 @@ async function audit(config, options) {
|
|
|
1338
1381
|
];
|
|
1339
1382
|
return { root, composeFiles, findings };
|
|
1340
1383
|
}
|
|
1341
|
-
var hasConfig = (root) => existsSync3(
|
|
1384
|
+
var hasConfig = (root) => existsSync3(join6(root, CONFIG_FILE));
|
|
1342
1385
|
|
|
1343
1386
|
// src/commands/audit.ts
|
|
1344
1387
|
var usage2 = `stack audit [dir]
|
|
@@ -1357,8 +1400,7 @@ async function audit2(args, overrides = {}) {
|
|
|
1357
1400
|
const parsed = parse(args, usage2, options);
|
|
1358
1401
|
const root = resolve2(parsed.positionals[0] ?? ".");
|
|
1359
1402
|
if (!hasConfig(root)) {
|
|
1360
|
-
|
|
1361
|
-
return 2;
|
|
1403
|
+
fail(`no ${CONFIG_FILE} in ${root}`);
|
|
1362
1404
|
}
|
|
1363
1405
|
const result = await audit(await loadConfig(root), { root, loadCompose: dockerCompose, env: process9.env, home: homedir2(), ...overrides });
|
|
1364
1406
|
if (parsed.values.json === true)
|
|
@@ -1409,7 +1451,7 @@ async function port(args) {
|
|
|
1409
1451
|
if (name === undefined)
|
|
1410
1452
|
fail("a name is needed");
|
|
1411
1453
|
const min = wholeNumber(parsed.values.min, "min", MIN_PORT, MIN_PORT);
|
|
1412
|
-
const max = wholeNumber(parsed.values.max, "max", DEFAULT_MAX_PORT, min);
|
|
1454
|
+
const max = wholeNumber(parsed.values.max, "max", Math.max(DEFAULT_MAX_PORT, min), min);
|
|
1413
1455
|
if (max > MAX_PORT)
|
|
1414
1456
|
fail(`--max goes up to ${MAX_PORT}, not ${max}`);
|
|
1415
1457
|
const number = stringToPort(name, min, max);
|
|
@@ -1426,7 +1468,6 @@ async function port(args) {
|
|
|
1426
1468
|
// src/cli.ts
|
|
1427
1469
|
process10.exitCode = await runCli({
|
|
1428
1470
|
name: "stack",
|
|
1429
|
-
version,
|
|
1430
1471
|
about: "a stable port per service name, and a compose release audit",
|
|
1431
1472
|
replaces: "picking a free host port by hand, and reading compose files against release.config.ts",
|
|
1432
1473
|
examples: ["stack port api", ["stack audit", "this folder's release setup"]],
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-stack",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"description": "stack: a stable port per service name, and an audit of a compose release setup against its release.config.ts.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"stack": "$npm_execpath src/cli.ts"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@kaynooo/cli-kit": "0.
|
|
31
|
+
"@kaynooo/cli-kit": "0.21.0"
|
|
32
32
|
}
|
|
33
33
|
}
|