@bensandee/tooling 0.15.0 → 0.16.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/CHANGELOG.md +6 -0
- package/README.md +48 -22
- package/dist/bin.mjs +549 -541
- package/dist/docker-verify/index.mjs +1 -1
- package/dist/index.d.mts +0 -2
- package/package.json +1 -1
package/dist/bin.mjs
CHANGED
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
import { t as isExecSyncError } from "./exec-CC49vrkM.mjs";
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
4
|
import * as p from "@clack/prompts";
|
|
5
|
-
import { execSync } from "node:child_process";
|
|
6
5
|
import path from "node:path";
|
|
7
6
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
8
7
|
import JSON5 from "json5";
|
|
9
8
|
import { parse } from "jsonc-parser";
|
|
10
9
|
import { z } from "zod";
|
|
11
10
|
import { isMap, isSeq, parseDocument } from "yaml";
|
|
11
|
+
import { execSync } from "node:child_process";
|
|
12
12
|
import { FatalError, TransientError, UnexpectedError } from "@bensandee/common";
|
|
13
13
|
//#region src/types.ts
|
|
14
|
-
/** Default CI platform when not explicitly chosen. */
|
|
15
|
-
const DEFAULT_CI = "forgejo";
|
|
16
14
|
const LEGACY_TOOLS = [
|
|
17
15
|
"eslint",
|
|
18
16
|
"prettier",
|
|
@@ -141,10 +139,6 @@ function readPackageJson(targetDir) {
|
|
|
141
139
|
return;
|
|
142
140
|
}
|
|
143
141
|
}
|
|
144
|
-
/** Detect whether the project is a monorepo. */
|
|
145
|
-
function detectMonorepo(targetDir) {
|
|
146
|
-
return existsSync(path.join(targetDir, "pnpm-workspace.yaml"));
|
|
147
|
-
}
|
|
148
142
|
/** Detect project type from package.json signals. */
|
|
149
143
|
function detectProjectType(targetDir) {
|
|
150
144
|
const pkg = readPackageJson(targetDir);
|
|
@@ -185,6 +179,32 @@ function hasWebUIDeps(targetDir) {
|
|
|
185
179
|
if (!pkg) return false;
|
|
186
180
|
return packageHasWebUIDeps(pkg);
|
|
187
181
|
}
|
|
182
|
+
/** Detect CI platform from existing workflow directories. */
|
|
183
|
+
function detectCiPlatform(targetDir) {
|
|
184
|
+
if (existsSync(path.join(targetDir, ".forgejo", "workflows"))) return "forgejo";
|
|
185
|
+
if (existsSync(path.join(targetDir, ".github", "workflows"))) return "github";
|
|
186
|
+
return "none";
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Compute convention-based defaults for a project directory.
|
|
190
|
+
* These are the values the tool would use when .tooling.json says nothing.
|
|
191
|
+
*/
|
|
192
|
+
function computeDefaults(targetDir) {
|
|
193
|
+
const detected = detectProject(targetDir);
|
|
194
|
+
const isMonorepo = detected.hasPnpmWorkspace;
|
|
195
|
+
const hasPrettier = detected.legacyConfigs.some((l) => l.tool === "prettier");
|
|
196
|
+
return {
|
|
197
|
+
structure: isMonorepo ? "monorepo" : "single",
|
|
198
|
+
useEslintPlugin: true,
|
|
199
|
+
formatter: hasPrettier ? "prettier" : "oxfmt",
|
|
200
|
+
setupVitest: !isMonorepo && !detected.hasVitestConfig,
|
|
201
|
+
ci: detectCiPlatform(targetDir),
|
|
202
|
+
setupRenovate: true,
|
|
203
|
+
releaseStrategy: isMonorepo ? "changesets" : "simple",
|
|
204
|
+
projectType: isMonorepo ? "default" : detectProjectType(targetDir),
|
|
205
|
+
detectPackageTypes: true
|
|
206
|
+
};
|
|
207
|
+
}
|
|
188
208
|
/** List packages in a monorepo's packages/ directory. */
|
|
189
209
|
function getMonorepoPackages(targetDir) {
|
|
190
210
|
const packagesDir = path.join(targetDir, "packages");
|
|
@@ -210,175 +230,99 @@ function isCancelled(value) {
|
|
|
210
230
|
return p.isCancel(value);
|
|
211
231
|
}
|
|
212
232
|
async function runInitPrompts(targetDir, saved) {
|
|
213
|
-
p.intro("@bensandee/tooling repo:
|
|
233
|
+
p.intro("@bensandee/tooling repo:sync");
|
|
214
234
|
const existingPkg = readPackageJson(targetDir);
|
|
215
235
|
const detected = detectProject(targetDir);
|
|
236
|
+
const defaults = computeDefaults(targetDir);
|
|
216
237
|
const isExisting = detected.hasPackageJson;
|
|
238
|
+
const isFirstInit = !saved;
|
|
217
239
|
const name = existingPkg?.name ?? path.basename(targetDir);
|
|
218
|
-
const
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
p.cancel("Cancelled.");
|
|
240
|
-
process.exit(0);
|
|
241
|
-
}
|
|
242
|
-
const hasExistingPrettier = detected.legacyConfigs.some((l) => l.tool === "prettier");
|
|
243
|
-
const formatter = await p.select({
|
|
244
|
-
message: "Formatter",
|
|
245
|
-
initialValue: saved?.formatter ?? (hasExistingPrettier ? "prettier" : "oxfmt"),
|
|
246
|
-
options: [{
|
|
247
|
-
value: "oxfmt",
|
|
248
|
-
label: "oxfmt",
|
|
249
|
-
hint: "fast, Rust-based"
|
|
250
|
-
}, {
|
|
251
|
-
value: "prettier",
|
|
252
|
-
label: "Prettier"
|
|
253
|
-
}]
|
|
254
|
-
});
|
|
255
|
-
if (isCancelled(formatter)) {
|
|
256
|
-
p.cancel("Cancelled.");
|
|
257
|
-
process.exit(0);
|
|
258
|
-
}
|
|
259
|
-
const setupVitest = await p.confirm({
|
|
260
|
-
message: "Set up vitest with a starter test?",
|
|
261
|
-
initialValue: saved?.setupVitest ?? !isExisting
|
|
262
|
-
});
|
|
263
|
-
if (isCancelled(setupVitest)) {
|
|
264
|
-
p.cancel("Cancelled.");
|
|
265
|
-
process.exit(0);
|
|
266
|
-
}
|
|
267
|
-
const ci = await p.select({
|
|
268
|
-
message: "CI workflow",
|
|
269
|
-
initialValue: saved?.ci,
|
|
270
|
-
options: [
|
|
271
|
-
{
|
|
272
|
-
value: "forgejo",
|
|
273
|
-
label: "Forgejo Actions"
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
value: "github",
|
|
277
|
-
label: "GitHub Actions"
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
value: "none",
|
|
281
|
-
label: "None"
|
|
282
|
-
}
|
|
283
|
-
]
|
|
284
|
-
});
|
|
285
|
-
if (isCancelled(ci)) {
|
|
286
|
-
p.cancel("Cancelled.");
|
|
287
|
-
process.exit(0);
|
|
288
|
-
}
|
|
289
|
-
let setupRenovate = true;
|
|
290
|
-
if (ci === "github") {
|
|
291
|
-
const renovateAnswer = await p.confirm({
|
|
292
|
-
message: "Set up Renovate for automated dependency updates?",
|
|
293
|
-
initialValue: saved?.setupRenovate ?? true
|
|
240
|
+
const structure = saved?.structure ?? defaults.structure;
|
|
241
|
+
const useEslintPlugin = saved?.useEslintPlugin ?? defaults.useEslintPlugin;
|
|
242
|
+
let formatter = saved?.formatter ?? defaults.formatter;
|
|
243
|
+
const setupVitest = saved?.setupVitest ?? defaults.setupVitest;
|
|
244
|
+
let ci = saved?.ci ?? defaults.ci;
|
|
245
|
+
const setupRenovate = saved?.setupRenovate ?? defaults.setupRenovate;
|
|
246
|
+
let releaseStrategy = saved?.releaseStrategy ?? defaults.releaseStrategy;
|
|
247
|
+
const projectType = saved?.projectType ?? defaults.projectType;
|
|
248
|
+
const detectPackageTypes = saved?.detectPackageTypes ?? defaults.detectPackageTypes;
|
|
249
|
+
if (detected.legacyConfigs.some((l) => l.tool === "prettier") && isFirstInit) {
|
|
250
|
+
const formatterAnswer = await p.select({
|
|
251
|
+
message: "Existing Prettier config found. Keep Prettier or migrate to oxfmt?",
|
|
252
|
+
initialValue: "prettier",
|
|
253
|
+
options: [{
|
|
254
|
+
value: "prettier",
|
|
255
|
+
label: "Keep Prettier"
|
|
256
|
+
}, {
|
|
257
|
+
value: "oxfmt",
|
|
258
|
+
label: "Migrate to oxfmt",
|
|
259
|
+
hint: "fast, Rust-based"
|
|
260
|
+
}]
|
|
294
261
|
});
|
|
295
|
-
if (isCancelled(
|
|
262
|
+
if (isCancelled(formatterAnswer)) {
|
|
296
263
|
p.cancel("Cancelled.");
|
|
297
264
|
process.exit(0);
|
|
298
265
|
}
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
const releaseStrategy = await p.select({
|
|
302
|
-
message: "Release management",
|
|
303
|
-
initialValue: saved?.releaseStrategy ?? "none",
|
|
304
|
-
options: [
|
|
305
|
-
{
|
|
306
|
-
value: "none",
|
|
307
|
-
label: "None"
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
value: "release-it",
|
|
311
|
-
label: "release-it",
|
|
312
|
-
hint: "interactive, conventional commits"
|
|
313
|
-
},
|
|
314
|
-
{
|
|
315
|
-
value: "changesets",
|
|
316
|
-
label: "Changesets",
|
|
317
|
-
hint: "PR-based versioning"
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
value: "simple",
|
|
321
|
-
label: "Simple",
|
|
322
|
-
hint: "uses commit-and-tag-version internally"
|
|
323
|
-
}
|
|
324
|
-
]
|
|
325
|
-
});
|
|
326
|
-
if (isCancelled(releaseStrategy)) {
|
|
327
|
-
p.cancel("Cancelled.");
|
|
328
|
-
process.exit(0);
|
|
266
|
+
formatter = formatterAnswer;
|
|
329
267
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
268
|
+
const detectedCi = detectCiPlatform(targetDir);
|
|
269
|
+
if (isFirstInit && detectedCi === "none") {
|
|
270
|
+
const ciAnswer = await p.select({
|
|
271
|
+
message: "CI workflow",
|
|
272
|
+
initialValue: "forgejo",
|
|
273
|
+
options: [
|
|
274
|
+
{
|
|
275
|
+
value: "forgejo",
|
|
276
|
+
label: "Forgejo Actions"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
value: "github",
|
|
280
|
+
label: "GitHub Actions"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
value: "none",
|
|
284
|
+
label: "None"
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
});
|
|
288
|
+
if (isCancelled(ciAnswer)) {
|
|
289
|
+
p.cancel("Cancelled.");
|
|
290
|
+
process.exit(0);
|
|
349
291
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
292
|
+
ci = ciAnswer;
|
|
293
|
+
}
|
|
294
|
+
const hasExistingRelease = detected.hasReleaseItConfig || detected.hasSimpleReleaseConfig || detected.hasChangesetsConfig;
|
|
295
|
+
if (isFirstInit && !hasExistingRelease) {
|
|
296
|
+
const releaseAnswer = await p.select({
|
|
297
|
+
message: "Release management",
|
|
298
|
+
initialValue: defaults.releaseStrategy,
|
|
354
299
|
options: [
|
|
355
300
|
{
|
|
356
|
-
value: "
|
|
357
|
-
label: "
|
|
358
|
-
hint: "strictest base, no runtime assumptions"
|
|
301
|
+
value: "none",
|
|
302
|
+
label: "None"
|
|
359
303
|
},
|
|
360
304
|
{
|
|
361
|
-
value: "
|
|
362
|
-
label: "
|
|
363
|
-
hint: "
|
|
305
|
+
value: "release-it",
|
|
306
|
+
label: "release-it",
|
|
307
|
+
hint: "interactive, conventional commits"
|
|
364
308
|
},
|
|
365
309
|
{
|
|
366
|
-
value: "
|
|
367
|
-
label: "
|
|
368
|
-
hint: "
|
|
310
|
+
value: "changesets",
|
|
311
|
+
label: "Changesets",
|
|
312
|
+
hint: "PR-based versioning"
|
|
369
313
|
},
|
|
370
314
|
{
|
|
371
|
-
value: "
|
|
372
|
-
label: "
|
|
373
|
-
hint: "
|
|
315
|
+
value: "simple",
|
|
316
|
+
label: "Simple",
|
|
317
|
+
hint: "uses commit-and-tag-version internally"
|
|
374
318
|
}
|
|
375
319
|
]
|
|
376
320
|
});
|
|
377
|
-
if (isCancelled(
|
|
321
|
+
if (isCancelled(releaseAnswer)) {
|
|
378
322
|
p.cancel("Cancelled.");
|
|
379
323
|
process.exit(0);
|
|
380
324
|
}
|
|
381
|
-
|
|
325
|
+
releaseStrategy = releaseAnswer;
|
|
382
326
|
}
|
|
383
327
|
p.outro("Configuration complete!");
|
|
384
328
|
return {
|
|
@@ -393,7 +337,6 @@ async function runInitPrompts(targetDir, saved) {
|
|
|
393
337
|
releaseStrategy,
|
|
394
338
|
projectType,
|
|
395
339
|
detectPackageTypes,
|
|
396
|
-
setupDocker: saved?.setupDocker ?? false,
|
|
397
340
|
targetDir
|
|
398
341
|
};
|
|
399
342
|
}
|
|
@@ -401,19 +344,13 @@ async function runInitPrompts(targetDir, saved) {
|
|
|
401
344
|
function buildDefaultConfig(targetDir, flags) {
|
|
402
345
|
const existingPkg = readPackageJson(targetDir);
|
|
403
346
|
const detected = detectProject(targetDir);
|
|
347
|
+
const defaults = computeDefaults(targetDir);
|
|
404
348
|
return {
|
|
405
349
|
name: existingPkg?.name ?? path.basename(targetDir),
|
|
406
350
|
isNew: !detected.hasPackageJson,
|
|
407
|
-
|
|
408
|
-
useEslintPlugin: flags.eslintPlugin
|
|
409
|
-
|
|
410
|
-
setupVitest: !detected.hasVitestConfig,
|
|
411
|
-
ci: flags.noCi ? "none" : DEFAULT_CI,
|
|
412
|
-
setupRenovate: true,
|
|
413
|
-
releaseStrategy: detected.hasReleaseItConfig ? "release-it" : detected.hasSimpleReleaseConfig ? "simple" : detected.hasChangesetsConfig ? "changesets" : "none",
|
|
414
|
-
projectType: "default",
|
|
415
|
-
detectPackageTypes: true,
|
|
416
|
-
setupDocker: false,
|
|
351
|
+
...defaults,
|
|
352
|
+
...flags.eslintPlugin !== void 0 && { useEslintPlugin: flags.eslintPlugin },
|
|
353
|
+
...flags.noCi && { ci: "none" },
|
|
417
354
|
targetDir
|
|
418
355
|
};
|
|
419
356
|
}
|
|
@@ -512,6 +449,109 @@ function createDryRunContext(config) {
|
|
|
512
449
|
};
|
|
513
450
|
}
|
|
514
451
|
//#endregion
|
|
452
|
+
//#region src/utils/tooling-config.ts
|
|
453
|
+
const CONFIG_FILE = ".tooling.json";
|
|
454
|
+
const ToolingConfigSchema = z.object({
|
|
455
|
+
structure: z.enum(["single", "monorepo"]).optional(),
|
|
456
|
+
useEslintPlugin: z.boolean().optional(),
|
|
457
|
+
formatter: z.enum(["oxfmt", "prettier"]).optional(),
|
|
458
|
+
setupVitest: z.boolean().optional(),
|
|
459
|
+
ci: z.enum([
|
|
460
|
+
"github",
|
|
461
|
+
"forgejo",
|
|
462
|
+
"none"
|
|
463
|
+
]).optional(),
|
|
464
|
+
setupRenovate: z.boolean().optional(),
|
|
465
|
+
releaseStrategy: z.enum([
|
|
466
|
+
"release-it",
|
|
467
|
+
"simple",
|
|
468
|
+
"changesets",
|
|
469
|
+
"none"
|
|
470
|
+
]).optional(),
|
|
471
|
+
projectType: z.enum([
|
|
472
|
+
"default",
|
|
473
|
+
"node",
|
|
474
|
+
"react",
|
|
475
|
+
"library"
|
|
476
|
+
]).optional(),
|
|
477
|
+
detectPackageTypes: z.boolean().optional(),
|
|
478
|
+
setupDocker: z.boolean().optional(),
|
|
479
|
+
docker: z.record(z.string(), z.object({
|
|
480
|
+
dockerfile: z.string(),
|
|
481
|
+
context: z.string().default(".")
|
|
482
|
+
})).optional()
|
|
483
|
+
});
|
|
484
|
+
/** Load saved tooling config from the target directory. Returns undefined if missing or invalid. */
|
|
485
|
+
function loadToolingConfig(targetDir) {
|
|
486
|
+
const fullPath = path.join(targetDir, CONFIG_FILE);
|
|
487
|
+
if (!existsSync(fullPath)) return void 0;
|
|
488
|
+
try {
|
|
489
|
+
const raw = readFileSync(fullPath, "utf-8");
|
|
490
|
+
const result = ToolingConfigSchema.safeParse(JSON.parse(raw));
|
|
491
|
+
return result.success ? result.data : void 0;
|
|
492
|
+
} catch {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
/** Config fields that can be overridden in .tooling.json. */
|
|
497
|
+
const OVERRIDE_KEYS = [
|
|
498
|
+
"structure",
|
|
499
|
+
"useEslintPlugin",
|
|
500
|
+
"formatter",
|
|
501
|
+
"setupVitest",
|
|
502
|
+
"ci",
|
|
503
|
+
"setupRenovate",
|
|
504
|
+
"releaseStrategy",
|
|
505
|
+
"projectType",
|
|
506
|
+
"detectPackageTypes"
|
|
507
|
+
];
|
|
508
|
+
/** Keys that have no effect for monorepos (generators ignore them). */
|
|
509
|
+
const MONOREPO_IGNORED_KEYS = new Set(["setupVitest", "projectType"]);
|
|
510
|
+
/**
|
|
511
|
+
* Save only the fields that differ from detected defaults to .tooling.json.
|
|
512
|
+
* A fully conventional project produces `{}` (or a minimal set of overrides).
|
|
513
|
+
* Keys that have no effect for the current structure are omitted.
|
|
514
|
+
*/
|
|
515
|
+
function saveToolingConfig(ctx, config) {
|
|
516
|
+
const defaults = computeDefaults(config.targetDir);
|
|
517
|
+
const isMonorepo = config.structure === "monorepo";
|
|
518
|
+
const overrides = {};
|
|
519
|
+
for (const key of OVERRIDE_KEYS) {
|
|
520
|
+
if (isMonorepo && MONOREPO_IGNORED_KEYS.has(key)) continue;
|
|
521
|
+
if (config[key] !== defaults[key]) overrides[key] = config[key];
|
|
522
|
+
}
|
|
523
|
+
const content = JSON.stringify(overrides, null, 2) + "\n";
|
|
524
|
+
const existing = ctx.exists(CONFIG_FILE) ? ctx.read(CONFIG_FILE) : void 0;
|
|
525
|
+
if (existing !== void 0 && contentEqual(CONFIG_FILE, existing, content)) return {
|
|
526
|
+
filePath: CONFIG_FILE,
|
|
527
|
+
action: "skipped",
|
|
528
|
+
description: "Already up to date"
|
|
529
|
+
};
|
|
530
|
+
ctx.write(CONFIG_FILE, content);
|
|
531
|
+
return {
|
|
532
|
+
filePath: CONFIG_FILE,
|
|
533
|
+
action: existing ? "updated" : "created",
|
|
534
|
+
description: "Saved tooling configuration"
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
/** Merge saved config over detected defaults. Saved values win when present. */
|
|
538
|
+
function mergeWithSavedConfig(detected, saved) {
|
|
539
|
+
return {
|
|
540
|
+
name: detected.name,
|
|
541
|
+
isNew: detected.isNew,
|
|
542
|
+
targetDir: detected.targetDir,
|
|
543
|
+
structure: saved.structure ?? detected.structure,
|
|
544
|
+
useEslintPlugin: saved.useEslintPlugin ?? detected.useEslintPlugin,
|
|
545
|
+
formatter: saved.formatter ?? detected.formatter,
|
|
546
|
+
setupVitest: saved.setupVitest ?? detected.setupVitest,
|
|
547
|
+
ci: saved.ci ?? detected.ci,
|
|
548
|
+
setupRenovate: saved.setupRenovate ?? detected.setupRenovate,
|
|
549
|
+
releaseStrategy: saved.releaseStrategy ?? detected.releaseStrategy,
|
|
550
|
+
projectType: saved.projectType ?? detected.projectType,
|
|
551
|
+
detectPackageTypes: saved.detectPackageTypes ?? detected.detectPackageTypes
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
//#endregion
|
|
515
555
|
//#region src/generators/package-json.ts
|
|
516
556
|
const STANDARD_SCRIPTS_SINGLE = {
|
|
517
557
|
build: "tsdown",
|
|
@@ -522,8 +562,8 @@ const STANDARD_SCRIPTS_SINGLE = {
|
|
|
522
562
|
knip: "knip",
|
|
523
563
|
check: "pnpm exec tooling checks:run",
|
|
524
564
|
"ci:check": "pnpm check",
|
|
525
|
-
"tooling:check": "pnpm exec tooling repo:check",
|
|
526
|
-
"tooling:
|
|
565
|
+
"tooling:check": "pnpm exec tooling repo:sync --check",
|
|
566
|
+
"tooling:sync": "pnpm exec tooling repo:sync"
|
|
527
567
|
};
|
|
528
568
|
const STANDARD_SCRIPTS_MONOREPO = {
|
|
529
569
|
build: "pnpm -r build",
|
|
@@ -533,16 +573,18 @@ const STANDARD_SCRIPTS_MONOREPO = {
|
|
|
533
573
|
knip: "knip",
|
|
534
574
|
check: "pnpm exec tooling checks:run",
|
|
535
575
|
"ci:check": "pnpm check",
|
|
536
|
-
"tooling:check": "pnpm exec tooling repo:check",
|
|
537
|
-
"tooling:
|
|
576
|
+
"tooling:check": "pnpm exec tooling repo:sync --check",
|
|
577
|
+
"tooling:sync": "pnpm exec tooling repo:sync"
|
|
538
578
|
};
|
|
539
579
|
/** Scripts that tooling owns — map from script name to keyword that must appear in the value. */
|
|
540
580
|
const MANAGED_SCRIPTS = {
|
|
541
581
|
check: "checks:run",
|
|
542
582
|
"ci:check": "pnpm check",
|
|
543
|
-
"tooling:check": "repo:check",
|
|
544
|
-
"tooling:
|
|
583
|
+
"tooling:check": "repo:sync --check",
|
|
584
|
+
"tooling:sync": "repo:sync"
|
|
545
585
|
};
|
|
586
|
+
/** Deprecated scripts to remove during migration. */
|
|
587
|
+
const DEPRECATED_SCRIPTS = ["tooling:init", "tooling:update"];
|
|
546
588
|
/** DevDeps that belong in every project (single repo) or per-package (monorepo). */
|
|
547
589
|
const PER_PACKAGE_DEV_DEPS = {
|
|
548
590
|
"@types/node": "25.3.2",
|
|
@@ -598,7 +640,7 @@ function getAddedDevDepNames(config) {
|
|
|
598
640
|
const deps = { ...ROOT_DEV_DEPS };
|
|
599
641
|
if (config.structure !== "monorepo") Object.assign(deps, PER_PACKAGE_DEV_DEPS);
|
|
600
642
|
deps["@bensandee/config"] = "0.8.1";
|
|
601
|
-
deps["@bensandee/tooling"] = "0.
|
|
643
|
+
deps["@bensandee/tooling"] = "0.16.0";
|
|
602
644
|
if (config.formatter === "oxfmt") deps["oxfmt"] = "0.35.0";
|
|
603
645
|
if (config.formatter === "prettier") deps["prettier"] = "3.8.1";
|
|
604
646
|
addReleaseDeps(deps, config);
|
|
@@ -619,7 +661,7 @@ async function generatePackageJson(ctx) {
|
|
|
619
661
|
const devDeps = { ...ROOT_DEV_DEPS };
|
|
620
662
|
if (!isMonorepo) Object.assign(devDeps, PER_PACKAGE_DEV_DEPS);
|
|
621
663
|
devDeps["@bensandee/config"] = isWorkspacePackage(ctx, "@bensandee/config") ? "workspace:*" : "0.8.1";
|
|
622
|
-
devDeps["@bensandee/tooling"] = isWorkspacePackage(ctx, "@bensandee/tooling") ? "workspace:*" : "0.
|
|
664
|
+
devDeps["@bensandee/tooling"] = isWorkspacePackage(ctx, "@bensandee/tooling") ? "workspace:*" : "0.16.0";
|
|
623
665
|
if (ctx.config.useEslintPlugin) devDeps["@bensandee/eslint-plugin"] = isWorkspacePackage(ctx, "@bensandee/eslint-plugin") ? "workspace:*" : "0.9.2";
|
|
624
666
|
if (ctx.config.formatter === "oxfmt") devDeps["oxfmt"] = "0.35.0";
|
|
625
667
|
if (ctx.config.formatter === "prettier") devDeps["prettier"] = "3.8.1";
|
|
@@ -644,6 +686,10 @@ async function generatePackageJson(ctx) {
|
|
|
644
686
|
existingScripts[key] = value;
|
|
645
687
|
changes.push(`updated script: ${key}`);
|
|
646
688
|
}
|
|
689
|
+
for (const key of DEPRECATED_SCRIPTS) if (key in existingScripts) {
|
|
690
|
+
delete existingScripts[key];
|
|
691
|
+
changes.push(`removed deprecated script: ${key}`);
|
|
692
|
+
}
|
|
647
693
|
pkg.scripts = existingScripts;
|
|
648
694
|
const existingDevDeps = pkg.devDependencies ?? {};
|
|
649
695
|
for (const [key, value] of Object.entries(devDeps)) if (!(key in existingDevDeps)) {
|
|
@@ -688,175 +734,6 @@ async function generatePackageJson(ctx) {
|
|
|
688
734
|
};
|
|
689
735
|
}
|
|
690
736
|
//#endregion
|
|
691
|
-
//#region src/generators/migrate-prompt.ts
|
|
692
|
-
/**
|
|
693
|
-
* Generate a context-aware AI migration prompt based on what the CLI did.
|
|
694
|
-
* This prompt can be pasted into Claude Code (or similar) to finish the migration.
|
|
695
|
-
*/
|
|
696
|
-
function generateMigratePrompt(results, config, detected) {
|
|
697
|
-
const sections = [];
|
|
698
|
-
sections.push("# Migration Prompt");
|
|
699
|
-
sections.push("");
|
|
700
|
-
sections.push("The following prompt was generated by `@bensandee/tooling repo:init`. Paste it into Claude Code or another AI assistant to finish migrating this repository.");
|
|
701
|
-
sections.push("");
|
|
702
|
-
sections.push("> **Tip:** Before starting, run `/init` in Claude Code to generate a `CLAUDE.md` that gives the AI a complete picture of your repository's structure, conventions, and build commands.");
|
|
703
|
-
sections.push("");
|
|
704
|
-
sections.push("## What was changed");
|
|
705
|
-
sections.push("");
|
|
706
|
-
const created = results.filter((r) => r.action === "created");
|
|
707
|
-
const updated = results.filter((r) => r.action === "updated");
|
|
708
|
-
const skipped = results.filter((r) => r.action === "skipped");
|
|
709
|
-
const archived = results.filter((r) => r.action === "archived");
|
|
710
|
-
if (created.length > 0) {
|
|
711
|
-
sections.push("**Created:**");
|
|
712
|
-
for (const r of created) sections.push(`- \`${r.filePath}\` — ${r.description}`);
|
|
713
|
-
sections.push("");
|
|
714
|
-
}
|
|
715
|
-
if (updated.length > 0) {
|
|
716
|
-
sections.push("**Updated:**");
|
|
717
|
-
for (const r of updated) sections.push(`- \`${r.filePath}\` — ${r.description}`);
|
|
718
|
-
sections.push("");
|
|
719
|
-
}
|
|
720
|
-
if (archived.length > 0) {
|
|
721
|
-
sections.push("**Archived:**");
|
|
722
|
-
for (const r of archived) sections.push(`- \`${r.filePath}\` — ${r.description}`);
|
|
723
|
-
sections.push("");
|
|
724
|
-
}
|
|
725
|
-
if (skipped.length > 0) {
|
|
726
|
-
sections.push("**Skipped (review these):**");
|
|
727
|
-
for (const r of skipped) sections.push(`- \`${r.filePath}\` — ${r.description}`);
|
|
728
|
-
sections.push("");
|
|
729
|
-
}
|
|
730
|
-
sections.push("## Migration tasks");
|
|
731
|
-
sections.push("");
|
|
732
|
-
const legacyToRemove = detected.legacyConfigs.filter((legacy) => !(legacy.tool === "prettier" && config.formatter === "prettier"));
|
|
733
|
-
if (legacyToRemove.length > 0) {
|
|
734
|
-
sections.push("### Remove legacy tooling");
|
|
735
|
-
sections.push("");
|
|
736
|
-
for (const legacy of legacyToRemove) {
|
|
737
|
-
const replacement = {
|
|
738
|
-
eslint: "oxlint",
|
|
739
|
-
prettier: "oxfmt",
|
|
740
|
-
jest: "vitest",
|
|
741
|
-
webpack: "tsdown",
|
|
742
|
-
rollup: "tsdown"
|
|
743
|
-
}[legacy.tool];
|
|
744
|
-
sections.push(`- Remove ${legacy.tool} config files (${legacy.files.map((f) => `\`${f}\``).join(", ")}). This project now uses **${replacement}**.`);
|
|
745
|
-
sections.push(` - Uninstall ${legacy.tool}-related packages from devDependencies`);
|
|
746
|
-
if (legacy.tool === "eslint") sections.push(" - Migrate any custom ESLint rules that don't have oxlint equivalents");
|
|
747
|
-
if (legacy.tool === "jest") sections.push(" - Migrate any jest-specific test utilities (jest.mock, jest.fn) to vitest equivalents (vi.mock, vi.fn)");
|
|
748
|
-
}
|
|
749
|
-
sections.push("");
|
|
750
|
-
}
|
|
751
|
-
if (archived.length > 0) {
|
|
752
|
-
sections.push("### Review archived files");
|
|
753
|
-
sections.push("");
|
|
754
|
-
sections.push("The following files were modified or replaced. The originals have been saved to `.tooling-archived/`:");
|
|
755
|
-
sections.push("");
|
|
756
|
-
for (const r of archived) sections.push(`- \`${r.filePath}\` → \`.tooling-archived/${r.filePath}\``);
|
|
757
|
-
sections.push("");
|
|
758
|
-
sections.push("For each archived file, **diff the old version against the new one** and look for features, categories, or modules that were enabled in the original but are missing from the replacement. Focus on broad capability gaps rather than individual rule strictness (in general, being stricter is fine). Examples of what to look for:");
|
|
759
|
-
sections.push("");
|
|
760
|
-
sections.push("- **Lint configs**: enabled plugin categories (e.g. `jsx-a11y`, `import`, `react`, `nextjs`), custom `plugins` or `overrides`, file-scoped rule blocks");
|
|
761
|
-
sections.push("- **TypeScript configs**: compiler features like `jsx`, `paths`, `baseUrl`, or `references` that affect build behavior");
|
|
762
|
-
sections.push("- **Other configs**: feature flags, custom presets, or integrations that go beyond the default template");
|
|
763
|
-
sections.push("");
|
|
764
|
-
sections.push("If the old config had capabilities the new one lacks, port them into the new file. Then:");
|
|
765
|
-
sections.push("");
|
|
766
|
-
sections.push("1. If the project previously used `husky` and `lint-staged`, remove them from `devDependencies`");
|
|
767
|
-
sections.push("2. Delete the `.tooling-archived/` directory when migration is complete");
|
|
768
|
-
sections.push("");
|
|
769
|
-
}
|
|
770
|
-
const oxlintWasSkipped = results.find((r) => r.filePath === "oxlint.config.ts")?.action === "skipped";
|
|
771
|
-
if (detected.hasLegacyOxlintJson) {
|
|
772
|
-
sections.push("### Migrate .oxlintrc.json to oxlint.config.ts");
|
|
773
|
-
sections.push("");
|
|
774
|
-
sections.push("A new `oxlint.config.ts` has been generated using `defineConfig` from the `oxlint` package. The existing `.oxlintrc.json` needs to be migrated:");
|
|
775
|
-
sections.push("");
|
|
776
|
-
sections.push("1. Read `.oxlintrc.json` and compare its `rules` against the rules provided by `@bensandee/config/oxlint/recommended` (check `node_modules/@bensandee/config`). Most standard rules are already included in the recommended config.");
|
|
777
|
-
sections.push("2. If there are any custom rules, overrides, settings, or `jsPlugins` not covered by the recommended config, add them to `oxlint.config.ts` alongside the `extends`.");
|
|
778
|
-
sections.push("3. Delete `.oxlintrc.json`.");
|
|
779
|
-
sections.push("4. Run `pnpm lint` to verify the new config works correctly.");
|
|
780
|
-
sections.push("");
|
|
781
|
-
} else if (oxlintWasSkipped && detected.hasOxlintConfig) {
|
|
782
|
-
sections.push("### Verify oxlint.config.ts includes recommended rules");
|
|
783
|
-
sections.push("");
|
|
784
|
-
sections.push("The existing `oxlint.config.ts` was kept as-is. Verify that it extends the recommended config from `@bensandee/config/oxlint`:");
|
|
785
|
-
sections.push("");
|
|
786
|
-
sections.push("1. Open `oxlint.config.ts` and check that it imports and extends `@bensandee/config/oxlint/recommended`.");
|
|
787
|
-
sections.push("2. The expected pattern is:");
|
|
788
|
-
sections.push(" ```ts");
|
|
789
|
-
sections.push(" import recommended from \"@bensandee/config/oxlint/recommended\";");
|
|
790
|
-
sections.push(" import { defineConfig } from \"oxlint\";");
|
|
791
|
-
sections.push("");
|
|
792
|
-
sections.push(" export default defineConfig({ extends: [recommended] });");
|
|
793
|
-
sections.push(" ```");
|
|
794
|
-
sections.push("3. If it uses a different pattern, update it to extend the recommended config while preserving any project-specific customizations.");
|
|
795
|
-
sections.push("4. Run `pnpm lint` to verify the config works correctly.");
|
|
796
|
-
sections.push("");
|
|
797
|
-
}
|
|
798
|
-
if (config.structure === "monorepo" && !detected.hasPnpmWorkspace) {
|
|
799
|
-
sections.push("### Migrate to monorepo structure");
|
|
800
|
-
sections.push("");
|
|
801
|
-
sections.push("This project was converted from a single repo to a monorepo. Complete the migration:");
|
|
802
|
-
sections.push("");
|
|
803
|
-
sections.push("1. Move existing source into `packages/<name>/` (using the existing package name)");
|
|
804
|
-
sections.push("2. Split the root `package.json` into a root workspace manifest + package-level `package.json`");
|
|
805
|
-
sections.push("3. Move the existing `tsconfig.json` into the package and update the root tsconfig with project references");
|
|
806
|
-
sections.push("4. Create a package-level `tsdown.config.ts` in the new package");
|
|
807
|
-
sections.push("5. Update any import paths or build scripts affected by the move");
|
|
808
|
-
sections.push("");
|
|
809
|
-
}
|
|
810
|
-
const skippedConfigs = skipped.filter((r) => r.filePath !== "ci" && r.description !== "Not a monorepo");
|
|
811
|
-
if (skippedConfigs.length > 0) {
|
|
812
|
-
sections.push("### Review skipped files");
|
|
813
|
-
sections.push("");
|
|
814
|
-
sections.push("The following files were left unchanged. Review them for compatibility:");
|
|
815
|
-
sections.push("");
|
|
816
|
-
for (const r of skippedConfigs) sections.push(`- \`${r.filePath}\` — ${r.description}`);
|
|
817
|
-
sections.push("");
|
|
818
|
-
}
|
|
819
|
-
if (results.some((r) => r.filePath === "test/example.test.ts" && r.action === "created")) {
|
|
820
|
-
sections.push("### Generate tests");
|
|
821
|
-
sections.push("");
|
|
822
|
-
sections.push("A starter test was created at `test/example.test.ts`. Now:");
|
|
823
|
-
sections.push("");
|
|
824
|
-
sections.push("1. Review the existing source code in `src/`");
|
|
825
|
-
sections.push("2. Create additional test files following the starter test's patterns (import style, describe/it structure)");
|
|
826
|
-
sections.push("3. Focus on edge cases and core business logic");
|
|
827
|
-
sections.push("4. Aim for meaningful coverage of exported functions and key code paths");
|
|
828
|
-
sections.push("");
|
|
829
|
-
}
|
|
830
|
-
sections.push("## Ground rules");
|
|
831
|
-
sections.push("");
|
|
832
|
-
sections.push("It is OK to add new packages (e.g. `zod`, `@bensandee/common`) if they are needed to resolve errors.");
|
|
833
|
-
sections.push("");
|
|
834
|
-
sections.push("When resolving errors from the checklist below, prefer fixing the root cause over suppressing the issue. For example:");
|
|
835
|
-
sections.push("");
|
|
836
|
-
sections.push("- **Lint errors**: fix the code rather than adding disable comments or rule exceptions");
|
|
837
|
-
sections.push("- **Test failures**: update the test or fix the underlying bug rather than skipping or deleting the test");
|
|
838
|
-
sections.push("- **Knip findings**: remove genuinely unused code/exports/dependencies rather than adding ignores to `knip.config.ts`");
|
|
839
|
-
sections.push("- **Type errors**: add proper types rather than using `any` or `@ts-expect-error`");
|
|
840
|
-
sections.push("");
|
|
841
|
-
sections.push("Only suppress an issue if there is a clear, documented reason why the fix is not feasible (e.g. a third-party type mismatch). Leave a comment explaining why.");
|
|
842
|
-
sections.push("");
|
|
843
|
-
sections.push("## Verification checklist");
|
|
844
|
-
sections.push("");
|
|
845
|
-
sections.push("Run each of these commands and fix any errors before moving on:");
|
|
846
|
-
sections.push("");
|
|
847
|
-
sections.push("1. `pnpm install`");
|
|
848
|
-
const updateCmd = `pnpm update --latest ${getAddedDevDepNames(config).join(" ")}`;
|
|
849
|
-
sections.push(`2. \`${updateCmd}\` — bump added dependencies to their latest versions`);
|
|
850
|
-
sections.push("3. `pnpm typecheck` — fix any type errors");
|
|
851
|
-
sections.push("4. `pnpm build` — fix any build errors");
|
|
852
|
-
sections.push("5. `pnpm test` — fix any test failures");
|
|
853
|
-
sections.push("6. `pnpm lint` — fix the code to satisfy lint rules");
|
|
854
|
-
sections.push("7. `pnpm knip` — remove unused exports, dependencies, and dead code");
|
|
855
|
-
sections.push("8. `pnpm format` — fix any formatting issues");
|
|
856
|
-
sections.push("");
|
|
857
|
-
return sections.join("\n");
|
|
858
|
-
}
|
|
859
|
-
//#endregion
|
|
860
737
|
//#region src/generators/tsconfig.ts
|
|
861
738
|
async function generateTsconfig(ctx) {
|
|
862
739
|
const filePath = "tsconfig.json";
|
|
@@ -1210,7 +1087,7 @@ async function generateTsdown(ctx) {
|
|
|
1210
1087
|
}
|
|
1211
1088
|
//#endregion
|
|
1212
1089
|
//#region src/generators/gitignore.ts
|
|
1213
|
-
/** Entries that every project should have — repo:check flags these as missing. */
|
|
1090
|
+
/** Entries that every project should have — repo:sync --check flags these as missing. */
|
|
1214
1091
|
const REQUIRED_ENTRIES = [
|
|
1215
1092
|
"node_modules/",
|
|
1216
1093
|
".pnpm-store/",
|
|
@@ -1220,7 +1097,7 @@ const REQUIRED_ENTRIES = [
|
|
|
1220
1097
|
".env.*",
|
|
1221
1098
|
"!.env.example"
|
|
1222
1099
|
];
|
|
1223
|
-
/** Tooling-specific entries added during init/update but not required for repo:check. */
|
|
1100
|
+
/** Tooling-specific entries added during init/update but not required for repo:sync --check. */
|
|
1224
1101
|
const OPTIONAL_ENTRIES = [".tooling-migrate.md", ".tooling-archived/"];
|
|
1225
1102
|
const ALL_ENTRIES = [...REQUIRED_ENTRIES, ...OPTIONAL_ENTRIES];
|
|
1226
1103
|
/** Normalize a gitignore entry for comparison: strip leading `/` and trailing `/`. */
|
|
@@ -2575,9 +2452,28 @@ function requiredDeploySteps() {
|
|
|
2575
2452
|
}
|
|
2576
2453
|
];
|
|
2577
2454
|
}
|
|
2455
|
+
/** Convention paths to check for Dockerfiles. */
|
|
2456
|
+
const CONVENTION_DOCKERFILE_PATHS$1 = ["Dockerfile", "docker/Dockerfile"];
|
|
2457
|
+
const DockerMapSchema = z.object({ docker: z.record(z.string(), z.unknown()).optional() });
|
|
2458
|
+
/** Check whether any Docker packages exist by convention or .tooling.json config. */
|
|
2459
|
+
function hasDockerPackages(ctx) {
|
|
2460
|
+
const configRaw = ctx.read(".tooling.json");
|
|
2461
|
+
if (configRaw) {
|
|
2462
|
+
const result = DockerMapSchema.safeParse(JSON.parse(configRaw));
|
|
2463
|
+
if (result.success && result.data.docker && Object.keys(result.data.docker).length > 0) return true;
|
|
2464
|
+
}
|
|
2465
|
+
if (ctx.config.structure === "monorepo") {
|
|
2466
|
+
const packages = getMonorepoPackages(ctx.targetDir);
|
|
2467
|
+
for (const pkg of packages) {
|
|
2468
|
+
const dirName = pkg.name.split("/").pop() ?? pkg.name;
|
|
2469
|
+
for (const rel of CONVENTION_DOCKERFILE_PATHS$1) if (ctx.exists(`packages/${dirName}/${rel}`)) return true;
|
|
2470
|
+
}
|
|
2471
|
+
} else for (const rel of CONVENTION_DOCKERFILE_PATHS$1) if (ctx.exists(rel)) return true;
|
|
2472
|
+
return false;
|
|
2473
|
+
}
|
|
2578
2474
|
async function generateDeployCi(ctx) {
|
|
2579
2475
|
const filePath = "deploy-ci";
|
|
2580
|
-
if (!ctx
|
|
2476
|
+
if (!hasDockerPackages(ctx) || ctx.config.ci === "none") return {
|
|
2581
2477
|
filePath,
|
|
2582
2478
|
action: "skipped",
|
|
2583
2479
|
description: "Deploy CI workflow not applicable"
|
|
@@ -2662,142 +2558,180 @@ async function runGenerators(ctx) {
|
|
|
2662
2558
|
results.push(await generateDeployCi(ctx));
|
|
2663
2559
|
results.push(...await generateVitest(ctx));
|
|
2664
2560
|
results.push(...await generateVscodeSettings(ctx));
|
|
2561
|
+
results.push(saveToolingConfig(ctx, ctx.config));
|
|
2665
2562
|
return results;
|
|
2666
2563
|
}
|
|
2667
2564
|
//#endregion
|
|
2668
|
-
//#region src/
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
"
|
|
2689
|
-
|
|
2690
|
-
"
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
});
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2565
|
+
//#region src/generators/migrate-prompt.ts
|
|
2566
|
+
/**
|
|
2567
|
+
* Generate a context-aware AI migration prompt based on what the CLI did.
|
|
2568
|
+
* This prompt can be pasted into Claude Code (or similar) to finish the migration.
|
|
2569
|
+
*/
|
|
2570
|
+
function generateMigratePrompt(results, config, detected) {
|
|
2571
|
+
const sections = [];
|
|
2572
|
+
sections.push("# Migration Prompt");
|
|
2573
|
+
sections.push("");
|
|
2574
|
+
sections.push("The following prompt was generated by `@bensandee/tooling repo:sync`. Paste it into Claude Code or another AI assistant to finish migrating this repository.");
|
|
2575
|
+
sections.push("");
|
|
2576
|
+
sections.push("> **Tip:** Before starting, run `/init` in Claude Code to generate a `CLAUDE.md` that gives the AI a complete picture of your repository's structure, conventions, and build commands.");
|
|
2577
|
+
sections.push("");
|
|
2578
|
+
sections.push("## What was changed");
|
|
2579
|
+
sections.push("");
|
|
2580
|
+
const created = results.filter((r) => r.action === "created");
|
|
2581
|
+
const updated = results.filter((r) => r.action === "updated");
|
|
2582
|
+
const skipped = results.filter((r) => r.action === "skipped");
|
|
2583
|
+
const archived = results.filter((r) => r.action === "archived");
|
|
2584
|
+
if (created.length > 0) {
|
|
2585
|
+
sections.push("**Created:**");
|
|
2586
|
+
for (const r of created) sections.push(`- \`${r.filePath}\` — ${r.description}`);
|
|
2587
|
+
sections.push("");
|
|
2588
|
+
}
|
|
2589
|
+
if (updated.length > 0) {
|
|
2590
|
+
sections.push("**Updated:**");
|
|
2591
|
+
for (const r of updated) sections.push(`- \`${r.filePath}\` — ${r.description}`);
|
|
2592
|
+
sections.push("");
|
|
2593
|
+
}
|
|
2594
|
+
if (archived.length > 0) {
|
|
2595
|
+
sections.push("**Archived:**");
|
|
2596
|
+
for (const r of archived) sections.push(`- \`${r.filePath}\` — ${r.description}`);
|
|
2597
|
+
sections.push("");
|
|
2598
|
+
}
|
|
2599
|
+
if (skipped.length > 0) {
|
|
2600
|
+
sections.push("**Skipped (review these):**");
|
|
2601
|
+
for (const r of skipped) sections.push(`- \`${r.filePath}\` — ${r.description}`);
|
|
2602
|
+
sections.push("");
|
|
2603
|
+
}
|
|
2604
|
+
sections.push("## Migration tasks");
|
|
2605
|
+
sections.push("");
|
|
2606
|
+
const legacyToRemove = detected.legacyConfigs.filter((legacy) => !(legacy.tool === "prettier" && config.formatter === "prettier"));
|
|
2607
|
+
if (legacyToRemove.length > 0) {
|
|
2608
|
+
sections.push("### Remove legacy tooling");
|
|
2609
|
+
sections.push("");
|
|
2610
|
+
for (const legacy of legacyToRemove) {
|
|
2611
|
+
const replacement = {
|
|
2612
|
+
eslint: "oxlint",
|
|
2613
|
+
prettier: "oxfmt",
|
|
2614
|
+
jest: "vitest",
|
|
2615
|
+
webpack: "tsdown",
|
|
2616
|
+
rollup: "tsdown"
|
|
2617
|
+
}[legacy.tool];
|
|
2618
|
+
sections.push(`- Remove ${legacy.tool} config files (${legacy.files.map((f) => `\`${f}\``).join(", ")}). This project now uses **${replacement}**.`);
|
|
2619
|
+
sections.push(` - Uninstall ${legacy.tool}-related packages from devDependencies`);
|
|
2620
|
+
if (legacy.tool === "eslint") sections.push(" - Migrate any custom ESLint rules that don't have oxlint equivalents");
|
|
2621
|
+
if (legacy.tool === "jest") sections.push(" - Migrate any jest-specific test utilities (jest.mock, jest.fn) to vitest equivalents (vi.mock, vi.fn)");
|
|
2622
|
+
}
|
|
2623
|
+
sections.push("");
|
|
2710
2624
|
}
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2625
|
+
if (archived.length > 0) {
|
|
2626
|
+
sections.push("### Review archived files");
|
|
2627
|
+
sections.push("");
|
|
2628
|
+
sections.push("The following files were modified or replaced. The originals have been saved to `.tooling-archived/`:");
|
|
2629
|
+
sections.push("");
|
|
2630
|
+
for (const r of archived) sections.push(`- \`${r.filePath}\` → \`.tooling-archived/${r.filePath}\``);
|
|
2631
|
+
sections.push("");
|
|
2632
|
+
sections.push("For each archived file, **diff the old version against the new one** and look for features, categories, or modules that were enabled in the original but are missing from the replacement. Focus on broad capability gaps rather than individual rule strictness (in general, being stricter is fine). Examples of what to look for:");
|
|
2633
|
+
sections.push("");
|
|
2634
|
+
sections.push("- **Lint configs**: enabled plugin categories (e.g. `jsx-a11y`, `import`, `react`, `nextjs`), custom `plugins` or `overrides`, file-scoped rule blocks");
|
|
2635
|
+
sections.push("- **TypeScript configs**: compiler features like `jsx`, `paths`, `baseUrl`, or `references` that affect build behavior");
|
|
2636
|
+
sections.push("- **Other configs**: feature flags, custom presets, or integrations that go beyond the default template");
|
|
2637
|
+
sections.push("");
|
|
2638
|
+
sections.push("If the old config had capabilities the new one lacks, port them into the new file. Then:");
|
|
2639
|
+
sections.push("");
|
|
2640
|
+
sections.push("1. If the project previously used `husky` and `lint-staged`, remove them from `devDependencies`");
|
|
2641
|
+
sections.push("2. Delete the `.tooling-archived/` directory when migration is complete");
|
|
2642
|
+
sections.push("");
|
|
2643
|
+
}
|
|
2644
|
+
const oxlintWasSkipped = results.find((r) => r.filePath === "oxlint.config.ts")?.action === "skipped";
|
|
2645
|
+
if (detected.hasLegacyOxlintJson) {
|
|
2646
|
+
sections.push("### Migrate .oxlintrc.json to oxlint.config.ts");
|
|
2647
|
+
sections.push("");
|
|
2648
|
+
sections.push("A new `oxlint.config.ts` has been generated using `defineConfig` from the `oxlint` package. The existing `.oxlintrc.json` needs to be migrated:");
|
|
2649
|
+
sections.push("");
|
|
2650
|
+
sections.push("1. Read `.oxlintrc.json` and compare its `rules` against the rules provided by `@bensandee/config/oxlint/recommended` (check `node_modules/@bensandee/config`). Most standard rules are already included in the recommended config.");
|
|
2651
|
+
sections.push("2. If there are any custom rules, overrides, settings, or `jsPlugins` not covered by the recommended config, add them to `oxlint.config.ts` alongside the `extends`.");
|
|
2652
|
+
sections.push("3. Delete `.oxlintrc.json`.");
|
|
2653
|
+
sections.push("4. Run `pnpm lint` to verify the new config works correctly.");
|
|
2654
|
+
sections.push("");
|
|
2655
|
+
} else if (oxlintWasSkipped && detected.hasOxlintConfig) {
|
|
2656
|
+
sections.push("### Verify oxlint.config.ts includes recommended rules");
|
|
2657
|
+
sections.push("");
|
|
2658
|
+
sections.push("The existing `oxlint.config.ts` was kept as-is. Verify that it extends the recommended config from `@bensandee/config/oxlint`:");
|
|
2659
|
+
sections.push("");
|
|
2660
|
+
sections.push("1. Open `oxlint.config.ts` and check that it imports and extends `@bensandee/config/oxlint/recommended`.");
|
|
2661
|
+
sections.push("2. The expected pattern is:");
|
|
2662
|
+
sections.push(" ```ts");
|
|
2663
|
+
sections.push(" import recommended from \"@bensandee/config/oxlint/recommended\";");
|
|
2664
|
+
sections.push(" import { defineConfig } from \"oxlint\";");
|
|
2665
|
+
sections.push("");
|
|
2666
|
+
sections.push(" export default defineConfig({ extends: [recommended] });");
|
|
2667
|
+
sections.push(" ```");
|
|
2668
|
+
sections.push("3. If it uses a different pattern, update it to extend the recommended config while preserving any project-specific customizations.");
|
|
2669
|
+
sections.push("4. Run `pnpm lint` to verify the config works correctly.");
|
|
2670
|
+
sections.push("");
|
|
2671
|
+
}
|
|
2672
|
+
if (config.structure === "monorepo" && !detected.hasPnpmWorkspace) {
|
|
2673
|
+
sections.push("### Migrate to monorepo structure");
|
|
2674
|
+
sections.push("");
|
|
2675
|
+
sections.push("This project was converted from a single repo to a monorepo. Complete the migration:");
|
|
2676
|
+
sections.push("");
|
|
2677
|
+
sections.push("1. Move existing source into `packages/<name>/` (using the existing package name)");
|
|
2678
|
+
sections.push("2. Split the root `package.json` into a root workspace manifest + package-level `package.json`");
|
|
2679
|
+
sections.push("3. Move the existing `tsconfig.json` into the package and update the root tsconfig with project references");
|
|
2680
|
+
sections.push("4. Create a package-level `tsdown.config.ts` in the new package");
|
|
2681
|
+
sections.push("5. Update any import paths or build scripts affected by the move");
|
|
2682
|
+
sections.push("");
|
|
2683
|
+
}
|
|
2684
|
+
const skippedConfigs = skipped.filter((r) => r.filePath !== "ci" && r.description !== "Not a monorepo");
|
|
2685
|
+
if (skippedConfigs.length > 0) {
|
|
2686
|
+
sections.push("### Review skipped files");
|
|
2687
|
+
sections.push("");
|
|
2688
|
+
sections.push("The following files were left unchanged. Review them for compatibility:");
|
|
2689
|
+
sections.push("");
|
|
2690
|
+
for (const r of skippedConfigs) sections.push(`- \`${r.filePath}\` — ${r.description}`);
|
|
2691
|
+
sections.push("");
|
|
2692
|
+
}
|
|
2693
|
+
if (results.some((r) => r.filePath === "test/example.test.ts" && r.action === "created")) {
|
|
2694
|
+
sections.push("### Generate tests");
|
|
2695
|
+
sections.push("");
|
|
2696
|
+
sections.push("A starter test was created at `test/example.test.ts`. Now:");
|
|
2697
|
+
sections.push("");
|
|
2698
|
+
sections.push("1. Review the existing source code in `src/`");
|
|
2699
|
+
sections.push("2. Create additional test files following the starter test's patterns (import style, describe/it structure)");
|
|
2700
|
+
sections.push("3. Focus on edge cases and core business logic");
|
|
2701
|
+
sections.push("4. Aim for meaningful coverage of exported functions and key code paths");
|
|
2702
|
+
sections.push("");
|
|
2703
|
+
}
|
|
2704
|
+
sections.push("## Ground rules");
|
|
2705
|
+
sections.push("");
|
|
2706
|
+
sections.push("It is OK to add new packages (e.g. `zod`, `@bensandee/common`) if they are needed to resolve errors.");
|
|
2707
|
+
sections.push("");
|
|
2708
|
+
sections.push("When resolving errors from the checklist below, prefer fixing the root cause over suppressing the issue. For example:");
|
|
2709
|
+
sections.push("");
|
|
2710
|
+
sections.push("- **Lint errors**: fix the code rather than adding disable comments or rule exceptions");
|
|
2711
|
+
sections.push("- **Test failures**: update the test or fix the underlying bug rather than skipping or deleting the test");
|
|
2712
|
+
sections.push("- **Knip findings**: remove genuinely unused code/exports/dependencies rather than adding ignores to `knip.config.ts`");
|
|
2713
|
+
sections.push("- **Type errors**: add proper types rather than using `any` or `@ts-expect-error`");
|
|
2714
|
+
sections.push("");
|
|
2715
|
+
sections.push("Only suppress an issue if there is a clear, documented reason why the fix is not feasible (e.g. a third-party type mismatch). Leave a comment explaining why.");
|
|
2716
|
+
sections.push("");
|
|
2717
|
+
sections.push("## Verification checklist");
|
|
2718
|
+
sections.push("");
|
|
2719
|
+
sections.push("Run each of these commands and fix any errors before moving on:");
|
|
2720
|
+
sections.push("");
|
|
2721
|
+
sections.push("1. `pnpm install`");
|
|
2722
|
+
const updateCmd = `pnpm update --latest ${getAddedDevDepNames(config).join(" ")}`;
|
|
2723
|
+
sections.push(`2. \`${updateCmd}\` — bump added dependencies to their latest versions`);
|
|
2724
|
+
sections.push("3. `pnpm typecheck` — fix any type errors");
|
|
2725
|
+
sections.push("4. `pnpm build` — fix any build errors");
|
|
2726
|
+
sections.push("5. `pnpm test` — fix any test failures");
|
|
2727
|
+
sections.push("6. `pnpm lint` — fix the code to satisfy lint rules");
|
|
2728
|
+
sections.push("7. `pnpm knip` — remove unused exports, dependencies, and dead code");
|
|
2729
|
+
sections.push("8. `pnpm format` — fix any formatting issues");
|
|
2730
|
+
sections.push("");
|
|
2731
|
+
return sections.join("\n");
|
|
2757
2732
|
}
|
|
2758
2733
|
//#endregion
|
|
2759
2734
|
//#region src/commands/repo-init.ts
|
|
2760
|
-
const initCommand = defineCommand({
|
|
2761
|
-
meta: {
|
|
2762
|
-
name: "repo:init",
|
|
2763
|
-
description: "Interactive setup wizard"
|
|
2764
|
-
},
|
|
2765
|
-
args: {
|
|
2766
|
-
dir: {
|
|
2767
|
-
type: "positional",
|
|
2768
|
-
description: "Target directory (default: current directory)",
|
|
2769
|
-
required: false
|
|
2770
|
-
},
|
|
2771
|
-
yes: {
|
|
2772
|
-
type: "boolean",
|
|
2773
|
-
alias: "y",
|
|
2774
|
-
description: "Accept all defaults (non-interactive)"
|
|
2775
|
-
},
|
|
2776
|
-
"eslint-plugin": {
|
|
2777
|
-
type: "boolean",
|
|
2778
|
-
description: "Include @bensandee/eslint-plugin (default: true)"
|
|
2779
|
-
},
|
|
2780
|
-
"no-ci": {
|
|
2781
|
-
type: "boolean",
|
|
2782
|
-
description: "Skip CI workflow generation"
|
|
2783
|
-
},
|
|
2784
|
-
"no-prompt": {
|
|
2785
|
-
type: "boolean",
|
|
2786
|
-
description: "Skip migration prompt generation"
|
|
2787
|
-
}
|
|
2788
|
-
},
|
|
2789
|
-
async run({ args }) {
|
|
2790
|
-
const targetDir = path.resolve(args.dir ?? ".");
|
|
2791
|
-
const saved = loadToolingConfig(targetDir);
|
|
2792
|
-
await runInit(args.yes ? (() => {
|
|
2793
|
-
const detected = buildDefaultConfig(targetDir, {
|
|
2794
|
-
eslintPlugin: args["eslint-plugin"] === true ? true : void 0,
|
|
2795
|
-
noCi: args["no-ci"] === true ? true : void 0
|
|
2796
|
-
});
|
|
2797
|
-
return saved ? mergeWithSavedConfig(detected, saved) : detected;
|
|
2798
|
-
})() : await runInitPrompts(targetDir, saved), args["no-prompt"] === true ? { noPrompt: true } : {});
|
|
2799
|
-
}
|
|
2800
|
-
});
|
|
2801
2735
|
async function runInit(config, options = {}) {
|
|
2802
2736
|
const detected = detectProject(config.targetDir);
|
|
2803
2737
|
const s = p.spinner();
|
|
@@ -2819,7 +2753,6 @@ async function runInit(config, options = {}) {
|
|
|
2819
2753
|
}));
|
|
2820
2754
|
s.start("Generating configuration files...");
|
|
2821
2755
|
const results = await runGenerators(ctx);
|
|
2822
|
-
results.push(saveToolingConfig(ctx, config));
|
|
2823
2756
|
const alreadyArchived = new Set(results.filter((r) => r.action === "archived").map((r) => r.filePath));
|
|
2824
2757
|
for (const rel of archivedFiles) if (!alreadyArchived.has(rel)) results.push({
|
|
2825
2758
|
filePath: rel,
|
|
@@ -2828,7 +2761,6 @@ async function runInit(config, options = {}) {
|
|
|
2828
2761
|
});
|
|
2829
2762
|
const created = results.filter((r) => r.action === "created");
|
|
2830
2763
|
const updated = results.filter((r) => r.action === "updated");
|
|
2831
|
-
const skipped = results.filter((r) => r.action === "skipped");
|
|
2832
2764
|
const archived = results.filter((r) => r.action === "archived");
|
|
2833
2765
|
if (!(created.length > 0 || updated.length > 0 || archived.length > 0) && options.noPrompt) {
|
|
2834
2766
|
s.stop("Repository is up to date.");
|
|
@@ -2845,7 +2777,6 @@ async function runInit(config, options = {}) {
|
|
|
2845
2777
|
if (created.length > 0) summaryLines.push(`Created: ${created.map((r) => r.filePath).join(", ")}`);
|
|
2846
2778
|
if (updated.length > 0) summaryLines.push(`Updated: ${updated.map((r) => r.filePath).join(", ")}`);
|
|
2847
2779
|
if (archived.length > 0) summaryLines.push(`Archived: ${archived.map((r) => r.filePath).join(", ")}`);
|
|
2848
|
-
if (skipped.length > 0) summaryLines.push(`Skipped: ${skipped.map((r) => r.filePath).join(", ")}`);
|
|
2849
2780
|
p.note(summaryLines.join("\n"), "Summary");
|
|
2850
2781
|
if (!options.noPrompt) {
|
|
2851
2782
|
const prompt = generateMigratePrompt(results, config, detected);
|
|
@@ -2878,57 +2809,68 @@ async function runInit(config, options = {}) {
|
|
|
2878
2809
|
return results;
|
|
2879
2810
|
}
|
|
2880
2811
|
//#endregion
|
|
2881
|
-
//#region src/commands/repo-
|
|
2882
|
-
const
|
|
2812
|
+
//#region src/commands/repo-sync.ts
|
|
2813
|
+
const syncCommand = defineCommand({
|
|
2883
2814
|
meta: {
|
|
2884
|
-
name: "repo:
|
|
2885
|
-
description: "
|
|
2815
|
+
name: "repo:sync",
|
|
2816
|
+
description: "Detect, generate, and sync project tooling (idempotent)"
|
|
2886
2817
|
},
|
|
2887
|
-
args: {
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2818
|
+
args: {
|
|
2819
|
+
dir: {
|
|
2820
|
+
type: "positional",
|
|
2821
|
+
description: "Target directory (default: current directory)",
|
|
2822
|
+
required: false
|
|
2823
|
+
},
|
|
2824
|
+
check: {
|
|
2825
|
+
type: "boolean",
|
|
2826
|
+
description: "Dry-run mode: report drift without writing files"
|
|
2827
|
+
},
|
|
2828
|
+
yes: {
|
|
2829
|
+
type: "boolean",
|
|
2830
|
+
alias: "y",
|
|
2831
|
+
description: "Accept all defaults (non-interactive)"
|
|
2832
|
+
},
|
|
2833
|
+
"eslint-plugin": {
|
|
2834
|
+
type: "boolean",
|
|
2835
|
+
description: "Include @bensandee/eslint-plugin (default: true)"
|
|
2836
|
+
},
|
|
2837
|
+
"no-ci": {
|
|
2838
|
+
type: "boolean",
|
|
2839
|
+
description: "Skip CI workflow generation"
|
|
2840
|
+
},
|
|
2841
|
+
"no-prompt": {
|
|
2842
|
+
type: "boolean",
|
|
2843
|
+
description: "Skip migration prompt generation"
|
|
2844
|
+
}
|
|
2914
2845
|
},
|
|
2915
|
-
args: { dir: {
|
|
2916
|
-
type: "positional",
|
|
2917
|
-
description: "Target directory (default: current directory)",
|
|
2918
|
-
required: false
|
|
2919
|
-
} },
|
|
2920
2846
|
async run({ args }) {
|
|
2921
|
-
const
|
|
2922
|
-
|
|
2847
|
+
const targetDir = path.resolve(args.dir ?? ".");
|
|
2848
|
+
if (args.check) {
|
|
2849
|
+
const exitCode = await runCheck(targetDir);
|
|
2850
|
+
process.exitCode = exitCode;
|
|
2851
|
+
return;
|
|
2852
|
+
}
|
|
2853
|
+
const saved = loadToolingConfig(targetDir);
|
|
2854
|
+
const isFirstRun = !saved;
|
|
2855
|
+
let config;
|
|
2856
|
+
if (args.yes || !isFirstRun) {
|
|
2857
|
+
const detected = buildDefaultConfig(targetDir, {
|
|
2858
|
+
eslintPlugin: args["eslint-plugin"] === true ? true : void 0,
|
|
2859
|
+
noCi: args["no-ci"] === true ? true : void 0
|
|
2860
|
+
});
|
|
2861
|
+
config = saved ? mergeWithSavedConfig(detected, saved) : detected;
|
|
2862
|
+
} else config = await runInitPrompts(targetDir, saved);
|
|
2863
|
+
await runInit(config, {
|
|
2864
|
+
noPrompt: args["no-prompt"] === true || !isFirstRun,
|
|
2865
|
+
...!isFirstRun && { confirmOverwrite: async () => "overwrite" }
|
|
2866
|
+
});
|
|
2923
2867
|
}
|
|
2924
2868
|
});
|
|
2869
|
+
/** Run sync in check mode: dry-run drift detection. */
|
|
2925
2870
|
async function runCheck(targetDir) {
|
|
2926
2871
|
const saved = loadToolingConfig(targetDir);
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
return 1;
|
|
2930
|
-
}
|
|
2931
|
-
const { ctx, pendingWrites } = createDryRunContext(mergeWithSavedConfig(buildDefaultConfig(targetDir, {}), saved));
|
|
2872
|
+
const detected = buildDefaultConfig(targetDir, {});
|
|
2873
|
+
const { ctx, pendingWrites } = createDryRunContext(saved ? mergeWithSavedConfig(detected, saved) : detected);
|
|
2932
2874
|
const actionable = (await runGenerators(ctx)).filter((r) => {
|
|
2933
2875
|
if (r.action !== "created" && r.action !== "updated") return false;
|
|
2934
2876
|
const newContent = pendingWrites.get(r.filePath);
|
|
@@ -2943,7 +2885,7 @@ async function runCheck(targetDir) {
|
|
|
2943
2885
|
p.log.success("Repository is up to date.");
|
|
2944
2886
|
return 0;
|
|
2945
2887
|
}
|
|
2946
|
-
p.log.warn(`${actionable.length} file(s) would be changed by repo:
|
|
2888
|
+
p.log.warn(`${actionable.length} file(s) would be changed by repo:sync`);
|
|
2947
2889
|
for (const r of actionable) {
|
|
2948
2890
|
p.log.info(` ${r.action}: ${r.filePath} — ${r.description}`);
|
|
2949
2891
|
const newContent = pendingWrites.get(r.filePath);
|
|
@@ -2955,13 +2897,12 @@ async function runCheck(targetDir) {
|
|
|
2955
2897
|
p.log.info(` + ${lineCount} new lines`);
|
|
2956
2898
|
} else {
|
|
2957
2899
|
const diff = lineDiff(existing, newContent);
|
|
2958
|
-
|
|
2900
|
+
for (const line of diff) p.log.info(` ${line}`);
|
|
2959
2901
|
}
|
|
2960
2902
|
}
|
|
2961
2903
|
return 1;
|
|
2962
2904
|
}
|
|
2963
2905
|
const normalize = (line) => line.trimEnd();
|
|
2964
|
-
/** Produce a compact line-level diff summary, ignoring whitespace-only differences. */
|
|
2965
2906
|
function lineDiff(oldText, newText) {
|
|
2966
2907
|
const oldLines = oldText.split("\n").map(normalize);
|
|
2967
2908
|
const newLines = newText.split("\n").map(normalize);
|
|
@@ -3038,6 +2979,14 @@ function createRealExecutor() {
|
|
|
3038
2979
|
} catch (_error) {}
|
|
3039
2980
|
return packages;
|
|
3040
2981
|
},
|
|
2982
|
+
listPackageDirs(cwd) {
|
|
2983
|
+
const packagesDir = path.join(cwd, "packages");
|
|
2984
|
+
try {
|
|
2985
|
+
return readdirSync(packagesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
2986
|
+
} catch {
|
|
2987
|
+
return [];
|
|
2988
|
+
}
|
|
2989
|
+
},
|
|
3041
2990
|
readFile(filePath) {
|
|
3042
2991
|
try {
|
|
3043
2992
|
return readFileSync(filePath, "utf-8");
|
|
@@ -3986,34 +3935,95 @@ function readPackageInfo(executor, packageJsonPath) {
|
|
|
3986
3935
|
};
|
|
3987
3936
|
}
|
|
3988
3937
|
}
|
|
3938
|
+
/** Convention paths to check for Dockerfiles in a package directory. */
|
|
3939
|
+
const CONVENTION_DOCKERFILE_PATHS = ["Dockerfile", "docker/Dockerfile"];
|
|
3940
|
+
/**
|
|
3941
|
+
* Find a Dockerfile at convention paths for a monorepo package.
|
|
3942
|
+
* Checks packages/{dir}/Dockerfile and packages/{dir}/docker/Dockerfile.
|
|
3943
|
+
*/
|
|
3944
|
+
function findConventionDockerfile(executor, cwd, dir) {
|
|
3945
|
+
for (const rel of CONVENTION_DOCKERFILE_PATHS) {
|
|
3946
|
+
const dockerfilePath = `packages/${dir}/${rel}`;
|
|
3947
|
+
if (executor.readFile(path.join(cwd, dockerfilePath)) !== null) return {
|
|
3948
|
+
dockerfile: dockerfilePath,
|
|
3949
|
+
context: "."
|
|
3950
|
+
};
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3989
3953
|
/**
|
|
3990
|
-
*
|
|
3991
|
-
*
|
|
3954
|
+
* Find a Dockerfile at convention paths for a single-package repo.
|
|
3955
|
+
* Checks Dockerfile and docker/Dockerfile at the project root.
|
|
3956
|
+
*/
|
|
3957
|
+
function findRootDockerfile(executor, cwd) {
|
|
3958
|
+
for (const rel of CONVENTION_DOCKERFILE_PATHS) if (executor.readFile(path.join(cwd, rel)) !== null) return {
|
|
3959
|
+
dockerfile: rel,
|
|
3960
|
+
context: "."
|
|
3961
|
+
};
|
|
3962
|
+
}
|
|
3963
|
+
/**
|
|
3964
|
+
* Discover Docker packages by convention and merge with .tooling.json overrides.
|
|
3965
|
+
*
|
|
3966
|
+
* Convention: any package with a Dockerfile or docker/Dockerfile is a Docker package.
|
|
3967
|
+
* For monorepos, scans packages/{name}/. For single-package repos, scans the root.
|
|
3968
|
+
* The docker map in .tooling.json overrides convention-discovered config and can add
|
|
3969
|
+
* packages at non-standard locations.
|
|
3970
|
+
*
|
|
3992
3971
|
* Image names are derived from {root-name}-{package-name} using each package's package.json name.
|
|
3993
3972
|
* Versions are read from each package's own package.json.
|
|
3994
3973
|
*/
|
|
3995
3974
|
function detectDockerPackages(executor, cwd, repoName) {
|
|
3996
|
-
const
|
|
3975
|
+
const overrides = loadDockerMap(executor, cwd);
|
|
3976
|
+
const packageDirs = executor.listPackageDirs(cwd);
|
|
3997
3977
|
const packages = [];
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
dir
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
3978
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3979
|
+
if (packageDirs.length > 0) {
|
|
3980
|
+
for (const dir of packageDirs) {
|
|
3981
|
+
const convention = findConventionDockerfile(executor, cwd, dir);
|
|
3982
|
+
const docker = overrides[dir] ?? convention;
|
|
3983
|
+
if (docker) {
|
|
3984
|
+
const { name, version } = readPackageInfo(executor, path.join(cwd, "packages", dir, "package.json"));
|
|
3985
|
+
packages.push({
|
|
3986
|
+
dir,
|
|
3987
|
+
imageName: `${repoName}-${name ?? dir}`,
|
|
3988
|
+
version,
|
|
3989
|
+
docker
|
|
3990
|
+
});
|
|
3991
|
+
seen.add(dir);
|
|
3992
|
+
}
|
|
3993
|
+
}
|
|
3994
|
+
for (const [dir, docker] of Object.entries(overrides)) if (!seen.has(dir)) {
|
|
3995
|
+
const { name, version } = readPackageInfo(executor, path.join(cwd, "packages", dir, "package.json"));
|
|
3996
|
+
packages.push({
|
|
3997
|
+
dir,
|
|
3998
|
+
imageName: `${repoName}-${name ?? dir}`,
|
|
3999
|
+
version,
|
|
4000
|
+
docker
|
|
4001
|
+
});
|
|
4002
|
+
}
|
|
4003
|
+
} else {
|
|
4004
|
+
const convention = findRootDockerfile(executor, cwd);
|
|
4005
|
+
const docker = overrides["."] ?? convention;
|
|
4006
|
+
if (docker) {
|
|
4007
|
+
const { name, version } = readPackageInfo(executor, path.join(cwd, "package.json"));
|
|
4008
|
+
packages.push({
|
|
4009
|
+
dir: ".",
|
|
4010
|
+
imageName: name ?? repoName,
|
|
4011
|
+
version,
|
|
4012
|
+
docker
|
|
4013
|
+
});
|
|
4014
|
+
}
|
|
4006
4015
|
}
|
|
4007
4016
|
return packages;
|
|
4008
4017
|
}
|
|
4009
4018
|
/**
|
|
4010
|
-
* Read docker config for a single package
|
|
4011
|
-
* Used by the per-package image:build script.
|
|
4019
|
+
* Read docker config for a single package, checking convention paths first,
|
|
4020
|
+
* then .tooling.json overrides. Used by the per-package image:build script.
|
|
4012
4021
|
*/
|
|
4013
4022
|
function readSinglePackageDocker(executor, cwd, packageDir, repoName) {
|
|
4014
4023
|
const dir = path.basename(path.resolve(cwd, packageDir));
|
|
4015
|
-
const
|
|
4016
|
-
|
|
4024
|
+
const convention = findConventionDockerfile(executor, cwd, dir);
|
|
4025
|
+
const docker = loadDockerMap(executor, cwd)[dir] ?? convention;
|
|
4026
|
+
if (!docker) throw new FatalError(`No Dockerfile found for package "${dir}" (checked convention paths and .tooling.json)`);
|
|
4017
4027
|
const { name, version } = readPackageInfo(executor, path.join(cwd, "packages", dir, "package.json"));
|
|
4018
4028
|
return {
|
|
4019
4029
|
dir,
|
|
@@ -4235,13 +4245,11 @@ const dockerBuildCommand = defineCommand({
|
|
|
4235
4245
|
const main = defineCommand({
|
|
4236
4246
|
meta: {
|
|
4237
4247
|
name: "tooling",
|
|
4238
|
-
version: "0.
|
|
4248
|
+
version: "0.16.0",
|
|
4239
4249
|
description: "Bootstrap and maintain standardized TypeScript project tooling"
|
|
4240
4250
|
},
|
|
4241
4251
|
subCommands: {
|
|
4242
|
-
"repo:
|
|
4243
|
-
"repo:update": updateCommand,
|
|
4244
|
-
"repo:check": checkCommand,
|
|
4252
|
+
"repo:sync": syncCommand,
|
|
4245
4253
|
"checks:run": runChecksCommand,
|
|
4246
4254
|
"release:changesets": releaseForgejoCommand,
|
|
4247
4255
|
"release:trigger": releaseTriggerCommand,
|
|
@@ -4252,7 +4260,7 @@ const main = defineCommand({
|
|
|
4252
4260
|
"docker:build": dockerBuildCommand
|
|
4253
4261
|
}
|
|
4254
4262
|
});
|
|
4255
|
-
console.log(`@bensandee/tooling v0.
|
|
4263
|
+
console.log(`@bensandee/tooling v0.16.0`);
|
|
4256
4264
|
runMain(main);
|
|
4257
4265
|
//#endregion
|
|
4258
4266
|
export {};
|