@domain-first/project-structure 7.2.0 → 8.0.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 (64) hide show
  1. package/README.md +124 -25
  2. package/dist/201.js +87 -338
  3. package/dist/287.js +1183 -568
  4. package/dist/561.js +518 -0
  5. package/dist/711.js +22 -0
  6. package/dist/870.js +438 -0
  7. package/dist/agent-cli.d.ts +378 -0
  8. package/dist/agent-cli.spec.d.ts +1 -0
  9. package/dist/agent-identifiers.d.ts +4 -0
  10. package/dist/agent-requests.d.ts +488 -0
  11. package/dist/config-file.d.ts +231 -26
  12. package/dist/config-file.spec.d.ts +1 -0
  13. package/dist/context-dependencies.d.ts +16 -0
  14. package/dist/dependency-rules.d.ts +17 -17
  15. package/dist/file-system.d.ts +10 -1
  16. package/dist/implementation-choices.d.ts +8 -0
  17. package/dist/implementation-choices.spec.d.ts +1 -0
  18. package/dist/implementation-options-schema.d.ts +14 -0
  19. package/dist/index.cjs +3598 -583
  20. package/dist/index.js +20 -7
  21. package/dist/init.cjs +717 -122
  22. package/dist/init.js +24 -12
  23. package/dist/integration.cjs +3737 -186
  24. package/dist/integration.js +29 -17
  25. package/dist/integrations/rest-endpoint-generator.d.ts +4 -2
  26. package/dist/integrations/storybook.d.ts +1 -0
  27. package/dist/interaction.d.ts +41 -0
  28. package/dist/lint.cjs +165 -41
  29. package/dist/lint.js +22 -7
  30. package/dist/next-app.d.ts +7 -0
  31. package/dist/react.cjs +5128 -414
  32. package/dist/react.js +72 -60
  33. package/dist/system-implementations.d.ts +6 -0
  34. package/dist/upgrade-steps.d.ts +81 -0
  35. package/dist/upgrade-steps.spec.d.ts +1 -0
  36. package/dist/upgrade.cjs +593 -0
  37. package/dist/upgrade.d.ts +2 -0
  38. package/dist/upgrade.js +235 -0
  39. package/dist/use-cases/add-integration.d.ts +16 -1
  40. package/dist/use-cases/cross-context-dependencies.spec.d.ts +1 -0
  41. package/dist/use-cases/initialize.d.ts +4 -4
  42. package/dist/use-cases/initialize.spec.d.ts +1 -0
  43. package/dist/use-cases/prompt-implementation-type.d.ts +20 -0
  44. package/dist/use-cases/scaffold-react-page.d.ts +3 -1
  45. package/dist/wire-branches.d.ts +26 -0
  46. package/dist/wiring.d.ts +3 -2
  47. package/package.json +3 -2
  48. package/skills/df-ps-implement/SKILL.md +9 -8
  49. package/skills/df-ps-plan-feature/SKILL.md +8 -7
  50. package/skills/df-ps-react/SKILL.md +13 -7
  51. package/skills/df-ps-react/references/generators.md +6 -2
  52. package/skills/df-ps-scaffold/SKILL.md +28 -17
  53. package/skills/df-ps-scaffold/references/agent-mode.md +72 -0
  54. package/skills/df-ps-scaffold/references/agent-operations.md +155 -0
  55. package/skills/df-ps-scaffold/references/choosing-components.md +13 -13
  56. package/skills/df-ps-scaffold/references/generators.md +20 -3
  57. package/skills/df-ps-scaffold/references/units/aggregate.md +4 -3
  58. package/skills/df-ps-scaffold/references/units/bounded-context.md +1 -1
  59. package/skills/df-ps-scaffold/references/units/command-query.md +12 -12
  60. package/skills/df-ps-scaffold/references/units/implementation.md +2 -2
  61. package/skills/df-ps-scaffold/references/units/move-or-rename.md +1 -1
  62. package/skills/df-ps-scaffold/references/units/port.md +7 -4
  63. package/skills/df-ps-scaffold/references/units/use-case.md +1 -1
  64. package/skills/df-ps-scaffold/scripts/drive.mjs +9 -1
@@ -0,0 +1,593 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __webpack_require__ = {};
4
+ (()=>{
5
+ __webpack_require__.n = (module)=>{
6
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
7
+ __webpack_require__.d(getter, {
8
+ a: getter
9
+ });
10
+ return getter;
11
+ };
12
+ })();
13
+ (()=>{
14
+ __webpack_require__.d = (exports1, getters, values)=>{
15
+ var define = (defs, kind)=>{
16
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
17
+ enumerable: true,
18
+ [kind]: defs[key]
19
+ });
20
+ };
21
+ define(getters, "get");
22
+ define(values, "value");
23
+ };
24
+ })();
25
+ (()=>{
26
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ const external_node_path_namespaceObject = require("node:path");
30
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
31
+ const external_node_util_namespaceObject = require("node:util");
32
+ const prompts_namespaceObject = require("@inquirer/prompts");
33
+ const external_zod_namespaceObject = require("zod");
34
+ var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
35
+ const moduleKinds = [
36
+ 'repositories',
37
+ 'domain-services',
38
+ 'application-ports',
39
+ 'application-services',
40
+ 'use-cases',
41
+ 'commands',
42
+ 'queries',
43
+ 'infrastructure-services',
44
+ 'presentation-services'
45
+ ];
46
+ const domain = [
47
+ 'repositories',
48
+ 'domain-services'
49
+ ];
50
+ const commandsAndQueries = [
51
+ 'commands',
52
+ 'queries'
53
+ ];
54
+ const infrastructure = [
55
+ ...domain,
56
+ 'application-ports',
57
+ 'infrastructure-services'
58
+ ];
59
+ const dependency_rules_defaultDependencies = {
60
+ 'domain-services': [
61
+ 'domain-services'
62
+ ],
63
+ repositories: [
64
+ 'domain-services',
65
+ 'application-ports',
66
+ 'infrastructure-services'
67
+ ],
68
+ 'application-ports': infrastructure,
69
+ 'application-services': [
70
+ ...domain,
71
+ 'application-ports',
72
+ ...commandsAndQueries
73
+ ],
74
+ 'use-cases': [
75
+ ...domain,
76
+ 'application-ports',
77
+ 'application-services',
78
+ ...commandsAndQueries
79
+ ],
80
+ commands: [
81
+ 'infrastructure-services'
82
+ ],
83
+ queries: [
84
+ 'infrastructure-services'
85
+ ],
86
+ 'infrastructure-services': infrastructure,
87
+ 'presentation-services': [
88
+ 'application-ports',
89
+ 'application-services',
90
+ 'use-cases',
91
+ ...commandsAndQueries,
92
+ 'presentation-services'
93
+ ]
94
+ };
95
+ const kindSchema = external_zod_default()["enum"](moduleKinds);
96
+ const dependencyRulesSchema = external_zod_default().partialRecord(kindSchema, external_zod_default().union([
97
+ external_zod_default().array(kindSchema),
98
+ external_zod_default().object({
99
+ add: external_zod_default().array(kindSchema).optional(),
100
+ remove: external_zod_default().array(kindSchema).optional()
101
+ })
102
+ ]));
103
+ const dependency_rules_resolveDependencyRules = (config = {})=>{
104
+ const entries = moduleKinds.map((kind)=>{
105
+ const override = config[kind];
106
+ if (Array.isArray(override)) return [
107
+ kind,
108
+ new Set(override)
109
+ ];
110
+ const kinds = new Set([
111
+ ...dependency_rules_defaultDependencies[kind],
112
+ ...override?.add ?? []
113
+ ]);
114
+ for (const removed of override?.remove ?? [])kinds.delete(removed);
115
+ return [
116
+ kind,
117
+ kinds
118
+ ];
119
+ });
120
+ return Object.fromEntries(entries);
121
+ };
122
+ dependency_rules_resolveDependencyRules();
123
+ const external_node_fs_namespaceObject = require("node:fs");
124
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
125
+ const pendingFiles = new Map();
126
+ const pendingFolders = new Set();
127
+ const pendingMoves = new Map();
128
+ const pendingDeletions = new Map();
129
+ const discardPendingChanges = ()=>{
130
+ pendingFolders.clear();
131
+ pendingFiles.clear();
132
+ pendingMoves.clear();
133
+ pendingDeletions.clear();
134
+ };
135
+ const removeEmptyFolders = (folderPath, stopAt)=>{
136
+ let current = folderPath;
137
+ while(current.startsWith(`${stopAt}${external_node_path_default().sep}`) && external_node_fs_default().existsSync(current) && !external_node_fs_default().readdirSync(current).length){
138
+ external_node_fs_default().rmdirSync(current);
139
+ current = external_node_path_default().dirname(current);
140
+ }
141
+ };
142
+ const writePendingChanges = ()=>{
143
+ for (const folderPath of pendingFolders)external_node_fs_default().mkdirSync(folderPath, {
144
+ recursive: true
145
+ });
146
+ for (const [filePath, { content }] of pendingFiles){
147
+ external_node_fs_default().mkdirSync(external_node_path_default().dirname(filePath), {
148
+ recursive: true
149
+ });
150
+ external_node_fs_default().writeFileSync(filePath, content, 'utf8');
151
+ }
152
+ for (const [targetPath, { sourcePath }] of pendingMoves){
153
+ external_node_fs_default().mkdirSync(external_node_path_default().dirname(targetPath), {
154
+ recursive: true
155
+ });
156
+ external_node_fs_default().renameSync(sourcePath, targetPath);
157
+ }
158
+ for (const filePath of pendingDeletions.keys())external_node_fs_default().rmSync(filePath, {
159
+ force: true
160
+ });
161
+ for (const [filePath, stopAt] of pendingDeletions)removeEmptyFolders(external_node_path_default().dirname(filePath), stopAt);
162
+ for (const { sourcePath, stopAt } of pendingMoves.values())removeEmptyFolders(external_node_path_default().dirname(sourcePath), stopAt);
163
+ discardPendingChanges();
164
+ };
165
+ class FileSystemItem {
166
+ path;
167
+ constructor(path){
168
+ this.path = path;
169
+ }
170
+ subitem = (relativePath)=>new this.constructor(external_node_path_default().resolve(this.path, ...relativePath));
171
+ get exists() {
172
+ return external_node_fs_default().existsSync(this.path);
173
+ }
174
+ }
175
+ class File extends FileSystemItem {
176
+ get exists() {
177
+ return pendingFiles.has(this.path) || pendingMoves.has(this.path) || external_node_fs_default().existsSync(this.path) && !pendingDeletions.has(this.path);
178
+ }
179
+ delete = (stopAt)=>{
180
+ pendingDeletions.set(this.path, stopAt);
181
+ };
182
+ moveTo = (targetPath, stopAt)=>{
183
+ pendingMoves.set(targetPath, {
184
+ sourcePath: this.path,
185
+ stopAt
186
+ });
187
+ };
188
+ get data() {
189
+ const pendingFile = pendingFiles.get(this.path);
190
+ if (pendingFile) return pendingFile.content;
191
+ if (!this.exists) throw new Error('File does not exist');
192
+ return external_node_fs_default().readFileSync(this.path, 'utf-8');
193
+ }
194
+ set data(content) {
195
+ pendingFiles.set(this.path, {
196
+ content,
197
+ replacesFile: true
198
+ });
199
+ }
200
+ update = (content)=>{
201
+ pendingFiles.set(this.path, {
202
+ content,
203
+ replacesFile: pendingFiles.get(this.path)?.replacesFile ?? false
204
+ });
205
+ };
206
+ addLine = (newLine, separator = '\n')=>{
207
+ const content = this.exists ? this.data : '';
208
+ pendingFiles.set(this.path, {
209
+ content: [
210
+ content.trim(),
211
+ newLine.trim()
212
+ ].filter((x)=>!!x).join(separator),
213
+ replacesFile: pendingFiles.get(this.path)?.replacesFile ?? false
214
+ });
215
+ };
216
+ addLineIfMissing = (newLine, separator = '\n')=>{
217
+ const alreadyAdded = this.exists && this.data.split('\n').some((line)=>line.trim() === newLine.trim());
218
+ if (!alreadyAdded) this.addLine(newLine, separator);
219
+ };
220
+ }
221
+ const implementationKinds = [
222
+ 'repositories',
223
+ 'commands',
224
+ 'queries',
225
+ 'ports'
226
+ ];
227
+ const implementationLabelSchema = external_zod_default().string().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/);
228
+ const implementationOptionsSchema = external_zod_default().partialRecord(external_zod_default()["enum"](implementationKinds), external_zod_default().object({
229
+ primary: external_zod_default().array(implementationLabelSchema).default([]),
230
+ test: external_zod_default().array(implementationLabelSchema).default([])
231
+ }).strict());
232
+ class ProjectRoot {
233
+ path;
234
+ constructor(){
235
+ let dir = process.cwd();
236
+ while(dir !== external_node_path_default().parse(dir).root){
237
+ if (external_node_fs_default().existsSync(external_node_path_default().join(dir, 'package.json'))) {
238
+ this.path = dir;
239
+ return;
240
+ }
241
+ dir = external_node_path_default().dirname(dir);
242
+ }
243
+ throw new Error('No package.json was found');
244
+ }
245
+ }
246
+ const lintChecks = [
247
+ 'context-isolation',
248
+ 'shared-kernel',
249
+ 'layers',
250
+ 'dependencies',
251
+ 'react',
252
+ 'clock'
253
+ ];
254
+ const configFileName = 'domain-first.project-structure.config.json';
255
+ const projectConfigSchema = external_zod_default().object({
256
+ rootFolder: external_zod_default().string().min(1)
257
+ }).passthrough();
258
+ const config_file_domainFirstPackages = [
259
+ '@domain-first/types',
260
+ '@domain-first/errors',
261
+ '@domain-first/handlers',
262
+ '@domain-first/wire',
263
+ '@domain-first/handlers-rest'
264
+ ];
265
+ const rulesSchema = external_zod_default().object({
266
+ dependencies: dependencyRulesSchema.optional(),
267
+ lint: external_zod_default().partialRecord(external_zod_default()["enum"](lintChecks), external_zod_default().boolean()).optional()
268
+ });
269
+ const branchNameSchema = external_zod_default().string().regex(/^[a-z][a-z0-9]*$/, 'Use lowercase letters and digits, e.g. staging.');
270
+ const envBranchesSchema = external_zod_default().object({
271
+ names: external_zod_default().array(branchNameSchema).min(1),
272
+ test: branchNameSchema.optional()
273
+ }).refine(({ names })=>new Set(names).size === names.length, {
274
+ message: 'Branch names must be unique.'
275
+ }).refine(({ names, test })=>void 0 === test || names.includes(test), {
276
+ message: 'The test branch must be one of the branches.'
277
+ }).refine(({ names, test })=>void 0 === test || names.length > 1, {
278
+ message: 'The primary implementation needs a branch besides the test one.'
279
+ });
280
+ const backendConfigSchema = external_zod_default().object({
281
+ domainFirstPackages: external_zod_default().array(external_zod_default()["enum"](config_file_domainFirstPackages)),
282
+ envBranches: envBranchesSchema.optional(),
283
+ withInMemoryDb: external_zod_default().boolean().optional(),
284
+ testingLibrary: external_zod_default().string().optional(),
285
+ implementations: implementationOptionsSchema.optional(),
286
+ rules: rulesSchema.optional()
287
+ }).passthrough();
288
+ const reactConfigSchema = external_zod_default().object({
289
+ framework: external_zod_default()["enum"]([
290
+ 'react',
291
+ 'next'
292
+ ]).optional(),
293
+ storybookFramework: external_zod_default().string().optional()
294
+ }).passthrough();
295
+ const frontendConfigSchema = external_zod_default().object({
296
+ react: reactConfigSchema.optional()
297
+ }).passthrough();
298
+ const configSchema = external_zod_default().object({
299
+ project: projectConfigSchema,
300
+ backend: backendConfigSchema.optional(),
301
+ frontend: frontendConfigSchema.optional()
302
+ }).passthrough();
303
+ const isOutdatedConfig = (value)=>'object' == typeof value && null !== value && !Array.isArray(value) && !('project' in value);
304
+ const outdatedConfigMessage = `${configFileName} uses the format of an earlier major version: run npx df-upgrade.`;
305
+ class ConfigOutdatedError extends Error {
306
+ constructor(){
307
+ super(outdatedConfigMessage);
308
+ }
309
+ }
310
+ class config_file_ConfigFile {
311
+ data;
312
+ constructor(){
313
+ const raw = JSON.parse(new File(config_file_ConfigFile.path).data);
314
+ if (isOutdatedConfig(raw)) throw new ConfigOutdatedError();
315
+ this.data = configSchema.parse(raw);
316
+ }
317
+ static get Instance() {
318
+ return new config_file_ConfigFile();
319
+ }
320
+ static get backend() {
321
+ const backend = config_file_ConfigFile.Instance.data.backend;
322
+ if (!backend) throw new Error('Backend is not configured: run df-init --section backend.');
323
+ return backend;
324
+ }
325
+ static get path() {
326
+ return external_node_path_default().resolve(new ProjectRoot().path, configFileName);
327
+ }
328
+ static get exists() {
329
+ return new File(config_file_ConfigFile.path).exists;
330
+ }
331
+ static get outdated() {
332
+ if (!config_file_ConfigFile.exists) return false;
333
+ try {
334
+ return isOutdatedConfig(JSON.parse(new File(config_file_ConfigFile.path).data));
335
+ } catch {
336
+ return false;
337
+ }
338
+ }
339
+ static write = (config)=>{
340
+ config_file_ConfigFile.stage(configSchema.parse(config));
341
+ };
342
+ static update = (sections)=>{
343
+ config_file_ConfigFile.stage(configSchema.parse({
344
+ ...config_file_ConfigFile.Instance.data,
345
+ ...sections
346
+ }));
347
+ };
348
+ static stage(config) {
349
+ new File(config_file_ConfigFile.path).update(`${JSON.stringify(config, null, 4)}\n`);
350
+ }
351
+ }
352
+ const hasDependency = (name)=>{
353
+ const manifestFile = new File(external_node_path_default().join(new ProjectRoot().path, 'package.json'));
354
+ if (!manifestFile.exists) return false;
355
+ const manifest = JSON.parse(manifestFile.data);
356
+ return [
357
+ manifest.dependencies,
358
+ manifest.devDependencies,
359
+ manifest.optionalDependencies
360
+ ].some((dependencies)=>dependencies && Object.hasOwn(dependencies, name));
361
+ };
362
+ const record = (value)=>'object' != typeof value || null === value || Array.isArray(value) ? {} : value;
363
+ const flatConfigSchema = external_zod_default().object({
364
+ rootFolder: external_zod_default().string().min(1),
365
+ domainFirstPackages: external_zod_default().array(external_zod_default()["enum"](config_file_domainFirstPackages)),
366
+ withInMemoryDb: external_zod_default().boolean().optional(),
367
+ testingLibrary: external_zod_default().string().optional(),
368
+ useReact: external_zod_default().boolean().optional(),
369
+ storybookFramework: external_zod_default().string().optional(),
370
+ defaultPersistenceLayerImplementation: external_zod_default().string().optional(),
371
+ rules: rulesSchema.optional()
372
+ }).passthrough();
373
+ const sectionsStep = {
374
+ id: 'config-sections',
375
+ kind: 'required',
376
+ title: 'Split the config into project, backend and frontend sections',
377
+ detect: ({ config })=>isOutdatedConfig(config),
378
+ plan: ({ config })=>{
379
+ const flat = flatConfigSchema.parse(config);
380
+ const backend = [
381
+ 'domainFirstPackages',
382
+ 'withInMemoryDb',
383
+ 'testingLibrary',
384
+ 'rules'
385
+ ].filter((key)=>key in flat);
386
+ return [
387
+ 'rootFolder → project.rootFolder',
388
+ `${backend.join(', ')} → backend`,
389
+ flat.useReact ? `useReact${flat.storybookFramework ? ', storybookFramework' : ''} → frontend.react` : 'useReact: false → no frontend section'
390
+ ];
391
+ },
392
+ apply: (context)=>{
393
+ const { rootFolder, domainFirstPackages, withInMemoryDb, testingLibrary, useReact, storybookFramework, defaultPersistenceLayerImplementation, rules, ...other } = flatConfigSchema.parse(context.config);
394
+ context.config = {
395
+ ...other,
396
+ project: {
397
+ rootFolder
398
+ },
399
+ backend: {
400
+ domainFirstPackages,
401
+ withInMemoryDb,
402
+ testingLibrary,
403
+ rules,
404
+ defaultPersistenceLayerImplementation
405
+ },
406
+ ...useReact ? {
407
+ frontend: {
408
+ react: {
409
+ storybookFramework
410
+ }
411
+ }
412
+ } : {}
413
+ };
414
+ }
415
+ };
416
+ const reactOf = (config)=>record(record(config.frontend).react);
417
+ const frameworkStep = {
418
+ id: 'react-framework',
419
+ kind: 'required',
420
+ title: 'Record the frontend framework explicitly',
421
+ detect: ({ config })=>'react' in record(config.frontend) && !reactOf(config).framework,
422
+ plan: ()=>[
423
+ hasDependency('next') ? 'frontend.react.framework: "next" (next is in package.json)' : 'frontend.react.framework: "react" (next is not in package.json)'
424
+ ],
425
+ apply: ({ config })=>{
426
+ const frontend = record(config.frontend);
427
+ config.frontend = {
428
+ ...frontend,
429
+ react: {
430
+ ...reactOf(config),
431
+ framework: hasDependency('next') ? 'next' : 'react'
432
+ }
433
+ };
434
+ }
435
+ };
436
+ const persistenceKinds = [
437
+ 'repositories',
438
+ 'commands',
439
+ 'queries'
440
+ ];
441
+ const persistenceStep = {
442
+ id: 'persistence-default',
443
+ kind: 'required',
444
+ title: 'Move the default persistence implementation to saved implementation types',
445
+ detect: ({ config })=>'defaultPersistenceLayerImplementation' in record(config.backend),
446
+ plan: ({ config })=>{
447
+ const label = record(config.backend).defaultPersistenceLayerImplementation;
448
+ if (void 0 === label) return [];
449
+ return implementationLabelSchema.safeParse(label).success ? [
450
+ `defaultPersistenceLayerImplementation "${label}" → first primary type of backend.implementations.${persistenceKinds.join(', ')}`
451
+ ] : [
452
+ `defaultPersistenceLayerImplementation "${String(label)}" is removed: it is not a kebab-case implementation type`
453
+ ];
454
+ },
455
+ apply: ({ config })=>{
456
+ const { defaultPersistenceLayerImplementation: label, ...backend } = record(config.backend);
457
+ const implementations = record(backend.implementations);
458
+ if (implementationLabelSchema.safeParse(label).success) {
459
+ for (const kind of persistenceKinds){
460
+ const group = record(implementations[kind]);
461
+ const primary = Array.isArray(group.primary) ? group.primary : [];
462
+ implementations[kind] = {
463
+ primary: [
464
+ label,
465
+ ...primary.filter((x)=>x !== label)
466
+ ],
467
+ test: Array.isArray(group.test) ? group.test : []
468
+ };
469
+ }
470
+ backend.implementations = implementations;
471
+ }
472
+ config.backend = backend;
473
+ }
474
+ };
475
+ const upgradeSteps = [
476
+ sectionsStep,
477
+ frameworkStep,
478
+ persistenceStep
479
+ ];
480
+ const skillsNote = 'Update the agent skills to this version: npx df-skills';
481
+ const planUpgrade = async (config, acceptOptional = ()=>true, steps = upgradeSteps)=>{
482
+ const context = {
483
+ config: structuredClone(record(config))
484
+ };
485
+ const planned = [];
486
+ for (const step of steps){
487
+ if (!step.detect(context)) continue;
488
+ const entry = {
489
+ step,
490
+ changes: step.plan(context)
491
+ };
492
+ if ('optional' !== step.kind || await acceptOptional(entry)) {
493
+ planned.push(entry);
494
+ step.apply?.(context);
495
+ }
496
+ }
497
+ const changed = planned.some(({ step })=>'manual' !== step.kind);
498
+ return {
499
+ planned,
500
+ changed,
501
+ config: changed ? configSchema.parse(context.config) : void 0
502
+ };
503
+ };
504
+ const help = `Usage: df-upgrade [--dry-run] [--yes]
505
+
506
+ Brings the project up to date after upgrading @domain-first/project-structure
507
+ to a new major version. Finds the steps the project needs, shows what each
508
+ one changes, asks once and applies them together. Other commands refuse a
509
+ config of an earlier major version until it is upgraded.
510
+
511
+ Options:
512
+ --dry-run show the plan without writing anything
513
+ --yes apply without asking, optional steps included
514
+ -h, --help show this help`;
515
+ const { values } = (0, external_node_util_namespaceObject.parseArgs)({
516
+ options: {
517
+ help: {
518
+ type: 'boolean',
519
+ short: 'h',
520
+ default: false
521
+ },
522
+ 'dry-run': {
523
+ type: 'boolean',
524
+ default: false
525
+ },
526
+ yes: {
527
+ type: 'boolean',
528
+ short: 'y',
529
+ default: false
530
+ }
531
+ }
532
+ });
533
+ if (values.help) {
534
+ console.log(help);
535
+ process.exit(0);
536
+ }
537
+ const printStep = ({ step, changes })=>{
538
+ console.log(`\n${step.title}${'optional' === step.kind ? ' (optional)' : ''}`);
539
+ for (const change of changes)console.log(` ${change}`);
540
+ };
541
+ const run = async ()=>{
542
+ const root = new ProjectRoot().path;
543
+ const configPath = external_node_path_default().join(root, configFileName);
544
+ if (!config_file_ConfigFile.exists) {
545
+ console.log(`No ${configFileName} found: run df-init to initialize the project.`);
546
+ process.exit(1);
547
+ }
548
+ let raw;
549
+ try {
550
+ raw = JSON.parse(new File(configPath).data);
551
+ } catch {
552
+ console.log(`${configFileName} is not valid JSON: fix it first.`);
553
+ process.exit(1);
554
+ }
555
+ const dryRun = values['dry-run'];
556
+ const { planned, changed, config } = await planUpgrade(raw, (entry)=>{
557
+ if (dryRun || values.yes) return true;
558
+ printStep(entry);
559
+ return (0, prompts_namespaceObject.confirm)({
560
+ message: 'Apply this optional step?',
561
+ default: true
562
+ });
563
+ });
564
+ if (!changed) return void console.log('Everything is up to date.');
565
+ console.log('Upgrade plan:');
566
+ for (const entry of planned.filter(({ step })=>'manual' !== step.kind))printStep(entry);
567
+ const manual = [
568
+ ...planned.filter(({ step })=>'manual' === step.kind).flatMap(({ changes })=>changes),
569
+ skillsNote
570
+ ];
571
+ if (dryRun) return void console.log('\nDry run: nothing was written.');
572
+ if (!values.yes && !await (0, prompts_namespaceObject.confirm)({
573
+ message: 'Apply?',
574
+ default: true
575
+ })) {
576
+ discardPendingChanges();
577
+ console.log('Cancelled: nothing was written.');
578
+ return;
579
+ }
580
+ if (config) config_file_ConfigFile.write(config);
581
+ writePendingChanges();
582
+ console.log(`\nUpgraded ${configFileName}.`);
583
+ console.log('\nDo it yourself:');
584
+ for (const note of manual)console.log(` ${note}`);
585
+ };
586
+ run().catch((error)=>{
587
+ console.error(error instanceof Error ? error.message : error);
588
+ process.exitCode = 1;
589
+ });
590
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
591
+ Object.defineProperty(exports, '__esModule', {
592
+ value: true
593
+ });
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};