@plexus-ms/cli 0.116.0 → 0.117.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/plx.js +155 -26
- package/package.json +2 -2
package/dist/plx.js
CHANGED
|
@@ -7969,12 +7969,13 @@ function compareTrains(a, b) {
|
|
|
7969
7969
|
|
|
7970
7970
|
// ../lib/dist/train.js
|
|
7971
7971
|
var PRIMITIVES = "primitives";
|
|
7972
|
+
var COMPENDIUM = "compendium";
|
|
7972
7973
|
var TRAIN_REPOS = [
|
|
7973
7974
|
PRIMITIVES,
|
|
7974
7975
|
"preset-repo-turbo",
|
|
7975
7976
|
"preset-app-nextjs",
|
|
7976
7977
|
"preset-repo-operations",
|
|
7977
|
-
|
|
7978
|
+
COMPENDIUM
|
|
7978
7979
|
];
|
|
7979
7980
|
var PHASES = [[PRIMITIVES], TRAIN_REPOS.filter((r) => r !== PRIMITIVES)];
|
|
7980
7981
|
var TRAIN_PACKAGES = [
|
|
@@ -8556,6 +8557,61 @@ async function resolveHealthUrl(remote, D, dc, ctx) {
|
|
|
8556
8557
|
return url;
|
|
8557
8558
|
}
|
|
8558
8559
|
|
|
8560
|
+
// ../lib/dist/manifest.js
|
|
8561
|
+
var MANIFEST_FILE = "train.json";
|
|
8562
|
+
var MANIFEST_SCHEMA = 1;
|
|
8563
|
+
function buildManifest(catalog, train, date) {
|
|
8564
|
+
const modules = [...catalog.values()].sort((a, b) => a.code.localeCompare(b.code));
|
|
8565
|
+
return { schema: MANIFEST_SCHEMA, train, date, modules };
|
|
8566
|
+
}
|
|
8567
|
+
var renderManifest = (manifest2) => `${JSON.stringify(manifest2, null, 2)}
|
|
8568
|
+
`;
|
|
8569
|
+
var catalogOf = (manifest2) => new Map(manifest2.modules.map((m) => [m.code, m]));
|
|
8570
|
+
var strings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
8571
|
+
function parseManifest(text) {
|
|
8572
|
+
let data;
|
|
8573
|
+
try {
|
|
8574
|
+
data = JSON.parse(text);
|
|
8575
|
+
} catch {
|
|
8576
|
+
throw new Error("the train manifest is not JSON");
|
|
8577
|
+
}
|
|
8578
|
+
if (data === null || typeof data !== "object" || Array.isArray(data))
|
|
8579
|
+
throw new Error("the train manifest is not an object");
|
|
8580
|
+
const { schema, train, date, modules } = data;
|
|
8581
|
+
if (schema !== MANIFEST_SCHEMA)
|
|
8582
|
+
throw new Error(`the train manifest has schema ${JSON.stringify(schema)}; this plx reads ${MANIFEST_SCHEMA}`);
|
|
8583
|
+
if (typeof train !== "string" || !isTrainVersion(train))
|
|
8584
|
+
throw new Error(`the train manifest names '${String(train)}', not a train`);
|
|
8585
|
+
if (typeof date !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(date))
|
|
8586
|
+
throw new Error(`the train manifest is dated '${String(date)}', not YYYY-MM-DD`);
|
|
8587
|
+
if (!Array.isArray(modules))
|
|
8588
|
+
throw new Error("the train manifest lists no modules");
|
|
8589
|
+
return { schema: MANIFEST_SCHEMA, train, date, modules: modules.map(parseEntry) };
|
|
8590
|
+
}
|
|
8591
|
+
function parseEntry(entry) {
|
|
8592
|
+
const m = entry ?? {};
|
|
8593
|
+
const where = `the train manifest's module ${typeof m.code === "string" ? m.code : JSON.stringify(entry)}`;
|
|
8594
|
+
if (typeof m.code !== "string" || m.code === "")
|
|
8595
|
+
throw new Error(`${where} has no code`);
|
|
8596
|
+
if (m.kind !== "contract" && m.kind !== "approach")
|
|
8597
|
+
throw new Error(`${where} is neither contract nor approach`);
|
|
8598
|
+
if (typeof m.maturity !== "string" || typeof m.binds !== "string")
|
|
8599
|
+
throw new Error(`${where} lacks maturity or binds`);
|
|
8600
|
+
if (!strings(m.depends) || !strings(m.consumes))
|
|
8601
|
+
throw new Error(`${where} lacks depends or consumes`);
|
|
8602
|
+
if (m.changed !== void 0 && typeof m.changed !== "string")
|
|
8603
|
+
throw new Error(`${where} has a changed that is no train`);
|
|
8604
|
+
return {
|
|
8605
|
+
code: m.code,
|
|
8606
|
+
kind: m.kind,
|
|
8607
|
+
maturity: m.maturity,
|
|
8608
|
+
binds: m.binds,
|
|
8609
|
+
changed: m.changed,
|
|
8610
|
+
depends: m.depends,
|
|
8611
|
+
consumes: m.consumes
|
|
8612
|
+
};
|
|
8613
|
+
}
|
|
8614
|
+
|
|
8559
8615
|
// ../lib/dist/model.js
|
|
8560
8616
|
function kindOf(declaration) {
|
|
8561
8617
|
const has = (code) => declaration.modules.includes(code);
|
|
@@ -8581,9 +8637,16 @@ var DEFAULT_MAX_AGE = 30;
|
|
|
8581
8637
|
var MAX_AGE_ANSWER = "update_max_age";
|
|
8582
8638
|
var DAY = 24 * 60 * 60 * 1e3;
|
|
8583
8639
|
var days = (n) => `${n} day${n === 1 ? "" : "s"}`;
|
|
8584
|
-
function needOf({ recorded, releases, asked, maxAge, now }) {
|
|
8640
|
+
function needOf({ recorded, releases, asked, stale = [], maxAge, now }) {
|
|
8585
8641
|
if (asked)
|
|
8586
8642
|
return { take: true, trigger: "asked", why: `asked for (${asked})` };
|
|
8643
|
+
const [first, ...more] = stale;
|
|
8644
|
+
if (first)
|
|
8645
|
+
return {
|
|
8646
|
+
take: true,
|
|
8647
|
+
trigger: "module",
|
|
8648
|
+
why: `${first.code} changed in ${first.changed}, declared at ${first.declared} in ${first.where}${more.length > 0 ? `, and ${more.length} more` : ""}`
|
|
8649
|
+
};
|
|
8587
8650
|
const odd = recorded.findIndex((r) => !r || !isTrainVersion(r));
|
|
8588
8651
|
if (recorded.length === 0 || odd >= 0)
|
|
8589
8652
|
return {
|
|
@@ -8591,13 +8654,13 @@ function needOf({ recorded, releases, asked, maxAge, now }) {
|
|
|
8591
8654
|
trigger: "backstop",
|
|
8592
8655
|
why: `a site records ${recorded[odd] ? `'${recorded[odd]}'` : "no version"}, not a train`
|
|
8593
8656
|
};
|
|
8594
|
-
const
|
|
8595
|
-
const oldest =
|
|
8657
|
+
const trains2 = recorded;
|
|
8658
|
+
const oldest = trains2.reduce((a, b) => compareTrains(a, b) <= 0 ? a : b);
|
|
8596
8659
|
const untaken = releases.filter((r) => isTrainVersion(r.train) && compareTrains(r.train, oldest) > 0).sort((a, b) => Date.parse(a.published) - Date.parse(b.published));
|
|
8597
|
-
const
|
|
8598
|
-
if (!
|
|
8660
|
+
const oldestUntaken = untaken[0];
|
|
8661
|
+
if (!oldestUntaken)
|
|
8599
8662
|
return { take: false, why: `no train newer than ${oldest}` };
|
|
8600
|
-
const age = Math.max(0, Math.floor((now.getTime() - Date.parse(
|
|
8663
|
+
const age = Math.max(0, Math.floor((now.getTime() - Date.parse(oldestUntaken.published)) / DAY));
|
|
8601
8664
|
const count = `${untaken.length} newer train${untaken.length === 1 ? "" : "s"}`;
|
|
8602
8665
|
if (maxAge === 0)
|
|
8603
8666
|
return { take: true, trigger: "backstop", why: `a backstop age of zero takes every train (${count})` };
|
|
@@ -8605,13 +8668,26 @@ function needOf({ recorded, releases, asked, maxAge, now }) {
|
|
|
8605
8668
|
return {
|
|
8606
8669
|
take: true,
|
|
8607
8670
|
trigger: "backstop",
|
|
8608
|
-
why: `${
|
|
8671
|
+
why: `${oldestUntaken.train}, the oldest train not taken, was cut ${days(age)} ago (backstop: ${days(maxAge)}; ${count})`
|
|
8609
8672
|
};
|
|
8610
8673
|
return {
|
|
8611
8674
|
take: false,
|
|
8612
|
-
why: `${count}, the oldest (${
|
|
8675
|
+
why: `${count}, the oldest (${oldestUntaken.train}) cut ${days(age)} ago; the backstop is ${days(maxAge)}`
|
|
8613
8676
|
};
|
|
8614
8677
|
}
|
|
8678
|
+
function staleModules(markers, catalog) {
|
|
8679
|
+
const stale = [];
|
|
8680
|
+
for (const { where, plexus, modules } of markers) {
|
|
8681
|
+
if (!isTrainVersion(plexus))
|
|
8682
|
+
continue;
|
|
8683
|
+
for (const code of modules) {
|
|
8684
|
+
const changed = catalog.get(code)?.changed;
|
|
8685
|
+
if (changed && isTrainVersion(changed) && compareTrains(changed, plexus) > 0)
|
|
8686
|
+
stale.push({ code, changed, where, declared: plexus });
|
|
8687
|
+
}
|
|
8688
|
+
}
|
|
8689
|
+
return stale;
|
|
8690
|
+
}
|
|
8615
8691
|
function maxAgeOf(answers) {
|
|
8616
8692
|
const value = answers[MAX_AGE_ANSWER];
|
|
8617
8693
|
if (value === void 0 || value === null || value === "")
|
|
@@ -9046,8 +9122,8 @@ async function update(ctx, options) {
|
|
|
9046
9122
|
if (!root)
|
|
9047
9123
|
throw new Error(`${name}: its root is not a site of a repo preset`);
|
|
9048
9124
|
await preflightForge(ctx);
|
|
9049
|
-
const releases = options.train === void 0 ? await
|
|
9050
|
-
const train = options.train ?? newestOf(releases
|
|
9125
|
+
const releases = options.train === void 0 ? await trains(ctx) : [];
|
|
9126
|
+
const train = options.train ?? newestOf(releases);
|
|
9051
9127
|
const summary = emptySummary(train, ctx.dryRun);
|
|
9052
9128
|
await ctx.read("git", ["fetch", "--quiet", "origin", consumer.branch], { cwd: repo }).catch(() => "");
|
|
9053
9129
|
const answers = await Promise.all(consumer.sites.map(async (s) => {
|
|
@@ -9072,10 +9148,12 @@ async function update(ctx, options) {
|
|
|
9072
9148
|
summary.pulls.push(url);
|
|
9073
9149
|
return summary;
|
|
9074
9150
|
}
|
|
9151
|
+
const asked = options.train !== void 0 ? `--train ${train}` : options.now ? "--now" : void 0;
|
|
9075
9152
|
const need = needOf({
|
|
9076
9153
|
recorded,
|
|
9077
9154
|
releases,
|
|
9078
|
-
asked
|
|
9155
|
+
asked,
|
|
9156
|
+
stale: asked ? [] : await staleIn(ctx, consumer, repo, train),
|
|
9079
9157
|
maxAge: options.maxAge ?? maxAgeOf(answers[consumer.sites.indexOf(root)]?.answers ?? {}),
|
|
9080
9158
|
now: options.today === void 0 ? /* @__PURE__ */ new Date() : new Date(options.today)
|
|
9081
9159
|
});
|
|
@@ -9105,16 +9183,37 @@ async function update(ctx, options) {
|
|
|
9105
9183
|
}
|
|
9106
9184
|
return summary;
|
|
9107
9185
|
}
|
|
9108
|
-
async function
|
|
9109
|
-
const
|
|
9186
|
+
async function staleIn(ctx, consumer, repo, train) {
|
|
9187
|
+
const text = await ctx.read("gh", ["release", "download", train, "-R", TRAINS, "-p", MANIFEST_FILE, "-O", "-"]).catch(() => void 0);
|
|
9188
|
+
if (text === void 0) {
|
|
9189
|
+
ctx.say(` ${consumer.rel}: train ${train} carries no ${MANIFEST_FILE} that can be read; its modules are not checked`);
|
|
9190
|
+
return [];
|
|
9191
|
+
}
|
|
9192
|
+
const catalog = catalogOf(parseManifest(text));
|
|
9193
|
+
const markers = [];
|
|
9194
|
+
for (const site of consumer.sites) {
|
|
9195
|
+
const file = join9(relative4(consumer.path, site.path), MARKER_FILE);
|
|
9196
|
+
const marker = await ctx.read("git", ["show", `origin/${consumer.branch}:${file}`], { cwd: repo }).catch(() => void 0) ?? await ctx.readFile(join9(site.path, MARKER_FILE)).catch(() => void 0);
|
|
9197
|
+
if (marker === void 0)
|
|
9198
|
+
continue;
|
|
9199
|
+
try {
|
|
9200
|
+
const { plexus, modules } = parseMarker(marker);
|
|
9201
|
+
markers.push({ where: join9(site.rel, MARKER_FILE), plexus, modules });
|
|
9202
|
+
} catch {
|
|
9203
|
+
}
|
|
9204
|
+
}
|
|
9205
|
+
return staleModules(markers, catalog);
|
|
9206
|
+
}
|
|
9207
|
+
var TRAINS = `plexus-ms/${COMPENDIUM}`;
|
|
9208
|
+
async function trains(ctx) {
|
|
9110
9209
|
const jq = '.[] | select(.draft | not) | "\\(.tag_name) \\(.published_at)"';
|
|
9111
|
-
const lines = await ctx.read("gh", ["api", `repos/${
|
|
9210
|
+
const lines = await ctx.read("gh", ["api", `repos/${TRAINS}/releases`, "--paginate", "--jq", jq]).catch(() => "");
|
|
9112
9211
|
return lines.split("\n").map((l) => l.trim().split(/\s+/)).filter((p) => p.length === 2 && isTrainVersion(p[0] ?? "")).map(([train, published]) => ({ train, published }));
|
|
9113
9212
|
}
|
|
9114
|
-
function newestOf(releases
|
|
9213
|
+
function newestOf(releases) {
|
|
9115
9214
|
const newest = releases.map((r) => r.train).reduce((a, b) => a && compareTrains(a, b) >= 0 ? a : b, "");
|
|
9116
9215
|
if (!newest)
|
|
9117
|
-
throw new Error(`no release of ${
|
|
9216
|
+
throw new Error(`no release of ${TRAINS} found \u2014 pass the train explicitly (--train <version>)`);
|
|
9118
9217
|
return newest;
|
|
9119
9218
|
}
|
|
9120
9219
|
|
|
@@ -9366,23 +9465,27 @@ async function releasePhase(ctx, train, repos2, next, today2) {
|
|
|
9366
9465
|
ctx.say(`\u2192 phase: ${repos2.map((r) => r.name).join(", ")}`);
|
|
9367
9466
|
await ctx.apply(await planBookkeeping(ctx, train, repos2, next, today2));
|
|
9368
9467
|
for (const repo of repos2)
|
|
9369
|
-
await tagAndRelease(ctx, repo, next);
|
|
9468
|
+
await tagAndRelease(ctx, repo, next, today2);
|
|
9370
9469
|
}
|
|
9371
|
-
async function tagAndRelease(ctx, repo, next) {
|
|
9470
|
+
async function tagAndRelease(ctx, repo, next, today2) {
|
|
9372
9471
|
const tagged = await ctx.read("git", ["rev-parse", "-q", "--verify", `refs/tags/${next}`], { cwd: repo.path }).then(() => true).catch(() => false);
|
|
9373
9472
|
if (tagged)
|
|
9374
9473
|
ctx.say(`\u2022 ${repo.name}: already tagged ${next}`);
|
|
9375
9474
|
else
|
|
9376
9475
|
await ctx.apply([run("git", ["tag", "-a", next, "-m", `train ${next}`], { cwd: repo.path })]);
|
|
9377
9476
|
await ctx.apply([run("git", ["push", "origin", "main", next], { cwd: repo.path })]);
|
|
9378
|
-
const
|
|
9379
|
-
if (
|
|
9380
|
-
|
|
9381
|
-
|
|
9477
|
+
const create = ["release", "create", next, "--verify-tag", "--generate-notes", "--title", next];
|
|
9478
|
+
if (repo.name === COMPENDIUM) {
|
|
9479
|
+
if (!await releaseWithManifest(ctx, repo, next, today2, create))
|
|
9480
|
+
return;
|
|
9481
|
+
} else {
|
|
9482
|
+
const released = await ctx.read("gh", ["release", "view", next], { cwd: repo.path }).then(() => true).catch(() => false);
|
|
9483
|
+
if (released) {
|
|
9484
|
+
ctx.say(`\u2022 ${repo.name}: release ${next} exists`);
|
|
9485
|
+
return;
|
|
9486
|
+
}
|
|
9487
|
+
await ctx.apply([run("gh", create, { cwd: repo.path })]);
|
|
9382
9488
|
}
|
|
9383
|
-
await ctx.apply([
|
|
9384
|
-
run("gh", ["release", "create", next, "--verify-tag", "--generate-notes", "--title", next], { cwd: repo.path })
|
|
9385
|
-
]);
|
|
9386
9489
|
if (ctx.dryRun)
|
|
9387
9490
|
return;
|
|
9388
9491
|
const immutable = (await ctx.read("gh", ["api", `repos/{owner}/{repo}/releases/tags/${next}`, "--jq", ".immutable"], {
|
|
@@ -9391,6 +9494,32 @@ async function tagAndRelease(ctx, repo, next) {
|
|
|
9391
9494
|
if (immutable !== "true")
|
|
9392
9495
|
throw new Error(mutableRelease(`${repo.name}: release ${next} was created mutable, and its tag can still move`));
|
|
9393
9496
|
}
|
|
9497
|
+
async function releaseWithManifest(ctx, repo, next, today2, create) {
|
|
9498
|
+
const state = (await ctx.read("gh", ["release", "view", next, "--json", "isDraft", "--jq", ".isDraft"], { cwd: repo.path }).catch(() => "")).trim();
|
|
9499
|
+
if (state === "false") {
|
|
9500
|
+
ctx.say(`\u2022 ${repo.name}: release ${next} exists`);
|
|
9501
|
+
return false;
|
|
9502
|
+
}
|
|
9503
|
+
if (state === "true")
|
|
9504
|
+
ctx.say(`\u2022 ${repo.name}: release ${next} is still a draft \u2014 finishing it`);
|
|
9505
|
+
else
|
|
9506
|
+
await ctx.apply([run("gh", [...create, "--draft"], { cwd: repo.path })]);
|
|
9507
|
+
const scratch = (await ctx.stage(run("mktemp", ["-d"])))?.trim() ?? "";
|
|
9508
|
+
const file = join11(scratch, MANIFEST_FILE);
|
|
9509
|
+
try {
|
|
9510
|
+
const manifest2 = buildManifest(await readCatalog(ctx, repo.path), next, today2);
|
|
9511
|
+
ctx.say(` ${repo.name}: ${MANIFEST_FILE}: train ${next}, ${manifest2.modules.length} modules`);
|
|
9512
|
+
await ctx.stage(write(file, renderManifest(manifest2)));
|
|
9513
|
+
await ctx.apply([
|
|
9514
|
+
run("gh", ["release", "upload", next, file, "--clobber"], { cwd: repo.path }),
|
|
9515
|
+
run("gh", ["release", "edit", next, "--draft=false"], { cwd: repo.path })
|
|
9516
|
+
]);
|
|
9517
|
+
} finally {
|
|
9518
|
+
if (scratch)
|
|
9519
|
+
await ctx.stage(run("rm", ["-rf", scratch]));
|
|
9520
|
+
}
|
|
9521
|
+
return true;
|
|
9522
|
+
}
|
|
9394
9523
|
async function awaitPublished(ctx, next, wait) {
|
|
9395
9524
|
const names = TRAIN_PACKAGES.map((p) => p.name);
|
|
9396
9525
|
const list2 = names.map((n) => `${n}@${next}`).join(", ");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plexus-ms/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.117.0",
|
|
4
4
|
"description": "plx, the Plexus command-line tool: a single-script adapter over @plexus-ms/lib",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@inquirer/prompts": "^8.7.5",
|
|
27
|
-
"@plexus-ms/lib": "0.
|
|
27
|
+
"@plexus-ms/lib": "0.117.0",
|
|
28
28
|
"commander": "^15.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|