@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/287.js
CHANGED
|
@@ -1,27 +1,13 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
3
|
import { Separator, checkbox as prompts_checkbox, confirm as prompts_confirm, input, select as prompts_select } from "@inquirer/prompts";
|
|
3
4
|
import { styleText } from "node:util";
|
|
4
5
|
import node_fs from "node:fs";
|
|
5
|
-
import { addImport, availableDependencies,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
console.log('These files already exist and will be overwritten:');
|
|
11
|
-
for (const filePath of overwrittenFiles)console.log(` ${node_path.relative(root, filePath)}`);
|
|
12
|
-
const overwrite = await prompts_confirm({
|
|
13
|
-
message: 'Overwrite them?',
|
|
14
|
-
default: false
|
|
15
|
-
});
|
|
16
|
-
if (!overwrite) {
|
|
17
|
-
discardPendingChanges();
|
|
18
|
-
console.log('Cancelled: nothing was written.');
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
writePendingChanges();
|
|
23
|
-
return true;
|
|
24
|
-
};
|
|
6
|
+
import { addImport, availableDependencies, compilerOption, findWiredModules, UnknownFormatNaming, readWiredModule, stripJsonComments, addClassMember, hasNeighboringBoundedContext, addBranchedImplementation, addWireDependencies, boundedContextLocation, addConstructorParameters, relativeImport, wireBranches, wireDependencies, implementationType as wiring_implementationType, crossContextImportAllowed, crossContextImplementation, isSuggestedFor } from "./201.js";
|
|
7
|
+
import { implementationLabelSchema, withoutOverwrites, domainFirstPackages as config_file_domainFirstPackages, scaffoldBackendRules, branchNameSchema, discardPendingChanges, ConfigFile, filesToOverwrite, Folder, writePendingChanges, File, ProjectRoot } from "./870.js";
|
|
8
|
+
import { missingPackages, hasDependency, missingDomainFirstPackages } from "./711.js";
|
|
9
|
+
const moduleId = (module)=>`${boundedContextLocation(module.typeFile)?.name ?? 'shared-kernel'}:${module.typeName}`;
|
|
10
|
+
const unitId = (unit)=>`${unit.kind}:${unit.aggregate ? `${unit.aggregate}/` : ''}${unit.name}`;
|
|
25
11
|
const inMemoryImplementationType = 'in-memory';
|
|
26
12
|
const in_memory_db_className = 'InMemoryDbInfrastructureService';
|
|
27
13
|
const in_memory_db_wireName = 'wireInMemoryDbInfrastructureService';
|
|
@@ -158,9 +144,9 @@ describe('in memory db', () => {
|
|
|
158
144
|
})
|
|
159
145
|
})
|
|
160
146
|
`.trim();
|
|
161
|
-
const in_memory_db_withWiring = ()=>ConfigFile.
|
|
147
|
+
const in_memory_db_withWiring = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
162
148
|
const in_memory_db_sharedFolder = ()=>new Folder(new ProjectRoot().path).subitem([
|
|
163
|
-
ConfigFile.Instance.data.rootFolder,
|
|
149
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
164
150
|
'shared-kernel'
|
|
165
151
|
]);
|
|
166
152
|
const serviceFile = ()=>new File(in_memory_db_sharedFolder().path).subitem([
|
|
@@ -174,7 +160,7 @@ const in_memory_db_wireFile = ()=>new File(in_memory_db_sharedFolder().path).sub
|
|
|
174
160
|
'wire-in-memory-db-infrastructure-service.ts'
|
|
175
161
|
]);
|
|
176
162
|
const scaffoldInMemoryDb = (shared)=>{
|
|
177
|
-
const { testingLibrary } = ConfigFile.
|
|
163
|
+
const { testingLibrary } = ConfigFile.backend;
|
|
178
164
|
const servicesFolder = shared.subitem([
|
|
179
165
|
'infrastructure',
|
|
180
166
|
'services'
|
|
@@ -187,7 +173,7 @@ const scaffoldInMemoryDb = (shared)=>{
|
|
|
187
173
|
]).createFile('wire-in-memory-db-infrastructure-service.ts', inMemoryDbWiring);
|
|
188
174
|
};
|
|
189
175
|
const inMemoryDbScaffolded = ()=>serviceFile().exists && (!in_memory_db_withWiring() || in_memory_db_wireFile().exists);
|
|
190
|
-
const usesInMemoryDb = (implementationType)=>Boolean(ConfigFile.Instance.data.withInMemoryDb) && new UnknownFormatNaming(implementationType).fileName === inMemoryImplementationType && inMemoryDbScaffolded();
|
|
176
|
+
const usesInMemoryDb = (implementationType)=>Boolean(ConfigFile.Instance.data.backend?.withInMemoryDb) && new UnknownFormatNaming(implementationType).fileName === inMemoryImplementationType && inMemoryDbScaffolded();
|
|
191
177
|
const uncountableEndings = [
|
|
192
178
|
'data',
|
|
193
179
|
'info',
|
|
@@ -247,36 +233,136 @@ const passInMemoryDb = (specFile, implementationName)=>{
|
|
|
247
233
|
};
|
|
248
234
|
const addInMemoryDb = ()=>{
|
|
249
235
|
const config = ConfigFile.Instance.data;
|
|
250
|
-
if (!
|
|
251
|
-
|
|
252
|
-
|
|
236
|
+
if (!ConfigFile.backend.withInMemoryDb) ConfigFile.update({
|
|
237
|
+
backend: {
|
|
238
|
+
...ConfigFile.backend,
|
|
239
|
+
withInMemoryDb: true
|
|
240
|
+
}
|
|
253
241
|
});
|
|
254
242
|
withoutOverwrites(()=>scaffoldInMemoryDb(new Folder(new ProjectRoot().path).subitem([
|
|
255
|
-
config.rootFolder,
|
|
243
|
+
config.project.rootFolder,
|
|
256
244
|
'shared-kernel'
|
|
257
245
|
])));
|
|
258
246
|
return [];
|
|
259
247
|
};
|
|
260
|
-
const inMemoryDbApplied = ()=>Boolean(ConfigFile.Instance.data.withInMemoryDb) && inMemoryDbScaffolded();
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
248
|
+
const inMemoryDbApplied = ()=>Boolean(ConfigFile.Instance.data.backend?.withInMemoryDb) && inMemoryDbScaffolded();
|
|
249
|
+
class RequestError extends Error {
|
|
250
|
+
code;
|
|
251
|
+
details;
|
|
252
|
+
constructor(code, message, details){
|
|
253
|
+
super(message), this.code = code, this.details = details;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const storage = new AsyncLocalStorage();
|
|
257
|
+
const isNonInteractive = ()=>Boolean(storage.getStore());
|
|
258
|
+
const runWithAnswers = async (answers, defaults, run)=>storage.run({
|
|
259
|
+
answers,
|
|
260
|
+
defaults,
|
|
261
|
+
used: new Set(),
|
|
262
|
+
messages: []
|
|
263
|
+
}, async ()=>{
|
|
264
|
+
const result = await run();
|
|
265
|
+
const state = storage.getStore();
|
|
266
|
+
assertAnswersConsumed();
|
|
267
|
+
return {
|
|
268
|
+
result,
|
|
269
|
+
messages: state.messages
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
const assertAnswersConsumed = ()=>{
|
|
273
|
+
const state = storage.getStore();
|
|
274
|
+
if (!state) return;
|
|
275
|
+
const unused = Object.keys(state.answers).filter((key)=>!state.used.has(key));
|
|
276
|
+
if (unused.length) throw new RequestError('UNUSED_PARAMETERS', 'Some parameters do not apply to this operation.', {
|
|
277
|
+
fields: unused
|
|
278
|
+
});
|
|
270
279
|
};
|
|
271
|
-
const
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
280
|
+
const answerFor = (key, fallback)=>{
|
|
281
|
+
const state = storage.getStore();
|
|
282
|
+
if (!state) return;
|
|
283
|
+
if (Object.hasOwn(state.answers, key)) {
|
|
284
|
+
state.used.add(key);
|
|
285
|
+
return state.answers[key];
|
|
286
|
+
}
|
|
287
|
+
return Object.hasOwn(state.defaults, key) ? state.defaults[key] : fallback;
|
|
288
|
+
};
|
|
289
|
+
const report = (...values)=>{
|
|
290
|
+
const state = storage.getStore();
|
|
291
|
+
if (state) state.messages.push(values.map(String).join(' '));
|
|
292
|
+
else console.log(...values);
|
|
293
|
+
};
|
|
294
|
+
const requireKey = (key)=>{
|
|
295
|
+
if (!key) throw new RequestError('UNSUPPORTED_PROMPT', 'This operation needs an answer that is not supported in non-interactive mode.');
|
|
296
|
+
return key;
|
|
297
|
+
};
|
|
298
|
+
const interaction_missing = (key)=>new RequestError('MISSING_PARAMETER', `Provide ${key}.`, {
|
|
299
|
+
field: key
|
|
300
|
+
});
|
|
301
|
+
const interaction_input = async (config)=>{
|
|
302
|
+
const { key, ...interactive } = config;
|
|
303
|
+
if (!isNonInteractive()) return input(interactive);
|
|
304
|
+
const field = requireKey(key);
|
|
305
|
+
const value = answerFor(field, config.default);
|
|
306
|
+
if ('string' != typeof value) throw interaction_missing(field);
|
|
307
|
+
const valid = await config.validate?.(value);
|
|
308
|
+
if (void 0 !== valid && true !== valid) throw new RequestError('INVALID_PARAMETER', 'string' == typeof valid ? valid : `Invalid ${field}.`, {
|
|
309
|
+
field
|
|
310
|
+
});
|
|
311
|
+
return value;
|
|
312
|
+
};
|
|
313
|
+
const interaction_confirm = async (config)=>{
|
|
314
|
+
const { key, requestRequired, ...interactive } = config;
|
|
315
|
+
if (!isNonInteractive()) return prompts_confirm(interactive);
|
|
316
|
+
const field = requireKey(key);
|
|
317
|
+
const value = answerFor(field, requestRequired ? void 0 : config.default ?? false);
|
|
318
|
+
if (void 0 === value) throw interaction_missing(field);
|
|
319
|
+
if ('boolean' != typeof value) throw new RequestError('INVALID_PARAMETER', `${field} must be a boolean.`, {
|
|
320
|
+
field
|
|
321
|
+
});
|
|
322
|
+
return value;
|
|
323
|
+
};
|
|
324
|
+
const choicesOf = (config)=>config.choices.filter((choice)=>!(choice instanceof Separator)).map((choice)=>'object' == typeof choice && null !== choice && 'value' in choice ? choice : {
|
|
325
|
+
value: choice
|
|
326
|
+
});
|
|
327
|
+
const choiceId = (choice, id)=>id?.(choice.value) ?? choice.value;
|
|
328
|
+
const resolveChoice = (value, choices, key, id)=>{
|
|
329
|
+
const matches = choices.filter((choice)=>Object.is(choice.value, value) || choiceId(choice, id) === value);
|
|
330
|
+
if (1 !== matches.length || matches[0].disabled) throw new RequestError('INVALID_CHOICE', `Invalid or unavailable choice for ${key}.`, {
|
|
331
|
+
field: key,
|
|
332
|
+
value,
|
|
333
|
+
choices: choices.filter((choice)=>!choice.disabled).map((choice)=>choiceId(choice, id))
|
|
334
|
+
});
|
|
335
|
+
return matches[0].value;
|
|
336
|
+
};
|
|
337
|
+
const interaction_select = async (config)=>{
|
|
338
|
+
const { key, id, ...interactive } = config;
|
|
339
|
+
if (!isNonInteractive()) return prompts_select(interactive);
|
|
340
|
+
const field = requireKey(key);
|
|
341
|
+
const value = answerFor(field, config.default);
|
|
342
|
+
if (void 0 === value) throw interaction_missing(field);
|
|
343
|
+
return resolveChoice(value, choicesOf(config), field, id);
|
|
344
|
+
};
|
|
345
|
+
const interaction_checkbox = async (config)=>{
|
|
346
|
+
const { key, id, ...interactive } = config;
|
|
347
|
+
if (!isNonInteractive()) return prompts_checkbox(interactive);
|
|
348
|
+
const field = requireKey(key);
|
|
349
|
+
const choices = choicesOf(config);
|
|
350
|
+
const values = answerFor(field, choices.filter((choice)=>choice.checked && !choice.disabled).map((choice)=>choice.value));
|
|
351
|
+
if (!Array.isArray(values)) throw new RequestError('INVALID_PARAMETER', `${field} must be an array.`, {
|
|
352
|
+
field
|
|
353
|
+
});
|
|
354
|
+
const selected = values.map((value)=>resolveChoice(value, choices, field, id));
|
|
355
|
+
if (new Set(selected).size !== selected.length) throw new RequestError('INVALID_PARAMETER', `Duplicate choices for ${field}.`, {
|
|
356
|
+
field
|
|
357
|
+
});
|
|
358
|
+
if (config.required && !selected.length) throw interaction_missing(field);
|
|
359
|
+
return selected;
|
|
278
360
|
};
|
|
279
|
-
const
|
|
361
|
+
const usesNext = ()=>ConfigFile.exists && ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
362
|
+
const nextAppFolder = (root)=>[
|
|
363
|
+
'app',
|
|
364
|
+
'src/app'
|
|
365
|
+
].find((folder)=>new Folder(node_path.join(root, folder)).exists) ?? 'app';
|
|
280
366
|
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
281
367
|
class NestedName {
|
|
282
368
|
folders;
|
|
@@ -311,16 +397,34 @@ export const ${ClassName}Page: FC<${ClassName}PageProps> = (props) => {
|
|
|
311
397
|
return ${body}
|
|
312
398
|
}
|
|
313
399
|
`.trim();
|
|
400
|
+
const nextRouteContent = (ClassName, pageImport)=>`
|
|
401
|
+
import { ${ClassName}Page } from '${pageImport}'
|
|
402
|
+
|
|
403
|
+
export default function Page() {
|
|
404
|
+
return <${ClassName}Page />
|
|
405
|
+
}
|
|
406
|
+
`.trim();
|
|
407
|
+
const scaffoldNextRoute = (name, pageFile)=>{
|
|
408
|
+
const root = new ProjectRoot().path;
|
|
409
|
+
const route = node_path.join(root, nextAppFolder(root), ...name.folders, name.folderName, 'page.tsx');
|
|
410
|
+
const relativeRoute = node_path.relative(root, route).split(node_path.sep).join('/');
|
|
411
|
+
const routeFile = new File(route);
|
|
412
|
+
if (routeFile.exists) return void report(`${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`);
|
|
413
|
+
routeFile.data = nextRouteContent(name.ClassName, relativeImport(route, pageFile.path.replace(/\.tsx$/, '')));
|
|
414
|
+
};
|
|
314
415
|
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
315
|
-
const name = await
|
|
416
|
+
const name = await interaction_input({
|
|
417
|
+
key: 'name',
|
|
316
418
|
message: 'Provide name (folders split by "/"):',
|
|
317
419
|
validate: NestedName.validate
|
|
318
420
|
});
|
|
319
|
-
const
|
|
320
|
-
|
|
421
|
+
const nestedName = new NestedName(name);
|
|
422
|
+
const { folders, ClassName, fileName } = nestedName;
|
|
423
|
+
const pageFile = presentationReactFolder.subitem([
|
|
321
424
|
'pages',
|
|
322
425
|
...folders
|
|
323
426
|
]).createFile(`${fileName}-page.tsx`, reactPageContent(ClassName));
|
|
427
|
+
if (usesNext()) scaffoldNextRoute(nestedName, pageFile);
|
|
324
428
|
};
|
|
325
429
|
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
326
430
|
const rootFolderSegments = (rootFolder)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n `).join('');
|
|
@@ -490,7 +594,8 @@ const addPackageScripts = async (file, additions)=>{
|
|
|
490
594
|
for (const [name, command] of Object.entries(additions)){
|
|
491
595
|
let target = name;
|
|
492
596
|
if (Object.hasOwn(scripts, name) && scripts[name] !== command) {
|
|
493
|
-
const action = await
|
|
597
|
+
const action = await interaction_select({
|
|
598
|
+
key: `scriptConflicts.${name}`,
|
|
494
599
|
message: `Script "${name}" already exists: ${scripts[name]}`,
|
|
495
600
|
choices: [
|
|
496
601
|
'Keep existing',
|
|
@@ -499,7 +604,8 @@ const addPackageScripts = async (file, additions)=>{
|
|
|
499
604
|
]
|
|
500
605
|
});
|
|
501
606
|
if ('Keep existing' === action) continue;
|
|
502
|
-
if ('Use another name' === action) target = await
|
|
607
|
+
if ('Use another name' === action) target = await interaction_input({
|
|
608
|
+
key: `scriptNames.${name}`,
|
|
503
609
|
message: "New script name:",
|
|
504
610
|
validate: (value)=>!/^[a-zA-Z0-9:_-]+$/.test(value) || Object.hasOwn(scripts, value) || Object.hasOwn(additions, value) ? "Enter an unused script name (letters, numbers, :, _, -)." : true
|
|
505
611
|
});
|
|
@@ -575,7 +681,7 @@ generateOpenAPI(${withExtractor ? 'handlers' : 'restHandlers'}, {
|
|
|
575
681
|
`;
|
|
576
682
|
};
|
|
577
683
|
const addOpenapi = async ()=>{
|
|
578
|
-
const { rootFolder } = ConfigFile.Instance.data;
|
|
684
|
+
const { rootFolder } = ConfigFile.Instance.data.project;
|
|
579
685
|
const root = new ProjectRoot().path;
|
|
580
686
|
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
581
687
|
const manifest = JSON.parse(manifestFile.data);
|
|
@@ -583,20 +689,24 @@ const addOpenapi = async ()=>{
|
|
|
583
689
|
...manifest.dependencies,
|
|
584
690
|
...manifest.devDependencies
|
|
585
691
|
};
|
|
586
|
-
const routePrefix = await
|
|
692
|
+
const routePrefix = await interaction_input({
|
|
693
|
+
key: 'routePrefix',
|
|
587
694
|
message: 'Route prefix the REST handlers are served under:',
|
|
588
695
|
default: '/api'
|
|
589
696
|
});
|
|
590
|
-
const outputPath = await
|
|
697
|
+
const outputPath = await interaction_input({
|
|
698
|
+
key: 'openapiPath',
|
|
591
699
|
message: 'OpenAPI document path:',
|
|
592
|
-
default: defaultOpenapiPath(
|
|
700
|
+
default: defaultOpenapiPath(usesNext()),
|
|
593
701
|
validate: (value)=>splitPath(value).length ? true : 'Path is required'
|
|
594
702
|
});
|
|
595
|
-
const withExtractor = await
|
|
703
|
+
const withExtractor = await interaction_confirm({
|
|
704
|
+
key: 'withExtractor',
|
|
596
705
|
message: "Fill operationId, summary and description from the endpoint logic TSDoc?",
|
|
597
706
|
default: true
|
|
598
707
|
});
|
|
599
|
-
const withSwaggerPage = ConfigFile.Instance.data.
|
|
708
|
+
const withSwaggerPage = Boolean(ConfigFile.Instance.data.frontend?.react) && await interaction_confirm({
|
|
709
|
+
key: 'swaggerPage',
|
|
600
710
|
message: 'Add a Swagger UI page?',
|
|
601
711
|
default: true
|
|
602
712
|
});
|
|
@@ -748,7 +858,8 @@ const openapiOutputPath = (root)=>{
|
|
|
748
858
|
return generator.data.match(/outputFile:\s*{\s*path:\s*'([^']+)'/)?.[1];
|
|
749
859
|
};
|
|
750
860
|
const addOrval = async ()=>{
|
|
751
|
-
const { rootFolder,
|
|
861
|
+
const { project: { rootFolder }, frontend } = ConfigFile.Instance.data;
|
|
862
|
+
const useReact = Boolean(frontend?.react);
|
|
752
863
|
const root = new ProjectRoot().path;
|
|
753
864
|
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
754
865
|
const manifest = JSON.parse(manifestFile.data);
|
|
@@ -756,14 +867,16 @@ const addOrval = async ()=>{
|
|
|
756
867
|
...manifest.dependencies,
|
|
757
868
|
...manifest.devDependencies
|
|
758
869
|
};
|
|
759
|
-
const withNext =
|
|
870
|
+
const withNext = usesNext();
|
|
760
871
|
const generatedOpenapiPath = openapiOutputPath(root);
|
|
761
|
-
const openapiPath = await
|
|
872
|
+
const openapiPath = await interaction_input({
|
|
873
|
+
key: 'openapiPath',
|
|
762
874
|
message: 'OpenAPI document path:',
|
|
763
875
|
default: generatedOpenapiPath ?? defaultOpenapiPath(withNext),
|
|
764
876
|
validate: (value)=>value.trim() ? true : 'Path is required'
|
|
765
877
|
});
|
|
766
|
-
const targets = useReact ? await
|
|
878
|
+
const targets = useReact ? await interaction_checkbox({
|
|
879
|
+
key: 'targets',
|
|
767
880
|
message: 'Generate:',
|
|
768
881
|
choices: [
|
|
769
882
|
{
|
|
@@ -949,6 +1062,34 @@ const addPlaywright = async ()=>{
|
|
|
949
1062
|
})
|
|
950
1063
|
];
|
|
951
1064
|
};
|
|
1065
|
+
const savedImplementations = (kind, purpose)=>[
|
|
1066
|
+
...new Set(ConfigFile.Instance.data.backend?.implementations?.[kind]?.[purpose] ?? [])
|
|
1067
|
+
];
|
|
1068
|
+
const rememberImplementation = (kind, purpose, label)=>{
|
|
1069
|
+
implementationLabelSchema.parse(label);
|
|
1070
|
+
const backend = ConfigFile.backend;
|
|
1071
|
+
const choices = {
|
|
1072
|
+
...backend.implementations
|
|
1073
|
+
};
|
|
1074
|
+
const group = choices[kind] ?? {
|
|
1075
|
+
primary: [],
|
|
1076
|
+
test: []
|
|
1077
|
+
};
|
|
1078
|
+
if (group[purpose].includes(label)) return;
|
|
1079
|
+
choices[kind] = {
|
|
1080
|
+
...group,
|
|
1081
|
+
[purpose]: [
|
|
1082
|
+
...group[purpose],
|
|
1083
|
+
label
|
|
1084
|
+
]
|
|
1085
|
+
};
|
|
1086
|
+
ConfigFile.update({
|
|
1087
|
+
backend: {
|
|
1088
|
+
...backend,
|
|
1089
|
+
implementations: choices
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
};
|
|
952
1093
|
const runtimePackages = [
|
|
953
1094
|
'@prisma/orm-postgres',
|
|
954
1095
|
'temporal-polyfill',
|
|
@@ -1026,32 +1167,30 @@ const addPrisma = async ()=>{
|
|
|
1026
1167
|
...manifest.dependencies,
|
|
1027
1168
|
...manifest.devDependencies
|
|
1028
1169
|
};
|
|
1029
|
-
const shared = node_path.resolve(root, config.rootFolder, 'shared-kernel');
|
|
1170
|
+
const shared = node_path.resolve(root, config.project.rootFolder, 'shared-kernel');
|
|
1030
1171
|
const prismaFolder = node_path.join(shared, 'infrastructure/prisma');
|
|
1031
1172
|
if (dependencies['@prisma/client'] || dependencies.prisma && !/^[~^]?8\./.test(dependencies.prisma) || dependencies['@prisma/orm-mongo'] || dependencies['@prisma/orm-sqlite'] || [
|
|
1032
1173
|
node_path.join(root, 'prisma/schema.prisma'),
|
|
1033
1174
|
node_path.join(prismaFolder, 'schema.prisma')
|
|
1034
1175
|
].some((filePath)=>new File(filePath).exists)) throw new Error('This preset adds Prisma 8 for PostgreSQL. Migrate the existing Prisma setup separately before using it.');
|
|
1035
|
-
const withService = await
|
|
1176
|
+
const withService = await interaction_confirm({
|
|
1177
|
+
key: 'withService',
|
|
1036
1178
|
message: 'Create the Prisma infrastructure service in the Shared Kernel?',
|
|
1037
1179
|
default: true
|
|
1038
1180
|
});
|
|
1039
|
-
const
|
|
1040
|
-
message: 'Use prisma as the default persistence implementation?',
|
|
1041
|
-
default: false
|
|
1042
|
-
});
|
|
1043
|
-
const selected = await addPackageScripts(manifestFile, prismaScripts(config.rootFolder));
|
|
1181
|
+
const selected = await addPackageScripts(manifestFile, prismaScripts(config.project.rootFolder));
|
|
1044
1182
|
stageFile(node_path.join(prismaFolder, 'prisma.config.ts'), prismaConfig);
|
|
1045
1183
|
const contract = new File(node_path.join(prismaFolder, 'contract.prisma'));
|
|
1046
1184
|
if (!contract.exists) contract.data = '// use prisma-8\n\n// Add your application models here before running prisma:emit.\n';
|
|
1047
1185
|
if (withService) {
|
|
1048
1186
|
stageFile(node_path.join(shared, 'infrastructure/services/prisma-infrastructure-service.ts'), prismaService);
|
|
1049
|
-
if (
|
|
1187
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) stageFile(node_path.join(shared, 'wiring/infrastructure-services/wire-prisma-infrastructure-service.ts'), prismaWiring);
|
|
1050
1188
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1189
|
+
for (const kind of [
|
|
1190
|
+
'repositories',
|
|
1191
|
+
'commands',
|
|
1192
|
+
'queries'
|
|
1193
|
+
])rememberImplementation(kind, 'primary', 'prisma');
|
|
1055
1194
|
const install = (packages, dev)=>{
|
|
1056
1195
|
const missing = packages.filter((name)=>!dependencies[name]);
|
|
1057
1196
|
return missing.length ? [
|
|
@@ -1111,12 +1250,16 @@ const groupedChoices = (items, suggested = [])=>{
|
|
|
1111
1250
|
];
|
|
1112
1251
|
};
|
|
1113
1252
|
const groupedPageSize = 20;
|
|
1114
|
-
const
|
|
1253
|
+
const dependencyOptions = (boundedContextFolder)=>{
|
|
1115
1254
|
const sharedFolder = new Folder(new ProjectRoot().path).subitem([
|
|
1116
|
-
ConfigFile.Instance.data.rootFolder,
|
|
1255
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
1117
1256
|
'shared-kernel'
|
|
1118
1257
|
]);
|
|
1119
1258
|
const isShared = sharedFolder.path === boundedContextFolder.path;
|
|
1259
|
+
const contextsFolder = new Folder(new ProjectRoot().path).subitem([
|
|
1260
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
1261
|
+
'bounded-contexts'
|
|
1262
|
+
]);
|
|
1120
1263
|
return [
|
|
1121
1264
|
...findWiredModules(boundedContextFolder.path).map((x)=>({
|
|
1122
1265
|
module: x,
|
|
@@ -1125,11 +1268,17 @@ const contextAndSharedModules = (boundedContextFolder)=>{
|
|
|
1125
1268
|
...isShared ? [] : findWiredModules(sharedFolder.path).map((x)=>({
|
|
1126
1269
|
module: x,
|
|
1127
1270
|
label: `${x.typeName} (shared-kernel)`
|
|
1128
|
-
}))
|
|
1271
|
+
})),
|
|
1272
|
+
...isShared ? [] : contextsFolder.content.subfolderNames.filter((name)=>name !== boundedContextFolder.name).sort().flatMap((name)=>findWiredModules(contextsFolder.subitem([
|
|
1273
|
+
name
|
|
1274
|
+
]).path).map((module)=>({
|
|
1275
|
+
module,
|
|
1276
|
+
label: `${module.typeName} (${name})`
|
|
1277
|
+
})))
|
|
1129
1278
|
];
|
|
1130
1279
|
};
|
|
1131
1280
|
const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations, customWiring)=>{
|
|
1132
|
-
const options =
|
|
1281
|
+
const options = dependencyOptions(boundedContextFolder);
|
|
1133
1282
|
let asked = false;
|
|
1134
1283
|
for (const implementation of implementations){
|
|
1135
1284
|
const available = availableDependencies(consumer, implementation, options.map((x)=>x.module));
|
|
@@ -1138,7 +1287,9 @@ const promptDependencies = async (boundedContextFolder, consumer, implementation
|
|
|
1138
1287
|
asked = true;
|
|
1139
1288
|
const type = wiring_implementationType(consumer, implementation);
|
|
1140
1289
|
const suggested = type ? candidates.filter((x)=>isSuggestedFor(x.module, type)) : [];
|
|
1141
|
-
const dependencies = await
|
|
1290
|
+
const dependencies = await interaction_checkbox({
|
|
1291
|
+
key: `dependencies.${implementation.className}`,
|
|
1292
|
+
id: (value)=>moduleId(value.module),
|
|
1142
1293
|
message: consumer.branched ? `Dependencies for ${implementation.className}:` : 'Dependencies:',
|
|
1143
1294
|
choices: groupedChoices(candidates, suggested),
|
|
1144
1295
|
pageSize: groupedPageSize,
|
|
@@ -1162,8 +1313,10 @@ const wireNewImplementationDependencies = async (boundedContextFolder, wireFile,
|
|
|
1162
1313
|
};
|
|
1163
1314
|
const wireDependency = async (boundedContextFolder)=>{
|
|
1164
1315
|
const modules = findWiredModules(boundedContextFolder.path);
|
|
1165
|
-
if (!modules.length) return void
|
|
1166
|
-
const { module: consumer, implementation } = await
|
|
1316
|
+
if (!modules.length) return void report('No wired modules here yet.');
|
|
1317
|
+
const { module: consumer, implementation } = await interaction_select({
|
|
1318
|
+
key: 'module',
|
|
1319
|
+
id: (value)=>`${moduleId(value.module)}:${value.implementation.className}`,
|
|
1167
1320
|
message: 'Module:',
|
|
1168
1321
|
choices: groupedChoices(modules.flatMap((x)=>x.implementations.map((implementation)=>{
|
|
1169
1322
|
const type = wiring_implementationType(x, implementation);
|
|
@@ -1178,7 +1331,7 @@ const wireDependency = async (boundedContextFolder)=>{
|
|
|
1178
1331
|
});
|
|
1179
1332
|
if (!await promptDependencies(boundedContextFolder, consumer, [
|
|
1180
1333
|
implementation
|
|
1181
|
-
]))
|
|
1334
|
+
])) report('No dependencies available for this module.');
|
|
1182
1335
|
};
|
|
1183
1336
|
const promptEndpointHandler = async (boundedContextFolder)=>{
|
|
1184
1337
|
const handlers = findWiredModules(boundedContextFolder.path).filter((x)=>[
|
|
@@ -1189,7 +1342,9 @@ const promptEndpointHandler = async (boundedContextFolder)=>{
|
|
|
1189
1342
|
module: x,
|
|
1190
1343
|
label: x.typeName
|
|
1191
1344
|
}));
|
|
1192
|
-
return handlers.length ? (await
|
|
1345
|
+
return handlers.length ? (await interaction_select({
|
|
1346
|
+
key: 'handler',
|
|
1347
|
+
id: (value)=>moduleId(value.module),
|
|
1193
1348
|
message: 'Handler:',
|
|
1194
1349
|
choices: groupedChoices(handlers),
|
|
1195
1350
|
pageSize: groupedPageSize,
|
|
@@ -1199,8 +1354,8 @@ const promptEndpointHandler = async (boundedContextFolder)=>{
|
|
|
1199
1354
|
const createPresentationService = (boundedContextFolder, name, classFile)=>{
|
|
1200
1355
|
const naming = new UnknownFormatNaming(name);
|
|
1201
1356
|
const className = `${naming.ClassName}PresentationService`;
|
|
1202
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
1203
|
-
const withWiring = ConfigFile.
|
|
1357
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
1358
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
1204
1359
|
const wiringFolder = boundedContextFolder.subitem([
|
|
1205
1360
|
'wiring',
|
|
1206
1361
|
'presentation-services'
|
|
@@ -1215,7 +1370,7 @@ export class ${className} {
|
|
|
1215
1370
|
}
|
|
1216
1371
|
`.trim());
|
|
1217
1372
|
if (scaffoldUnitTests) presentationServicesFolder.createFile(`${naming.fileName}-presentation-service.spec.ts`, `
|
|
1218
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
1373
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
1219
1374
|
${withWiring ? `import { type ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'
|
|
1220
1375
|
import { wire${naming.ClassName}PresentationService } from '../../wiring/presentation-services/wire-${naming.fileName}-presentation-service'` : `import { ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'`}
|
|
1221
1376
|
|
|
@@ -1242,7 +1397,8 @@ export const wire${naming.ClassName}PresentationService = wireClass(
|
|
|
1242
1397
|
`.trim());
|
|
1243
1398
|
};
|
|
1244
1399
|
const scaffoldNewPresentationService = async (boundedContextFolder)=>{
|
|
1245
|
-
const name = await
|
|
1400
|
+
const name = await interaction_input({
|
|
1401
|
+
key: 'name',
|
|
1246
1402
|
message: 'Name: '
|
|
1247
1403
|
});
|
|
1248
1404
|
const wireFile = createPresentationService(boundedContextFolder, name);
|
|
@@ -1282,10 +1438,6 @@ const findRestEndpointGenerator = (sharedFolder)=>{
|
|
|
1282
1438
|
wireFile: node_path.join(sharedFolder.path, 'wiring', 'presentation-services', `wire-${rest_endpoint_generator_name}-presentation-service.ts`)
|
|
1283
1439
|
};
|
|
1284
1440
|
};
|
|
1285
|
-
const nextAppFolder = (root)=>[
|
|
1286
|
-
'app',
|
|
1287
|
-
'src/app'
|
|
1288
|
-
].find((folder)=>new Folder(node_path.join(root, folder)).exists) ?? 'app';
|
|
1289
1441
|
const nextRoutePath = (root)=>node_path.posix.join(nextAppFolder(root), 'api/[...path]/route.ts');
|
|
1290
1442
|
const nextRoute = (restHandlersImport)=>`
|
|
1291
1443
|
import { nextEndpoints } from '@domain-first/handlers-next'
|
|
@@ -1303,8 +1455,9 @@ export const PUT = handler
|
|
|
1303
1455
|
export const PATCH = handler
|
|
1304
1456
|
export const DELETE = handler
|
|
1305
1457
|
`.trim();
|
|
1306
|
-
const
|
|
1307
|
-
const { rootFolder
|
|
1458
|
+
const rest_endpoint_generator_scaffoldNextRoute = (root)=>{
|
|
1459
|
+
const { rootFolder } = ConfigFile.Instance.data.project;
|
|
1460
|
+
const { domainFirstPackages } = ConfigFile.backend;
|
|
1308
1461
|
const routePath = nextRoutePath(root);
|
|
1309
1462
|
const routeFile = node_path.join(root, routePath);
|
|
1310
1463
|
if (new File(routeFile).exists) return [];
|
|
@@ -1322,20 +1475,21 @@ const scaffoldNextRoute = (root)=>{
|
|
|
1322
1475
|
`${routePath} serves restHandlers from ${node_path.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`
|
|
1323
1476
|
];
|
|
1324
1477
|
};
|
|
1325
|
-
const askNextAdapter = async ()=>
|
|
1326
|
-
|
|
1478
|
+
const askNextAdapter = async ({ nextSelected } = {})=>(nextSelected ?? usesNext()) && await interaction_confirm({
|
|
1479
|
+
key: 'nextAdapter',
|
|
1480
|
+
message: 'Use @domain-first/handlers-next for REST endpoints'
|
|
1327
1481
|
});
|
|
1328
1482
|
const scaffoldRestEndpointGeneratorFiles = ({ withNextAdapter })=>{
|
|
1329
1483
|
const root = new ProjectRoot().path;
|
|
1330
1484
|
const generatorExisted = restEndpointGeneratorApplied();
|
|
1331
1485
|
const routeNotes = withoutOverwrites(()=>{
|
|
1332
1486
|
scaffoldRestEndpointGenerator(new Folder(root).subitem([
|
|
1333
|
-
ConfigFile.Instance.data.rootFolder,
|
|
1487
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
1334
1488
|
'shared-kernel'
|
|
1335
1489
|
]), {
|
|
1336
1490
|
withNextAdapter
|
|
1337
1491
|
});
|
|
1338
|
-
return withNextAdapter ?
|
|
1492
|
+
return withNextAdapter ? rest_endpoint_generator_scaffoldNextRoute(root) : [];
|
|
1339
1493
|
});
|
|
1340
1494
|
if (!withNextAdapter) return [];
|
|
1341
1495
|
return [
|
|
@@ -1352,20 +1506,21 @@ const addRestEndpointGenerator = async ()=>scaffoldRestEndpointGeneratorFiles({
|
|
|
1352
1506
|
withNextAdapter: await askNextAdapter()
|
|
1353
1507
|
});
|
|
1354
1508
|
const restEndpointGeneratorApplied = ()=>Boolean(findRestEndpointGenerator(new Folder(new ProjectRoot().path).subitem([
|
|
1355
|
-
ConfigFile.Instance.data.rootFolder,
|
|
1509
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
1356
1510
|
'shared-kernel'
|
|
1357
1511
|
])));
|
|
1512
|
+
const storybookFrameworkPackage = '@storybook/react-vite';
|
|
1358
1513
|
const storybookFiles = (relativeProjectRoot)=>({
|
|
1359
1514
|
'main.ts': `import { resolve } from 'node:path';
|
|
1360
1515
|
import react from '@vitejs/plugin-react';
|
|
1361
|
-
import type { StorybookConfig } from '
|
|
1516
|
+
import type { StorybookConfig } from '${storybookFrameworkPackage}';
|
|
1362
1517
|
|
|
1363
1518
|
const projectRoot = resolve(import.meta.dirname, ${JSON.stringify(relativeProjectRoot)});
|
|
1364
1519
|
|
|
1365
1520
|
const config: StorybookConfig = {
|
|
1366
1521
|
stories: ['../**/*.mdx', '../**/*.stories.@(ts|tsx)'],
|
|
1367
1522
|
framework: {
|
|
1368
|
-
name: '
|
|
1523
|
+
name: '${storybookFrameworkPackage}',
|
|
1369
1524
|
options: {}
|
|
1370
1525
|
},
|
|
1371
1526
|
core: {
|
|
@@ -1387,7 +1542,7 @@ const config: StorybookConfig = {
|
|
|
1387
1542
|
|
|
1388
1543
|
export default config;
|
|
1389
1544
|
`,
|
|
1390
|
-
'preview.ts': `import type { Preview } from '
|
|
1545
|
+
'preview.ts': `import type { Preview } from '${storybookFrameworkPackage}';
|
|
1391
1546
|
|
|
1392
1547
|
const preview: Preview = {
|
|
1393
1548
|
parameters: {
|
|
@@ -1413,16 +1568,18 @@ const storybookScripts = (rootFolder)=>{
|
|
|
1413
1568
|
};
|
|
1414
1569
|
const addStorybook = async ()=>{
|
|
1415
1570
|
const config = ConfigFile.Instance.data;
|
|
1416
|
-
if ((!config.
|
|
1417
|
-
|
|
1571
|
+
if ((!config.frontend?.react || config.frontend?.react?.storybookFramework && config.frontend?.react?.storybookFramework !== storybookFrameworkPackage) && !await interaction_confirm({
|
|
1572
|
+
key: 'configureReact',
|
|
1573
|
+
requestRequired: true,
|
|
1574
|
+
message: `Configure React scaffolding with ${storybookFrameworkPackage}?`,
|
|
1418
1575
|
default: false
|
|
1419
1576
|
})) return [];
|
|
1420
1577
|
const root = new ProjectRoot().path;
|
|
1421
1578
|
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
1422
1579
|
const manifest = JSON.parse(manifestFile.data);
|
|
1423
|
-
const selected = await addPackageScripts(manifestFile, storybookScripts(config.rootFolder));
|
|
1580
|
+
const selected = await addPackageScripts(manifestFile, storybookScripts(config.project.rootFolder));
|
|
1424
1581
|
const folder = new Folder(root).subitem([
|
|
1425
|
-
config.rootFolder,
|
|
1582
|
+
config.project.rootFolder,
|
|
1426
1583
|
'presentation',
|
|
1427
1584
|
'react',
|
|
1428
1585
|
'.storybook'
|
|
@@ -1431,12 +1588,16 @@ const addStorybook = async ()=>{
|
|
|
1431
1588
|
const file = new File(node_path.join(folder.path, name));
|
|
1432
1589
|
if (!file.exists || file.data !== content) file.data = content;
|
|
1433
1590
|
}
|
|
1434
|
-
if (!config.
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1591
|
+
if (!config.frontend?.react || config.frontend?.react?.storybookFramework !== storybookFrameworkPackage) ConfigFile.update({
|
|
1592
|
+
frontend: {
|
|
1593
|
+
...config.frontend,
|
|
1594
|
+
react: {
|
|
1595
|
+
...config.frontend?.react,
|
|
1596
|
+
storybookFramework: storybookFrameworkPackage
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1438
1599
|
});
|
|
1439
|
-
const buildFolder = node_path.posix.join(config.rootFolder.replaceAll('\\', '/'), 'presentation/react/storybook-static');
|
|
1600
|
+
const buildFolder = node_path.posix.join(config.project.rootFolder.replaceAll('\\', '/'), 'presentation/react/storybook-static');
|
|
1440
1601
|
addGitignoreEntry(root, `/${buildFolder}/`);
|
|
1441
1602
|
const dependencies = {
|
|
1442
1603
|
...manifest.dependencies,
|
|
@@ -1444,7 +1605,7 @@ const addStorybook = async ()=>{
|
|
|
1444
1605
|
};
|
|
1445
1606
|
const missing = [
|
|
1446
1607
|
'storybook',
|
|
1447
|
-
|
|
1608
|
+
storybookFrameworkPackage,
|
|
1448
1609
|
'vite',
|
|
1449
1610
|
'@vitejs/plugin-react'
|
|
1450
1611
|
].filter((name)=>!dependencies[name]);
|
|
@@ -1465,6 +1626,57 @@ const addStorybook = async ()=>{
|
|
|
1465
1626
|
})
|
|
1466
1627
|
];
|
|
1467
1628
|
};
|
|
1629
|
+
const defaultEnvBranches = {
|
|
1630
|
+
names: [
|
|
1631
|
+
'test',
|
|
1632
|
+
'development',
|
|
1633
|
+
'production'
|
|
1634
|
+
],
|
|
1635
|
+
test: 'test'
|
|
1636
|
+
};
|
|
1637
|
+
const wire_branches_envBranches = ()=>{
|
|
1638
|
+
const configured = ConfigFile.exists ? ConfigFile.Instance.data.backend?.envBranches : void 0;
|
|
1639
|
+
const { names, test } = configured ?? defaultEnvBranches;
|
|
1640
|
+
return {
|
|
1641
|
+
names,
|
|
1642
|
+
test,
|
|
1643
|
+
primary: names.filter((name)=>name !== test),
|
|
1644
|
+
custom: Boolean(configured)
|
|
1645
|
+
};
|
|
1646
|
+
};
|
|
1647
|
+
const offersTestImplementation = ()=>{
|
|
1648
|
+
const backend = ConfigFile.exists ? ConfigFile.Instance.data.backend : void 0;
|
|
1649
|
+
return !(backend?.domainFirstPackages.includes('@domain-first/wire') && backend.envBranches && void 0 === backend.envBranches.test);
|
|
1650
|
+
};
|
|
1651
|
+
const envBranchedWireArgument = (testWire, primaryWire)=>{
|
|
1652
|
+
const { test, primary } = wire_branches_envBranches();
|
|
1653
|
+
return `{\n${[
|
|
1654
|
+
...test ? [
|
|
1655
|
+
` ${test}: ${testWire}`
|
|
1656
|
+
] : [],
|
|
1657
|
+
...primary.map((name)=>` ${name}: ${primaryWire}`)
|
|
1658
|
+
].join(',\n')}\n}`;
|
|
1659
|
+
};
|
|
1660
|
+
const envBranchedWireSource = ()=>{
|
|
1661
|
+
const { names, custom } = wire_branches_envBranches();
|
|
1662
|
+
if (!custom) return `import { branchedWire } from '@domain-first/wire'
|
|
1663
|
+
|
|
1664
|
+
export const envBranchedWire = branchedWire(() => {
|
|
1665
|
+
return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
|
|
1666
|
+
});`;
|
|
1667
|
+
return `import { branchedWire } from '@domain-first/wire'
|
|
1668
|
+
|
|
1669
|
+
export type EnvBranch = ${names.map((name)=>`'${name}'`).join(' | ')}
|
|
1670
|
+
|
|
1671
|
+
/**
|
|
1672
|
+
* The branch this process runs in. Write how it is selected:
|
|
1673
|
+
* until then, this function doesn't compile.
|
|
1674
|
+
*/
|
|
1675
|
+
const currentBranch = (): EnvBranch => {
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
export const envBranchedWire = branchedWire(currentBranch)`;
|
|
1679
|
+
};
|
|
1468
1680
|
const integrationFolder = 'specs/integration';
|
|
1469
1681
|
const testcontainersScripts = {
|
|
1470
1682
|
'test:integration': `vitest run --config ${integrationFolder}/vitest.config.ts --reporter=dot --silent=passed-only`
|
|
@@ -1598,8 +1810,8 @@ const addTestcontainers = async ()=>{
|
|
|
1598
1810
|
...manifest.devDependencies
|
|
1599
1811
|
};
|
|
1600
1812
|
const selected = await addPackageScripts(manifestFile, testcontainersScripts);
|
|
1601
|
-
const withPrisma = new File(node_path.resolve(root, config.rootFolder, 'shared-kernel/infrastructure/prisma/prisma.config.ts')).exists;
|
|
1602
|
-
const migrationCommand = withPrisma ? `npx ${prismaScripts(config.rootFolder)['prisma:migration:apply'].replace(' --advance-ref db', '')}` : void 0;
|
|
1813
|
+
const withPrisma = new File(node_path.resolve(root, config.project.rootFolder, 'shared-kernel/infrastructure/prisma/prisma.config.ts')).exists;
|
|
1814
|
+
const migrationCommand = withPrisma ? `npx ${prismaScripts(config.project.rootFolder)['prisma:migration:apply'].replace(' --advance-ref db', '')}` : void 0;
|
|
1603
1815
|
const folder = node_path.join(root, integrationFolder);
|
|
1604
1816
|
testcontainers_stageFile(node_path.join(folder, 'vitest.config.ts'), testcontainersVitestConfig(Boolean(dependencies['@domain-first/handlers-next'])));
|
|
1605
1817
|
testcontainers_stageFile(node_path.join(folder, 'global-setup.ts'), testcontainersGlobalSetup(migrationCommand));
|
|
@@ -1631,6 +1843,9 @@ const addTestcontainers = async ()=>{
|
|
|
1631
1843
|
...excludedFromUnitTests ? [] : [
|
|
1632
1844
|
`Add '${integrationFolder}/**' to test.exclude in vitest.config.ts, so unit tests skip integration specs.`
|
|
1633
1845
|
],
|
|
1846
|
+
...wire_branches_envBranches().custom ? [
|
|
1847
|
+
`${integrationFolder} runs with NODE_ENV=development and ${integrationFolder}/setup-env.ts requires it, but your envBranchedWire branches are custom: make currentBranch in shared-kernel/wiring/env-branched-wire.ts return the branch for integration specs, and adjust setup-env.ts.`
|
|
1848
|
+
] : [],
|
|
1634
1849
|
'Docker must be running for integration specs.',
|
|
1635
1850
|
...describeScripts(selected, {
|
|
1636
1851
|
'test:integration': `run integration specs from ${integrationFolder} against PostgreSQL in a container`
|
|
@@ -1678,8 +1893,10 @@ export default defineConfig({
|
|
|
1678
1893
|
};
|
|
1679
1894
|
const addVitest = async ()=>{
|
|
1680
1895
|
const config = ConfigFile.Instance.data;
|
|
1681
|
-
if (
|
|
1682
|
-
|
|
1896
|
+
if (ConfigFile.backend.testingLibrary && 'vitest' !== ConfigFile.backend.testingLibrary && !await interaction_confirm({
|
|
1897
|
+
key: 'replaceTestingLibrary',
|
|
1898
|
+
requestRequired: true,
|
|
1899
|
+
message: `Replace testing library "${ConfigFile.backend.testingLibrary}" with vitest for generated tests?`,
|
|
1683
1900
|
default: false
|
|
1684
1901
|
})) return [];
|
|
1685
1902
|
const root = new ProjectRoot().path;
|
|
@@ -1691,11 +1908,13 @@ const addVitest = async ()=>{
|
|
|
1691
1908
|
};
|
|
1692
1909
|
const selected = await addPackageScripts(manifestFile, vitestScripts);
|
|
1693
1910
|
const configFile = new File(node_path.join(root, 'vitest.config.ts'));
|
|
1694
|
-
const content = vitestConfig(config.rootFolder, Boolean(dependencies['@domain-first/handlers-next']));
|
|
1911
|
+
const content = vitestConfig(config.project.rootFolder, Boolean(dependencies['@domain-first/handlers-next']));
|
|
1695
1912
|
if (!configFile.exists || configFile.data !== content) configFile.data = content;
|
|
1696
|
-
if ('vitest' !==
|
|
1697
|
-
|
|
1698
|
-
|
|
1913
|
+
if ('vitest' !== ConfigFile.backend.testingLibrary) ConfigFile.update({
|
|
1914
|
+
backend: {
|
|
1915
|
+
...ConfigFile.backend,
|
|
1916
|
+
testingLibrary: 'vitest'
|
|
1917
|
+
}
|
|
1699
1918
|
});
|
|
1700
1919
|
addGitignoreEntry(root, '/coverage/');
|
|
1701
1920
|
const missing = [
|
|
@@ -1761,17 +1980,56 @@ const printNextSteps = (nextSteps)=>{
|
|
|
1761
1980
|
].join('\n'));
|
|
1762
1981
|
if (sections.length) console.log(sections.join('\n\n'));
|
|
1763
1982
|
};
|
|
1764
|
-
const
|
|
1983
|
+
const savePendingChanges = async ()=>{
|
|
1984
|
+
assertAnswersConsumed();
|
|
1985
|
+
const overwrittenFiles = filesToOverwrite({
|
|
1986
|
+
changedOnly: isNonInteractive()
|
|
1987
|
+
});
|
|
1988
|
+
if (isNonInteractive() && overwrittenFiles.length && !answerFor('overwrite', false)) throw new RequestError('OVERWRITE_REQUIRED', 'Set overwrite to true to replace existing files.', {
|
|
1989
|
+
files: overwrittenFiles.map((file)=>node_path.relative(new ProjectRoot().path, file).split(node_path.sep).join('/'))
|
|
1990
|
+
});
|
|
1991
|
+
if (overwrittenFiles.length) {
|
|
1992
|
+
const root = new ProjectRoot().path;
|
|
1993
|
+
report('These files already exist and will be overwritten:');
|
|
1994
|
+
for (const filePath of overwrittenFiles)report(` ${node_path.relative(root, filePath)}`);
|
|
1995
|
+
const overwrite = await interaction_confirm({
|
|
1996
|
+
key: 'overwrite',
|
|
1997
|
+
message: 'Overwrite them?',
|
|
1998
|
+
default: false
|
|
1999
|
+
});
|
|
2000
|
+
if (!overwrite) {
|
|
2001
|
+
discardPendingChanges();
|
|
2002
|
+
report('Cancelled: nothing was written.');
|
|
2003
|
+
return false;
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
writePendingChanges();
|
|
2007
|
+
return true;
|
|
2008
|
+
};
|
|
2009
|
+
const withHandlersRest = ()=>ConfigFile.Instance.data.backend?.domainFirstPackages.includes('@domain-first/handlers-rest') ?? false;
|
|
1765
2010
|
const created = (...segments)=>new File(node_path.join(new ProjectRoot().path, ...segments)).exists;
|
|
1766
|
-
const createdInRoot = (...segments)=>created(ConfigFile.Instance.data.rootFolder, ...segments);
|
|
2011
|
+
const createdInRoot = (...segments)=>created(ConfigFile.Instance.data.project.rootFolder, ...segments);
|
|
2012
|
+
const integrationIds = [
|
|
2013
|
+
'storybook',
|
|
2014
|
+
'rest-endpoint-generator',
|
|
2015
|
+
'in-memory-db',
|
|
2016
|
+
'prisma',
|
|
2017
|
+
'vitest',
|
|
2018
|
+
'playwright',
|
|
2019
|
+
'testcontainers',
|
|
2020
|
+
'openapi',
|
|
2021
|
+
'orval'
|
|
2022
|
+
];
|
|
1767
2023
|
const integrations = [
|
|
1768
2024
|
{
|
|
2025
|
+
id: 'storybook',
|
|
1769
2026
|
name: 'Storybook (React + Vite)',
|
|
1770
2027
|
group: 'frontend',
|
|
1771
2028
|
run: addStorybook,
|
|
1772
2029
|
applied: ()=>createdInRoot('presentation/react/.storybook/main.ts')
|
|
1773
2030
|
},
|
|
1774
2031
|
{
|
|
2032
|
+
id: 'rest-endpoint-generator',
|
|
1775
2033
|
name: 'REST endpoint generator',
|
|
1776
2034
|
group: 'backend',
|
|
1777
2035
|
run: addRestEndpointGenerator,
|
|
@@ -1779,36 +2037,42 @@ const integrations = [
|
|
|
1779
2037
|
applied: restEndpointGeneratorApplied
|
|
1780
2038
|
},
|
|
1781
2039
|
{
|
|
2040
|
+
id: 'in-memory-db',
|
|
1782
2041
|
name: 'In-memory DB',
|
|
1783
2042
|
group: 'backend',
|
|
1784
2043
|
run: addInMemoryDb,
|
|
1785
2044
|
applied: inMemoryDbApplied
|
|
1786
2045
|
},
|
|
1787
2046
|
{
|
|
2047
|
+
id: 'prisma',
|
|
1788
2048
|
name: 'Prisma 8 (PostgreSQL, RC)',
|
|
1789
2049
|
group: 'backend',
|
|
1790
2050
|
run: addPrisma,
|
|
1791
2051
|
applied: ()=>createdInRoot('shared-kernel/infrastructure/prisma/prisma.config.ts')
|
|
1792
2052
|
},
|
|
1793
2053
|
{
|
|
2054
|
+
id: 'vitest',
|
|
1794
2055
|
name: 'Vitest',
|
|
1795
2056
|
group: 'backend',
|
|
1796
2057
|
run: addVitest,
|
|
1797
2058
|
applied: ()=>created('vitest.config.ts')
|
|
1798
2059
|
},
|
|
1799
2060
|
{
|
|
2061
|
+
id: 'playwright',
|
|
1800
2062
|
name: 'Playwright',
|
|
1801
2063
|
group: 'frontend',
|
|
1802
2064
|
run: addPlaywright,
|
|
1803
2065
|
applied: ()=>created('playwright.config.ts')
|
|
1804
2066
|
},
|
|
1805
2067
|
{
|
|
2068
|
+
id: 'testcontainers',
|
|
1806
2069
|
name: 'Integration tests (Testcontainers, PostgreSQL)',
|
|
1807
2070
|
group: 'backend',
|
|
1808
2071
|
run: addTestcontainers,
|
|
1809
2072
|
applied: ()=>created('specs/integration/vitest.config.ts')
|
|
1810
2073
|
},
|
|
1811
2074
|
{
|
|
2075
|
+
id: 'openapi',
|
|
1812
2076
|
name: 'OpenAPI',
|
|
1813
2077
|
group: 'backend',
|
|
1814
2078
|
run: addOpenapi,
|
|
@@ -1816,6 +2080,7 @@ const integrations = [
|
|
|
1816
2080
|
applied: ()=>created(openapiScriptPath)
|
|
1817
2081
|
},
|
|
1818
2082
|
{
|
|
2083
|
+
id: 'orval',
|
|
1819
2084
|
name: 'Orval (API client)',
|
|
1820
2085
|
group: 'frontend',
|
|
1821
2086
|
run: addOrval,
|
|
@@ -1823,8 +2088,8 @@ const integrations = [
|
|
|
1823
2088
|
applied: ()=>createdInRoot('presentation/react/data-layer/orval.config.ts') || createdInRoot('presentation/data-layer/orval.config.ts')
|
|
1824
2089
|
}
|
|
1825
2090
|
];
|
|
1826
|
-
const addIntegration = async ()=>{
|
|
1827
|
-
const available = integrations.filter(({ available })=>available?.() ?? true).map((value)=>({
|
|
2091
|
+
const addIntegration = async ({ save = true } = {})=>{
|
|
2092
|
+
const available = integrations.filter(({ group, available })=>('backend' !== group || Boolean(ConfigFile.Instance.data.backend)) && (available?.() ?? true)).map((value)=>({
|
|
1828
2093
|
value,
|
|
1829
2094
|
applied: value.applied()
|
|
1830
2095
|
}));
|
|
@@ -1845,88 +2110,24 @@ const addIntegration = async ()=>{
|
|
|
1845
2110
|
...section('New integrations', false),
|
|
1846
2111
|
...section('Already applied (select to reapply)', true)
|
|
1847
2112
|
];
|
|
1848
|
-
const selected = await
|
|
2113
|
+
const selected = await interaction_checkbox({
|
|
2114
|
+
key: 'integrations',
|
|
2115
|
+
id: (integration)=>integration.id,
|
|
1849
2116
|
message: 'Integrations:',
|
|
1850
2117
|
choices,
|
|
1851
2118
|
pageSize: choices.length
|
|
1852
2119
|
});
|
|
1853
2120
|
const nextSteps = [];
|
|
1854
2121
|
for (const integration of integrations.filter((value)=>selected.includes(value)))nextSteps.push(...await integration.run());
|
|
1855
|
-
if (await savePendingChanges()) printNextSteps(nextSteps);
|
|
1856
|
-
};
|
|
1857
|
-
const initializeUseCase = async ()=>{
|
|
1858
|
-
const rootFolderName = await input({
|
|
1859
|
-
message: 'Root folder (use "/" for inner folders):',
|
|
1860
|
-
default: 'src'
|
|
1861
|
-
});
|
|
1862
|
-
const domainFirstPackages = await prompts_checkbox({
|
|
1863
|
-
message: '@domain-first packages',
|
|
1864
|
-
choices: [
|
|
1865
|
-
'@domain-first/types',
|
|
1866
|
-
'@domain-first/errors',
|
|
1867
|
-
'@domain-first/handlers',
|
|
1868
|
-
'@domain-first/wire',
|
|
1869
|
-
'@domain-first/handlers-rest'
|
|
1870
|
-
]
|
|
1871
|
-
});
|
|
1872
|
-
const withNextAdapter = domainFirstPackages.includes('@domain-first/handlers-rest') && await askNextAdapter();
|
|
1873
|
-
const defaultPersistenceLayerImplementation = await input({
|
|
1874
|
-
message: 'Default persistence layer implementation:'
|
|
1875
|
-
});
|
|
1876
|
-
const withInMemoryDb = await prompts_confirm({
|
|
1877
|
-
message: 'Scaffold in-memory DB for test implementations'
|
|
1878
|
-
});
|
|
1879
|
-
const useReact = await prompts_confirm({
|
|
1880
|
-
message: 'Use React'
|
|
1881
|
-
});
|
|
1882
|
-
let storybookFramework;
|
|
1883
|
-
const withStorybook = useReact ? await prompts_confirm({
|
|
1884
|
-
message: 'Use Storybook'
|
|
1885
|
-
}) : false;
|
|
1886
|
-
if (withStorybook) storybookFramework = await input({
|
|
1887
|
-
message: 'Storybook framework package:',
|
|
1888
|
-
default: '@storybook/react-vite'
|
|
1889
|
-
});
|
|
1890
|
-
let testingLibrary;
|
|
1891
|
-
const withTests = await prompts_confirm({
|
|
1892
|
-
message: 'Scaffold unit tests'
|
|
1893
|
-
});
|
|
1894
|
-
if (withTests) testingLibrary = await input({
|
|
1895
|
-
message: 'Unit testing library:',
|
|
1896
|
-
default: 'vitest'
|
|
1897
|
-
});
|
|
1898
|
-
ConfigFile.write({
|
|
1899
|
-
rootFolder: rootFolderName,
|
|
1900
|
-
domainFirstPackages,
|
|
1901
|
-
defaultPersistenceLayerImplementation,
|
|
1902
|
-
withInMemoryDb,
|
|
1903
|
-
useReact,
|
|
1904
|
-
storybookFramework,
|
|
1905
|
-
testingLibrary
|
|
1906
|
-
});
|
|
1907
|
-
const { path } = new ProjectRoot();
|
|
1908
|
-
const rootFolder = new Folder(path);
|
|
1909
|
-
if (domainFirstPackages.includes('@domain-first/wire')) rootFolder.subitem([
|
|
1910
|
-
rootFolderName,
|
|
1911
|
-
'shared-kernel',
|
|
1912
|
-
'wiring'
|
|
1913
|
-
]).createFile('env-branched-wire.ts', `
|
|
1914
|
-
import { branchedWire } from '@domain-first/wire'
|
|
1915
|
-
|
|
1916
|
-
export const envBranchedWire = branchedWire(() => {
|
|
1917
|
-
return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
|
|
1918
|
-
});
|
|
1919
|
-
`.trim());
|
|
1920
|
-
if (withInMemoryDb) scaffoldInMemoryDb(rootFolder.subitem([
|
|
1921
|
-
rootFolderName,
|
|
1922
|
-
'shared-kernel'
|
|
1923
|
-
]));
|
|
1924
|
-
const nextSteps = missingDomainFirstPackages();
|
|
1925
|
-
if (domainFirstPackages.includes('@domain-first/handlers-rest')) nextSteps.push(...scaffoldRestEndpointGeneratorFiles({
|
|
1926
|
-
withNextAdapter
|
|
1927
|
-
}));
|
|
2122
|
+
if (save && await savePendingChanges()) printNextSteps(nextSteps);
|
|
1928
2123
|
return nextSteps;
|
|
1929
2124
|
};
|
|
2125
|
+
const integrationDescriptions = ()=>integrations.map((integration)=>({
|
|
2126
|
+
id: integration.id,
|
|
2127
|
+
name: integration.name,
|
|
2128
|
+
group: integration.group,
|
|
2129
|
+
available: ('backend' !== integration.group || Boolean(ConfigFile.Instance.data.backend)) && (integration.available?.() ?? true)
|
|
2130
|
+
}));
|
|
1930
2131
|
const ignoredFolders = new Set([
|
|
1931
2132
|
'node_modules',
|
|
1932
2133
|
'.git',
|
|
@@ -2248,7 +2449,7 @@ const isolationAllows = (rootFolderPath, from, to)=>{
|
|
|
2248
2449
|
const fromOwner = ownerOf(rootFolderPath, from);
|
|
2249
2450
|
const toOwner = ownerOf(rootFolderPath, to);
|
|
2250
2451
|
if (!fromOwner || !toOwner?.context) return true;
|
|
2251
|
-
if (fromOwner.context) return fromOwner.context === toOwner.context;
|
|
2452
|
+
if (fromOwner.context) return fromOwner.context === toOwner.context || true === crossContextImportAllowed(from, to);
|
|
2252
2453
|
const inside = (folder)=>to === node_path.join(toOwner.path, folder) || to.startsWith(node_path.join(toOwner.path, folder) + node_path.sep);
|
|
2253
2454
|
return inside('domain/errors') || from.replace(codeExtension, '') === inMemoryDbFile(rootFolderPath).replace(codeExtension, '') && inside('domain');
|
|
2254
2455
|
};
|
|
@@ -2395,92 +2596,140 @@ const projectRelative = (fromFile, toFile)=>{
|
|
|
2395
2596
|
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toFile.replace(codeExtension, '')));
|
|
2396
2597
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
2397
2598
|
};
|
|
2398
|
-
const
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
...contexts,
|
|
2426
|
-
...kindLayouts[unit.kind].sharedKernel ? [
|
|
2427
|
-
sharedKernelPath
|
|
2428
|
-
] : []
|
|
2429
|
-
].filter((place, index, all)=>all.indexOf(place) === index);
|
|
2430
|
-
const ownerPath = await prompts_select({
|
|
2431
|
-
message: 'Move to:',
|
|
2432
|
-
choices: places.map((value)=>({
|
|
2433
|
-
name: value === unit.ownerPath ? `${placeName(value)} (stays)` : placeName(value),
|
|
2434
|
-
value
|
|
2435
|
-
}))
|
|
2436
|
-
});
|
|
2437
|
-
let aggregate;
|
|
2438
|
-
const aggregates = ownerPath === sharedKernelPath ? [] : aggregatesOf(ownerPath);
|
|
2439
|
-
if (('entity' === unit.kind || 'value-object' === unit.kind) && aggregates.length) {
|
|
2440
|
-
const picked = await prompts_select({
|
|
2441
|
-
message: 'Aggregate:',
|
|
2442
|
-
choices: [
|
|
2443
|
-
noAggregate,
|
|
2444
|
-
...aggregates
|
|
2445
|
-
],
|
|
2446
|
-
default: ownerPath === unit.ownerPath && unit.aggregate ? unit.aggregate : noAggregate
|
|
2447
|
-
});
|
|
2448
|
-
aggregate = picked === noAggregate ? void 0 : picked;
|
|
2599
|
+
const contractKinds = [
|
|
2600
|
+
'aggregate',
|
|
2601
|
+
'command',
|
|
2602
|
+
'query',
|
|
2603
|
+
'port'
|
|
2604
|
+
];
|
|
2605
|
+
const implementations_withWiring = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
2606
|
+
const withHandlers = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers');
|
|
2607
|
+
const contractFile = (unit)=>'aggregate' === unit.kind ? `domain/aggregates/${unit.name}/${unit.name}-repository.ts` : kindLayouts[unit.kind].files(unit, [])[0];
|
|
2608
|
+
const findContracts = (ownerPath)=>findBackendUnits(ownerPath).filter((unit)=>contractKinds.includes(unit.kind) && node_fs.existsSync(node_path.join(ownerPath, contractFile(unit))));
|
|
2609
|
+
const implementationWireName = (label)=>`wire${new UnknownFormatNaming(label).ClassName}Implementation`;
|
|
2610
|
+
const contractClassName = (unit)=>kindLayouts[unit.kind].core(new UnknownFormatNaming(unit.name).ClassName);
|
|
2611
|
+
const implementationClassName = (unit, label)=>`${new UnknownFormatNaming(label).ClassName}${contractClassName(unit)}`;
|
|
2612
|
+
const implementationFile = (unit, label)=>{
|
|
2613
|
+
const { implementations } = kindLayouts[unit.kind];
|
|
2614
|
+
return kindLayouts[unit.kind].files(unit, [
|
|
2615
|
+
label
|
|
2616
|
+
]).find((file)=>file.startsWith(`${implementations}/`));
|
|
2617
|
+
};
|
|
2618
|
+
const contractWireFile = (unit)=>kindLayouts[unit.kind].files(unit, []).find((file)=>file.startsWith('wiring/'));
|
|
2619
|
+
const handlerImplementation = (ContractName, ClassName, contractImport)=>withHandlers() ? `
|
|
2620
|
+
import { defineHandler } from '@domain-first/handlers'
|
|
2621
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2622
|
+
|
|
2623
|
+
export class ${ClassName} extends ${ContractName} {
|
|
2624
|
+
constructor() {
|
|
2625
|
+
super()
|
|
2449
2626
|
}
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
].join('\n'));
|
|
2466
|
-
const relative = (file)=>node_path.relative(root, file);
|
|
2467
|
-
console.log([
|
|
2468
|
-
'Files to move:',
|
|
2469
|
-
...result.moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
2470
|
-
...result.updated.length ? [
|
|
2471
|
-
'Files with updated imports and names:',
|
|
2472
|
-
...result.updated.map((file)=>` ${relative(file)}`)
|
|
2473
|
-
] : []
|
|
2474
|
-
].join('\n'));
|
|
2475
|
-
if (!await prompts_confirm({
|
|
2476
|
-
message: 'Apply?',
|
|
2477
|
-
default: true
|
|
2478
|
-
})) {
|
|
2479
|
-
discardPendingChanges();
|
|
2480
|
-
console.log('Cancelled: nothing was written.');
|
|
2627
|
+
|
|
2628
|
+
handle = defineHandler({
|
|
2629
|
+
inputSchema: ${ContractName}.inputSchema,
|
|
2630
|
+
outputSchema: ${ContractName}.outputSchema,
|
|
2631
|
+
handler: async (input) => {
|
|
2632
|
+
return {}
|
|
2633
|
+
}
|
|
2634
|
+
})
|
|
2635
|
+
}
|
|
2636
|
+
`.trim() : `
|
|
2637
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2638
|
+
|
|
2639
|
+
export class ${ClassName} extends ${ContractName} {
|
|
2640
|
+
constructor() {
|
|
2641
|
+
super()
|
|
2481
2642
|
}
|
|
2482
|
-
}
|
|
2483
|
-
|
|
2643
|
+
}
|
|
2644
|
+
`.trim();
|
|
2645
|
+
const createImplementation = (ownerFolder, unit, label)=>{
|
|
2646
|
+
const naming = new UnknownFormatNaming(unit.name);
|
|
2647
|
+
const ContractName = contractClassName(unit);
|
|
2648
|
+
const className = implementationClassName(unit, label);
|
|
2649
|
+
const [folder, fileName] = [
|
|
2650
|
+
node_path.dirname(implementationFile(unit, label)),
|
|
2651
|
+
node_path.basename(implementationFile(unit, label))
|
|
2652
|
+
];
|
|
2653
|
+
const implementationFolder = ownerFolder.subitem(folder.split('/'));
|
|
2654
|
+
const inMemoryDb = !implementations_withWiring() && usesInMemoryDb(label);
|
|
2655
|
+
switch(unit.kind){
|
|
2656
|
+
case 'aggregate':
|
|
2657
|
+
{
|
|
2658
|
+
const contractImport = `../../../domain/aggregates/${unit.name}`;
|
|
2659
|
+
if (inMemoryDb) {
|
|
2660
|
+
const section = addInMemoryDbSection(naming, ownerFolder.subitem([
|
|
2661
|
+
'domain',
|
|
2662
|
+
'aggregates',
|
|
2663
|
+
unit.name
|
|
2664
|
+
]).path);
|
|
2665
|
+
const file = implementationFolder.createFile(fileName, `
|
|
2666
|
+
${inMemoryDbTypeImport(implementationFolder.subitem([
|
|
2667
|
+
fileName
|
|
2668
|
+
]).path)}
|
|
2669
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2670
|
+
|
|
2671
|
+
export class ${className} implements ${ContractName} {
|
|
2672
|
+
${inMemoryDbSectionMembers(section, false)}
|
|
2673
|
+
}
|
|
2674
|
+
`.trim());
|
|
2675
|
+
return {
|
|
2676
|
+
file,
|
|
2677
|
+
className
|
|
2678
|
+
};
|
|
2679
|
+
}
|
|
2680
|
+
const file = implementationFolder.createFile(fileName, `
|
|
2681
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2682
|
+
|
|
2683
|
+
export class ${className} implements ${ContractName} {
|
|
2684
|
+
constructor() {}
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
`.trim());
|
|
2688
|
+
return {
|
|
2689
|
+
file,
|
|
2690
|
+
className
|
|
2691
|
+
};
|
|
2692
|
+
}
|
|
2693
|
+
case 'command':
|
|
2694
|
+
case 'query':
|
|
2695
|
+
{
|
|
2696
|
+
const folderName = 'command' === unit.kind ? 'commands' : 'queries';
|
|
2697
|
+
const file = implementationFolder.createFile(fileName, handlerImplementation(ContractName, className, `../../../application/${folderName}/${naming.fileName}-${unit.kind}`));
|
|
2698
|
+
if (inMemoryDb) injectInMemoryDb(file, className);
|
|
2699
|
+
return {
|
|
2700
|
+
file,
|
|
2701
|
+
className
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2704
|
+
case 'port':
|
|
2705
|
+
{
|
|
2706
|
+
const file = implementationFolder.createFile(fileName, `
|
|
2707
|
+
import { ${ContractName} } from '../../../application/ports/${naming.fileName}'
|
|
2708
|
+
|
|
2709
|
+
export class ${className} extends ${ContractName} {
|
|
2710
|
+
|
|
2711
|
+
}
|
|
2712
|
+
`.trim());
|
|
2713
|
+
return {
|
|
2714
|
+
file,
|
|
2715
|
+
className
|
|
2716
|
+
};
|
|
2717
|
+
}
|
|
2718
|
+
default:
|
|
2719
|
+
throw new Error(`${unit.kind} has no implementations`);
|
|
2720
|
+
}
|
|
2721
|
+
};
|
|
2722
|
+
const inMemoryRepositoryWiring = (ownerFolder, unit, wireFile)=>(implementation, dependency)=>{
|
|
2723
|
+
if ('aggregate' !== unit.kind || !isInMemoryDb(dependency)) return false;
|
|
2724
|
+
keepInMemoryDbSection(new File(implementation.file), addInMemoryDbSection(new UnknownFormatNaming(unit.name), ownerFolder.subitem([
|
|
2725
|
+
'domain',
|
|
2726
|
+
'aggregates',
|
|
2727
|
+
unit.name
|
|
2728
|
+
]).path));
|
|
2729
|
+
wireInMemoryDb(wireFile, implementation.className);
|
|
2730
|
+
return true;
|
|
2731
|
+
};
|
|
2732
|
+
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
2484
2733
|
const prefix = `${folders.join('-')}-`;
|
|
2485
2734
|
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
2486
2735
|
return [
|
|
@@ -2497,7 +2746,7 @@ const findReactModules = (reactFolder, kind)=>{
|
|
|
2497
2746
|
const modules = 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
2498
2747
|
const folders = node_path.relative(node_path.join(reactFolder, 'pages'), node_path.dirname(file)).split(node_path.sep).filter((segment)=>!!segment);
|
|
2499
2748
|
const fileBase = node_path.basename(file, '-page.tsx');
|
|
2500
|
-
const name =
|
|
2749
|
+
const name = react_module_move_nestedName(folders, fileBase);
|
|
2501
2750
|
return {
|
|
2502
2751
|
kind,
|
|
2503
2752
|
name,
|
|
@@ -2569,11 +2818,403 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2569
2818
|
}
|
|
2570
2819
|
});
|
|
2571
2820
|
};
|
|
2821
|
+
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
2822
|
+
if ('ports' === kind) return crossContext ? [
|
|
2823
|
+
{
|
|
2824
|
+
name: 'System: cross-context (calls handlers in another bounded context)',
|
|
2825
|
+
value: crossContextImplementation
|
|
2826
|
+
}
|
|
2827
|
+
] : [];
|
|
2828
|
+
return ConfigFile.exists && usesInMemoryDb('in-memory') ? [
|
|
2829
|
+
{
|
|
2830
|
+
name: 'System: in-memory (uses the shared in-memory database)',
|
|
2831
|
+
value: 'in-memory'
|
|
2832
|
+
}
|
|
2833
|
+
] : [];
|
|
2834
|
+
};
|
|
2835
|
+
const configurationSections = [
|
|
2836
|
+
'project',
|
|
2837
|
+
'backend',
|
|
2838
|
+
'frontend'
|
|
2839
|
+
];
|
|
2840
|
+
const configureProject = async (config)=>{
|
|
2841
|
+
const rootFolder = await input({
|
|
2842
|
+
message: 'Root folder (use "/" for inner folders):',
|
|
2843
|
+
default: config.project.rootFolder,
|
|
2844
|
+
validate: (value)=>value.trim() ? true : 'Root folder is required'
|
|
2845
|
+
});
|
|
2846
|
+
ConfigFile.update({
|
|
2847
|
+
project: {
|
|
2848
|
+
...config.project,
|
|
2849
|
+
rootFolder: rootFolder.trim()
|
|
2850
|
+
}
|
|
2851
|
+
});
|
|
2852
|
+
};
|
|
2853
|
+
const createTestBranch = Symbol('create-test-branch');
|
|
2854
|
+
const noTestBranch = Symbol('no-test-branch');
|
|
2855
|
+
const promptEnvBranches = async (current)=>{
|
|
2856
|
+
const kind = await prompts_select({
|
|
2857
|
+
message: 'envBranchedWire branches:',
|
|
2858
|
+
choices: [
|
|
2859
|
+
{
|
|
2860
|
+
name: 'Default: test, development, production by NODE_ENV',
|
|
2861
|
+
value: 'default'
|
|
2862
|
+
},
|
|
2863
|
+
{
|
|
2864
|
+
name: 'Custom branches',
|
|
2865
|
+
value: 'custom'
|
|
2866
|
+
}
|
|
2867
|
+
],
|
|
2868
|
+
default: current ? 'custom' : 'default'
|
|
2869
|
+
});
|
|
2870
|
+
if ('default' === kind) return;
|
|
2871
|
+
const parse = (value)=>value.split(',').map((name)=>name.trim()).filter(Boolean);
|
|
2872
|
+
const names = parse(await input({
|
|
2873
|
+
message: 'Branches (comma-separated):',
|
|
2874
|
+
default: current?.names.join(', '),
|
|
2875
|
+
validate: (value)=>{
|
|
2876
|
+
const names = parse(value);
|
|
2877
|
+
if (!names.length) return 'Enter at least one branch.';
|
|
2878
|
+
if (1 === names.length && 'test' === names[0]) return 'Add a branch for primary implementations besides test.';
|
|
2879
|
+
const invalid = names.find((name)=>!branchNameSchema.safeParse(name).success);
|
|
2880
|
+
if (invalid) return `${invalid}: use lowercase letters and digits, e.g. staging.`;
|
|
2881
|
+
return new Set(names).size === names.length ? true : 'Branch names must be unique.';
|
|
2882
|
+
}
|
|
2883
|
+
}));
|
|
2884
|
+
const test = await prompts_select({
|
|
2885
|
+
message: 'Test branch:',
|
|
2886
|
+
choices: [
|
|
2887
|
+
...names.map((name)=>({
|
|
2888
|
+
name,
|
|
2889
|
+
value: name,
|
|
2890
|
+
disabled: 1 === names.length ? '(the only branch)' : false
|
|
2891
|
+
})),
|
|
2892
|
+
...names.includes('test') ? [] : [
|
|
2893
|
+
{
|
|
2894
|
+
name: 'Create a "test" branch',
|
|
2895
|
+
value: createTestBranch
|
|
2896
|
+
}
|
|
2897
|
+
],
|
|
2898
|
+
{
|
|
2899
|
+
name: 'No test branch: every branch uses the primary implementation',
|
|
2900
|
+
value: noTestBranch
|
|
2901
|
+
}
|
|
2902
|
+
],
|
|
2903
|
+
default: current && !current.test ? noTestBranch : current?.test && names.includes(current.test) ? current.test : names.includes('test') ? 'test' : createTestBranch
|
|
2904
|
+
});
|
|
2905
|
+
if (test === noTestBranch) return {
|
|
2906
|
+
names
|
|
2907
|
+
};
|
|
2908
|
+
return test === createTestBranch ? {
|
|
2909
|
+
names: [
|
|
2910
|
+
...names,
|
|
2911
|
+
'test'
|
|
2912
|
+
],
|
|
2913
|
+
test: 'test'
|
|
2914
|
+
} : {
|
|
2915
|
+
names,
|
|
2916
|
+
test
|
|
2917
|
+
};
|
|
2918
|
+
};
|
|
2919
|
+
const configureBackend = async (config)=>{
|
|
2920
|
+
const current = config.backend;
|
|
2921
|
+
const domainFirstPackages = await prompts_checkbox({
|
|
2922
|
+
message: '@domain-first packages',
|
|
2923
|
+
choices: config_file_domainFirstPackages.map((value)=>({
|
|
2924
|
+
name: value,
|
|
2925
|
+
value,
|
|
2926
|
+
checked: current?.domainFirstPackages.includes(value) ?? false
|
|
2927
|
+
}))
|
|
2928
|
+
});
|
|
2929
|
+
const envBranches = domainFirstPackages.includes('@domain-first/wire') ? await promptEnvBranches(current?.envBranches) : current?.envBranches;
|
|
2930
|
+
const withInMemoryDb = await prompts_confirm({
|
|
2931
|
+
message: 'Scaffold in-memory DB for test implementations',
|
|
2932
|
+
default: current ? Boolean(current.withInMemoryDb) : true
|
|
2933
|
+
});
|
|
2934
|
+
const withTests = await prompts_confirm({
|
|
2935
|
+
message: 'Scaffold unit tests',
|
|
2936
|
+
default: current ? Boolean(current.testingLibrary) : true
|
|
2937
|
+
});
|
|
2938
|
+
const testingLibrary = withTests ? await input({
|
|
2939
|
+
message: 'Unit testing library:',
|
|
2940
|
+
default: current?.testingLibrary ?? 'vitest'
|
|
2941
|
+
}) : void 0;
|
|
2942
|
+
ConfigFile.update({
|
|
2943
|
+
backend: {
|
|
2944
|
+
...current,
|
|
2945
|
+
domainFirstPackages,
|
|
2946
|
+
envBranches,
|
|
2947
|
+
withInMemoryDb,
|
|
2948
|
+
testingLibrary,
|
|
2949
|
+
rules: scaffoldBackendRules(current?.rules)
|
|
2950
|
+
}
|
|
2951
|
+
});
|
|
2952
|
+
const rootFolder = new Folder(new ProjectRoot().path);
|
|
2953
|
+
const rootFolderName = config.project.rootFolder;
|
|
2954
|
+
const wiringFolder = rootFolder.subitem([
|
|
2955
|
+
rootFolderName,
|
|
2956
|
+
'shared-kernel',
|
|
2957
|
+
'wiring'
|
|
2958
|
+
]);
|
|
2959
|
+
const notes = [];
|
|
2960
|
+
const envBranchedWireExisted = new File(node_path.join(wiringFolder.path, 'env-branched-wire.ts')).exists;
|
|
2961
|
+
if (domainFirstPackages.includes('@domain-first/wire') && envBranchedWireExisted && JSON.stringify(envBranches ?? null) !== JSON.stringify(current?.envBranches ?? null)) {
|
|
2962
|
+
const { names } = envBranches ?? defaultEnvBranches;
|
|
2963
|
+
notes.push(`${rootFolderName}/shared-kernel/wiring/env-branched-wire.ts and existing envBranchedWire calls keep their branches: change them to ${names.join(', ')} yourself`);
|
|
2964
|
+
}
|
|
2965
|
+
withoutOverwrites(()=>{
|
|
2966
|
+
if (domainFirstPackages.includes('@domain-first/wire')) wiringFolder.createFile('env-branched-wire.ts', envBranchedWireSource());
|
|
2967
|
+
if (withInMemoryDb) scaffoldInMemoryDb(rootFolder.subitem([
|
|
2968
|
+
rootFolderName,
|
|
2969
|
+
'shared-kernel'
|
|
2970
|
+
]));
|
|
2971
|
+
});
|
|
2972
|
+
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(', ')})`);
|
|
2973
|
+
return notes;
|
|
2974
|
+
};
|
|
2975
|
+
const configureFrontend = async (config)=>{
|
|
2976
|
+
const currentFramework = config.frontend?.react?.framework ?? (hasDependency('next') ? 'next' : 'react');
|
|
2977
|
+
const framework = await prompts_select({
|
|
2978
|
+
message: 'Frontend framework:',
|
|
2979
|
+
choices: [
|
|
2980
|
+
{
|
|
2981
|
+
name: 'React',
|
|
2982
|
+
value: 'react'
|
|
2983
|
+
},
|
|
2984
|
+
{
|
|
2985
|
+
name: 'Next.js',
|
|
2986
|
+
value: 'next'
|
|
2987
|
+
}
|
|
2988
|
+
],
|
|
2989
|
+
default: currentFramework
|
|
2990
|
+
});
|
|
2991
|
+
const withNextAdapter = 'next' === framework && config.backend ? await askNextAdapter({
|
|
2992
|
+
nextSelected: true
|
|
2993
|
+
}) : false;
|
|
2994
|
+
const withStorybook = await prompts_confirm({
|
|
2995
|
+
message: 'Use Storybook',
|
|
2996
|
+
default: config.frontend?.react ? Boolean(config.frontend.react.storybookFramework) : true
|
|
2997
|
+
});
|
|
2998
|
+
const storybookFramework = withStorybook ? storybookFrameworkPackage : void 0;
|
|
2999
|
+
ConfigFile.update({
|
|
3000
|
+
frontend: {
|
|
3001
|
+
...config.frontend,
|
|
3002
|
+
react: {
|
|
3003
|
+
...config.frontend?.react,
|
|
3004
|
+
framework,
|
|
3005
|
+
storybookFramework
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
});
|
|
3009
|
+
return {
|
|
3010
|
+
withNextAdapter,
|
|
3011
|
+
nextSteps: [
|
|
3012
|
+
...missingPackages('next' === framework ? [
|
|
3013
|
+
'next',
|
|
3014
|
+
'react',
|
|
3015
|
+
'react-dom'
|
|
3016
|
+
] : [
|
|
3017
|
+
'react',
|
|
3018
|
+
'react-dom'
|
|
3019
|
+
]),
|
|
3020
|
+
...withStorybook ? await addStorybook() : []
|
|
3021
|
+
]
|
|
3022
|
+
};
|
|
3023
|
+
};
|
|
3024
|
+
const configureRest = async (withNextAdapter)=>{
|
|
3025
|
+
const backend = ConfigFile.Instance.data.backend;
|
|
3026
|
+
if (!backend) return [];
|
|
3027
|
+
const withRest = backend.domainFirstPackages.includes('@domain-first/handlers-rest');
|
|
3028
|
+
const nextSelected = ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
3029
|
+
if (void 0 === withNextAdapter && (withRest || nextSelected)) withNextAdapter = await askNextAdapter();
|
|
3030
|
+
if (!withRest && !withNextAdapter) return [];
|
|
3031
|
+
if (withNextAdapter && !withRest) ConfigFile.update({
|
|
3032
|
+
backend: {
|
|
3033
|
+
...backend,
|
|
3034
|
+
domainFirstPackages: [
|
|
3035
|
+
...backend.domainFirstPackages,
|
|
3036
|
+
'@domain-first/handlers-rest'
|
|
3037
|
+
]
|
|
3038
|
+
}
|
|
3039
|
+
});
|
|
3040
|
+
return scaffoldRestEndpointGeneratorFiles({
|
|
3041
|
+
withNextAdapter: withNextAdapter ?? false
|
|
3042
|
+
});
|
|
3043
|
+
};
|
|
3044
|
+
const initializeUseCase = async (section)=>{
|
|
3045
|
+
const existing = ConfigFile.exists;
|
|
3046
|
+
if (!existing) ConfigFile.write({
|
|
3047
|
+
project: {
|
|
3048
|
+
rootFolder: 'src'
|
|
3049
|
+
}
|
|
3050
|
+
});
|
|
3051
|
+
let sections = configurationSections;
|
|
3052
|
+
if (section) sections = 'project' === section || existing ? [
|
|
3053
|
+
section
|
|
3054
|
+
] : [
|
|
3055
|
+
'project',
|
|
3056
|
+
section
|
|
3057
|
+
];
|
|
3058
|
+
else if (existing) {
|
|
3059
|
+
const selected = await prompts_select({
|
|
3060
|
+
message: 'Configuration section:',
|
|
3061
|
+
choices: [
|
|
3062
|
+
...configurationSections.map((value)=>({
|
|
3063
|
+
name: `${value[0].toUpperCase()}${value.slice(1)}${ConfigFile.Instance.data[value] ? '' : ' (not configured)'}`,
|
|
3064
|
+
value
|
|
3065
|
+
})),
|
|
3066
|
+
{
|
|
3067
|
+
name: 'All sections',
|
|
3068
|
+
value: 'all'
|
|
3069
|
+
}
|
|
3070
|
+
]
|
|
3071
|
+
});
|
|
3072
|
+
sections = 'all' === selected ? configurationSections : [
|
|
3073
|
+
selected
|
|
3074
|
+
];
|
|
3075
|
+
}
|
|
3076
|
+
const nextSteps = [];
|
|
3077
|
+
let backendConfigured = false;
|
|
3078
|
+
let withNextAdapter;
|
|
3079
|
+
for (const currentSection of sections){
|
|
3080
|
+
console.log(`\n${currentSection[0].toUpperCase()}${currentSection.slice(1)} configuration`);
|
|
3081
|
+
if (!section && sections.length > 1 && !await prompts_confirm({
|
|
3082
|
+
message: `Configure ${currentSection} now?`,
|
|
3083
|
+
default: true
|
|
3084
|
+
})) {
|
|
3085
|
+
if ('project' === currentSection) console.log(`Keeping project root folder: ${ConfigFile.Instance.data.project.rootFolder}.`);
|
|
3086
|
+
nextSteps.push(`configure ${currentSection} later with df-init --section ${currentSection}`);
|
|
3087
|
+
continue;
|
|
3088
|
+
}
|
|
3089
|
+
const config = ConfigFile.Instance.data;
|
|
3090
|
+
switch(currentSection){
|
|
3091
|
+
case 'project':
|
|
3092
|
+
await configureProject(config);
|
|
3093
|
+
break;
|
|
3094
|
+
case 'backend':
|
|
3095
|
+
nextSteps.push(...await configureBackend(config));
|
|
3096
|
+
backendConfigured = true;
|
|
3097
|
+
break;
|
|
3098
|
+
case 'frontend':
|
|
3099
|
+
{
|
|
3100
|
+
const frontend = await configureFrontend(config);
|
|
3101
|
+
withNextAdapter = frontend.withNextAdapter;
|
|
3102
|
+
nextSteps.push(...frontend.nextSteps);
|
|
3103
|
+
break;
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
if (backendConfigured || withNextAdapter) {
|
|
3108
|
+
const restSteps = await configureRest(withNextAdapter);
|
|
3109
|
+
nextSteps.push(...missingDomainFirstPackages(), ...restSteps);
|
|
3110
|
+
}
|
|
3111
|
+
return nextSteps;
|
|
3112
|
+
};
|
|
3113
|
+
const noAggregate = 'No aggregate';
|
|
3114
|
+
const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
3115
|
+
const root = new ProjectRoot().path;
|
|
3116
|
+
const rootFolderPath = node_path.join(root, ConfigFile.Instance.data.project.rootFolder);
|
|
3117
|
+
const sharedKernelPath = node_path.join(rootFolderPath, 'shared-kernel');
|
|
3118
|
+
const units = findBackendUnits(ownerFolder.path);
|
|
3119
|
+
if (!units.length) return void report('No modules generated by df-scaffold were found here.');
|
|
3120
|
+
const unit = await interaction_select({
|
|
3121
|
+
key: 'module',
|
|
3122
|
+
id: unitId,
|
|
3123
|
+
message: 'Module:',
|
|
3124
|
+
choices: Object.keys(kindLayouts).flatMap((kind)=>{
|
|
3125
|
+
const group = units.filter((x)=>x.kind === kind);
|
|
3126
|
+
return group.length ? [
|
|
3127
|
+
new Separator(`── ${kindLayouts[group[0].kind].title}`),
|
|
3128
|
+
...group.map((value)=>({
|
|
3129
|
+
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
3130
|
+
value
|
|
3131
|
+
}))
|
|
3132
|
+
] : [];
|
|
3133
|
+
}),
|
|
3134
|
+
pageSize: 20
|
|
3135
|
+
});
|
|
3136
|
+
const placeName = (ownerPath)=>ownerPath === sharedKernelPath ? 'Shared Kernel' : `Bounded Context: ${node_path.basename(ownerPath)}`;
|
|
3137
|
+
const contexts = new Folder(rootFolderPath).subitem([
|
|
3138
|
+
'bounded-contexts'
|
|
3139
|
+
]).content.subfolderNames.map((name)=>node_path.join(rootFolderPath, 'bounded-contexts', name));
|
|
3140
|
+
const places = [
|
|
3141
|
+
unit.ownerPath,
|
|
3142
|
+
...contexts,
|
|
3143
|
+
...kindLayouts[unit.kind].sharedKernel ? [
|
|
3144
|
+
sharedKernelPath
|
|
3145
|
+
] : []
|
|
3146
|
+
].filter((place, index, all)=>all.indexOf(place) === index);
|
|
3147
|
+
const ownerPath = await interaction_select({
|
|
3148
|
+
key: 'targetContext',
|
|
3149
|
+
id: (owner)=>owner === sharedKernelPath ? 'shared-kernel' : node_path.basename(owner),
|
|
3150
|
+
message: 'Move to:',
|
|
3151
|
+
choices: places.map((value)=>({
|
|
3152
|
+
name: value === unit.ownerPath ? `${placeName(value)} (stays)` : placeName(value),
|
|
3153
|
+
value
|
|
3154
|
+
}))
|
|
3155
|
+
});
|
|
3156
|
+
let aggregate;
|
|
3157
|
+
const aggregates = ownerPath === sharedKernelPath ? [] : aggregatesOf(ownerPath);
|
|
3158
|
+
if (('entity' === unit.kind || 'value-object' === unit.kind) && aggregates.length) {
|
|
3159
|
+
const picked = await interaction_select({
|
|
3160
|
+
key: 'aggregate',
|
|
3161
|
+
message: 'Aggregate:',
|
|
3162
|
+
choices: [
|
|
3163
|
+
noAggregate,
|
|
3164
|
+
...aggregates
|
|
3165
|
+
],
|
|
3166
|
+
default: ownerPath === unit.ownerPath && unit.aggregate ? unit.aggregate : noAggregate
|
|
3167
|
+
});
|
|
3168
|
+
aggregate = picked === noAggregate ? void 0 : picked;
|
|
3169
|
+
}
|
|
3170
|
+
const target = (name)=>({
|
|
3171
|
+
ownerPath,
|
|
3172
|
+
aggregate,
|
|
3173
|
+
name: name.trim()
|
|
3174
|
+
});
|
|
3175
|
+
const name = await interaction_input({
|
|
3176
|
+
key: 'name',
|
|
3177
|
+
message: 'New name:',
|
|
3178
|
+
default: unit.name,
|
|
3179
|
+
validate: (value)=>validateBackendMove(unit, target(value), sharedKernelPath)
|
|
3180
|
+
});
|
|
3181
|
+
const result = moveBackendUnit(root, rootFolderPath, unit, target(name));
|
|
3182
|
+
if (result.violations) {
|
|
3183
|
+
if (isNonInteractive()) throw new RequestError('MOVE_NOT_ALLOWED', 'The move would cross bounded-context boundaries.', {
|
|
3184
|
+
violations: result.violations
|
|
3185
|
+
});
|
|
3186
|
+
report([
|
|
3187
|
+
"Nothing was moved: these imports would cross a bounded context boundary.",
|
|
3188
|
+
...result.violations.map(([from, to])=>` ${from} → ${to}`),
|
|
3189
|
+
'Give the other context its own query or command, or move what it depends on first.'
|
|
3190
|
+
].join('\n'));
|
|
3191
|
+
return;
|
|
3192
|
+
}
|
|
3193
|
+
const relative = (file)=>node_path.relative(root, file);
|
|
3194
|
+
report([
|
|
3195
|
+
'Files to move:',
|
|
3196
|
+
...result.moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
3197
|
+
...result.updated.length ? [
|
|
3198
|
+
'Files with updated imports and names:',
|
|
3199
|
+
...result.updated.map((file)=>` ${relative(file)}`)
|
|
3200
|
+
] : []
|
|
3201
|
+
].join('\n'));
|
|
3202
|
+
if (!await interaction_confirm({
|
|
3203
|
+
key: 'apply',
|
|
3204
|
+
message: 'Apply?',
|
|
3205
|
+
default: true
|
|
3206
|
+
})) {
|
|
3207
|
+
discardPendingChanges();
|
|
3208
|
+
report('Cancelled: nothing was written.');
|
|
3209
|
+
}
|
|
3210
|
+
};
|
|
2572
3211
|
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
2573
3212
|
const reactFolder = presentationReactFolder.path;
|
|
2574
3213
|
const modules = findReactModules(reactFolder, kind);
|
|
2575
|
-
if (!modules.length) return void
|
|
2576
|
-
const module = await
|
|
3214
|
+
if (!modules.length) return void report(`No ${kind}s generated by df-react were found.`);
|
|
3215
|
+
const module = await interaction_select({
|
|
3216
|
+
key: 'module',
|
|
3217
|
+
id: (value)=>value.name,
|
|
2577
3218
|
message: 'page' === kind ? 'Page:' : 'Widget:',
|
|
2578
3219
|
choices: modules.map((value)=>({
|
|
2579
3220
|
name: value.name,
|
|
@@ -2581,16 +3222,17 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
2581
3222
|
description: node_path.relative(reactFolder, value.path)
|
|
2582
3223
|
}))
|
|
2583
3224
|
});
|
|
2584
|
-
const name = await
|
|
3225
|
+
const name = await interaction_input({
|
|
3226
|
+
key: 'name',
|
|
2585
3227
|
message: 'New name (folders split by "/"):',
|
|
2586
3228
|
default: module.name,
|
|
2587
3229
|
validate: (value)=>validateMove(reactFolder, module, value)
|
|
2588
3230
|
});
|
|
2589
3231
|
const root = new ProjectRoot().path;
|
|
2590
3232
|
const { moves, updated } = moveReactModule(root, reactFolder, module, name);
|
|
2591
|
-
if (!moves.length && !updated.length) return void
|
|
3233
|
+
if (!moves.length && !updated.length) return void report('Nothing to change.');
|
|
2592
3234
|
const relative = (file)=>node_path.relative(root, file);
|
|
2593
|
-
|
|
3235
|
+
report([
|
|
2594
3236
|
'Files to move:',
|
|
2595
3237
|
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
2596
3238
|
...updated.length ? [
|
|
@@ -2598,154 +3240,105 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
2598
3240
|
...updated.map((file)=>` ${relative(file)}`)
|
|
2599
3241
|
] : []
|
|
2600
3242
|
].join('\n'));
|
|
2601
|
-
if (!await
|
|
3243
|
+
if (!await interaction_confirm({
|
|
3244
|
+
key: 'apply',
|
|
2602
3245
|
message: 'Apply?',
|
|
2603
3246
|
default: true
|
|
2604
3247
|
})) {
|
|
2605
3248
|
discardPendingChanges();
|
|
2606
|
-
|
|
3249
|
+
report('Cancelled: nothing was written.');
|
|
2607
3250
|
}
|
|
2608
3251
|
};
|
|
2609
|
-
const
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
const findContracts = (ownerPath)=>findBackendUnits(ownerPath).filter((unit)=>contractKinds.includes(unit.kind) && node_fs.existsSync(node_path.join(ownerPath, contractFile(unit))));
|
|
2619
|
-
const implementationWireName = (label)=>`wire${new UnknownFormatNaming(label).ClassName}Implementation`;
|
|
2620
|
-
const contractClassName = (unit)=>kindLayouts[unit.kind].core(new UnknownFormatNaming(unit.name).ClassName);
|
|
2621
|
-
const implementationClassName = (unit, label)=>`${new UnknownFormatNaming(label).ClassName}${contractClassName(unit)}`;
|
|
2622
|
-
const implementationFile = (unit, label)=>{
|
|
2623
|
-
const { implementations } = kindLayouts[unit.kind];
|
|
2624
|
-
return kindLayouts[unit.kind].files(unit, [
|
|
2625
|
-
label
|
|
2626
|
-
]).find((file)=>file.startsWith(`${implementations}/`));
|
|
2627
|
-
};
|
|
2628
|
-
const contractWireFile = (unit)=>kindLayouts[unit.kind].files(unit, []).find((file)=>file.startsWith('wiring/'));
|
|
2629
|
-
const handlerImplementation = (ContractName, ClassName, contractImport)=>withHandlers() ? `
|
|
2630
|
-
import { defineHandler } from '@domain-first/handlers'
|
|
2631
|
-
import { ${ContractName} } from '${contractImport}'
|
|
2632
|
-
|
|
2633
|
-
export class ${ClassName} extends ${ContractName} {
|
|
2634
|
-
constructor() {
|
|
2635
|
-
super()
|
|
2636
|
-
}
|
|
2637
|
-
|
|
2638
|
-
handle = defineHandler({
|
|
2639
|
-
inputSchema: ${ContractName}.inputSchema,
|
|
2640
|
-
outputSchema: ${ContractName}.outputSchema,
|
|
2641
|
-
handler: async (input) => {
|
|
2642
|
-
return {}
|
|
2643
|
-
}
|
|
2644
|
-
})
|
|
2645
|
-
}
|
|
2646
|
-
`.trim() : `
|
|
2647
|
-
import { ${ContractName} } from '${contractImport}'
|
|
2648
|
-
|
|
2649
|
-
export class ${ClassName} extends ${ContractName} {
|
|
2650
|
-
constructor() {
|
|
2651
|
-
super()
|
|
3252
|
+
const enterImplementationTypeOnce = Symbol('enter-implementation-type-once');
|
|
3253
|
+
const implementationTypeEntryChoices = [
|
|
3254
|
+
{
|
|
3255
|
+
name: 'Enter implementation type and save for future use',
|
|
3256
|
+
value: null
|
|
3257
|
+
},
|
|
3258
|
+
{
|
|
3259
|
+
name: 'Enter implementation type for this run only',
|
|
3260
|
+
value: enterImplementationTypeOnce
|
|
2652
3261
|
}
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
const
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
node_path.dirname(implementationFile(unit, label)),
|
|
2661
|
-
node_path.basename(implementationFile(unit, label))
|
|
3262
|
+
];
|
|
3263
|
+
const promptImplementationType = async (message, kind, { existing = [], purpose = 'primary', crossContext = false, remember = true } = {})=>{
|
|
3264
|
+
const roles = 'all' === purpose ? [
|
|
3265
|
+
'primary',
|
|
3266
|
+
'test'
|
|
3267
|
+
] : [
|
|
3268
|
+
purpose
|
|
2662
3269
|
];
|
|
2663
|
-
const
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
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
|
-
return {
|
|
2699
|
-
file,
|
|
2700
|
-
className
|
|
2701
|
-
};
|
|
2702
|
-
}
|
|
2703
|
-
case 'command':
|
|
2704
|
-
case 'query':
|
|
2705
|
-
{
|
|
2706
|
-
const folderName = 'command' === unit.kind ? 'commands' : 'queries';
|
|
2707
|
-
const file = implementationFolder.createFile(fileName, handlerImplementation(ContractName, className, `../../../application/${folderName}/${naming.fileName}-${unit.kind}`));
|
|
2708
|
-
if (inMemoryDb) injectInMemoryDb(file, className);
|
|
2709
|
-
return {
|
|
2710
|
-
file,
|
|
2711
|
-
className
|
|
2712
|
-
};
|
|
2713
|
-
}
|
|
2714
|
-
case 'port':
|
|
2715
|
-
{
|
|
2716
|
-
const file = implementationFolder.createFile(fileName, `
|
|
2717
|
-
import { ${ContractName} } from '../../../application/ports/${naming.fileName}'
|
|
2718
|
-
|
|
2719
|
-
export class ${className} extends ${ContractName} {
|
|
2720
|
-
|
|
2721
|
-
}
|
|
2722
|
-
`.trim());
|
|
2723
|
-
return {
|
|
2724
|
-
file,
|
|
2725
|
-
className
|
|
2726
|
-
};
|
|
2727
|
-
}
|
|
2728
|
-
default:
|
|
2729
|
-
throw new Error(`${unit.kind} has no implementations`);
|
|
3270
|
+
const saved = [
|
|
3271
|
+
...new Set(roles.flatMap((role)=>savedImplementations(kind, role)))
|
|
3272
|
+
].filter((label)=>label !== crossContextImplementation || 'ports' === kind && crossContext);
|
|
3273
|
+
const allowCrossContext = 'ports' === kind && crossContext;
|
|
3274
|
+
const system = systemImplementationChoices(kind, crossContext);
|
|
3275
|
+
const choices = saved.map((label)=>system.find(({ value })=>value === label) ?? {
|
|
3276
|
+
name: label,
|
|
3277
|
+
value: label
|
|
3278
|
+
});
|
|
3279
|
+
for (const choice of system)if (!choices.some(({ value })=>value === choice.value)) choices.push(choice);
|
|
3280
|
+
const defaultType = saved.find((label)=>!existing.includes(label));
|
|
3281
|
+
const preferred = choices.find(({ value })=>value === defaultType && !existing.includes(value)) ?? choices.find(({ value })=>!existing.includes(value));
|
|
3282
|
+
const validateLabel = (value)=>{
|
|
3283
|
+
const label = value.trim();
|
|
3284
|
+
if (!allowCrossContext && label === crossContextImplementation) return 'Cross-context implementations require an application port with a neighboring bounded context.';
|
|
3285
|
+
if (!kebabName.test(label)) return 'Use lowercase kebab-case, e.g. prisma or in-memory.';
|
|
3286
|
+
return existing.includes(label) ? `The ${label} implementation already exists.` : true;
|
|
3287
|
+
};
|
|
3288
|
+
if (isNonInteractive()) {
|
|
3289
|
+
const key = 'test' === purpose ? 'testImplementation' : 'implementation';
|
|
3290
|
+
const implementation = answerFor(key);
|
|
3291
|
+
if (!implementation) throw new RequestError('MISSING_PARAMETER', `Provide ${key}.`, {
|
|
3292
|
+
field: key
|
|
3293
|
+
});
|
|
3294
|
+
const valid = validateLabel(implementation.type);
|
|
3295
|
+
if (true !== valid) throw new RequestError('INVALID_IMPLEMENTATION', valid, {
|
|
3296
|
+
field: key
|
|
3297
|
+
});
|
|
3298
|
+
const label = implementation.type.trim();
|
|
3299
|
+
const saveForFutureUse = implementation.save ?? false;
|
|
3300
|
+
if (remember && saveForFutureUse && !system.some((choice)=>choice.value === label)) rememberImplementation(kind, 'all' === purpose ? 'primary' : purpose, label);
|
|
3301
|
+
return {
|
|
3302
|
+
label,
|
|
3303
|
+
saveForFutureUse
|
|
3304
|
+
};
|
|
2730
3305
|
}
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
3306
|
+
const type = await interaction_select({
|
|
3307
|
+
message,
|
|
3308
|
+
choices: [
|
|
3309
|
+
...choices.map((choice)=>({
|
|
3310
|
+
...choice,
|
|
3311
|
+
disabled: existing.includes(choice.value)
|
|
3312
|
+
})),
|
|
3313
|
+
...implementationTypeEntryChoices
|
|
3314
|
+
],
|
|
3315
|
+
default: preferred?.value ?? null
|
|
3316
|
+
});
|
|
3317
|
+
if ('string' == typeof type) return {
|
|
3318
|
+
label: type,
|
|
3319
|
+
saveForFutureUse: true
|
|
2741
3320
|
};
|
|
3321
|
+
const saveForFutureUse = type !== enterImplementationTypeOnce;
|
|
3322
|
+
const label = (await interaction_input({
|
|
3323
|
+
message,
|
|
3324
|
+
default: defaultType ?? '',
|
|
3325
|
+
validate: validateLabel
|
|
3326
|
+
})).trim();
|
|
3327
|
+
if (saveForFutureUse && remember && !choices.some(({ value })=>value === label)) rememberImplementation(kind, 'all' === purpose ? 'primary' : purpose, label);
|
|
3328
|
+
return {
|
|
3329
|
+
label,
|
|
3330
|
+
saveForFutureUse
|
|
3331
|
+
};
|
|
3332
|
+
};
|
|
2742
3333
|
const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
2743
|
-
const aggregateName = await
|
|
3334
|
+
const aggregateName = await interaction_input({
|
|
3335
|
+
key: 'name',
|
|
2744
3336
|
message: 'Aggregate name:'
|
|
2745
3337
|
});
|
|
2746
3338
|
const aggregateNaming = new UnknownFormatNaming(aggregateName);
|
|
2747
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
2748
|
-
const withRepository = await
|
|
3339
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3340
|
+
const withRepository = await interaction_confirm({
|
|
3341
|
+
key: 'withRepository',
|
|
2749
3342
|
message: 'With Repository'
|
|
2750
3343
|
});
|
|
2751
3344
|
const aggregatesFolder = boundedContextFolder.subitem([
|
|
@@ -2753,7 +3346,7 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
|
2753
3346
|
'aggregates',
|
|
2754
3347
|
aggregateName
|
|
2755
3348
|
]);
|
|
2756
|
-
const withTypes = ConfigFile.
|
|
3349
|
+
const withTypes = ConfigFile.backend.domainFirstPackages.includes('@domain-first/types');
|
|
2757
3350
|
aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.ts`, withTypes ? `
|
|
2758
3351
|
import { domainType } from '@domain-first/types'
|
|
2759
3352
|
|
|
@@ -2762,7 +3355,7 @@ export class ${aggregateNaming.ClassName} extends domainType() {
|
|
|
2762
3355
|
}`.trim() : `export class ${aggregateNaming.ClassName} {}`);
|
|
2763
3356
|
const barrelFile = aggregatesFolder.createFile("index.ts", `export * from './${aggregateNaming.fileName}.aggregate-root'`);
|
|
2764
3357
|
if (scaffoldUnitTests) aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.spec.ts`, `
|
|
2765
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3358
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
2766
3359
|
import { ${aggregateNaming.ClassName} } from './${aggregateNaming.fileName}.aggregate-root'
|
|
2767
3360
|
|
|
2768
3361
|
let ${aggregateNaming.variableName}: ${aggregateNaming.ClassName}
|
|
@@ -2780,19 +3373,19 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
2780
3373
|
if (withRepository) {
|
|
2781
3374
|
aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.ts`, `export abstract class ${aggregateNaming.ClassName}Repository { }`);
|
|
2782
3375
|
barrelFile.addLine(`export * from './${aggregateNaming.fileName}-repository'`);
|
|
2783
|
-
const infrastructureImplementationType = await
|
|
2784
|
-
message: 'Repository infrastructure implementation type:',
|
|
2785
|
-
default: ConfigFile.Instance.data.defaultPersistenceLayerImplementation
|
|
2786
|
-
});
|
|
3376
|
+
const { label: infrastructureImplementationType } = await promptImplementationType('Repository infrastructure implementation type:', 'repositories');
|
|
2787
3377
|
let addTestImplementation = false;
|
|
2788
3378
|
let testImplementationType = '';
|
|
2789
|
-
addTestImplementation = await
|
|
3379
|
+
addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
3380
|
+
key: 'withTestImplementation',
|
|
2790
3381
|
message: 'Add a test implementation for Repository'
|
|
2791
3382
|
});
|
|
2792
|
-
if (addTestImplementation) testImplementationType = await
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
3383
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test Repository infrastructure implementation type:', 'repositories', {
|
|
3384
|
+
purpose: 'test',
|
|
3385
|
+
existing: [
|
|
3386
|
+
infrastructureImplementationType
|
|
3387
|
+
]
|
|
3388
|
+
})).label;
|
|
2796
3389
|
const implementationTypes = [
|
|
2797
3390
|
infrastructureImplementationType,
|
|
2798
3391
|
testImplementationType
|
|
@@ -2807,8 +3400,8 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
2807
3400
|
if (scaffoldUnitTests) {
|
|
2808
3401
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
2809
3402
|
const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
|
|
2810
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
2811
|
-
${ConfigFile.
|
|
3403
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3404
|
+
${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
|
|
2812
3405
|
import type { ${aggregateNaming.ClassName}Repository } from './${aggregateNaming.fileName}-repository'` : `import { ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository } from '../../../infrastructure/repositories/${implementationNaming.fileName}/${implementationNaming.fileName}-${aggregateNaming.fileName}-repository'
|
|
2813
3406
|
|
|
2814
3407
|
type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`}
|
|
@@ -2816,18 +3409,18 @@ type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}$
|
|
|
2816
3409
|
let ${aggregateNaming.variableName}Repository: ${aggregateNaming.ClassName}Repository
|
|
2817
3410
|
|
|
2818
3411
|
beforeEach(() => {
|
|
2819
|
-
${aggregateNaming.variableName}Repository = ${ConfigFile.
|
|
3412
|
+
${aggregateNaming.variableName}Repository = ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${aggregateNaming.ClassName}Repository()` : `new ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository()`}
|
|
2820
3413
|
})
|
|
2821
3414
|
|
|
2822
3415
|
describe('${aggregateNaming.withSpaces} repository', () => {
|
|
2823
|
-
test('can be ${ConfigFile.
|
|
3416
|
+
test('can be ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
|
|
2824
3417
|
expect(${aggregateNaming.variableName}Repository).toBeDefined()
|
|
2825
3418
|
})
|
|
2826
3419
|
})
|
|
2827
3420
|
`.trim());
|
|
2828
|
-
if (!ConfigFile.
|
|
3421
|
+
if (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
|
|
2829
3422
|
}
|
|
2830
|
-
if (ConfigFile.
|
|
3423
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2831
3424
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
2832
3425
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
2833
3426
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -2840,22 +3433,19 @@ ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fil
|
|
|
2840
3433
|
|
|
2841
3434
|
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${aggregateNaming.ClassName}Repository, [])`).join('\n\n')}
|
|
2842
3435
|
|
|
2843
|
-
export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
|
|
2844
|
-
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
2845
|
-
development: wire${implementationNaming.ClassName}Implementation,
|
|
2846
|
-
production: wire${implementationNaming.ClassName}Implementation
|
|
2847
|
-
})
|
|
3436
|
+
export const wire${aggregateNaming.ClassName}Repository = envBranchedWire(${envBranchedWireArgument(`wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation`, `wire${implementationNaming.ClassName}Implementation`)})
|
|
2848
3437
|
`.trim());
|
|
2849
3438
|
await wireNewModuleDependencies(boundedContextFolder, wireFile, inMemoryRepositoryWiring(boundedContextFolder, repository, wireFile));
|
|
2850
3439
|
}
|
|
2851
3440
|
}
|
|
2852
3441
|
};
|
|
2853
3442
|
const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
|
|
2854
|
-
const name = await
|
|
3443
|
+
const name = await interaction_input({
|
|
3444
|
+
key: 'name',
|
|
2855
3445
|
message: 'Name: '
|
|
2856
3446
|
});
|
|
2857
3447
|
const naming = new UnknownFormatNaming(name);
|
|
2858
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3448
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
2859
3449
|
const wiringFolder = boundedContextFolder.subitem([
|
|
2860
3450
|
'wiring',
|
|
2861
3451
|
'application-ports'
|
|
@@ -2869,18 +3459,22 @@ export abstract class ${naming.ClassName} {
|
|
|
2869
3459
|
|
|
2870
3460
|
}
|
|
2871
3461
|
`.trim());
|
|
2872
|
-
const
|
|
2873
|
-
|
|
2874
|
-
|
|
3462
|
+
const crossContext = hasNeighboringBoundedContext(boundedContextFolder.path);
|
|
3463
|
+
const { label: implementationType } = await promptImplementationType('Adapter implementation type:', 'ports', {
|
|
3464
|
+
crossContext
|
|
2875
3465
|
});
|
|
2876
|
-
const addTestImplementation = await
|
|
3466
|
+
const addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
3467
|
+
key: 'withTestImplementation',
|
|
2877
3468
|
message: 'With test implementation'
|
|
2878
3469
|
});
|
|
2879
3470
|
let testImplementationType = '';
|
|
2880
|
-
if (addTestImplementation) testImplementationType = await
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
3471
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test adapter implementation type:', 'ports', {
|
|
3472
|
+
existing: [
|
|
3473
|
+
implementationType
|
|
3474
|
+
],
|
|
3475
|
+
purpose: 'test',
|
|
3476
|
+
crossContext
|
|
3477
|
+
})).label;
|
|
2884
3478
|
const implementationTypes = [
|
|
2885
3479
|
implementationType,
|
|
2886
3480
|
testImplementationType
|
|
@@ -2894,8 +3488,8 @@ export abstract class ${naming.ClassName} {
|
|
|
2894
3488
|
if (scaffoldUnitTests) {
|
|
2895
3489
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
2896
3490
|
applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
|
|
2897
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
2898
|
-
${ConfigFile.
|
|
3491
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3492
|
+
${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { type ${naming.ClassName} } from './${naming.fileName}'
|
|
2899
3493
|
import { wire${naming.ClassName} } from '../../wiring/application-ports/wire-${naming.fileName}'` : `import { ${implementationNaming.ClassName}${naming.ClassName} } from '../../infrastructure/application-adapters/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}'
|
|
2900
3494
|
|
|
2901
3495
|
type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`}
|
|
@@ -2903,17 +3497,17 @@ type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`
|
|
|
2903
3497
|
let ${naming.variableName}: ${naming.ClassName}
|
|
2904
3498
|
|
|
2905
3499
|
beforeEach(() => {
|
|
2906
|
-
${naming.variableName} = ${ConfigFile.
|
|
3500
|
+
${naming.variableName} = ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${naming.ClassName}()` : `new ${implementationNaming.ClassName}${naming.ClassName}()`}
|
|
2907
3501
|
})
|
|
2908
3502
|
|
|
2909
3503
|
describe('${naming.withSpaces}', () => {
|
|
2910
|
-
test('can be ${ConfigFile.
|
|
3504
|
+
test('can be ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
|
|
2911
3505
|
expect(${naming.variableName}).toBeDefined()
|
|
2912
3506
|
})
|
|
2913
3507
|
})
|
|
2914
3508
|
`.trim());
|
|
2915
3509
|
}
|
|
2916
|
-
if (ConfigFile.
|
|
3510
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2917
3511
|
const wireFile = wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
|
|
2918
3512
|
import { wireClass } from '@domain-first/wire'
|
|
2919
3513
|
import { envBranchedWire } from '../../../${'shared-kernel' === boundedContextFolder.name ? '' : '../'}shared-kernel/wiring/env-branched-wire'
|
|
@@ -2927,23 +3521,20 @@ ${implementationTypes.map((x)=>({
|
|
|
2927
3521
|
implementation: x
|
|
2928
3522
|
})).map(({ naming: { ClassName }, implementation })=>`const wire${new UnknownFormatNaming(implementation).ClassName}Implementation = wireClass(${ClassName}, [])`).join('\n\n')}
|
|
2929
3523
|
|
|
2930
|
-
export const wire${naming.ClassName} = envBranchedWire({
|
|
2931
|
-
test: wire${new UnknownFormatNaming(`${implementationTypes.at(-1)}-implementation`).ClassName},
|
|
2932
|
-
development: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName},
|
|
2933
|
-
production: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName}
|
|
2934
|
-
})
|
|
3524
|
+
export const wire${naming.ClassName} = envBranchedWire(${envBranchedWireArgument(`wire${new UnknownFormatNaming(`${implementationTypes.at(-1)}-implementation`).ClassName}`, `wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName}`)})
|
|
2935
3525
|
|
|
2936
3526
|
`.trim());
|
|
2937
3527
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
2938
3528
|
}
|
|
2939
3529
|
};
|
|
2940
3530
|
const scaffoldNewApplicationService = async (boundedContextFolder)=>{
|
|
2941
|
-
const name = await
|
|
3531
|
+
const name = await interaction_input({
|
|
3532
|
+
key: 'name',
|
|
2942
3533
|
message: 'Name: '
|
|
2943
3534
|
});
|
|
2944
3535
|
const naming = new UnknownFormatNaming(name);
|
|
2945
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
2946
|
-
const withWiring = ConfigFile.
|
|
3536
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3537
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
2947
3538
|
const wiringFolder = boundedContextFolder.subitem([
|
|
2948
3539
|
'wiring',
|
|
2949
3540
|
'application-services'
|
|
@@ -2958,7 +3549,7 @@ export class ${naming.ClassName}ApplicationService {
|
|
|
2958
3549
|
}
|
|
2959
3550
|
`.trim());
|
|
2960
3551
|
if (scaffoldUnitTests) applicationServicesFolder.createFile(`${naming.fileName}-application-service.spec.ts`, `
|
|
2961
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3552
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
2962
3553
|
${withWiring ? `import { type ${naming.ClassName}ApplicationService } from './${naming.fileName}-application-service'
|
|
2963
3554
|
import { wire${naming.ClassName}ApplicationService } from '../../wiring/application-services/wire-${naming.fileName}-application-service'` : `import { ${naming.ClassName}ApplicationService } from './${naming.fileName}-application-service'`}
|
|
2964
3555
|
|
|
@@ -2988,14 +3579,15 @@ export const wire${naming.ClassName}ApplicationService = wireClass(
|
|
|
2988
3579
|
}
|
|
2989
3580
|
};
|
|
2990
3581
|
const scaffoldNewBoundedContextUseCase = async ()=>{
|
|
2991
|
-
const name = await
|
|
3582
|
+
const name = await interaction_input({
|
|
3583
|
+
key: 'name',
|
|
2992
3584
|
message: 'Name:',
|
|
2993
3585
|
validate: (x)=>!!x.length
|
|
2994
3586
|
});
|
|
2995
3587
|
const { path } = new ProjectRoot();
|
|
2996
3588
|
const rootFolder = new Folder(path);
|
|
2997
3589
|
const folder = rootFolder.subitem([
|
|
2998
|
-
ConfigFile.Instance.data.rootFolder,
|
|
3590
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
2999
3591
|
'bounded-contexts',
|
|
3000
3592
|
name
|
|
3001
3593
|
]);
|
|
@@ -3006,25 +3598,26 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
3006
3598
|
'application',
|
|
3007
3599
|
'commands'
|
|
3008
3600
|
]);
|
|
3009
|
-
const commandName = await
|
|
3601
|
+
const commandName = await interaction_input({
|
|
3602
|
+
key: 'name',
|
|
3010
3603
|
message: 'Name: '
|
|
3011
3604
|
});
|
|
3012
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3605
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3013
3606
|
const naming = new UnknownFormatNaming(commandName);
|
|
3014
|
-
const withWiring = ConfigFile.
|
|
3015
|
-
const implementationType = await
|
|
3016
|
-
message: 'Command infrastructure implementation type:',
|
|
3017
|
-
default: ConfigFile.Instance.data.defaultPersistenceLayerImplementation
|
|
3018
|
-
});
|
|
3607
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3608
|
+
const { label: implementationType } = await promptImplementationType('Command infrastructure implementation type:', 'commands');
|
|
3019
3609
|
let addTestImplementation = false;
|
|
3020
3610
|
let testImplementationType = '';
|
|
3021
|
-
addTestImplementation = await
|
|
3611
|
+
addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
3612
|
+
key: 'withTestImplementation',
|
|
3022
3613
|
message: 'Add a test implementation for Command'
|
|
3023
3614
|
});
|
|
3024
|
-
if (addTestImplementation) testImplementationType = await
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3615
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test Command infrastructure implementation type:', 'commands', {
|
|
3616
|
+
existing: [
|
|
3617
|
+
implementationType
|
|
3618
|
+
],
|
|
3619
|
+
purpose: 'test'
|
|
3620
|
+
})).label;
|
|
3028
3621
|
const implementationTypes = [
|
|
3029
3622
|
implementationType,
|
|
3030
3623
|
testImplementationType
|
|
@@ -3035,7 +3628,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
3035
3628
|
ownerPath: boundedContextFolder.path,
|
|
3036
3629
|
labels: []
|
|
3037
3630
|
}, new UnknownFormatNaming(implementation).fileName);
|
|
3038
|
-
if (ConfigFile.
|
|
3631
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.createFile(`${naming.fileName}-command.ts`, `
|
|
3039
3632
|
import type { Handler } from '@domain-first/handlers'
|
|
3040
3633
|
|
|
3041
3634
|
export abstract class ${naming.ClassName}Command {
|
|
@@ -3052,7 +3645,7 @@ export abstract class ${naming.ClassName}Command {
|
|
|
3052
3645
|
if (scaffoldUnitTests) {
|
|
3053
3646
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3054
3647
|
const specFile = commandsFolder.createFile(`${naming.fileName}-command.spec.ts`, `
|
|
3055
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3648
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3056
3649
|
${withWiring ? `import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
|
|
3057
3650
|
import { wire${naming.ClassName}Command } from '../../wiring/commands/wire-${naming.fileName}-command'` : `import { ${implementationNaming.ClassName}${naming.ClassName}Command } from '../../infrastructure/commands/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}-command'
|
|
3058
3651
|
|
|
@@ -3072,7 +3665,7 @@ describe('${naming.withSpaces} command', () => {
|
|
|
3072
3665
|
`.trim());
|
|
3073
3666
|
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
|
|
3074
3667
|
}
|
|
3075
|
-
if (ConfigFile.
|
|
3668
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3076
3669
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3077
3670
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
3078
3671
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -3085,18 +3678,15 @@ ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fil
|
|
|
3085
3678
|
|
|
3086
3679
|
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Command, [])`).join('\n\n')}
|
|
3087
3680
|
|
|
3088
|
-
export const wire${naming.ClassName}Command = envBranchedWire({
|
|
3089
|
-
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
3090
|
-
development: wire${implementationNaming.ClassName}Implementation,
|
|
3091
|
-
production: wire${implementationNaming.ClassName}Implementation
|
|
3092
|
-
})
|
|
3681
|
+
export const wire${naming.ClassName}Command = envBranchedWire(${envBranchedWireArgument(`wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation`, `wire${implementationNaming.ClassName}Implementation`)})
|
|
3093
3682
|
`.trim());
|
|
3094
3683
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
3095
3684
|
}
|
|
3096
3685
|
};
|
|
3097
3686
|
const scaffold_new_domain_object_noAggregate = 'No aggregate';
|
|
3098
3687
|
const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
3099
|
-
const name = await
|
|
3688
|
+
const name = await interaction_input({
|
|
3689
|
+
key: 'name',
|
|
3100
3690
|
message: 'Name: '
|
|
3101
3691
|
});
|
|
3102
3692
|
const naming = new UnknownFormatNaming(name);
|
|
@@ -3105,7 +3695,8 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
|
3105
3695
|
'aggregates'
|
|
3106
3696
|
]);
|
|
3107
3697
|
const aggregateNames = aggregatesFolder.content.subfolderNames;
|
|
3108
|
-
const aggregate = aggregateNames.length ? await
|
|
3698
|
+
const aggregate = aggregateNames.length ? await interaction_select({
|
|
3699
|
+
key: 'aggregate',
|
|
3109
3700
|
message: 'Aggregate:',
|
|
3110
3701
|
choices: [
|
|
3111
3702
|
...aggregateNames,
|
|
@@ -3121,7 +3712,7 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
|
3121
3712
|
kindFolderName
|
|
3122
3713
|
]);
|
|
3123
3714
|
const fileName = `${naming.fileName}.${kind}`;
|
|
3124
|
-
const withTypes = ConfigFile.
|
|
3715
|
+
const withTypes = ConfigFile.backend.domainFirstPackages.includes('@domain-first/types');
|
|
3125
3716
|
folder.createFile(`${fileName}.ts`, withTypes ? `
|
|
3126
3717
|
import { domainType } from '@domain-first/types'
|
|
3127
3718
|
|
|
@@ -3131,7 +3722,7 @@ export class ${naming.ClassName} extends domainType() {
|
|
|
3131
3722
|
if (aggregate !== scaffold_new_domain_object_noAggregate) aggregatesFolder.subitem([
|
|
3132
3723
|
aggregate
|
|
3133
3724
|
]).file('index.ts').addLineIfMissing(`export * from './${kindFolderName}/${fileName}'`);
|
|
3134
|
-
const { testingLibrary } = ConfigFile.
|
|
3725
|
+
const { testingLibrary } = ConfigFile.backend;
|
|
3135
3726
|
if (testingLibrary) folder.createFile(`${fileName}.spec.ts`, `
|
|
3136
3727
|
import { describe, test, expect, beforeEach } from '${testingLibrary}'
|
|
3137
3728
|
import { ${naming.ClassName} } from './${fileName}'
|
|
@@ -3150,12 +3741,13 @@ describe('${naming.withSpaces}', () => {
|
|
|
3150
3741
|
`.trim());
|
|
3151
3742
|
};
|
|
3152
3743
|
const scaffoldNewDomainService = async (boundedContextFolder)=>{
|
|
3153
|
-
const portName = await
|
|
3744
|
+
const portName = await interaction_input({
|
|
3745
|
+
key: 'name',
|
|
3154
3746
|
message: 'Name:'
|
|
3155
3747
|
});
|
|
3156
3748
|
const naming = new UnknownFormatNaming(portName);
|
|
3157
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3158
|
-
const withWiring = ConfigFile.
|
|
3749
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3750
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3159
3751
|
const domainServicesFolder = boundedContextFolder.subitem([
|
|
3160
3752
|
'domain',
|
|
3161
3753
|
'services'
|
|
@@ -3166,7 +3758,7 @@ export class ${naming.ClassName}DomainService {
|
|
|
3166
3758
|
}
|
|
3167
3759
|
`.trim());
|
|
3168
3760
|
if (scaffoldUnitTests) domainServicesFolder.createFile(`${naming.fileName}-domain-service.spec.ts`, `
|
|
3169
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3761
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3170
3762
|
${withWiring ? `import { type ${naming.ClassName}DomainService } from './${naming.fileName}-domain-service'
|
|
3171
3763
|
import { wire${naming.ClassName}DomainService } from '../../wiring/domain-services/wire-${naming.fileName}-domain-service'` : `import { ${naming.ClassName}DomainService } from './${naming.fileName}-domain-service'`}
|
|
3172
3764
|
|
|
@@ -3200,7 +3792,7 @@ export const wire${naming.ClassName}DomainService = wireClass(
|
|
|
3200
3792
|
};
|
|
3201
3793
|
const errorNames = (boundedContextFolder)=>{
|
|
3202
3794
|
const isShared = boundedContextFolder.path === new Folder(new ProjectRoot().path).subitem([
|
|
3203
|
-
ConfigFile.Instance.data.rootFolder,
|
|
3795
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
3204
3796
|
'shared-kernel'
|
|
3205
3797
|
]).path;
|
|
3206
3798
|
return {
|
|
@@ -3235,12 +3827,14 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
3235
3827
|
...currentErrorNamespaces.map((x)=>`New error in namespace ${x}`),
|
|
3236
3828
|
'New namespace'
|
|
3237
3829
|
];
|
|
3238
|
-
const selectedVariant = await
|
|
3830
|
+
const selectedVariant = await interaction_select({
|
|
3239
3831
|
choices: variants,
|
|
3832
|
+
key: 'errorAction',
|
|
3240
3833
|
message: 'Action:'
|
|
3241
3834
|
});
|
|
3242
3835
|
if ('New error without namespace' === selectedVariant) {
|
|
3243
|
-
const errorName = await
|
|
3836
|
+
const errorName = await interaction_input({
|
|
3837
|
+
key: 'name',
|
|
3244
3838
|
message: 'Error name:'
|
|
3245
3839
|
});
|
|
3246
3840
|
const naming = new UnknownFormatNaming(errorName);
|
|
@@ -3249,7 +3843,8 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
3249
3843
|
return;
|
|
3250
3844
|
}
|
|
3251
3845
|
if ('New namespace' === selectedVariant) {
|
|
3252
|
-
const namespaceName = await
|
|
3846
|
+
const namespaceName = await interaction_input({
|
|
3847
|
+
key: 'name',
|
|
3253
3848
|
message: 'Namespace name:'
|
|
3254
3849
|
});
|
|
3255
3850
|
const { ClassName, fileName } = new UnknownFormatNaming(namespaceName);
|
|
@@ -3263,7 +3858,8 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
|
|
|
3263
3858
|
}
|
|
3264
3859
|
const namespace = selectedVariant.substring(23);
|
|
3265
3860
|
const namespaceNaming = new UnknownFormatNaming(namespace);
|
|
3266
|
-
const errorName = await
|
|
3861
|
+
const errorName = await interaction_input({
|
|
3862
|
+
key: 'name',
|
|
3267
3863
|
message: 'Error name:'
|
|
3268
3864
|
});
|
|
3269
3865
|
const { ClassName, fileName } = new UnknownFormatNaming(errorName);
|
|
@@ -3276,7 +3872,8 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
3276
3872
|
'rest'
|
|
3277
3873
|
]);
|
|
3278
3874
|
const controllers = restPresentationFolder.content.subfolderNames;
|
|
3279
|
-
let controller = await
|
|
3875
|
+
let controller = await interaction_select({
|
|
3876
|
+
key: 'controllerSelection',
|
|
3280
3877
|
message: 'Controller: ',
|
|
3281
3878
|
choices: [
|
|
3282
3879
|
...controllers,
|
|
@@ -3284,10 +3881,11 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
3284
3881
|
]
|
|
3285
3882
|
});
|
|
3286
3883
|
if ('New controller' === controller) {
|
|
3287
|
-
controller = await
|
|
3884
|
+
controller = await interaction_input({
|
|
3885
|
+
key: 'controllerName',
|
|
3288
3886
|
message: 'Name: '
|
|
3289
3887
|
});
|
|
3290
|
-
if (ConfigFile.
|
|
3888
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3291
3889
|
boundedContextFolder.subitem([
|
|
3292
3890
|
'wiring',
|
|
3293
3891
|
'presentation',
|
|
@@ -3309,7 +3907,8 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
3309
3907
|
`.trim());
|
|
3310
3908
|
}
|
|
3311
3909
|
}
|
|
3312
|
-
const method = await
|
|
3910
|
+
const method = await interaction_select({
|
|
3911
|
+
key: 'method',
|
|
3313
3912
|
message: 'Method:',
|
|
3314
3913
|
choices: [
|
|
3315
3914
|
'get',
|
|
@@ -3319,7 +3918,8 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
3319
3918
|
'put'
|
|
3320
3919
|
]
|
|
3321
3920
|
});
|
|
3322
|
-
const routeSegments = (await
|
|
3921
|
+
const routeSegments = (await interaction_input({
|
|
3922
|
+
key: 'path',
|
|
3323
3923
|
message: 'Relative path (split by "/"):'
|
|
3324
3924
|
})).split('/').filter((x)=>!!x);
|
|
3325
3925
|
const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
|
|
@@ -3334,7 +3934,7 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
3334
3934
|
method,
|
|
3335
3935
|
'endpoint'
|
|
3336
3936
|
].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
|
|
3337
|
-
const withWiring = ConfigFile.
|
|
3937
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3338
3938
|
const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
|
|
3339
3939
|
'..',
|
|
3340
3940
|
'..',
|
|
@@ -3384,7 +3984,7 @@ export const wire${endpointClassName} = wireClass(
|
|
|
3384
3984
|
[${dependencies.map((x)=>x.wireName).join(', ')}]
|
|
3385
3985
|
)
|
|
3386
3986
|
`.trim());
|
|
3387
|
-
wiringFolder.file('index.ts').
|
|
3987
|
+
wiringFolder.file('index.ts').addLineIfMissing(`export * from './${wireNaming.fileName}'`);
|
|
3388
3988
|
}
|
|
3389
3989
|
};
|
|
3390
3990
|
const scaffold_new_implementation_kindTitles = {
|
|
@@ -3393,11 +3993,6 @@ const scaffold_new_implementation_kindTitles = {
|
|
|
3393
3993
|
query: 'Queries',
|
|
3394
3994
|
port: 'Ports'
|
|
3395
3995
|
};
|
|
3396
|
-
const environments = [
|
|
3397
|
-
'test',
|
|
3398
|
-
'development',
|
|
3399
|
-
'production'
|
|
3400
|
-
];
|
|
3401
3996
|
const branchesOf = (wireFile, wireName)=>{
|
|
3402
3997
|
if (!wireFile.exists) return;
|
|
3403
3998
|
try {
|
|
@@ -3408,8 +4003,10 @@ const branchesOf = (wireFile, wireName)=>{
|
|
|
3408
4003
|
};
|
|
3409
4004
|
const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
3410
4005
|
const contracts = findContracts(ownerFolder.path);
|
|
3411
|
-
if (!contracts.length) return void
|
|
3412
|
-
const unit = await
|
|
4006
|
+
if (!contracts.length) return void report('No repositories, commands, queries or ports here yet.');
|
|
4007
|
+
const unit = await interaction_select({
|
|
4008
|
+
key: 'contract',
|
|
4009
|
+
id: unitId,
|
|
3413
4010
|
message: 'Contract:',
|
|
3414
4011
|
choices: contractKinds.flatMap((kind)=>{
|
|
3415
4012
|
const group = contracts.filter((x)=>x.kind === kind);
|
|
@@ -3423,33 +4020,47 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
|
3423
4020
|
}),
|
|
3424
4021
|
pageSize: 20
|
|
3425
4022
|
});
|
|
3426
|
-
const
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
})).trim();
|
|
4023
|
+
const kind = 'aggregate' === unit.kind ? 'repositories' : 'command' === unit.kind ? 'commands' : 'query' === unit.kind ? 'queries' : 'ports';
|
|
4024
|
+
const { label, saveForFutureUse } = await promptImplementationType('Implementation type:', kind, {
|
|
4025
|
+
existing: unit.labels,
|
|
4026
|
+
purpose: 'all',
|
|
4027
|
+
remember: false,
|
|
4028
|
+
crossContext: 'port' === unit.kind && hasNeighboringBoundedContext(ownerFolder.path)
|
|
4029
|
+
});
|
|
3434
4030
|
const { file, className } = createImplementation(ownerFolder, unit, label);
|
|
3435
|
-
|
|
4031
|
+
const branches = wire_branches_envBranches();
|
|
4032
|
+
const rememberFor = (environments)=>{
|
|
4033
|
+
if (!saveForFutureUse) return;
|
|
4034
|
+
if (systemImplementationChoices(kind, 'port' === unit.kind && hasNeighboringBoundedContext(ownerFolder.path)).some((choice)=>choice.value === label)) return;
|
|
4035
|
+
if (branches.test && environments.includes(branches.test)) rememberImplementation(kind, 'test', label);
|
|
4036
|
+
if (environments.some((environment)=>environment !== branches.test)) rememberImplementation(kind, 'primary', label);
|
|
4037
|
+
};
|
|
4038
|
+
if (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) return void rememberFor(branches.primary);
|
|
3436
4039
|
const wireFile = new File(ownerFolder.path).subitem(contractWireFile(unit).split('/'));
|
|
3437
4040
|
const wireName = `wire${contractClassName(unit)}`;
|
|
3438
|
-
const
|
|
3439
|
-
if (!
|
|
4041
|
+
const wired = branchesOf(wireFile, wireName);
|
|
4042
|
+
if (!wired) {
|
|
4043
|
+
rememberFor(branches.primary);
|
|
4044
|
+
report(`${wireFile.path} has no ${wireName} = envBranchedWire({...}): wire ${className} there yourself.`);
|
|
4045
|
+
return;
|
|
4046
|
+
}
|
|
3440
4047
|
const labelOfWire = new Map(unit.labels.map((x)=>[
|
|
3441
4048
|
implementationWireName(x),
|
|
3442
4049
|
x
|
|
3443
4050
|
]));
|
|
3444
|
-
const chosenEnvironments = await
|
|
4051
|
+
const chosenEnvironments = await interaction_checkbox({
|
|
4052
|
+
key: 'environments',
|
|
3445
4053
|
message: 'Environments:',
|
|
3446
4054
|
choices: [
|
|
3447
4055
|
...new Set([
|
|
3448
|
-
...
|
|
3449
|
-
|
|
4056
|
+
...branches.test ? [
|
|
4057
|
+
branches.test
|
|
4058
|
+
] : [],
|
|
4059
|
+
...branches.primary,
|
|
4060
|
+
...wired.keys()
|
|
3450
4061
|
])
|
|
3451
4062
|
].map((environment)=>{
|
|
3452
|
-
const current =
|
|
4063
|
+
const current = wired.get(environment);
|
|
3453
4064
|
return {
|
|
3454
4065
|
name: current ? `${environment} (now: ${labelOfWire.get(current) ?? current})` : environment,
|
|
3455
4066
|
value: environment
|
|
@@ -3457,6 +4068,7 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
|
3457
4068
|
}),
|
|
3458
4069
|
required: true
|
|
3459
4070
|
});
|
|
4071
|
+
rememberFor(chosenEnvironments);
|
|
3460
4072
|
const before = readWiredModule(wireFile.path, ownerFolder.path);
|
|
3461
4073
|
wireFile.update(addBranchedImplementation(wireFile.data, wireName, {
|
|
3462
4074
|
importLine: `import { ${className} } from '${relativeImport(wireFile.path, file.path)}'`,
|
|
@@ -3466,16 +4078,17 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
|
3466
4078
|
}));
|
|
3467
4079
|
const after = readWiredModule(wireFile.path, ownerFolder.path);
|
|
3468
4080
|
const unused = (before?.implementations ?? []).filter((x)=>!after?.implementations.some((y)=>y.className === x.className));
|
|
3469
|
-
for (const implementation of unused)
|
|
4081
|
+
for (const implementation of unused)report(`${implementation.className} is no longer used in any environment.`);
|
|
3470
4082
|
await wireNewImplementationDependencies(ownerFolder, wireFile, className, inMemoryRepositoryWiring(ownerFolder, unit, wireFile));
|
|
3471
4083
|
};
|
|
3472
4084
|
const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
|
|
3473
|
-
const name = await
|
|
4085
|
+
const name = await interaction_input({
|
|
4086
|
+
key: 'name',
|
|
3474
4087
|
message: 'Name: '
|
|
3475
4088
|
});
|
|
3476
4089
|
const naming = new UnknownFormatNaming(name);
|
|
3477
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3478
|
-
const withWiring = ConfigFile.
|
|
4090
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
4091
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3479
4092
|
const wiringFolder = boundedContextFolder.subitem([
|
|
3480
4093
|
'wiring',
|
|
3481
4094
|
'infrastructure-services'
|
|
@@ -3490,7 +4103,7 @@ export class ${naming.ClassName}InfrastructureService {
|
|
|
3490
4103
|
}
|
|
3491
4104
|
`.trim());
|
|
3492
4105
|
if (scaffoldUnitTests) infrastructureServicesFolder.createFile(`${naming.fileName}-infrastructure-service.spec.ts`, `
|
|
3493
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
4106
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3494
4107
|
${withWiring ? `import { type ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'
|
|
3495
4108
|
import { wire${naming.ClassName}InfrastructureService } from '../../wiring/infrastructure-services/wire-${naming.fileName}-infrastructure-service'` : `import { ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'`}
|
|
3496
4109
|
|
|
@@ -3524,25 +4137,26 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
3524
4137
|
'application',
|
|
3525
4138
|
'queries'
|
|
3526
4139
|
]);
|
|
3527
|
-
const queryName = await
|
|
4140
|
+
const queryName = await interaction_input({
|
|
4141
|
+
key: 'name',
|
|
3528
4142
|
message: 'Name: '
|
|
3529
4143
|
});
|
|
3530
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
4144
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3531
4145
|
const naming = new UnknownFormatNaming(queryName);
|
|
3532
|
-
const withWiring = ConfigFile.
|
|
3533
|
-
const implementationType = await
|
|
3534
|
-
message: 'Query infrastructure implementation type:',
|
|
3535
|
-
default: ConfigFile.Instance.data.defaultPersistenceLayerImplementation
|
|
3536
|
-
});
|
|
4146
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
4147
|
+
const { label: implementationType } = await promptImplementationType('Query infrastructure implementation type:', 'queries');
|
|
3537
4148
|
let addTestImplementation = false;
|
|
3538
4149
|
let testImplementationType = '';
|
|
3539
|
-
addTestImplementation = await
|
|
4150
|
+
addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
4151
|
+
key: 'withTestImplementation',
|
|
3540
4152
|
message: 'Add a test implementation for Query'
|
|
3541
4153
|
});
|
|
3542
|
-
if (addTestImplementation) testImplementationType = await
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
4154
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test Query infrastructure implementation type:', 'queries', {
|
|
4155
|
+
existing: [
|
|
4156
|
+
implementationType
|
|
4157
|
+
],
|
|
4158
|
+
purpose: 'test'
|
|
4159
|
+
})).label;
|
|
3546
4160
|
const implementationTypes = [
|
|
3547
4161
|
implementationType,
|
|
3548
4162
|
testImplementationType
|
|
@@ -3553,7 +4167,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
3553
4167
|
ownerPath: boundedContextFolder.path,
|
|
3554
4168
|
labels: []
|
|
3555
4169
|
}, new UnknownFormatNaming(implementation).fileName);
|
|
3556
|
-
if (ConfigFile.
|
|
4170
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.createFile(`${naming.fileName}-query.ts`, `
|
|
3557
4171
|
import type { Handler } from '@domain-first/handlers'
|
|
3558
4172
|
|
|
3559
4173
|
export abstract class ${naming.ClassName}Query {
|
|
@@ -3570,7 +4184,7 @@ export abstract class ${naming.ClassName}Query {
|
|
|
3570
4184
|
if (scaffoldUnitTests) {
|
|
3571
4185
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3572
4186
|
const specFile = queriesFolder.createFile(`${naming.fileName}-query.spec.ts`, `
|
|
3573
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
4187
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3574
4188
|
${withWiring ? `import { type ${naming.ClassName}Query } from './${naming.fileName}-query'
|
|
3575
4189
|
import { wire${naming.ClassName}Query } from '../../wiring/queries/wire-${naming.fileName}-query'` : `import { ${implementationNaming.ClassName}${naming.ClassName}Query } from '../../infrastructure/queries/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}-query'
|
|
3576
4190
|
|
|
@@ -3590,7 +4204,7 @@ describe('${naming.withSpaces} query', () => {
|
|
|
3590
4204
|
`.trim());
|
|
3591
4205
|
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
|
|
3592
4206
|
}
|
|
3593
|
-
if (ConfigFile.
|
|
4207
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3594
4208
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3595
4209
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
3596
4210
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -3603,11 +4217,7 @@ ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fil
|
|
|
3603
4217
|
|
|
3604
4218
|
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Query, [])`).join('\n\n')}
|
|
3605
4219
|
|
|
3606
|
-
export const wire${naming.ClassName}Query = envBranchedWire({
|
|
3607
|
-
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
3608
|
-
development: wire${implementationNaming.ClassName}Implementation,
|
|
3609
|
-
production: wire${implementationNaming.ClassName}Implementation
|
|
3610
|
-
})
|
|
4220
|
+
export const wire${naming.ClassName}Query = envBranchedWire(${envBranchedWireArgument(`wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation`, `wire${implementationNaming.ClassName}Implementation`)})
|
|
3611
4221
|
`.trim());
|
|
3612
4222
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
3613
4223
|
}
|
|
@@ -3617,13 +4227,14 @@ const scaffoldNewUseCase = async (boundedContextFolder)=>{
|
|
|
3617
4227
|
'application',
|
|
3618
4228
|
'use-cases'
|
|
3619
4229
|
]);
|
|
3620
|
-
const useCaseName = await
|
|
4230
|
+
const useCaseName = await interaction_input({
|
|
4231
|
+
key: 'name',
|
|
3621
4232
|
message: 'Name: '
|
|
3622
4233
|
});
|
|
3623
4234
|
const naming = new UnknownFormatNaming(useCaseName);
|
|
3624
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3625
|
-
const withWiring = ConfigFile.
|
|
3626
|
-
useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, ConfigFile.
|
|
4235
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
4236
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
4237
|
+
useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
3627
4238
|
import { defineHandler } from '@domain-first/handlers'
|
|
3628
4239
|
|
|
3629
4240
|
export class ${naming.ClassName}UseCase {
|
|
@@ -3646,7 +4257,7 @@ export class ${naming.ClassName}UseCase {
|
|
|
3646
4257
|
}
|
|
3647
4258
|
`.trim());
|
|
3648
4259
|
if (scaffoldUnitTests) useCasesFolder.createFile(`${naming.fileName}-use-case.spec.ts`, `
|
|
3649
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
4260
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3650
4261
|
${withWiring ? `import { type ${naming.ClassName}UseCase } from './${naming.fileName}-use-case'
|
|
3651
4262
|
import { wire${naming.ClassName}UseCase } from '../../wiring/use-cases/wire-${naming.fileName}-use-case'` : `import { ${naming.ClassName}UseCase } from './${naming.fileName}-use-case'`}
|
|
3652
4263
|
|
|
@@ -3680,7 +4291,8 @@ export const wire${naming.ClassName}UseCase = wireClass(
|
|
|
3680
4291
|
}
|
|
3681
4292
|
};
|
|
3682
4293
|
const scaffoldReactSharedHook = async (presentationReactFolder)=>{
|
|
3683
|
-
const name = await
|
|
4294
|
+
const name = await interaction_input({
|
|
4295
|
+
key: 'name',
|
|
3684
4296
|
message: 'Name without "use" (e.g. debounce): '
|
|
3685
4297
|
});
|
|
3686
4298
|
const { ClassName, fileName } = new UnknownFormatNaming(name.trim().replace(/^use-/, ''));
|
|
@@ -3693,7 +4305,8 @@ export const use${ClassName} = () => {
|
|
|
3693
4305
|
`.trim());
|
|
3694
4306
|
};
|
|
3695
4307
|
const scaffoldReactUIKitComponent = async (presentationReactFolder)=>{
|
|
3696
|
-
const name = await
|
|
4308
|
+
const name = await interaction_input({
|
|
4309
|
+
key: 'name',
|
|
3697
4310
|
message: 'Name: '
|
|
3698
4311
|
});
|
|
3699
4312
|
const { ClassName, fileName } = new UnknownFormatNaming(name);
|
|
@@ -3711,7 +4324,7 @@ export const ${ClassName}: FC<${ClassName}Props> = (props) => {
|
|
|
3711
4324
|
return <></>
|
|
3712
4325
|
}
|
|
3713
4326
|
`.trim());
|
|
3714
|
-
const { storybookFramework } = ConfigFile.Instance.data;
|
|
4327
|
+
const { storybookFramework } = ConfigFile.Instance.data.frontend?.react ?? {};
|
|
3715
4328
|
if (storybookFramework) componentFolder.createFile(`${fileName}.stories.tsx`, `
|
|
3716
4329
|
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
3717
4330
|
import { ${ClassName} } from './${fileName}'
|
|
@@ -3731,16 +4344,18 @@ export const Default: Story = {
|
|
|
3731
4344
|
`.trim());
|
|
3732
4345
|
};
|
|
3733
4346
|
const scaffoldReactWidget = async (presentationReactFolder)=>{
|
|
3734
|
-
const widgetName = await
|
|
4347
|
+
const widgetName = await interaction_input({
|
|
4348
|
+
key: 'name',
|
|
3735
4349
|
message: 'Name (folders split by "/"): ',
|
|
3736
4350
|
validate: NestedName.validate
|
|
3737
4351
|
});
|
|
3738
|
-
const widgetType = await
|
|
4352
|
+
const widgetType = await interaction_select({
|
|
3739
4353
|
choices: [
|
|
3740
4354
|
'monolithic',
|
|
3741
4355
|
'with separated ui',
|
|
3742
4356
|
'headless'
|
|
3743
4357
|
],
|
|
4358
|
+
key: 'widgetType',
|
|
3744
4359
|
message: 'Type: '
|
|
3745
4360
|
});
|
|
3746
4361
|
const { folders, folderName, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
|
|
@@ -3799,7 +4414,7 @@ export const ${ClassName}WidgetUI: FC<${ClassName}WidgetUIProps> = (props) => {
|
|
|
3799
4414
|
return <></>
|
|
3800
4415
|
}
|
|
3801
4416
|
`.trim());
|
|
3802
|
-
const { storybookFramework } = ConfigFile.Instance.data;
|
|
4417
|
+
const { storybookFramework } = ConfigFile.Instance.data.frontend?.react ?? {};
|
|
3803
4418
|
if (storybookFramework) folder.subitem([
|
|
3804
4419
|
'ui'
|
|
3805
4420
|
]).createFile(`${uiFileName}.stories.tsx`, `
|
|
@@ -3865,4 +4480,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
3865
4480
|
break;
|
|
3866
4481
|
}
|
|
3867
4482
|
};
|
|
3868
|
-
export { addIntegration, initializeUseCase, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, savePendingChanges, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, wireDependency };
|
|
4483
|
+
export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
|