@domain-first/project-structure 7.2.0 → 8.1.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 +125 -26
- package/dist/201.js +87 -338
- package/dist/287.js +1235 -575
- package/dist/561.js +519 -0
- package/dist/711.js +22 -0
- package/dist/870.js +438 -0
- package/dist/agent-cli.d.ts +379 -0
- package/dist/agent-cli.spec.d.ts +1 -0
- package/dist/agent-identifiers.d.ts +4 -0
- package/dist/agent-requests.d.ts +490 -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 +3645 -584
- package/dist/index.js +20 -7
- package/dist/init.cjs +717 -122
- package/dist/init.js +24 -12
- package/dist/integration.cjs +3783 -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/module-move.d.ts +6 -2
- package/dist/next-app.d.ts +7 -0
- package/dist/react-module-move.d.ts +17 -2
- package/dist/react.cjs +5181 -421
- 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 +14 -8
- 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',
|
|
@@ -2010,7 +2211,8 @@ const projectImports = (projectRoot)=>{
|
|
|
2010
2211
|
importsOf
|
|
2011
2212
|
};
|
|
2012
2213
|
};
|
|
2013
|
-
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content })=>{
|
|
2214
|
+
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
2215
|
+
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
2014
2216
|
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
2015
2217
|
const barrels = new Set();
|
|
2016
2218
|
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
@@ -2047,14 +2249,14 @@ const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyF
|
|
|
2047
2249
|
moved: moves.has(oldFile)
|
|
2048
2250
|
});
|
|
2049
2251
|
};
|
|
2050
|
-
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile,
|
|
2252
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile, stopFor(file));
|
|
2051
2253
|
const updated = [];
|
|
2052
2254
|
for (const [file, content] of codeFiles){
|
|
2053
2255
|
const newFile = moves.get(file);
|
|
2054
2256
|
const next = rewrite(content, file, newFile ?? file);
|
|
2055
2257
|
if (newFile && newFile !== file) {
|
|
2056
2258
|
new File(newFile).data = next;
|
|
2057
|
-
new File(file).delete(
|
|
2259
|
+
new File(file).delete(stopFor(file));
|
|
2058
2260
|
} else if (next !== content) {
|
|
2059
2261
|
new File(file).update(next);
|
|
2060
2262
|
if (!newFile) updated.push(file);
|
|
@@ -2248,7 +2450,7 @@ const isolationAllows = (rootFolderPath, from, to)=>{
|
|
|
2248
2450
|
const fromOwner = ownerOf(rootFolderPath, from);
|
|
2249
2451
|
const toOwner = ownerOf(rootFolderPath, to);
|
|
2250
2452
|
if (!fromOwner || !toOwner?.context) return true;
|
|
2251
|
-
if (fromOwner.context) return fromOwner.context === toOwner.context;
|
|
2453
|
+
if (fromOwner.context) return fromOwner.context === toOwner.context || true === crossContextImportAllowed(from, to);
|
|
2252
2454
|
const inside = (folder)=>to === node_path.join(toOwner.path, folder) || to.startsWith(node_path.join(toOwner.path, folder) + node_path.sep);
|
|
2253
2455
|
return inside('domain/errors') || from.replace(codeExtension, '') === inMemoryDbFile(rootFolderPath).replace(codeExtension, '') && inside('domain');
|
|
2254
2456
|
};
|
|
@@ -2395,92 +2597,140 @@ const projectRelative = (fromFile, toFile)=>{
|
|
|
2395
2597
|
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toFile.replace(codeExtension, '')));
|
|
2396
2598
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
2397
2599
|
};
|
|
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;
|
|
2600
|
+
const contractKinds = [
|
|
2601
|
+
'aggregate',
|
|
2602
|
+
'command',
|
|
2603
|
+
'query',
|
|
2604
|
+
'port'
|
|
2605
|
+
];
|
|
2606
|
+
const implementations_withWiring = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
2607
|
+
const withHandlers = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers');
|
|
2608
|
+
const contractFile = (unit)=>'aggregate' === unit.kind ? `domain/aggregates/${unit.name}/${unit.name}-repository.ts` : kindLayouts[unit.kind].files(unit, [])[0];
|
|
2609
|
+
const findContracts = (ownerPath)=>findBackendUnits(ownerPath).filter((unit)=>contractKinds.includes(unit.kind) && node_fs.existsSync(node_path.join(ownerPath, contractFile(unit))));
|
|
2610
|
+
const implementationWireName = (label)=>`wire${new UnknownFormatNaming(label).ClassName}Implementation`;
|
|
2611
|
+
const contractClassName = (unit)=>kindLayouts[unit.kind].core(new UnknownFormatNaming(unit.name).ClassName);
|
|
2612
|
+
const implementationClassName = (unit, label)=>`${new UnknownFormatNaming(label).ClassName}${contractClassName(unit)}`;
|
|
2613
|
+
const implementationFile = (unit, label)=>{
|
|
2614
|
+
const { implementations } = kindLayouts[unit.kind];
|
|
2615
|
+
return kindLayouts[unit.kind].files(unit, [
|
|
2616
|
+
label
|
|
2617
|
+
]).find((file)=>file.startsWith(`${implementations}/`));
|
|
2618
|
+
};
|
|
2619
|
+
const contractWireFile = (unit)=>kindLayouts[unit.kind].files(unit, []).find((file)=>file.startsWith('wiring/'));
|
|
2620
|
+
const handlerImplementation = (ContractName, ClassName, contractImport)=>withHandlers() ? `
|
|
2621
|
+
import { defineHandler } from '@domain-first/handlers'
|
|
2622
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2623
|
+
|
|
2624
|
+
export class ${ClassName} extends ${ContractName} {
|
|
2625
|
+
constructor() {
|
|
2626
|
+
super()
|
|
2449
2627
|
}
|
|
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.');
|
|
2628
|
+
|
|
2629
|
+
handle = defineHandler({
|
|
2630
|
+
inputSchema: ${ContractName}.inputSchema,
|
|
2631
|
+
outputSchema: ${ContractName}.outputSchema,
|
|
2632
|
+
handler: async (input) => {
|
|
2633
|
+
return {}
|
|
2634
|
+
}
|
|
2635
|
+
})
|
|
2636
|
+
}
|
|
2637
|
+
`.trim() : `
|
|
2638
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2639
|
+
|
|
2640
|
+
export class ${ClassName} extends ${ContractName} {
|
|
2641
|
+
constructor() {
|
|
2642
|
+
super()
|
|
2481
2643
|
}
|
|
2482
|
-
}
|
|
2483
|
-
|
|
2644
|
+
}
|
|
2645
|
+
`.trim();
|
|
2646
|
+
const createImplementation = (ownerFolder, unit, label)=>{
|
|
2647
|
+
const naming = new UnknownFormatNaming(unit.name);
|
|
2648
|
+
const ContractName = contractClassName(unit);
|
|
2649
|
+
const className = implementationClassName(unit, label);
|
|
2650
|
+
const [folder, fileName] = [
|
|
2651
|
+
node_path.dirname(implementationFile(unit, label)),
|
|
2652
|
+
node_path.basename(implementationFile(unit, label))
|
|
2653
|
+
];
|
|
2654
|
+
const implementationFolder = ownerFolder.subitem(folder.split('/'));
|
|
2655
|
+
const inMemoryDb = !implementations_withWiring() && usesInMemoryDb(label);
|
|
2656
|
+
switch(unit.kind){
|
|
2657
|
+
case 'aggregate':
|
|
2658
|
+
{
|
|
2659
|
+
const contractImport = `../../../domain/aggregates/${unit.name}`;
|
|
2660
|
+
if (inMemoryDb) {
|
|
2661
|
+
const section = addInMemoryDbSection(naming, ownerFolder.subitem([
|
|
2662
|
+
'domain',
|
|
2663
|
+
'aggregates',
|
|
2664
|
+
unit.name
|
|
2665
|
+
]).path);
|
|
2666
|
+
const file = implementationFolder.createFile(fileName, `
|
|
2667
|
+
${inMemoryDbTypeImport(implementationFolder.subitem([
|
|
2668
|
+
fileName
|
|
2669
|
+
]).path)}
|
|
2670
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2671
|
+
|
|
2672
|
+
export class ${className} implements ${ContractName} {
|
|
2673
|
+
${inMemoryDbSectionMembers(section, false)}
|
|
2674
|
+
}
|
|
2675
|
+
`.trim());
|
|
2676
|
+
return {
|
|
2677
|
+
file,
|
|
2678
|
+
className
|
|
2679
|
+
};
|
|
2680
|
+
}
|
|
2681
|
+
const file = implementationFolder.createFile(fileName, `
|
|
2682
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2683
|
+
|
|
2684
|
+
export class ${className} implements ${ContractName} {
|
|
2685
|
+
constructor() {}
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
`.trim());
|
|
2689
|
+
return {
|
|
2690
|
+
file,
|
|
2691
|
+
className
|
|
2692
|
+
};
|
|
2693
|
+
}
|
|
2694
|
+
case 'command':
|
|
2695
|
+
case 'query':
|
|
2696
|
+
{
|
|
2697
|
+
const folderName = 'command' === unit.kind ? 'commands' : 'queries';
|
|
2698
|
+
const file = implementationFolder.createFile(fileName, handlerImplementation(ContractName, className, `../../../application/${folderName}/${naming.fileName}-${unit.kind}`));
|
|
2699
|
+
if (inMemoryDb) injectInMemoryDb(file, className);
|
|
2700
|
+
return {
|
|
2701
|
+
file,
|
|
2702
|
+
className
|
|
2703
|
+
};
|
|
2704
|
+
}
|
|
2705
|
+
case 'port':
|
|
2706
|
+
{
|
|
2707
|
+
const file = implementationFolder.createFile(fileName, `
|
|
2708
|
+
import { ${ContractName} } from '../../../application/ports/${naming.fileName}'
|
|
2709
|
+
|
|
2710
|
+
export class ${className} extends ${ContractName} {
|
|
2711
|
+
|
|
2712
|
+
}
|
|
2713
|
+
`.trim());
|
|
2714
|
+
return {
|
|
2715
|
+
file,
|
|
2716
|
+
className
|
|
2717
|
+
};
|
|
2718
|
+
}
|
|
2719
|
+
default:
|
|
2720
|
+
throw new Error(`${unit.kind} has no implementations`);
|
|
2721
|
+
}
|
|
2722
|
+
};
|
|
2723
|
+
const inMemoryRepositoryWiring = (ownerFolder, unit, wireFile)=>(implementation, dependency)=>{
|
|
2724
|
+
if ('aggregate' !== unit.kind || !isInMemoryDb(dependency)) return false;
|
|
2725
|
+
keepInMemoryDbSection(new File(implementation.file), addInMemoryDbSection(new UnknownFormatNaming(unit.name), ownerFolder.subitem([
|
|
2726
|
+
'domain',
|
|
2727
|
+
'aggregates',
|
|
2728
|
+
unit.name
|
|
2729
|
+
]).path));
|
|
2730
|
+
wireInMemoryDb(wireFile, implementation.className);
|
|
2731
|
+
return true;
|
|
2732
|
+
};
|
|
2733
|
+
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
2484
2734
|
const prefix = `${folders.join('-')}-`;
|
|
2485
2735
|
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
2486
2736
|
return [
|
|
@@ -2497,7 +2747,7 @@ const findReactModules = (reactFolder, kind)=>{
|
|
|
2497
2747
|
const modules = 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
2498
2748
|
const folders = node_path.relative(node_path.join(reactFolder, 'pages'), node_path.dirname(file)).split(node_path.sep).filter((segment)=>!!segment);
|
|
2499
2749
|
const fileBase = node_path.basename(file, '-page.tsx');
|
|
2500
|
-
const name =
|
|
2750
|
+
const name = react_module_move_nestedName(folders, fileBase);
|
|
2501
2751
|
return {
|
|
2502
2752
|
kind,
|
|
2503
2753
|
name,
|
|
@@ -2530,7 +2780,14 @@ const validateMove = (reactFolder, module, rawName)=>{
|
|
|
2530
2780
|
if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
|
|
2531
2781
|
return true;
|
|
2532
2782
|
};
|
|
2533
|
-
const
|
|
2783
|
+
const routeFolder = (appFolder, rawName)=>{
|
|
2784
|
+
const { folders, folderName } = new NestedName(rawName);
|
|
2785
|
+
return node_path.join(appFolder, ...folders, folderName);
|
|
2786
|
+
};
|
|
2787
|
+
const routeFiles = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(folder, {
|
|
2788
|
+
withFileTypes: true
|
|
2789
|
+
}).filter((entry)=>entry.isFile()).map((entry)=>node_path.join(folder, entry.name)) : [];
|
|
2790
|
+
const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
2534
2791
|
const newName = new NestedName(rawName);
|
|
2535
2792
|
const target = targetPath(reactFolder, module, rawName);
|
|
2536
2793
|
const newClassName = newName.ClassName;
|
|
@@ -2538,7 +2795,19 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2538
2795
|
const oldFolder = 'page' === module.kind ? node_path.dirname(module.path) : module.path;
|
|
2539
2796
|
const newFolder = 'page' === module.kind ? node_path.dirname(target) : target;
|
|
2540
2797
|
const ownsPath = (candidate)=>'page' === module.kind ? node_path.dirname(candidate) === oldFolder && new RegExp(`^${escapeRegExp(module.fileBase)}-page(?:\\.|$)`).test(node_path.basename(candidate)) : candidate === oldFolder || candidate.startsWith(`${oldFolder}${node_path.sep}`);
|
|
2798
|
+
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
2799
|
+
const routeTarget = (candidate)=>{
|
|
2800
|
+
if (!route) return;
|
|
2801
|
+
const file = [
|
|
2802
|
+
...routeFileSet
|
|
2803
|
+
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
2804
|
+
if (!file) return;
|
|
2805
|
+
const moved = node_path.join(route.to, node_path.relative(route.from, file));
|
|
2806
|
+
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
2807
|
+
};
|
|
2541
2808
|
const movedPath = (candidate)=>{
|
|
2809
|
+
const routed = routeTarget(candidate);
|
|
2810
|
+
if (routed) return routed;
|
|
2542
2811
|
if (!ownsPath(candidate)) return;
|
|
2543
2812
|
const segments = node_path.relative(oldFolder, candidate).split(node_path.sep);
|
|
2544
2813
|
const last = segments.length - 1;
|
|
@@ -2546,7 +2815,10 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2546
2815
|
return node_path.join(newFolder, ...segments);
|
|
2547
2816
|
};
|
|
2548
2817
|
const moduleFiles = 'page' === module.kind ? node_fs.readdirSync(oldFolder).map((name)=>node_path.join(oldFolder, name)).filter((file)=>node_fs.statSync(file).isFile() && ownsPath(file)) : walk(oldFolder);
|
|
2549
|
-
const moves = new Map(
|
|
2818
|
+
const moves = new Map([
|
|
2819
|
+
...moduleFiles,
|
|
2820
|
+
...routeFileSet
|
|
2821
|
+
].map((file)=>[
|
|
2550
2822
|
file,
|
|
2551
2823
|
movedPath(file) ?? file
|
|
2552
2824
|
]));
|
|
@@ -2561,6 +2833,7 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2561
2833
|
return stageModuleMove({
|
|
2562
2834
|
projectRoot,
|
|
2563
2835
|
stopAt: reactFolder,
|
|
2836
|
+
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
2564
2837
|
moves,
|
|
2565
2838
|
movedPath,
|
|
2566
2839
|
rename: (content, { moved })=>{
|
|
@@ -2569,11 +2842,423 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2569
2842
|
}
|
|
2570
2843
|
});
|
|
2571
2844
|
};
|
|
2845
|
+
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
2846
|
+
if ('ports' === kind) return crossContext ? [
|
|
2847
|
+
{
|
|
2848
|
+
name: 'System: cross-context (calls handlers in another bounded context)',
|
|
2849
|
+
value: crossContextImplementation
|
|
2850
|
+
}
|
|
2851
|
+
] : [];
|
|
2852
|
+
return ConfigFile.exists && usesInMemoryDb('in-memory') ? [
|
|
2853
|
+
{
|
|
2854
|
+
name: 'System: in-memory (uses the shared in-memory database)',
|
|
2855
|
+
value: 'in-memory'
|
|
2856
|
+
}
|
|
2857
|
+
] : [];
|
|
2858
|
+
};
|
|
2859
|
+
const configurationSections = [
|
|
2860
|
+
'project',
|
|
2861
|
+
'backend',
|
|
2862
|
+
'frontend'
|
|
2863
|
+
];
|
|
2864
|
+
const configureProject = async (config)=>{
|
|
2865
|
+
const rootFolder = await input({
|
|
2866
|
+
message: 'Root folder (use "/" for inner folders):',
|
|
2867
|
+
default: config.project.rootFolder,
|
|
2868
|
+
validate: (value)=>value.trim() ? true : 'Root folder is required'
|
|
2869
|
+
});
|
|
2870
|
+
ConfigFile.update({
|
|
2871
|
+
project: {
|
|
2872
|
+
...config.project,
|
|
2873
|
+
rootFolder: rootFolder.trim()
|
|
2874
|
+
}
|
|
2875
|
+
});
|
|
2876
|
+
};
|
|
2877
|
+
const createTestBranch = Symbol('create-test-branch');
|
|
2878
|
+
const noTestBranch = Symbol('no-test-branch');
|
|
2879
|
+
const promptEnvBranches = async (current)=>{
|
|
2880
|
+
const kind = await prompts_select({
|
|
2881
|
+
message: 'envBranchedWire branches:',
|
|
2882
|
+
choices: [
|
|
2883
|
+
{
|
|
2884
|
+
name: 'Default: test, development, production by NODE_ENV',
|
|
2885
|
+
value: 'default'
|
|
2886
|
+
},
|
|
2887
|
+
{
|
|
2888
|
+
name: 'Custom branches',
|
|
2889
|
+
value: 'custom'
|
|
2890
|
+
}
|
|
2891
|
+
],
|
|
2892
|
+
default: current ? 'custom' : 'default'
|
|
2893
|
+
});
|
|
2894
|
+
if ('default' === kind) return;
|
|
2895
|
+
const parse = (value)=>value.split(',').map((name)=>name.trim()).filter(Boolean);
|
|
2896
|
+
const names = parse(await input({
|
|
2897
|
+
message: 'Branches (comma-separated):',
|
|
2898
|
+
default: current?.names.join(', '),
|
|
2899
|
+
validate: (value)=>{
|
|
2900
|
+
const names = parse(value);
|
|
2901
|
+
if (!names.length) return 'Enter at least one branch.';
|
|
2902
|
+
if (1 === names.length && 'test' === names[0]) return 'Add a branch for primary implementations besides test.';
|
|
2903
|
+
const invalid = names.find((name)=>!branchNameSchema.safeParse(name).success);
|
|
2904
|
+
if (invalid) return `${invalid}: use lowercase letters and digits, e.g. staging.`;
|
|
2905
|
+
return new Set(names).size === names.length ? true : 'Branch names must be unique.';
|
|
2906
|
+
}
|
|
2907
|
+
}));
|
|
2908
|
+
const test = await prompts_select({
|
|
2909
|
+
message: 'Test branch:',
|
|
2910
|
+
choices: [
|
|
2911
|
+
...names.map((name)=>({
|
|
2912
|
+
name,
|
|
2913
|
+
value: name,
|
|
2914
|
+
disabled: 1 === names.length ? '(the only branch)' : false
|
|
2915
|
+
})),
|
|
2916
|
+
...names.includes('test') ? [] : [
|
|
2917
|
+
{
|
|
2918
|
+
name: 'Create a "test" branch',
|
|
2919
|
+
value: createTestBranch
|
|
2920
|
+
}
|
|
2921
|
+
],
|
|
2922
|
+
{
|
|
2923
|
+
name: 'No test branch: every branch uses the primary implementation',
|
|
2924
|
+
value: noTestBranch
|
|
2925
|
+
}
|
|
2926
|
+
],
|
|
2927
|
+
default: current && !current.test ? noTestBranch : current?.test && names.includes(current.test) ? current.test : names.includes('test') ? 'test' : createTestBranch
|
|
2928
|
+
});
|
|
2929
|
+
if (test === noTestBranch) return {
|
|
2930
|
+
names
|
|
2931
|
+
};
|
|
2932
|
+
return test === createTestBranch ? {
|
|
2933
|
+
names: [
|
|
2934
|
+
...names,
|
|
2935
|
+
'test'
|
|
2936
|
+
],
|
|
2937
|
+
test: 'test'
|
|
2938
|
+
} : {
|
|
2939
|
+
names,
|
|
2940
|
+
test
|
|
2941
|
+
};
|
|
2942
|
+
};
|
|
2943
|
+
const configureBackend = async (config)=>{
|
|
2944
|
+
const current = config.backend;
|
|
2945
|
+
const domainFirstPackages = await prompts_checkbox({
|
|
2946
|
+
message: '@domain-first packages',
|
|
2947
|
+
choices: config_file_domainFirstPackages.map((value)=>({
|
|
2948
|
+
name: value,
|
|
2949
|
+
value,
|
|
2950
|
+
checked: current?.domainFirstPackages.includes(value) ?? false
|
|
2951
|
+
}))
|
|
2952
|
+
});
|
|
2953
|
+
const envBranches = domainFirstPackages.includes('@domain-first/wire') ? await promptEnvBranches(current?.envBranches) : current?.envBranches;
|
|
2954
|
+
const withInMemoryDb = await prompts_confirm({
|
|
2955
|
+
message: 'Scaffold in-memory DB for test implementations',
|
|
2956
|
+
default: current ? Boolean(current.withInMemoryDb) : true
|
|
2957
|
+
});
|
|
2958
|
+
const withTests = await prompts_confirm({
|
|
2959
|
+
message: 'Scaffold unit tests',
|
|
2960
|
+
default: current ? Boolean(current.testingLibrary) : true
|
|
2961
|
+
});
|
|
2962
|
+
const testingLibrary = withTests ? await input({
|
|
2963
|
+
message: 'Unit testing library:',
|
|
2964
|
+
default: current?.testingLibrary ?? 'vitest'
|
|
2965
|
+
}) : void 0;
|
|
2966
|
+
ConfigFile.update({
|
|
2967
|
+
backend: {
|
|
2968
|
+
...current,
|
|
2969
|
+
domainFirstPackages,
|
|
2970
|
+
envBranches,
|
|
2971
|
+
withInMemoryDb,
|
|
2972
|
+
testingLibrary,
|
|
2973
|
+
rules: scaffoldBackendRules(current?.rules)
|
|
2974
|
+
}
|
|
2975
|
+
});
|
|
2976
|
+
const rootFolder = new Folder(new ProjectRoot().path);
|
|
2977
|
+
const rootFolderName = config.project.rootFolder;
|
|
2978
|
+
const wiringFolder = rootFolder.subitem([
|
|
2979
|
+
rootFolderName,
|
|
2980
|
+
'shared-kernel',
|
|
2981
|
+
'wiring'
|
|
2982
|
+
]);
|
|
2983
|
+
const notes = [];
|
|
2984
|
+
const envBranchedWireExisted = new File(node_path.join(wiringFolder.path, 'env-branched-wire.ts')).exists;
|
|
2985
|
+
if (domainFirstPackages.includes('@domain-first/wire') && envBranchedWireExisted && JSON.stringify(envBranches ?? null) !== JSON.stringify(current?.envBranches ?? null)) {
|
|
2986
|
+
const { names } = envBranches ?? defaultEnvBranches;
|
|
2987
|
+
notes.push(`${rootFolderName}/shared-kernel/wiring/env-branched-wire.ts and existing envBranchedWire calls keep their branches: change them to ${names.join(', ')} yourself`);
|
|
2988
|
+
}
|
|
2989
|
+
withoutOverwrites(()=>{
|
|
2990
|
+
if (domainFirstPackages.includes('@domain-first/wire')) wiringFolder.createFile('env-branched-wire.ts', envBranchedWireSource());
|
|
2991
|
+
if (withInMemoryDb) scaffoldInMemoryDb(rootFolder.subitem([
|
|
2992
|
+
rootFolderName,
|
|
2993
|
+
'shared-kernel'
|
|
2994
|
+
]));
|
|
2995
|
+
});
|
|
2996
|
+
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(', ')})`);
|
|
2997
|
+
return notes;
|
|
2998
|
+
};
|
|
2999
|
+
const configureFrontend = async (config)=>{
|
|
3000
|
+
const currentFramework = config.frontend?.react?.framework ?? (hasDependency('next') ? 'next' : 'react');
|
|
3001
|
+
const framework = await prompts_select({
|
|
3002
|
+
message: 'Frontend framework:',
|
|
3003
|
+
choices: [
|
|
3004
|
+
{
|
|
3005
|
+
name: 'React',
|
|
3006
|
+
value: 'react'
|
|
3007
|
+
},
|
|
3008
|
+
{
|
|
3009
|
+
name: 'Next.js',
|
|
3010
|
+
value: 'next'
|
|
3011
|
+
}
|
|
3012
|
+
],
|
|
3013
|
+
default: currentFramework
|
|
3014
|
+
});
|
|
3015
|
+
const withNextAdapter = 'next' === framework && config.backend ? await askNextAdapter({
|
|
3016
|
+
nextSelected: true
|
|
3017
|
+
}) : false;
|
|
3018
|
+
const withStorybook = await prompts_confirm({
|
|
3019
|
+
message: 'Use Storybook',
|
|
3020
|
+
default: config.frontend?.react ? Boolean(config.frontend.react.storybookFramework) : true
|
|
3021
|
+
});
|
|
3022
|
+
const storybookFramework = withStorybook ? storybookFrameworkPackage : void 0;
|
|
3023
|
+
ConfigFile.update({
|
|
3024
|
+
frontend: {
|
|
3025
|
+
...config.frontend,
|
|
3026
|
+
react: {
|
|
3027
|
+
...config.frontend?.react,
|
|
3028
|
+
framework,
|
|
3029
|
+
storybookFramework
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
});
|
|
3033
|
+
return {
|
|
3034
|
+
withNextAdapter,
|
|
3035
|
+
nextSteps: [
|
|
3036
|
+
...missingPackages('next' === framework ? [
|
|
3037
|
+
'next',
|
|
3038
|
+
'react',
|
|
3039
|
+
'react-dom'
|
|
3040
|
+
] : [
|
|
3041
|
+
'react',
|
|
3042
|
+
'react-dom'
|
|
3043
|
+
]),
|
|
3044
|
+
...withStorybook ? await addStorybook() : []
|
|
3045
|
+
]
|
|
3046
|
+
};
|
|
3047
|
+
};
|
|
3048
|
+
const configureRest = async (withNextAdapter)=>{
|
|
3049
|
+
const backend = ConfigFile.Instance.data.backend;
|
|
3050
|
+
if (!backend) return [];
|
|
3051
|
+
const withRest = backend.domainFirstPackages.includes('@domain-first/handlers-rest');
|
|
3052
|
+
const nextSelected = ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
3053
|
+
if (void 0 === withNextAdapter && (withRest || nextSelected)) withNextAdapter = await askNextAdapter();
|
|
3054
|
+
if (!withRest && !withNextAdapter) return [];
|
|
3055
|
+
if (withNextAdapter && !withRest) ConfigFile.update({
|
|
3056
|
+
backend: {
|
|
3057
|
+
...backend,
|
|
3058
|
+
domainFirstPackages: [
|
|
3059
|
+
...backend.domainFirstPackages,
|
|
3060
|
+
'@domain-first/handlers-rest'
|
|
3061
|
+
]
|
|
3062
|
+
}
|
|
3063
|
+
});
|
|
3064
|
+
return scaffoldRestEndpointGeneratorFiles({
|
|
3065
|
+
withNextAdapter: withNextAdapter ?? false
|
|
3066
|
+
});
|
|
3067
|
+
};
|
|
3068
|
+
const initializeUseCase = async (section)=>{
|
|
3069
|
+
const existing = ConfigFile.exists;
|
|
3070
|
+
if (!existing) ConfigFile.write({
|
|
3071
|
+
project: {
|
|
3072
|
+
rootFolder: 'src'
|
|
3073
|
+
}
|
|
3074
|
+
});
|
|
3075
|
+
let sections = configurationSections;
|
|
3076
|
+
if (section) sections = 'project' === section || existing ? [
|
|
3077
|
+
section
|
|
3078
|
+
] : [
|
|
3079
|
+
'project',
|
|
3080
|
+
section
|
|
3081
|
+
];
|
|
3082
|
+
else if (existing) {
|
|
3083
|
+
const selected = await prompts_select({
|
|
3084
|
+
message: 'Configuration section:',
|
|
3085
|
+
choices: [
|
|
3086
|
+
...configurationSections.map((value)=>({
|
|
3087
|
+
name: `${value[0].toUpperCase()}${value.slice(1)}${ConfigFile.Instance.data[value] ? '' : ' (not configured)'}`,
|
|
3088
|
+
value
|
|
3089
|
+
})),
|
|
3090
|
+
{
|
|
3091
|
+
name: 'All sections',
|
|
3092
|
+
value: 'all'
|
|
3093
|
+
}
|
|
3094
|
+
]
|
|
3095
|
+
});
|
|
3096
|
+
sections = 'all' === selected ? configurationSections : [
|
|
3097
|
+
selected
|
|
3098
|
+
];
|
|
3099
|
+
}
|
|
3100
|
+
const nextSteps = [];
|
|
3101
|
+
let backendConfigured = false;
|
|
3102
|
+
let withNextAdapter;
|
|
3103
|
+
for (const currentSection of sections){
|
|
3104
|
+
console.log(`\n${currentSection[0].toUpperCase()}${currentSection.slice(1)} configuration`);
|
|
3105
|
+
if (!section && sections.length > 1 && !await prompts_confirm({
|
|
3106
|
+
message: `Configure ${currentSection} now?`,
|
|
3107
|
+
default: true
|
|
3108
|
+
})) {
|
|
3109
|
+
if ('project' === currentSection) console.log(`Keeping project root folder: ${ConfigFile.Instance.data.project.rootFolder}.`);
|
|
3110
|
+
nextSteps.push(`configure ${currentSection} later with df-init --section ${currentSection}`);
|
|
3111
|
+
continue;
|
|
3112
|
+
}
|
|
3113
|
+
const config = ConfigFile.Instance.data;
|
|
3114
|
+
switch(currentSection){
|
|
3115
|
+
case 'project':
|
|
3116
|
+
await configureProject(config);
|
|
3117
|
+
break;
|
|
3118
|
+
case 'backend':
|
|
3119
|
+
nextSteps.push(...await configureBackend(config));
|
|
3120
|
+
backendConfigured = true;
|
|
3121
|
+
break;
|
|
3122
|
+
case 'frontend':
|
|
3123
|
+
{
|
|
3124
|
+
const frontend = await configureFrontend(config);
|
|
3125
|
+
withNextAdapter = frontend.withNextAdapter;
|
|
3126
|
+
nextSteps.push(...frontend.nextSteps);
|
|
3127
|
+
break;
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
if (backendConfigured || withNextAdapter) {
|
|
3132
|
+
const restSteps = await configureRest(withNextAdapter);
|
|
3133
|
+
nextSteps.push(...missingDomainFirstPackages(), ...restSteps);
|
|
3134
|
+
}
|
|
3135
|
+
return nextSteps;
|
|
3136
|
+
};
|
|
3137
|
+
const noAggregate = 'No aggregate';
|
|
3138
|
+
const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
3139
|
+
const root = new ProjectRoot().path;
|
|
3140
|
+
const rootFolderPath = node_path.join(root, ConfigFile.Instance.data.project.rootFolder);
|
|
3141
|
+
const sharedKernelPath = node_path.join(rootFolderPath, 'shared-kernel');
|
|
3142
|
+
const units = findBackendUnits(ownerFolder.path);
|
|
3143
|
+
if (!units.length) return void report('No modules generated by df-scaffold were found here.');
|
|
3144
|
+
const unit = await interaction_select({
|
|
3145
|
+
key: 'module',
|
|
3146
|
+
id: unitId,
|
|
3147
|
+
message: 'Module:',
|
|
3148
|
+
choices: Object.keys(kindLayouts).flatMap((kind)=>{
|
|
3149
|
+
const group = units.filter((x)=>x.kind === kind);
|
|
3150
|
+
return group.length ? [
|
|
3151
|
+
new Separator(`── ${kindLayouts[group[0].kind].title}`),
|
|
3152
|
+
...group.map((value)=>({
|
|
3153
|
+
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
3154
|
+
value
|
|
3155
|
+
}))
|
|
3156
|
+
] : [];
|
|
3157
|
+
}),
|
|
3158
|
+
pageSize: 20
|
|
3159
|
+
});
|
|
3160
|
+
const placeName = (ownerPath)=>ownerPath === sharedKernelPath ? 'Shared Kernel' : `Bounded Context: ${node_path.basename(ownerPath)}`;
|
|
3161
|
+
const contexts = new Folder(rootFolderPath).subitem([
|
|
3162
|
+
'bounded-contexts'
|
|
3163
|
+
]).content.subfolderNames.map((name)=>node_path.join(rootFolderPath, 'bounded-contexts', name));
|
|
3164
|
+
const places = [
|
|
3165
|
+
unit.ownerPath,
|
|
3166
|
+
...contexts,
|
|
3167
|
+
...kindLayouts[unit.kind].sharedKernel ? [
|
|
3168
|
+
sharedKernelPath
|
|
3169
|
+
] : []
|
|
3170
|
+
].filter((place, index, all)=>all.indexOf(place) === index);
|
|
3171
|
+
const ownerPath = await interaction_select({
|
|
3172
|
+
key: 'targetContext',
|
|
3173
|
+
id: (owner)=>owner === sharedKernelPath ? 'shared-kernel' : node_path.basename(owner),
|
|
3174
|
+
message: 'Move to:',
|
|
3175
|
+
choices: places.map((value)=>({
|
|
3176
|
+
name: value === unit.ownerPath ? `${placeName(value)} (stays)` : placeName(value),
|
|
3177
|
+
value
|
|
3178
|
+
}))
|
|
3179
|
+
});
|
|
3180
|
+
let aggregate;
|
|
3181
|
+
const aggregates = ownerPath === sharedKernelPath ? [] : aggregatesOf(ownerPath);
|
|
3182
|
+
if (('entity' === unit.kind || 'value-object' === unit.kind) && aggregates.length) {
|
|
3183
|
+
const picked = await interaction_select({
|
|
3184
|
+
key: 'aggregate',
|
|
3185
|
+
message: 'Aggregate:',
|
|
3186
|
+
choices: [
|
|
3187
|
+
noAggregate,
|
|
3188
|
+
...aggregates
|
|
3189
|
+
],
|
|
3190
|
+
default: ownerPath === unit.ownerPath && unit.aggregate ? unit.aggregate : noAggregate
|
|
3191
|
+
});
|
|
3192
|
+
aggregate = picked === noAggregate ? void 0 : picked;
|
|
3193
|
+
}
|
|
3194
|
+
const target = (name)=>({
|
|
3195
|
+
ownerPath,
|
|
3196
|
+
aggregate,
|
|
3197
|
+
name: name.trim()
|
|
3198
|
+
});
|
|
3199
|
+
const name = await interaction_input({
|
|
3200
|
+
key: 'name',
|
|
3201
|
+
message: 'New name:',
|
|
3202
|
+
default: unit.name,
|
|
3203
|
+
validate: (value)=>validateBackendMove(unit, target(value), sharedKernelPath)
|
|
3204
|
+
});
|
|
3205
|
+
const result = moveBackendUnit(root, rootFolderPath, unit, target(name));
|
|
3206
|
+
if (result.violations) {
|
|
3207
|
+
if (isNonInteractive()) throw new RequestError('MOVE_NOT_ALLOWED', 'The move would cross bounded-context boundaries.', {
|
|
3208
|
+
violations: result.violations
|
|
3209
|
+
});
|
|
3210
|
+
report([
|
|
3211
|
+
"Nothing was moved: these imports would cross a bounded context boundary.",
|
|
3212
|
+
...result.violations.map(([from, to])=>` ${from} → ${to}`),
|
|
3213
|
+
'Give the other context its own query or command, or move what it depends on first.'
|
|
3214
|
+
].join('\n'));
|
|
3215
|
+
return;
|
|
3216
|
+
}
|
|
3217
|
+
const relative = (file)=>node_path.relative(root, file);
|
|
3218
|
+
report([
|
|
3219
|
+
'Files to move:',
|
|
3220
|
+
...result.moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
3221
|
+
...result.updated.length ? [
|
|
3222
|
+
'Files with updated imports and names:',
|
|
3223
|
+
...result.updated.map((file)=>` ${relative(file)}`)
|
|
3224
|
+
] : []
|
|
3225
|
+
].join('\n'));
|
|
3226
|
+
if (!await interaction_confirm({
|
|
3227
|
+
key: 'apply',
|
|
3228
|
+
message: 'Apply?',
|
|
3229
|
+
default: true
|
|
3230
|
+
})) {
|
|
3231
|
+
discardPendingChanges();
|
|
3232
|
+
report('Cancelled: nothing was written.');
|
|
3233
|
+
}
|
|
3234
|
+
};
|
|
3235
|
+
const promptRouteMove = async (root, page, newName)=>{
|
|
3236
|
+
if (!usesNext()) return;
|
|
3237
|
+
const appFolder = node_path.join(root, nextAppFolder(root));
|
|
3238
|
+
const from = routeFolder(appFolder, page.name);
|
|
3239
|
+
const to = routeFolder(appFolder, newName);
|
|
3240
|
+
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3241
|
+
const routePage = node_path.join(from, 'page.tsx');
|
|
3242
|
+
if (from === to || !node_fs.existsSync(routePage) || !new RegExp(`\\b${page.ClassName}Page\\b`).test(node_fs.readFileSync(routePage, 'utf8'))) return;
|
|
3243
|
+
if (node_fs.existsSync(node_path.join(to, 'page.tsx'))) return void report(`${relative(to)}/page.tsx already exists: the route ${relative(from)} stays.`);
|
|
3244
|
+
const move = await interaction_confirm({
|
|
3245
|
+
key: 'moveRoute',
|
|
3246
|
+
message: `Move the Next.js route too: ${relative(from)} → ${relative(to)}? Its URL changes.`,
|
|
3247
|
+
default: true
|
|
3248
|
+
});
|
|
3249
|
+
return move ? {
|
|
3250
|
+
appFolder,
|
|
3251
|
+
from,
|
|
3252
|
+
to
|
|
3253
|
+
} : void 0;
|
|
3254
|
+
};
|
|
2572
3255
|
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
2573
3256
|
const reactFolder = presentationReactFolder.path;
|
|
2574
3257
|
const modules = findReactModules(reactFolder, kind);
|
|
2575
|
-
if (!modules.length) return void
|
|
2576
|
-
const module = await
|
|
3258
|
+
if (!modules.length) return void report(`No ${kind}s generated by df-react were found.`);
|
|
3259
|
+
const module = await interaction_select({
|
|
3260
|
+
key: 'module',
|
|
3261
|
+
id: (value)=>value.name,
|
|
2577
3262
|
message: 'page' === kind ? 'Page:' : 'Widget:',
|
|
2578
3263
|
choices: modules.map((value)=>({
|
|
2579
3264
|
name: value.name,
|
|
@@ -2581,16 +3266,18 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
2581
3266
|
description: node_path.relative(reactFolder, value.path)
|
|
2582
3267
|
}))
|
|
2583
3268
|
});
|
|
2584
|
-
const name = await
|
|
3269
|
+
const name = await interaction_input({
|
|
3270
|
+
key: 'name',
|
|
2585
3271
|
message: 'New name (folders split by "/"):',
|
|
2586
3272
|
default: module.name,
|
|
2587
3273
|
validate: (value)=>validateMove(reactFolder, module, value)
|
|
2588
3274
|
});
|
|
2589
3275
|
const root = new ProjectRoot().path;
|
|
2590
|
-
const
|
|
2591
|
-
|
|
2592
|
-
const
|
|
2593
|
-
|
|
3276
|
+
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3277
|
+
const route = 'page' === kind ? await promptRouteMove(root, module, name) : void 0;
|
|
3278
|
+
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route);
|
|
3279
|
+
if (!moves.length && !updated.length) return void report('Nothing to change.');
|
|
3280
|
+
report([
|
|
2594
3281
|
'Files to move:',
|
|
2595
3282
|
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
2596
3283
|
...updated.length ? [
|
|
@@ -2598,154 +3285,105 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
2598
3285
|
...updated.map((file)=>` ${relative(file)}`)
|
|
2599
3286
|
] : []
|
|
2600
3287
|
].join('\n'));
|
|
2601
|
-
if (!await
|
|
3288
|
+
if (!await interaction_confirm({
|
|
3289
|
+
key: 'apply',
|
|
2602
3290
|
message: 'Apply?',
|
|
2603
3291
|
default: true
|
|
2604
3292
|
})) {
|
|
2605
3293
|
discardPendingChanges();
|
|
2606
|
-
|
|
3294
|
+
report('Cancelled: nothing was written.');
|
|
2607
3295
|
}
|
|
2608
3296
|
};
|
|
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()
|
|
3297
|
+
const enterImplementationTypeOnce = Symbol('enter-implementation-type-once');
|
|
3298
|
+
const implementationTypeEntryChoices = [
|
|
3299
|
+
{
|
|
3300
|
+
name: 'Enter implementation type and save for future use',
|
|
3301
|
+
value: null
|
|
3302
|
+
},
|
|
3303
|
+
{
|
|
3304
|
+
name: 'Enter implementation type for this run only',
|
|
3305
|
+
value: enterImplementationTypeOnce
|
|
2652
3306
|
}
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
const
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
node_path.dirname(implementationFile(unit, label)),
|
|
2661
|
-
node_path.basename(implementationFile(unit, label))
|
|
3307
|
+
];
|
|
3308
|
+
const promptImplementationType = async (message, kind, { existing = [], purpose = 'primary', crossContext = false, remember = true } = {})=>{
|
|
3309
|
+
const roles = 'all' === purpose ? [
|
|
3310
|
+
'primary',
|
|
3311
|
+
'test'
|
|
3312
|
+
] : [
|
|
3313
|
+
purpose
|
|
2662
3314
|
];
|
|
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`);
|
|
3315
|
+
const saved = [
|
|
3316
|
+
...new Set(roles.flatMap((role)=>savedImplementations(kind, role)))
|
|
3317
|
+
].filter((label)=>label !== crossContextImplementation || 'ports' === kind && crossContext);
|
|
3318
|
+
const allowCrossContext = 'ports' === kind && crossContext;
|
|
3319
|
+
const system = systemImplementationChoices(kind, crossContext);
|
|
3320
|
+
const choices = saved.map((label)=>system.find(({ value })=>value === label) ?? {
|
|
3321
|
+
name: label,
|
|
3322
|
+
value: label
|
|
3323
|
+
});
|
|
3324
|
+
for (const choice of system)if (!choices.some(({ value })=>value === choice.value)) choices.push(choice);
|
|
3325
|
+
const defaultType = saved.find((label)=>!existing.includes(label));
|
|
3326
|
+
const preferred = choices.find(({ value })=>value === defaultType && !existing.includes(value)) ?? choices.find(({ value })=>!existing.includes(value));
|
|
3327
|
+
const validateLabel = (value)=>{
|
|
3328
|
+
const label = value.trim();
|
|
3329
|
+
if (!allowCrossContext && label === crossContextImplementation) return 'Cross-context implementations require an application port with a neighboring bounded context.';
|
|
3330
|
+
if (!kebabName.test(label)) return 'Use lowercase kebab-case, e.g. prisma or in-memory.';
|
|
3331
|
+
return existing.includes(label) ? `The ${label} implementation already exists.` : true;
|
|
3332
|
+
};
|
|
3333
|
+
if (isNonInteractive()) {
|
|
3334
|
+
const key = 'test' === purpose ? 'testImplementation' : 'implementation';
|
|
3335
|
+
const implementation = answerFor(key);
|
|
3336
|
+
if (!implementation) throw new RequestError('MISSING_PARAMETER', `Provide ${key}.`, {
|
|
3337
|
+
field: key
|
|
3338
|
+
});
|
|
3339
|
+
const valid = validateLabel(implementation.type);
|
|
3340
|
+
if (true !== valid) throw new RequestError('INVALID_IMPLEMENTATION', valid, {
|
|
3341
|
+
field: key
|
|
3342
|
+
});
|
|
3343
|
+
const label = implementation.type.trim();
|
|
3344
|
+
const saveForFutureUse = implementation.save ?? false;
|
|
3345
|
+
if (remember && saveForFutureUse && !system.some((choice)=>choice.value === label)) rememberImplementation(kind, 'all' === purpose ? 'primary' : purpose, label);
|
|
3346
|
+
return {
|
|
3347
|
+
label,
|
|
3348
|
+
saveForFutureUse
|
|
3349
|
+
};
|
|
2730
3350
|
}
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
3351
|
+
const type = await interaction_select({
|
|
3352
|
+
message,
|
|
3353
|
+
choices: [
|
|
3354
|
+
...choices.map((choice)=>({
|
|
3355
|
+
...choice,
|
|
3356
|
+
disabled: existing.includes(choice.value)
|
|
3357
|
+
})),
|
|
3358
|
+
...implementationTypeEntryChoices
|
|
3359
|
+
],
|
|
3360
|
+
default: preferred?.value ?? null
|
|
3361
|
+
});
|
|
3362
|
+
if ('string' == typeof type) return {
|
|
3363
|
+
label: type,
|
|
3364
|
+
saveForFutureUse: true
|
|
3365
|
+
};
|
|
3366
|
+
const saveForFutureUse = type !== enterImplementationTypeOnce;
|
|
3367
|
+
const label = (await interaction_input({
|
|
3368
|
+
message,
|
|
3369
|
+
default: defaultType ?? '',
|
|
3370
|
+
validate: validateLabel
|
|
3371
|
+
})).trim();
|
|
3372
|
+
if (saveForFutureUse && remember && !choices.some(({ value })=>value === label)) rememberImplementation(kind, 'all' === purpose ? 'primary' : purpose, label);
|
|
3373
|
+
return {
|
|
3374
|
+
label,
|
|
3375
|
+
saveForFutureUse
|
|
2741
3376
|
};
|
|
3377
|
+
};
|
|
2742
3378
|
const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
2743
|
-
const aggregateName = await
|
|
3379
|
+
const aggregateName = await interaction_input({
|
|
3380
|
+
key: 'name',
|
|
2744
3381
|
message: 'Aggregate name:'
|
|
2745
3382
|
});
|
|
2746
3383
|
const aggregateNaming = new UnknownFormatNaming(aggregateName);
|
|
2747
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
2748
|
-
const withRepository = await
|
|
3384
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3385
|
+
const withRepository = await interaction_confirm({
|
|
3386
|
+
key: 'withRepository',
|
|
2749
3387
|
message: 'With Repository'
|
|
2750
3388
|
});
|
|
2751
3389
|
const aggregatesFolder = boundedContextFolder.subitem([
|
|
@@ -2753,7 +3391,7 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
|
2753
3391
|
'aggregates',
|
|
2754
3392
|
aggregateName
|
|
2755
3393
|
]);
|
|
2756
|
-
const withTypes = ConfigFile.
|
|
3394
|
+
const withTypes = ConfigFile.backend.domainFirstPackages.includes('@domain-first/types');
|
|
2757
3395
|
aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.ts`, withTypes ? `
|
|
2758
3396
|
import { domainType } from '@domain-first/types'
|
|
2759
3397
|
|
|
@@ -2762,7 +3400,7 @@ export class ${aggregateNaming.ClassName} extends domainType() {
|
|
|
2762
3400
|
}`.trim() : `export class ${aggregateNaming.ClassName} {}`);
|
|
2763
3401
|
const barrelFile = aggregatesFolder.createFile("index.ts", `export * from './${aggregateNaming.fileName}.aggregate-root'`);
|
|
2764
3402
|
if (scaffoldUnitTests) aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.spec.ts`, `
|
|
2765
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3403
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
2766
3404
|
import { ${aggregateNaming.ClassName} } from './${aggregateNaming.fileName}.aggregate-root'
|
|
2767
3405
|
|
|
2768
3406
|
let ${aggregateNaming.variableName}: ${aggregateNaming.ClassName}
|
|
@@ -2780,19 +3418,19 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
2780
3418
|
if (withRepository) {
|
|
2781
3419
|
aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.ts`, `export abstract class ${aggregateNaming.ClassName}Repository { }`);
|
|
2782
3420
|
barrelFile.addLine(`export * from './${aggregateNaming.fileName}-repository'`);
|
|
2783
|
-
const infrastructureImplementationType = await
|
|
2784
|
-
message: 'Repository infrastructure implementation type:',
|
|
2785
|
-
default: ConfigFile.Instance.data.defaultPersistenceLayerImplementation
|
|
2786
|
-
});
|
|
3421
|
+
const { label: infrastructureImplementationType } = await promptImplementationType('Repository infrastructure implementation type:', 'repositories');
|
|
2787
3422
|
let addTestImplementation = false;
|
|
2788
3423
|
let testImplementationType = '';
|
|
2789
|
-
addTestImplementation = await
|
|
3424
|
+
addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
3425
|
+
key: 'withTestImplementation',
|
|
2790
3426
|
message: 'Add a test implementation for Repository'
|
|
2791
3427
|
});
|
|
2792
|
-
if (addTestImplementation) testImplementationType = await
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
3428
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test Repository infrastructure implementation type:', 'repositories', {
|
|
3429
|
+
purpose: 'test',
|
|
3430
|
+
existing: [
|
|
3431
|
+
infrastructureImplementationType
|
|
3432
|
+
]
|
|
3433
|
+
})).label;
|
|
2796
3434
|
const implementationTypes = [
|
|
2797
3435
|
infrastructureImplementationType,
|
|
2798
3436
|
testImplementationType
|
|
@@ -2807,8 +3445,8 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
2807
3445
|
if (scaffoldUnitTests) {
|
|
2808
3446
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
2809
3447
|
const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
|
|
2810
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
2811
|
-
${ConfigFile.
|
|
3448
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3449
|
+
${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
|
|
2812
3450
|
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
3451
|
|
|
2814
3452
|
type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`}
|
|
@@ -2816,18 +3454,18 @@ type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}$
|
|
|
2816
3454
|
let ${aggregateNaming.variableName}Repository: ${aggregateNaming.ClassName}Repository
|
|
2817
3455
|
|
|
2818
3456
|
beforeEach(() => {
|
|
2819
|
-
${aggregateNaming.variableName}Repository = ${ConfigFile.
|
|
3457
|
+
${aggregateNaming.variableName}Repository = ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${aggregateNaming.ClassName}Repository()` : `new ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository()`}
|
|
2820
3458
|
})
|
|
2821
3459
|
|
|
2822
3460
|
describe('${aggregateNaming.withSpaces} repository', () => {
|
|
2823
|
-
test('can be ${ConfigFile.
|
|
3461
|
+
test('can be ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
|
|
2824
3462
|
expect(${aggregateNaming.variableName}Repository).toBeDefined()
|
|
2825
3463
|
})
|
|
2826
3464
|
})
|
|
2827
3465
|
`.trim());
|
|
2828
|
-
if (!ConfigFile.
|
|
3466
|
+
if (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
|
|
2829
3467
|
}
|
|
2830
|
-
if (ConfigFile.
|
|
3468
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2831
3469
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
2832
3470
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
2833
3471
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -2840,22 +3478,19 @@ ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fil
|
|
|
2840
3478
|
|
|
2841
3479
|
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${aggregateNaming.ClassName}Repository, [])`).join('\n\n')}
|
|
2842
3480
|
|
|
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
|
-
})
|
|
3481
|
+
export const wire${aggregateNaming.ClassName}Repository = envBranchedWire(${envBranchedWireArgument(`wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation`, `wire${implementationNaming.ClassName}Implementation`)})
|
|
2848
3482
|
`.trim());
|
|
2849
3483
|
await wireNewModuleDependencies(boundedContextFolder, wireFile, inMemoryRepositoryWiring(boundedContextFolder, repository, wireFile));
|
|
2850
3484
|
}
|
|
2851
3485
|
}
|
|
2852
3486
|
};
|
|
2853
3487
|
const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
|
|
2854
|
-
const name = await
|
|
3488
|
+
const name = await interaction_input({
|
|
3489
|
+
key: 'name',
|
|
2855
3490
|
message: 'Name: '
|
|
2856
3491
|
});
|
|
2857
3492
|
const naming = new UnknownFormatNaming(name);
|
|
2858
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3493
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
2859
3494
|
const wiringFolder = boundedContextFolder.subitem([
|
|
2860
3495
|
'wiring',
|
|
2861
3496
|
'application-ports'
|
|
@@ -2869,18 +3504,22 @@ export abstract class ${naming.ClassName} {
|
|
|
2869
3504
|
|
|
2870
3505
|
}
|
|
2871
3506
|
`.trim());
|
|
2872
|
-
const
|
|
2873
|
-
|
|
2874
|
-
|
|
3507
|
+
const crossContext = hasNeighboringBoundedContext(boundedContextFolder.path);
|
|
3508
|
+
const { label: implementationType } = await promptImplementationType('Adapter implementation type:', 'ports', {
|
|
3509
|
+
crossContext
|
|
2875
3510
|
});
|
|
2876
|
-
const addTestImplementation = await
|
|
3511
|
+
const addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
3512
|
+
key: 'withTestImplementation',
|
|
2877
3513
|
message: 'With test implementation'
|
|
2878
3514
|
});
|
|
2879
3515
|
let testImplementationType = '';
|
|
2880
|
-
if (addTestImplementation) testImplementationType = await
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
3516
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test adapter implementation type:', 'ports', {
|
|
3517
|
+
existing: [
|
|
3518
|
+
implementationType
|
|
3519
|
+
],
|
|
3520
|
+
purpose: 'test',
|
|
3521
|
+
crossContext
|
|
3522
|
+
})).label;
|
|
2884
3523
|
const implementationTypes = [
|
|
2885
3524
|
implementationType,
|
|
2886
3525
|
testImplementationType
|
|
@@ -2894,8 +3533,8 @@ export abstract class ${naming.ClassName} {
|
|
|
2894
3533
|
if (scaffoldUnitTests) {
|
|
2895
3534
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
2896
3535
|
applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
|
|
2897
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
2898
|
-
${ConfigFile.
|
|
3536
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3537
|
+
${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { type ${naming.ClassName} } from './${naming.fileName}'
|
|
2899
3538
|
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
3539
|
|
|
2901
3540
|
type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`}
|
|
@@ -2903,17 +3542,17 @@ type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`
|
|
|
2903
3542
|
let ${naming.variableName}: ${naming.ClassName}
|
|
2904
3543
|
|
|
2905
3544
|
beforeEach(() => {
|
|
2906
|
-
${naming.variableName} = ${ConfigFile.
|
|
3545
|
+
${naming.variableName} = ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${naming.ClassName}()` : `new ${implementationNaming.ClassName}${naming.ClassName}()`}
|
|
2907
3546
|
})
|
|
2908
3547
|
|
|
2909
3548
|
describe('${naming.withSpaces}', () => {
|
|
2910
|
-
test('can be ${ConfigFile.
|
|
3549
|
+
test('can be ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
|
|
2911
3550
|
expect(${naming.variableName}).toBeDefined()
|
|
2912
3551
|
})
|
|
2913
3552
|
})
|
|
2914
3553
|
`.trim());
|
|
2915
3554
|
}
|
|
2916
|
-
if (ConfigFile.
|
|
3555
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2917
3556
|
const wireFile = wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
|
|
2918
3557
|
import { wireClass } from '@domain-first/wire'
|
|
2919
3558
|
import { envBranchedWire } from '../../../${'shared-kernel' === boundedContextFolder.name ? '' : '../'}shared-kernel/wiring/env-branched-wire'
|
|
@@ -2927,23 +3566,20 @@ ${implementationTypes.map((x)=>({
|
|
|
2927
3566
|
implementation: x
|
|
2928
3567
|
})).map(({ naming: { ClassName }, implementation })=>`const wire${new UnknownFormatNaming(implementation).ClassName}Implementation = wireClass(${ClassName}, [])`).join('\n\n')}
|
|
2929
3568
|
|
|
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
|
-
})
|
|
3569
|
+
export const wire${naming.ClassName} = envBranchedWire(${envBranchedWireArgument(`wire${new UnknownFormatNaming(`${implementationTypes.at(-1)}-implementation`).ClassName}`, `wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName}`)})
|
|
2935
3570
|
|
|
2936
3571
|
`.trim());
|
|
2937
3572
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
2938
3573
|
}
|
|
2939
3574
|
};
|
|
2940
3575
|
const scaffoldNewApplicationService = async (boundedContextFolder)=>{
|
|
2941
|
-
const name = await
|
|
3576
|
+
const name = await interaction_input({
|
|
3577
|
+
key: 'name',
|
|
2942
3578
|
message: 'Name: '
|
|
2943
3579
|
});
|
|
2944
3580
|
const naming = new UnknownFormatNaming(name);
|
|
2945
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
2946
|
-
const withWiring = ConfigFile.
|
|
3581
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3582
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
2947
3583
|
const wiringFolder = boundedContextFolder.subitem([
|
|
2948
3584
|
'wiring',
|
|
2949
3585
|
'application-services'
|
|
@@ -2958,7 +3594,7 @@ export class ${naming.ClassName}ApplicationService {
|
|
|
2958
3594
|
}
|
|
2959
3595
|
`.trim());
|
|
2960
3596
|
if (scaffoldUnitTests) applicationServicesFolder.createFile(`${naming.fileName}-application-service.spec.ts`, `
|
|
2961
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3597
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
2962
3598
|
${withWiring ? `import { type ${naming.ClassName}ApplicationService } from './${naming.fileName}-application-service'
|
|
2963
3599
|
import { wire${naming.ClassName}ApplicationService } from '../../wiring/application-services/wire-${naming.fileName}-application-service'` : `import { ${naming.ClassName}ApplicationService } from './${naming.fileName}-application-service'`}
|
|
2964
3600
|
|
|
@@ -2988,14 +3624,15 @@ export const wire${naming.ClassName}ApplicationService = wireClass(
|
|
|
2988
3624
|
}
|
|
2989
3625
|
};
|
|
2990
3626
|
const scaffoldNewBoundedContextUseCase = async ()=>{
|
|
2991
|
-
const name = await
|
|
3627
|
+
const name = await interaction_input({
|
|
3628
|
+
key: 'name',
|
|
2992
3629
|
message: 'Name:',
|
|
2993
3630
|
validate: (x)=>!!x.length
|
|
2994
3631
|
});
|
|
2995
3632
|
const { path } = new ProjectRoot();
|
|
2996
3633
|
const rootFolder = new Folder(path);
|
|
2997
3634
|
const folder = rootFolder.subitem([
|
|
2998
|
-
ConfigFile.Instance.data.rootFolder,
|
|
3635
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
2999
3636
|
'bounded-contexts',
|
|
3000
3637
|
name
|
|
3001
3638
|
]);
|
|
@@ -3006,25 +3643,26 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
3006
3643
|
'application',
|
|
3007
3644
|
'commands'
|
|
3008
3645
|
]);
|
|
3009
|
-
const commandName = await
|
|
3646
|
+
const commandName = await interaction_input({
|
|
3647
|
+
key: 'name',
|
|
3010
3648
|
message: 'Name: '
|
|
3011
3649
|
});
|
|
3012
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3650
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3013
3651
|
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
|
-
});
|
|
3652
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3653
|
+
const { label: implementationType } = await promptImplementationType('Command infrastructure implementation type:', 'commands');
|
|
3019
3654
|
let addTestImplementation = false;
|
|
3020
3655
|
let testImplementationType = '';
|
|
3021
|
-
addTestImplementation = await
|
|
3656
|
+
addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
3657
|
+
key: 'withTestImplementation',
|
|
3022
3658
|
message: 'Add a test implementation for Command'
|
|
3023
3659
|
});
|
|
3024
|
-
if (addTestImplementation) testImplementationType = await
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3660
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test Command infrastructure implementation type:', 'commands', {
|
|
3661
|
+
existing: [
|
|
3662
|
+
implementationType
|
|
3663
|
+
],
|
|
3664
|
+
purpose: 'test'
|
|
3665
|
+
})).label;
|
|
3028
3666
|
const implementationTypes = [
|
|
3029
3667
|
implementationType,
|
|
3030
3668
|
testImplementationType
|
|
@@ -3035,7 +3673,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
3035
3673
|
ownerPath: boundedContextFolder.path,
|
|
3036
3674
|
labels: []
|
|
3037
3675
|
}, new UnknownFormatNaming(implementation).fileName);
|
|
3038
|
-
if (ConfigFile.
|
|
3676
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.createFile(`${naming.fileName}-command.ts`, `
|
|
3039
3677
|
import type { Handler } from '@domain-first/handlers'
|
|
3040
3678
|
|
|
3041
3679
|
export abstract class ${naming.ClassName}Command {
|
|
@@ -3052,7 +3690,7 @@ export abstract class ${naming.ClassName}Command {
|
|
|
3052
3690
|
if (scaffoldUnitTests) {
|
|
3053
3691
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3054
3692
|
const specFile = commandsFolder.createFile(`${naming.fileName}-command.spec.ts`, `
|
|
3055
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3693
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3056
3694
|
${withWiring ? `import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
|
|
3057
3695
|
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
3696
|
|
|
@@ -3072,7 +3710,7 @@ describe('${naming.withSpaces} command', () => {
|
|
|
3072
3710
|
`.trim());
|
|
3073
3711
|
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
|
|
3074
3712
|
}
|
|
3075
|
-
if (ConfigFile.
|
|
3713
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3076
3714
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3077
3715
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
3078
3716
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -3085,18 +3723,15 @@ ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fil
|
|
|
3085
3723
|
|
|
3086
3724
|
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Command, [])`).join('\n\n')}
|
|
3087
3725
|
|
|
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
|
-
})
|
|
3726
|
+
export const wire${naming.ClassName}Command = envBranchedWire(${envBranchedWireArgument(`wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation`, `wire${implementationNaming.ClassName}Implementation`)})
|
|
3093
3727
|
`.trim());
|
|
3094
3728
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
3095
3729
|
}
|
|
3096
3730
|
};
|
|
3097
3731
|
const scaffold_new_domain_object_noAggregate = 'No aggregate';
|
|
3098
3732
|
const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
3099
|
-
const name = await
|
|
3733
|
+
const name = await interaction_input({
|
|
3734
|
+
key: 'name',
|
|
3100
3735
|
message: 'Name: '
|
|
3101
3736
|
});
|
|
3102
3737
|
const naming = new UnknownFormatNaming(name);
|
|
@@ -3105,7 +3740,8 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
|
3105
3740
|
'aggregates'
|
|
3106
3741
|
]);
|
|
3107
3742
|
const aggregateNames = aggregatesFolder.content.subfolderNames;
|
|
3108
|
-
const aggregate = aggregateNames.length ? await
|
|
3743
|
+
const aggregate = aggregateNames.length ? await interaction_select({
|
|
3744
|
+
key: 'aggregate',
|
|
3109
3745
|
message: 'Aggregate:',
|
|
3110
3746
|
choices: [
|
|
3111
3747
|
...aggregateNames,
|
|
@@ -3121,7 +3757,7 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
|
3121
3757
|
kindFolderName
|
|
3122
3758
|
]);
|
|
3123
3759
|
const fileName = `${naming.fileName}.${kind}`;
|
|
3124
|
-
const withTypes = ConfigFile.
|
|
3760
|
+
const withTypes = ConfigFile.backend.domainFirstPackages.includes('@domain-first/types');
|
|
3125
3761
|
folder.createFile(`${fileName}.ts`, withTypes ? `
|
|
3126
3762
|
import { domainType } from '@domain-first/types'
|
|
3127
3763
|
|
|
@@ -3131,7 +3767,7 @@ export class ${naming.ClassName} extends domainType() {
|
|
|
3131
3767
|
if (aggregate !== scaffold_new_domain_object_noAggregate) aggregatesFolder.subitem([
|
|
3132
3768
|
aggregate
|
|
3133
3769
|
]).file('index.ts').addLineIfMissing(`export * from './${kindFolderName}/${fileName}'`);
|
|
3134
|
-
const { testingLibrary } = ConfigFile.
|
|
3770
|
+
const { testingLibrary } = ConfigFile.backend;
|
|
3135
3771
|
if (testingLibrary) folder.createFile(`${fileName}.spec.ts`, `
|
|
3136
3772
|
import { describe, test, expect, beforeEach } from '${testingLibrary}'
|
|
3137
3773
|
import { ${naming.ClassName} } from './${fileName}'
|
|
@@ -3150,12 +3786,13 @@ describe('${naming.withSpaces}', () => {
|
|
|
3150
3786
|
`.trim());
|
|
3151
3787
|
};
|
|
3152
3788
|
const scaffoldNewDomainService = async (boundedContextFolder)=>{
|
|
3153
|
-
const portName = await
|
|
3789
|
+
const portName = await interaction_input({
|
|
3790
|
+
key: 'name',
|
|
3154
3791
|
message: 'Name:'
|
|
3155
3792
|
});
|
|
3156
3793
|
const naming = new UnknownFormatNaming(portName);
|
|
3157
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3158
|
-
const withWiring = ConfigFile.
|
|
3794
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3795
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3159
3796
|
const domainServicesFolder = boundedContextFolder.subitem([
|
|
3160
3797
|
'domain',
|
|
3161
3798
|
'services'
|
|
@@ -3166,7 +3803,7 @@ export class ${naming.ClassName}DomainService {
|
|
|
3166
3803
|
}
|
|
3167
3804
|
`.trim());
|
|
3168
3805
|
if (scaffoldUnitTests) domainServicesFolder.createFile(`${naming.fileName}-domain-service.spec.ts`, `
|
|
3169
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3806
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3170
3807
|
${withWiring ? `import { type ${naming.ClassName}DomainService } from './${naming.fileName}-domain-service'
|
|
3171
3808
|
import { wire${naming.ClassName}DomainService } from '../../wiring/domain-services/wire-${naming.fileName}-domain-service'` : `import { ${naming.ClassName}DomainService } from './${naming.fileName}-domain-service'`}
|
|
3172
3809
|
|
|
@@ -3200,7 +3837,7 @@ export const wire${naming.ClassName}DomainService = wireClass(
|
|
|
3200
3837
|
};
|
|
3201
3838
|
const errorNames = (boundedContextFolder)=>{
|
|
3202
3839
|
const isShared = boundedContextFolder.path === new Folder(new ProjectRoot().path).subitem([
|
|
3203
|
-
ConfigFile.Instance.data.rootFolder,
|
|
3840
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
3204
3841
|
'shared-kernel'
|
|
3205
3842
|
]).path;
|
|
3206
3843
|
return {
|
|
@@ -3235,12 +3872,14 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
3235
3872
|
...currentErrorNamespaces.map((x)=>`New error in namespace ${x}`),
|
|
3236
3873
|
'New namespace'
|
|
3237
3874
|
];
|
|
3238
|
-
const selectedVariant = await
|
|
3875
|
+
const selectedVariant = await interaction_select({
|
|
3239
3876
|
choices: variants,
|
|
3877
|
+
key: 'errorAction',
|
|
3240
3878
|
message: 'Action:'
|
|
3241
3879
|
});
|
|
3242
3880
|
if ('New error without namespace' === selectedVariant) {
|
|
3243
|
-
const errorName = await
|
|
3881
|
+
const errorName = await interaction_input({
|
|
3882
|
+
key: 'name',
|
|
3244
3883
|
message: 'Error name:'
|
|
3245
3884
|
});
|
|
3246
3885
|
const naming = new UnknownFormatNaming(errorName);
|
|
@@ -3249,7 +3888,8 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
3249
3888
|
return;
|
|
3250
3889
|
}
|
|
3251
3890
|
if ('New namespace' === selectedVariant) {
|
|
3252
|
-
const namespaceName = await
|
|
3891
|
+
const namespaceName = await interaction_input({
|
|
3892
|
+
key: 'name',
|
|
3253
3893
|
message: 'Namespace name:'
|
|
3254
3894
|
});
|
|
3255
3895
|
const { ClassName, fileName } = new UnknownFormatNaming(namespaceName);
|
|
@@ -3263,7 +3903,8 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
|
|
|
3263
3903
|
}
|
|
3264
3904
|
const namespace = selectedVariant.substring(23);
|
|
3265
3905
|
const namespaceNaming = new UnknownFormatNaming(namespace);
|
|
3266
|
-
const errorName = await
|
|
3906
|
+
const errorName = await interaction_input({
|
|
3907
|
+
key: 'name',
|
|
3267
3908
|
message: 'Error name:'
|
|
3268
3909
|
});
|
|
3269
3910
|
const { ClassName, fileName } = new UnknownFormatNaming(errorName);
|
|
@@ -3276,7 +3917,8 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
3276
3917
|
'rest'
|
|
3277
3918
|
]);
|
|
3278
3919
|
const controllers = restPresentationFolder.content.subfolderNames;
|
|
3279
|
-
let controller = await
|
|
3920
|
+
let controller = await interaction_select({
|
|
3921
|
+
key: 'controllerSelection',
|
|
3280
3922
|
message: 'Controller: ',
|
|
3281
3923
|
choices: [
|
|
3282
3924
|
...controllers,
|
|
@@ -3284,10 +3926,11 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
3284
3926
|
]
|
|
3285
3927
|
});
|
|
3286
3928
|
if ('New controller' === controller) {
|
|
3287
|
-
controller = await
|
|
3929
|
+
controller = await interaction_input({
|
|
3930
|
+
key: 'controllerName',
|
|
3288
3931
|
message: 'Name: '
|
|
3289
3932
|
});
|
|
3290
|
-
if (ConfigFile.
|
|
3933
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3291
3934
|
boundedContextFolder.subitem([
|
|
3292
3935
|
'wiring',
|
|
3293
3936
|
'presentation',
|
|
@@ -3309,7 +3952,8 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
3309
3952
|
`.trim());
|
|
3310
3953
|
}
|
|
3311
3954
|
}
|
|
3312
|
-
const method = await
|
|
3955
|
+
const method = await interaction_select({
|
|
3956
|
+
key: 'method',
|
|
3313
3957
|
message: 'Method:',
|
|
3314
3958
|
choices: [
|
|
3315
3959
|
'get',
|
|
@@ -3319,7 +3963,8 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
3319
3963
|
'put'
|
|
3320
3964
|
]
|
|
3321
3965
|
});
|
|
3322
|
-
const routeSegments = (await
|
|
3966
|
+
const routeSegments = (await interaction_input({
|
|
3967
|
+
key: 'path',
|
|
3323
3968
|
message: 'Relative path (split by "/"):'
|
|
3324
3969
|
})).split('/').filter((x)=>!!x);
|
|
3325
3970
|
const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
|
|
@@ -3334,7 +3979,7 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
3334
3979
|
method,
|
|
3335
3980
|
'endpoint'
|
|
3336
3981
|
].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
|
|
3337
|
-
const withWiring = ConfigFile.
|
|
3982
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3338
3983
|
const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
|
|
3339
3984
|
'..',
|
|
3340
3985
|
'..',
|
|
@@ -3384,7 +4029,7 @@ export const wire${endpointClassName} = wireClass(
|
|
|
3384
4029
|
[${dependencies.map((x)=>x.wireName).join(', ')}]
|
|
3385
4030
|
)
|
|
3386
4031
|
`.trim());
|
|
3387
|
-
wiringFolder.file('index.ts').
|
|
4032
|
+
wiringFolder.file('index.ts').addLineIfMissing(`export * from './${wireNaming.fileName}'`);
|
|
3388
4033
|
}
|
|
3389
4034
|
};
|
|
3390
4035
|
const scaffold_new_implementation_kindTitles = {
|
|
@@ -3393,11 +4038,6 @@ const scaffold_new_implementation_kindTitles = {
|
|
|
3393
4038
|
query: 'Queries',
|
|
3394
4039
|
port: 'Ports'
|
|
3395
4040
|
};
|
|
3396
|
-
const environments = [
|
|
3397
|
-
'test',
|
|
3398
|
-
'development',
|
|
3399
|
-
'production'
|
|
3400
|
-
];
|
|
3401
4041
|
const branchesOf = (wireFile, wireName)=>{
|
|
3402
4042
|
if (!wireFile.exists) return;
|
|
3403
4043
|
try {
|
|
@@ -3408,8 +4048,10 @@ const branchesOf = (wireFile, wireName)=>{
|
|
|
3408
4048
|
};
|
|
3409
4049
|
const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
3410
4050
|
const contracts = findContracts(ownerFolder.path);
|
|
3411
|
-
if (!contracts.length) return void
|
|
3412
|
-
const unit = await
|
|
4051
|
+
if (!contracts.length) return void report('No repositories, commands, queries or ports here yet.');
|
|
4052
|
+
const unit = await interaction_select({
|
|
4053
|
+
key: 'contract',
|
|
4054
|
+
id: unitId,
|
|
3413
4055
|
message: 'Contract:',
|
|
3414
4056
|
choices: contractKinds.flatMap((kind)=>{
|
|
3415
4057
|
const group = contracts.filter((x)=>x.kind === kind);
|
|
@@ -3423,33 +4065,47 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
|
3423
4065
|
}),
|
|
3424
4066
|
pageSize: 20
|
|
3425
4067
|
});
|
|
3426
|
-
const
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
})).trim();
|
|
4068
|
+
const kind = 'aggregate' === unit.kind ? 'repositories' : 'command' === unit.kind ? 'commands' : 'query' === unit.kind ? 'queries' : 'ports';
|
|
4069
|
+
const { label, saveForFutureUse } = await promptImplementationType('Implementation type:', kind, {
|
|
4070
|
+
existing: unit.labels,
|
|
4071
|
+
purpose: 'all',
|
|
4072
|
+
remember: false,
|
|
4073
|
+
crossContext: 'port' === unit.kind && hasNeighboringBoundedContext(ownerFolder.path)
|
|
4074
|
+
});
|
|
3434
4075
|
const { file, className } = createImplementation(ownerFolder, unit, label);
|
|
3435
|
-
|
|
4076
|
+
const branches = wire_branches_envBranches();
|
|
4077
|
+
const rememberFor = (environments)=>{
|
|
4078
|
+
if (!saveForFutureUse) return;
|
|
4079
|
+
if (systemImplementationChoices(kind, 'port' === unit.kind && hasNeighboringBoundedContext(ownerFolder.path)).some((choice)=>choice.value === label)) return;
|
|
4080
|
+
if (branches.test && environments.includes(branches.test)) rememberImplementation(kind, 'test', label);
|
|
4081
|
+
if (environments.some((environment)=>environment !== branches.test)) rememberImplementation(kind, 'primary', label);
|
|
4082
|
+
};
|
|
4083
|
+
if (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) return void rememberFor(branches.primary);
|
|
3436
4084
|
const wireFile = new File(ownerFolder.path).subitem(contractWireFile(unit).split('/'));
|
|
3437
4085
|
const wireName = `wire${contractClassName(unit)}`;
|
|
3438
|
-
const
|
|
3439
|
-
if (!
|
|
4086
|
+
const wired = branchesOf(wireFile, wireName);
|
|
4087
|
+
if (!wired) {
|
|
4088
|
+
rememberFor(branches.primary);
|
|
4089
|
+
report(`${wireFile.path} has no ${wireName} = envBranchedWire({...}): wire ${className} there yourself.`);
|
|
4090
|
+
return;
|
|
4091
|
+
}
|
|
3440
4092
|
const labelOfWire = new Map(unit.labels.map((x)=>[
|
|
3441
4093
|
implementationWireName(x),
|
|
3442
4094
|
x
|
|
3443
4095
|
]));
|
|
3444
|
-
const chosenEnvironments = await
|
|
4096
|
+
const chosenEnvironments = await interaction_checkbox({
|
|
4097
|
+
key: 'environments',
|
|
3445
4098
|
message: 'Environments:',
|
|
3446
4099
|
choices: [
|
|
3447
4100
|
...new Set([
|
|
3448
|
-
...
|
|
3449
|
-
|
|
4101
|
+
...branches.test ? [
|
|
4102
|
+
branches.test
|
|
4103
|
+
] : [],
|
|
4104
|
+
...branches.primary,
|
|
4105
|
+
...wired.keys()
|
|
3450
4106
|
])
|
|
3451
4107
|
].map((environment)=>{
|
|
3452
|
-
const current =
|
|
4108
|
+
const current = wired.get(environment);
|
|
3453
4109
|
return {
|
|
3454
4110
|
name: current ? `${environment} (now: ${labelOfWire.get(current) ?? current})` : environment,
|
|
3455
4111
|
value: environment
|
|
@@ -3457,6 +4113,7 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
|
3457
4113
|
}),
|
|
3458
4114
|
required: true
|
|
3459
4115
|
});
|
|
4116
|
+
rememberFor(chosenEnvironments);
|
|
3460
4117
|
const before = readWiredModule(wireFile.path, ownerFolder.path);
|
|
3461
4118
|
wireFile.update(addBranchedImplementation(wireFile.data, wireName, {
|
|
3462
4119
|
importLine: `import { ${className} } from '${relativeImport(wireFile.path, file.path)}'`,
|
|
@@ -3466,16 +4123,17 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
|
3466
4123
|
}));
|
|
3467
4124
|
const after = readWiredModule(wireFile.path, ownerFolder.path);
|
|
3468
4125
|
const unused = (before?.implementations ?? []).filter((x)=>!after?.implementations.some((y)=>y.className === x.className));
|
|
3469
|
-
for (const implementation of unused)
|
|
4126
|
+
for (const implementation of unused)report(`${implementation.className} is no longer used in any environment.`);
|
|
3470
4127
|
await wireNewImplementationDependencies(ownerFolder, wireFile, className, inMemoryRepositoryWiring(ownerFolder, unit, wireFile));
|
|
3471
4128
|
};
|
|
3472
4129
|
const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
|
|
3473
|
-
const name = await
|
|
4130
|
+
const name = await interaction_input({
|
|
4131
|
+
key: 'name',
|
|
3474
4132
|
message: 'Name: '
|
|
3475
4133
|
});
|
|
3476
4134
|
const naming = new UnknownFormatNaming(name);
|
|
3477
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3478
|
-
const withWiring = ConfigFile.
|
|
4135
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
4136
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3479
4137
|
const wiringFolder = boundedContextFolder.subitem([
|
|
3480
4138
|
'wiring',
|
|
3481
4139
|
'infrastructure-services'
|
|
@@ -3490,7 +4148,7 @@ export class ${naming.ClassName}InfrastructureService {
|
|
|
3490
4148
|
}
|
|
3491
4149
|
`.trim());
|
|
3492
4150
|
if (scaffoldUnitTests) infrastructureServicesFolder.createFile(`${naming.fileName}-infrastructure-service.spec.ts`, `
|
|
3493
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
4151
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3494
4152
|
${withWiring ? `import { type ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'
|
|
3495
4153
|
import { wire${naming.ClassName}InfrastructureService } from '../../wiring/infrastructure-services/wire-${naming.fileName}-infrastructure-service'` : `import { ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'`}
|
|
3496
4154
|
|
|
@@ -3524,25 +4182,26 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
3524
4182
|
'application',
|
|
3525
4183
|
'queries'
|
|
3526
4184
|
]);
|
|
3527
|
-
const queryName = await
|
|
4185
|
+
const queryName = await interaction_input({
|
|
4186
|
+
key: 'name',
|
|
3528
4187
|
message: 'Name: '
|
|
3529
4188
|
});
|
|
3530
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
4189
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3531
4190
|
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
|
-
});
|
|
4191
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
4192
|
+
const { label: implementationType } = await promptImplementationType('Query infrastructure implementation type:', 'queries');
|
|
3537
4193
|
let addTestImplementation = false;
|
|
3538
4194
|
let testImplementationType = '';
|
|
3539
|
-
addTestImplementation = await
|
|
4195
|
+
addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
4196
|
+
key: 'withTestImplementation',
|
|
3540
4197
|
message: 'Add a test implementation for Query'
|
|
3541
4198
|
});
|
|
3542
|
-
if (addTestImplementation) testImplementationType = await
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
4199
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test Query infrastructure implementation type:', 'queries', {
|
|
4200
|
+
existing: [
|
|
4201
|
+
implementationType
|
|
4202
|
+
],
|
|
4203
|
+
purpose: 'test'
|
|
4204
|
+
})).label;
|
|
3546
4205
|
const implementationTypes = [
|
|
3547
4206
|
implementationType,
|
|
3548
4207
|
testImplementationType
|
|
@@ -3553,7 +4212,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
3553
4212
|
ownerPath: boundedContextFolder.path,
|
|
3554
4213
|
labels: []
|
|
3555
4214
|
}, new UnknownFormatNaming(implementation).fileName);
|
|
3556
|
-
if (ConfigFile.
|
|
4215
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.createFile(`${naming.fileName}-query.ts`, `
|
|
3557
4216
|
import type { Handler } from '@domain-first/handlers'
|
|
3558
4217
|
|
|
3559
4218
|
export abstract class ${naming.ClassName}Query {
|
|
@@ -3570,7 +4229,7 @@ export abstract class ${naming.ClassName}Query {
|
|
|
3570
4229
|
if (scaffoldUnitTests) {
|
|
3571
4230
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3572
4231
|
const specFile = queriesFolder.createFile(`${naming.fileName}-query.spec.ts`, `
|
|
3573
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
4232
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3574
4233
|
${withWiring ? `import { type ${naming.ClassName}Query } from './${naming.fileName}-query'
|
|
3575
4234
|
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
4235
|
|
|
@@ -3590,7 +4249,7 @@ describe('${naming.withSpaces} query', () => {
|
|
|
3590
4249
|
`.trim());
|
|
3591
4250
|
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
|
|
3592
4251
|
}
|
|
3593
|
-
if (ConfigFile.
|
|
4252
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3594
4253
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3595
4254
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
3596
4255
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -3603,11 +4262,7 @@ ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fil
|
|
|
3603
4262
|
|
|
3604
4263
|
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Query, [])`).join('\n\n')}
|
|
3605
4264
|
|
|
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
|
-
})
|
|
4265
|
+
export const wire${naming.ClassName}Query = envBranchedWire(${envBranchedWireArgument(`wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation`, `wire${implementationNaming.ClassName}Implementation`)})
|
|
3611
4266
|
`.trim());
|
|
3612
4267
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
3613
4268
|
}
|
|
@@ -3617,13 +4272,14 @@ const scaffoldNewUseCase = async (boundedContextFolder)=>{
|
|
|
3617
4272
|
'application',
|
|
3618
4273
|
'use-cases'
|
|
3619
4274
|
]);
|
|
3620
|
-
const useCaseName = await
|
|
4275
|
+
const useCaseName = await interaction_input({
|
|
4276
|
+
key: 'name',
|
|
3621
4277
|
message: 'Name: '
|
|
3622
4278
|
});
|
|
3623
4279
|
const naming = new UnknownFormatNaming(useCaseName);
|
|
3624
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3625
|
-
const withWiring = ConfigFile.
|
|
3626
|
-
useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, ConfigFile.
|
|
4280
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
4281
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
4282
|
+
useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
3627
4283
|
import { defineHandler } from '@domain-first/handlers'
|
|
3628
4284
|
|
|
3629
4285
|
export class ${naming.ClassName}UseCase {
|
|
@@ -3646,7 +4302,7 @@ export class ${naming.ClassName}UseCase {
|
|
|
3646
4302
|
}
|
|
3647
4303
|
`.trim());
|
|
3648
4304
|
if (scaffoldUnitTests) useCasesFolder.createFile(`${naming.fileName}-use-case.spec.ts`, `
|
|
3649
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
4305
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3650
4306
|
${withWiring ? `import { type ${naming.ClassName}UseCase } from './${naming.fileName}-use-case'
|
|
3651
4307
|
import { wire${naming.ClassName}UseCase } from '../../wiring/use-cases/wire-${naming.fileName}-use-case'` : `import { ${naming.ClassName}UseCase } from './${naming.fileName}-use-case'`}
|
|
3652
4308
|
|
|
@@ -3680,7 +4336,8 @@ export const wire${naming.ClassName}UseCase = wireClass(
|
|
|
3680
4336
|
}
|
|
3681
4337
|
};
|
|
3682
4338
|
const scaffoldReactSharedHook = async (presentationReactFolder)=>{
|
|
3683
|
-
const name = await
|
|
4339
|
+
const name = await interaction_input({
|
|
4340
|
+
key: 'name',
|
|
3684
4341
|
message: 'Name without "use" (e.g. debounce): '
|
|
3685
4342
|
});
|
|
3686
4343
|
const { ClassName, fileName } = new UnknownFormatNaming(name.trim().replace(/^use-/, ''));
|
|
@@ -3693,7 +4350,8 @@ export const use${ClassName} = () => {
|
|
|
3693
4350
|
`.trim());
|
|
3694
4351
|
};
|
|
3695
4352
|
const scaffoldReactUIKitComponent = async (presentationReactFolder)=>{
|
|
3696
|
-
const name = await
|
|
4353
|
+
const name = await interaction_input({
|
|
4354
|
+
key: 'name',
|
|
3697
4355
|
message: 'Name: '
|
|
3698
4356
|
});
|
|
3699
4357
|
const { ClassName, fileName } = new UnknownFormatNaming(name);
|
|
@@ -3711,7 +4369,7 @@ export const ${ClassName}: FC<${ClassName}Props> = (props) => {
|
|
|
3711
4369
|
return <></>
|
|
3712
4370
|
}
|
|
3713
4371
|
`.trim());
|
|
3714
|
-
const { storybookFramework } = ConfigFile.Instance.data;
|
|
4372
|
+
const { storybookFramework } = ConfigFile.Instance.data.frontend?.react ?? {};
|
|
3715
4373
|
if (storybookFramework) componentFolder.createFile(`${fileName}.stories.tsx`, `
|
|
3716
4374
|
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
3717
4375
|
import { ${ClassName} } from './${fileName}'
|
|
@@ -3731,16 +4389,18 @@ export const Default: Story = {
|
|
|
3731
4389
|
`.trim());
|
|
3732
4390
|
};
|
|
3733
4391
|
const scaffoldReactWidget = async (presentationReactFolder)=>{
|
|
3734
|
-
const widgetName = await
|
|
4392
|
+
const widgetName = await interaction_input({
|
|
4393
|
+
key: 'name',
|
|
3735
4394
|
message: 'Name (folders split by "/"): ',
|
|
3736
4395
|
validate: NestedName.validate
|
|
3737
4396
|
});
|
|
3738
|
-
const widgetType = await
|
|
4397
|
+
const widgetType = await interaction_select({
|
|
3739
4398
|
choices: [
|
|
3740
4399
|
'monolithic',
|
|
3741
4400
|
'with separated ui',
|
|
3742
4401
|
'headless'
|
|
3743
4402
|
],
|
|
4403
|
+
key: 'widgetType',
|
|
3744
4404
|
message: 'Type: '
|
|
3745
4405
|
});
|
|
3746
4406
|
const { folders, folderName, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
|
|
@@ -3799,7 +4459,7 @@ export const ${ClassName}WidgetUI: FC<${ClassName}WidgetUIProps> = (props) => {
|
|
|
3799
4459
|
return <></>
|
|
3800
4460
|
}
|
|
3801
4461
|
`.trim());
|
|
3802
|
-
const { storybookFramework } = ConfigFile.Instance.data;
|
|
4462
|
+
const { storybookFramework } = ConfigFile.Instance.data.frontend?.react ?? {};
|
|
3803
4463
|
if (storybookFramework) folder.subitem([
|
|
3804
4464
|
'ui'
|
|
3805
4465
|
]).createFile(`${uiFileName}.stories.tsx`, `
|
|
@@ -3865,4 +4525,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
3865
4525
|
break;
|
|
3866
4526
|
}
|
|
3867
4527
|
};
|
|
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 };
|
|
4528
|
+
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 };
|