@bensandee/tooling 0.11.0 → 0.13.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/bin.mjs +69 -44
  2. package/package.json +1 -1
package/dist/bin.mjs CHANGED
@@ -516,8 +516,10 @@ const STANDARD_SCRIPTS_SINGLE = {
516
516
  test: "vitest run",
517
517
  lint: "oxlint",
518
518
  knip: "knip",
519
- check: "pnpm exec tooling repo:run-checks",
520
- "tooling:check": "pnpm exec tooling repo:check"
519
+ check: "pnpm exec tooling checks:run",
520
+ "ci:check": "pnpm check",
521
+ "tooling:check": "pnpm exec tooling repo:check",
522
+ "tooling:update": "pnpm exec tooling repo:update"
521
523
  };
522
524
  const STANDARD_SCRIPTS_MONOREPO = {
523
525
  build: "pnpm -r build",
@@ -525,8 +527,17 @@ const STANDARD_SCRIPTS_MONOREPO = {
525
527
  typecheck: "pnpm -r --parallel run typecheck",
526
528
  lint: "oxlint",
527
529
  knip: "knip",
528
- check: "pnpm exec tooling repo:run-checks",
529
- "tooling:check": "pnpm exec tooling repo:check"
530
+ check: "pnpm exec tooling checks:run",
531
+ "ci:check": "pnpm check",
532
+ "tooling:check": "pnpm exec tooling repo:check",
533
+ "tooling:update": "pnpm exec tooling repo:update"
534
+ };
535
+ /** Scripts that tooling owns — map from script name to keyword that must appear in the value. */
536
+ const MANAGED_SCRIPTS = {
537
+ check: "checks:run",
538
+ "ci:check": "pnpm check",
539
+ "tooling:check": "repo:check",
540
+ "tooling:update": "repo:update"
530
541
  };
531
542
  /** DevDeps that belong in every project (single repo) or per-package (monorepo). */
532
543
  const PER_PACKAGE_DEV_DEPS = {
@@ -583,7 +594,7 @@ function getAddedDevDepNames(config) {
583
594
  const deps = { ...ROOT_DEV_DEPS };
584
595
  if (config.structure !== "monorepo") Object.assign(deps, PER_PACKAGE_DEV_DEPS);
585
596
  deps["@bensandee/config"] = "0.7.1";
586
- deps["@bensandee/tooling"] = "0.11.0";
597
+ deps["@bensandee/tooling"] = "0.13.0";
587
598
  if (config.formatter === "oxfmt") deps["oxfmt"] = "0.35.0";
588
599
  if (config.formatter === "prettier") deps["prettier"] = "3.8.1";
589
600
  addReleaseDeps(deps, config);
@@ -604,7 +615,7 @@ async function generatePackageJson(ctx) {
604
615
  const devDeps = { ...ROOT_DEV_DEPS };
605
616
  if (!isMonorepo) Object.assign(devDeps, PER_PACKAGE_DEV_DEPS);
606
617
  devDeps["@bensandee/config"] = isWorkspacePackage(ctx, "@bensandee/config") ? "workspace:*" : "0.7.1";
607
- devDeps["@bensandee/tooling"] = isWorkspacePackage(ctx, "@bensandee/tooling") ? "workspace:*" : "0.11.0";
618
+ devDeps["@bensandee/tooling"] = isWorkspacePackage(ctx, "@bensandee/tooling") ? "workspace:*" : "0.13.0";
608
619
  if (ctx.config.useEslintPlugin) devDeps["@bensandee/eslint-plugin"] = isWorkspacePackage(ctx, "@bensandee/eslint-plugin") ? "workspace:*" : "0.9.0";
609
620
  if (ctx.config.formatter === "oxfmt") devDeps["oxfmt"] = "0.35.0";
610
621
  if (ctx.config.formatter === "prettier") devDeps["prettier"] = "3.8.1";
@@ -625,6 +636,9 @@ async function generatePackageJson(ctx) {
625
636
  for (const [key, value] of Object.entries(allScripts)) if (!(key in existingScripts)) {
626
637
  existingScripts[key] = value;
627
638
  changes.push(`added script: ${key}`);
639
+ } else if (key in MANAGED_SCRIPTS && !existingScripts[key]?.includes(MANAGED_SCRIPTS[key])) {
640
+ existingScripts[key] = value;
641
+ changes.push(`updated script: ${key}`);
628
642
  }
629
643
  pkg.scripts = existingScripts;
630
644
  const existingDevDeps = pkg.devDependencies ?? {};
@@ -1378,7 +1392,7 @@ jobs:
1378
1392
  cache: pnpm
1379
1393
  - run: pnpm install --frozen-lockfile
1380
1394
  - name: Run all checks
1381
- run: pnpm check
1395
+ run: pnpm ci:check
1382
1396
  `;
1383
1397
  }
1384
1398
  function requiredCheckSteps(nodeVersionYaml) {
@@ -1409,7 +1423,7 @@ function requiredCheckSteps(nodeVersionYaml) {
1409
1423
  match: { run: "check" },
1410
1424
  step: {
1411
1425
  name: "Run all checks",
1412
- run: "pnpm check"
1426
+ run: "pnpm ci:check"
1413
1427
  }
1414
1428
  }
1415
1429
  ];
@@ -3404,35 +3418,26 @@ function mergeGitHub(dryRun) {
3404
3418
  //#endregion
3405
3419
  //#region src/commands/repo-run-checks.ts
3406
3420
  const CHECKS = [
3407
- {
3408
- name: "build",
3409
- cmd: "pnpm run --if-present build"
3410
- },
3411
- {
3412
- name: "typecheck",
3413
- cmd: "pnpm run --if-present typecheck"
3414
- },
3415
- {
3416
- name: "lint",
3417
- cmd: "pnpm run --if-present lint"
3418
- },
3419
- {
3420
- name: "test",
3421
- cmd: "pnpm run --if-present test"
3422
- },
3421
+ { name: "build" },
3422
+ { name: "typecheck" },
3423
+ { name: "lint" },
3424
+ { name: "test" },
3423
3425
  {
3424
3426
  name: "format",
3425
- cmd: "pnpm run --if-present format -- --check"
3426
- },
3427
- {
3428
- name: "knip",
3429
- cmd: "pnpm run --if-present knip"
3427
+ args: "--check"
3430
3428
  },
3431
- {
3432
- name: "tooling:check",
3433
- cmd: "pnpm run --if-present tooling:check"
3434
- }
3429
+ { name: "knip" },
3430
+ { name: "tooling:check" },
3431
+ { name: "image:check" }
3435
3432
  ];
3433
+ function defaultGetScripts(targetDir) {
3434
+ try {
3435
+ const pkg = parsePackageJson(readFileSync(path.join(targetDir, "package.json"), "utf-8"));
3436
+ return new Set(Object.keys(pkg?.scripts ?? {}));
3437
+ } catch {
3438
+ return /* @__PURE__ */ new Set();
3439
+ }
3440
+ }
3436
3441
  function defaultExecCommand(cmd, cwd) {
3437
3442
  try {
3438
3443
  execSync(cmd, {
@@ -3448,16 +3453,27 @@ function defaultExecCommand(cmd, cwd) {
3448
3453
  const ciLog = (msg) => console.log(msg);
3449
3454
  function runRunChecks(targetDir, options = {}) {
3450
3455
  const exec = options.execCommand ?? defaultExecCommand;
3456
+ const getScripts = options.getScripts ?? defaultGetScripts;
3451
3457
  const skip = options.skip ?? /* @__PURE__ */ new Set();
3458
+ const add = options.add ?? [];
3452
3459
  const isCI = Boolean(process.env["CI"]);
3460
+ const definedScripts = getScripts(targetDir);
3461
+ const addedNames = new Set(add);
3462
+ const allChecks = [...CHECKS, ...add.map((name) => ({ name }))];
3453
3463
  const failures = [];
3454
- for (const check of CHECKS) {
3455
- if (skip.has(check.name)) {
3456
- p.log.info(`${check.name} (skipped)`);
3464
+ const notDefined = [];
3465
+ for (const check of allChecks) {
3466
+ if (skip.has(check.name)) continue;
3467
+ if (!definedScripts.has(check.name)) {
3468
+ if (addedNames.has(check.name)) {
3469
+ p.log.error(`${check.name} not defined in package.json`);
3470
+ failures.push(check.name);
3471
+ } else notDefined.push(check.name);
3457
3472
  continue;
3458
3473
  }
3474
+ const cmd = check.args ? `pnpm run ${check.name} ${check.args}` : `pnpm run ${check.name}`;
3459
3475
  if (isCI) ciLog(`::group::${check.name}`);
3460
- const exitCode = exec(check.cmd, targetDir);
3476
+ const exitCode = exec(cmd, targetDir);
3461
3477
  if (isCI) ciLog("::endgroup::");
3462
3478
  if (exitCode === 0) p.log.success(check.name);
3463
3479
  else {
@@ -3466,6 +3482,7 @@ function runRunChecks(targetDir, options = {}) {
3466
3482
  failures.push(check.name);
3467
3483
  }
3468
3484
  }
3485
+ if (notDefined.length > 0) p.log.info(`Skipped (not defined): ${notDefined.join(", ")}`);
3469
3486
  if (failures.length > 0) {
3470
3487
  p.log.error(`Failed checks: ${failures.join(", ")}`);
3471
3488
  return 1;
@@ -3475,8 +3492,8 @@ function runRunChecks(targetDir, options = {}) {
3475
3492
  }
3476
3493
  const runChecksCommand = defineCommand({
3477
3494
  meta: {
3478
- name: "repo:run-checks",
3479
- description: "Run all standard checks (build, typecheck, lint, test, format, knip, tooling:check)"
3495
+ name: "checks:run",
3496
+ description: "Run all standard checks (build, typecheck, lint, test, format, knip, tooling:check, image:check)"
3480
3497
  },
3481
3498
  args: {
3482
3499
  dir: {
@@ -3486,12 +3503,20 @@ const runChecksCommand = defineCommand({
3486
3503
  },
3487
3504
  skip: {
3488
3505
  type: "string",
3489
- description: "Comma-separated list of checks to skip (build, typecheck, lint, test, format, knip, tooling:check)",
3506
+ description: "Comma-separated list of checks to skip (build, typecheck, lint, test, format, knip, tooling:check, image:check)",
3507
+ required: false
3508
+ },
3509
+ add: {
3510
+ type: "string",
3511
+ description: "Comma-separated list of additional check names to run (uses pnpm run <name>)",
3490
3512
  required: false
3491
3513
  }
3492
3514
  },
3493
3515
  run({ args }) {
3494
- const exitCode = runRunChecks(path.resolve(args.dir ?? "."), { skip: args.skip ? new Set(args.skip.split(",").map((s) => s.trim())) : void 0 });
3516
+ const exitCode = runRunChecks(path.resolve(args.dir ?? "."), {
3517
+ skip: args.skip ? new Set(args.skip.split(",").map((s) => s.trim())) : void 0,
3518
+ add: args.add ? args.add.split(",").map((s) => s.trim()) : void 0
3519
+ });
3495
3520
  process.exitCode = exitCode;
3496
3521
  }
3497
3522
  });
@@ -3500,21 +3525,21 @@ const runChecksCommand = defineCommand({
3500
3525
  const main = defineCommand({
3501
3526
  meta: {
3502
3527
  name: "tooling",
3503
- version: "0.11.0",
3528
+ version: "0.13.0",
3504
3529
  description: "Bootstrap and maintain standardized TypeScript project tooling"
3505
3530
  },
3506
3531
  subCommands: {
3507
3532
  "repo:init": initCommand,
3508
3533
  "repo:update": updateCommand,
3509
3534
  "repo:check": checkCommand,
3510
- "repo:run-checks": runChecksCommand,
3535
+ "checks:run": runChecksCommand,
3511
3536
  "release:changesets": releaseForgejoCommand,
3512
3537
  "release:trigger": releaseTriggerCommand,
3513
3538
  "release:create-forgejo-release": createForgejoReleaseCommand,
3514
3539
  "release:merge": releaseMergeCommand
3515
3540
  }
3516
3541
  });
3517
- console.log(`@bensandee/tooling v0.11.0`);
3542
+ console.log(`@bensandee/tooling v0.13.0`);
3518
3543
  runMain(main);
3519
3544
  //#endregion
3520
3545
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bensandee/tooling",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "CLI tool to bootstrap and maintain standardized TypeScript project tooling",
5
5
  "bin": {
6
6
  "tooling": "./dist/bin.mjs"