@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.
- package/README.md +124 -25
- package/dist/201.js +87 -338
- package/dist/287.js +1183 -568
- package/dist/561.js +518 -0
- package/dist/711.js +22 -0
- package/dist/870.js +438 -0
- package/dist/agent-cli.d.ts +378 -0
- package/dist/agent-cli.spec.d.ts +1 -0
- package/dist/agent-identifiers.d.ts +4 -0
- package/dist/agent-requests.d.ts +488 -0
- package/dist/config-file.d.ts +231 -26
- package/dist/config-file.spec.d.ts +1 -0
- package/dist/context-dependencies.d.ts +16 -0
- package/dist/dependency-rules.d.ts +17 -17
- package/dist/file-system.d.ts +10 -1
- package/dist/implementation-choices.d.ts +8 -0
- package/dist/implementation-choices.spec.d.ts +1 -0
- package/dist/implementation-options-schema.d.ts +14 -0
- package/dist/index.cjs +3598 -583
- package/dist/index.js +20 -7
- package/dist/init.cjs +717 -122
- package/dist/init.js +24 -12
- package/dist/integration.cjs +3737 -186
- package/dist/integration.js +29 -17
- package/dist/integrations/rest-endpoint-generator.d.ts +4 -2
- package/dist/integrations/storybook.d.ts +1 -0
- package/dist/interaction.d.ts +41 -0
- package/dist/lint.cjs +165 -41
- package/dist/lint.js +22 -7
- package/dist/next-app.d.ts +7 -0
- package/dist/react.cjs +5128 -414
- package/dist/react.js +72 -60
- package/dist/system-implementations.d.ts +6 -0
- package/dist/upgrade-steps.d.ts +81 -0
- package/dist/upgrade-steps.spec.d.ts +1 -0
- package/dist/upgrade.cjs +593 -0
- package/dist/upgrade.d.ts +2 -0
- package/dist/upgrade.js +235 -0
- package/dist/use-cases/add-integration.d.ts +16 -1
- package/dist/use-cases/cross-context-dependencies.spec.d.ts +1 -0
- package/dist/use-cases/initialize.d.ts +4 -4
- package/dist/use-cases/initialize.spec.d.ts +1 -0
- package/dist/use-cases/prompt-implementation-type.d.ts +20 -0
- package/dist/use-cases/scaffold-react-page.d.ts +3 -1
- package/dist/wire-branches.d.ts +26 -0
- package/dist/wiring.d.ts +3 -2
- package/package.json +3 -2
- package/skills/df-ps-implement/SKILL.md +9 -8
- package/skills/df-ps-plan-feature/SKILL.md +8 -7
- package/skills/df-ps-react/SKILL.md +13 -7
- package/skills/df-ps-react/references/generators.md +6 -2
- package/skills/df-ps-scaffold/SKILL.md +28 -17
- package/skills/df-ps-scaffold/references/agent-mode.md +72 -0
- package/skills/df-ps-scaffold/references/agent-operations.md +155 -0
- package/skills/df-ps-scaffold/references/choosing-components.md +13 -13
- package/skills/df-ps-scaffold/references/generators.md +20 -3
- package/skills/df-ps-scaffold/references/units/aggregate.md +4 -3
- package/skills/df-ps-scaffold/references/units/bounded-context.md +1 -1
- package/skills/df-ps-scaffold/references/units/command-query.md +12 -12
- package/skills/df-ps-scaffold/references/units/implementation.md +2 -2
- package/skills/df-ps-scaffold/references/units/move-or-rename.md +1 -1
- package/skills/df-ps-scaffold/references/units/port.md +7 -4
- package/skills/df-ps-scaffold/references/units/use-case.md +1 -1
- package/skills/df-ps-scaffold/scripts/drive.mjs +9 -1
package/dist/init.cjs
CHANGED
|
@@ -125,9 +125,9 @@ const pendingFiles = new Map();
|
|
|
125
125
|
const pendingFolders = new Set();
|
|
126
126
|
const pendingMoves = new Map();
|
|
127
127
|
const pendingDeletions = new Map();
|
|
128
|
-
const filesToOverwrite = ()=>[
|
|
128
|
+
const filesToOverwrite = ({ changedOnly = false } = {})=>[
|
|
129
129
|
...pendingFiles
|
|
130
|
-
].filter(([filePath, { replacesFile }])=>replacesFile && external_node_fs_default().existsSync(filePath)).map(([filePath])=>filePath);
|
|
130
|
+
].filter(([filePath, { replacesFile, content }])=>replacesFile && external_node_fs_default().existsSync(filePath) && (!changedOnly || external_node_fs_default().readFileSync(filePath, 'utf8') !== content)).map(([filePath])=>filePath);
|
|
131
131
|
const file_system_withoutOverwrites = (generate)=>{
|
|
132
132
|
const before = new Map(pendingFiles);
|
|
133
133
|
const result = generate();
|
|
@@ -267,6 +267,17 @@ class file_system_File extends FileSystemItem {
|
|
|
267
267
|
if (!alreadyAdded) this.addLine(newLine, separator);
|
|
268
268
|
};
|
|
269
269
|
}
|
|
270
|
+
const implementationKinds = [
|
|
271
|
+
'repositories',
|
|
272
|
+
'commands',
|
|
273
|
+
'queries',
|
|
274
|
+
'ports'
|
|
275
|
+
];
|
|
276
|
+
const implementation_options_schema_implementationLabelSchema = external_zod_default().string().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/);
|
|
277
|
+
const implementationOptionsSchema = external_zod_default().partialRecord(external_zod_default()["enum"](implementationKinds), external_zod_default().object({
|
|
278
|
+
primary: external_zod_default().array(implementation_options_schema_implementationLabelSchema).default([]),
|
|
279
|
+
test: external_zod_default().array(implementation_options_schema_implementationLabelSchema).default([])
|
|
280
|
+
}).strict());
|
|
270
281
|
class project_root_ProjectRoot {
|
|
271
282
|
path;
|
|
272
283
|
constructor(){
|
|
@@ -289,47 +300,121 @@ const lintChecks = [
|
|
|
289
300
|
'react',
|
|
290
301
|
'clock'
|
|
291
302
|
];
|
|
292
|
-
const
|
|
293
|
-
const
|
|
294
|
-
rootFolder: external_zod_default().string()
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
+
const config_file_configFileName = 'domain-first.project-structure.config.json';
|
|
304
|
+
const projectConfigSchema = external_zod_default().object({
|
|
305
|
+
rootFolder: external_zod_default().string().min(1)
|
|
306
|
+
}).passthrough();
|
|
307
|
+
const config_file_domainFirstPackages = [
|
|
308
|
+
'@domain-first/types',
|
|
309
|
+
'@domain-first/errors',
|
|
310
|
+
'@domain-first/handlers',
|
|
311
|
+
'@domain-first/wire',
|
|
312
|
+
'@domain-first/handlers-rest'
|
|
313
|
+
];
|
|
314
|
+
const rulesSchema = external_zod_default().object({
|
|
315
|
+
dependencies: dependencyRulesSchema.optional(),
|
|
316
|
+
lint: external_zod_default().partialRecord(external_zod_default()["enum"](lintChecks), external_zod_default().boolean()).optional()
|
|
317
|
+
});
|
|
318
|
+
const branchNameSchema = external_zod_default().string().regex(/^[a-z][a-z0-9]*$/, 'Use lowercase letters and digits, e.g. staging.');
|
|
319
|
+
const envBranchesSchema = external_zod_default().object({
|
|
320
|
+
names: external_zod_default().array(branchNameSchema).min(1),
|
|
321
|
+
test: branchNameSchema.optional()
|
|
322
|
+
}).refine(({ names })=>new Set(names).size === names.length, {
|
|
323
|
+
message: 'Branch names must be unique.'
|
|
324
|
+
}).refine(({ names, test })=>void 0 === test || names.includes(test), {
|
|
325
|
+
message: 'The test branch must be one of the branches.'
|
|
326
|
+
}).refine(({ names, test })=>void 0 === test || names.length > 1, {
|
|
327
|
+
message: 'The primary implementation needs a branch besides the test one.'
|
|
328
|
+
});
|
|
329
|
+
const backendConfigSchema = external_zod_default().object({
|
|
330
|
+
domainFirstPackages: external_zod_default().array(external_zod_default()["enum"](config_file_domainFirstPackages)),
|
|
331
|
+
envBranches: envBranchesSchema.optional(),
|
|
303
332
|
withInMemoryDb: external_zod_default().boolean().optional(),
|
|
304
|
-
useReact: external_zod_default().boolean(),
|
|
305
|
-
storybookFramework: external_zod_default().string().optional(),
|
|
306
333
|
testingLibrary: external_zod_default().string().optional(),
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
334
|
+
implementations: implementationOptionsSchema.optional(),
|
|
335
|
+
rules: rulesSchema.optional()
|
|
336
|
+
}).passthrough();
|
|
337
|
+
const reactConfigSchema = external_zod_default().object({
|
|
338
|
+
framework: external_zod_default()["enum"]([
|
|
339
|
+
'react',
|
|
340
|
+
'next'
|
|
341
|
+
]).optional(),
|
|
342
|
+
storybookFramework: external_zod_default().string().optional()
|
|
343
|
+
}).passthrough();
|
|
344
|
+
const frontendConfigSchema = external_zod_default().object({
|
|
345
|
+
react: reactConfigSchema.optional()
|
|
346
|
+
}).passthrough();
|
|
347
|
+
const configSchema = external_zod_default().object({
|
|
348
|
+
project: projectConfigSchema,
|
|
349
|
+
backend: backendConfigSchema.optional(),
|
|
350
|
+
frontend: frontendConfigSchema.optional()
|
|
351
|
+
}).passthrough();
|
|
352
|
+
const scaffoldBackendRules = (rules = {})=>({
|
|
353
|
+
dependencies: {
|
|
354
|
+
...Object.fromEntries(Object.entries(defaultDependencies).map(([kind, dependencies])=>[
|
|
355
|
+
kind,
|
|
356
|
+
[
|
|
357
|
+
...dependencies
|
|
358
|
+
]
|
|
359
|
+
])),
|
|
360
|
+
...rules.dependencies
|
|
361
|
+
},
|
|
362
|
+
lint: {
|
|
363
|
+
...Object.fromEntries(lintChecks.map((check)=>[
|
|
364
|
+
check,
|
|
365
|
+
true
|
|
366
|
+
])),
|
|
367
|
+
...rules.lint
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
const isOutdatedConfig = (value)=>'object' == typeof value && null !== value && !Array.isArray(value) && !('project' in value);
|
|
371
|
+
const outdatedConfigMessage = `${config_file_configFileName} uses the format of an earlier major version: run npx df-upgrade.`;
|
|
372
|
+
class ConfigOutdatedError extends Error {
|
|
373
|
+
constructor(){
|
|
374
|
+
super(outdatedConfigMessage);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
312
377
|
class config_file_ConfigFile {
|
|
313
378
|
data;
|
|
314
379
|
constructor(){
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
this.data = configSchema.parse(configObject);
|
|
380
|
+
const raw = JSON.parse(new file_system_File(config_file_ConfigFile.path).data);
|
|
381
|
+
if (isOutdatedConfig(raw)) throw new ConfigOutdatedError();
|
|
382
|
+
this.data = configSchema.parse(raw);
|
|
319
383
|
}
|
|
320
384
|
static get Instance() {
|
|
321
385
|
return new config_file_ConfigFile();
|
|
322
386
|
}
|
|
387
|
+
static get backend() {
|
|
388
|
+
const backend = config_file_ConfigFile.Instance.data.backend;
|
|
389
|
+
if (!backend) throw new Error('Backend is not configured: run df-init --section backend.');
|
|
390
|
+
return backend;
|
|
391
|
+
}
|
|
323
392
|
static get path() {
|
|
324
|
-
|
|
325
|
-
return external_node_path_default().resolve(root, configFileName);
|
|
393
|
+
return external_node_path_default().resolve(new project_root_ProjectRoot().path, config_file_configFileName);
|
|
326
394
|
}
|
|
327
395
|
static get exists() {
|
|
328
396
|
return new file_system_File(config_file_ConfigFile.path).exists;
|
|
329
397
|
}
|
|
398
|
+
static get outdated() {
|
|
399
|
+
if (!config_file_ConfigFile.exists) return false;
|
|
400
|
+
try {
|
|
401
|
+
return isOutdatedConfig(JSON.parse(new file_system_File(config_file_ConfigFile.path).data));
|
|
402
|
+
} catch {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
330
406
|
static write = (config)=>{
|
|
331
|
-
|
|
407
|
+
config_file_ConfigFile.stage(configSchema.parse(config));
|
|
332
408
|
};
|
|
409
|
+
static update = (sections)=>{
|
|
410
|
+
config_file_ConfigFile.stage(configSchema.parse({
|
|
411
|
+
...config_file_ConfigFile.Instance.data,
|
|
412
|
+
...sections
|
|
413
|
+
}));
|
|
414
|
+
};
|
|
415
|
+
static stage(config) {
|
|
416
|
+
new file_system_File(config_file_ConfigFile.path).update(`${JSON.stringify(config, null, 4)}\n`);
|
|
417
|
+
}
|
|
333
418
|
}
|
|
334
419
|
const installCommand = /^\s*npm (?:i|install)((?:\s+(?:--save-dev|-D))?)\s+(.+)$/;
|
|
335
420
|
const mergeInstallCommands = (commands)=>{
|
|
@@ -380,20 +465,110 @@ const print_next_steps_printNextSteps = (nextSteps)=>{
|
|
|
380
465
|
].join('\n'));
|
|
381
466
|
if (sections.length) console.log(sections.join('\n\n'));
|
|
382
467
|
};
|
|
468
|
+
const external_node_async_hooks_namespaceObject = require("node:async_hooks");
|
|
383
469
|
const prompts_namespaceObject = require("@inquirer/prompts");
|
|
470
|
+
class interaction_RequestError extends Error {
|
|
471
|
+
code;
|
|
472
|
+
details;
|
|
473
|
+
constructor(code, message, details){
|
|
474
|
+
super(message), this.code = code, this.details = details;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
const storage = new external_node_async_hooks_namespaceObject.AsyncLocalStorage();
|
|
478
|
+
const interaction_isNonInteractive = ()=>Boolean(storage.getStore());
|
|
479
|
+
const assertAnswersConsumed = ()=>{
|
|
480
|
+
const state = storage.getStore();
|
|
481
|
+
if (!state) return;
|
|
482
|
+
const unused = Object.keys(state.answers).filter((key)=>!state.used.has(key));
|
|
483
|
+
if (unused.length) throw new interaction_RequestError('UNUSED_PARAMETERS', 'Some parameters do not apply to this operation.', {
|
|
484
|
+
fields: unused
|
|
485
|
+
});
|
|
486
|
+
};
|
|
487
|
+
const interaction_answerFor = (key, fallback)=>{
|
|
488
|
+
const state = storage.getStore();
|
|
489
|
+
if (!state) return;
|
|
490
|
+
if (Object.hasOwn(state.answers, key)) {
|
|
491
|
+
state.used.add(key);
|
|
492
|
+
return state.answers[key];
|
|
493
|
+
}
|
|
494
|
+
return Object.hasOwn(state.defaults, key) ? state.defaults[key] : fallback;
|
|
495
|
+
};
|
|
496
|
+
const interaction_report = (...values)=>{
|
|
497
|
+
const state = storage.getStore();
|
|
498
|
+
if (state) state.messages.push(values.map(String).join(' '));
|
|
499
|
+
else console.log(...values);
|
|
500
|
+
};
|
|
501
|
+
const requireKey = (key)=>{
|
|
502
|
+
if (!key) throw new interaction_RequestError('UNSUPPORTED_PROMPT', 'This operation needs an answer that is not supported in non-interactive mode.');
|
|
503
|
+
return key;
|
|
504
|
+
};
|
|
505
|
+
const interaction_missing = (key)=>new interaction_RequestError('MISSING_PARAMETER', `Provide ${key}.`, {
|
|
506
|
+
field: key
|
|
507
|
+
});
|
|
508
|
+
const interaction_input = async (config)=>{
|
|
509
|
+
const { key, ...interactive } = config;
|
|
510
|
+
if (!interaction_isNonInteractive()) return (0, prompts_namespaceObject.input)(interactive);
|
|
511
|
+
const field = requireKey(key);
|
|
512
|
+
const value = interaction_answerFor(field, config.default);
|
|
513
|
+
if ('string' != typeof value) throw interaction_missing(field);
|
|
514
|
+
const valid = await config.validate?.(value);
|
|
515
|
+
if (void 0 !== valid && true !== valid) throw new interaction_RequestError('INVALID_PARAMETER', 'string' == typeof valid ? valid : `Invalid ${field}.`, {
|
|
516
|
+
field
|
|
517
|
+
});
|
|
518
|
+
return value;
|
|
519
|
+
};
|
|
520
|
+
const interaction_confirm = async (config)=>{
|
|
521
|
+
const { key, requestRequired, ...interactive } = config;
|
|
522
|
+
if (!interaction_isNonInteractive()) return (0, prompts_namespaceObject.confirm)(interactive);
|
|
523
|
+
const field = requireKey(key);
|
|
524
|
+
const value = interaction_answerFor(field, requestRequired ? void 0 : config.default ?? false);
|
|
525
|
+
if (void 0 === value) throw interaction_missing(field);
|
|
526
|
+
if ('boolean' != typeof value) throw new interaction_RequestError('INVALID_PARAMETER', `${field} must be a boolean.`, {
|
|
527
|
+
field
|
|
528
|
+
});
|
|
529
|
+
return value;
|
|
530
|
+
};
|
|
531
|
+
const choicesOf = (config)=>config.choices.filter((choice)=>!(choice instanceof prompts_namespaceObject.Separator)).map((choice)=>'object' == typeof choice && null !== choice && 'value' in choice ? choice : {
|
|
532
|
+
value: choice
|
|
533
|
+
});
|
|
534
|
+
const choiceId = (choice, id)=>id?.(choice.value) ?? choice.value;
|
|
535
|
+
const resolveChoice = (value, choices, key, id)=>{
|
|
536
|
+
const matches = choices.filter((choice)=>Object.is(choice.value, value) || choiceId(choice, id) === value);
|
|
537
|
+
if (1 !== matches.length || matches[0].disabled) throw new interaction_RequestError('INVALID_CHOICE', `Invalid or unavailable choice for ${key}.`, {
|
|
538
|
+
field: key,
|
|
539
|
+
value,
|
|
540
|
+
choices: choices.filter((choice)=>!choice.disabled).map((choice)=>choiceId(choice, id))
|
|
541
|
+
});
|
|
542
|
+
return matches[0].value;
|
|
543
|
+
};
|
|
544
|
+
const interaction_select = async (config)=>{
|
|
545
|
+
const { key, id, ...interactive } = config;
|
|
546
|
+
if (!interaction_isNonInteractive()) return (0, prompts_namespaceObject.select)(interactive);
|
|
547
|
+
const field = requireKey(key);
|
|
548
|
+
const value = interaction_answerFor(field, config.default);
|
|
549
|
+
if (void 0 === value) throw interaction_missing(field);
|
|
550
|
+
return resolveChoice(value, choicesOf(config), field, id);
|
|
551
|
+
};
|
|
384
552
|
const save_pending_changes_savePendingChanges = async ()=>{
|
|
385
|
-
|
|
553
|
+
assertAnswersConsumed();
|
|
554
|
+
const overwrittenFiles = filesToOverwrite({
|
|
555
|
+
changedOnly: interaction_isNonInteractive()
|
|
556
|
+
});
|
|
557
|
+
if (interaction_isNonInteractive() && overwrittenFiles.length && !interaction_answerFor('overwrite', false)) throw new interaction_RequestError('OVERWRITE_REQUIRED', 'Set overwrite to true to replace existing files.', {
|
|
558
|
+
files: overwrittenFiles.map((file)=>external_node_path_default().relative(new project_root_ProjectRoot().path, file).split(external_node_path_default().sep).join('/'))
|
|
559
|
+
});
|
|
386
560
|
if (overwrittenFiles.length) {
|
|
387
561
|
const root = new project_root_ProjectRoot().path;
|
|
388
|
-
|
|
389
|
-
for (const filePath of overwrittenFiles)
|
|
390
|
-
const overwrite = await (
|
|
562
|
+
interaction_report('These files already exist and will be overwritten:');
|
|
563
|
+
for (const filePath of overwrittenFiles)interaction_report(` ${external_node_path_default().relative(root, filePath)}`);
|
|
564
|
+
const overwrite = await interaction_confirm({
|
|
565
|
+
key: 'overwrite',
|
|
391
566
|
message: 'Overwrite them?',
|
|
392
567
|
default: false
|
|
393
568
|
});
|
|
394
569
|
if (!overwrite) {
|
|
395
570
|
file_system_discardPendingChanges();
|
|
396
|
-
|
|
571
|
+
interaction_report('Cancelled: nothing was written.');
|
|
397
572
|
return false;
|
|
398
573
|
}
|
|
399
574
|
}
|
|
@@ -536,9 +711,9 @@ describe('in memory db', () => {
|
|
|
536
711
|
})
|
|
537
712
|
})
|
|
538
713
|
`.trim();
|
|
539
|
-
const in_memory_db_withWiring = ()=>config_file_ConfigFile.
|
|
714
|
+
const in_memory_db_withWiring = ()=>config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
540
715
|
const in_memory_db_scaffoldInMemoryDb = (shared)=>{
|
|
541
|
-
const { testingLibrary } = config_file_ConfigFile.
|
|
716
|
+
const { testingLibrary } = config_file_ConfigFile.backend;
|
|
542
717
|
const servicesFolder = shared.subitem([
|
|
543
718
|
'infrastructure',
|
|
544
719
|
'services'
|
|
@@ -584,8 +759,57 @@ const missingPackages = (packages)=>{
|
|
|
584
759
|
`npm i ${missing.join(' ')}`
|
|
585
760
|
] : [];
|
|
586
761
|
};
|
|
587
|
-
const missingDomainFirstPackages = ()=>missingPackages(config_file_ConfigFile.
|
|
762
|
+
const missingDomainFirstPackages = ()=>missingPackages(config_file_ConfigFile.backend.domainFirstPackages);
|
|
763
|
+
const next_app_usesNext = ()=>config_file_ConfigFile.exists && config_file_ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
764
|
+
const next_app_nextAppFolder = (root)=>[
|
|
765
|
+
'app',
|
|
766
|
+
'src/app'
|
|
767
|
+
].find((folder)=>new file_system_Folder(external_node_path_default().join(root, folder)).exists) ?? 'app';
|
|
588
768
|
require("node:module");
|
|
769
|
+
const package_scripts_addPackageScripts = async (file, additions)=>{
|
|
770
|
+
const original = file.data;
|
|
771
|
+
const manifest = JSON.parse(original);
|
|
772
|
+
const scripts = {
|
|
773
|
+
...manifest.scripts
|
|
774
|
+
};
|
|
775
|
+
const selected = {};
|
|
776
|
+
for (const [name, command] of Object.entries(additions)){
|
|
777
|
+
let target = name;
|
|
778
|
+
if (Object.hasOwn(scripts, name) && scripts[name] !== command) {
|
|
779
|
+
const action = await interaction_select({
|
|
780
|
+
key: `scriptConflicts.${name}`,
|
|
781
|
+
message: `Script "${name}" already exists: ${scripts[name]}`,
|
|
782
|
+
choices: [
|
|
783
|
+
'Keep existing',
|
|
784
|
+
'Replace',
|
|
785
|
+
'Use another name'
|
|
786
|
+
]
|
|
787
|
+
});
|
|
788
|
+
if ('Keep existing' === action) continue;
|
|
789
|
+
if ('Use another name' === action) target = await interaction_input({
|
|
790
|
+
key: `scriptNames.${name}`,
|
|
791
|
+
message: "New script name:",
|
|
792
|
+
validate: (value)=>!/^[a-zA-Z0-9:_-]+$/.test(value) || Object.hasOwn(scripts, value) || Object.hasOwn(additions, value) ? "Enter an unused script name (letters, numbers, :, _, -)." : true
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
scripts[target] = command;
|
|
796
|
+
selected[name] = target;
|
|
797
|
+
}
|
|
798
|
+
if (JSON.stringify(manifest.scripts) !== JSON.stringify(scripts)) {
|
|
799
|
+
manifest.scripts = scripts;
|
|
800
|
+
const indent = original.match(/\n([\t ]+)"/)?.[1] ?? ' ';
|
|
801
|
+
file.update(`${JSON.stringify(manifest, null, indent)}\n`);
|
|
802
|
+
}
|
|
803
|
+
return selected;
|
|
804
|
+
};
|
|
805
|
+
const package_scripts_describeScripts = (selected, descriptions)=>Object.entries(descriptions).filter(([name])=>selected[name]).map(([name, description])=>`npm run ${selected[name]} — ${description}`);
|
|
806
|
+
const gitignore_addGitignoreEntry = (root, entry)=>{
|
|
807
|
+
const gitignore = new file_system_File(external_node_path_default().join(root, '.gitignore'));
|
|
808
|
+
const ignored = gitignore.exists ? gitignore.data : '';
|
|
809
|
+
if (ignored.split(/\r?\n/).includes(entry)) return;
|
|
810
|
+
const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
|
|
811
|
+
gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${entry}${newline}`);
|
|
812
|
+
};
|
|
589
813
|
class unknown_format_naming_UnknownFormatNaming {
|
|
590
814
|
rawSource;
|
|
591
815
|
camelCase;
|
|
@@ -617,8 +841,8 @@ class unknown_format_naming_UnknownFormatNaming {
|
|
|
617
841
|
const createPresentationService = (boundedContextFolder, name, classFile)=>{
|
|
618
842
|
const naming = new unknown_format_naming_UnknownFormatNaming(name);
|
|
619
843
|
const className = `${naming.ClassName}PresentationService`;
|
|
620
|
-
const scaffoldUnitTests = Boolean(config_file_ConfigFile.
|
|
621
|
-
const withWiring = config_file_ConfigFile.
|
|
844
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.backend.testingLibrary);
|
|
845
|
+
const withWiring = config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
622
846
|
const wiringFolder = boundedContextFolder.subitem([
|
|
623
847
|
'wiring',
|
|
624
848
|
'presentation-services'
|
|
@@ -633,7 +857,7 @@ export class ${className} {
|
|
|
633
857
|
}
|
|
634
858
|
`.trim());
|
|
635
859
|
if (scaffoldUnitTests) presentationServicesFolder.createFile(`${naming.fileName}-presentation-service.spec.ts`, `
|
|
636
|
-
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.
|
|
860
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.backend.testingLibrary}'
|
|
637
861
|
${withWiring ? `import { type ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'
|
|
638
862
|
import { wire${naming.ClassName}PresentationService } from '../../wiring/presentation-services/wire-${naming.fileName}-presentation-service'` : `import { ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'`}
|
|
639
863
|
|
|
@@ -693,11 +917,7 @@ const rest_endpoint_generator_findRestEndpointGenerator = (sharedFolder)=>{
|
|
|
693
917
|
wireFile: external_node_path_default().join(sharedFolder.path, 'wiring', 'presentation-services', `wire-${rest_endpoint_generator_name}-presentation-service.ts`)
|
|
694
918
|
};
|
|
695
919
|
};
|
|
696
|
-
const
|
|
697
|
-
'app',
|
|
698
|
-
'src/app'
|
|
699
|
-
].find((folder)=>new file_system_Folder(external_node_path_default().join(root, folder)).exists) ?? 'app';
|
|
700
|
-
const nextRoutePath = (root)=>external_node_path_default().posix.join(nextAppFolder(root), 'api/[...path]/route.ts');
|
|
920
|
+
const nextRoutePath = (root)=>external_node_path_default().posix.join(next_app_nextAppFolder(root), 'api/[...path]/route.ts');
|
|
701
921
|
const nextRoute = (restHandlersImport)=>`
|
|
702
922
|
import { nextEndpoints } from '@domain-first/handlers-next'
|
|
703
923
|
${restHandlersImport ? `import { restHandlers } from '${restHandlersImport}'
|
|
@@ -714,8 +934,9 @@ export const PUT = handler
|
|
|
714
934
|
export const PATCH = handler
|
|
715
935
|
export const DELETE = handler
|
|
716
936
|
`.trim();
|
|
717
|
-
const
|
|
718
|
-
const { rootFolder
|
|
937
|
+
const rest_endpoint_generator_scaffoldNextRoute = (root)=>{
|
|
938
|
+
const { rootFolder } = config_file_ConfigFile.Instance.data.project;
|
|
939
|
+
const { domainFirstPackages } = config_file_ConfigFile.backend;
|
|
719
940
|
const routePath = nextRoutePath(root);
|
|
720
941
|
const routeFile = external_node_path_default().join(root, routePath);
|
|
721
942
|
if (new file_system_File(routeFile).exists) return [];
|
|
@@ -733,20 +954,21 @@ const scaffoldNextRoute = (root)=>{
|
|
|
733
954
|
`${routePath} serves restHandlers from ${external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/rest/index.ts')}, which appears with the first REST endpoint — generate one with df-scaffold (Presentation → New Handlers-REST Endpoint) and the route compiles`
|
|
734
955
|
];
|
|
735
956
|
};
|
|
736
|
-
const askNextAdapter = async ()=>
|
|
737
|
-
|
|
957
|
+
const askNextAdapter = async ({ nextSelected } = {})=>(nextSelected ?? next_app_usesNext()) && await interaction_confirm({
|
|
958
|
+
key: 'nextAdapter',
|
|
959
|
+
message: 'Use @domain-first/handlers-next for REST endpoints'
|
|
738
960
|
});
|
|
739
961
|
const scaffoldRestEndpointGeneratorFiles = ({ withNextAdapter })=>{
|
|
740
962
|
const root = new project_root_ProjectRoot().path;
|
|
741
963
|
const generatorExisted = rest_endpoint_generator_restEndpointGeneratorApplied();
|
|
742
964
|
const routeNotes = file_system_withoutOverwrites(()=>{
|
|
743
965
|
scaffoldRestEndpointGenerator(new file_system_Folder(root).subitem([
|
|
744
|
-
config_file_ConfigFile.Instance.data.rootFolder,
|
|
966
|
+
config_file_ConfigFile.Instance.data.project.rootFolder,
|
|
745
967
|
'shared-kernel'
|
|
746
968
|
]), {
|
|
747
969
|
withNextAdapter
|
|
748
970
|
});
|
|
749
|
-
return withNextAdapter ?
|
|
971
|
+
return withNextAdapter ? rest_endpoint_generator_scaffoldNextRoute(root) : [];
|
|
750
972
|
});
|
|
751
973
|
if (!withNextAdapter) return [];
|
|
752
974
|
return [
|
|
@@ -760,80 +982,440 @@ const scaffoldRestEndpointGeneratorFiles = ({ withNextAdapter })=>{
|
|
|
760
982
|
];
|
|
761
983
|
};
|
|
762
984
|
const rest_endpoint_generator_restEndpointGeneratorApplied = ()=>Boolean(rest_endpoint_generator_findRestEndpointGenerator(new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
763
|
-
config_file_ConfigFile.Instance.data.rootFolder,
|
|
985
|
+
config_file_ConfigFile.Instance.data.project.rootFolder,
|
|
764
986
|
'shared-kernel'
|
|
765
987
|
])));
|
|
766
|
-
const
|
|
767
|
-
|
|
988
|
+
const storybookFrameworkPackage = '@storybook/react-vite';
|
|
989
|
+
const storybookFiles = (relativeProjectRoot)=>({
|
|
990
|
+
'main.ts': `import { resolve } from 'node:path';
|
|
991
|
+
import react from '@vitejs/plugin-react';
|
|
992
|
+
import type { StorybookConfig } from '${storybookFrameworkPackage}';
|
|
993
|
+
|
|
994
|
+
const projectRoot = resolve(import.meta.dirname, ${JSON.stringify(relativeProjectRoot)});
|
|
995
|
+
|
|
996
|
+
const config: StorybookConfig = {
|
|
997
|
+
stories: ['../**/*.mdx', '../**/*.stories.@(ts|tsx)'],
|
|
998
|
+
framework: {
|
|
999
|
+
name: '${storybookFrameworkPackage}',
|
|
1000
|
+
options: {}
|
|
1001
|
+
},
|
|
1002
|
+
core: {
|
|
1003
|
+
disableTelemetry: true
|
|
1004
|
+
},
|
|
1005
|
+
async viteFinal(viteConfig) {
|
|
1006
|
+
const { mergeConfig } = await import('vite');
|
|
1007
|
+
|
|
1008
|
+
return mergeConfig(viteConfig, {
|
|
1009
|
+
plugins: [react()],
|
|
1010
|
+
resolve: {
|
|
1011
|
+
alias: {
|
|
1012
|
+
'@': projectRoot
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1019
|
+
export default config;
|
|
1020
|
+
`,
|
|
1021
|
+
'preview.ts': `import type { Preview } from '${storybookFrameworkPackage}';
|
|
1022
|
+
|
|
1023
|
+
const preview: Preview = {
|
|
1024
|
+
parameters: {
|
|
1025
|
+
controls: {
|
|
1026
|
+
matchers: {
|
|
1027
|
+
color: /(background|color)$/i,
|
|
1028
|
+
date: /Date$/i
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
export default preview;
|
|
1035
|
+
`
|
|
1036
|
+
});
|
|
1037
|
+
const storybookScripts = (rootFolder)=>{
|
|
1038
|
+
const folder = external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react');
|
|
1039
|
+
const quote = (value)=>JSON.stringify(value);
|
|
1040
|
+
return {
|
|
1041
|
+
storybook: `storybook dev -p 6006 -c ${quote(`${folder}/.storybook`)}`,
|
|
1042
|
+
'build-storybook': `storybook build -c ${quote(`${folder}/.storybook`)} -o ${quote(`${folder}/storybook-static`)}`
|
|
1043
|
+
};
|
|
1044
|
+
};
|
|
1045
|
+
const storybook_addStorybook = async ()=>{
|
|
1046
|
+
const config = config_file_ConfigFile.Instance.data;
|
|
1047
|
+
if ((!config.frontend?.react || config.frontend?.react?.storybookFramework && config.frontend?.react?.storybookFramework !== storybookFrameworkPackage) && !await interaction_confirm({
|
|
1048
|
+
key: 'configureReact',
|
|
1049
|
+
requestRequired: true,
|
|
1050
|
+
message: `Configure React scaffolding with ${storybookFrameworkPackage}?`,
|
|
1051
|
+
default: false
|
|
1052
|
+
})) return [];
|
|
1053
|
+
const root = new project_root_ProjectRoot().path;
|
|
1054
|
+
const manifestFile = new file_system_File(external_node_path_default().join(root, 'package.json'));
|
|
1055
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
1056
|
+
const selected = await package_scripts_addPackageScripts(manifestFile, storybookScripts(config.project.rootFolder));
|
|
1057
|
+
const folder = new file_system_Folder(root).subitem([
|
|
1058
|
+
config.project.rootFolder,
|
|
1059
|
+
'presentation',
|
|
1060
|
+
'react',
|
|
1061
|
+
'.storybook'
|
|
1062
|
+
]);
|
|
1063
|
+
for (const [name, content] of Object.entries(storybookFiles(external_node_path_default().relative(folder.path, root).split(external_node_path_default().sep).join('/')))){
|
|
1064
|
+
const file = new file_system_File(external_node_path_default().join(folder.path, name));
|
|
1065
|
+
if (!file.exists || file.data !== content) file.data = content;
|
|
1066
|
+
}
|
|
1067
|
+
if (!config.frontend?.react || config.frontend?.react?.storybookFramework !== storybookFrameworkPackage) config_file_ConfigFile.update({
|
|
1068
|
+
frontend: {
|
|
1069
|
+
...config.frontend,
|
|
1070
|
+
react: {
|
|
1071
|
+
...config.frontend?.react,
|
|
1072
|
+
storybookFramework: storybookFrameworkPackage
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
const buildFolder = external_node_path_default().posix.join(config.project.rootFolder.replaceAll('\\', '/'), 'presentation/react/storybook-static');
|
|
1077
|
+
gitignore_addGitignoreEntry(root, `/${buildFolder}/`);
|
|
1078
|
+
const dependencies = {
|
|
1079
|
+
...manifest.dependencies,
|
|
1080
|
+
...manifest.devDependencies
|
|
1081
|
+
};
|
|
1082
|
+
const missing = [
|
|
1083
|
+
'storybook',
|
|
1084
|
+
storybookFrameworkPackage,
|
|
1085
|
+
'vite',
|
|
1086
|
+
'@vitejs/plugin-react'
|
|
1087
|
+
].filter((name)=>!dependencies[name]);
|
|
1088
|
+
const missingReact = [
|
|
1089
|
+
'react',
|
|
1090
|
+
'react-dom'
|
|
1091
|
+
].filter((name)=>!dependencies[name]);
|
|
1092
|
+
return [
|
|
1093
|
+
...missing.length ? [
|
|
1094
|
+
`npm install --save-dev ${missing.join(' ')}`
|
|
1095
|
+
] : [],
|
|
1096
|
+
...missingReact.length ? [
|
|
1097
|
+
`npm install ${missingReact.join(' ')}`
|
|
1098
|
+
] : [],
|
|
1099
|
+
...package_scripts_describeScripts(selected, {
|
|
1100
|
+
storybook: 'start Storybook on http://localhost:6006',
|
|
1101
|
+
'build-storybook': `build static Storybook into ${buildFolder}`
|
|
1102
|
+
})
|
|
1103
|
+
];
|
|
1104
|
+
};
|
|
1105
|
+
const defaultEnvBranches = {
|
|
1106
|
+
names: [
|
|
1107
|
+
'test',
|
|
1108
|
+
'development',
|
|
1109
|
+
'production'
|
|
1110
|
+
],
|
|
1111
|
+
test: 'test'
|
|
1112
|
+
};
|
|
1113
|
+
const wire_branches_envBranches = ()=>{
|
|
1114
|
+
const configured = config_file_ConfigFile.exists ? config_file_ConfigFile.Instance.data.backend?.envBranches : void 0;
|
|
1115
|
+
const { names, test } = configured ?? defaultEnvBranches;
|
|
1116
|
+
return {
|
|
1117
|
+
names,
|
|
1118
|
+
test,
|
|
1119
|
+
primary: names.filter((name)=>name !== test),
|
|
1120
|
+
custom: Boolean(configured)
|
|
1121
|
+
};
|
|
1122
|
+
};
|
|
1123
|
+
const envBranchedWireSource = ()=>{
|
|
1124
|
+
const { names, custom } = wire_branches_envBranches();
|
|
1125
|
+
if (!custom) return `import { branchedWire } from '@domain-first/wire'
|
|
1126
|
+
|
|
1127
|
+
export const envBranchedWire = branchedWire(() => {
|
|
1128
|
+
return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
|
|
1129
|
+
});`;
|
|
1130
|
+
return `import { branchedWire } from '@domain-first/wire'
|
|
1131
|
+
|
|
1132
|
+
export type EnvBranch = ${names.map((name)=>`'${name}'`).join(' | ')}
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
* The branch this process runs in. Write how it is selected:
|
|
1136
|
+
* until then, this function doesn't compile.
|
|
1137
|
+
*/
|
|
1138
|
+
const currentBranch = (): EnvBranch => {
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
export const envBranchedWire = branchedWire(currentBranch)`;
|
|
1142
|
+
};
|
|
1143
|
+
const configurationSections = [
|
|
1144
|
+
'project',
|
|
1145
|
+
'backend',
|
|
1146
|
+
'frontend'
|
|
1147
|
+
];
|
|
1148
|
+
const configureProject = async (config)=>{
|
|
1149
|
+
const rootFolder = await (0, prompts_namespaceObject.input)({
|
|
768
1150
|
message: 'Root folder (use "/" for inner folders):',
|
|
769
|
-
default:
|
|
1151
|
+
default: config.project.rootFolder,
|
|
1152
|
+
validate: (value)=>value.trim() ? true : 'Root folder is required'
|
|
770
1153
|
});
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
'@domain-first/handlers',
|
|
777
|
-
'@domain-first/wire',
|
|
778
|
-
'@domain-first/handlers-rest'
|
|
779
|
-
]
|
|
1154
|
+
config_file_ConfigFile.update({
|
|
1155
|
+
project: {
|
|
1156
|
+
...config.project,
|
|
1157
|
+
rootFolder: rootFolder.trim()
|
|
1158
|
+
}
|
|
780
1159
|
});
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
1160
|
+
};
|
|
1161
|
+
const createTestBranch = Symbol('create-test-branch');
|
|
1162
|
+
const noTestBranch = Symbol('no-test-branch');
|
|
1163
|
+
const promptEnvBranches = async (current)=>{
|
|
1164
|
+
const kind = await (0, prompts_namespaceObject.select)({
|
|
1165
|
+
message: 'envBranchedWire branches:',
|
|
1166
|
+
choices: [
|
|
1167
|
+
{
|
|
1168
|
+
name: 'Default: test, development, production by NODE_ENV',
|
|
1169
|
+
value: 'default'
|
|
1170
|
+
},
|
|
1171
|
+
{
|
|
1172
|
+
name: 'Custom branches',
|
|
1173
|
+
value: 'custom'
|
|
1174
|
+
}
|
|
1175
|
+
],
|
|
1176
|
+
default: current ? 'custom' : 'default'
|
|
784
1177
|
});
|
|
785
|
-
|
|
786
|
-
|
|
1178
|
+
if ('default' === kind) return;
|
|
1179
|
+
const parse = (value)=>value.split(',').map((name)=>name.trim()).filter(Boolean);
|
|
1180
|
+
const names = parse(await (0, prompts_namespaceObject.input)({
|
|
1181
|
+
message: 'Branches (comma-separated):',
|
|
1182
|
+
default: current?.names.join(', '),
|
|
1183
|
+
validate: (value)=>{
|
|
1184
|
+
const names = parse(value);
|
|
1185
|
+
if (!names.length) return 'Enter at least one branch.';
|
|
1186
|
+
if (1 === names.length && 'test' === names[0]) return 'Add a branch for primary implementations besides test.';
|
|
1187
|
+
const invalid = names.find((name)=>!branchNameSchema.safeParse(name).success);
|
|
1188
|
+
if (invalid) return `${invalid}: use lowercase letters and digits, e.g. staging.`;
|
|
1189
|
+
return new Set(names).size === names.length ? true : 'Branch names must be unique.';
|
|
1190
|
+
}
|
|
1191
|
+
}));
|
|
1192
|
+
const test = await (0, prompts_namespaceObject.select)({
|
|
1193
|
+
message: 'Test branch:',
|
|
1194
|
+
choices: [
|
|
1195
|
+
...names.map((name)=>({
|
|
1196
|
+
name,
|
|
1197
|
+
value: name,
|
|
1198
|
+
disabled: 1 === names.length ? '(the only branch)' : false
|
|
1199
|
+
})),
|
|
1200
|
+
...names.includes('test') ? [] : [
|
|
1201
|
+
{
|
|
1202
|
+
name: 'Create a "test" branch',
|
|
1203
|
+
value: createTestBranch
|
|
1204
|
+
}
|
|
1205
|
+
],
|
|
1206
|
+
{
|
|
1207
|
+
name: 'No test branch: every branch uses the primary implementation',
|
|
1208
|
+
value: noTestBranch
|
|
1209
|
+
}
|
|
1210
|
+
],
|
|
1211
|
+
default: current && !current.test ? noTestBranch : current?.test && names.includes(current.test) ? current.test : names.includes('test') ? 'test' : createTestBranch
|
|
787
1212
|
});
|
|
788
|
-
|
|
789
|
-
|
|
1213
|
+
if (test === noTestBranch) return {
|
|
1214
|
+
names
|
|
1215
|
+
};
|
|
1216
|
+
return test === createTestBranch ? {
|
|
1217
|
+
names: [
|
|
1218
|
+
...names,
|
|
1219
|
+
'test'
|
|
1220
|
+
],
|
|
1221
|
+
test: 'test'
|
|
1222
|
+
} : {
|
|
1223
|
+
names,
|
|
1224
|
+
test
|
|
1225
|
+
};
|
|
1226
|
+
};
|
|
1227
|
+
const configureBackend = async (config)=>{
|
|
1228
|
+
const current = config.backend;
|
|
1229
|
+
const domainFirstPackages = await (0, prompts_namespaceObject.checkbox)({
|
|
1230
|
+
message: '@domain-first packages',
|
|
1231
|
+
choices: config_file_domainFirstPackages.map((value)=>({
|
|
1232
|
+
name: value,
|
|
1233
|
+
value,
|
|
1234
|
+
checked: current?.domainFirstPackages.includes(value) ?? false
|
|
1235
|
+
}))
|
|
790
1236
|
});
|
|
791
|
-
|
|
792
|
-
const
|
|
793
|
-
message: '
|
|
794
|
-
|
|
795
|
-
if (withStorybook) storybookFramework = await (0, prompts_namespaceObject.input)({
|
|
796
|
-
message: 'Storybook framework package:',
|
|
797
|
-
default: '@storybook/react-vite'
|
|
1237
|
+
const envBranches = domainFirstPackages.includes('@domain-first/wire') ? await promptEnvBranches(current?.envBranches) : current?.envBranches;
|
|
1238
|
+
const withInMemoryDb = await (0, prompts_namespaceObject.confirm)({
|
|
1239
|
+
message: 'Scaffold in-memory DB for test implementations',
|
|
1240
|
+
default: current ? Boolean(current.withInMemoryDb) : true
|
|
798
1241
|
});
|
|
799
|
-
let testingLibrary;
|
|
800
1242
|
const withTests = await (0, prompts_namespaceObject.confirm)({
|
|
801
|
-
message: 'Scaffold unit tests'
|
|
1243
|
+
message: 'Scaffold unit tests',
|
|
1244
|
+
default: current ? Boolean(current.testingLibrary) : true
|
|
802
1245
|
});
|
|
803
|
-
|
|
1246
|
+
const testingLibrary = withTests ? await (0, prompts_namespaceObject.input)({
|
|
804
1247
|
message: 'Unit testing library:',
|
|
805
|
-
default: 'vitest'
|
|
806
|
-
});
|
|
807
|
-
config_file_ConfigFile.
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
const rootFolder = new file_system_Folder(path);
|
|
818
|
-
|
|
1248
|
+
default: current?.testingLibrary ?? 'vitest'
|
|
1249
|
+
}) : void 0;
|
|
1250
|
+
config_file_ConfigFile.update({
|
|
1251
|
+
backend: {
|
|
1252
|
+
...current,
|
|
1253
|
+
domainFirstPackages,
|
|
1254
|
+
envBranches,
|
|
1255
|
+
withInMemoryDb,
|
|
1256
|
+
testingLibrary,
|
|
1257
|
+
rules: scaffoldBackendRules(current?.rules)
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
1260
|
+
const rootFolder = new file_system_Folder(new project_root_ProjectRoot().path);
|
|
1261
|
+
const rootFolderName = config.project.rootFolder;
|
|
1262
|
+
const wiringFolder = rootFolder.subitem([
|
|
819
1263
|
rootFolderName,
|
|
820
1264
|
'shared-kernel',
|
|
821
1265
|
'wiring'
|
|
822
|
-
])
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
});
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
}));
|
|
1266
|
+
]);
|
|
1267
|
+
const notes = [];
|
|
1268
|
+
const envBranchedWireExisted = new file_system_File(external_node_path_default().join(wiringFolder.path, 'env-branched-wire.ts')).exists;
|
|
1269
|
+
if (domainFirstPackages.includes('@domain-first/wire') && envBranchedWireExisted && JSON.stringify(envBranches ?? null) !== JSON.stringify(current?.envBranches ?? null)) {
|
|
1270
|
+
const { names } = envBranches ?? defaultEnvBranches;
|
|
1271
|
+
notes.push(`${rootFolderName}/shared-kernel/wiring/env-branched-wire.ts and existing envBranchedWire calls keep their branches: change them to ${names.join(', ')} yourself`);
|
|
1272
|
+
}
|
|
1273
|
+
file_system_withoutOverwrites(()=>{
|
|
1274
|
+
if (domainFirstPackages.includes('@domain-first/wire')) wiringFolder.createFile('env-branched-wire.ts', envBranchedWireSource());
|
|
1275
|
+
if (withInMemoryDb) in_memory_db_scaffoldInMemoryDb(rootFolder.subitem([
|
|
1276
|
+
rootFolderName,
|
|
1277
|
+
'shared-kernel'
|
|
1278
|
+
]));
|
|
1279
|
+
});
|
|
1280
|
+
if (envBranches && !envBranchedWireExisted) notes.push(`${rootFolderName}/shared-kernel/wiring/env-branched-wire.ts doesn't compile until you write currentBranch: return the branch this process runs in (${envBranches.names.join(', ')})`);
|
|
1281
|
+
return notes;
|
|
1282
|
+
};
|
|
1283
|
+
const configureFrontend = async (config)=>{
|
|
1284
|
+
const currentFramework = config.frontend?.react?.framework ?? (hasDependency('next') ? 'next' : 'react');
|
|
1285
|
+
const framework = await (0, prompts_namespaceObject.select)({
|
|
1286
|
+
message: 'Frontend framework:',
|
|
1287
|
+
choices: [
|
|
1288
|
+
{
|
|
1289
|
+
name: 'React',
|
|
1290
|
+
value: 'react'
|
|
1291
|
+
},
|
|
1292
|
+
{
|
|
1293
|
+
name: 'Next.js',
|
|
1294
|
+
value: 'next'
|
|
1295
|
+
}
|
|
1296
|
+
],
|
|
1297
|
+
default: currentFramework
|
|
1298
|
+
});
|
|
1299
|
+
const withNextAdapter = 'next' === framework && config.backend ? await askNextAdapter({
|
|
1300
|
+
nextSelected: true
|
|
1301
|
+
}) : false;
|
|
1302
|
+
const withStorybook = await (0, prompts_namespaceObject.confirm)({
|
|
1303
|
+
message: 'Use Storybook',
|
|
1304
|
+
default: config.frontend?.react ? Boolean(config.frontend.react.storybookFramework) : true
|
|
1305
|
+
});
|
|
1306
|
+
const storybookFramework = withStorybook ? storybookFrameworkPackage : void 0;
|
|
1307
|
+
config_file_ConfigFile.update({
|
|
1308
|
+
frontend: {
|
|
1309
|
+
...config.frontend,
|
|
1310
|
+
react: {
|
|
1311
|
+
...config.frontend?.react,
|
|
1312
|
+
framework,
|
|
1313
|
+
storybookFramework
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
});
|
|
1317
|
+
return {
|
|
1318
|
+
withNextAdapter,
|
|
1319
|
+
nextSteps: [
|
|
1320
|
+
...missingPackages('next' === framework ? [
|
|
1321
|
+
'next',
|
|
1322
|
+
'react',
|
|
1323
|
+
'react-dom'
|
|
1324
|
+
] : [
|
|
1325
|
+
'react',
|
|
1326
|
+
'react-dom'
|
|
1327
|
+
]),
|
|
1328
|
+
...withStorybook ? await storybook_addStorybook() : []
|
|
1329
|
+
]
|
|
1330
|
+
};
|
|
1331
|
+
};
|
|
1332
|
+
const configureRest = async (withNextAdapter)=>{
|
|
1333
|
+
const backend = config_file_ConfigFile.Instance.data.backend;
|
|
1334
|
+
if (!backend) return [];
|
|
1335
|
+
const withRest = backend.domainFirstPackages.includes('@domain-first/handlers-rest');
|
|
1336
|
+
const nextSelected = config_file_ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
1337
|
+
if (void 0 === withNextAdapter && (withRest || nextSelected)) withNextAdapter = await askNextAdapter();
|
|
1338
|
+
if (!withRest && !withNextAdapter) return [];
|
|
1339
|
+
if (withNextAdapter && !withRest) config_file_ConfigFile.update({
|
|
1340
|
+
backend: {
|
|
1341
|
+
...backend,
|
|
1342
|
+
domainFirstPackages: [
|
|
1343
|
+
...backend.domainFirstPackages,
|
|
1344
|
+
'@domain-first/handlers-rest'
|
|
1345
|
+
]
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
return scaffoldRestEndpointGeneratorFiles({
|
|
1349
|
+
withNextAdapter: withNextAdapter ?? false
|
|
1350
|
+
});
|
|
1351
|
+
};
|
|
1352
|
+
const initializeUseCase = async (section)=>{
|
|
1353
|
+
const existing = config_file_ConfigFile.exists;
|
|
1354
|
+
if (!existing) config_file_ConfigFile.write({
|
|
1355
|
+
project: {
|
|
1356
|
+
rootFolder: 'src'
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
let sections = configurationSections;
|
|
1360
|
+
if (section) sections = 'project' === section || existing ? [
|
|
1361
|
+
section
|
|
1362
|
+
] : [
|
|
1363
|
+
'project',
|
|
1364
|
+
section
|
|
1365
|
+
];
|
|
1366
|
+
else if (existing) {
|
|
1367
|
+
const selected = await (0, prompts_namespaceObject.select)({
|
|
1368
|
+
message: 'Configuration section:',
|
|
1369
|
+
choices: [
|
|
1370
|
+
...configurationSections.map((value)=>({
|
|
1371
|
+
name: `${value[0].toUpperCase()}${value.slice(1)}${config_file_ConfigFile.Instance.data[value] ? '' : ' (not configured)'}`,
|
|
1372
|
+
value
|
|
1373
|
+
})),
|
|
1374
|
+
{
|
|
1375
|
+
name: 'All sections',
|
|
1376
|
+
value: 'all'
|
|
1377
|
+
}
|
|
1378
|
+
]
|
|
1379
|
+
});
|
|
1380
|
+
sections = 'all' === selected ? configurationSections : [
|
|
1381
|
+
selected
|
|
1382
|
+
];
|
|
1383
|
+
}
|
|
1384
|
+
const nextSteps = [];
|
|
1385
|
+
let backendConfigured = false;
|
|
1386
|
+
let withNextAdapter;
|
|
1387
|
+
for (const currentSection of sections){
|
|
1388
|
+
console.log(`\n${currentSection[0].toUpperCase()}${currentSection.slice(1)} configuration`);
|
|
1389
|
+
if (!section && sections.length > 1 && !await (0, prompts_namespaceObject.confirm)({
|
|
1390
|
+
message: `Configure ${currentSection} now?`,
|
|
1391
|
+
default: true
|
|
1392
|
+
})) {
|
|
1393
|
+
if ('project' === currentSection) console.log(`Keeping project root folder: ${config_file_ConfigFile.Instance.data.project.rootFolder}.`);
|
|
1394
|
+
nextSteps.push(`configure ${currentSection} later with df-init --section ${currentSection}`);
|
|
1395
|
+
continue;
|
|
1396
|
+
}
|
|
1397
|
+
const config = config_file_ConfigFile.Instance.data;
|
|
1398
|
+
switch(currentSection){
|
|
1399
|
+
case 'project':
|
|
1400
|
+
await configureProject(config);
|
|
1401
|
+
break;
|
|
1402
|
+
case 'backend':
|
|
1403
|
+
nextSteps.push(...await configureBackend(config));
|
|
1404
|
+
backendConfigured = true;
|
|
1405
|
+
break;
|
|
1406
|
+
case 'frontend':
|
|
1407
|
+
{
|
|
1408
|
+
const frontend = await configureFrontend(config);
|
|
1409
|
+
withNextAdapter = frontend.withNextAdapter;
|
|
1410
|
+
nextSteps.push(...frontend.nextSteps);
|
|
1411
|
+
break;
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
if (backendConfigured || withNextAdapter) {
|
|
1416
|
+
const restSteps = await configureRest(withNextAdapter);
|
|
1417
|
+
nextSteps.push(...missingDomainFirstPackages(), ...restSteps);
|
|
1418
|
+
}
|
|
837
1419
|
return nextSteps;
|
|
838
1420
|
};
|
|
839
1421
|
new Set([
|
|
@@ -891,38 +1473,51 @@ const domainModelLayout = (kind)=>{
|
|
|
891
1473
|
};
|
|
892
1474
|
};
|
|
893
1475
|
domainModelLayout('entity'), domainModelLayout('value-object'), serviceLayout('domain'), serviceLayout('application'), serviceLayout('infrastructure'), serviceLayout('presentation'), handlerLayout('command'), handlerLayout('query');
|
|
894
|
-
|
|
1476
|
+
Symbol('enter-implementation-type-once');
|
|
1477
|
+
const help = `Usage: df-init [--section project|backend|frontend]
|
|
895
1478
|
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1479
|
+
Configures project, backend and frontend in order. Any section
|
|
1480
|
+
can be deferred and configured later by rerunning df-init or selecting
|
|
1481
|
+
--section. Backend setup writes editable default dependency rules and lint
|
|
1482
|
+
checks into backend.rules, preserving existing entries and saved choices.
|
|
1483
|
+
Frontend selects React or Next.js; Next.js offers handlers-next REST setup
|
|
1484
|
+
when backend is configured.
|
|
1485
|
+
Migrates the legacy config and implementation choices into sections in
|
|
1486
|
+
domain-first.project-structure.config.json. Prints install commands;
|
|
1487
|
+
nothing is installed.
|
|
901
1488
|
|
|
902
1489
|
Options:
|
|
903
|
-
|
|
904
|
-
|
|
1490
|
+
--section <name> configure one section
|
|
1491
|
+
-h, --help show this help`;
|
|
1492
|
+
const { values: init_values } = (0, external_node_util_namespaceObject.parseArgs)({
|
|
905
1493
|
options: {
|
|
906
1494
|
help: {
|
|
907
1495
|
type: 'boolean',
|
|
908
1496
|
short: 'h',
|
|
909
1497
|
default: false
|
|
1498
|
+
},
|
|
1499
|
+
section: {
|
|
1500
|
+
type: 'string'
|
|
910
1501
|
}
|
|
911
1502
|
}
|
|
912
1503
|
});
|
|
913
|
-
if (
|
|
1504
|
+
if (init_values.help) {
|
|
914
1505
|
console.log(help);
|
|
915
1506
|
process.exit(0);
|
|
916
1507
|
}
|
|
917
|
-
if (
|
|
918
|
-
console.
|
|
1508
|
+
if (void 0 !== init_values.section && !configurationSections.includes(init_values.section)) {
|
|
1509
|
+
console.error('Unknown section: use project, backend or frontend.');
|
|
919
1510
|
process.exit(1);
|
|
920
1511
|
}
|
|
921
|
-
const
|
|
922
|
-
|
|
1512
|
+
const init_run = async ()=>{
|
|
1513
|
+
if (config_file_ConfigFile.outdated) {
|
|
1514
|
+
console.log(outdatedConfigMessage);
|
|
1515
|
+
process.exit(1);
|
|
1516
|
+
}
|
|
1517
|
+
const nextSteps = await initializeUseCase(init_values.section);
|
|
923
1518
|
if (await save_pending_changes_savePendingChanges()) print_next_steps_printNextSteps(nextSteps);
|
|
924
1519
|
};
|
|
925
|
-
|
|
1520
|
+
init_run();
|
|
926
1521
|
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
927
1522
|
Object.defineProperty(exports, '__esModule', {
|
|
928
1523
|
value: true
|