@theholocron/cli 5.6.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -1224,7 +1224,7 @@ const moveTagEntry = {
1224
1224
  // src/commands/new/new-repo.entry.ts
1225
1225
  const newRepoEntry = {
1226
1226
  name: "new repo",
1227
- description: "Scaffold a new repo from a GitHub template (e.g. cli, react, nextjs, node, monorepo, base)",
1227
+ description: "Scaffold a new repo from a GitHub template (e.g. cli, react, nextjs, node, monorepo, monorepo-react, base)",
1228
1228
  positionals: [],
1229
1229
  skipOptions: [
1230
1230
  "description",
@@ -25560,7 +25560,7 @@ function isGenerated(text) {
25560
25560
  }
25561
25561
  // src/commands/probe/tasks/is-scanned.ts
25562
25562
  /** Files that describe the old names on purpose: specs, ADRs, the changelog, tests, and this probe's own folder. */
25563
- const SKIPPED = [
25563
+ const SKIPPED$1 = [
25564
25564
  /(^|\/)CHANGELOG\.md$/,
25565
25565
  /^\.notes\//,
25566
25566
  /^docs\/wiki\//,
@@ -25579,7 +25579,7 @@ const SCANNED = [
25579
25579
  ];
25580
25580
  /** Whether `path` (repo-relative) is a hand-written kind of place to scan for old task names. */
25581
25581
  function isScanned(path) {
25582
- return SCANNED.some((p) => p.test(path)) && !SKIPPED.some((p) => p.test(path));
25582
+ return SCANNED.some((p) => p.test(path)) && !SKIPPED$1.some((p) => p.test(path));
25583
25583
  }
25584
25584
  // src/commands/probe/tasks/legacy-replacements.ts
25585
25585
  /**
@@ -34909,7 +34909,7 @@ async function runNew(input) {
34909
34909
  // src/commands/new/new-repo.args.ts
34910
34910
  const newRepoArgs = (y) => y.positional("type", {
34911
34911
  type: "string",
34912
- describe: "Template type — maps to theholocron/<type>-template (e.g. cli, react, nextjs, node, monorepo, base)"
34912
+ describe: "Template type — maps to theholocron/<type>-template (e.g. cli, react, nextjs, node, monorepo, monorepo-react, base)"
34913
34913
  }).positional("name", {
34914
34914
  type: "string",
34915
34915
  describe: "New repo name (kebab-case, e.g. my-tool)"
@@ -34996,6 +34996,14 @@ async function askNewRepoAnswers(argv, prompts = {
34996
34996
  name: "monorepo — Turbo monorepo",
34997
34997
  value: "monorepo"
34998
34998
  },
34999
+ {
35000
+ name: "monorepo-react — Turbo monorepo of React libraries",
35001
+ value: "monorepo-react"
35002
+ },
35003
+ {
35004
+ name: "monorepo-nextjs — Turbo monorepo with a Next.js app",
35005
+ value: "monorepo-nextjs"
35006
+ },
34999
35007
  {
35000
35008
  name: "react — React component library",
35001
35009
  value: "react"
@@ -35156,7 +35164,7 @@ async function askNewRepoAnswers(argv, prompts = {
35156
35164
  // src/commands/new/new-repo.command.ts
35157
35165
  const newRepoCommand = {
35158
35166
  command: "repo [type] [name]",
35159
- describe: "Scaffold a new repo from a GitHub template (e.g. cli, react, nextjs, node, monorepo, base)",
35167
+ describe: "Scaffold a new repo from a GitHub template (e.g. cli, react, nextjs, node, monorepo, monorepo-react, base)",
35160
35168
  builder: newRepoArgs,
35161
35169
  handler: async (argv) => {
35162
35170
  try {
@@ -44352,46 +44360,79 @@ const syncRequestsCommand = {
44352
44360
  })).status === "fail") process.exitCode = 1;
44353
44361
  }
44354
44362
  };
44363
+ // src/commands/sync-templates/blob-sha/blob-sha.ts
44364
+ /** The git blob sha of some bytes: `sha1("blob <size>\0" + bytes)`, what `git hash-object` prints, so a file is compared with a tree entry without reading it. */
44365
+ function blobSha(bytes) {
44366
+ return createHash("sha1").update(`blob ${bytes.byteLength}\0`).update(bytes).digest("hex");
44367
+ }
44355
44368
  // src/commands/sync-templates/plan-template-sync/plan-template-sync.ts
44356
- /** Compares a template folder with its repo and lists only what differs: files to create, to replace and to remove. */
44357
- async function planTemplateSync(input) {
44358
- const remote = new Set(input.remotePaths);
44359
- const paths = Object.keys(input.files).sort();
44369
+ /**
44370
+ * Compares a template folder with its repo's tree by path, mode and git blob sha (computed here, so no file is read
44371
+ * from the repo) and lists only what differs: files to create, to replace (other content or other mode) and to remove.
44372
+ */
44373
+ function planTemplateSync(input) {
44374
+ const remote = new Map(input.remote.map((e) => [e.path, e]));
44360
44375
  const plan = {
44376
+ changes: [],
44361
44377
  create: [],
44362
44378
  update: [],
44363
- remove: []
44379
+ remove: [],
44380
+ modes: []
44364
44381
  };
44365
- for (const path of paths) {
44366
- if (!remote.has(path)) {
44367
- plan.create.push(path);
44368
- continue;
44369
- }
44370
- const file = await input.read(path);
44371
- if (!file) plan.create.push(path);
44372
- else if (file.content !== input.files[path]) plan.update.push({
44373
- path,
44374
- version: file.version
44382
+ for (const file of input.files) {
44383
+ const have = remote.get(file.path);
44384
+ if (have && have.mode === file.mode && have.sha === blobSha(file.content)) continue;
44385
+ plan.changes.push({
44386
+ path: file.path,
44387
+ mode: file.mode,
44388
+ content: file.content
44389
+ });
44390
+ (have ? plan.update : plan.create).push(file.path);
44391
+ if (have?.mode !== file.mode && (have || file.mode !== "100644")) plan.modes.push({
44392
+ path: file.path,
44393
+ ...have ? { from: have.mode } : {},
44394
+ to: file.mode
44375
44395
  });
44376
44396
  }
44377
- plan.remove = [...remote].filter((p) => !(p in input.files)).sort();
44397
+ const kept = new Set(input.files.map((f) => f.path));
44398
+ plan.remove = [...remote.keys()].filter((p) => !kept.has(p)).sort();
44399
+ for (const path of plan.remove) plan.changes.push({
44400
+ path,
44401
+ remove: true
44402
+ });
44378
44403
  return plan;
44379
44404
  }
44380
44405
  // src/commands/sync-templates/template-files/template-files.ts
44406
+ /** Folders a template never publishes, wherever they are. */
44407
+ const SKIPPED = /* @__PURE__ */ new Set([".git", "node_modules"]);
44381
44408
  /**
44382
- * Every file of one template folder as `path from the folder -> text`, with `/` separators. `.git` and
44383
- * `node_modules` are not entered. A file with a NUL byte is binary and throws: the `source` capability writes text, so
44384
- * publishing it would corrupt it.
44409
+ * Every file and symbolic link of one template folder, sorted by path (`/` separators). A regular file keeps its
44410
+ * bytes (binary files too) and its execute bit (`100755` when the owner can execute it); a symbolic link is listed
44411
+ * as a `120000` entry whose content is its target and is never followed. `.git` and `node_modules` are not entered.
44385
44412
  */
44386
44413
  function templateFiles(dir) {
44387
- const files = {};
44388
- for (const full of walkFilesSync(dir)) {
44389
- const path = relative(dir, full).split(sep).join("/");
44390
- const bytes = readFileSync(full);
44391
- if (bytes.includes(0)) throw new Error(`${path} is a binary file; templates publish text files only`);
44392
- files[path] = bytes.toString("utf8");
44393
- }
44394
- return files;
44414
+ const files = [];
44415
+ const walk = (folder, prefix) => {
44416
+ for (const entry of readdirSync(folder, { withFileTypes: true })) {
44417
+ const full = join(folder, entry.name);
44418
+ const path = `${prefix}${entry.name}`;
44419
+ const stat = lstatSync(full);
44420
+ if (stat.isSymbolicLink()) files.push({
44421
+ path,
44422
+ mode: "120000",
44423
+ content: Buffer.from(readlinkSync(full))
44424
+ });
44425
+ else if (stat.isDirectory()) {
44426
+ if (!SKIPPED.has(entry.name)) walk(full, `${path}/`);
44427
+ } else if (stat.isFile()) files.push({
44428
+ path,
44429
+ mode: stat.mode & 64 ? "100755" : "100644",
44430
+ content: readFileSync(full)
44431
+ });
44432
+ }
44433
+ };
44434
+ walk(dir, "");
44435
+ return files.sort((a, b) => Number(a.path > b.path) - Number(a.path < b.path));
44395
44436
  }
44396
44437
  // src/commands/sync-templates/template-folders/template-folders.ts
44397
44438
  /**
@@ -44427,15 +44468,16 @@ function templatesVersion(templatesDir) {
44427
44468
  * `holocron sync templates` -- publish each `templates/<type>/` folder to `<org>/<type>-template` and tag that repo
44428
44469
  * `templates-v<version>` (spec `tech-template-repos`, rollout step 3, #2926).
44429
44470
  *
44430
- * Each folder is compared with its repo's default branch; only the difference is written through the `source`
44431
- * capability (files made, replaced, and removed when the repo has them and the folder no longer does), then the repo is
44432
- * tagged with the `templates` group's version from `templates/package.json`, and the major tag (`templates-v1`) is moved
44433
- * to the same commit, so a caller that follows it gets the newest minor. A rerun writes nothing, a version tag already
44471
+ * Each folder is compared with its repo's default branch by path, mode and git blob sha; only the difference is written
44472
+ * through the `source` capability, as ONE commit per template (files made or replaced, symlinks and the executable bit
44473
+ * included, and files removed when the repo has them and the folder no longer does), a fast-forward that is refused
44474
+ * when the branch moved since it was read. Then the repo is tagged with the `templates` group's version from `templates/package.json`, and the major tag (`templates-v1`) is moved
44475
+ * to the same commit, so a caller that follows it gets the newest minor. A rerun makes no commit, a version tag already
44434
44476
  * at the same content is left alone and a major tag already there stays. It never creates or deletes a repository: a missing template repo is a failing row.
44435
44477
  * One template failing does not stop the others. It writes, so it asks first; `--yes` skips the question and, without a
44436
44478
  * terminal, a run with neither `--yes` nor `--dry-run` refuses.
44437
44479
  */
44438
- const counts = (p) => `${p.create.length} to create, ${p.update.length} to replace, ${p.remove.length} to remove`;
44480
+ const counts = (p) => `${p.create.length} to create, ${p.update.length} to replace, ${p.remove.length} to remove${p.modes.length > 0 ? ` (modes: ${p.modes.map((m) => `${m.path} ${m.from ?? "new"} -> ${m.to}`).join(", ")})` : ""}`;
44439
44481
  async function runSyncTemplates(input) {
44440
44482
  const print = input.print ?? ((line) => console.log(line));
44441
44483
  const row = (status, ...parts) => print(statusRow$1(status, ["sync templates", ...parts]));
@@ -44472,24 +44514,23 @@ async function runSyncTemplates(input) {
44472
44514
  await loader.load();
44473
44515
  assertPluginsResolvable(loader, "sync templates");
44474
44516
  const source = loader.has("source") ? loader.get("source") : void 0;
44475
- if (!source?.readFile || !source.writeFile || !source.listFiles || !source.deleteFile || !source.ensureTag || !source.moveTag) return stop("fail", whyMissing(loader, "source", "no `source` provider that can read, write, list and delete files and tag is available"));
44476
- const { readFile, writeFile, listFiles, deleteFile, ensureTag, moveTag } = source;
44517
+ if (!source?.readTree || !source.commitFiles || !source.ensureTag || !source.moveTag) return stop("fail", whyMissing(loader, "source", "no `source` provider that can read a file tree (`readTree`), commit files (`commitFiles`) and tag is available"));
44518
+ const { readTree, commitFiles, ensureTag, moveTag } = source;
44477
44519
  const results = [];
44478
44520
  const planned = [];
44479
44521
  for (const name of names) {
44480
44522
  const repo = `${org}/${name}-template`;
44481
44523
  try {
44482
44524
  const files = templateFiles(join(dir, name));
44483
- const plan = await planTemplateSync({
44484
- files,
44485
- remotePaths: await listFiles.call(source, repo),
44486
- read: (path) => readFile.call(source, path, repo)
44487
- });
44525
+ const tree = await readTree.call(source, repo);
44488
44526
  planned.push({
44489
44527
  name,
44490
44528
  repo,
44491
- files,
44492
- plan
44529
+ base: tree.commit,
44530
+ plan: planTemplateSync({
44531
+ files,
44532
+ remote: tree.entries
44533
+ })
44493
44534
  });
44494
44535
  } catch (err) {
44495
44536
  row("fail", name, repo, describeError(err));
@@ -44549,7 +44590,7 @@ async function runSyncTemplates(input) {
44549
44590
  }
44550
44591
  }
44551
44592
  const message = `chore: sync from ${HOLOCRON_REPO$1} ${tag}`;
44552
- for (const { name, repo, files, plan } of planned) {
44593
+ for (const { name, repo, base, plan } of planned) {
44553
44594
  const result = {
44554
44595
  name,
44555
44596
  repo,
@@ -44559,31 +44600,20 @@ async function runSyncTemplates(input) {
44559
44600
  removed: 0
44560
44601
  };
44561
44602
  try {
44562
- for (const path of plan.create) {
44563
- await writeFile.call(source, path, files[path], {
44564
- message,
44565
- repo
44566
- });
44567
- result.created++;
44568
- }
44569
- for (const { path, version: fileVersion } of plan.update) {
44570
- await writeFile.call(source, path, files[path], {
44603
+ if (plan.changes.length > 0) {
44604
+ result.commit = (await commitFiles.call(source, {
44605
+ repo,
44571
44606
  message,
44572
- version: fileVersion,
44573
- repo
44574
- });
44575
- result.updated++;
44576
- }
44577
- for (const path of plan.remove) {
44578
- await deleteFile.call(source, path, {
44579
- message,
44580
- repo
44581
- });
44582
- result.removed++;
44607
+ changes: plan.changes,
44608
+ base
44609
+ })).commit;
44610
+ result.created = plan.create.length;
44611
+ result.updated = plan.update.length;
44612
+ result.removed = plan.remove.length;
44583
44613
  }
44584
44614
  result.tagged = await ensureTag.call(source, tag, repo);
44585
44615
  result.majorMoved = await moveTag.call(source, majorTag, repo);
44586
- row("ok", name, repo, `${result.created} created, ${result.updated} replaced, ${result.removed} removed; ${result.tagged ? `tagged ${tag}` : `${tag} already there`}; ${result.majorMoved ? `${majorTag} moved here` : `${majorTag} already here`}`);
44616
+ row("ok", name, repo, `${result.commit ? `committed ${result.commit.slice(0, 7)} (${result.created} created, ${result.updated} replaced, ${result.removed} removed)` : "already up to date"}; ${result.tagged ? `tagged ${tag}` : `${tag} already there`}; ${result.majorMoved ? `${majorTag} moved here` : `${majorTag} already here`}`);
44587
44617
  } catch (err) {
44588
44618
  result.status = "fail";
44589
44619
  result.reason = errorMessage(err);