@plexus-ms/cli 0.8.1 → 0.9.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 +44 -10
  2. package/package.json +2 -2
package/dist/plx.js CHANGED
@@ -8240,7 +8240,7 @@ function latestTag(tags) {
8240
8240
  return tags.filter((t) => /^v?\d/.test(t)).sort((a, b) => compareTrains(a.replace(/^v/, ""), b.replace(/^v/, ""))).at(-1);
8241
8241
  }
8242
8242
  async function readTrain(ctx, upstream) {
8243
- const repos = [];
8243
+ const repos2 = [];
8244
8244
  const all = /* @__PURE__ */ new Set();
8245
8245
  for (const name of TRAIN_REPOS) {
8246
8246
  const path3 = join4(upstream, name);
@@ -8260,10 +8260,10 @@ async function readTrain(ctx, upstream) {
8260
8260
  const tag = latestTag(tags);
8261
8261
  const range = tag ? `${tag}..HEAD` : "HEAD";
8262
8262
  const pending = (await ctx.read("git", ["log", "--oneline", range], { cwd: path3 })).split("\n").filter(Boolean);
8263
- repos.push({ name, path: path3, tag, latest: tag?.replace(/^v/, ""), pending });
8263
+ repos2.push({ name, path: path3, tag, latest: tag?.replace(/^v/, ""), pending });
8264
8264
  }
8265
- const latest = repos.map((r) => r.latest);
8266
- return { repos, last: latestTag([...all]), skew: latest.some((l) => l !== latest[0]) };
8265
+ const latest = repos2.map((r) => r.latest);
8266
+ return { repos: repos2, last: latestTag([...all]), skew: latest.some((l) => l !== latest[0]) };
8267
8267
  }
8268
8268
  async function preflightRelease(ctx, train) {
8269
8269
  for (const { name, path: path3 } of train.repos) {
@@ -8557,8 +8557,41 @@ var PRUNED = /* @__PURE__ */ new Set([
8557
8557
  ".terraform",
8558
8558
  ".gradle"
8559
8559
  ]);
8560
- function overview(ctx, root, options = {}) {
8561
- return walk(ctx, root, root.replace(/\/+$/, "").split("/").pop() || root, { git: true, ...options });
8560
+ var FETCHES = 8;
8561
+ async function overview(ctx, root, options = {}) {
8562
+ const opts = { git: true, fetch: false, ...options };
8563
+ const tree = await walk(ctx, root, root.replace(/\/+$/, "").split("/").pop() || root, opts);
8564
+ if (opts.git && opts.fetch)
8565
+ await syncAll(ctx, repos(tree));
8566
+ return tree;
8567
+ }
8568
+ function repos(dir) {
8569
+ return [...dir.git ? [dir] : [], ...dir.children.flatMap(repos)];
8570
+ }
8571
+ async function syncAll(ctx, dirs) {
8572
+ const queue = [...dirs];
8573
+ const worker = async () => {
8574
+ for (let dir = queue.shift(); dir; dir = queue.shift())
8575
+ await sync(ctx, dir);
8576
+ };
8577
+ await Promise.all(Array.from({ length: Math.min(FETCHES, queue.length) }, worker));
8578
+ }
8579
+ async function sync(ctx, dir) {
8580
+ const facet2 = dir.git;
8581
+ if (!facet2)
8582
+ return;
8583
+ try {
8584
+ await ctx.read("git", ["fetch", "--all", "--quiet"], { cwd: dir.path });
8585
+ } catch (error) {
8586
+ dir.problems ??= [];
8587
+ dir.problems.push(`git fetch: ${error instanceof Error ? error.message : String(error)}`);
8588
+ }
8589
+ const counts = await git(ctx, dir.path, ["rev-list", "--left-right", "--count", "HEAD...@{upstream}"]);
8590
+ const [ahead, behind] = (counts ?? "").split(/\s+/).map(Number);
8591
+ if (ahead === void 0 || behind === void 0 || Number.isNaN(ahead) || Number.isNaN(behind))
8592
+ return;
8593
+ facet2.ahead = ahead;
8594
+ facet2.behind = behind;
8562
8595
  }
8563
8596
  async function walk(ctx, path3, name, options) {
8564
8597
  const entries = await ctx.readDir(path3);
@@ -14035,9 +14068,9 @@ function renderReport(report, s, showCurrent) {
14035
14068
  // src/commands/overview.ts
14036
14069
  import { resolve as resolve6 } from "node:path";
14037
14070
  function register6(program2) {
14038
- program2.command("overview").description("map the git repos, copier templates and projects, and Plexus units under a directory").argument("[dir]", "directory to map", ".").option("--color", "colour the tree even when piped").option("--no-color", "never colour the tree").action(async (dir, opts, command) => {
14071
+ program2.command("overview").description("map the git repos, copier templates and projects, and Plexus units under a directory").argument("[dir]", "directory to map", ".").option("-s, --sync", "fetch every repo first, to show branches behind (or ahead of) their upstream").option("--color", "colour the tree even when piped").option("--no-color", "never colour the tree").action(async (dir, opts, command) => {
14039
14072
  const ctx = contextOf2(command);
14040
- const tree = await overview(ctx, resolve6(dir));
14073
+ const tree = await overview(ctx, resolve6(dir), { fetch: opts.sync ?? false });
14041
14074
  const s = style(opts.color ?? colorByDefault());
14042
14075
  ctx.result(tree, (t) => renderTree(t, s, ctx.verbose >= 1));
14043
14076
  });
@@ -14061,9 +14094,10 @@ function renderTree(root, s, modules) {
14061
14094
  function annotate(dir, s, modules) {
14062
14095
  const tags = [];
14063
14096
  if (dir.git) {
14064
- const { branch, dirty, tag, remote } = dir.git;
14097
+ const { branch, dirty, tag, remote, ahead, behind } = dir.git;
14098
+ const drift = `${behind ? ` \u2193${behind}` : ""}${ahead ? ` \u2191${ahead}` : ""}`;
14065
14099
  const rest = `${tag ? ` ${tag}` : ""}${remote ? ` \u2192 ${remote}` : ""}]`;
14066
- tags.push(`${s.ok(`[${branch}`)}${dirty ? s.warn("*") : ""}${s.ok(rest)}`);
14100
+ tags.push(`${s.ok(`[${branch}`)}${dirty ? s.warn("*") : ""}${drift ? s.warn(drift) : ""}${s.ok(rest)}`);
14067
14101
  }
14068
14102
  if (dir.template) tags.push(s.note(`[template ${dir.template.tag ?? "untagged"}]`));
14069
14103
  if (dir.copier) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexus-ms/cli",
3
- "version": "0.8.1",
3
+ "version": "0.9.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.4",
27
- "@plexus-ms/lib": "0.8.1",
27
+ "@plexus-ms/lib": "0.9.0",
28
28
  "commander": "^15.0.0"
29
29
  },
30
30
  "devDependencies": {