@domain-first/project-structure 7.1.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -25
- package/dist/201.js +146 -342
- package/dist/287.js +1304 -568
- package/dist/561.js +518 -0
- package/dist/711.js +22 -0
- package/dist/870.js +438 -0
- package/dist/agent-cli.d.ts +378 -0
- package/dist/agent-cli.spec.d.ts +1 -0
- package/dist/agent-identifiers.d.ts +4 -0
- package/dist/agent-requests.d.ts +488 -0
- package/dist/backend-module-move.d.ts +1 -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/implementations.d.ts +48 -0
- package/dist/index.cjs +3768 -574
- package/dist/index.js +25 -9
- package/dist/init.cjs +717 -122
- package/dist/init.js +24 -12
- package/dist/integration.cjs +3737 -186
- package/dist/integration.js +29 -17
- package/dist/integrations/rest-endpoint-generator.d.ts +4 -2
- package/dist/integrations/storybook.d.ts +1 -0
- package/dist/interaction.d.ts +41 -0
- package/dist/lint.cjs +173 -46
- package/dist/lint.js +22 -7
- package/dist/next-app.d.ts +7 -0
- package/dist/react.cjs +5128 -414
- package/dist/react.js +72 -60
- package/dist/system-implementations.d.ts +6 -0
- package/dist/upgrade-steps.d.ts +81 -0
- package/dist/upgrade-steps.spec.d.ts +1 -0
- package/dist/upgrade.cjs +593 -0
- package/dist/upgrade.d.ts +2 -0
- package/dist/upgrade.js +235 -0
- package/dist/use-cases/add-integration.d.ts +16 -1
- package/dist/use-cases/cross-context-dependencies.spec.d.ts +1 -0
- package/dist/use-cases/index.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-new-aggregate.d.ts +1 -1
- package/dist/use-cases/scaffold-new-implementation.d.ts +6 -0
- package/dist/use-cases/scaffold-new-implementation.spec.d.ts +1 -0
- package/dist/use-cases/scaffold-react-page.d.ts +3 -1
- package/dist/use-cases/wire-dependency.d.ts +5 -0
- package/dist/wire-branches.d.ts +26 -0
- package/dist/wiring.d.ts +24 -2
- package/package.json +3 -2
- package/skills/df-ps-implement/SKILL.md +9 -8
- package/skills/df-ps-plan-feature/SKILL.md +8 -7
- package/skills/df-ps-react/SKILL.md +13 -7
- package/skills/df-ps-react/references/generators.md +6 -2
- package/skills/df-ps-scaffold/SKILL.md +31 -19
- 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 +14 -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 +20 -0
- 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,30 +1,16 @@
|
|
|
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
|
-
const
|
|
13
|
+
const in_memory_db_wireName = 'wireInMemoryDbInfrastructureService';
|
|
28
14
|
const parameterName = 'inMemoryDbInfrastructureService';
|
|
29
15
|
const inMemoryDbService = `type Entry = {
|
|
30
16
|
id: unknown;
|
|
@@ -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',
|
|
@@ -231,15 +217,15 @@ const inMemoryDbSectionMembers = (field, derived)=>`
|
|
|
231
217
|
const keepInMemoryDbSection = (classFile, field)=>{
|
|
232
218
|
classFile.update(addImport(classFile.data, inMemoryDbTypeImport(classFile.path)).replace('constructor() {}', inMemoryDbSectionMembers(field, false)));
|
|
233
219
|
};
|
|
234
|
-
const isInMemoryDb = (module)=>module.wireName ===
|
|
220
|
+
const isInMemoryDb = (module)=>module.wireName === in_memory_db_wireName;
|
|
235
221
|
const injectInMemoryDb = (classFile, implementationName)=>{
|
|
236
222
|
classFile.update(addConstructorParameters(addImport(classFile.data, inMemoryDbTypeImport(classFile.path)), implementationName, [
|
|
237
223
|
`private readonly ${parameterName}: ${in_memory_db_className}`
|
|
238
224
|
]));
|
|
239
225
|
};
|
|
240
226
|
const wireInMemoryDb = (consumerWireFile, implementationName)=>{
|
|
241
|
-
consumerWireFile.update(addWireDependencies(addImport(consumerWireFile.data, `import { ${
|
|
242
|
-
|
|
227
|
+
consumerWireFile.update(addWireDependencies(addImport(consumerWireFile.data, `import { ${in_memory_db_wireName} } from '${relativeImport(consumerWireFile.path, in_memory_db_wireFile().path)}'`), implementationName, [
|
|
228
|
+
in_memory_db_wireName
|
|
243
229
|
]));
|
|
244
230
|
};
|
|
245
231
|
const passInMemoryDb = (specFile, implementationName)=>{
|
|
@@ -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,
|
|
@@ -1153,10 +1304,19 @@ const wireNewModuleDependencies = async (boundedContextFolder, wireFile, customW
|
|
|
1153
1304
|
const consumer = readWiredModule(wireFile.path, boundedContextFolder.path);
|
|
1154
1305
|
if (consumer) await promptDependencies(boundedContextFolder, consumer, consumer.implementations, customWiring);
|
|
1155
1306
|
};
|
|
1307
|
+
const wireNewImplementationDependencies = async (boundedContextFolder, wireFile, className, customWiring)=>{
|
|
1308
|
+
const consumer = readWiredModule(wireFile.path, boundedContextFolder.path);
|
|
1309
|
+
const implementation = consumer?.implementations.find((x)=>x.className === className);
|
|
1310
|
+
if (consumer && implementation) await promptDependencies(boundedContextFolder, consumer, [
|
|
1311
|
+
implementation
|
|
1312
|
+
], customWiring);
|
|
1313
|
+
};
|
|
1156
1314
|
const wireDependency = async (boundedContextFolder)=>{
|
|
1157
1315
|
const modules = findWiredModules(boundedContextFolder.path);
|
|
1158
|
-
if (!modules.length) return void
|
|
1159
|
-
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}`,
|
|
1160
1320
|
message: 'Module:',
|
|
1161
1321
|
choices: groupedChoices(modules.flatMap((x)=>x.implementations.map((implementation)=>{
|
|
1162
1322
|
const type = wiring_implementationType(x, implementation);
|
|
@@ -1171,7 +1331,7 @@ const wireDependency = async (boundedContextFolder)=>{
|
|
|
1171
1331
|
});
|
|
1172
1332
|
if (!await promptDependencies(boundedContextFolder, consumer, [
|
|
1173
1333
|
implementation
|
|
1174
|
-
]))
|
|
1334
|
+
])) report('No dependencies available for this module.');
|
|
1175
1335
|
};
|
|
1176
1336
|
const promptEndpointHandler = async (boundedContextFolder)=>{
|
|
1177
1337
|
const handlers = findWiredModules(boundedContextFolder.path).filter((x)=>[
|
|
@@ -1182,7 +1342,9 @@ const promptEndpointHandler = async (boundedContextFolder)=>{
|
|
|
1182
1342
|
module: x,
|
|
1183
1343
|
label: x.typeName
|
|
1184
1344
|
}));
|
|
1185
|
-
return handlers.length ? (await
|
|
1345
|
+
return handlers.length ? (await interaction_select({
|
|
1346
|
+
key: 'handler',
|
|
1347
|
+
id: (value)=>moduleId(value.module),
|
|
1186
1348
|
message: 'Handler:',
|
|
1187
1349
|
choices: groupedChoices(handlers),
|
|
1188
1350
|
pageSize: groupedPageSize,
|
|
@@ -1192,8 +1354,8 @@ const promptEndpointHandler = async (boundedContextFolder)=>{
|
|
|
1192
1354
|
const createPresentationService = (boundedContextFolder, name, classFile)=>{
|
|
1193
1355
|
const naming = new UnknownFormatNaming(name);
|
|
1194
1356
|
const className = `${naming.ClassName}PresentationService`;
|
|
1195
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
1196
|
-
const withWiring = ConfigFile.
|
|
1357
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
1358
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
1197
1359
|
const wiringFolder = boundedContextFolder.subitem([
|
|
1198
1360
|
'wiring',
|
|
1199
1361
|
'presentation-services'
|
|
@@ -1208,7 +1370,7 @@ export class ${className} {
|
|
|
1208
1370
|
}
|
|
1209
1371
|
`.trim());
|
|
1210
1372
|
if (scaffoldUnitTests) presentationServicesFolder.createFile(`${naming.fileName}-presentation-service.spec.ts`, `
|
|
1211
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
1373
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
1212
1374
|
${withWiring ? `import { type ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'
|
|
1213
1375
|
import { wire${naming.ClassName}PresentationService } from '../../wiring/presentation-services/wire-${naming.fileName}-presentation-service'` : `import { ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'`}
|
|
1214
1376
|
|
|
@@ -1235,7 +1397,8 @@ export const wire${naming.ClassName}PresentationService = wireClass(
|
|
|
1235
1397
|
`.trim());
|
|
1236
1398
|
};
|
|
1237
1399
|
const scaffoldNewPresentationService = async (boundedContextFolder)=>{
|
|
1238
|
-
const name = await
|
|
1400
|
+
const name = await interaction_input({
|
|
1401
|
+
key: 'name',
|
|
1239
1402
|
message: 'Name: '
|
|
1240
1403
|
});
|
|
1241
1404
|
const wireFile = createPresentationService(boundedContextFolder, name);
|
|
@@ -1275,10 +1438,6 @@ const findRestEndpointGenerator = (sharedFolder)=>{
|
|
|
1275
1438
|
wireFile: node_path.join(sharedFolder.path, 'wiring', 'presentation-services', `wire-${rest_endpoint_generator_name}-presentation-service.ts`)
|
|
1276
1439
|
};
|
|
1277
1440
|
};
|
|
1278
|
-
const nextAppFolder = (root)=>[
|
|
1279
|
-
'app',
|
|
1280
|
-
'src/app'
|
|
1281
|
-
].find((folder)=>new Folder(node_path.join(root, folder)).exists) ?? 'app';
|
|
1282
1441
|
const nextRoutePath = (root)=>node_path.posix.join(nextAppFolder(root), 'api/[...path]/route.ts');
|
|
1283
1442
|
const nextRoute = (restHandlersImport)=>`
|
|
1284
1443
|
import { nextEndpoints } from '@domain-first/handlers-next'
|
|
@@ -1296,8 +1455,9 @@ export const PUT = handler
|
|
|
1296
1455
|
export const PATCH = handler
|
|
1297
1456
|
export const DELETE = handler
|
|
1298
1457
|
`.trim();
|
|
1299
|
-
const
|
|
1300
|
-
const { rootFolder
|
|
1458
|
+
const rest_endpoint_generator_scaffoldNextRoute = (root)=>{
|
|
1459
|
+
const { rootFolder } = ConfigFile.Instance.data.project;
|
|
1460
|
+
const { domainFirstPackages } = ConfigFile.backend;
|
|
1301
1461
|
const routePath = nextRoutePath(root);
|
|
1302
1462
|
const routeFile = node_path.join(root, routePath);
|
|
1303
1463
|
if (new File(routeFile).exists) return [];
|
|
@@ -1315,20 +1475,21 @@ const scaffoldNextRoute = (root)=>{
|
|
|
1315
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`
|
|
1316
1476
|
];
|
|
1317
1477
|
};
|
|
1318
|
-
const askNextAdapter = async ()=>
|
|
1319
|
-
|
|
1478
|
+
const askNextAdapter = async ({ nextSelected } = {})=>(nextSelected ?? usesNext()) && await interaction_confirm({
|
|
1479
|
+
key: 'nextAdapter',
|
|
1480
|
+
message: 'Use @domain-first/handlers-next for REST endpoints'
|
|
1320
1481
|
});
|
|
1321
1482
|
const scaffoldRestEndpointGeneratorFiles = ({ withNextAdapter })=>{
|
|
1322
1483
|
const root = new ProjectRoot().path;
|
|
1323
1484
|
const generatorExisted = restEndpointGeneratorApplied();
|
|
1324
1485
|
const routeNotes = withoutOverwrites(()=>{
|
|
1325
1486
|
scaffoldRestEndpointGenerator(new Folder(root).subitem([
|
|
1326
|
-
ConfigFile.Instance.data.rootFolder,
|
|
1487
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
1327
1488
|
'shared-kernel'
|
|
1328
1489
|
]), {
|
|
1329
1490
|
withNextAdapter
|
|
1330
1491
|
});
|
|
1331
|
-
return withNextAdapter ?
|
|
1492
|
+
return withNextAdapter ? rest_endpoint_generator_scaffoldNextRoute(root) : [];
|
|
1332
1493
|
});
|
|
1333
1494
|
if (!withNextAdapter) return [];
|
|
1334
1495
|
return [
|
|
@@ -1345,20 +1506,21 @@ const addRestEndpointGenerator = async ()=>scaffoldRestEndpointGeneratorFiles({
|
|
|
1345
1506
|
withNextAdapter: await askNextAdapter()
|
|
1346
1507
|
});
|
|
1347
1508
|
const restEndpointGeneratorApplied = ()=>Boolean(findRestEndpointGenerator(new Folder(new ProjectRoot().path).subitem([
|
|
1348
|
-
ConfigFile.Instance.data.rootFolder,
|
|
1509
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
1349
1510
|
'shared-kernel'
|
|
1350
1511
|
])));
|
|
1512
|
+
const storybookFrameworkPackage = '@storybook/react-vite';
|
|
1351
1513
|
const storybookFiles = (relativeProjectRoot)=>({
|
|
1352
1514
|
'main.ts': `import { resolve } from 'node:path';
|
|
1353
1515
|
import react from '@vitejs/plugin-react';
|
|
1354
|
-
import type { StorybookConfig } from '
|
|
1516
|
+
import type { StorybookConfig } from '${storybookFrameworkPackage}';
|
|
1355
1517
|
|
|
1356
1518
|
const projectRoot = resolve(import.meta.dirname, ${JSON.stringify(relativeProjectRoot)});
|
|
1357
1519
|
|
|
1358
1520
|
const config: StorybookConfig = {
|
|
1359
1521
|
stories: ['../**/*.mdx', '../**/*.stories.@(ts|tsx)'],
|
|
1360
1522
|
framework: {
|
|
1361
|
-
name: '
|
|
1523
|
+
name: '${storybookFrameworkPackage}',
|
|
1362
1524
|
options: {}
|
|
1363
1525
|
},
|
|
1364
1526
|
core: {
|
|
@@ -1380,7 +1542,7 @@ const config: StorybookConfig = {
|
|
|
1380
1542
|
|
|
1381
1543
|
export default config;
|
|
1382
1544
|
`,
|
|
1383
|
-
'preview.ts': `import type { Preview } from '
|
|
1545
|
+
'preview.ts': `import type { Preview } from '${storybookFrameworkPackage}';
|
|
1384
1546
|
|
|
1385
1547
|
const preview: Preview = {
|
|
1386
1548
|
parameters: {
|
|
@@ -1406,16 +1568,18 @@ const storybookScripts = (rootFolder)=>{
|
|
|
1406
1568
|
};
|
|
1407
1569
|
const addStorybook = async ()=>{
|
|
1408
1570
|
const config = ConfigFile.Instance.data;
|
|
1409
|
-
if ((!config.
|
|
1410
|
-
|
|
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}?`,
|
|
1411
1575
|
default: false
|
|
1412
1576
|
})) return [];
|
|
1413
1577
|
const root = new ProjectRoot().path;
|
|
1414
1578
|
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
1415
1579
|
const manifest = JSON.parse(manifestFile.data);
|
|
1416
|
-
const selected = await addPackageScripts(manifestFile, storybookScripts(config.rootFolder));
|
|
1580
|
+
const selected = await addPackageScripts(manifestFile, storybookScripts(config.project.rootFolder));
|
|
1417
1581
|
const folder = new Folder(root).subitem([
|
|
1418
|
-
config.rootFolder,
|
|
1582
|
+
config.project.rootFolder,
|
|
1419
1583
|
'presentation',
|
|
1420
1584
|
'react',
|
|
1421
1585
|
'.storybook'
|
|
@@ -1424,12 +1588,16 @@ const addStorybook = async ()=>{
|
|
|
1424
1588
|
const file = new File(node_path.join(folder.path, name));
|
|
1425
1589
|
if (!file.exists || file.data !== content) file.data = content;
|
|
1426
1590
|
}
|
|
1427
|
-
if (!config.
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
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
|
+
}
|
|
1431
1599
|
});
|
|
1432
|
-
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');
|
|
1433
1601
|
addGitignoreEntry(root, `/${buildFolder}/`);
|
|
1434
1602
|
const dependencies = {
|
|
1435
1603
|
...manifest.dependencies,
|
|
@@ -1437,7 +1605,7 @@ const addStorybook = async ()=>{
|
|
|
1437
1605
|
};
|
|
1438
1606
|
const missing = [
|
|
1439
1607
|
'storybook',
|
|
1440
|
-
|
|
1608
|
+
storybookFrameworkPackage,
|
|
1441
1609
|
'vite',
|
|
1442
1610
|
'@vitejs/plugin-react'
|
|
1443
1611
|
].filter((name)=>!dependencies[name]);
|
|
@@ -1458,6 +1626,57 @@ const addStorybook = async ()=>{
|
|
|
1458
1626
|
})
|
|
1459
1627
|
];
|
|
1460
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
|
+
};
|
|
1461
1680
|
const integrationFolder = 'specs/integration';
|
|
1462
1681
|
const testcontainersScripts = {
|
|
1463
1682
|
'test:integration': `vitest run --config ${integrationFolder}/vitest.config.ts --reporter=dot --silent=passed-only`
|
|
@@ -1591,8 +1810,8 @@ const addTestcontainers = async ()=>{
|
|
|
1591
1810
|
...manifest.devDependencies
|
|
1592
1811
|
};
|
|
1593
1812
|
const selected = await addPackageScripts(manifestFile, testcontainersScripts);
|
|
1594
|
-
const withPrisma = new File(node_path.resolve(root, config.rootFolder, 'shared-kernel/infrastructure/prisma/prisma.config.ts')).exists;
|
|
1595
|
-
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;
|
|
1596
1815
|
const folder = node_path.join(root, integrationFolder);
|
|
1597
1816
|
testcontainers_stageFile(node_path.join(folder, 'vitest.config.ts'), testcontainersVitestConfig(Boolean(dependencies['@domain-first/handlers-next'])));
|
|
1598
1817
|
testcontainers_stageFile(node_path.join(folder, 'global-setup.ts'), testcontainersGlobalSetup(migrationCommand));
|
|
@@ -1624,6 +1843,9 @@ const addTestcontainers = async ()=>{
|
|
|
1624
1843
|
...excludedFromUnitTests ? [] : [
|
|
1625
1844
|
`Add '${integrationFolder}/**' to test.exclude in vitest.config.ts, so unit tests skip integration specs.`
|
|
1626
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
|
+
] : [],
|
|
1627
1849
|
'Docker must be running for integration specs.',
|
|
1628
1850
|
...describeScripts(selected, {
|
|
1629
1851
|
'test:integration': `run integration specs from ${integrationFolder} against PostgreSQL in a container`
|
|
@@ -1671,8 +1893,10 @@ export default defineConfig({
|
|
|
1671
1893
|
};
|
|
1672
1894
|
const addVitest = async ()=>{
|
|
1673
1895
|
const config = ConfigFile.Instance.data;
|
|
1674
|
-
if (
|
|
1675
|
-
|
|
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?`,
|
|
1676
1900
|
default: false
|
|
1677
1901
|
})) return [];
|
|
1678
1902
|
const root = new ProjectRoot().path;
|
|
@@ -1684,11 +1908,13 @@ const addVitest = async ()=>{
|
|
|
1684
1908
|
};
|
|
1685
1909
|
const selected = await addPackageScripts(manifestFile, vitestScripts);
|
|
1686
1910
|
const configFile = new File(node_path.join(root, 'vitest.config.ts'));
|
|
1687
|
-
const content = vitestConfig(config.rootFolder, Boolean(dependencies['@domain-first/handlers-next']));
|
|
1911
|
+
const content = vitestConfig(config.project.rootFolder, Boolean(dependencies['@domain-first/handlers-next']));
|
|
1688
1912
|
if (!configFile.exists || configFile.data !== content) configFile.data = content;
|
|
1689
|
-
if ('vitest' !==
|
|
1690
|
-
|
|
1691
|
-
|
|
1913
|
+
if ('vitest' !== ConfigFile.backend.testingLibrary) ConfigFile.update({
|
|
1914
|
+
backend: {
|
|
1915
|
+
...ConfigFile.backend,
|
|
1916
|
+
testingLibrary: 'vitest'
|
|
1917
|
+
}
|
|
1692
1918
|
});
|
|
1693
1919
|
addGitignoreEntry(root, '/coverage/');
|
|
1694
1920
|
const missing = [
|
|
@@ -1754,17 +1980,56 @@ const printNextSteps = (nextSteps)=>{
|
|
|
1754
1980
|
].join('\n'));
|
|
1755
1981
|
if (sections.length) console.log(sections.join('\n\n'));
|
|
1756
1982
|
};
|
|
1757
|
-
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;
|
|
1758
2010
|
const created = (...segments)=>new File(node_path.join(new ProjectRoot().path, ...segments)).exists;
|
|
1759
|
-
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
|
+
];
|
|
1760
2023
|
const integrations = [
|
|
1761
2024
|
{
|
|
2025
|
+
id: 'storybook',
|
|
1762
2026
|
name: 'Storybook (React + Vite)',
|
|
1763
2027
|
group: 'frontend',
|
|
1764
2028
|
run: addStorybook,
|
|
1765
2029
|
applied: ()=>createdInRoot('presentation/react/.storybook/main.ts')
|
|
1766
2030
|
},
|
|
1767
2031
|
{
|
|
2032
|
+
id: 'rest-endpoint-generator',
|
|
1768
2033
|
name: 'REST endpoint generator',
|
|
1769
2034
|
group: 'backend',
|
|
1770
2035
|
run: addRestEndpointGenerator,
|
|
@@ -1772,36 +2037,42 @@ const integrations = [
|
|
|
1772
2037
|
applied: restEndpointGeneratorApplied
|
|
1773
2038
|
},
|
|
1774
2039
|
{
|
|
2040
|
+
id: 'in-memory-db',
|
|
1775
2041
|
name: 'In-memory DB',
|
|
1776
2042
|
group: 'backend',
|
|
1777
2043
|
run: addInMemoryDb,
|
|
1778
2044
|
applied: inMemoryDbApplied
|
|
1779
2045
|
},
|
|
1780
2046
|
{
|
|
2047
|
+
id: 'prisma',
|
|
1781
2048
|
name: 'Prisma 8 (PostgreSQL, RC)',
|
|
1782
2049
|
group: 'backend',
|
|
1783
2050
|
run: addPrisma,
|
|
1784
2051
|
applied: ()=>createdInRoot('shared-kernel/infrastructure/prisma/prisma.config.ts')
|
|
1785
2052
|
},
|
|
1786
2053
|
{
|
|
2054
|
+
id: 'vitest',
|
|
1787
2055
|
name: 'Vitest',
|
|
1788
2056
|
group: 'backend',
|
|
1789
2057
|
run: addVitest,
|
|
1790
2058
|
applied: ()=>created('vitest.config.ts')
|
|
1791
2059
|
},
|
|
1792
2060
|
{
|
|
2061
|
+
id: 'playwright',
|
|
1793
2062
|
name: 'Playwright',
|
|
1794
2063
|
group: 'frontend',
|
|
1795
2064
|
run: addPlaywright,
|
|
1796
2065
|
applied: ()=>created('playwright.config.ts')
|
|
1797
2066
|
},
|
|
1798
2067
|
{
|
|
2068
|
+
id: 'testcontainers',
|
|
1799
2069
|
name: 'Integration tests (Testcontainers, PostgreSQL)',
|
|
1800
2070
|
group: 'backend',
|
|
1801
2071
|
run: addTestcontainers,
|
|
1802
2072
|
applied: ()=>created('specs/integration/vitest.config.ts')
|
|
1803
2073
|
},
|
|
1804
2074
|
{
|
|
2075
|
+
id: 'openapi',
|
|
1805
2076
|
name: 'OpenAPI',
|
|
1806
2077
|
group: 'backend',
|
|
1807
2078
|
run: addOpenapi,
|
|
@@ -1809,6 +2080,7 @@ const integrations = [
|
|
|
1809
2080
|
applied: ()=>created(openapiScriptPath)
|
|
1810
2081
|
},
|
|
1811
2082
|
{
|
|
2083
|
+
id: 'orval',
|
|
1812
2084
|
name: 'Orval (API client)',
|
|
1813
2085
|
group: 'frontend',
|
|
1814
2086
|
run: addOrval,
|
|
@@ -1816,8 +2088,8 @@ const integrations = [
|
|
|
1816
2088
|
applied: ()=>createdInRoot('presentation/react/data-layer/orval.config.ts') || createdInRoot('presentation/data-layer/orval.config.ts')
|
|
1817
2089
|
}
|
|
1818
2090
|
];
|
|
1819
|
-
const addIntegration = async ()=>{
|
|
1820
|
-
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)=>({
|
|
1821
2093
|
value,
|
|
1822
2094
|
applied: value.applied()
|
|
1823
2095
|
}));
|
|
@@ -1838,88 +2110,24 @@ const addIntegration = async ()=>{
|
|
|
1838
2110
|
...section('New integrations', false),
|
|
1839
2111
|
...section('Already applied (select to reapply)', true)
|
|
1840
2112
|
];
|
|
1841
|
-
const selected = await
|
|
2113
|
+
const selected = await interaction_checkbox({
|
|
2114
|
+
key: 'integrations',
|
|
2115
|
+
id: (integration)=>integration.id,
|
|
1842
2116
|
message: 'Integrations:',
|
|
1843
2117
|
choices,
|
|
1844
2118
|
pageSize: choices.length
|
|
1845
2119
|
});
|
|
1846
2120
|
const nextSteps = [];
|
|
1847
2121
|
for (const integration of integrations.filter((value)=>selected.includes(value)))nextSteps.push(...await integration.run());
|
|
1848
|
-
if (await savePendingChanges()) printNextSteps(nextSteps);
|
|
1849
|
-
};
|
|
1850
|
-
const initializeUseCase = async ()=>{
|
|
1851
|
-
const rootFolderName = await input({
|
|
1852
|
-
message: 'Root folder (use "/" for inner folders):',
|
|
1853
|
-
default: 'src'
|
|
1854
|
-
});
|
|
1855
|
-
const domainFirstPackages = await prompts_checkbox({
|
|
1856
|
-
message: '@domain-first packages',
|
|
1857
|
-
choices: [
|
|
1858
|
-
'@domain-first/types',
|
|
1859
|
-
'@domain-first/errors',
|
|
1860
|
-
'@domain-first/handlers',
|
|
1861
|
-
'@domain-first/wire',
|
|
1862
|
-
'@domain-first/handlers-rest'
|
|
1863
|
-
]
|
|
1864
|
-
});
|
|
1865
|
-
const withNextAdapter = domainFirstPackages.includes('@domain-first/handlers-rest') && await askNextAdapter();
|
|
1866
|
-
const defaultPersistenceLayerImplementation = await input({
|
|
1867
|
-
message: 'Default persistence layer implementation:'
|
|
1868
|
-
});
|
|
1869
|
-
const withInMemoryDb = await prompts_confirm({
|
|
1870
|
-
message: 'Scaffold in-memory DB for test implementations'
|
|
1871
|
-
});
|
|
1872
|
-
const useReact = await prompts_confirm({
|
|
1873
|
-
message: 'Use React'
|
|
1874
|
-
});
|
|
1875
|
-
let storybookFramework;
|
|
1876
|
-
const withStorybook = useReact ? await prompts_confirm({
|
|
1877
|
-
message: 'Use Storybook'
|
|
1878
|
-
}) : false;
|
|
1879
|
-
if (withStorybook) storybookFramework = await input({
|
|
1880
|
-
message: 'Storybook framework package:',
|
|
1881
|
-
default: '@storybook/react-vite'
|
|
1882
|
-
});
|
|
1883
|
-
let testingLibrary;
|
|
1884
|
-
const withTests = await prompts_confirm({
|
|
1885
|
-
message: 'Scaffold unit tests'
|
|
1886
|
-
});
|
|
1887
|
-
if (withTests) testingLibrary = await input({
|
|
1888
|
-
message: 'Unit testing library:',
|
|
1889
|
-
default: 'vitest'
|
|
1890
|
-
});
|
|
1891
|
-
ConfigFile.write({
|
|
1892
|
-
rootFolder: rootFolderName,
|
|
1893
|
-
domainFirstPackages,
|
|
1894
|
-
defaultPersistenceLayerImplementation,
|
|
1895
|
-
withInMemoryDb,
|
|
1896
|
-
useReact,
|
|
1897
|
-
storybookFramework,
|
|
1898
|
-
testingLibrary
|
|
1899
|
-
});
|
|
1900
|
-
const { path } = new ProjectRoot();
|
|
1901
|
-
const rootFolder = new Folder(path);
|
|
1902
|
-
if (domainFirstPackages.includes('@domain-first/wire')) rootFolder.subitem([
|
|
1903
|
-
rootFolderName,
|
|
1904
|
-
'shared-kernel',
|
|
1905
|
-
'wiring'
|
|
1906
|
-
]).createFile('env-branched-wire.ts', `
|
|
1907
|
-
import { branchedWire } from '@domain-first/wire'
|
|
1908
|
-
|
|
1909
|
-
export const envBranchedWire = branchedWire(() => {
|
|
1910
|
-
return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
|
|
1911
|
-
});
|
|
1912
|
-
`.trim());
|
|
1913
|
-
if (withInMemoryDb) scaffoldInMemoryDb(rootFolder.subitem([
|
|
1914
|
-
rootFolderName,
|
|
1915
|
-
'shared-kernel'
|
|
1916
|
-
]));
|
|
1917
|
-
const nextSteps = missingDomainFirstPackages();
|
|
1918
|
-
if (domainFirstPackages.includes('@domain-first/handlers-rest')) nextSteps.push(...scaffoldRestEndpointGeneratorFiles({
|
|
1919
|
-
withNextAdapter
|
|
1920
|
-
}));
|
|
2122
|
+
if (save && await savePendingChanges()) printNextSteps(nextSteps);
|
|
1921
2123
|
return nextSteps;
|
|
1922
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
|
+
}));
|
|
1923
2131
|
const ignoredFolders = new Set([
|
|
1924
2132
|
'node_modules',
|
|
1925
2133
|
'.git',
|
|
@@ -2241,7 +2449,7 @@ const isolationAllows = (rootFolderPath, from, to)=>{
|
|
|
2241
2449
|
const fromOwner = ownerOf(rootFolderPath, from);
|
|
2242
2450
|
const toOwner = ownerOf(rootFolderPath, to);
|
|
2243
2451
|
if (!fromOwner || !toOwner?.context) return true;
|
|
2244
|
-
if (fromOwner.context) return fromOwner.context === toOwner.context;
|
|
2452
|
+
if (fromOwner.context) return fromOwner.context === toOwner.context || true === crossContextImportAllowed(from, to);
|
|
2245
2453
|
const inside = (folder)=>to === node_path.join(toOwner.path, folder) || to.startsWith(node_path.join(toOwner.path, folder) + node_path.sep);
|
|
2246
2454
|
return inside('domain/errors') || from.replace(codeExtension, '') === inMemoryDbFile(rootFolderPath).replace(codeExtension, '') && inside('domain');
|
|
2247
2455
|
};
|
|
@@ -2388,113 +2596,161 @@ const projectRelative = (fromFile, toFile)=>{
|
|
|
2388
2596
|
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toFile.replace(codeExtension, '')));
|
|
2389
2597
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
2390
2598
|
};
|
|
2391
|
-
const
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
...contexts,
|
|
2419
|
-
...kindLayouts[unit.kind].sharedKernel ? [
|
|
2420
|
-
sharedKernelPath
|
|
2421
|
-
] : []
|
|
2422
|
-
].filter((place, index, all)=>all.indexOf(place) === index);
|
|
2423
|
-
const ownerPath = await prompts_select({
|
|
2424
|
-
message: 'Move to:',
|
|
2425
|
-
choices: places.map((value)=>({
|
|
2426
|
-
name: value === unit.ownerPath ? `${placeName(value)} (stays)` : placeName(value),
|
|
2427
|
-
value
|
|
2428
|
-
}))
|
|
2429
|
-
});
|
|
2430
|
-
let aggregate;
|
|
2431
|
-
const aggregates = ownerPath === sharedKernelPath ? [] : aggregatesOf(ownerPath);
|
|
2432
|
-
if (('entity' === unit.kind || 'value-object' === unit.kind) && aggregates.length) {
|
|
2433
|
-
const picked = await prompts_select({
|
|
2434
|
-
message: 'Aggregate:',
|
|
2435
|
-
choices: [
|
|
2436
|
-
noAggregate,
|
|
2437
|
-
...aggregates
|
|
2438
|
-
],
|
|
2439
|
-
default: ownerPath === unit.ownerPath && unit.aggregate ? unit.aggregate : noAggregate
|
|
2440
|
-
});
|
|
2441
|
-
aggregate = picked === noAggregate ? void 0 : picked;
|
|
2599
|
+
const contractKinds = [
|
|
2600
|
+
'aggregate',
|
|
2601
|
+
'command',
|
|
2602
|
+
'query',
|
|
2603
|
+
'port'
|
|
2604
|
+
];
|
|
2605
|
+
const implementations_withWiring = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
2606
|
+
const withHandlers = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers');
|
|
2607
|
+
const contractFile = (unit)=>'aggregate' === unit.kind ? `domain/aggregates/${unit.name}/${unit.name}-repository.ts` : kindLayouts[unit.kind].files(unit, [])[0];
|
|
2608
|
+
const findContracts = (ownerPath)=>findBackendUnits(ownerPath).filter((unit)=>contractKinds.includes(unit.kind) && node_fs.existsSync(node_path.join(ownerPath, contractFile(unit))));
|
|
2609
|
+
const implementationWireName = (label)=>`wire${new UnknownFormatNaming(label).ClassName}Implementation`;
|
|
2610
|
+
const contractClassName = (unit)=>kindLayouts[unit.kind].core(new UnknownFormatNaming(unit.name).ClassName);
|
|
2611
|
+
const implementationClassName = (unit, label)=>`${new UnknownFormatNaming(label).ClassName}${contractClassName(unit)}`;
|
|
2612
|
+
const implementationFile = (unit, label)=>{
|
|
2613
|
+
const { implementations } = kindLayouts[unit.kind];
|
|
2614
|
+
return kindLayouts[unit.kind].files(unit, [
|
|
2615
|
+
label
|
|
2616
|
+
]).find((file)=>file.startsWith(`${implementations}/`));
|
|
2617
|
+
};
|
|
2618
|
+
const contractWireFile = (unit)=>kindLayouts[unit.kind].files(unit, []).find((file)=>file.startsWith('wiring/'));
|
|
2619
|
+
const handlerImplementation = (ContractName, ClassName, contractImport)=>withHandlers() ? `
|
|
2620
|
+
import { defineHandler } from '@domain-first/handlers'
|
|
2621
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2622
|
+
|
|
2623
|
+
export class ${ClassName} extends ${ContractName} {
|
|
2624
|
+
constructor() {
|
|
2625
|
+
super()
|
|
2442
2626
|
}
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
].join('\n'));
|
|
2459
|
-
const relative = (file)=>node_path.relative(root, file);
|
|
2460
|
-
console.log([
|
|
2461
|
-
'Files to move:',
|
|
2462
|
-
...result.moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
2463
|
-
...result.updated.length ? [
|
|
2464
|
-
'Files with updated imports and names:',
|
|
2465
|
-
...result.updated.map((file)=>` ${relative(file)}`)
|
|
2466
|
-
] : []
|
|
2467
|
-
].join('\n'));
|
|
2468
|
-
if (!await prompts_confirm({
|
|
2469
|
-
message: 'Apply?',
|
|
2470
|
-
default: true
|
|
2471
|
-
})) {
|
|
2472
|
-
discardPendingChanges();
|
|
2473
|
-
console.log('Cancelled: nothing was written.');
|
|
2627
|
+
|
|
2628
|
+
handle = defineHandler({
|
|
2629
|
+
inputSchema: ${ContractName}.inputSchema,
|
|
2630
|
+
outputSchema: ${ContractName}.outputSchema,
|
|
2631
|
+
handler: async (input) => {
|
|
2632
|
+
return {}
|
|
2633
|
+
}
|
|
2634
|
+
})
|
|
2635
|
+
}
|
|
2636
|
+
`.trim() : `
|
|
2637
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2638
|
+
|
|
2639
|
+
export class ${ClassName} extends ${ContractName} {
|
|
2640
|
+
constructor() {
|
|
2641
|
+
super()
|
|
2474
2642
|
}
|
|
2475
|
-
}
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
const
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
const
|
|
2486
|
-
const
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2643
|
+
}
|
|
2644
|
+
`.trim();
|
|
2645
|
+
const createImplementation = (ownerFolder, unit, label)=>{
|
|
2646
|
+
const naming = new UnknownFormatNaming(unit.name);
|
|
2647
|
+
const ContractName = contractClassName(unit);
|
|
2648
|
+
const className = implementationClassName(unit, label);
|
|
2649
|
+
const [folder, fileName] = [
|
|
2650
|
+
node_path.dirname(implementationFile(unit, label)),
|
|
2651
|
+
node_path.basename(implementationFile(unit, label))
|
|
2652
|
+
];
|
|
2653
|
+
const implementationFolder = ownerFolder.subitem(folder.split('/'));
|
|
2654
|
+
const inMemoryDb = !implementations_withWiring() && usesInMemoryDb(label);
|
|
2655
|
+
switch(unit.kind){
|
|
2656
|
+
case 'aggregate':
|
|
2657
|
+
{
|
|
2658
|
+
const contractImport = `../../../domain/aggregates/${unit.name}`;
|
|
2659
|
+
if (inMemoryDb) {
|
|
2660
|
+
const section = addInMemoryDbSection(naming, ownerFolder.subitem([
|
|
2661
|
+
'domain',
|
|
2662
|
+
'aggregates',
|
|
2663
|
+
unit.name
|
|
2664
|
+
]).path);
|
|
2665
|
+
const file = implementationFolder.createFile(fileName, `
|
|
2666
|
+
${inMemoryDbTypeImport(implementationFolder.subitem([
|
|
2667
|
+
fileName
|
|
2668
|
+
]).path)}
|
|
2669
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2670
|
+
|
|
2671
|
+
export class ${className} implements ${ContractName} {
|
|
2672
|
+
${inMemoryDbSectionMembers(section, false)}
|
|
2673
|
+
}
|
|
2674
|
+
`.trim());
|
|
2675
|
+
return {
|
|
2676
|
+
file,
|
|
2677
|
+
className
|
|
2678
|
+
};
|
|
2679
|
+
}
|
|
2680
|
+
const file = implementationFolder.createFile(fileName, `
|
|
2681
|
+
import { ${ContractName} } from '${contractImport}'
|
|
2682
|
+
|
|
2683
|
+
export class ${className} implements ${ContractName} {
|
|
2684
|
+
constructor() {}
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
`.trim());
|
|
2688
|
+
return {
|
|
2689
|
+
file,
|
|
2690
|
+
className
|
|
2691
|
+
};
|
|
2692
|
+
}
|
|
2693
|
+
case 'command':
|
|
2694
|
+
case 'query':
|
|
2695
|
+
{
|
|
2696
|
+
const folderName = 'command' === unit.kind ? 'commands' : 'queries';
|
|
2697
|
+
const file = implementationFolder.createFile(fileName, handlerImplementation(ContractName, className, `../../../application/${folderName}/${naming.fileName}-${unit.kind}`));
|
|
2698
|
+
if (inMemoryDb) injectInMemoryDb(file, className);
|
|
2699
|
+
return {
|
|
2700
|
+
file,
|
|
2701
|
+
className
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2704
|
+
case 'port':
|
|
2705
|
+
{
|
|
2706
|
+
const file = implementationFolder.createFile(fileName, `
|
|
2707
|
+
import { ${ContractName} } from '../../../application/ports/${naming.fileName}'
|
|
2708
|
+
|
|
2709
|
+
export class ${className} extends ${ContractName} {
|
|
2710
|
+
|
|
2711
|
+
}
|
|
2712
|
+
`.trim());
|
|
2713
|
+
return {
|
|
2714
|
+
file,
|
|
2715
|
+
className
|
|
2716
|
+
};
|
|
2717
|
+
}
|
|
2718
|
+
default:
|
|
2719
|
+
throw new Error(`${unit.kind} has no implementations`);
|
|
2720
|
+
}
|
|
2721
|
+
};
|
|
2722
|
+
const inMemoryRepositoryWiring = (ownerFolder, unit, wireFile)=>(implementation, dependency)=>{
|
|
2723
|
+
if ('aggregate' !== unit.kind || !isInMemoryDb(dependency)) return false;
|
|
2724
|
+
keepInMemoryDbSection(new File(implementation.file), addInMemoryDbSection(new UnknownFormatNaming(unit.name), ownerFolder.subitem([
|
|
2725
|
+
'domain',
|
|
2726
|
+
'aggregates',
|
|
2727
|
+
unit.name
|
|
2728
|
+
]).path));
|
|
2729
|
+
wireInMemoryDb(wireFile, implementation.className);
|
|
2730
|
+
return true;
|
|
2731
|
+
};
|
|
2732
|
+
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
2733
|
+
const prefix = `${folders.join('-')}-`;
|
|
2734
|
+
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
2735
|
+
return [
|
|
2736
|
+
...folders,
|
|
2737
|
+
last
|
|
2738
|
+
].join('/');
|
|
2739
|
+
};
|
|
2740
|
+
const declaredClassName = (filePath, suffix, name)=>{
|
|
2741
|
+
const content = node_fs.readFileSync(filePath, 'utf8');
|
|
2742
|
+
const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
2743
|
+
return declared ?? new NestedName(name).ClassName;
|
|
2744
|
+
};
|
|
2745
|
+
const findReactModules = (reactFolder, kind)=>{
|
|
2746
|
+
const modules = 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
2747
|
+
const folders = node_path.relative(node_path.join(reactFolder, 'pages'), node_path.dirname(file)).split(node_path.sep).filter((segment)=>!!segment);
|
|
2748
|
+
const fileBase = node_path.basename(file, '-page.tsx');
|
|
2749
|
+
const name = react_module_move_nestedName(folders, fileBase);
|
|
2750
|
+
return {
|
|
2751
|
+
kind,
|
|
2752
|
+
name,
|
|
2753
|
+
path: file,
|
|
2498
2754
|
fileBase,
|
|
2499
2755
|
ClassName: declaredClassName(file, 'Page', name)
|
|
2500
2756
|
};
|
|
@@ -2562,11 +2818,403 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2562
2818
|
}
|
|
2563
2819
|
});
|
|
2564
2820
|
};
|
|
2821
|
+
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
2822
|
+
if ('ports' === kind) return crossContext ? [
|
|
2823
|
+
{
|
|
2824
|
+
name: 'System: cross-context (calls handlers in another bounded context)',
|
|
2825
|
+
value: crossContextImplementation
|
|
2826
|
+
}
|
|
2827
|
+
] : [];
|
|
2828
|
+
return ConfigFile.exists && usesInMemoryDb('in-memory') ? [
|
|
2829
|
+
{
|
|
2830
|
+
name: 'System: in-memory (uses the shared in-memory database)',
|
|
2831
|
+
value: 'in-memory'
|
|
2832
|
+
}
|
|
2833
|
+
] : [];
|
|
2834
|
+
};
|
|
2835
|
+
const configurationSections = [
|
|
2836
|
+
'project',
|
|
2837
|
+
'backend',
|
|
2838
|
+
'frontend'
|
|
2839
|
+
];
|
|
2840
|
+
const configureProject = async (config)=>{
|
|
2841
|
+
const rootFolder = await input({
|
|
2842
|
+
message: 'Root folder (use "/" for inner folders):',
|
|
2843
|
+
default: config.project.rootFolder,
|
|
2844
|
+
validate: (value)=>value.trim() ? true : 'Root folder is required'
|
|
2845
|
+
});
|
|
2846
|
+
ConfigFile.update({
|
|
2847
|
+
project: {
|
|
2848
|
+
...config.project,
|
|
2849
|
+
rootFolder: rootFolder.trim()
|
|
2850
|
+
}
|
|
2851
|
+
});
|
|
2852
|
+
};
|
|
2853
|
+
const createTestBranch = Symbol('create-test-branch');
|
|
2854
|
+
const noTestBranch = Symbol('no-test-branch');
|
|
2855
|
+
const promptEnvBranches = async (current)=>{
|
|
2856
|
+
const kind = await prompts_select({
|
|
2857
|
+
message: 'envBranchedWire branches:',
|
|
2858
|
+
choices: [
|
|
2859
|
+
{
|
|
2860
|
+
name: 'Default: test, development, production by NODE_ENV',
|
|
2861
|
+
value: 'default'
|
|
2862
|
+
},
|
|
2863
|
+
{
|
|
2864
|
+
name: 'Custom branches',
|
|
2865
|
+
value: 'custom'
|
|
2866
|
+
}
|
|
2867
|
+
],
|
|
2868
|
+
default: current ? 'custom' : 'default'
|
|
2869
|
+
});
|
|
2870
|
+
if ('default' === kind) return;
|
|
2871
|
+
const parse = (value)=>value.split(',').map((name)=>name.trim()).filter(Boolean);
|
|
2872
|
+
const names = parse(await input({
|
|
2873
|
+
message: 'Branches (comma-separated):',
|
|
2874
|
+
default: current?.names.join(', '),
|
|
2875
|
+
validate: (value)=>{
|
|
2876
|
+
const names = parse(value);
|
|
2877
|
+
if (!names.length) return 'Enter at least one branch.';
|
|
2878
|
+
if (1 === names.length && 'test' === names[0]) return 'Add a branch for primary implementations besides test.';
|
|
2879
|
+
const invalid = names.find((name)=>!branchNameSchema.safeParse(name).success);
|
|
2880
|
+
if (invalid) return `${invalid}: use lowercase letters and digits, e.g. staging.`;
|
|
2881
|
+
return new Set(names).size === names.length ? true : 'Branch names must be unique.';
|
|
2882
|
+
}
|
|
2883
|
+
}));
|
|
2884
|
+
const test = await prompts_select({
|
|
2885
|
+
message: 'Test branch:',
|
|
2886
|
+
choices: [
|
|
2887
|
+
...names.map((name)=>({
|
|
2888
|
+
name,
|
|
2889
|
+
value: name,
|
|
2890
|
+
disabled: 1 === names.length ? '(the only branch)' : false
|
|
2891
|
+
})),
|
|
2892
|
+
...names.includes('test') ? [] : [
|
|
2893
|
+
{
|
|
2894
|
+
name: 'Create a "test" branch',
|
|
2895
|
+
value: createTestBranch
|
|
2896
|
+
}
|
|
2897
|
+
],
|
|
2898
|
+
{
|
|
2899
|
+
name: 'No test branch: every branch uses the primary implementation',
|
|
2900
|
+
value: noTestBranch
|
|
2901
|
+
}
|
|
2902
|
+
],
|
|
2903
|
+
default: current && !current.test ? noTestBranch : current?.test && names.includes(current.test) ? current.test : names.includes('test') ? 'test' : createTestBranch
|
|
2904
|
+
});
|
|
2905
|
+
if (test === noTestBranch) return {
|
|
2906
|
+
names
|
|
2907
|
+
};
|
|
2908
|
+
return test === createTestBranch ? {
|
|
2909
|
+
names: [
|
|
2910
|
+
...names,
|
|
2911
|
+
'test'
|
|
2912
|
+
],
|
|
2913
|
+
test: 'test'
|
|
2914
|
+
} : {
|
|
2915
|
+
names,
|
|
2916
|
+
test
|
|
2917
|
+
};
|
|
2918
|
+
};
|
|
2919
|
+
const configureBackend = async (config)=>{
|
|
2920
|
+
const current = config.backend;
|
|
2921
|
+
const domainFirstPackages = await prompts_checkbox({
|
|
2922
|
+
message: '@domain-first packages',
|
|
2923
|
+
choices: config_file_domainFirstPackages.map((value)=>({
|
|
2924
|
+
name: value,
|
|
2925
|
+
value,
|
|
2926
|
+
checked: current?.domainFirstPackages.includes(value) ?? false
|
|
2927
|
+
}))
|
|
2928
|
+
});
|
|
2929
|
+
const envBranches = domainFirstPackages.includes('@domain-first/wire') ? await promptEnvBranches(current?.envBranches) : current?.envBranches;
|
|
2930
|
+
const withInMemoryDb = await prompts_confirm({
|
|
2931
|
+
message: 'Scaffold in-memory DB for test implementations',
|
|
2932
|
+
default: current ? Boolean(current.withInMemoryDb) : true
|
|
2933
|
+
});
|
|
2934
|
+
const withTests = await prompts_confirm({
|
|
2935
|
+
message: 'Scaffold unit tests',
|
|
2936
|
+
default: current ? Boolean(current.testingLibrary) : true
|
|
2937
|
+
});
|
|
2938
|
+
const testingLibrary = withTests ? await input({
|
|
2939
|
+
message: 'Unit testing library:',
|
|
2940
|
+
default: current?.testingLibrary ?? 'vitest'
|
|
2941
|
+
}) : void 0;
|
|
2942
|
+
ConfigFile.update({
|
|
2943
|
+
backend: {
|
|
2944
|
+
...current,
|
|
2945
|
+
domainFirstPackages,
|
|
2946
|
+
envBranches,
|
|
2947
|
+
withInMemoryDb,
|
|
2948
|
+
testingLibrary,
|
|
2949
|
+
rules: scaffoldBackendRules(current?.rules)
|
|
2950
|
+
}
|
|
2951
|
+
});
|
|
2952
|
+
const rootFolder = new Folder(new ProjectRoot().path);
|
|
2953
|
+
const rootFolderName = config.project.rootFolder;
|
|
2954
|
+
const wiringFolder = rootFolder.subitem([
|
|
2955
|
+
rootFolderName,
|
|
2956
|
+
'shared-kernel',
|
|
2957
|
+
'wiring'
|
|
2958
|
+
]);
|
|
2959
|
+
const notes = [];
|
|
2960
|
+
const envBranchedWireExisted = new File(node_path.join(wiringFolder.path, 'env-branched-wire.ts')).exists;
|
|
2961
|
+
if (domainFirstPackages.includes('@domain-first/wire') && envBranchedWireExisted && JSON.stringify(envBranches ?? null) !== JSON.stringify(current?.envBranches ?? null)) {
|
|
2962
|
+
const { names } = envBranches ?? defaultEnvBranches;
|
|
2963
|
+
notes.push(`${rootFolderName}/shared-kernel/wiring/env-branched-wire.ts and existing envBranchedWire calls keep their branches: change them to ${names.join(', ')} yourself`);
|
|
2964
|
+
}
|
|
2965
|
+
withoutOverwrites(()=>{
|
|
2966
|
+
if (domainFirstPackages.includes('@domain-first/wire')) wiringFolder.createFile('env-branched-wire.ts', envBranchedWireSource());
|
|
2967
|
+
if (withInMemoryDb) scaffoldInMemoryDb(rootFolder.subitem([
|
|
2968
|
+
rootFolderName,
|
|
2969
|
+
'shared-kernel'
|
|
2970
|
+
]));
|
|
2971
|
+
});
|
|
2972
|
+
if (envBranches && !envBranchedWireExisted) notes.push(`${rootFolderName}/shared-kernel/wiring/env-branched-wire.ts doesn't compile until you write currentBranch: return the branch this process runs in (${envBranches.names.join(', ')})`);
|
|
2973
|
+
return notes;
|
|
2974
|
+
};
|
|
2975
|
+
const configureFrontend = async (config)=>{
|
|
2976
|
+
const currentFramework = config.frontend?.react?.framework ?? (hasDependency('next') ? 'next' : 'react');
|
|
2977
|
+
const framework = await prompts_select({
|
|
2978
|
+
message: 'Frontend framework:',
|
|
2979
|
+
choices: [
|
|
2980
|
+
{
|
|
2981
|
+
name: 'React',
|
|
2982
|
+
value: 'react'
|
|
2983
|
+
},
|
|
2984
|
+
{
|
|
2985
|
+
name: 'Next.js',
|
|
2986
|
+
value: 'next'
|
|
2987
|
+
}
|
|
2988
|
+
],
|
|
2989
|
+
default: currentFramework
|
|
2990
|
+
});
|
|
2991
|
+
const withNextAdapter = 'next' === framework && config.backend ? await askNextAdapter({
|
|
2992
|
+
nextSelected: true
|
|
2993
|
+
}) : false;
|
|
2994
|
+
const withStorybook = await prompts_confirm({
|
|
2995
|
+
message: 'Use Storybook',
|
|
2996
|
+
default: config.frontend?.react ? Boolean(config.frontend.react.storybookFramework) : true
|
|
2997
|
+
});
|
|
2998
|
+
const storybookFramework = withStorybook ? storybookFrameworkPackage : void 0;
|
|
2999
|
+
ConfigFile.update({
|
|
3000
|
+
frontend: {
|
|
3001
|
+
...config.frontend,
|
|
3002
|
+
react: {
|
|
3003
|
+
...config.frontend?.react,
|
|
3004
|
+
framework,
|
|
3005
|
+
storybookFramework
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
});
|
|
3009
|
+
return {
|
|
3010
|
+
withNextAdapter,
|
|
3011
|
+
nextSteps: [
|
|
3012
|
+
...missingPackages('next' === framework ? [
|
|
3013
|
+
'next',
|
|
3014
|
+
'react',
|
|
3015
|
+
'react-dom'
|
|
3016
|
+
] : [
|
|
3017
|
+
'react',
|
|
3018
|
+
'react-dom'
|
|
3019
|
+
]),
|
|
3020
|
+
...withStorybook ? await addStorybook() : []
|
|
3021
|
+
]
|
|
3022
|
+
};
|
|
3023
|
+
};
|
|
3024
|
+
const configureRest = async (withNextAdapter)=>{
|
|
3025
|
+
const backend = ConfigFile.Instance.data.backend;
|
|
3026
|
+
if (!backend) return [];
|
|
3027
|
+
const withRest = backend.domainFirstPackages.includes('@domain-first/handlers-rest');
|
|
3028
|
+
const nextSelected = ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
3029
|
+
if (void 0 === withNextAdapter && (withRest || nextSelected)) withNextAdapter = await askNextAdapter();
|
|
3030
|
+
if (!withRest && !withNextAdapter) return [];
|
|
3031
|
+
if (withNextAdapter && !withRest) ConfigFile.update({
|
|
3032
|
+
backend: {
|
|
3033
|
+
...backend,
|
|
3034
|
+
domainFirstPackages: [
|
|
3035
|
+
...backend.domainFirstPackages,
|
|
3036
|
+
'@domain-first/handlers-rest'
|
|
3037
|
+
]
|
|
3038
|
+
}
|
|
3039
|
+
});
|
|
3040
|
+
return scaffoldRestEndpointGeneratorFiles({
|
|
3041
|
+
withNextAdapter: withNextAdapter ?? false
|
|
3042
|
+
});
|
|
3043
|
+
};
|
|
3044
|
+
const initializeUseCase = async (section)=>{
|
|
3045
|
+
const existing = ConfigFile.exists;
|
|
3046
|
+
if (!existing) ConfigFile.write({
|
|
3047
|
+
project: {
|
|
3048
|
+
rootFolder: 'src'
|
|
3049
|
+
}
|
|
3050
|
+
});
|
|
3051
|
+
let sections = configurationSections;
|
|
3052
|
+
if (section) sections = 'project' === section || existing ? [
|
|
3053
|
+
section
|
|
3054
|
+
] : [
|
|
3055
|
+
'project',
|
|
3056
|
+
section
|
|
3057
|
+
];
|
|
3058
|
+
else if (existing) {
|
|
3059
|
+
const selected = await prompts_select({
|
|
3060
|
+
message: 'Configuration section:',
|
|
3061
|
+
choices: [
|
|
3062
|
+
...configurationSections.map((value)=>({
|
|
3063
|
+
name: `${value[0].toUpperCase()}${value.slice(1)}${ConfigFile.Instance.data[value] ? '' : ' (not configured)'}`,
|
|
3064
|
+
value
|
|
3065
|
+
})),
|
|
3066
|
+
{
|
|
3067
|
+
name: 'All sections',
|
|
3068
|
+
value: 'all'
|
|
3069
|
+
}
|
|
3070
|
+
]
|
|
3071
|
+
});
|
|
3072
|
+
sections = 'all' === selected ? configurationSections : [
|
|
3073
|
+
selected
|
|
3074
|
+
];
|
|
3075
|
+
}
|
|
3076
|
+
const nextSteps = [];
|
|
3077
|
+
let backendConfigured = false;
|
|
3078
|
+
let withNextAdapter;
|
|
3079
|
+
for (const currentSection of sections){
|
|
3080
|
+
console.log(`\n${currentSection[0].toUpperCase()}${currentSection.slice(1)} configuration`);
|
|
3081
|
+
if (!section && sections.length > 1 && !await prompts_confirm({
|
|
3082
|
+
message: `Configure ${currentSection} now?`,
|
|
3083
|
+
default: true
|
|
3084
|
+
})) {
|
|
3085
|
+
if ('project' === currentSection) console.log(`Keeping project root folder: ${ConfigFile.Instance.data.project.rootFolder}.`);
|
|
3086
|
+
nextSteps.push(`configure ${currentSection} later with df-init --section ${currentSection}`);
|
|
3087
|
+
continue;
|
|
3088
|
+
}
|
|
3089
|
+
const config = ConfigFile.Instance.data;
|
|
3090
|
+
switch(currentSection){
|
|
3091
|
+
case 'project':
|
|
3092
|
+
await configureProject(config);
|
|
3093
|
+
break;
|
|
3094
|
+
case 'backend':
|
|
3095
|
+
nextSteps.push(...await configureBackend(config));
|
|
3096
|
+
backendConfigured = true;
|
|
3097
|
+
break;
|
|
3098
|
+
case 'frontend':
|
|
3099
|
+
{
|
|
3100
|
+
const frontend = await configureFrontend(config);
|
|
3101
|
+
withNextAdapter = frontend.withNextAdapter;
|
|
3102
|
+
nextSteps.push(...frontend.nextSteps);
|
|
3103
|
+
break;
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
if (backendConfigured || withNextAdapter) {
|
|
3108
|
+
const restSteps = await configureRest(withNextAdapter);
|
|
3109
|
+
nextSteps.push(...missingDomainFirstPackages(), ...restSteps);
|
|
3110
|
+
}
|
|
3111
|
+
return nextSteps;
|
|
3112
|
+
};
|
|
3113
|
+
const noAggregate = 'No aggregate';
|
|
3114
|
+
const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
3115
|
+
const root = new ProjectRoot().path;
|
|
3116
|
+
const rootFolderPath = node_path.join(root, ConfigFile.Instance.data.project.rootFolder);
|
|
3117
|
+
const sharedKernelPath = node_path.join(rootFolderPath, 'shared-kernel');
|
|
3118
|
+
const units = findBackendUnits(ownerFolder.path);
|
|
3119
|
+
if (!units.length) return void report('No modules generated by df-scaffold were found here.');
|
|
3120
|
+
const unit = await interaction_select({
|
|
3121
|
+
key: 'module',
|
|
3122
|
+
id: unitId,
|
|
3123
|
+
message: 'Module:',
|
|
3124
|
+
choices: Object.keys(kindLayouts).flatMap((kind)=>{
|
|
3125
|
+
const group = units.filter((x)=>x.kind === kind);
|
|
3126
|
+
return group.length ? [
|
|
3127
|
+
new Separator(`── ${kindLayouts[group[0].kind].title}`),
|
|
3128
|
+
...group.map((value)=>({
|
|
3129
|
+
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
3130
|
+
value
|
|
3131
|
+
}))
|
|
3132
|
+
] : [];
|
|
3133
|
+
}),
|
|
3134
|
+
pageSize: 20
|
|
3135
|
+
});
|
|
3136
|
+
const placeName = (ownerPath)=>ownerPath === sharedKernelPath ? 'Shared Kernel' : `Bounded Context: ${node_path.basename(ownerPath)}`;
|
|
3137
|
+
const contexts = new Folder(rootFolderPath).subitem([
|
|
3138
|
+
'bounded-contexts'
|
|
3139
|
+
]).content.subfolderNames.map((name)=>node_path.join(rootFolderPath, 'bounded-contexts', name));
|
|
3140
|
+
const places = [
|
|
3141
|
+
unit.ownerPath,
|
|
3142
|
+
...contexts,
|
|
3143
|
+
...kindLayouts[unit.kind].sharedKernel ? [
|
|
3144
|
+
sharedKernelPath
|
|
3145
|
+
] : []
|
|
3146
|
+
].filter((place, index, all)=>all.indexOf(place) === index);
|
|
3147
|
+
const ownerPath = await interaction_select({
|
|
3148
|
+
key: 'targetContext',
|
|
3149
|
+
id: (owner)=>owner === sharedKernelPath ? 'shared-kernel' : node_path.basename(owner),
|
|
3150
|
+
message: 'Move to:',
|
|
3151
|
+
choices: places.map((value)=>({
|
|
3152
|
+
name: value === unit.ownerPath ? `${placeName(value)} (stays)` : placeName(value),
|
|
3153
|
+
value
|
|
3154
|
+
}))
|
|
3155
|
+
});
|
|
3156
|
+
let aggregate;
|
|
3157
|
+
const aggregates = ownerPath === sharedKernelPath ? [] : aggregatesOf(ownerPath);
|
|
3158
|
+
if (('entity' === unit.kind || 'value-object' === unit.kind) && aggregates.length) {
|
|
3159
|
+
const picked = await interaction_select({
|
|
3160
|
+
key: 'aggregate',
|
|
3161
|
+
message: 'Aggregate:',
|
|
3162
|
+
choices: [
|
|
3163
|
+
noAggregate,
|
|
3164
|
+
...aggregates
|
|
3165
|
+
],
|
|
3166
|
+
default: ownerPath === unit.ownerPath && unit.aggregate ? unit.aggregate : noAggregate
|
|
3167
|
+
});
|
|
3168
|
+
aggregate = picked === noAggregate ? void 0 : picked;
|
|
3169
|
+
}
|
|
3170
|
+
const target = (name)=>({
|
|
3171
|
+
ownerPath,
|
|
3172
|
+
aggregate,
|
|
3173
|
+
name: name.trim()
|
|
3174
|
+
});
|
|
3175
|
+
const name = await interaction_input({
|
|
3176
|
+
key: 'name',
|
|
3177
|
+
message: 'New name:',
|
|
3178
|
+
default: unit.name,
|
|
3179
|
+
validate: (value)=>validateBackendMove(unit, target(value), sharedKernelPath)
|
|
3180
|
+
});
|
|
3181
|
+
const result = moveBackendUnit(root, rootFolderPath, unit, target(name));
|
|
3182
|
+
if (result.violations) {
|
|
3183
|
+
if (isNonInteractive()) throw new RequestError('MOVE_NOT_ALLOWED', 'The move would cross bounded-context boundaries.', {
|
|
3184
|
+
violations: result.violations
|
|
3185
|
+
});
|
|
3186
|
+
report([
|
|
3187
|
+
"Nothing was moved: these imports would cross a bounded context boundary.",
|
|
3188
|
+
...result.violations.map(([from, to])=>` ${from} → ${to}`),
|
|
3189
|
+
'Give the other context its own query or command, or move what it depends on first.'
|
|
3190
|
+
].join('\n'));
|
|
3191
|
+
return;
|
|
3192
|
+
}
|
|
3193
|
+
const relative = (file)=>node_path.relative(root, file);
|
|
3194
|
+
report([
|
|
3195
|
+
'Files to move:',
|
|
3196
|
+
...result.moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
3197
|
+
...result.updated.length ? [
|
|
3198
|
+
'Files with updated imports and names:',
|
|
3199
|
+
...result.updated.map((file)=>` ${relative(file)}`)
|
|
3200
|
+
] : []
|
|
3201
|
+
].join('\n'));
|
|
3202
|
+
if (!await interaction_confirm({
|
|
3203
|
+
key: 'apply',
|
|
3204
|
+
message: 'Apply?',
|
|
3205
|
+
default: true
|
|
3206
|
+
})) {
|
|
3207
|
+
discardPendingChanges();
|
|
3208
|
+
report('Cancelled: nothing was written.');
|
|
3209
|
+
}
|
|
3210
|
+
};
|
|
2565
3211
|
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
2566
3212
|
const reactFolder = presentationReactFolder.path;
|
|
2567
3213
|
const modules = findReactModules(reactFolder, kind);
|
|
2568
|
-
if (!modules.length) return void
|
|
2569
|
-
const module = await
|
|
3214
|
+
if (!modules.length) return void report(`No ${kind}s generated by df-react were found.`);
|
|
3215
|
+
const module = await interaction_select({
|
|
3216
|
+
key: 'module',
|
|
3217
|
+
id: (value)=>value.name,
|
|
2570
3218
|
message: 'page' === kind ? 'Page:' : 'Widget:',
|
|
2571
3219
|
choices: modules.map((value)=>({
|
|
2572
3220
|
name: value.name,
|
|
@@ -2574,16 +3222,17 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
2574
3222
|
description: node_path.relative(reactFolder, value.path)
|
|
2575
3223
|
}))
|
|
2576
3224
|
});
|
|
2577
|
-
const name = await
|
|
3225
|
+
const name = await interaction_input({
|
|
3226
|
+
key: 'name',
|
|
2578
3227
|
message: 'New name (folders split by "/"):',
|
|
2579
3228
|
default: module.name,
|
|
2580
3229
|
validate: (value)=>validateMove(reactFolder, module, value)
|
|
2581
3230
|
});
|
|
2582
3231
|
const root = new ProjectRoot().path;
|
|
2583
3232
|
const { moves, updated } = moveReactModule(root, reactFolder, module, name);
|
|
2584
|
-
if (!moves.length && !updated.length) return void
|
|
3233
|
+
if (!moves.length && !updated.length) return void report('Nothing to change.');
|
|
2585
3234
|
const relative = (file)=>node_path.relative(root, file);
|
|
2586
|
-
|
|
3235
|
+
report([
|
|
2587
3236
|
'Files to move:',
|
|
2588
3237
|
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
2589
3238
|
...updated.length ? [
|
|
@@ -2591,21 +3240,105 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
2591
3240
|
...updated.map((file)=>` ${relative(file)}`)
|
|
2592
3241
|
] : []
|
|
2593
3242
|
].join('\n'));
|
|
2594
|
-
if (!await
|
|
3243
|
+
if (!await interaction_confirm({
|
|
3244
|
+
key: 'apply',
|
|
2595
3245
|
message: 'Apply?',
|
|
2596
3246
|
default: true
|
|
2597
3247
|
})) {
|
|
2598
3248
|
discardPendingChanges();
|
|
2599
|
-
|
|
3249
|
+
report('Cancelled: nothing was written.');
|
|
2600
3250
|
}
|
|
2601
3251
|
};
|
|
3252
|
+
const enterImplementationTypeOnce = Symbol('enter-implementation-type-once');
|
|
3253
|
+
const implementationTypeEntryChoices = [
|
|
3254
|
+
{
|
|
3255
|
+
name: 'Enter implementation type and save for future use',
|
|
3256
|
+
value: null
|
|
3257
|
+
},
|
|
3258
|
+
{
|
|
3259
|
+
name: 'Enter implementation type for this run only',
|
|
3260
|
+
value: enterImplementationTypeOnce
|
|
3261
|
+
}
|
|
3262
|
+
];
|
|
3263
|
+
const promptImplementationType = async (message, kind, { existing = [], purpose = 'primary', crossContext = false, remember = true } = {})=>{
|
|
3264
|
+
const roles = 'all' === purpose ? [
|
|
3265
|
+
'primary',
|
|
3266
|
+
'test'
|
|
3267
|
+
] : [
|
|
3268
|
+
purpose
|
|
3269
|
+
];
|
|
3270
|
+
const saved = [
|
|
3271
|
+
...new Set(roles.flatMap((role)=>savedImplementations(kind, role)))
|
|
3272
|
+
].filter((label)=>label !== crossContextImplementation || 'ports' === kind && crossContext);
|
|
3273
|
+
const allowCrossContext = 'ports' === kind && crossContext;
|
|
3274
|
+
const system = systemImplementationChoices(kind, crossContext);
|
|
3275
|
+
const choices = saved.map((label)=>system.find(({ value })=>value === label) ?? {
|
|
3276
|
+
name: label,
|
|
3277
|
+
value: label
|
|
3278
|
+
});
|
|
3279
|
+
for (const choice of system)if (!choices.some(({ value })=>value === choice.value)) choices.push(choice);
|
|
3280
|
+
const defaultType = saved.find((label)=>!existing.includes(label));
|
|
3281
|
+
const preferred = choices.find(({ value })=>value === defaultType && !existing.includes(value)) ?? choices.find(({ value })=>!existing.includes(value));
|
|
3282
|
+
const validateLabel = (value)=>{
|
|
3283
|
+
const label = value.trim();
|
|
3284
|
+
if (!allowCrossContext && label === crossContextImplementation) return 'Cross-context implementations require an application port with a neighboring bounded context.';
|
|
3285
|
+
if (!kebabName.test(label)) return 'Use lowercase kebab-case, e.g. prisma or in-memory.';
|
|
3286
|
+
return existing.includes(label) ? `The ${label} implementation already exists.` : true;
|
|
3287
|
+
};
|
|
3288
|
+
if (isNonInteractive()) {
|
|
3289
|
+
const key = 'test' === purpose ? 'testImplementation' : 'implementation';
|
|
3290
|
+
const implementation = answerFor(key);
|
|
3291
|
+
if (!implementation) throw new RequestError('MISSING_PARAMETER', `Provide ${key}.`, {
|
|
3292
|
+
field: key
|
|
3293
|
+
});
|
|
3294
|
+
const valid = validateLabel(implementation.type);
|
|
3295
|
+
if (true !== valid) throw new RequestError('INVALID_IMPLEMENTATION', valid, {
|
|
3296
|
+
field: key
|
|
3297
|
+
});
|
|
3298
|
+
const label = implementation.type.trim();
|
|
3299
|
+
const saveForFutureUse = implementation.save ?? false;
|
|
3300
|
+
if (remember && saveForFutureUse && !system.some((choice)=>choice.value === label)) rememberImplementation(kind, 'all' === purpose ? 'primary' : purpose, label);
|
|
3301
|
+
return {
|
|
3302
|
+
label,
|
|
3303
|
+
saveForFutureUse
|
|
3304
|
+
};
|
|
3305
|
+
}
|
|
3306
|
+
const type = await interaction_select({
|
|
3307
|
+
message,
|
|
3308
|
+
choices: [
|
|
3309
|
+
...choices.map((choice)=>({
|
|
3310
|
+
...choice,
|
|
3311
|
+
disabled: existing.includes(choice.value)
|
|
3312
|
+
})),
|
|
3313
|
+
...implementationTypeEntryChoices
|
|
3314
|
+
],
|
|
3315
|
+
default: preferred?.value ?? null
|
|
3316
|
+
});
|
|
3317
|
+
if ('string' == typeof type) return {
|
|
3318
|
+
label: type,
|
|
3319
|
+
saveForFutureUse: true
|
|
3320
|
+
};
|
|
3321
|
+
const saveForFutureUse = type !== enterImplementationTypeOnce;
|
|
3322
|
+
const label = (await interaction_input({
|
|
3323
|
+
message,
|
|
3324
|
+
default: defaultType ?? '',
|
|
3325
|
+
validate: validateLabel
|
|
3326
|
+
})).trim();
|
|
3327
|
+
if (saveForFutureUse && remember && !choices.some(({ value })=>value === label)) rememberImplementation(kind, 'all' === purpose ? 'primary' : purpose, label);
|
|
3328
|
+
return {
|
|
3329
|
+
label,
|
|
3330
|
+
saveForFutureUse
|
|
3331
|
+
};
|
|
3332
|
+
};
|
|
2602
3333
|
const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
2603
|
-
const aggregateName = await
|
|
3334
|
+
const aggregateName = await interaction_input({
|
|
3335
|
+
key: 'name',
|
|
2604
3336
|
message: 'Aggregate name:'
|
|
2605
3337
|
});
|
|
2606
3338
|
const aggregateNaming = new UnknownFormatNaming(aggregateName);
|
|
2607
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
2608
|
-
const withRepository = await
|
|
3339
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3340
|
+
const withRepository = await interaction_confirm({
|
|
3341
|
+
key: 'withRepository',
|
|
2609
3342
|
message: 'With Repository'
|
|
2610
3343
|
});
|
|
2611
3344
|
const aggregatesFolder = boundedContextFolder.subitem([
|
|
@@ -2613,7 +3346,7 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
|
2613
3346
|
'aggregates',
|
|
2614
3347
|
aggregateName
|
|
2615
3348
|
]);
|
|
2616
|
-
const withTypes = ConfigFile.
|
|
3349
|
+
const withTypes = ConfigFile.backend.domainFirstPackages.includes('@domain-first/types');
|
|
2617
3350
|
aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.ts`, withTypes ? `
|
|
2618
3351
|
import { domainType } from '@domain-first/types'
|
|
2619
3352
|
|
|
@@ -2622,7 +3355,7 @@ export class ${aggregateNaming.ClassName} extends domainType() {
|
|
|
2622
3355
|
}`.trim() : `export class ${aggregateNaming.ClassName} {}`);
|
|
2623
3356
|
const barrelFile = aggregatesFolder.createFile("index.ts", `export * from './${aggregateNaming.fileName}.aggregate-root'`);
|
|
2624
3357
|
if (scaffoldUnitTests) aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.spec.ts`, `
|
|
2625
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3358
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
2626
3359
|
import { ${aggregateNaming.ClassName} } from './${aggregateNaming.fileName}.aggregate-root'
|
|
2627
3360
|
|
|
2628
3361
|
let ${aggregateNaming.variableName}: ${aggregateNaming.ClassName}
|
|
@@ -2640,61 +3373,35 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
2640
3373
|
if (withRepository) {
|
|
2641
3374
|
aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.ts`, `export abstract class ${aggregateNaming.ClassName}Repository { }`);
|
|
2642
3375
|
barrelFile.addLine(`export * from './${aggregateNaming.fileName}-repository'`);
|
|
2643
|
-
const infrastructureImplementationType = await
|
|
2644
|
-
message: 'Repository infrastructure implementation type:',
|
|
2645
|
-
default: ConfigFile.Instance.data.defaultPersistenceLayerImplementation
|
|
2646
|
-
});
|
|
3376
|
+
const { label: infrastructureImplementationType } = await promptImplementationType('Repository infrastructure implementation type:', 'repositories');
|
|
2647
3377
|
let addTestImplementation = false;
|
|
2648
3378
|
let testImplementationType = '';
|
|
2649
|
-
addTestImplementation = await
|
|
3379
|
+
addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
3380
|
+
key: 'withTestImplementation',
|
|
2650
3381
|
message: 'Add a test implementation for Repository'
|
|
2651
3382
|
});
|
|
2652
|
-
if (addTestImplementation) testImplementationType = await
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
'repositories'
|
|
2659
|
-
]);
|
|
3383
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test Repository infrastructure implementation type:', 'repositories', {
|
|
3384
|
+
purpose: 'test',
|
|
3385
|
+
existing: [
|
|
3386
|
+
infrastructureImplementationType
|
|
3387
|
+
]
|
|
3388
|
+
})).label;
|
|
2660
3389
|
const implementationTypes = [
|
|
2661
3390
|
infrastructureImplementationType,
|
|
2662
3391
|
testImplementationType
|
|
2663
3392
|
].filter((x)=>!!x);
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
]
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
const section = addInMemoryDbSection(aggregateNaming, aggregatesFolder.path);
|
|
2672
|
-
repositoryFolder.createFile(repositoryFileName, `
|
|
2673
|
-
${inMemoryDbTypeImport(repositoryFolder.subitem([
|
|
2674
|
-
repositoryFileName
|
|
2675
|
-
]).path)}
|
|
2676
|
-
import { ${aggregateNaming.ClassName}Repository } from '../../../domain/aggregates/${aggregateName}'
|
|
2677
|
-
|
|
2678
|
-
export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implements ${aggregateNaming.ClassName}Repository {
|
|
2679
|
-
${inMemoryDbSectionMembers(section, false)}
|
|
2680
|
-
}
|
|
2681
|
-
`.trim());
|
|
2682
|
-
continue;
|
|
2683
|
-
}
|
|
2684
|
-
repositoryFolder.createFile(repositoryFileName, `
|
|
2685
|
-
import { ${aggregateNaming.ClassName}Repository } from '../../../domain/aggregates/${aggregateName}'
|
|
2686
|
-
|
|
2687
|
-
export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implements ${aggregateNaming.ClassName}Repository {
|
|
2688
|
-
constructor() {}
|
|
2689
|
-
}
|
|
2690
|
-
|
|
2691
|
-
`.trim());
|
|
2692
|
-
}
|
|
3393
|
+
const repository = {
|
|
3394
|
+
kind: 'aggregate',
|
|
3395
|
+
name: aggregateName,
|
|
3396
|
+
ownerPath: boundedContextFolder.path,
|
|
3397
|
+
labels: []
|
|
3398
|
+
};
|
|
3399
|
+
for (const implementation of implementationTypes)createImplementation(boundedContextFolder, repository, new UnknownFormatNaming(implementation).fileName);
|
|
2693
3400
|
if (scaffoldUnitTests) {
|
|
2694
3401
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
2695
3402
|
const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
|
|
2696
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
2697
|
-
${ConfigFile.
|
|
3403
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3404
|
+
${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
|
|
2698
3405
|
import type { ${aggregateNaming.ClassName}Repository } from './${aggregateNaming.fileName}-repository'` : `import { ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository } from '../../../infrastructure/repositories/${implementationNaming.fileName}/${implementationNaming.fileName}-${aggregateNaming.fileName}-repository'
|
|
2699
3406
|
|
|
2700
3407
|
type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`}
|
|
@@ -2702,18 +3409,18 @@ type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}$
|
|
|
2702
3409
|
let ${aggregateNaming.variableName}Repository: ${aggregateNaming.ClassName}Repository
|
|
2703
3410
|
|
|
2704
3411
|
beforeEach(() => {
|
|
2705
|
-
${aggregateNaming.variableName}Repository = ${ConfigFile.
|
|
3412
|
+
${aggregateNaming.variableName}Repository = ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${aggregateNaming.ClassName}Repository()` : `new ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository()`}
|
|
2706
3413
|
})
|
|
2707
3414
|
|
|
2708
3415
|
describe('${aggregateNaming.withSpaces} repository', () => {
|
|
2709
|
-
test('can be ${ConfigFile.
|
|
3416
|
+
test('can be ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
|
|
2710
3417
|
expect(${aggregateNaming.variableName}Repository).toBeDefined()
|
|
2711
3418
|
})
|
|
2712
3419
|
})
|
|
2713
3420
|
`.trim());
|
|
2714
|
-
if (!ConfigFile.
|
|
3421
|
+
if (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
|
|
2715
3422
|
}
|
|
2716
|
-
if (ConfigFile.
|
|
3423
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2717
3424
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
2718
3425
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
2719
3426
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -2726,27 +3433,19 @@ ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fil
|
|
|
2726
3433
|
|
|
2727
3434
|
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${aggregateNaming.ClassName}Repository, [])`).join('\n\n')}
|
|
2728
3435
|
|
|
2729
|
-
export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
|
|
2730
|
-
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
2731
|
-
development: wire${implementationNaming.ClassName}Implementation,
|
|
2732
|
-
production: wire${implementationNaming.ClassName}Implementation
|
|
2733
|
-
})
|
|
3436
|
+
export const wire${aggregateNaming.ClassName}Repository = envBranchedWire(${envBranchedWireArgument(`wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation`, `wire${implementationNaming.ClassName}Implementation`)})
|
|
2734
3437
|
`.trim());
|
|
2735
|
-
await wireNewModuleDependencies(boundedContextFolder, wireFile, (
|
|
2736
|
-
if (!isInMemoryDb(dependency)) return false;
|
|
2737
|
-
keepInMemoryDbSection(new File(implementation.file), addInMemoryDbSection(aggregateNaming, aggregatesFolder.path));
|
|
2738
|
-
wireInMemoryDb(wireFile, implementation.className);
|
|
2739
|
-
return true;
|
|
2740
|
-
});
|
|
3438
|
+
await wireNewModuleDependencies(boundedContextFolder, wireFile, inMemoryRepositoryWiring(boundedContextFolder, repository, wireFile));
|
|
2741
3439
|
}
|
|
2742
3440
|
}
|
|
2743
3441
|
};
|
|
2744
3442
|
const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
|
|
2745
|
-
const name = await
|
|
3443
|
+
const name = await interaction_input({
|
|
3444
|
+
key: 'name',
|
|
2746
3445
|
message: 'Name: '
|
|
2747
3446
|
});
|
|
2748
3447
|
const naming = new UnknownFormatNaming(name);
|
|
2749
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3448
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
2750
3449
|
const wiringFolder = boundedContextFolder.subitem([
|
|
2751
3450
|
'wiring',
|
|
2752
3451
|
'application-ports'
|
|
@@ -2760,43 +3459,37 @@ export abstract class ${naming.ClassName} {
|
|
|
2760
3459
|
|
|
2761
3460
|
}
|
|
2762
3461
|
`.trim());
|
|
2763
|
-
const
|
|
2764
|
-
|
|
2765
|
-
|
|
3462
|
+
const crossContext = hasNeighboringBoundedContext(boundedContextFolder.path);
|
|
3463
|
+
const { label: implementationType } = await promptImplementationType('Adapter implementation type:', 'ports', {
|
|
3464
|
+
crossContext
|
|
2766
3465
|
});
|
|
2767
|
-
const addTestImplementation = await
|
|
3466
|
+
const addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
3467
|
+
key: 'withTestImplementation',
|
|
2768
3468
|
message: 'With test implementation'
|
|
2769
3469
|
});
|
|
2770
3470
|
let testImplementationType = '';
|
|
2771
|
-
if (addTestImplementation) testImplementationType = await
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
]);
|
|
3471
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test adapter implementation type:', 'ports', {
|
|
3472
|
+
existing: [
|
|
3473
|
+
implementationType
|
|
3474
|
+
],
|
|
3475
|
+
purpose: 'test',
|
|
3476
|
+
crossContext
|
|
3477
|
+
})).label;
|
|
2779
3478
|
const implementationTypes = [
|
|
2780
3479
|
implementationType,
|
|
2781
3480
|
testImplementationType
|
|
2782
|
-
].filter((x)=>!!x);
|
|
2783
|
-
for (const implementation of implementationTypes){
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
]
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
export class ${currentNaming.ClassName} extends ${naming.ClassName} {
|
|
2791
|
-
|
|
2792
|
-
}
|
|
2793
|
-
`.trim());
|
|
2794
|
-
}
|
|
3481
|
+
].filter((x)=>!!x).map((x)=>new UnknownFormatNaming(x).fileName);
|
|
3482
|
+
for (const implementation of implementationTypes)createImplementation(boundedContextFolder, {
|
|
3483
|
+
kind: 'port',
|
|
3484
|
+
name: naming.fileName,
|
|
3485
|
+
ownerPath: boundedContextFolder.path,
|
|
3486
|
+
labels: []
|
|
3487
|
+
}, implementation);
|
|
2795
3488
|
if (scaffoldUnitTests) {
|
|
2796
3489
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
2797
3490
|
applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
|
|
2798
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
2799
|
-
${ConfigFile.
|
|
3491
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3492
|
+
${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `import { type ${naming.ClassName} } from './${naming.fileName}'
|
|
2800
3493
|
import { wire${naming.ClassName} } from '../../wiring/application-ports/wire-${naming.fileName}'` : `import { ${implementationNaming.ClassName}${naming.ClassName} } from '../../infrastructure/application-adapters/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}'
|
|
2801
3494
|
|
|
2802
3495
|
type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`}
|
|
@@ -2804,17 +3497,17 @@ type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`
|
|
|
2804
3497
|
let ${naming.variableName}: ${naming.ClassName}
|
|
2805
3498
|
|
|
2806
3499
|
beforeEach(() => {
|
|
2807
|
-
${naming.variableName} = ${ConfigFile.
|
|
3500
|
+
${naming.variableName} = ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? `wire${naming.ClassName}()` : `new ${implementationNaming.ClassName}${naming.ClassName}()`}
|
|
2808
3501
|
})
|
|
2809
3502
|
|
|
2810
3503
|
describe('${naming.withSpaces}', () => {
|
|
2811
|
-
test('can be ${ConfigFile.
|
|
3504
|
+
test('can be ${ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
|
|
2812
3505
|
expect(${naming.variableName}).toBeDefined()
|
|
2813
3506
|
})
|
|
2814
3507
|
})
|
|
2815
3508
|
`.trim());
|
|
2816
3509
|
}
|
|
2817
|
-
if (ConfigFile.
|
|
3510
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2818
3511
|
const wireFile = wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
|
|
2819
3512
|
import { wireClass } from '@domain-first/wire'
|
|
2820
3513
|
import { envBranchedWire } from '../../../${'shared-kernel' === boundedContextFolder.name ? '' : '../'}shared-kernel/wiring/env-branched-wire'
|
|
@@ -2828,23 +3521,20 @@ ${implementationTypes.map((x)=>({
|
|
|
2828
3521
|
implementation: x
|
|
2829
3522
|
})).map(({ naming: { ClassName }, implementation })=>`const wire${new UnknownFormatNaming(implementation).ClassName}Implementation = wireClass(${ClassName}, [])`).join('\n\n')}
|
|
2830
3523
|
|
|
2831
|
-
export const wire${naming.ClassName} = envBranchedWire({
|
|
2832
|
-
test: wire${new UnknownFormatNaming(`${implementationTypes.at(-1)}-implementation`).ClassName},
|
|
2833
|
-
development: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName},
|
|
2834
|
-
production: wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName}
|
|
2835
|
-
})
|
|
3524
|
+
export const wire${naming.ClassName} = envBranchedWire(${envBranchedWireArgument(`wire${new UnknownFormatNaming(`${implementationTypes.at(-1)}-implementation`).ClassName}`, `wire${new UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName}`)})
|
|
2836
3525
|
|
|
2837
3526
|
`.trim());
|
|
2838
3527
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
2839
3528
|
}
|
|
2840
3529
|
};
|
|
2841
3530
|
const scaffoldNewApplicationService = async (boundedContextFolder)=>{
|
|
2842
|
-
const name = await
|
|
3531
|
+
const name = await interaction_input({
|
|
3532
|
+
key: 'name',
|
|
2843
3533
|
message: 'Name: '
|
|
2844
3534
|
});
|
|
2845
3535
|
const naming = new UnknownFormatNaming(name);
|
|
2846
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
2847
|
-
const withWiring = ConfigFile.
|
|
3536
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3537
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
2848
3538
|
const wiringFolder = boundedContextFolder.subitem([
|
|
2849
3539
|
'wiring',
|
|
2850
3540
|
'application-services'
|
|
@@ -2859,7 +3549,7 @@ export class ${naming.ClassName}ApplicationService {
|
|
|
2859
3549
|
}
|
|
2860
3550
|
`.trim());
|
|
2861
3551
|
if (scaffoldUnitTests) applicationServicesFolder.createFile(`${naming.fileName}-application-service.spec.ts`, `
|
|
2862
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3552
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
2863
3553
|
${withWiring ? `import { type ${naming.ClassName}ApplicationService } from './${naming.fileName}-application-service'
|
|
2864
3554
|
import { wire${naming.ClassName}ApplicationService } from '../../wiring/application-services/wire-${naming.fileName}-application-service'` : `import { ${naming.ClassName}ApplicationService } from './${naming.fileName}-application-service'`}
|
|
2865
3555
|
|
|
@@ -2889,14 +3579,15 @@ export const wire${naming.ClassName}ApplicationService = wireClass(
|
|
|
2889
3579
|
}
|
|
2890
3580
|
};
|
|
2891
3581
|
const scaffoldNewBoundedContextUseCase = async ()=>{
|
|
2892
|
-
const name = await
|
|
3582
|
+
const name = await interaction_input({
|
|
3583
|
+
key: 'name',
|
|
2893
3584
|
message: 'Name:',
|
|
2894
3585
|
validate: (x)=>!!x.length
|
|
2895
3586
|
});
|
|
2896
3587
|
const { path } = new ProjectRoot();
|
|
2897
3588
|
const rootFolder = new Folder(path);
|
|
2898
3589
|
const folder = rootFolder.subitem([
|
|
2899
|
-
ConfigFile.Instance.data.rootFolder,
|
|
3590
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
2900
3591
|
'bounded-contexts',
|
|
2901
3592
|
name
|
|
2902
3593
|
]);
|
|
@@ -2907,66 +3598,37 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
2907
3598
|
'application',
|
|
2908
3599
|
'commands'
|
|
2909
3600
|
]);
|
|
2910
|
-
const
|
|
2911
|
-
'
|
|
2912
|
-
'commands'
|
|
2913
|
-
]);
|
|
2914
|
-
const commandName = await input({
|
|
3601
|
+
const commandName = await interaction_input({
|
|
3602
|
+
key: 'name',
|
|
2915
3603
|
message: 'Name: '
|
|
2916
3604
|
});
|
|
2917
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3605
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
2918
3606
|
const naming = new UnknownFormatNaming(commandName);
|
|
2919
|
-
const withWiring = ConfigFile.
|
|
2920
|
-
const implementationType = await
|
|
2921
|
-
message: 'Command infrastructure implementation type:',
|
|
2922
|
-
default: ConfigFile.Instance.data.defaultPersistenceLayerImplementation
|
|
2923
|
-
});
|
|
3607
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3608
|
+
const { label: implementationType } = await promptImplementationType('Command infrastructure implementation type:', 'commands');
|
|
2924
3609
|
let addTestImplementation = false;
|
|
2925
3610
|
let testImplementationType = '';
|
|
2926
|
-
addTestImplementation = await
|
|
3611
|
+
addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
3612
|
+
key: 'withTestImplementation',
|
|
2927
3613
|
message: 'Add a test implementation for Command'
|
|
2928
3614
|
});
|
|
2929
|
-
if (addTestImplementation) testImplementationType = await
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
3615
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test Command infrastructure implementation type:', 'commands', {
|
|
3616
|
+
existing: [
|
|
3617
|
+
implementationType
|
|
3618
|
+
],
|
|
3619
|
+
purpose: 'test'
|
|
3620
|
+
})).label;
|
|
2933
3621
|
const implementationTypes = [
|
|
2934
3622
|
implementationType,
|
|
2935
3623
|
testImplementationType
|
|
2936
3624
|
].filter((x)=>!!x);
|
|
2937
|
-
for (const implementation of implementationTypes){
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
]
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${naming.ClassName}Command {
|
|
2946
|
-
constructor() {
|
|
2947
|
-
super()
|
|
2948
|
-
}
|
|
2949
|
-
|
|
2950
|
-
handle = defineHandler({
|
|
2951
|
-
inputSchema: ${naming.ClassName}Command.inputSchema,
|
|
2952
|
-
outputSchema: ${naming.ClassName}Command.outputSchema,
|
|
2953
|
-
handler: async (input) => {
|
|
2954
|
-
return {}
|
|
2955
|
-
}
|
|
2956
|
-
})
|
|
2957
|
-
}
|
|
2958
|
-
`.trim() : `
|
|
2959
|
-
import { ${naming.ClassName}Command } from '../../../application/commands/${naming.fileName}-command'
|
|
2960
|
-
|
|
2961
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${naming.ClassName}Command {
|
|
2962
|
-
constructor() {
|
|
2963
|
-
super()
|
|
2964
|
-
}
|
|
2965
|
-
}
|
|
2966
|
-
`.trim());
|
|
2967
|
-
if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Command`);
|
|
2968
|
-
}
|
|
2969
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.createFile(`${naming.fileName}-command.ts`, `
|
|
3625
|
+
for (const implementation of implementationTypes)createImplementation(boundedContextFolder, {
|
|
3626
|
+
kind: 'command',
|
|
3627
|
+
name: naming.fileName,
|
|
3628
|
+
ownerPath: boundedContextFolder.path,
|
|
3629
|
+
labels: []
|
|
3630
|
+
}, new UnknownFormatNaming(implementation).fileName);
|
|
3631
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.createFile(`${naming.fileName}-command.ts`, `
|
|
2970
3632
|
import type { Handler } from '@domain-first/handlers'
|
|
2971
3633
|
|
|
2972
3634
|
export abstract class ${naming.ClassName}Command {
|
|
@@ -2983,7 +3645,7 @@ export abstract class ${naming.ClassName}Command {
|
|
|
2983
3645
|
if (scaffoldUnitTests) {
|
|
2984
3646
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
2985
3647
|
const specFile = commandsFolder.createFile(`${naming.fileName}-command.spec.ts`, `
|
|
2986
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3648
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
2987
3649
|
${withWiring ? `import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
|
|
2988
3650
|
import { wire${naming.ClassName}Command } from '../../wiring/commands/wire-${naming.fileName}-command'` : `import { ${implementationNaming.ClassName}${naming.ClassName}Command } from '../../infrastructure/commands/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}-command'
|
|
2989
3651
|
|
|
@@ -3003,7 +3665,7 @@ describe('${naming.withSpaces} command', () => {
|
|
|
3003
3665
|
`.trim());
|
|
3004
3666
|
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
|
|
3005
3667
|
}
|
|
3006
|
-
if (ConfigFile.
|
|
3668
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3007
3669
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3008
3670
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
3009
3671
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -3016,18 +3678,15 @@ ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fil
|
|
|
3016
3678
|
|
|
3017
3679
|
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Command, [])`).join('\n\n')}
|
|
3018
3680
|
|
|
3019
|
-
export const wire${naming.ClassName}Command = envBranchedWire({
|
|
3020
|
-
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
3021
|
-
development: wire${implementationNaming.ClassName}Implementation,
|
|
3022
|
-
production: wire${implementationNaming.ClassName}Implementation
|
|
3023
|
-
})
|
|
3681
|
+
export const wire${naming.ClassName}Command = envBranchedWire(${envBranchedWireArgument(`wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation`, `wire${implementationNaming.ClassName}Implementation`)})
|
|
3024
3682
|
`.trim());
|
|
3025
3683
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
3026
3684
|
}
|
|
3027
3685
|
};
|
|
3028
3686
|
const scaffold_new_domain_object_noAggregate = 'No aggregate';
|
|
3029
3687
|
const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
3030
|
-
const name = await
|
|
3688
|
+
const name = await interaction_input({
|
|
3689
|
+
key: 'name',
|
|
3031
3690
|
message: 'Name: '
|
|
3032
3691
|
});
|
|
3033
3692
|
const naming = new UnknownFormatNaming(name);
|
|
@@ -3036,7 +3695,8 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
|
3036
3695
|
'aggregates'
|
|
3037
3696
|
]);
|
|
3038
3697
|
const aggregateNames = aggregatesFolder.content.subfolderNames;
|
|
3039
|
-
const aggregate = aggregateNames.length ? await
|
|
3698
|
+
const aggregate = aggregateNames.length ? await interaction_select({
|
|
3699
|
+
key: 'aggregate',
|
|
3040
3700
|
message: 'Aggregate:',
|
|
3041
3701
|
choices: [
|
|
3042
3702
|
...aggregateNames,
|
|
@@ -3052,7 +3712,7 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
|
3052
3712
|
kindFolderName
|
|
3053
3713
|
]);
|
|
3054
3714
|
const fileName = `${naming.fileName}.${kind}`;
|
|
3055
|
-
const withTypes = ConfigFile.
|
|
3715
|
+
const withTypes = ConfigFile.backend.domainFirstPackages.includes('@domain-first/types');
|
|
3056
3716
|
folder.createFile(`${fileName}.ts`, withTypes ? `
|
|
3057
3717
|
import { domainType } from '@domain-first/types'
|
|
3058
3718
|
|
|
@@ -3062,7 +3722,7 @@ export class ${naming.ClassName} extends domainType() {
|
|
|
3062
3722
|
if (aggregate !== scaffold_new_domain_object_noAggregate) aggregatesFolder.subitem([
|
|
3063
3723
|
aggregate
|
|
3064
3724
|
]).file('index.ts').addLineIfMissing(`export * from './${kindFolderName}/${fileName}'`);
|
|
3065
|
-
const { testingLibrary } = ConfigFile.
|
|
3725
|
+
const { testingLibrary } = ConfigFile.backend;
|
|
3066
3726
|
if (testingLibrary) folder.createFile(`${fileName}.spec.ts`, `
|
|
3067
3727
|
import { describe, test, expect, beforeEach } from '${testingLibrary}'
|
|
3068
3728
|
import { ${naming.ClassName} } from './${fileName}'
|
|
@@ -3081,12 +3741,13 @@ describe('${naming.withSpaces}', () => {
|
|
|
3081
3741
|
`.trim());
|
|
3082
3742
|
};
|
|
3083
3743
|
const scaffoldNewDomainService = async (boundedContextFolder)=>{
|
|
3084
|
-
const portName = await
|
|
3744
|
+
const portName = await interaction_input({
|
|
3745
|
+
key: 'name',
|
|
3085
3746
|
message: 'Name:'
|
|
3086
3747
|
});
|
|
3087
3748
|
const naming = new UnknownFormatNaming(portName);
|
|
3088
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3089
|
-
const withWiring = ConfigFile.
|
|
3749
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3750
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3090
3751
|
const domainServicesFolder = boundedContextFolder.subitem([
|
|
3091
3752
|
'domain',
|
|
3092
3753
|
'services'
|
|
@@ -3097,7 +3758,7 @@ export class ${naming.ClassName}DomainService {
|
|
|
3097
3758
|
}
|
|
3098
3759
|
`.trim());
|
|
3099
3760
|
if (scaffoldUnitTests) domainServicesFolder.createFile(`${naming.fileName}-domain-service.spec.ts`, `
|
|
3100
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
3761
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3101
3762
|
${withWiring ? `import { type ${naming.ClassName}DomainService } from './${naming.fileName}-domain-service'
|
|
3102
3763
|
import { wire${naming.ClassName}DomainService } from '../../wiring/domain-services/wire-${naming.fileName}-domain-service'` : `import { ${naming.ClassName}DomainService } from './${naming.fileName}-domain-service'`}
|
|
3103
3764
|
|
|
@@ -3131,7 +3792,7 @@ export const wire${naming.ClassName}DomainService = wireClass(
|
|
|
3131
3792
|
};
|
|
3132
3793
|
const errorNames = (boundedContextFolder)=>{
|
|
3133
3794
|
const isShared = boundedContextFolder.path === new Folder(new ProjectRoot().path).subitem([
|
|
3134
|
-
ConfigFile.Instance.data.rootFolder,
|
|
3795
|
+
ConfigFile.Instance.data.project.rootFolder,
|
|
3135
3796
|
'shared-kernel'
|
|
3136
3797
|
]).path;
|
|
3137
3798
|
return {
|
|
@@ -3166,12 +3827,14 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
3166
3827
|
...currentErrorNamespaces.map((x)=>`New error in namespace ${x}`),
|
|
3167
3828
|
'New namespace'
|
|
3168
3829
|
];
|
|
3169
|
-
const selectedVariant = await
|
|
3830
|
+
const selectedVariant = await interaction_select({
|
|
3170
3831
|
choices: variants,
|
|
3832
|
+
key: 'errorAction',
|
|
3171
3833
|
message: 'Action:'
|
|
3172
3834
|
});
|
|
3173
3835
|
if ('New error without namespace' === selectedVariant) {
|
|
3174
|
-
const errorName = await
|
|
3836
|
+
const errorName = await interaction_input({
|
|
3837
|
+
key: 'name',
|
|
3175
3838
|
message: 'Error name:'
|
|
3176
3839
|
});
|
|
3177
3840
|
const naming = new UnknownFormatNaming(errorName);
|
|
@@ -3180,7 +3843,8 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
3180
3843
|
return;
|
|
3181
3844
|
}
|
|
3182
3845
|
if ('New namespace' === selectedVariant) {
|
|
3183
|
-
const namespaceName = await
|
|
3846
|
+
const namespaceName = await interaction_input({
|
|
3847
|
+
key: 'name',
|
|
3184
3848
|
message: 'Namespace name:'
|
|
3185
3849
|
});
|
|
3186
3850
|
const { ClassName, fileName } = new UnknownFormatNaming(namespaceName);
|
|
@@ -3194,7 +3858,8 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
|
|
|
3194
3858
|
}
|
|
3195
3859
|
const namespace = selectedVariant.substring(23);
|
|
3196
3860
|
const namespaceNaming = new UnknownFormatNaming(namespace);
|
|
3197
|
-
const errorName = await
|
|
3861
|
+
const errorName = await interaction_input({
|
|
3862
|
+
key: 'name',
|
|
3198
3863
|
message: 'Error name:'
|
|
3199
3864
|
});
|
|
3200
3865
|
const { ClassName, fileName } = new UnknownFormatNaming(errorName);
|
|
@@ -3207,7 +3872,8 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
3207
3872
|
'rest'
|
|
3208
3873
|
]);
|
|
3209
3874
|
const controllers = restPresentationFolder.content.subfolderNames;
|
|
3210
|
-
let controller = await
|
|
3875
|
+
let controller = await interaction_select({
|
|
3876
|
+
key: 'controllerSelection',
|
|
3211
3877
|
message: 'Controller: ',
|
|
3212
3878
|
choices: [
|
|
3213
3879
|
...controllers,
|
|
@@ -3215,10 +3881,11 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
3215
3881
|
]
|
|
3216
3882
|
});
|
|
3217
3883
|
if ('New controller' === controller) {
|
|
3218
|
-
controller = await
|
|
3884
|
+
controller = await interaction_input({
|
|
3885
|
+
key: 'controllerName',
|
|
3219
3886
|
message: 'Name: '
|
|
3220
3887
|
});
|
|
3221
|
-
if (ConfigFile.
|
|
3888
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3222
3889
|
boundedContextFolder.subitem([
|
|
3223
3890
|
'wiring',
|
|
3224
3891
|
'presentation',
|
|
@@ -3240,7 +3907,8 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
3240
3907
|
`.trim());
|
|
3241
3908
|
}
|
|
3242
3909
|
}
|
|
3243
|
-
const method = await
|
|
3910
|
+
const method = await interaction_select({
|
|
3911
|
+
key: 'method',
|
|
3244
3912
|
message: 'Method:',
|
|
3245
3913
|
choices: [
|
|
3246
3914
|
'get',
|
|
@@ -3250,7 +3918,8 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
3250
3918
|
'put'
|
|
3251
3919
|
]
|
|
3252
3920
|
});
|
|
3253
|
-
const routeSegments = (await
|
|
3921
|
+
const routeSegments = (await interaction_input({
|
|
3922
|
+
key: 'path',
|
|
3254
3923
|
message: 'Relative path (split by "/"):'
|
|
3255
3924
|
})).split('/').filter((x)=>!!x);
|
|
3256
3925
|
const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
|
|
@@ -3265,7 +3934,7 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
3265
3934
|
method,
|
|
3266
3935
|
'endpoint'
|
|
3267
3936
|
].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
|
|
3268
|
-
const withWiring = ConfigFile.
|
|
3937
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3269
3938
|
const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
|
|
3270
3939
|
'..',
|
|
3271
3940
|
'..',
|
|
@@ -3315,16 +3984,111 @@ export const wire${endpointClassName} = wireClass(
|
|
|
3315
3984
|
[${dependencies.map((x)=>x.wireName).join(', ')}]
|
|
3316
3985
|
)
|
|
3317
3986
|
`.trim());
|
|
3318
|
-
wiringFolder.file('index.ts').
|
|
3987
|
+
wiringFolder.file('index.ts').addLineIfMissing(`export * from './${wireNaming.fileName}'`);
|
|
3319
3988
|
}
|
|
3320
3989
|
};
|
|
3990
|
+
const scaffold_new_implementation_kindTitles = {
|
|
3991
|
+
aggregate: 'Repositories',
|
|
3992
|
+
command: 'Commands',
|
|
3993
|
+
query: 'Queries',
|
|
3994
|
+
port: 'Ports'
|
|
3995
|
+
};
|
|
3996
|
+
const branchesOf = (wireFile, wireName)=>{
|
|
3997
|
+
if (!wireFile.exists) return;
|
|
3998
|
+
try {
|
|
3999
|
+
return wireBranches(wireFile.data, wireName);
|
|
4000
|
+
} catch {
|
|
4001
|
+
return;
|
|
4002
|
+
}
|
|
4003
|
+
};
|
|
4004
|
+
const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
4005
|
+
const contracts = findContracts(ownerFolder.path);
|
|
4006
|
+
if (!contracts.length) return void report('No repositories, commands, queries or ports here yet.');
|
|
4007
|
+
const unit = await interaction_select({
|
|
4008
|
+
key: 'contract',
|
|
4009
|
+
id: unitId,
|
|
4010
|
+
message: 'Contract:',
|
|
4011
|
+
choices: contractKinds.flatMap((kind)=>{
|
|
4012
|
+
const group = contracts.filter((x)=>x.kind === kind);
|
|
4013
|
+
return group.length ? [
|
|
4014
|
+
new Separator(`── ${scaffold_new_implementation_kindTitles[kind]}`),
|
|
4015
|
+
...group.map((value)=>({
|
|
4016
|
+
name: value.labels.length ? `${value.name} (${value.labels.join(', ')})` : value.name,
|
|
4017
|
+
value
|
|
4018
|
+
}))
|
|
4019
|
+
] : [];
|
|
4020
|
+
}),
|
|
4021
|
+
pageSize: 20
|
|
4022
|
+
});
|
|
4023
|
+
const kind = 'aggregate' === unit.kind ? 'repositories' : 'command' === unit.kind ? 'commands' : 'query' === unit.kind ? 'queries' : 'ports';
|
|
4024
|
+
const { label, saveForFutureUse } = await promptImplementationType('Implementation type:', kind, {
|
|
4025
|
+
existing: unit.labels,
|
|
4026
|
+
purpose: 'all',
|
|
4027
|
+
remember: false,
|
|
4028
|
+
crossContext: 'port' === unit.kind && hasNeighboringBoundedContext(ownerFolder.path)
|
|
4029
|
+
});
|
|
4030
|
+
const { file, className } = createImplementation(ownerFolder, unit, label);
|
|
4031
|
+
const branches = wire_branches_envBranches();
|
|
4032
|
+
const rememberFor = (environments)=>{
|
|
4033
|
+
if (!saveForFutureUse) return;
|
|
4034
|
+
if (systemImplementationChoices(kind, 'port' === unit.kind && hasNeighboringBoundedContext(ownerFolder.path)).some((choice)=>choice.value === label)) return;
|
|
4035
|
+
if (branches.test && environments.includes(branches.test)) rememberImplementation(kind, 'test', label);
|
|
4036
|
+
if (environments.some((environment)=>environment !== branches.test)) rememberImplementation(kind, 'primary', label);
|
|
4037
|
+
};
|
|
4038
|
+
if (!ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) return void rememberFor(branches.primary);
|
|
4039
|
+
const wireFile = new File(ownerFolder.path).subitem(contractWireFile(unit).split('/'));
|
|
4040
|
+
const wireName = `wire${contractClassName(unit)}`;
|
|
4041
|
+
const wired = branchesOf(wireFile, wireName);
|
|
4042
|
+
if (!wired) {
|
|
4043
|
+
rememberFor(branches.primary);
|
|
4044
|
+
report(`${wireFile.path} has no ${wireName} = envBranchedWire({...}): wire ${className} there yourself.`);
|
|
4045
|
+
return;
|
|
4046
|
+
}
|
|
4047
|
+
const labelOfWire = new Map(unit.labels.map((x)=>[
|
|
4048
|
+
implementationWireName(x),
|
|
4049
|
+
x
|
|
4050
|
+
]));
|
|
4051
|
+
const chosenEnvironments = await interaction_checkbox({
|
|
4052
|
+
key: 'environments',
|
|
4053
|
+
message: 'Environments:',
|
|
4054
|
+
choices: [
|
|
4055
|
+
...new Set([
|
|
4056
|
+
...branches.test ? [
|
|
4057
|
+
branches.test
|
|
4058
|
+
] : [],
|
|
4059
|
+
...branches.primary,
|
|
4060
|
+
...wired.keys()
|
|
4061
|
+
])
|
|
4062
|
+
].map((environment)=>{
|
|
4063
|
+
const current = wired.get(environment);
|
|
4064
|
+
return {
|
|
4065
|
+
name: current ? `${environment} (now: ${labelOfWire.get(current) ?? current})` : environment,
|
|
4066
|
+
value: environment
|
|
4067
|
+
};
|
|
4068
|
+
}),
|
|
4069
|
+
required: true
|
|
4070
|
+
});
|
|
4071
|
+
rememberFor(chosenEnvironments);
|
|
4072
|
+
const before = readWiredModule(wireFile.path, ownerFolder.path);
|
|
4073
|
+
wireFile.update(addBranchedImplementation(wireFile.data, wireName, {
|
|
4074
|
+
importLine: `import { ${className} } from '${relativeImport(wireFile.path, file.path)}'`,
|
|
4075
|
+
className,
|
|
4076
|
+
wireName: implementationWireName(label),
|
|
4077
|
+
environments: chosenEnvironments
|
|
4078
|
+
}));
|
|
4079
|
+
const after = readWiredModule(wireFile.path, ownerFolder.path);
|
|
4080
|
+
const unused = (before?.implementations ?? []).filter((x)=>!after?.implementations.some((y)=>y.className === x.className));
|
|
4081
|
+
for (const implementation of unused)report(`${implementation.className} is no longer used in any environment.`);
|
|
4082
|
+
await wireNewImplementationDependencies(ownerFolder, wireFile, className, inMemoryRepositoryWiring(ownerFolder, unit, wireFile));
|
|
4083
|
+
};
|
|
3321
4084
|
const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
|
|
3322
|
-
const name = await
|
|
4085
|
+
const name = await interaction_input({
|
|
4086
|
+
key: 'name',
|
|
3323
4087
|
message: 'Name: '
|
|
3324
4088
|
});
|
|
3325
4089
|
const naming = new UnknownFormatNaming(name);
|
|
3326
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3327
|
-
const withWiring = ConfigFile.
|
|
4090
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
4091
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3328
4092
|
const wiringFolder = boundedContextFolder.subitem([
|
|
3329
4093
|
'wiring',
|
|
3330
4094
|
'infrastructure-services'
|
|
@@ -3339,7 +4103,7 @@ export class ${naming.ClassName}InfrastructureService {
|
|
|
3339
4103
|
}
|
|
3340
4104
|
`.trim());
|
|
3341
4105
|
if (scaffoldUnitTests) infrastructureServicesFolder.createFile(`${naming.fileName}-infrastructure-service.spec.ts`, `
|
|
3342
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
4106
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3343
4107
|
${withWiring ? `import { type ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'
|
|
3344
4108
|
import { wire${naming.ClassName}InfrastructureService } from '../../wiring/infrastructure-services/wire-${naming.fileName}-infrastructure-service'` : `import { ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'`}
|
|
3345
4109
|
|
|
@@ -3373,66 +4137,37 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
3373
4137
|
'application',
|
|
3374
4138
|
'queries'
|
|
3375
4139
|
]);
|
|
3376
|
-
const
|
|
3377
|
-
'
|
|
3378
|
-
'queries'
|
|
3379
|
-
]);
|
|
3380
|
-
const queryName = await input({
|
|
4140
|
+
const queryName = await interaction_input({
|
|
4141
|
+
key: 'name',
|
|
3381
4142
|
message: 'Name: '
|
|
3382
4143
|
});
|
|
3383
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
4144
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
3384
4145
|
const naming = new UnknownFormatNaming(queryName);
|
|
3385
|
-
const withWiring = ConfigFile.
|
|
3386
|
-
const implementationType = await
|
|
3387
|
-
message: 'Query infrastructure implementation type:',
|
|
3388
|
-
default: ConfigFile.Instance.data.defaultPersistenceLayerImplementation
|
|
3389
|
-
});
|
|
4146
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
4147
|
+
const { label: implementationType } = await promptImplementationType('Query infrastructure implementation type:', 'queries');
|
|
3390
4148
|
let addTestImplementation = false;
|
|
3391
4149
|
let testImplementationType = '';
|
|
3392
|
-
addTestImplementation = await
|
|
4150
|
+
addTestImplementation = offersTestImplementation() && await interaction_confirm({
|
|
4151
|
+
key: 'withTestImplementation',
|
|
3393
4152
|
message: 'Add a test implementation for Query'
|
|
3394
4153
|
});
|
|
3395
|
-
if (addTestImplementation) testImplementationType = await
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
4154
|
+
if (addTestImplementation) testImplementationType = (await promptImplementationType('Test Query infrastructure implementation type:', 'queries', {
|
|
4155
|
+
existing: [
|
|
4156
|
+
implementationType
|
|
4157
|
+
],
|
|
4158
|
+
purpose: 'test'
|
|
4159
|
+
})).label;
|
|
3399
4160
|
const implementationTypes = [
|
|
3400
4161
|
implementationType,
|
|
3401
4162
|
testImplementationType
|
|
3402
4163
|
].filter((x)=>!!x);
|
|
3403
|
-
for (const implementation of implementationTypes){
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
]
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.ClassName}Query {
|
|
3412
|
-
constructor() {
|
|
3413
|
-
super()
|
|
3414
|
-
}
|
|
3415
|
-
|
|
3416
|
-
handle = defineHandler({
|
|
3417
|
-
inputSchema: ${naming.ClassName}Query.inputSchema,
|
|
3418
|
-
outputSchema: ${naming.ClassName}Query.outputSchema,
|
|
3419
|
-
handler: async (input) => {
|
|
3420
|
-
return {}
|
|
3421
|
-
}
|
|
3422
|
-
})
|
|
3423
|
-
}
|
|
3424
|
-
`.trim() : `
|
|
3425
|
-
import { ${naming.ClassName}Query } from '../../../application/queries/${naming.fileName}-query'
|
|
3426
|
-
|
|
3427
|
-
export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.ClassName}Query {
|
|
3428
|
-
constructor() {
|
|
3429
|
-
super()
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
`.trim());
|
|
3433
|
-
if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Query`);
|
|
3434
|
-
}
|
|
3435
|
-
if (ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.createFile(`${naming.fileName}-query.ts`, `
|
|
4164
|
+
for (const implementation of implementationTypes)createImplementation(boundedContextFolder, {
|
|
4165
|
+
kind: 'query',
|
|
4166
|
+
name: naming.fileName,
|
|
4167
|
+
ownerPath: boundedContextFolder.path,
|
|
4168
|
+
labels: []
|
|
4169
|
+
}, new UnknownFormatNaming(implementation).fileName);
|
|
4170
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.createFile(`${naming.fileName}-query.ts`, `
|
|
3436
4171
|
import type { Handler } from '@domain-first/handlers'
|
|
3437
4172
|
|
|
3438
4173
|
export abstract class ${naming.ClassName}Query {
|
|
@@ -3449,7 +4184,7 @@ export abstract class ${naming.ClassName}Query {
|
|
|
3449
4184
|
if (scaffoldUnitTests) {
|
|
3450
4185
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3451
4186
|
const specFile = queriesFolder.createFile(`${naming.fileName}-query.spec.ts`, `
|
|
3452
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
4187
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3453
4188
|
${withWiring ? `import { type ${naming.ClassName}Query } from './${naming.fileName}-query'
|
|
3454
4189
|
import { wire${naming.ClassName}Query } from '../../wiring/queries/wire-${naming.fileName}-query'` : `import { ${implementationNaming.ClassName}${naming.ClassName}Query } from '../../infrastructure/queries/${implementationNaming.fileName}/${implementationNaming.fileName}-${naming.fileName}-query'
|
|
3455
4190
|
|
|
@@ -3469,7 +4204,7 @@ describe('${naming.withSpaces} query', () => {
|
|
|
3469
4204
|
`.trim());
|
|
3470
4205
|
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
|
|
3471
4206
|
}
|
|
3472
|
-
if (ConfigFile.
|
|
4207
|
+
if (ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3473
4208
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3474
4209
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
3475
4210
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -3482,11 +4217,7 @@ ${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName, fil
|
|
|
3482
4217
|
|
|
3483
4218
|
${implementationTypes.map((x)=>new UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Query, [])`).join('\n\n')}
|
|
3484
4219
|
|
|
3485
|
-
export const wire${naming.ClassName}Query = envBranchedWire({
|
|
3486
|
-
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
3487
|
-
development: wire${implementationNaming.ClassName}Implementation,
|
|
3488
|
-
production: wire${implementationNaming.ClassName}Implementation
|
|
3489
|
-
})
|
|
4220
|
+
export const wire${naming.ClassName}Query = envBranchedWire(${envBranchedWireArgument(`wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation`, `wire${implementationNaming.ClassName}Implementation`)})
|
|
3490
4221
|
`.trim());
|
|
3491
4222
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
3492
4223
|
}
|
|
@@ -3496,13 +4227,14 @@ const scaffoldNewUseCase = async (boundedContextFolder)=>{
|
|
|
3496
4227
|
'application',
|
|
3497
4228
|
'use-cases'
|
|
3498
4229
|
]);
|
|
3499
|
-
const useCaseName = await
|
|
4230
|
+
const useCaseName = await interaction_input({
|
|
4231
|
+
key: 'name',
|
|
3500
4232
|
message: 'Name: '
|
|
3501
4233
|
});
|
|
3502
4234
|
const naming = new UnknownFormatNaming(useCaseName);
|
|
3503
|
-
const scaffoldUnitTests = Boolean(ConfigFile.
|
|
3504
|
-
const withWiring = ConfigFile.
|
|
3505
|
-
useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, ConfigFile.
|
|
4235
|
+
const scaffoldUnitTests = Boolean(ConfigFile.backend.testingLibrary);
|
|
4236
|
+
const withWiring = ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
4237
|
+
useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
3506
4238
|
import { defineHandler } from '@domain-first/handlers'
|
|
3507
4239
|
|
|
3508
4240
|
export class ${naming.ClassName}UseCase {
|
|
@@ -3525,7 +4257,7 @@ export class ${naming.ClassName}UseCase {
|
|
|
3525
4257
|
}
|
|
3526
4258
|
`.trim());
|
|
3527
4259
|
if (scaffoldUnitTests) useCasesFolder.createFile(`${naming.fileName}-use-case.spec.ts`, `
|
|
3528
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.
|
|
4260
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.backend.testingLibrary}'
|
|
3529
4261
|
${withWiring ? `import { type ${naming.ClassName}UseCase } from './${naming.fileName}-use-case'
|
|
3530
4262
|
import { wire${naming.ClassName}UseCase } from '../../wiring/use-cases/wire-${naming.fileName}-use-case'` : `import { ${naming.ClassName}UseCase } from './${naming.fileName}-use-case'`}
|
|
3531
4263
|
|
|
@@ -3559,7 +4291,8 @@ export const wire${naming.ClassName}UseCase = wireClass(
|
|
|
3559
4291
|
}
|
|
3560
4292
|
};
|
|
3561
4293
|
const scaffoldReactSharedHook = async (presentationReactFolder)=>{
|
|
3562
|
-
const name = await
|
|
4294
|
+
const name = await interaction_input({
|
|
4295
|
+
key: 'name',
|
|
3563
4296
|
message: 'Name without "use" (e.g. debounce): '
|
|
3564
4297
|
});
|
|
3565
4298
|
const { ClassName, fileName } = new UnknownFormatNaming(name.trim().replace(/^use-/, ''));
|
|
@@ -3572,7 +4305,8 @@ export const use${ClassName} = () => {
|
|
|
3572
4305
|
`.trim());
|
|
3573
4306
|
};
|
|
3574
4307
|
const scaffoldReactUIKitComponent = async (presentationReactFolder)=>{
|
|
3575
|
-
const name = await
|
|
4308
|
+
const name = await interaction_input({
|
|
4309
|
+
key: 'name',
|
|
3576
4310
|
message: 'Name: '
|
|
3577
4311
|
});
|
|
3578
4312
|
const { ClassName, fileName } = new UnknownFormatNaming(name);
|
|
@@ -3590,7 +4324,7 @@ export const ${ClassName}: FC<${ClassName}Props> = (props) => {
|
|
|
3590
4324
|
return <></>
|
|
3591
4325
|
}
|
|
3592
4326
|
`.trim());
|
|
3593
|
-
const { storybookFramework } = ConfigFile.Instance.data;
|
|
4327
|
+
const { storybookFramework } = ConfigFile.Instance.data.frontend?.react ?? {};
|
|
3594
4328
|
if (storybookFramework) componentFolder.createFile(`${fileName}.stories.tsx`, `
|
|
3595
4329
|
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
3596
4330
|
import { ${ClassName} } from './${fileName}'
|
|
@@ -3610,16 +4344,18 @@ export const Default: Story = {
|
|
|
3610
4344
|
`.trim());
|
|
3611
4345
|
};
|
|
3612
4346
|
const scaffoldReactWidget = async (presentationReactFolder)=>{
|
|
3613
|
-
const widgetName = await
|
|
4347
|
+
const widgetName = await interaction_input({
|
|
4348
|
+
key: 'name',
|
|
3614
4349
|
message: 'Name (folders split by "/"): ',
|
|
3615
4350
|
validate: NestedName.validate
|
|
3616
4351
|
});
|
|
3617
|
-
const widgetType = await
|
|
4352
|
+
const widgetType = await interaction_select({
|
|
3618
4353
|
choices: [
|
|
3619
4354
|
'monolithic',
|
|
3620
4355
|
'with separated ui',
|
|
3621
4356
|
'headless'
|
|
3622
4357
|
],
|
|
4358
|
+
key: 'widgetType',
|
|
3623
4359
|
message: 'Type: '
|
|
3624
4360
|
});
|
|
3625
4361
|
const { folders, folderName, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
|
|
@@ -3678,7 +4414,7 @@ export const ${ClassName}WidgetUI: FC<${ClassName}WidgetUIProps> = (props) => {
|
|
|
3678
4414
|
return <></>
|
|
3679
4415
|
}
|
|
3680
4416
|
`.trim());
|
|
3681
|
-
const { storybookFramework } = ConfigFile.Instance.data;
|
|
4417
|
+
const { storybookFramework } = ConfigFile.Instance.data.frontend?.react ?? {};
|
|
3682
4418
|
if (storybookFramework) folder.subitem([
|
|
3683
4419
|
'ui'
|
|
3684
4420
|
]).createFile(`${uiFileName}.stories.tsx`, `
|
|
@@ -3744,4 +4480,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
3744
4480
|
break;
|
|
3745
4481
|
}
|
|
3746
4482
|
};
|
|
3747
|
-
export { addIntegration, initializeUseCase, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, savePendingChanges, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, wireDependency };
|
|
4483
|
+
export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
|