@plexus-ms/cli 0.115.0 → 0.116.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.
Files changed (2) hide show
  1. package/dist/plx.js +475 -346
  2. package/package.json +2 -2
package/dist/plx.js CHANGED
@@ -7903,7 +7903,165 @@ async function expand(ctx, root, glob) {
7903
7903
  }
7904
7904
 
7905
7905
  // ../lib/dist/consumers.js
7906
+ import { relative as relative2 } from "node:path";
7907
+
7908
+ // ../lib/dist/train.js
7909
+ import { join as join3 } from "node:path";
7910
+
7911
+ // ../lib/dist/doctor.js
7906
7912
  import { relative } from "node:path";
7913
+ function diagnose(root, catalog) {
7914
+ const units = collect(root, []);
7915
+ const declarations = units.map((u) => diagnoseUnit(u, units, catalog, root.path));
7916
+ return { declarations, stale: declarations.filter((d) => d.findings.length > 0).length };
7917
+ }
7918
+ function collect(dir, ancestors, parent) {
7919
+ const here = dir.declaration || dir.problems?.some((p) => p.startsWith("PLEXUS.md")) ? [{ dir, ancestors, parent }] : [];
7920
+ const below = dir.declaration ? [...ancestors, dir] : ancestors;
7921
+ return [...here, ...dir.children.flatMap((c) => collect(c, below, dir))];
7922
+ }
7923
+ function diagnoseUnit(unit, units, catalog, root) {
7924
+ const { dir } = unit;
7925
+ const path3 = relative(root, dir.path) || ".";
7926
+ const problem = dir.problems?.find((p) => p.startsWith("PLEXUS.md"));
7927
+ if (!dir.declaration)
7928
+ return { path: path3, modules: [], findings: [problem?.replace(/^PLEXUS\.md: /, "") ?? "unreadable marker"] };
7929
+ const { plexus, modules } = dir.declaration;
7930
+ const context = new Set(contextOf(unit, units).flatMap((d) => d.declaration?.modules ?? []));
7931
+ const findings = [];
7932
+ for (const code of modules) {
7933
+ const module = catalog.get(code);
7934
+ if (!module) {
7935
+ findings.push(`declares ${code}, which no module carries`);
7936
+ continue;
7937
+ }
7938
+ if (module.changed && compareTrains(module.changed, plexus) > 0)
7939
+ findings.push(`${code} changed in ${module.changed}, declared at ${plexus}`);
7940
+ for (const dep of module.depends)
7941
+ if (!modules.includes(dep) && !context.has(dep))
7942
+ findings.push(`${code} depends on ${dep}, declared neither here nor by an enclosing or contained declaration`);
7943
+ }
7944
+ return { path: path3, plexus, modules, findings };
7945
+ }
7946
+ function contextOf(unit, units) {
7947
+ const { dir, ancestors } = unit;
7948
+ const context = [...ancestors, ...descendants(dir)];
7949
+ const repo = ancestors[0] ?? dir;
7950
+ const repoParent = units.find((u) => u.dir === repo)?.parent;
7951
+ const siblings = repoParent?.children.filter((c) => c !== repo && c.declaration) ?? [];
7952
+ const isTenancy = (d) => d.declaration?.modules.includes("PLX-Tenancy") ?? false;
7953
+ context.push(...siblings.filter(isTenancy));
7954
+ if (isTenancy(dir))
7955
+ context.push(...siblings);
7956
+ return context;
7957
+ }
7958
+ function descendants(dir) {
7959
+ return dir.children.flatMap((c) => [...c.declaration ? [c] : [], ...descendants(c)]);
7960
+ }
7961
+ function compareTrains(a, b) {
7962
+ const nums = (v) => v.split(".").slice(0, 3).map((p) => Number.parseInt(p, 10) || 0);
7963
+ const [x, y] = [nums(a), nums(b)];
7964
+ for (let i = 0; i < 3; i++)
7965
+ if ((x[i] ?? 0) !== (y[i] ?? 0))
7966
+ return (x[i] ?? 0) > (y[i] ?? 0) ? 1 : -1;
7967
+ return 0;
7968
+ }
7969
+
7970
+ // ../lib/dist/train.js
7971
+ var PRIMITIVES = "primitives";
7972
+ var TRAIN_REPOS = [
7973
+ PRIMITIVES,
7974
+ "preset-repo-turbo",
7975
+ "preset-app-nextjs",
7976
+ "preset-repo-operations",
7977
+ "compendium"
7978
+ ];
7979
+ var PHASES = [[PRIMITIVES], TRAIN_REPOS.filter((r) => r !== PRIMITIVES)];
7980
+ var TRAIN_PACKAGES = [
7981
+ { name: "@plexus-ms/cli", dir: "packages/cli" },
7982
+ { name: "@plexus-ms/cli-ci", dir: "packages/cli-ci" },
7983
+ { name: "@plexus-ms/lib", dir: "packages/lib" },
7984
+ { name: "@plexus-ms/config", dir: "packages/config" }
7985
+ ];
7986
+ var UPSTREAM = "plexus-ms";
7987
+ var isTrainVersion = (v) => /^\d+\.\d+\.\d+$/.test(v);
7988
+ function nextMinor(version2) {
7989
+ const [major = "0", minor = "0"] = version2.split(".");
7990
+ return `${major}.${Number(minor) + 1}.0`;
7991
+ }
7992
+ function latestTag(tags) {
7993
+ return tags.filter((t) => /^v?\d+(\.\d+){1,2}$/.test(t)).sort((a, b) => compareTrains(a.replace(/^v/, ""), b.replace(/^v/, ""))).at(-1);
7994
+ }
7995
+ async function readTrain(ctx, upstream) {
7996
+ const repos2 = [];
7997
+ const all = /* @__PURE__ */ new Set();
7998
+ for (const name of TRAIN_REPOS) {
7999
+ const path3 = join3(upstream, name);
8000
+ try {
8001
+ await ctx.read("git", ["rev-parse", "--git-dir"], { cwd: path3 });
8002
+ } catch {
8003
+ throw new Error(`${path3} is not a git repo`);
8004
+ }
8005
+ try {
8006
+ await ctx.read("git", ["fetch", "origin", "--tags", "--quiet"], { cwd: path3 });
8007
+ } catch {
8008
+ throw new Error(`${name}: fetch from origin failed`);
8009
+ }
8010
+ const tags = (await ctx.read("git", ["tag", "--list", "v*", "[0-9]*"], { cwd: path3 })).split("\n").filter(Boolean);
8011
+ for (const t of tags)
8012
+ all.add(t.replace(/^v/, ""));
8013
+ const tag = latestTag(tags);
8014
+ const range = tag ? `${tag}..HEAD` : "HEAD";
8015
+ const pending = (await ctx.read("git", ["log", "--oneline", range], { cwd: path3 })).split("\n").filter(Boolean);
8016
+ repos2.push({ name, path: path3, tag, latest: tag?.replace(/^v/, ""), pending });
8017
+ }
8018
+ const latest = repos2.map((r) => r.latest);
8019
+ return { repos: repos2, last: latestTag([...all]), skew: latest.some((l) => l !== latest[0]) };
8020
+ }
8021
+ var phasesOf = (train) => PHASES.map((names) => train.repos.filter((r) => names.includes(r.name)));
8022
+ async function preflightRelease(ctx, train) {
8023
+ for (const { name, path: path3 } of train.repos) {
8024
+ const branch = (await ctx.read("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd: path3 })).trim();
8025
+ if (branch !== "main")
8026
+ throw new Error(`${name} is on '${branch}', trains cut from main`);
8027
+ if ((await ctx.read("git", ["status", "--porcelain"], { cwd: path3 })).trim() !== "")
8028
+ throw new Error(`${name} has uncommitted changes \u2014 commit first`);
8029
+ const behind = (await ctx.read("git", ["rev-list", "--count", "main..origin/main"], { cwd: path3 })).trim();
8030
+ if (behind !== "0")
8031
+ throw new Error(`${name} is ${behind} commit(s) behind origin/main \u2014 pull first, or the tag lands on a stale commit`);
8032
+ }
8033
+ }
8034
+ async function preflightForge(ctx) {
8035
+ try {
8036
+ await ctx.read("gh", ["auth", "status"]);
8037
+ } catch {
8038
+ throw new Error("gh is not logged in (gh auth status failed) \u2014 run gh auth login first");
8039
+ }
8040
+ }
8041
+ function resolveVersion(train, explicit, propagateOnly) {
8042
+ if (explicit !== void 0 && !isTrainVersion(explicit))
8043
+ throw new UsageError(`'${explicit}' is not plain semver (X.Y.Z, no v)`);
8044
+ if (propagateOnly) {
8045
+ const v = explicit ?? train.last;
8046
+ if (!v)
8047
+ throw new Error("no train version found to propagate");
8048
+ return v;
8049
+ }
8050
+ if (explicit)
8051
+ return explicit;
8052
+ if (train.skew) {
8053
+ const report = train.repos.map((r) => ` ${r.name}: ${r.latest ?? "none"}`).join("\n");
8054
+ throw new Error(`the train repos' latest tags disagree:
8055
+ ${report}
8056
+ pass the version explicitly (--train ${train.last}) to finish the half-tagged train, or a higher one to start a new one`);
8057
+ }
8058
+ return train.last ? nextMinor(train.last) : "0.1.0";
8059
+ }
8060
+ var UsageError = class extends Error {
8061
+ };
8062
+
8063
+ // ../lib/dist/consumers.js
8064
+ var PRESETS = TRAIN_REPOS.filter((r) => r.startsWith("preset-"));
7907
8065
  function expectedBranch(declaration, answers = {}) {
7908
8066
  if (!declaration)
7909
8067
  return void 0;
@@ -7935,7 +8093,7 @@ async function findConsumers(ctx, root, presets) {
7935
8093
  const template = inTemplate || Boolean(dir.template);
7936
8094
  const preset = dir.copier?.src ? presetOf(dir.copier.src, presets) : void 0;
7937
8095
  if (preset && !template) {
7938
- const site = { path: dir.path, rel: relative(root.path, dir.path) || ".", preset };
8096
+ const site = { path: dir.path, rel: relative2(root.path, dir.path) || ".", preset };
7939
8097
  if (!here)
7940
8098
  orphans.push(site);
7941
8099
  else {
@@ -7944,7 +8102,7 @@ async function findConsumers(ctx, root, presets) {
7944
8102
  const expected = expectedBranch(here.declaration, here.copier?.answers);
7945
8103
  consumer = {
7946
8104
  path: here.path,
7947
- rel: relative(root.path, here.path) || ".",
8105
+ rel: relative2(root.path, here.path) || ".",
7948
8106
  branch: expected ?? here.git?.branch ?? "main",
7949
8107
  expected,
7950
8108
  sites: []
@@ -8083,208 +8241,51 @@ var Context = class {
8083
8241
  cwd: step.cwd,
8084
8242
  input: step.input,
8085
8243
  inherit,
8086
- env: step.env === void 0 ? void 0 : { ...process.env, ...step.env }
8087
- });
8088
- case "write":
8089
- await this.io.writeFile(step.path, step.content);
8090
- return void 0;
8091
- }
8092
- }
8093
- };
8094
- function renderHuman(data) {
8095
- if (typeof data === "string")
8096
- return data;
8097
- if (Array.isArray(data))
8098
- return data.map(String).join("\n");
8099
- return JSON.stringify(data, null, 2);
8100
- }
8101
- function indent(text) {
8102
- return text.trimEnd().split("\n").map((l) => ` ${l}`).join("\n");
8103
- }
8104
-
8105
- // ../lib/dist/copier.js
8106
- var import_yaml3 = __toESM(require_dist(), 1);
8107
- var ANSWERS_FILE = ".copier-answers.yml";
8108
- var TEMPLATE_FILES = ["copier.yml", "copier.yaml"];
8109
- var COPIER_VERSION = "9.19.1";
8110
- var copierVia = (args) => ["exec", `copier@${COPIER_VERSION}`, "--", "copier", ...args];
8111
- function parseAnswers(text) {
8112
- const data = (0, import_yaml3.parse)(text);
8113
- if (data === null || typeof data !== "object" || Array.isArray(data))
8114
- throw new Error("answers file is not a mapping");
8115
- const { _commit, _src_path, ...answers } = data;
8116
- return {
8117
- commit: _commit === void 0 ? void 0 : String(_commit),
8118
- src: _src_path === void 0 ? void 0 : String(_src_path),
8119
- answers
8120
- };
8121
- }
8122
-
8123
- // ../lib/dist/deploy.js
8124
- import { randomBytes } from "node:crypto";
8125
- import { tmpdir } from "node:os";
8126
- import { join as join5 } from "node:path";
8127
-
8128
- // ../lib/dist/deployTargets.js
8129
- var import_yaml4 = __toESM(require_dist(), 1);
8130
- import { join as join4 } from "node:path";
8131
-
8132
- // ../lib/dist/train.js
8133
- import { join as join3 } from "node:path";
8134
-
8135
- // ../lib/dist/doctor.js
8136
- import { relative as relative2 } from "node:path";
8137
- function diagnose(root, catalog) {
8138
- const units = collect(root, []);
8139
- const declarations = units.map((u) => diagnoseUnit(u, units, catalog, root.path));
8140
- return { declarations, stale: declarations.filter((d) => d.findings.length > 0).length };
8141
- }
8142
- function collect(dir, ancestors, parent) {
8143
- const here = dir.declaration || dir.problems?.some((p) => p.startsWith("PLEXUS.md")) ? [{ dir, ancestors, parent }] : [];
8144
- const below = dir.declaration ? [...ancestors, dir] : ancestors;
8145
- return [...here, ...dir.children.flatMap((c) => collect(c, below, dir))];
8146
- }
8147
- function diagnoseUnit(unit, units, catalog, root) {
8148
- const { dir } = unit;
8149
- const path3 = relative2(root, dir.path) || ".";
8150
- const problem = dir.problems?.find((p) => p.startsWith("PLEXUS.md"));
8151
- if (!dir.declaration)
8152
- return { path: path3, modules: [], findings: [problem?.replace(/^PLEXUS\.md: /, "") ?? "unreadable marker"] };
8153
- const { plexus, modules } = dir.declaration;
8154
- const context = new Set(contextOf(unit, units).flatMap((d) => d.declaration?.modules ?? []));
8155
- const findings = [];
8156
- for (const code of modules) {
8157
- const module = catalog.get(code);
8158
- if (!module) {
8159
- findings.push(`declares ${code}, which no module carries`);
8160
- continue;
8161
- }
8162
- if (module.changed && compareTrains(module.changed, plexus) > 0)
8163
- findings.push(`${code} changed in ${module.changed}, declared at ${plexus}`);
8164
- for (const dep of module.depends)
8165
- if (!modules.includes(dep) && !context.has(dep))
8166
- findings.push(`${code} depends on ${dep}, declared neither here nor by an enclosing or contained declaration`);
8167
- }
8168
- return { path: path3, plexus, modules, findings };
8169
- }
8170
- function contextOf(unit, units) {
8171
- const { dir, ancestors } = unit;
8172
- const context = [...ancestors, ...descendants(dir)];
8173
- const repo = ancestors[0] ?? dir;
8174
- const repoParent = units.find((u) => u.dir === repo)?.parent;
8175
- const siblings = repoParent?.children.filter((c) => c !== repo && c.declaration) ?? [];
8176
- const isTenancy = (d) => d.declaration?.modules.includes("PLX-Tenancy") ?? false;
8177
- context.push(...siblings.filter(isTenancy));
8178
- if (isTenancy(dir))
8179
- context.push(...siblings);
8180
- return context;
8181
- }
8182
- function descendants(dir) {
8183
- return dir.children.flatMap((c) => [...c.declaration ? [c] : [], ...descendants(c)]);
8184
- }
8185
- function compareTrains(a, b) {
8186
- const nums = (v) => v.split(".").slice(0, 3).map((p) => Number.parseInt(p, 10) || 0);
8187
- const [x, y] = [nums(a), nums(b)];
8188
- for (let i = 0; i < 3; i++)
8189
- if ((x[i] ?? 0) !== (y[i] ?? 0))
8190
- return (x[i] ?? 0) > (y[i] ?? 0) ? 1 : -1;
8191
- return 0;
8192
- }
8193
-
8194
- // ../lib/dist/train.js
8195
- var PRIMITIVES = "primitives";
8196
- var TRAIN_REPOS = [
8197
- PRIMITIVES,
8198
- "preset-repo-turbo",
8199
- "preset-app-nextjs",
8200
- "preset-repo-operations",
8201
- "compendium"
8202
- ];
8203
- var PHASES = [[PRIMITIVES], TRAIN_REPOS.filter((r) => r !== PRIMITIVES)];
8204
- var TRAIN_PACKAGES = [
8205
- { name: "@plexus-ms/cli", dir: "packages/cli" },
8206
- { name: "@plexus-ms/cli-ci", dir: "packages/cli-ci" },
8207
- { name: "@plexus-ms/lib", dir: "packages/lib" },
8208
- { name: "@plexus-ms/config", dir: "packages/config" }
8209
- ];
8210
- var UPSTREAM = "plexus-ms";
8211
- var isTrainVersion = (v) => /^\d+\.\d+\.\d+$/.test(v);
8212
- function nextMinor(version2) {
8213
- const [major = "0", minor = "0"] = version2.split(".");
8214
- return `${major}.${Number(minor) + 1}.0`;
8215
- }
8216
- function latestTag(tags) {
8217
- return tags.filter((t) => /^v?\d+(\.\d+){1,2}$/.test(t)).sort((a, b) => compareTrains(a.replace(/^v/, ""), b.replace(/^v/, ""))).at(-1);
8218
- }
8219
- async function readTrain(ctx, upstream) {
8220
- const repos2 = [];
8221
- const all = /* @__PURE__ */ new Set();
8222
- for (const name of TRAIN_REPOS) {
8223
- const path3 = join3(upstream, name);
8224
- try {
8225
- await ctx.read("git", ["rev-parse", "--git-dir"], { cwd: path3 });
8226
- } catch {
8227
- throw new Error(`${path3} is not a git repo`);
8228
- }
8229
- try {
8230
- await ctx.read("git", ["fetch", "origin", "--tags", "--quiet"], { cwd: path3 });
8231
- } catch {
8232
- throw new Error(`${name}: fetch from origin failed`);
8233
- }
8234
- const tags = (await ctx.read("git", ["tag", "--list", "v*", "[0-9]*"], { cwd: path3 })).split("\n").filter(Boolean);
8235
- for (const t of tags)
8236
- all.add(t.replace(/^v/, ""));
8237
- const tag = latestTag(tags);
8238
- const range = tag ? `${tag}..HEAD` : "HEAD";
8239
- const pending = (await ctx.read("git", ["log", "--oneline", range], { cwd: path3 })).split("\n").filter(Boolean);
8240
- repos2.push({ name, path: path3, tag, latest: tag?.replace(/^v/, ""), pending });
8241
- }
8242
- const latest = repos2.map((r) => r.latest);
8243
- return { repos: repos2, last: latestTag([...all]), skew: latest.some((l) => l !== latest[0]) };
8244
- }
8245
- var phasesOf = (train) => PHASES.map((names) => train.repos.filter((r) => names.includes(r.name)));
8246
- async function preflightRelease(ctx, train) {
8247
- for (const { name, path: path3 } of train.repos) {
8248
- const branch = (await ctx.read("git", ["rev-parse", "--abbrev-ref", "HEAD"], { cwd: path3 })).trim();
8249
- if (branch !== "main")
8250
- throw new Error(`${name} is on '${branch}', trains cut from main`);
8251
- if ((await ctx.read("git", ["status", "--porcelain"], { cwd: path3 })).trim() !== "")
8252
- throw new Error(`${name} has uncommitted changes \u2014 commit first`);
8253
- const behind = (await ctx.read("git", ["rev-list", "--count", "main..origin/main"], { cwd: path3 })).trim();
8254
- if (behind !== "0")
8255
- throw new Error(`${name} is ${behind} commit(s) behind origin/main \u2014 pull first, or the tag lands on a stale commit`);
8256
- }
8257
- }
8258
- async function preflightForge(ctx) {
8259
- try {
8260
- await ctx.read("gh", ["auth", "status"]);
8261
- } catch {
8262
- throw new Error("gh is not logged in (gh auth status failed) \u2014 run gh auth login first");
8263
- }
8264
- }
8265
- function resolveVersion(train, explicit, propagateOnly) {
8266
- if (explicit !== void 0 && !isTrainVersion(explicit))
8267
- throw new UsageError(`'${explicit}' is not plain semver (X.Y.Z, no v)`);
8268
- if (propagateOnly) {
8269
- const v = explicit ?? train.last;
8270
- if (!v)
8271
- throw new Error("no train version found to propagate");
8272
- return v;
8273
- }
8274
- if (explicit)
8275
- return explicit;
8276
- if (train.skew) {
8277
- const report = train.repos.map((r) => ` ${r.name}: ${r.latest ?? "none"}`).join("\n");
8278
- throw new Error(`the train repos' latest tags disagree:
8279
- ${report}
8280
- pass the version explicitly (--train ${train.last}) to finish the half-tagged train, or a higher one to start a new one`);
8244
+ env: step.env === void 0 ? void 0 : { ...process.env, ...step.env }
8245
+ });
8246
+ case "write":
8247
+ await this.io.writeFile(step.path, step.content);
8248
+ return void 0;
8249
+ }
8281
8250
  }
8282
- return train.last ? nextMinor(train.last) : "0.1.0";
8283
- }
8284
- var UsageError = class extends Error {
8285
8251
  };
8252
+ function renderHuman(data) {
8253
+ if (typeof data === "string")
8254
+ return data;
8255
+ if (Array.isArray(data))
8256
+ return data.map(String).join("\n");
8257
+ return JSON.stringify(data, null, 2);
8258
+ }
8259
+ function indent(text) {
8260
+ return text.trimEnd().split("\n").map((l) => ` ${l}`).join("\n");
8261
+ }
8262
+
8263
+ // ../lib/dist/copier.js
8264
+ var import_yaml3 = __toESM(require_dist(), 1);
8265
+ var ANSWERS_FILE = ".copier-answers.yml";
8266
+ var TEMPLATE_FILES = ["copier.yml", "copier.yaml"];
8267
+ var COPIER_VERSION = "9.19.1";
8268
+ var copierVia = (args) => ["exec", `copier@${COPIER_VERSION}`, "--", "copier", ...args];
8269
+ function parseAnswers(text) {
8270
+ const data = (0, import_yaml3.parse)(text);
8271
+ if (data === null || typeof data !== "object" || Array.isArray(data))
8272
+ throw new Error("answers file is not a mapping");
8273
+ const { _commit, _src_path, ...answers } = data;
8274
+ return {
8275
+ commit: _commit === void 0 ? void 0 : String(_commit),
8276
+ src: _src_path === void 0 ? void 0 : String(_src_path),
8277
+ answers
8278
+ };
8279
+ }
8280
+
8281
+ // ../lib/dist/deploy.js
8282
+ import { randomBytes } from "node:crypto";
8283
+ import { tmpdir } from "node:os";
8284
+ import { join as join5 } from "node:path";
8286
8285
 
8287
8286
  // ../lib/dist/deployTargets.js
8287
+ var import_yaml4 = __toESM(require_dist(), 1);
8288
+ import { join as join4 } from "node:path";
8288
8289
  var VARS_DIRS = ["group_vars", "host_vars"];
8289
8290
  var DEFAULT_ENVIRONMENT = "production";
8290
8291
  function deploymentSlug(app, environment = DEFAULT_ENVIRONMENT) {
@@ -8575,6 +8576,54 @@ function isNotable(dir) {
8575
8576
  return Boolean(dir.git || dir.template || dir.copier || dir.declaration || dir.problems?.length);
8576
8577
  }
8577
8578
 
8579
+ // ../lib/dist/need.js
8580
+ var DEFAULT_MAX_AGE = 30;
8581
+ var MAX_AGE_ANSWER = "update_max_age";
8582
+ var DAY = 24 * 60 * 60 * 1e3;
8583
+ var days = (n) => `${n} day${n === 1 ? "" : "s"}`;
8584
+ function needOf({ recorded, releases, asked, maxAge, now }) {
8585
+ if (asked)
8586
+ return { take: true, trigger: "asked", why: `asked for (${asked})` };
8587
+ const odd = recorded.findIndex((r) => !r || !isTrainVersion(r));
8588
+ if (recorded.length === 0 || odd >= 0)
8589
+ return {
8590
+ take: true,
8591
+ trigger: "backstop",
8592
+ why: `a site records ${recorded[odd] ? `'${recorded[odd]}'` : "no version"}, not a train`
8593
+ };
8594
+ const trains = recorded;
8595
+ const oldest = trains.reduce((a, b) => compareTrains(a, b) <= 0 ? a : b);
8596
+ 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 first = untaken[0];
8598
+ if (!first)
8599
+ return { take: false, why: `no train newer than ${oldest}` };
8600
+ const age = Math.max(0, Math.floor((now.getTime() - Date.parse(first.published)) / DAY));
8601
+ const count = `${untaken.length} newer train${untaken.length === 1 ? "" : "s"}`;
8602
+ if (maxAge === 0)
8603
+ return { take: true, trigger: "backstop", why: `a backstop age of zero takes every train (${count})` };
8604
+ if (age >= maxAge)
8605
+ return {
8606
+ take: true,
8607
+ trigger: "backstop",
8608
+ why: `${first.train}, the oldest train not taken, was cut ${days(age)} ago (backstop: ${days(maxAge)}; ${count})`
8609
+ };
8610
+ return {
8611
+ take: false,
8612
+ why: `${count}, the oldest (${first.train}) cut ${days(age)} ago; the backstop is ${days(maxAge)}`
8613
+ };
8614
+ }
8615
+ function maxAgeOf(answers) {
8616
+ const value = answers[MAX_AGE_ANSWER];
8617
+ if (value === void 0 || value === null || value === "")
8618
+ return DEFAULT_MAX_AGE;
8619
+ return parseMaxAge(String(value), `the answer ${MAX_AGE_ANSWER}`);
8620
+ }
8621
+ function parseMaxAge(value, what) {
8622
+ if (!/^\d+$/.test(value.trim()))
8623
+ throw new Error(`${what} is '${value}', not a whole number of days`);
8624
+ return Number(value.trim());
8625
+ }
8626
+
8578
8627
  // ../lib/dist/overview.js
8579
8628
  import { join as join6 } from "node:path";
8580
8629
  var PRUNED = /* @__PURE__ */ new Set([
@@ -8703,9 +8752,20 @@ async function templateFacet(ctx, cwd) {
8703
8752
  return tag ? { tag } : {};
8704
8753
  }
8705
8754
 
8706
- // ../lib/dist/propagate.js
8755
+ // ../lib/dist/preview.js
8756
+ import { join as join8 } from "node:path";
8757
+
8758
+ // ../lib/dist/take.js
8707
8759
  import { join as join7, relative as relative3 } from "node:path";
8708
8760
  var isClean = (s) => s.conflicted.length === 0 && s.failed.length === 0 && s.skipped.length === 0;
8761
+ function mergeSummary(into, from) {
8762
+ into.clean.push(...from.clean);
8763
+ into.conflicted.push(...from.conflicted);
8764
+ into.failed.push(...from.failed);
8765
+ into.skipped.push(...from.skipped);
8766
+ into.resting.push(...from.resting);
8767
+ into.pulls.push(...from.pulls);
8768
+ }
8709
8769
  var emptySummary = (train, preview) => ({
8710
8770
  train,
8711
8771
  preview,
@@ -8713,6 +8773,7 @@ var emptySummary = (train, preview) => ({
8713
8773
  conflicted: [],
8714
8774
  failed: [],
8715
8775
  skipped: [],
8776
+ resting: [],
8716
8777
  pulls: []
8717
8778
  });
8718
8779
  var trainBranch = (train) => `plexus/${train}`;
@@ -8720,45 +8781,6 @@ var copierIn = (dir, args) => [
8720
8781
  "env",
8721
8782
  [`MISE_IGNORED_CONFIG_PATHS=${dir}`, "mise", ...copierVia(args)]
8722
8783
  ];
8723
- async function propagate(ctx, workspace, train) {
8724
- const summary = emptySummary(train, ctx.dryRun);
8725
- const upstream = join7(workspace, UPSTREAM);
8726
- const tree = await overview(ctx, workspace);
8727
- const upstreamDir = tree.children.find((c) => c.path === upstream);
8728
- const presets = TRAIN_REPOS.filter((r) => upstreamDir?.children.some((c) => c.name === r && c.template));
8729
- const consumers = await findConsumers(ctx, tree, presets);
8730
- for (const c of consumers) {
8731
- if (!c.skipped)
8732
- continue;
8733
- ctx.say(`\u26A0 ${c.rel}: ${c.skipped} \u2014 skipped (fix it, then re-run propagate)`);
8734
- summary.skipped.push({ path: c.rel, reason: c.skipped });
8735
- }
8736
- for (const preset of presets)
8737
- if (!consumers.some((c) => c.sites.some((s) => s.preset === preset)))
8738
- ctx.say(`\u2022 no consumers of ${presetSource(preset)} found under ${workspace}`);
8739
- const take = { train, opener: "`plx ship`", ...ctx.dryRun ? { previewFrom: upstream } : {} };
8740
- const scratch = (await ctx.stage(run("mktemp", ["-d"])))?.trim() ?? "";
8741
- try {
8742
- for (const consumer of consumers) {
8743
- if (consumer.skipped || !consumer.origin)
8744
- continue;
8745
- const clone = join7(scratch, consumer.rel);
8746
- ctx.say(`\u2192 ${consumer.rel}: clone ${consumer.origin} at ${consumer.branch}`);
8747
- try {
8748
- await ctx.stage(run("git", ["clone", "--quiet", "--branch", consumer.branch, consumer.origin, clone]));
8749
- } catch (error) {
8750
- ctx.say(` \u2717 FAILED \u2014 clone${detail(error)}`);
8751
- summary.failed.push(consumer.rel);
8752
- continue;
8753
- }
8754
- await takeTrain(ctx, consumer, clone, take, summary);
8755
- }
8756
- } finally {
8757
- if (scratch)
8758
- await ctx.stage(run("rm", ["-rf", scratch]));
8759
- }
8760
- return summary;
8761
- }
8762
8784
  async function takeTrain(ctx, consumer, dir, take, summary) {
8763
8785
  const base = (await ctx.read("git", ["rev-parse", "HEAD"], { cwd: dir })).trim();
8764
8786
  for (const site of consumer.sites)
@@ -8931,7 +8953,7 @@ async function openPull(ctx, consumer, dir, take, summary) {
8931
8953
  const body2 = [
8932
8954
  `Train ${train} (\xA7 1.5 PLX): \`copier update\` at ${sites.join(", ")}, the marker, the lockfile where manifests moved, and the workflow refs.`,
8933
8955
  conflicted.length > 0 ? `Conflicts to resolve, committed with their markers: ${conflicted.join(", ")}.` : "Merged clean at every site.",
8934
- `Opened by ${take.opener}.`
8956
+ `Opened by ${take.opener}${take.why ? `: ${take.why}` : ""}.`
8935
8957
  ].join("\n\n");
8936
8958
  try {
8937
8959
  await ctx.apply([
@@ -8963,8 +8985,168 @@ var detail = (error) => {
8963
8985
  return last && !/exited with/.test(last) ? `: ${last}` : "";
8964
8986
  };
8965
8987
 
8988
+ // ../lib/dist/preview.js
8989
+ async function previewConsumers(ctx, workspace, train) {
8990
+ const summary = emptySummary(train, ctx.dryRun);
8991
+ const upstream = join8(workspace, UPSTREAM);
8992
+ const tree = await overview(ctx, workspace);
8993
+ const upstreamDir = tree.children.find((c) => c.path === upstream);
8994
+ const presets = TRAIN_REPOS.filter((r) => upstreamDir?.children.some((c) => c.name === r && c.template));
8995
+ const consumers = await findConsumers(ctx, tree, presets);
8996
+ for (const c of consumers) {
8997
+ if (!c.skipped)
8998
+ continue;
8999
+ ctx.say(`\u26A0 ${c.rel}: ${c.skipped} \u2014 not previewed`);
9000
+ summary.skipped.push({ path: c.rel, reason: c.skipped });
9001
+ }
9002
+ for (const preset of presets)
9003
+ if (!consumers.some((c) => c.sites.some((s) => s.preset === preset)))
9004
+ ctx.say(`\u2022 no consumers of ${presetSource(preset)} found under ${workspace}`);
9005
+ const take = { train, opener: "`plx ship`", previewFrom: upstream };
9006
+ const scratch = (await ctx.stage(run("mktemp", ["-d"])))?.trim() ?? "";
9007
+ try {
9008
+ for (const consumer of consumers) {
9009
+ if (consumer.skipped || !consumer.origin)
9010
+ continue;
9011
+ const clone = join8(scratch, consumer.rel);
9012
+ ctx.say(`\u2192 ${consumer.rel}: clone ${consumer.origin} at ${consumer.branch}`);
9013
+ try {
9014
+ await ctx.stage(run("git", ["clone", "--quiet", "--branch", consumer.branch, consumer.origin, clone]));
9015
+ } catch (error) {
9016
+ ctx.say(` \u2717 FAILED \u2014 clone${detail(error)}`);
9017
+ summary.failed.push(consumer.rel);
9018
+ continue;
9019
+ }
9020
+ await takeTrain(ctx, consumer, clone, take, summary);
9021
+ }
9022
+ } finally {
9023
+ if (scratch)
9024
+ await ctx.stage(run("rm", ["-rf", scratch]));
9025
+ }
9026
+ return summary;
9027
+ }
9028
+
9029
+ // ../lib/dist/update.js
9030
+ import { basename, join as join9, relative as relative4 } from "node:path";
9031
+ async function update(ctx, options) {
9032
+ const { repo } = options;
9033
+ const name = options.name ?? basename(repo);
9034
+ if (options.train !== void 0 && !isTrainVersion(options.train))
9035
+ throw new UsageError(`'${options.train}' is not plain semver (X.Y.Z, no v)`);
9036
+ const tree = await overview(ctx, repo);
9037
+ const consumer = (await findConsumers(ctx, tree, PRESETS)).find((c) => c.path === tree.path);
9038
+ if (!consumer)
9039
+ throw new Error(`${repo} is not a repo generated from the presets: no ${ANSWERS_FILE} at its root naming one of ${PRESETS.map(presetSource).join(", ")}`);
9040
+ if (consumer.skipped)
9041
+ throw new Error(`${name}: ${consumer.skipped}`);
9042
+ consumer.rel = name;
9043
+ for (const s of consumer.sites)
9044
+ s.rel = s.rel === "." ? name : join9(name, s.rel);
9045
+ const root = consumer.sites.find((s) => s.path === consumer.path);
9046
+ if (!root)
9047
+ throw new Error(`${name}: its root is not a site of a repo preset`);
9048
+ await preflightForge(ctx);
9049
+ const releases = options.train === void 0 ? await releasesOf(ctx, root.preset) : [];
9050
+ const train = options.train ?? newestOf(releases, root.preset);
9051
+ const summary = emptySummary(train, ctx.dryRun);
9052
+ await ctx.read("git", ["fetch", "--quiet", "origin", consumer.branch], { cwd: repo }).catch(() => "");
9053
+ const answers = await Promise.all(consumer.sites.map(async (s) => {
9054
+ const file = join9(relative4(consumer.path, s.path), ANSWERS_FILE);
9055
+ const onOrigin2 = await ctx.read("git", ["show", `origin/${consumer.branch}:${file}`], { cwd: repo }).catch(() => void 0);
9056
+ return parseAnswers(onOrigin2 ?? await ctx.readFile(join9(s.path, ANSWERS_FILE)));
9057
+ }));
9058
+ const recorded = answers.map((a) => a.commit);
9059
+ if (recorded.every((c) => c === train)) {
9060
+ ctx.say(`\u2022 ${name}: already at ${train}`);
9061
+ return summary;
9062
+ }
9063
+ const past = recorded.find((c) => c && isTrainVersion(c) && compareTrains(c, train) > 0);
9064
+ if (past)
9065
+ throw new Error(`${name} is at ${past}, past ${train}; a repo is never taken back to an older train`);
9066
+ const branch = trainBranch(train);
9067
+ const onOrigin = await ctx.read("git", ["ls-remote", "--exit-code", "--heads", "origin", `refs/heads/${branch}`], { cwd: repo }).then(() => true).catch(() => false);
9068
+ if (onOrigin) {
9069
+ const url = await openPullUrl(ctx, consumer, repo, train);
9070
+ ctx.say(`\u2022 ${name}: ${branch} is already on origin${url ? ` (${url})` : ""} \u2014 nothing to do; delete the branch to pull the train again`);
9071
+ if (url)
9072
+ summary.pulls.push(url);
9073
+ return summary;
9074
+ }
9075
+ const need = needOf({
9076
+ recorded,
9077
+ releases,
9078
+ asked: options.train !== void 0 ? `--train ${train}` : options.now ? "--now" : void 0,
9079
+ maxAge: options.maxAge ?? maxAgeOf(answers[consumer.sites.indexOf(root)]?.answers ?? {}),
9080
+ now: options.today === void 0 ? /* @__PURE__ */ new Date() : new Date(options.today)
9081
+ });
9082
+ if (!need.take) {
9083
+ ctx.say(`\u2022 ${name}: rests \u2014 ${need.why} (plx update --now takes ${train})`);
9084
+ summary.resting.push({ path: name, reason: need.why });
9085
+ return summary;
9086
+ }
9087
+ ctx.say(`\u2022 ${name}: takes ${train} \u2014 ${need.why}`);
9088
+ const scratch = (await ctx.stage(run("mktemp", ["-d"])))?.trim() ?? "";
9089
+ const dir = join9(scratch, name);
9090
+ try {
9091
+ ctx.say(`\u2192 ${name}: worktree of origin/${consumer.branch}`);
9092
+ try {
9093
+ await ctx.stage(run("git", ["fetch", "--quiet", "origin", consumer.branch], { cwd: repo }));
9094
+ await ctx.stage(run("git", ["worktree", "add", "--quiet", "--detach", dir, `origin/${consumer.branch}`], { cwd: repo }));
9095
+ } catch (error) {
9096
+ ctx.say(` \u2717 FAILED \u2014 worktree of origin/${consumer.branch}${detail(error)}`);
9097
+ summary.failed.push(name);
9098
+ return summary;
9099
+ }
9100
+ await takeTrain(ctx, consumer, dir, { train, ref: train, opener: "`plx update`", why: need.why }, summary);
9101
+ } finally {
9102
+ await ctx.stage(run("git", ["worktree", "remove", "--force", dir], { cwd: repo })).catch(() => void 0);
9103
+ if (scratch)
9104
+ await ctx.stage(run("rm", ["-rf", scratch]));
9105
+ }
9106
+ return summary;
9107
+ }
9108
+ async function releasesOf(ctx, preset) {
9109
+ const source = presetSource(preset).replace(/^gh:/, "");
9110
+ const jq = '.[] | select(.draft | not) | "\\(.tag_name) \\(.published_at)"';
9111
+ const lines = await ctx.read("gh", ["api", `repos/${source}/releases`, "--paginate", "--jq", jq]).catch(() => "");
9112
+ return lines.split("\n").map((l) => l.trim().split(/\s+/)).filter((p) => p.length === 2 && isTrainVersion(p[0] ?? "")).map(([train, published]) => ({ train, published }));
9113
+ }
9114
+ function newestOf(releases, preset) {
9115
+ const newest = releases.map((r) => r.train).reduce((a, b) => a && compareTrains(a, b) >= 0 ? a : b, "");
9116
+ if (!newest)
9117
+ throw new Error(`no release of ${presetSource(preset).replace(/^gh:/, "")} found \u2014 pass the train explicitly (--train <version>)`);
9118
+ return newest;
9119
+ }
9120
+
9121
+ // ../lib/dist/propagate.js
9122
+ async function propagate(ctx, options) {
9123
+ const { dir, ...rest } = options;
9124
+ if (options.train !== void 0 && !isTrainVersion(options.train))
9125
+ throw new UsageError(`'${options.train}' is not plain semver (X.Y.Z, no v)`);
9126
+ const summary = emptySummary(options.train ?? "", ctx.dryRun);
9127
+ const consumers = await findConsumers(ctx, await overview(ctx, dir), PRESETS);
9128
+ if (consumers.length === 0)
9129
+ ctx.say(`\u2022 no repo generated from ${PRESETS.map(presetSource).join(", ")} found under ${dir}`);
9130
+ for (const consumer of consumers) {
9131
+ if (consumer.skipped) {
9132
+ ctx.say(`\u26A0 ${consumer.rel}: ${consumer.skipped} \u2014 skipped (fix it, then re-run propagate)`);
9133
+ summary.skipped.push({ path: consumer.rel, reason: consumer.skipped });
9134
+ continue;
9135
+ }
9136
+ try {
9137
+ const one = await update(ctx, { repo: consumer.path, name: consumer.rel, ...rest });
9138
+ mergeSummary(summary, one);
9139
+ summary.train ||= one.train;
9140
+ } catch (error) {
9141
+ ctx.say(` \u2717 FAILED \u2014 ${consumer.rel}${detail(error)}`);
9142
+ summary.failed.push(consumer.rel);
9143
+ }
9144
+ }
9145
+ return summary;
9146
+ }
9147
+
8966
9148
  // ../lib/dist/requirements.js
8967
- import { join as join8 } from "node:path";
9149
+ import { join as join10 } from "node:path";
8968
9150
  var KEYWORD = /MUST|SHOULD|MAY/;
8969
9151
  var hasKeyword = (line) => KEYWORD.test(line.replace(/MUSTs|SHOULDs|MAYs/g, ""));
8970
9152
  var list = (value) => value.replace(/^\s*\[/, "").replace(/\].*$/, "").split(",").map((s) => s.trim()).filter(Boolean);
@@ -9057,7 +9239,7 @@ var MAP_PAGE = "essentials/standard.md";
9057
9239
  async function modulePages(ctx, compendium) {
9058
9240
  const pages = [];
9059
9241
  for (const dir of Object.keys(CATALOG_DIRS)) {
9060
- const entries = await ctx.readDir(join8(compendium, dir));
9242
+ const entries = await ctx.readDir(join10(compendium, dir));
9061
9243
  for (const e of entries.filter((e2) => !e2.directory && e2.name.endsWith(".md") && e2.name !== "index.md").sort())
9062
9244
  pages.push(`${dir}/${e.name}`);
9063
9245
  }
@@ -9065,11 +9247,11 @@ async function modulePages(ctx, compendium) {
9065
9247
  }
9066
9248
  async function checkCompendium(ctx, compendium) {
9067
9249
  const defects = [];
9068
- defects.push(...scanPage(await ctx.readFile(join8(compendium, MAP_PAGE)), MAP_PAGE, "map").defects);
9250
+ defects.push(...scanPage(await ctx.readFile(join10(compendium, MAP_PAGE)), MAP_PAGE, "map").defects);
9069
9251
  const pages = await modulePages(ctx, compendium);
9070
9252
  const scans = /* @__PURE__ */ new Map();
9071
9253
  for (const page of pages) {
9072
- const scan = scanPage(await ctx.readFile(join8(compendium, page)), page, "module");
9254
+ const scan = scanPage(await ctx.readFile(join10(compendium, page)), page, "module");
9073
9255
  defects.push(...scan.defects);
9074
9256
  scans.set(page, scan);
9075
9257
  }
@@ -9128,24 +9310,22 @@ async function preflightSelf(ctx, running) {
9128
9310
  }
9129
9311
 
9130
9312
  // ../lib/dist/ship.js
9131
- import { join as join9 } from "node:path";
9313
+ import { join as join11 } from "node:path";
9132
9314
  var DEFAULT_WAIT = { interval: 15e3, timeout: 20 * 6e4 };
9133
9315
  async function ship(ctx, options) {
9134
- const upstream = join9(options.workspace, UPSTREAM);
9135
- const propagateOnly = options.propagateOnly ?? false;
9316
+ const upstream = join11(options.workspace, UPSTREAM);
9136
9317
  if (options.plx)
9137
9318
  await preflightSelf(ctx, options.plx);
9138
9319
  const train = await readTrain(ctx, upstream);
9139
9320
  await preflightForge(ctx);
9140
- if (!propagateOnly) {
9141
- await preflightRelease(ctx, train);
9142
- await preflightImmutable(ctx, train);
9143
- }
9144
- const next = resolveVersion(train, options.train, propagateOnly);
9145
- if (!propagateOnly)
9146
- await release(ctx, train, next, options.today ?? today(), { ...DEFAULT_WAIT, ...options.wait });
9147
- const summary = await propagate(ctx, options.workspace, next);
9148
- return { ...summary, released: !propagateOnly };
9321
+ await preflightRelease(ctx, train);
9322
+ await preflightImmutable(ctx, train);
9323
+ const next = resolveVersion(train, options.train, false);
9324
+ await release(ctx, train, next, options.today ?? today(), { ...DEFAULT_WAIT, ...options.wait });
9325
+ if (ctx.dryRun)
9326
+ return { ...await previewConsumers(ctx, options.workspace, next), released: true };
9327
+ ctx.say(`\u2022 train ${next} is cut; every repo takes it itself, when it needs it (plx update)`);
9328
+ return { ...emptySummary(next, false), released: true };
9149
9329
  }
9150
9330
  async function preflightImmutable(ctx, train) {
9151
9331
  for (const repo of train.repos) {
@@ -9242,7 +9422,7 @@ async function planBookkeeping(ctx, train, repos2, next, today2) {
9242
9422
  const touched = /* @__PURE__ */ new Set();
9243
9423
  const repo = (name) => repos2.find((r) => r.name === name);
9244
9424
  const edit = async (r, rel, what, transform) => {
9245
- const path3 = join9(r.path, rel);
9425
+ const path3 = join11(r.path, rel);
9246
9426
  const text = await ctx.readFile(path3).catch(() => void 0);
9247
9427
  if (text === void 0)
9248
9428
  return;
@@ -9279,7 +9459,7 @@ async function planBookkeeping(ctx, train, repos2, next, today2) {
9279
9459
  if (comp) {
9280
9460
  await edit(comp, MAP_PAGE, `version \u2192 ${next}, timestamp \u2192 ${today2}`, (t) => stampStandard(t, next, today2));
9281
9461
  for (const page of await modulePages(ctx, comp.path)) {
9282
- const text = await ctx.readFile(join9(comp.path, page));
9462
+ const text = await ctx.readFile(join11(comp.path, page));
9283
9463
  if (frontmatterField(text, "maturity") !== "standard")
9284
9464
  continue;
9285
9465
  const previous = comp.tag ? await ctx.read("git", ["show", `${comp.tag}:${page}`], { cwd: comp.path }).catch(() => "") : "";
@@ -9297,76 +9477,6 @@ async function planBookkeeping(ctx, train, repos2, next, today2) {
9297
9477
  return plan;
9298
9478
  }
9299
9479
 
9300
- // ../lib/dist/update.js
9301
- import { basename, join as join10 } from "node:path";
9302
- var PRESETS = TRAIN_REPOS.filter((r) => r.startsWith("preset-"));
9303
- async function update(ctx, options) {
9304
- const { repo } = options;
9305
- const name = basename(repo);
9306
- if (options.train !== void 0 && !isTrainVersion(options.train))
9307
- throw new UsageError(`'${options.train}' is not plain semver (X.Y.Z, no v)`);
9308
- const tree = await overview(ctx, repo);
9309
- const consumer = (await findConsumers(ctx, tree, PRESETS)).find((c) => c.path === tree.path);
9310
- if (!consumer)
9311
- throw new Error(`${repo} is not a repo generated from the presets: no ${ANSWERS_FILE} at its root naming one of ${PRESETS.map(presetSource).join(", ")}`);
9312
- if (consumer.skipped)
9313
- throw new Error(`${name}: ${consumer.skipped}`);
9314
- consumer.rel = name;
9315
- for (const s of consumer.sites)
9316
- s.rel = s.rel === "." ? name : join10(name, s.rel);
9317
- const root = consumer.sites.find((s) => s.path === consumer.path);
9318
- if (!root)
9319
- throw new Error(`${name}: its root is not a site of a repo preset`);
9320
- await preflightForge(ctx);
9321
- const train = options.train ?? await newestTrain(ctx, root.preset);
9322
- const summary = emptySummary(train, ctx.dryRun);
9323
- const recorded = await Promise.all(consumer.sites.map(async (s) => parseAnswers(await ctx.readFile(join10(s.path, ANSWERS_FILE))).commit));
9324
- if (recorded.every((c) => c === train)) {
9325
- ctx.say(`\u2022 ${name}: already at ${train}`);
9326
- return summary;
9327
- }
9328
- const past = recorded.find((c) => c && isTrainVersion(c) && compareTrains(c, train) > 0);
9329
- if (past)
9330
- throw new Error(`${name} is at ${past}, past ${train}; a repo is never taken back to an older train`);
9331
- const branch = trainBranch(train);
9332
- const onOrigin = await ctx.read("git", ["ls-remote", "--exit-code", "--heads", "origin", `refs/heads/${branch}`], { cwd: repo }).then(() => true).catch(() => false);
9333
- if (onOrigin) {
9334
- const url = await openPullUrl(ctx, consumer, repo, train);
9335
- ctx.say(`\u2022 ${name}: ${branch} is already on origin${url ? ` (${url})` : ""} \u2014 nothing to do; delete the branch to pull the train again`);
9336
- if (url)
9337
- summary.pulls.push(url);
9338
- return summary;
9339
- }
9340
- const scratch = (await ctx.stage(run("mktemp", ["-d"])))?.trim() ?? "";
9341
- const dir = join10(scratch, name);
9342
- try {
9343
- ctx.say(`\u2192 ${name}: worktree of origin/${consumer.branch}`);
9344
- try {
9345
- await ctx.stage(run("git", ["fetch", "--quiet", "origin", consumer.branch], { cwd: repo }));
9346
- await ctx.stage(run("git", ["worktree", "add", "--quiet", "--detach", dir, `origin/${consumer.branch}`], { cwd: repo }));
9347
- } catch (error) {
9348
- ctx.say(` \u2717 FAILED \u2014 worktree of origin/${consumer.branch}${detail(error)}`);
9349
- summary.failed.push(name);
9350
- return summary;
9351
- }
9352
- await takeTrain(ctx, consumer, dir, { train, ref: train, opener: "`plx update`" }, summary);
9353
- } finally {
9354
- await ctx.stage(run("git", ["worktree", "remove", "--force", dir], { cwd: repo })).catch(() => void 0);
9355
- if (scratch)
9356
- await ctx.stage(run("rm", ["-rf", scratch]));
9357
- }
9358
- return summary;
9359
- }
9360
- async function newestTrain(ctx, preset) {
9361
- const source = presetSource(preset).replace(/^gh:/, "");
9362
- const tag = (await ctx.read("gh", ["api", `repos/${source}/releases/latest`, "--jq", ".tag_name"]).catch(() => "")).trim();
9363
- if (!tag)
9364
- throw new Error(`no release of ${source} found \u2014 pass the train explicitly (--train <version>)`);
9365
- if (!isTrainVersion(tag))
9366
- throw new Error(`the newest release of ${source} is '${tag}', not a train`);
9367
- return tag;
9368
- }
9369
-
9370
9480
  // src/program.ts
9371
9481
  import { createRequire } from "node:module";
9372
9482
 
@@ -14308,7 +14418,7 @@ function register3(program2) {
14308
14418
 
14309
14419
  // src/commands/doctor.ts
14310
14420
  import { existsSync } from "node:fs";
14311
- import { join as join11, resolve as resolve4 } from "node:path";
14421
+ import { join as join12, resolve as resolve4 } from "node:path";
14312
14422
 
14313
14423
  // src/style.ts
14314
14424
  function style(enabled) {
@@ -14326,8 +14436,8 @@ function register4(program2) {
14326
14436
  ).option("--color", "colour the report even when piped").option("--no-color", "never colour the report").action(async (dir, opts, command) => {
14327
14437
  const ctx = contextOf2(command);
14328
14438
  const root = resolve4(dir);
14329
- const compendium = resolve4(opts.compendium ?? join11(root, WORKSPACE_COMPENDIUM));
14330
- if (!existsSync(join11(compendium, "contracts")))
14439
+ const compendium = resolve4(opts.compendium ?? join12(root, WORKSPACE_COMPENDIUM));
14440
+ if (!existsSync(join12(compendium, "contracts")))
14331
14441
  throw new Error(
14332
14442
  `no compendium at ${compendium}; pass --compendium <path to a checkout of plexus-ms/compendium>`
14333
14443
  );
@@ -14409,11 +14519,14 @@ import { resolve as resolve7 } from "node:path";
14409
14519
  import { resolve as resolve6 } from "node:path";
14410
14520
  function register6(program2) {
14411
14521
  program2.command("ship").description(
14412
- "release the train: tag and release every train repo identically, then open a pull request per consumer"
14413
- ).argument("[dir]", "the workspace: plexus-ms/ and the consumers sit under it", ".").option("--train <version>", "the train version, plain semver (default: minor+1 over the latest train)").action(async (dir, opts, command) => {
14522
+ "cut the train: tag and release every train repo identically; repos take it themselves (update, propagate)"
14523
+ ).argument("[dir]", "the workspace: plexus-ms/ sits under it, and the consumers the dry run previews", ".").option("--train <version>", "the train version, plain semver (default: minor+1 over the latest train)").action(async (dir, opts, command) => {
14414
14524
  const ctx = contextOf2(command);
14415
14525
  const result = await ship(ctx, { workspace: resolve6(dir), train: opts.train, plx: version });
14416
- ctx.result(result, (r) => renderSummary(r, `plx -y ship --train ${r.train} ${dir}`));
14526
+ ctx.result(
14527
+ result,
14528
+ (r) => r.preview ? renderSummary(r, `plx -y ship --train ${r.train} ${dir}`, "ship") : `\u2713 train ${r.train} cut \u2014 repos take it themselves; to take it now where it matters: plx propagate --now ${dir}`
14529
+ );
14417
14530
  if (!isClean(result)) process.exitCode = 1;
14418
14531
  });
14419
14532
  }
@@ -14423,36 +14536,48 @@ function renderSummary(s, realCommand, verb = "propagate") {
14423
14536
  for (const p of s.conflicted) lines.push(` \u2717 conflicts: ${p}`);
14424
14537
  for (const p of s.failed) lines.push(` \u2717 failed: ${p}`);
14425
14538
  for (const { path: path3, reason } of s.skipped) lines.push(` \u26A0 skipped: ${path3} (${reason})`);
14539
+ for (const { path: path3, reason } of s.resting) lines.push(` \u2022 resting: ${path3} (${reason})`);
14426
14540
  for (const url of s.pulls) lines.push(` \u2192 pull: ${url}`);
14427
14541
  const clean = isClean(s);
14428
- if (s.preview) {
14542
+ const idle = clean && s.clean.length === 0 && s.pulls.length === 0;
14543
+ if (s.preview && !idle) {
14429
14544
  lines.push(" (preview only \u2014 nothing was changed)");
14430
14545
  if (clean) lines.push(`\u2713 dry run clean \u2014 run it for real: ${realCommand}`);
14431
14546
  } else if (clean) {
14432
- lines.push("\u2713 done \u2014 review and merge the pull requests");
14547
+ lines.push(s.pulls.length > 0 ? "\u2713 done \u2014 review and merge the pull requests" : "\u2713 done \u2014 no pull request");
14433
14548
  }
14434
- if (!clean) lines.push(`\u2717 needs attention \u2014 see above; fix the consumer, then re-run ${verb}`);
14549
+ if (!clean) lines.push(`\u2717 needs attention \u2014 see above; fix the repo, then re-run ${verb}`);
14435
14550
  return lines.join("\n");
14436
14551
  }
14437
14552
 
14438
14553
  // src/commands/propagate.ts
14439
14554
  function register7(program2) {
14440
- program2.command("propagate").description("copier-update every consumer of the presets to the current train, as one pull request per consumer").argument("[dir]", "the workspace: plexus-ms/ and the consumers sit under it", ".").option("--train <version>", "the train to propagate (default: the current one)").action(async (dir, opts, command) => {
14555
+ program2.command("propagate").description(
14556
+ "run update in every repo generated from the presets under a directory: each takes the newest train when it needs it, as one pull request per repo"
14557
+ ).argument("[dir]", "a directory the repos sit under, at any depth", ".").option(
14558
+ "--train <version>",
14559
+ "the train every repo takes, whatever the triggers say (default: each preset's newest)"
14560
+ ).option("--now", "take the newest train in every repo, whatever the triggers say").option(
14561
+ "--max-age <days>",
14562
+ "the backstop for every repo (default: each repo's answer update_max_age, else 30; 0 takes every train)",
14563
+ (v) => parseMaxAge(v, "--max-age")
14564
+ ).action(async (dir, opts, command) => {
14441
14565
  const ctx = contextOf2(command);
14442
- const result = await ship(ctx, { workspace: resolve7(dir), train: opts.train, propagateOnly: true, plx: version });
14443
- ctx.result(result, (r) => renderSummary(r, `plx -y propagate --train ${r.train} ${dir}`));
14566
+ const result = await propagate(ctx, { dir: resolve7(dir), train: opts.train, now: opts.now, maxAge: opts.maxAge });
14567
+ const flags = [opts.train ? `--train ${opts.train}` : "", opts.now ? "--now" : ""].filter(Boolean).join(" ");
14568
+ ctx.result(result, (r) => renderSummary(r, `plx -y propagate ${flags} ${dir}`.replace(/ +/g, " ")));
14444
14569
  if (!isClean(result)) process.exitCode = 1;
14445
14570
  });
14446
14571
  }
14447
14572
 
14448
14573
  // src/commands/requirements.ts
14449
- import { join as join12, resolve as resolve8 } from "node:path";
14574
+ import { join as join13, resolve as resolve8 } from "node:path";
14450
14575
  function register8(program2) {
14451
14576
  program2.command("requirements").description("lint the standard's map and module pages, or extract one module's requirement lines").argument("[dir]", "a checkout of the compendium", ".").option("--extract <page>", "print a module page's requirement lines instead of linting (path relative to dir)").action(async (dir, opts, command) => {
14452
14577
  const ctx = contextOf2(command);
14453
14578
  const compendium = resolve8(dir);
14454
14579
  if (opts.extract) {
14455
- ctx.result(extractRequirements(await ctx.readFile(join12(compendium, opts.extract))));
14580
+ ctx.result(extractRequirements(await ctx.readFile(join13(compendium, opts.extract))));
14456
14581
  return;
14457
14582
  }
14458
14583
  const check = await checkCompendium(ctx, compendium);
@@ -14469,10 +14594,14 @@ function renderCheck(c) {
14469
14594
  import { resolve as resolve9 } from "node:path";
14470
14595
  function register9(program2) {
14471
14596
  program2.command("update").description(
14472
- "bring this repo up to a train, as a pull request on plexus/<version>: copier update at every site, the marker, the lockfile, the workflow refs"
14473
- ).argument("[dir]", "a repo generated from the presets", ".").option("--train <version>", "the train to take (default: the preset's newest release)").action(async (dir, opts, command) => {
14597
+ "bring this repo up to the newest train when it needs it (asked, or past the backstop age), as a pull request on plexus/<version>: copier update at every site, the marker, the lockfile, the workflow refs"
14598
+ ).argument("[dir]", "a repo generated from the presets", ".").option("--train <version>", "the train to take, whatever the triggers say (default: the preset's newest release)").option("--now", "take the newest train whatever the triggers say").option(
14599
+ "--max-age <days>",
14600
+ "the backstop: take the newest train once the oldest one not taken is this old (default: the repo's answer update_max_age, else 30; 0 takes every train)",
14601
+ (v) => parseMaxAge(v, "--max-age")
14602
+ ).action(async (dir, opts, command) => {
14474
14603
  const ctx = contextOf2(command);
14475
- const result = await update(ctx, { repo: resolve9(dir), train: opts.train });
14604
+ const result = await update(ctx, { repo: resolve9(dir), train: opts.train, now: opts.now, maxAge: opts.maxAge });
14476
14605
  ctx.result(result, (r) => renderSummary(r, `plx -y update --train ${r.train} ${dir}`, "update"));
14477
14606
  if (!isClean(result)) process.exitCode = 1;
14478
14607
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexus-ms/cli",
3
- "version": "0.115.0",
3
+ "version": "0.116.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.115.0",
27
+ "@plexus-ms/lib": "0.116.0",
28
28
  "commander": "^15.0.0"
29
29
  },
30
30
  "devDependencies": {