@domain-first/project-structure 5.1.1 → 6.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 +6 -6
- package/dist/287.js +3217 -0
- package/dist/index.cjs +148 -1293
- package/dist/index.js +4 -3124
- package/dist/integration.cjs +1684 -0
- package/dist/integration.d.ts +2 -0
- package/dist/integration.js +31 -0
- package/dist/integrations/orval.d.ts +7 -4
- package/dist/print-next-steps.d.ts +7 -0
- package/dist/use-cases/add-integration-order.spec.d.ts +1 -0
- package/package.json +3 -2
- package/skills/df-ps-implement/SKILL.md +4 -4
- package/skills/df-ps-plan-feature/SKILL.md +1 -1
- package/skills/df-ps-scaffold/SKILL.md +16 -16
- package/skills/df-ps-scaffold/references/generators.md +2 -2
- package/skills/df-ps-scaffold/scripts/drive.mjs +3 -3
package/dist/index.cjs
CHANGED
|
@@ -176,7 +176,7 @@ class FileSystemItem {
|
|
|
176
176
|
return external_node_fs_default().existsSync(this.path);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
class
|
|
179
|
+
class file_system_Folder extends FileSystemItem {
|
|
180
180
|
createIfNotExisted = ()=>{
|
|
181
181
|
pendingFolders.add(this.path);
|
|
182
182
|
};
|
|
@@ -198,7 +198,7 @@ class Folder extends FileSystemItem {
|
|
|
198
198
|
}
|
|
199
199
|
createFile = (name, content)=>{
|
|
200
200
|
this.createIfNotExisted();
|
|
201
|
-
const file = new
|
|
201
|
+
const file = new file_system_File(this.path).subitem([
|
|
202
202
|
name
|
|
203
203
|
]);
|
|
204
204
|
file.data = content;
|
|
@@ -206,13 +206,13 @@ class Folder extends FileSystemItem {
|
|
|
206
206
|
};
|
|
207
207
|
file = (name)=>{
|
|
208
208
|
this.createIfNotExisted();
|
|
209
|
-
const file = new
|
|
209
|
+
const file = new file_system_File(this.path).subitem([
|
|
210
210
|
name
|
|
211
211
|
]);
|
|
212
212
|
return file;
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
|
-
class
|
|
215
|
+
class file_system_File extends FileSystemItem {
|
|
216
216
|
get exists() {
|
|
217
217
|
return pendingFiles.has(this.path) || pendingMoves.has(this.path) || external_node_fs_default().existsSync(this.path) && !pendingDeletions.has(this.path);
|
|
218
218
|
}
|
|
@@ -258,7 +258,7 @@ class File extends FileSystemItem {
|
|
|
258
258
|
if (!alreadyAdded) this.addLine(newLine, separator);
|
|
259
259
|
};
|
|
260
260
|
}
|
|
261
|
-
class
|
|
261
|
+
class project_root_ProjectRoot {
|
|
262
262
|
path;
|
|
263
263
|
constructor(){
|
|
264
264
|
let dir = process.cwd();
|
|
@@ -300,33 +300,61 @@ const configSchema = external_zod_default().object({
|
|
|
300
300
|
lint: external_zod_default().partialRecord(external_zod_default()["enum"](lintChecks), external_zod_default().boolean()).optional()
|
|
301
301
|
}).optional()
|
|
302
302
|
});
|
|
303
|
-
class
|
|
303
|
+
class config_file_ConfigFile {
|
|
304
304
|
data;
|
|
305
305
|
constructor(){
|
|
306
|
-
const filePath =
|
|
307
|
-
const file = new
|
|
306
|
+
const filePath = config_file_ConfigFile.path;
|
|
307
|
+
const file = new file_system_File(filePath);
|
|
308
308
|
const configObject = JSON.parse(file.data);
|
|
309
309
|
this.data = configSchema.parse(configObject);
|
|
310
310
|
}
|
|
311
311
|
static get Instance() {
|
|
312
|
-
return new
|
|
312
|
+
return new config_file_ConfigFile();
|
|
313
313
|
}
|
|
314
314
|
static get path() {
|
|
315
|
-
const { path: root } = new
|
|
315
|
+
const { path: root } = new project_root_ProjectRoot();
|
|
316
316
|
return external_node_path_default().resolve(root, configFileName);
|
|
317
317
|
}
|
|
318
318
|
static get exists() {
|
|
319
|
-
return new
|
|
319
|
+
return new file_system_File(config_file_ConfigFile.path).exists;
|
|
320
320
|
}
|
|
321
321
|
static write = (config)=>{
|
|
322
|
-
new
|
|
322
|
+
new file_system_File(config_file_ConfigFile.path).data = JSON.stringify(config, null, '\t');
|
|
323
323
|
};
|
|
324
324
|
}
|
|
325
|
-
const configuredDependencyRules = ()=>resolveDependencyRules(
|
|
325
|
+
const configuredDependencyRules = ()=>resolveDependencyRules(config_file_ConfigFile.exists ? config_file_ConfigFile.Instance.data.rules?.dependencies : void 0);
|
|
326
326
|
const external_node_util_namespaceObject = require("node:util");
|
|
327
|
-
const
|
|
327
|
+
const installCommand = /^\s*npm (?:i|install)((?:\s+(?:--save-dev|-D))?)\s+(.+)$/;
|
|
328
|
+
const mergeInstallCommands = (commands)=>{
|
|
329
|
+
const runtime = new Set();
|
|
330
|
+
const development = new Set();
|
|
331
|
+
const rest = [];
|
|
332
|
+
for (const command of commands){
|
|
333
|
+
const match = installCommand.exec(command);
|
|
334
|
+
if (!match) {
|
|
335
|
+
rest.push(command);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
for (const name of match[2].trim().split(/\s+/))(match[1] ? development : runtime).add(name);
|
|
339
|
+
}
|
|
340
|
+
const devOnly = [
|
|
341
|
+
...development
|
|
342
|
+
].filter((name)=>!runtime.has(name));
|
|
343
|
+
return [
|
|
344
|
+
...runtime.size ? [
|
|
345
|
+
`npm install ${[
|
|
346
|
+
...runtime
|
|
347
|
+
].join(' ')}`
|
|
348
|
+
] : [],
|
|
349
|
+
...devOnly.length ? [
|
|
350
|
+
`npm install --save-dev ${devOnly.join(' ')}`
|
|
351
|
+
] : [],
|
|
352
|
+
...rest
|
|
353
|
+
];
|
|
354
|
+
};
|
|
355
|
+
const print_next_steps_printNextSteps = (nextSteps)=>{
|
|
328
356
|
const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
|
|
329
|
-
const commands = nextSteps.filter(isCommand);
|
|
357
|
+
const commands = mergeInstallCommands(nextSteps.filter(isCommand));
|
|
330
358
|
const notes = nextSteps.filter((line)=>!isCommand(line));
|
|
331
359
|
const sections = [];
|
|
332
360
|
if (commands.length) sections.push([
|
|
@@ -345,10 +373,10 @@ const printNextSteps = (nextSteps)=>{
|
|
|
345
373
|
].join('\n'));
|
|
346
374
|
if (sections.length) console.log(sections.join('\n\n'));
|
|
347
375
|
};
|
|
348
|
-
const
|
|
376
|
+
const save_pending_changes_savePendingChanges = async ()=>{
|
|
349
377
|
const overwrittenFiles = filesToOverwrite();
|
|
350
378
|
if (overwrittenFiles.length) {
|
|
351
|
-
const root = new
|
|
379
|
+
const root = new project_root_ProjectRoot().path;
|
|
352
380
|
console.log('These files already exist and will be overwritten:');
|
|
353
381
|
for (const filePath of overwrittenFiles)console.log(` ${external_node_path_default().relative(root, filePath)}`);
|
|
354
382
|
const overwrite = await (0, prompts_namespaceObject.confirm)({
|
|
@@ -364,55 +392,8 @@ const savePendingChanges = async ()=>{
|
|
|
364
392
|
writePendingChanges();
|
|
365
393
|
return true;
|
|
366
394
|
};
|
|
367
|
-
|
|
368
|
-
const packages = ConfigFile.Instance.data.domainFirstPackages;
|
|
369
|
-
const manifest = JSON.parse(new File(external_node_path_default().join(new ProjectRoot().path, 'package.json')).data);
|
|
370
|
-
const dependencies = {
|
|
371
|
-
...manifest.dependencies,
|
|
372
|
-
...manifest.devDependencies,
|
|
373
|
-
...manifest.optionalDependencies
|
|
374
|
-
};
|
|
375
|
-
const missing = [
|
|
376
|
-
...new Set(packages)
|
|
377
|
-
].filter((name)=>!Object.hasOwn(dependencies, name));
|
|
378
|
-
return missing.length ? [
|
|
379
|
-
`npm i ${missing.join(' ')}`
|
|
380
|
-
] : [];
|
|
381
|
-
};
|
|
382
|
-
const external_node_module_namespaceObject = require("node:module");
|
|
395
|
+
require("node:module");
|
|
383
396
|
const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
|
|
384
|
-
const resolveExtends = (fromFile, target)=>{
|
|
385
|
-
if (target.startsWith('.') || external_node_path_default().isAbsolute(target)) {
|
|
386
|
-
const resolved = external_node_path_default().resolve(external_node_path_default().dirname(fromFile), target);
|
|
387
|
-
return resolved.endsWith('.json') ? resolved : `${resolved}.json`;
|
|
388
|
-
}
|
|
389
|
-
const require1 = (0, external_node_module_namespaceObject.createRequire)(fromFile);
|
|
390
|
-
for (const candidate of [
|
|
391
|
-
target,
|
|
392
|
-
`${target}/tsconfig.json`
|
|
393
|
-
])try {
|
|
394
|
-
return require1.resolve(candidate);
|
|
395
|
-
} catch {}
|
|
396
|
-
};
|
|
397
|
-
const compilerOption = (configFile, name, seen = new Set())=>{
|
|
398
|
-
if (seen.has(configFile) || !external_node_fs_default().existsSync(configFile)) return null;
|
|
399
|
-
seen.add(configFile);
|
|
400
|
-
let config;
|
|
401
|
-
try {
|
|
402
|
-
config = JSON.parse(stripJsonComments(external_node_fs_default().readFileSync(configFile, 'utf8')));
|
|
403
|
-
} catch {
|
|
404
|
-
return null;
|
|
405
|
-
}
|
|
406
|
-
if (config.compilerOptions && name in config.compilerOptions) return config.compilerOptions[name];
|
|
407
|
-
const parents = [
|
|
408
|
-
config.extends ?? []
|
|
409
|
-
].flat().reverse();
|
|
410
|
-
for (const parent of parents){
|
|
411
|
-
const parentFile = resolveExtends(configFile, parent);
|
|
412
|
-
const value = parentFile ? compilerOption(parentFile, name, seen) : null;
|
|
413
|
-
if (void 0 !== value) return value;
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
397
|
class UnknownFormatNaming {
|
|
417
398
|
rawSource;
|
|
418
399
|
camelCase;
|
|
@@ -463,7 +444,7 @@ class NestedName {
|
|
|
463
444
|
return true;
|
|
464
445
|
};
|
|
465
446
|
}
|
|
466
|
-
const
|
|
447
|
+
const scaffold_react_page_reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
467
448
|
${[
|
|
468
449
|
...imports,
|
|
469
450
|
"import { type FC } from 'react'"
|
|
@@ -484,1127 +465,7 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
484
465
|
presentationReactFolder.subitem([
|
|
485
466
|
'pages',
|
|
486
467
|
...folders
|
|
487
|
-
]).createFile(`${fileName}-page.tsx`,
|
|
488
|
-
};
|
|
489
|
-
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
490
|
-
const rootFolderSegments = (rootFolder)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n `).join('');
|
|
491
|
-
const openapiExtractor = (rootFolder)=>`import path from 'node:path';
|
|
492
|
-
import {
|
|
493
|
-
type DocNode,
|
|
494
|
-
DocPlainText,
|
|
495
|
-
TSDocConfiguration,
|
|
496
|
-
TSDocParser,
|
|
497
|
-
TSDocTagDefinition,
|
|
498
|
-
TSDocTagSyntaxKind
|
|
499
|
-
} from '@microsoft/tsdoc';
|
|
500
|
-
import { Node, Project, type SourceFile, SyntaxKind } from 'ts-morph';
|
|
501
|
-
|
|
502
|
-
type BlockTag = \`@\${string}\`;
|
|
503
|
-
|
|
504
|
-
type OpenApiDataTags = {
|
|
505
|
-
/** Omit to take the summary from the comment text before the first tag. */
|
|
506
|
-
summary?: BlockTag;
|
|
507
|
-
description?: BlockTag;
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
type OpenApiData = Partial<{
|
|
511
|
-
summary: string;
|
|
512
|
-
description: string;
|
|
513
|
-
operationId: string;
|
|
514
|
-
}>;
|
|
515
|
-
|
|
516
|
-
const project = new Project({
|
|
517
|
-
tsConfigFilePath: 'tsconfig.json'
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
const getText = (node: DocNode): string =>
|
|
521
|
-
node
|
|
522
|
-
.getChildNodes()
|
|
523
|
-
.map((child) => {
|
|
524
|
-
if (child instanceof DocPlainText) {
|
|
525
|
-
return child.text;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return getText(child);
|
|
529
|
-
})
|
|
530
|
-
.join('');
|
|
531
|
-
|
|
532
|
-
const getRawCommentText = (comment: string): string =>
|
|
533
|
-
comment
|
|
534
|
-
.replace(/^\\/\\*\\*/, '')
|
|
535
|
-
.replace(/\\*\\/$/, '')
|
|
536
|
-
.split(/\\r?\\n/)
|
|
537
|
-
.map((line) => line.replace(/^\\s*\\*\\s?/, ''))
|
|
538
|
-
.join('\\n');
|
|
539
|
-
|
|
540
|
-
// TSDoc treats an unknown tag as summary content, so every block tag of the
|
|
541
|
-
// comment has to be registered for the summary section to end before it.
|
|
542
|
-
const parseSummary = (comment: string): string | undefined => {
|
|
543
|
-
const configuration = new TSDocConfiguration();
|
|
544
|
-
const tagNames = getRawCommentText(comment).matchAll(/(?:^|\\n)\\s*(@\\w+)/g);
|
|
545
|
-
|
|
546
|
-
for (const [, tagName] of tagNames) {
|
|
547
|
-
if (!configuration.tryGetTagDefinition(tagName)) {
|
|
548
|
-
configuration.addTagDefinition(
|
|
549
|
-
new TSDocTagDefinition({
|
|
550
|
-
tagName,
|
|
551
|
-
syntaxKind: TSDocTagSyntaxKind.BlockTag
|
|
552
|
-
})
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
const { docComment } = new TSDocParser(configuration).parseString(comment);
|
|
558
|
-
|
|
559
|
-
return getText(docComment.summarySection).trim() || undefined;
|
|
560
|
-
};
|
|
561
|
-
|
|
562
|
-
// Parsed by hand rather than through TSDoc, which drops the line breaks.
|
|
563
|
-
const getTagText = (comment: string, tag: BlockTag): string | undefined => {
|
|
564
|
-
const tagMatch = getRawCommentText(comment).match(
|
|
565
|
-
new RegExp(
|
|
566
|
-
\`(?:^|\\\\n)\\\\s*\${tag}(?:[ \\\\t]*\\\\n|[ \\\\t]+)([\\\\s\\\\S]*?)(?=\\\\n\\\\s*@\\\\w+|\\\\s*$)\`
|
|
567
|
-
)
|
|
568
|
-
);
|
|
569
|
-
|
|
570
|
-
return tagMatch?.[1].trim() || undefined;
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
// Endpoints pass their logic as the generator's first argument
|
|
574
|
-
// (\`this.endpointGenerator(this.handler.handle, ...)\`), while other injected
|
|
575
|
-
// queries only serve as helpers, e.g. guest checks.
|
|
576
|
-
const findHandlerClass = (endpointFile: SourceFile) =>
|
|
577
|
-
endpointFile
|
|
578
|
-
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
579
|
-
.map((call) => call.getArguments()[0])
|
|
580
|
-
.filter(Node.isPropertyAccessExpression)
|
|
581
|
-
.find((argument) => argument.getName() === 'handle')
|
|
582
|
-
?.getExpression()
|
|
583
|
-
.getType()
|
|
584
|
-
.getSymbol()
|
|
585
|
-
?.getDeclarations()
|
|
586
|
-
.find(Node.isClassDeclaration);
|
|
587
|
-
|
|
588
|
-
// Path parameters (\`:id\`) can't be part of file and folder names
|
|
589
|
-
// everywhere (Windows), so endpoints name them \`_id_\` there.
|
|
590
|
-
const pathParameterAsName = (segment: string) =>
|
|
591
|
-
segment.startsWith(':') ? \`_\${segment.slice(1)}_\` : segment;
|
|
592
|
-
|
|
593
|
-
export const createOpenApiDataFromEndpointLogicExtractor = ({
|
|
594
|
-
summary: summaryTag,
|
|
595
|
-
description: descriptionTag = '@description'
|
|
596
|
-
}: OpenApiDataTags = {}) => {
|
|
597
|
-
return (routeMetadata: {
|
|
598
|
-
method: string;
|
|
599
|
-
path: readonly string[];
|
|
600
|
-
}): OpenApiData | undefined => {
|
|
601
|
-
try {
|
|
602
|
-
const [currentBoundedContext, controller, ...relativePath] =
|
|
603
|
-
routeMetadata.path;
|
|
604
|
-
|
|
605
|
-
if (!currentBoundedContext || !controller) {
|
|
606
|
-
return undefined;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
const endpointFile = project.getSourceFile(
|
|
610
|
-
path.join(
|
|
611
|
-
${rootFolderSegments(rootFolder)}'bounded-contexts',
|
|
612
|
-
currentBoundedContext,
|
|
613
|
-
'presentation',
|
|
614
|
-
'rest',
|
|
615
|
-
controller,
|
|
616
|
-
...relativePath.map(pathParameterAsName),
|
|
617
|
-
\`\${routeMetadata.method.toUpperCase()}.ts\`
|
|
618
|
-
)
|
|
619
|
-
);
|
|
620
|
-
|
|
621
|
-
if (!endpointFile) {
|
|
622
|
-
return undefined;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
const declaration = findHandlerClass(endpointFile);
|
|
626
|
-
const operationId = declaration?.getName();
|
|
627
|
-
const comment = declaration?.getJsDocs().at(-1)?.getText();
|
|
628
|
-
|
|
629
|
-
if (!comment) {
|
|
630
|
-
return { operationId };
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
return {
|
|
634
|
-
summary: summaryTag
|
|
635
|
-
? getTagText(comment, summaryTag)
|
|
636
|
-
: parseSummary(comment),
|
|
637
|
-
description: getTagText(comment, descriptionTag),
|
|
638
|
-
operationId
|
|
639
|
-
};
|
|
640
|
-
} catch (e: unknown) {
|
|
641
|
-
console.error(e);
|
|
642
|
-
return undefined;
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
};
|
|
646
|
-
`;
|
|
647
|
-
const addPackageScripts = async (file, additions)=>{
|
|
648
|
-
const original = file.data;
|
|
649
|
-
const manifest = JSON.parse(original);
|
|
650
|
-
const scripts = {
|
|
651
|
-
...manifest.scripts
|
|
652
|
-
};
|
|
653
|
-
const selected = {};
|
|
654
|
-
for (const [name, command] of Object.entries(additions)){
|
|
655
|
-
let target = name;
|
|
656
|
-
if (Object.hasOwn(scripts, name) && scripts[name] !== command) {
|
|
657
|
-
const action = await (0, prompts_namespaceObject.select)({
|
|
658
|
-
message: `Script "${name}" already exists: ${scripts[name]}`,
|
|
659
|
-
choices: [
|
|
660
|
-
'Keep existing',
|
|
661
|
-
'Replace',
|
|
662
|
-
'Use another name'
|
|
663
|
-
]
|
|
664
|
-
});
|
|
665
|
-
if ('Keep existing' === action) continue;
|
|
666
|
-
if ('Use another name' === action) target = await (0, prompts_namespaceObject.input)({
|
|
667
|
-
message: "New script name:",
|
|
668
|
-
validate: (value)=>!/^[a-zA-Z0-9:_-]+$/.test(value) || Object.hasOwn(scripts, value) || Object.hasOwn(additions, value) ? "Enter an unused script name (letters, numbers, :, _, -)." : true
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
scripts[target] = command;
|
|
672
|
-
selected[name] = target;
|
|
673
|
-
}
|
|
674
|
-
if (JSON.stringify(manifest.scripts) !== JSON.stringify(scripts)) {
|
|
675
|
-
manifest.scripts = scripts;
|
|
676
|
-
const indent = original.match(/\n([\t ]+)"/)?.[1] ?? ' ';
|
|
677
|
-
file.update(`${JSON.stringify(manifest, null, indent)}\n`);
|
|
678
|
-
}
|
|
679
|
-
return selected;
|
|
680
|
-
};
|
|
681
|
-
const describeScripts = (selected, descriptions)=>Object.entries(descriptions).filter(([name])=>selected[name]).map(([name, description])=>`npm run ${selected[name]} — ${description}`);
|
|
682
|
-
const openapiScriptPath = "scripts/generate-openapi.ts";
|
|
683
|
-
const defaultOpenapiPath = (withNext)=>withNext ? 'public/openapi.json' : 'openapi.json';
|
|
684
|
-
const extractorPackages = [
|
|
685
|
-
'ts-morph',
|
|
686
|
-
'@microsoft/tsdoc'
|
|
687
|
-
];
|
|
688
|
-
const swaggerPagePath = (rootFolder)=>external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react/pages/swagger-page.tsx');
|
|
689
|
-
const swaggerPage = (rootFolder, outputPath)=>{
|
|
690
|
-
const specImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(swaggerPagePath(rootFolder)), outputPath);
|
|
691
|
-
return reactPageContent('Swagger', {
|
|
692
|
-
imports: [
|
|
693
|
-
"import 'swagger-ui-react/swagger-ui.css'",
|
|
694
|
-
"import SwaggerUI from 'swagger-ui-react'",
|
|
695
|
-
`import spec from '${specImport.startsWith('.') ? specImport : `./${specImport}`}' with { type: 'json' }`
|
|
696
|
-
],
|
|
697
|
-
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
698
|
-
});
|
|
699
|
-
};
|
|
700
|
-
const openapiScripts = {
|
|
701
|
-
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
702
|
-
};
|
|
703
|
-
const splitPath = (value)=>value.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
704
|
-
const apiTitle = (packageName)=>{
|
|
705
|
-
const words = String(packageName ?? '').replace(/^@[^/]*\//, '').split(/[^a-zA-Z0-9]+/).filter((word)=>!!word).map((word)=>word[0].toUpperCase() + word.slice(1));
|
|
706
|
-
return [
|
|
707
|
-
...words,
|
|
708
|
-
'API'
|
|
709
|
-
].join(' ');
|
|
710
|
-
};
|
|
711
|
-
const openapiGenerator = (rootFolder, title, routePrefix, outputPath, withExtractor = false)=>{
|
|
712
|
-
const restFolder = external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/rest');
|
|
713
|
-
const restImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(openapiScriptPath), restFolder);
|
|
714
|
-
const prefixSegments = splitPath(routePrefix);
|
|
715
|
-
const apiRoutePrefix = prefixSegments.length ? `\n apiRoutePrefix: [${prefixSegments.map((segment)=>`'${segment}'`).join(', ')}],` : '';
|
|
716
|
-
const extractorImport = `./${external_node_path_default().posix.relative(external_node_path_default().posix.dirname(openapiScriptPath), openapiExtractorPath.replace(/\.ts$/, ''))}`;
|
|
717
|
-
const handlers = withExtractor ? `
|
|
718
|
-
const extractOpenApiDataFromEndpointLogic =
|
|
719
|
-
createOpenApiDataFromEndpointLogicExtractor();
|
|
720
|
-
|
|
721
|
-
const handlers = restHandlers.map((x) => ({
|
|
722
|
-
...x,
|
|
723
|
-
metadata: {
|
|
724
|
-
...x.metadata,
|
|
725
|
-
openApiMetadata: {
|
|
726
|
-
...extractOpenApiDataFromEndpointLogic(x.metadata.route),
|
|
727
|
-
...(x.metadata.openApiMetadata ?? {})
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
}));
|
|
731
|
-
` : '';
|
|
732
|
-
return `import { generateOpenAPI } from '@domain-first/handlers-rest';
|
|
733
|
-
import { restHandlers } from '${restImport.startsWith('.') ? restImport : `./${restImport}`}';${withExtractor ? `\nimport { createOpenApiDataFromEndpointLogicExtractor } from '${extractorImport}';` : ''}
|
|
734
|
-
${handlers}
|
|
735
|
-
generateOpenAPI(${withExtractor ? 'handlers' : 'restHandlers'}, {
|
|
736
|
-
document: { info: { title: '${title}', version: '1.0.0' } },${apiRoutePrefix}
|
|
737
|
-
outputFile: { path: '${outputPath}' }
|
|
738
|
-
});
|
|
739
|
-
`;
|
|
740
|
-
};
|
|
741
|
-
const addOpenapi = async ()=>{
|
|
742
|
-
const { rootFolder } = ConfigFile.Instance.data;
|
|
743
|
-
const root = new ProjectRoot().path;
|
|
744
|
-
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
745
|
-
const manifest = JSON.parse(manifestFile.data);
|
|
746
|
-
const dependencies = {
|
|
747
|
-
...manifest.dependencies,
|
|
748
|
-
...manifest.devDependencies
|
|
749
|
-
};
|
|
750
|
-
const routePrefix = await (0, prompts_namespaceObject.input)({
|
|
751
|
-
message: 'Route prefix the REST handlers are served under:',
|
|
752
|
-
default: '/api'
|
|
753
|
-
});
|
|
754
|
-
const outputPath = await (0, prompts_namespaceObject.input)({
|
|
755
|
-
message: 'OpenAPI document path:',
|
|
756
|
-
default: defaultOpenapiPath(Boolean(dependencies.next)),
|
|
757
|
-
validate: (value)=>splitPath(value).length ? true : 'Path is required'
|
|
758
|
-
});
|
|
759
|
-
const withExtractor = await (0, prompts_namespaceObject.confirm)({
|
|
760
|
-
message: "Fill operationId, summary and description from the endpoint logic TSDoc?",
|
|
761
|
-
default: true
|
|
762
|
-
});
|
|
763
|
-
const withSwaggerPage = ConfigFile.Instance.data.useReact && await (0, prompts_namespaceObject.confirm)({
|
|
764
|
-
message: 'Add a Swagger UI page?',
|
|
765
|
-
default: true
|
|
766
|
-
});
|
|
767
|
-
const selected = await addPackageScripts(manifestFile, openapiScripts);
|
|
768
|
-
if (withExtractor) {
|
|
769
|
-
const extractorFile = new File(external_node_path_default().join(root, openapiExtractorPath));
|
|
770
|
-
const extractor = openapiExtractor(rootFolder);
|
|
771
|
-
if (!extractorFile.exists || extractorFile.data !== extractor) extractorFile.data = extractor;
|
|
772
|
-
}
|
|
773
|
-
const generatorFile = new File(external_node_path_default().join(root, openapiScriptPath));
|
|
774
|
-
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
775
|
-
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
776
|
-
if (withSwaggerPage) {
|
|
777
|
-
const pageFile = new File(external_node_path_default().join(root, swaggerPagePath(rootFolder)));
|
|
778
|
-
const page = swaggerPage(rootFolder, splitPath(outputPath).join('/'));
|
|
779
|
-
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
780
|
-
}
|
|
781
|
-
const resolveJsonModule = withSwaggerPage ? compilerOption(external_node_path_default().join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
782
|
-
const hasRestHandlers = new File(external_node_path_default().join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
783
|
-
const missingExtractorPackages = withExtractor ? extractorPackages.filter((name)=>!dependencies[name]) : [];
|
|
784
|
-
return [
|
|
785
|
-
...dependencies['@domain-first/handlers-rest'] ? [] : [
|
|
786
|
-
'npm install @domain-first/handlers-rest'
|
|
787
|
-
],
|
|
788
|
-
...dependencies.tsx ? [] : [
|
|
789
|
-
'npm install --save-dev tsx'
|
|
790
|
-
],
|
|
791
|
-
...missingExtractorPackages.length ? [
|
|
792
|
-
`npm install --save-dev ${missingExtractorPackages.join(' ')}`
|
|
793
|
-
] : [],
|
|
794
|
-
...withSwaggerPage && !dependencies['swagger-ui-react'] ? [
|
|
795
|
-
'npm install swagger-ui-react'
|
|
796
|
-
] : [],
|
|
797
|
-
...withSwaggerPage && !dependencies['@types/swagger-ui-react'] ? [
|
|
798
|
-
'npm install --save-dev @types/swagger-ui-react'
|
|
799
|
-
] : [],
|
|
800
|
-
...true === resolveJsonModule || null === resolveJsonModule ? [] : [
|
|
801
|
-
'set "resolveJsonModule": true in compilerOptions of tsconfig.json — the Swagger UI page imports the OpenAPI document as JSON'
|
|
802
|
-
],
|
|
803
|
-
...describeScripts(selected, {
|
|
804
|
-
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
805
|
-
}),
|
|
806
|
-
...withSwaggerPage ? [
|
|
807
|
-
`SwaggerPage from ${swaggerPagePath(rootFolder)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
808
|
-
] : [],
|
|
809
|
-
...hasRestHandlers ? [] : [
|
|
810
|
-
`restHandlers appear in ${external_node_path_default().posix.join(rootFolder, 'presentation/rest/index.ts')} with the first REST endpoint generated with @domain-first/wire`
|
|
811
|
-
]
|
|
812
|
-
];
|
|
813
|
-
};
|
|
814
|
-
const addGitignoreEntry = (root, entry)=>{
|
|
815
|
-
const gitignore = new File(external_node_path_default().join(root, '.gitignore'));
|
|
816
|
-
const ignored = gitignore.exists ? gitignore.data : '';
|
|
817
|
-
if (ignored.split(/\r?\n/).includes(entry)) return;
|
|
818
|
-
const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
|
|
819
|
-
gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${entry}${newline}`);
|
|
820
|
-
};
|
|
821
|
-
const dataLayerFolder = (rootFolder)=>external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react/data-layer');
|
|
822
|
-
const orvalScripts = (rootFolder)=>({
|
|
823
|
-
'client:orval': `orval --config ${JSON.stringify(`${dataLayerFolder(rootFolder)}/orval.config.ts`)}`
|
|
824
|
-
});
|
|
825
|
-
const orvalConfig = (rootFolder, openapiPath, withNext)=>{
|
|
826
|
-
const inputPath = external_node_path_default().posix.relative(dataLayerFolder(rootFolder), openapiPath);
|
|
827
|
-
const baseUrl = withNext ? `
|
|
828
|
-
baseUrl: {
|
|
829
|
-
runtime: 'process.env.NEXT_PUBLIC_API_BASE_URL ?? ""'
|
|
830
|
-
},` : '';
|
|
831
|
-
return `import { defineConfig } from 'orval';
|
|
832
|
-
|
|
833
|
-
export default defineConfig({
|
|
834
|
-
api: {
|
|
835
|
-
input: '${inputPath.startsWith('.') ? inputPath : `./${inputPath}`}',
|
|
836
|
-
output: {
|
|
837
|
-
mode: 'tags-split',
|
|
838
|
-
target: './orval',
|
|
839
|
-
schemas: './orval/model',
|
|
840
|
-
client: 'react-query',
|
|
841
|
-
httpClient: 'fetch',${baseUrl}
|
|
842
|
-
clean: true,
|
|
843
|
-
override: {
|
|
844
|
-
mutator: {
|
|
845
|
-
path: './api-client/mutator.ts',
|
|
846
|
-
name: 'customInstance'
|
|
847
|
-
},
|
|
848
|
-
fetch: {
|
|
849
|
-
includeHttpResponseReturnType: false
|
|
850
|
-
},
|
|
851
|
-
query: {
|
|
852
|
-
version: 5
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
`;
|
|
859
|
-
};
|
|
860
|
-
const orvalMutator = `/** Error of the generated hooks, with the parsed response body. */
|
|
861
|
-
export class ApiError<Body = unknown> extends Error {
|
|
862
|
-
constructor(
|
|
863
|
-
public readonly status: number,
|
|
864
|
-
public readonly body: Body
|
|
865
|
-
) {
|
|
866
|
-
super(\`API error \${status}\`);
|
|
867
|
-
this.name = 'ApiError';
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
/** Error type of the generated hooks, typed per endpoint by Orval. */
|
|
872
|
-
export type ErrorType<Body> = ApiError<Body>;
|
|
873
|
-
|
|
874
|
-
/** Every generated request goes through here: add auth headers, token refresh, logging. */
|
|
875
|
-
export const customInstance = async <T>(
|
|
876
|
-
url: string,
|
|
877
|
-
init?: RequestInit
|
|
878
|
-
): Promise<T> => {
|
|
879
|
-
const response = await fetch(url, init);
|
|
880
|
-
const text = await response.text();
|
|
881
|
-
const body = text ? JSON.parse(text) : undefined;
|
|
882
|
-
|
|
883
|
-
if (!response.ok) {
|
|
884
|
-
throw new ApiError(response.status, body);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
return body as T;
|
|
888
|
-
};
|
|
889
|
-
`;
|
|
890
|
-
const queryProvider = `'use client';
|
|
891
|
-
|
|
892
|
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
893
|
-
import { type FC, type ReactNode, useState } from 'react';
|
|
894
|
-
|
|
895
|
-
export const QueryProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
|
896
|
-
// One client per browser session; a module-level client would be shared between requests on the server
|
|
897
|
-
const [queryClient] = useState(() => new QueryClient());
|
|
898
|
-
|
|
899
|
-
return (
|
|
900
|
-
<QueryClientProvider client={queryClient}>
|
|
901
|
-
{children}
|
|
902
|
-
</QueryClientProvider>
|
|
903
|
-
);
|
|
904
|
-
};
|
|
905
|
-
`;
|
|
906
|
-
const openapiOutputPath = (root)=>{
|
|
907
|
-
const generator = new File(external_node_path_default().join(root, openapiScriptPath));
|
|
908
|
-
if (!generator.exists) return;
|
|
909
|
-
return generator.data.match(/outputFile:\s*{\s*path:\s*'([^']+)'/)?.[1];
|
|
910
|
-
};
|
|
911
|
-
const addOrval = async ()=>{
|
|
912
|
-
const { rootFolder } = ConfigFile.Instance.data;
|
|
913
|
-
const root = new ProjectRoot().path;
|
|
914
|
-
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
915
|
-
const manifest = JSON.parse(manifestFile.data);
|
|
916
|
-
const dependencies = {
|
|
917
|
-
...manifest.dependencies,
|
|
918
|
-
...manifest.devDependencies
|
|
919
|
-
};
|
|
920
|
-
const withNext = Boolean(dependencies.next);
|
|
921
|
-
const generatedOpenapiPath = openapiOutputPath(root);
|
|
922
|
-
const openapiPath = await (0, prompts_namespaceObject.input)({
|
|
923
|
-
message: 'OpenAPI document path:',
|
|
924
|
-
default: generatedOpenapiPath ?? defaultOpenapiPath(withNext),
|
|
925
|
-
validate: (value)=>value.trim() ? true : 'Path is required'
|
|
926
|
-
});
|
|
927
|
-
const selected = await addPackageScripts(manifestFile, orvalScripts(rootFolder));
|
|
928
|
-
const dataLayer = dataLayerFolder(rootFolder);
|
|
929
|
-
const configFile = new File(external_node_path_default().join(root, dataLayer, 'orval.config.ts'));
|
|
930
|
-
const content = orvalConfig(rootFolder, external_node_path_default().posix.normalize(openapiPath.trim().replaceAll('\\', '/')), withNext);
|
|
931
|
-
if (!configFile.exists || configFile.data !== content) configFile.data = content;
|
|
932
|
-
for (const [name, fileContent] of [
|
|
933
|
-
[
|
|
934
|
-
'api-client/mutator.ts',
|
|
935
|
-
orvalMutator
|
|
936
|
-
],
|
|
937
|
-
[
|
|
938
|
-
'query-provider.tsx',
|
|
939
|
-
queryProvider
|
|
940
|
-
]
|
|
941
|
-
]){
|
|
942
|
-
const file = new File(external_node_path_default().join(root, dataLayer, name));
|
|
943
|
-
if (!file.exists) file.data = fileContent;
|
|
944
|
-
}
|
|
945
|
-
addGitignoreEntry(root, `/${dataLayer}/orval/`);
|
|
946
|
-
const missing = (names)=>names.filter((name)=>!dependencies[name]);
|
|
947
|
-
const runtime = missing([
|
|
948
|
-
'@tanstack/react-query'
|
|
949
|
-
]);
|
|
950
|
-
const development = missing([
|
|
951
|
-
'orval'
|
|
952
|
-
]);
|
|
953
|
-
return [
|
|
954
|
-
...runtime.length ? [
|
|
955
|
-
`npm install ${runtime.join(' ')}`
|
|
956
|
-
] : [],
|
|
957
|
-
...development.length ? [
|
|
958
|
-
`npm install --save-dev ${development.join(' ')}`
|
|
959
|
-
] : [],
|
|
960
|
-
...describeScripts(selected, {
|
|
961
|
-
'client:orval': `generate React Query hooks from ${openapiPath.trim()} in ${dataLayer}/orval`
|
|
962
|
-
}),
|
|
963
|
-
`Wrap your app in QueryProvider from ${dataLayer}/query-provider.tsx`,
|
|
964
|
-
...generatedOpenapiPath ? [] : [
|
|
965
|
-
'Add integration → OpenAPI generates the OpenAPI document the client is built from'
|
|
966
|
-
]
|
|
967
|
-
];
|
|
968
|
-
};
|
|
969
|
-
const playwrightScripts = {
|
|
970
|
-
'test:e2e': 'playwright test'
|
|
971
|
-
};
|
|
972
|
-
const playwrightConfig = `import { defineConfig, devices } from '@playwright/test';
|
|
973
|
-
|
|
974
|
-
export default defineConfig({
|
|
975
|
-
testDir: './specs/e2e',
|
|
976
|
-
fullyParallel: true,
|
|
977
|
-
forbidOnly: !!process.env.CI,
|
|
978
|
-
retries: process.env.CI ? 2 : 0,
|
|
979
|
-
workers: process.env.CI ? 1 : undefined,
|
|
980
|
-
reporter: 'html',
|
|
981
|
-
use: {
|
|
982
|
-
baseURL: 'http://localhost:3000',
|
|
983
|
-
trace: 'on-first-retry',
|
|
984
|
-
screenshot: 'only-on-failure',
|
|
985
|
-
video: 'retain-on-failure'
|
|
986
|
-
},
|
|
987
|
-
|
|
988
|
-
projects: [
|
|
989
|
-
{
|
|
990
|
-
name: 'chromium',
|
|
991
|
-
use: { ...devices['Desktop Chrome'] }
|
|
992
|
-
},
|
|
993
|
-
{
|
|
994
|
-
name: 'firefox',
|
|
995
|
-
use: { ...devices['Desktop Firefox'] }
|
|
996
|
-
},
|
|
997
|
-
{
|
|
998
|
-
name: 'webkit',
|
|
999
|
-
use: { ...devices['Desktop Safari'] }
|
|
1000
|
-
},
|
|
1001
|
-
{
|
|
1002
|
-
name: 'Mobile Chrome',
|
|
1003
|
-
use: { ...devices['Pixel 5'] }
|
|
1004
|
-
},
|
|
1005
|
-
{
|
|
1006
|
-
name: 'Mobile Safari',
|
|
1007
|
-
use: { ...devices['iPhone 12'] }
|
|
1008
|
-
}
|
|
1009
|
-
],
|
|
1010
|
-
|
|
1011
|
-
webServer: {
|
|
1012
|
-
// Playwright only stops the dev server on a clean shutdown. If its process dies any other
|
|
1013
|
-
// way (SIGHUP, SIGKILL), the dev server lives on in its own process group, so it is killed
|
|
1014
|
-
// as soon as Playwright is gone.
|
|
1015
|
-
command:
|
|
1016
|
-
process.platform === 'win32'
|
|
1017
|
-
? 'npm run dev'
|
|
1018
|
-
: \`npm run dev & while kill -0 \${process.pid} 2>/dev/null && kill -0 $! 2>/dev/null; do sleep 1; done; kill 0\`,
|
|
1019
|
-
url: 'http://localhost:3000',
|
|
1020
|
-
timeout: 120000,
|
|
1021
|
-
reuseExistingServer: !process.env.CI
|
|
1022
|
-
}
|
|
1023
|
-
});
|
|
1024
|
-
`;
|
|
1025
|
-
const exampleSpec = `import { expect, test } from '@playwright/test';
|
|
1026
|
-
|
|
1027
|
-
test.describe('home page', () => {
|
|
1028
|
-
test('opens the home page', async ({ page, baseURL }) => {
|
|
1029
|
-
await page.goto('/');
|
|
1030
|
-
await expect(page).toHaveURL(\`\${baseURL}/\`);
|
|
1031
|
-
});
|
|
1032
|
-
});
|
|
1033
|
-
`;
|
|
1034
|
-
const exampleReadme = `# Home page e2e cases
|
|
1035
|
-
|
|
1036
|
-
## User Stories
|
|
1037
|
-
|
|
1038
|
-
1. Guest opens \`/\` and stays on the home page.
|
|
1039
|
-
`;
|
|
1040
|
-
const gitignoreEntries = [
|
|
1041
|
-
'/test-results/',
|
|
1042
|
-
'/playwright-report/',
|
|
1043
|
-
'/blob-report/',
|
|
1044
|
-
'/playwright/.cache/',
|
|
1045
|
-
'/playwright/.auth/'
|
|
1046
|
-
];
|
|
1047
|
-
const addPlaywright = async ()=>{
|
|
1048
|
-
const root = new ProjectRoot().path;
|
|
1049
|
-
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
1050
|
-
const manifest = JSON.parse(manifestFile.data);
|
|
1051
|
-
const dependencies = {
|
|
1052
|
-
...manifest.dependencies,
|
|
1053
|
-
...manifest.devDependencies
|
|
1054
|
-
};
|
|
1055
|
-
const selected = await addPackageScripts(manifestFile, playwrightScripts);
|
|
1056
|
-
const configFile = new File(external_node_path_default().join(root, 'playwright.config.ts'));
|
|
1057
|
-
if (!configFile.exists || configFile.data !== playwrightConfig) configFile.data = playwrightConfig;
|
|
1058
|
-
const exampleFolder = external_node_path_default().join(root, 'specs/e2e/home');
|
|
1059
|
-
for (const [name, content] of [
|
|
1060
|
-
[
|
|
1061
|
-
'home.e2e.spec.ts',
|
|
1062
|
-
exampleSpec
|
|
1063
|
-
],
|
|
1064
|
-
[
|
|
1065
|
-
'README.MD',
|
|
1066
|
-
exampleReadme
|
|
1067
|
-
]
|
|
1068
|
-
]){
|
|
1069
|
-
const file = new File(external_node_path_default().join(exampleFolder, name));
|
|
1070
|
-
if (!file.exists) file.data = content;
|
|
1071
|
-
}
|
|
1072
|
-
for (const entry of gitignoreEntries)addGitignoreEntry(root, entry);
|
|
1073
|
-
return [
|
|
1074
|
-
...dependencies['@playwright/test'] ? [] : [
|
|
1075
|
-
'npm install --save-dev @playwright/test'
|
|
1076
|
-
],
|
|
1077
|
-
'npx playwright install --with-deps',
|
|
1078
|
-
...describeScripts(selected, {
|
|
1079
|
-
'test:e2e': 'start the dev server and run end-to-end specs from specs/e2e'
|
|
1080
|
-
})
|
|
1081
|
-
];
|
|
1082
|
-
};
|
|
1083
|
-
const runtimePackages = [
|
|
1084
|
-
'@prisma/orm-postgres',
|
|
1085
|
-
'temporal-polyfill',
|
|
1086
|
-
'dotenv'
|
|
1087
|
-
];
|
|
1088
|
-
const developmentPackages = [
|
|
1089
|
-
'prisma',
|
|
1090
|
-
'@prisma/cli-engine'
|
|
1091
|
-
];
|
|
1092
|
-
const prismaScripts = (rootFolder)=>{
|
|
1093
|
-
const config = JSON.stringify(external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'shared/infrastructure/prisma/prisma.config.ts'));
|
|
1094
|
-
const emit = `prisma contract emit --config ${config}`;
|
|
1095
|
-
return {
|
|
1096
|
-
'prisma:emit': emit,
|
|
1097
|
-
'prisma:migration:plan': `${emit} && prisma migration plan --config ${config}`,
|
|
1098
|
-
'prisma:migration:apply': `prisma db migrate --advance-ref db --config ${config}`
|
|
1099
|
-
};
|
|
1100
|
-
};
|
|
1101
|
-
const prismaConfig = `import 'dotenv/config';
|
|
1102
|
-
import { definePrismaConfig } from '@prisma/cli-engine';
|
|
1103
|
-
import { defineConfig as ormConfig } from '@prisma/orm-postgres/config';
|
|
1104
|
-
|
|
1105
|
-
export default definePrismaConfig({
|
|
1106
|
-
orm: ormConfig({
|
|
1107
|
-
contract: './contract.prisma',
|
|
1108
|
-
migrations: { dir: './migrations' },
|
|
1109
|
-
db: {
|
|
1110
|
-
connection: process.env.DATABASE_URL
|
|
1111
|
-
}
|
|
1112
|
-
})
|
|
1113
|
-
});
|
|
1114
|
-
`;
|
|
1115
|
-
const prismaService = `import 'temporal-polyfill/global';
|
|
1116
|
-
import postgres from '@prisma/orm-postgres/runtime';
|
|
1117
|
-
import type {} from 'temporal-polyfill/types/global';
|
|
1118
|
-
import type { Contract } from '../prisma/contract.d';
|
|
1119
|
-
import contractJson from '../prisma/contract.json' with { type: 'json' };
|
|
1120
|
-
|
|
1121
|
-
type PrismaClient = ReturnType<typeof postgres<Contract>>;
|
|
1122
|
-
|
|
1123
|
-
const globalForPrisma = globalThis as typeof globalThis & {
|
|
1124
|
-
prismaClient?: PrismaClient;
|
|
1125
|
-
};
|
|
1126
|
-
|
|
1127
|
-
// Reuse the client across development hot reloads.
|
|
1128
|
-
const prismaClient = globalForPrisma.prismaClient ??
|
|
1129
|
-
postgres<Contract>({ contractJson, url: process.env.DATABASE_URL });
|
|
1130
|
-
|
|
1131
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1132
|
-
globalForPrisma.prismaClient = prismaClient;
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
export class PrismaInfrastructureService {
|
|
1136
|
-
readonly orm = prismaClient.orm.public;
|
|
1137
|
-
}
|
|
1138
|
-
`;
|
|
1139
|
-
const prismaWiring = `import { wireClass } from '@domain-first/wire';
|
|
1140
|
-
import { PrismaInfrastructureService } from '../../infrastructure/services/prisma-infrastructure-service';
|
|
1141
|
-
|
|
1142
|
-
export const wirePrismaInfrastructureService = wireClass(
|
|
1143
|
-
PrismaInfrastructureService,
|
|
1144
|
-
[]
|
|
1145
|
-
);
|
|
1146
|
-
`;
|
|
1147
|
-
const stageFile = (filePath, content)=>{
|
|
1148
|
-
const file = new File(filePath);
|
|
1149
|
-
if (!file.exists || file.data !== content) file.data = content;
|
|
1150
|
-
};
|
|
1151
|
-
const addPrisma = async ()=>{
|
|
1152
|
-
const config = ConfigFile.Instance.data;
|
|
1153
|
-
const root = new ProjectRoot().path;
|
|
1154
|
-
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
1155
|
-
const manifest = JSON.parse(manifestFile.data);
|
|
1156
|
-
const dependencies = {
|
|
1157
|
-
...manifest.dependencies,
|
|
1158
|
-
...manifest.devDependencies
|
|
1159
|
-
};
|
|
1160
|
-
const shared = external_node_path_default().resolve(root, config.rootFolder, 'shared');
|
|
1161
|
-
const prismaFolder = external_node_path_default().join(shared, 'infrastructure/prisma');
|
|
1162
|
-
if (dependencies['@prisma/client'] || dependencies.prisma && !/^[~^]?8\./.test(dependencies.prisma) || dependencies['@prisma/orm-mongo'] || dependencies['@prisma/orm-sqlite'] || [
|
|
1163
|
-
external_node_path_default().join(root, 'prisma/schema.prisma'),
|
|
1164
|
-
external_node_path_default().join(prismaFolder, 'schema.prisma')
|
|
1165
|
-
].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.');
|
|
1166
|
-
const withService = await (0, prompts_namespaceObject.confirm)({
|
|
1167
|
-
message: 'Create shared Prisma infrastructure service?',
|
|
1168
|
-
default: true
|
|
1169
|
-
});
|
|
1170
|
-
const useByDefault = 'prisma' !== config.defaultPersistenceLayerImplementation && await (0, prompts_namespaceObject.confirm)({
|
|
1171
|
-
message: 'Use prisma as the default persistence implementation?',
|
|
1172
|
-
default: false
|
|
1173
|
-
});
|
|
1174
|
-
const selected = await addPackageScripts(manifestFile, prismaScripts(config.rootFolder));
|
|
1175
|
-
stageFile(external_node_path_default().join(prismaFolder, 'prisma.config.ts'), prismaConfig);
|
|
1176
|
-
const contract = new File(external_node_path_default().join(prismaFolder, 'contract.prisma'));
|
|
1177
|
-
if (!contract.exists) contract.data = '// use prisma-8\n\n// Add your application models here before running prisma:emit.\n';
|
|
1178
|
-
if (withService) {
|
|
1179
|
-
stageFile(external_node_path_default().join(shared, 'infrastructure/services/prisma-infrastructure-service.ts'), prismaService);
|
|
1180
|
-
if (config.domainFirstPackages.includes('@domain-first/wire')) stageFile(external_node_path_default().join(shared, 'wiring/infrastructure-services/wire-prisma-infrastructure-service.ts'), prismaWiring);
|
|
1181
|
-
}
|
|
1182
|
-
if (useByDefault) ConfigFile.write({
|
|
1183
|
-
...config,
|
|
1184
|
-
defaultPersistenceLayerImplementation: 'prisma'
|
|
1185
|
-
});
|
|
1186
|
-
const install = (packages, dev)=>{
|
|
1187
|
-
const missing = packages.filter((name)=>!dependencies[name]);
|
|
1188
|
-
return missing.length ? [
|
|
1189
|
-
`npm install${dev ? ' --save-dev' : ''} ${missing.join(' ')}`
|
|
1190
|
-
] : [];
|
|
1191
|
-
};
|
|
1192
|
-
const relativeFolder = external_node_path_default().relative(root, prismaFolder).split(external_node_path_default().sep).join('/');
|
|
1193
|
-
return [
|
|
1194
|
-
...install(runtimePackages, false),
|
|
1195
|
-
...install(developmentPackages, true),
|
|
1196
|
-
`Add !${relativeFolder} in your linter, to ignore prisma files.`,
|
|
1197
|
-
...describeScripts(selected, {
|
|
1198
|
-
'prisma:emit': 'emit contract.json and contract.d.ts from contract.prisma',
|
|
1199
|
-
'prisma:migration:plan': 'emit the contract and plan a migration',
|
|
1200
|
-
'prisma:migration:apply': 'apply planned migrations to the database in DATABASE_URL'
|
|
1201
|
-
})
|
|
1202
|
-
];
|
|
1203
|
-
};
|
|
1204
|
-
const storybookFiles = (relativeProjectRoot)=>({
|
|
1205
|
-
'main.ts': `import { resolve } from 'node:path';
|
|
1206
|
-
import react from '@vitejs/plugin-react';
|
|
1207
|
-
import type { StorybookConfig } from '@storybook/react-vite';
|
|
1208
|
-
|
|
1209
|
-
const projectRoot = resolve(import.meta.dirname, ${JSON.stringify(relativeProjectRoot)});
|
|
1210
|
-
|
|
1211
|
-
const config: StorybookConfig = {
|
|
1212
|
-
stories: ['../**/*.mdx', '../**/*.stories.@(ts|tsx)'],
|
|
1213
|
-
framework: {
|
|
1214
|
-
name: '@storybook/react-vite',
|
|
1215
|
-
options: {}
|
|
1216
|
-
},
|
|
1217
|
-
core: {
|
|
1218
|
-
disableTelemetry: true
|
|
1219
|
-
},
|
|
1220
|
-
async viteFinal(viteConfig) {
|
|
1221
|
-
const { mergeConfig } = await import('vite');
|
|
1222
|
-
|
|
1223
|
-
return mergeConfig(viteConfig, {
|
|
1224
|
-
plugins: [react()],
|
|
1225
|
-
resolve: {
|
|
1226
|
-
alias: {
|
|
1227
|
-
'@': projectRoot
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
};
|
|
1233
|
-
|
|
1234
|
-
export default config;
|
|
1235
|
-
`,
|
|
1236
|
-
'preview.ts': `import type { Preview } from '@storybook/react-vite';
|
|
1237
|
-
|
|
1238
|
-
const preview: Preview = {
|
|
1239
|
-
parameters: {
|
|
1240
|
-
controls: {
|
|
1241
|
-
matchers: {
|
|
1242
|
-
color: /(background|color)$/i,
|
|
1243
|
-
date: /Date$/i
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
};
|
|
1248
|
-
|
|
1249
|
-
export default preview;
|
|
1250
|
-
`
|
|
1251
|
-
});
|
|
1252
|
-
const storybookScripts = (rootFolder)=>{
|
|
1253
|
-
const folder = external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react');
|
|
1254
|
-
const quote = (value)=>JSON.stringify(value);
|
|
1255
|
-
return {
|
|
1256
|
-
storybook: `storybook dev -p 6006 -c ${quote(`${folder}/.storybook`)}`,
|
|
1257
|
-
'build-storybook': `storybook build -c ${quote(`${folder}/.storybook`)} -o ${quote(`${folder}/storybook-static`)}`
|
|
1258
|
-
};
|
|
1259
|
-
};
|
|
1260
|
-
const addStorybook = async ()=>{
|
|
1261
|
-
const config = ConfigFile.Instance.data;
|
|
1262
|
-
if ((!config.useReact || config.storybookFramework && '@storybook/react-vite' !== config.storybookFramework) && !await (0, prompts_namespaceObject.confirm)({
|
|
1263
|
-
message: 'Configure React scaffolding with @storybook/react-vite?',
|
|
1264
|
-
default: false
|
|
1265
|
-
})) return [];
|
|
1266
|
-
const root = new ProjectRoot().path;
|
|
1267
|
-
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
1268
|
-
const manifest = JSON.parse(manifestFile.data);
|
|
1269
|
-
const selected = await addPackageScripts(manifestFile, storybookScripts(config.rootFolder));
|
|
1270
|
-
const folder = new Folder(root).subitem([
|
|
1271
|
-
config.rootFolder,
|
|
1272
|
-
'presentation',
|
|
1273
|
-
'react',
|
|
1274
|
-
'.storybook'
|
|
1275
|
-
]);
|
|
1276
|
-
for (const [name, content] of Object.entries(storybookFiles(external_node_path_default().relative(folder.path, root).split(external_node_path_default().sep).join('/')))){
|
|
1277
|
-
const file = new File(external_node_path_default().join(folder.path, name));
|
|
1278
|
-
if (!file.exists || file.data !== content) file.data = content;
|
|
1279
|
-
}
|
|
1280
|
-
if (!config.useReact || '@storybook/react-vite' !== config.storybookFramework) ConfigFile.write({
|
|
1281
|
-
...config,
|
|
1282
|
-
useReact: true,
|
|
1283
|
-
storybookFramework: '@storybook/react-vite'
|
|
1284
|
-
});
|
|
1285
|
-
const buildFolder = external_node_path_default().posix.join(config.rootFolder.replaceAll('\\', '/'), 'presentation/react/storybook-static');
|
|
1286
|
-
addGitignoreEntry(root, `/${buildFolder}/`);
|
|
1287
|
-
const dependencies = {
|
|
1288
|
-
...manifest.dependencies,
|
|
1289
|
-
...manifest.devDependencies
|
|
1290
|
-
};
|
|
1291
|
-
const missing = [
|
|
1292
|
-
'storybook',
|
|
1293
|
-
'@storybook/react-vite',
|
|
1294
|
-
'vite',
|
|
1295
|
-
'@vitejs/plugin-react'
|
|
1296
|
-
].filter((name)=>!dependencies[name]);
|
|
1297
|
-
const missingReact = [
|
|
1298
|
-
'react',
|
|
1299
|
-
'react-dom'
|
|
1300
|
-
].filter((name)=>!dependencies[name]);
|
|
1301
|
-
return [
|
|
1302
|
-
...missing.length ? [
|
|
1303
|
-
`npm install --save-dev ${missing.join(' ')}`
|
|
1304
|
-
] : [],
|
|
1305
|
-
...missingReact.length ? [
|
|
1306
|
-
`npm install ${missingReact.join(' ')}`
|
|
1307
|
-
] : [],
|
|
1308
|
-
...describeScripts(selected, {
|
|
1309
|
-
storybook: 'start Storybook on http://localhost:6006',
|
|
1310
|
-
'build-storybook': `build static Storybook into ${buildFolder}`
|
|
1311
|
-
})
|
|
1312
|
-
];
|
|
1313
|
-
};
|
|
1314
|
-
const integrationFolder = 'specs/integration';
|
|
1315
|
-
const testcontainersScripts = {
|
|
1316
|
-
'test:integration': `vitest run --config ${integrationFolder}/vitest.config.ts --reporter=dot --silent=passed-only`
|
|
1317
|
-
};
|
|
1318
|
-
const testcontainersVitestConfig = (inlineHandlersNext)=>{
|
|
1319
|
-
const server = inlineHandlersNext ? `,
|
|
1320
|
-
server: {
|
|
1321
|
-
deps: {
|
|
1322
|
-
// Imports \`next/headers\` without an extension, which only a bundler can resolve
|
|
1323
|
-
inline: ['@domain-first/handlers-next']
|
|
1324
|
-
}
|
|
1325
|
-
}` : '';
|
|
1326
|
-
return `import { fileURLToPath } from 'node:url';
|
|
1327
|
-
import { defineConfig } from 'vitest/config';
|
|
1328
|
-
|
|
1329
|
-
// Runs specs from this folder against PostgreSQL in a container, see global-setup.ts.
|
|
1330
|
-
export default defineConfig({
|
|
1331
|
-
// Paths below are relative to the project root, not this folder
|
|
1332
|
-
root: fileURLToPath(new URL('../..', import.meta.url)),
|
|
1333
|
-
resolve: {
|
|
1334
|
-
tsconfigPaths: true
|
|
1335
|
-
},
|
|
1336
|
-
test: {
|
|
1337
|
-
include: ['${integrationFolder}/**/*.spec.ts'],
|
|
1338
|
-
// Development implementations work with the real database
|
|
1339
|
-
env: { NODE_ENV: 'development' },
|
|
1340
|
-
globalSetup: ['${integrationFolder}/global-setup.ts'],
|
|
1341
|
-
setupFiles: ['${integrationFolder}/setup-env.ts'],
|
|
1342
|
-
// Pulling the image on the first run takes a while
|
|
1343
|
-
hookTimeout: 120_000${server}
|
|
1344
|
-
}
|
|
1345
|
-
});
|
|
1346
|
-
`;
|
|
1347
|
-
};
|
|
1348
|
-
const testcontainersGlobalSetup = (migrationCommand)=>{
|
|
1349
|
-
const migrations = migrationCommand ? `
|
|
1350
|
-
// dotenv in the Prisma config does not override an already set variable
|
|
1351
|
-
execSync(${JSON.stringify(migrationCommand)}, {
|
|
1352
|
-
cwd: project.config.root,
|
|
1353
|
-
env: { ...process.env, DATABASE_URL: databaseUrl },
|
|
1354
|
-
// On failure the error carries the command's output
|
|
1355
|
-
stdio: 'pipe'
|
|
1356
|
-
});
|
|
1357
|
-
` : `
|
|
1358
|
-
// Apply your migrations to databaseUrl here.
|
|
1359
|
-
`;
|
|
1360
|
-
return `${migrationCommand ? "import { execSync } from 'node:child_process';\n" : ''}import { GenericContainer, Wait } from 'testcontainers';
|
|
1361
|
-
import type { TestProject } from 'vitest/node';
|
|
1362
|
-
|
|
1363
|
-
declare module 'vitest' {
|
|
1364
|
-
export interface ProvidedContext {
|
|
1365
|
-
databaseUrl: string;
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
const POSTGRES_IMAGE = 'postgres:15';
|
|
1370
|
-
const POSTGRES_PORT = 5432;
|
|
1371
|
-
const POSTGRES_USER = 'test';
|
|
1372
|
-
const POSTGRES_PASSWORD = 'test';
|
|
1373
|
-
const POSTGRES_DB = 'test';
|
|
1374
|
-
|
|
1375
|
-
export default async function setup(project: TestProject) {
|
|
1376
|
-
const container = await new GenericContainer(POSTGRES_IMAGE)
|
|
1377
|
-
.withEnvironment({ POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB })
|
|
1378
|
-
.withExposedPorts(POSTGRES_PORT)
|
|
1379
|
-
// During init PostgreSQL listens on a unix socket only and restarts,
|
|
1380
|
-
// so checking over TCP passes once the final server is up
|
|
1381
|
-
.withHealthCheck({
|
|
1382
|
-
test: [
|
|
1383
|
-
'CMD-SHELL',
|
|
1384
|
-
\`pg_isready --host localhost --username \${POSTGRES_USER} --dbname \${POSTGRES_DB}\`
|
|
1385
|
-
],
|
|
1386
|
-
interval: 250,
|
|
1387
|
-
timeout: 1000,
|
|
1388
|
-
retries: 1000
|
|
1389
|
-
})
|
|
1390
|
-
.withWaitStrategy(Wait.forHealthCheck())
|
|
1391
|
-
.withStartupTimeout(120_000)
|
|
1392
|
-
.start();
|
|
1393
|
-
|
|
1394
|
-
const databaseUrl = \`postgresql://\${POSTGRES_USER}:\${POSTGRES_PASSWORD}@\${container.getHost()}:\${container.getMappedPort(POSTGRES_PORT)}/\${POSTGRES_DB}\`;
|
|
1395
|
-
${migrations}
|
|
1396
|
-
project.provide('databaseUrl', databaseUrl);
|
|
1397
|
-
|
|
1398
|
-
return async () => {
|
|
1399
|
-
await container.stop();
|
|
1400
|
-
};
|
|
1401
|
-
}
|
|
1402
|
-
`;
|
|
1403
|
-
};
|
|
1404
|
-
const testcontainersSetupEnv = `import 'dotenv/config';
|
|
1405
|
-
import { inject } from 'vitest';
|
|
1406
|
-
|
|
1407
|
-
// Runs before each spec's imports: development implementations get the .env
|
|
1408
|
-
// config, and DATABASE_URL points to the container instead of the one from .env.
|
|
1409
|
-
if (process.env.NODE_ENV !== 'development') {
|
|
1410
|
-
throw new Error(
|
|
1411
|
-
\`Integration specs need NODE_ENV=development to wire development implementations, got "\${process.env.NODE_ENV}"\`
|
|
1412
|
-
);
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
process.env.DATABASE_URL = inject('databaseUrl');
|
|
1416
|
-
`;
|
|
1417
|
-
const testcontainers_exampleSpec = `import { expect, inject, test } from 'vitest';
|
|
1418
|
-
|
|
1419
|
-
test('connects to the database in the container', () => {
|
|
1420
|
-
expect(process.env.DATABASE_URL).toBe(inject('databaseUrl'));
|
|
1421
|
-
});
|
|
1422
|
-
`;
|
|
1423
|
-
const excludeFromUnitTests = (content)=>{
|
|
1424
|
-
const exclude = /(exclude:\s*\[\s*\.\.\.configDefaults\.exclude\b[^\]]*?)(,?)(\s*)\]/;
|
|
1425
|
-
if (!exclude.test(content)) return;
|
|
1426
|
-
const entry = `'${integrationFolder}/**'`;
|
|
1427
|
-
return content.replace(exclude, (_, items, comma, whitespace)=>{
|
|
1428
|
-
const indent = whitespace.includes('\n') ? /\n([ \t]*)[^\n]*$/.exec(items)?.[1] : void 0;
|
|
1429
|
-
const separator = void 0 === indent ? ', ' : `,\n${indent}`;
|
|
1430
|
-
return `${items}${separator}${entry}${comma}${whitespace}]`;
|
|
1431
|
-
}).replace('// Playwright runs end-to-end specs\n', '// Playwright runs end-to-end specs, test:integration runs integration ones\n');
|
|
1432
|
-
};
|
|
1433
|
-
const testcontainers_stageFile = (filePath, content)=>{
|
|
1434
|
-
const file = new File(filePath);
|
|
1435
|
-
if (!file.exists || file.data !== content) file.data = content;
|
|
1436
|
-
};
|
|
1437
|
-
const addTestcontainers = async ()=>{
|
|
1438
|
-
const config = ConfigFile.Instance.data;
|
|
1439
|
-
const root = new ProjectRoot().path;
|
|
1440
|
-
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
1441
|
-
const manifest = JSON.parse(manifestFile.data);
|
|
1442
|
-
const dependencies = {
|
|
1443
|
-
...manifest.dependencies,
|
|
1444
|
-
...manifest.devDependencies
|
|
1445
|
-
};
|
|
1446
|
-
const selected = await addPackageScripts(manifestFile, testcontainersScripts);
|
|
1447
|
-
const withPrisma = new File(external_node_path_default().resolve(root, config.rootFolder, 'shared/infrastructure/prisma/prisma.config.ts')).exists;
|
|
1448
|
-
const migrationCommand = withPrisma ? `npx ${prismaScripts(config.rootFolder)['prisma:migration:apply']}` : void 0;
|
|
1449
|
-
const folder = external_node_path_default().join(root, integrationFolder);
|
|
1450
|
-
testcontainers_stageFile(external_node_path_default().join(folder, 'vitest.config.ts'), testcontainersVitestConfig(Boolean(dependencies['@domain-first/handlers-next'])));
|
|
1451
|
-
testcontainers_stageFile(external_node_path_default().join(folder, 'global-setup.ts'), testcontainersGlobalSetup(migrationCommand));
|
|
1452
|
-
testcontainers_stageFile(external_node_path_default().join(folder, 'setup-env.ts'), testcontainersSetupEnv);
|
|
1453
|
-
const example = new File(external_node_path_default().join(folder, 'database/database.spec.ts'));
|
|
1454
|
-
if (!example.exists) example.data = testcontainers_exampleSpec;
|
|
1455
|
-
const unitConfig = new File(external_node_path_default().join(root, 'vitest.config.ts'));
|
|
1456
|
-
let excludedFromUnitTests = !unitConfig.exists || unitConfig.data.includes(integrationFolder);
|
|
1457
|
-
if (!excludedFromUnitTests) {
|
|
1458
|
-
const excluded = excludeFromUnitTests(unitConfig.data);
|
|
1459
|
-
if (excluded) {
|
|
1460
|
-
unitConfig.update(excluded);
|
|
1461
|
-
excludedFromUnitTests = true;
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
const missing = [
|
|
1465
|
-
'vitest',
|
|
1466
|
-
'testcontainers',
|
|
1467
|
-
'dotenv'
|
|
1468
|
-
].filter((name)=>!dependencies[name]);
|
|
1469
|
-
return [
|
|
1470
|
-
...missing.length ? [
|
|
1471
|
-
`npm install --save-dev ${missing.join(' ')}`
|
|
1472
|
-
] : [],
|
|
1473
|
-
`Integration specs run against postgres:15 and get its address in DATABASE_URL. Change the image, credentials and connection string in ${integrationFolder}/global-setup.ts, and the variable name in ${integrationFolder}/setup-env.ts.`,
|
|
1474
|
-
...migrationCommand ? [] : [
|
|
1475
|
-
`Apply your migrations in ${integrationFolder}/global-setup.ts.`
|
|
1476
|
-
],
|
|
1477
|
-
...excludedFromUnitTests ? [] : [
|
|
1478
|
-
`Add '${integrationFolder}/**' to test.exclude in vitest.config.ts, so unit tests skip integration specs.`
|
|
1479
|
-
],
|
|
1480
|
-
'Docker must be running for integration specs.',
|
|
1481
|
-
...describeScripts(selected, {
|
|
1482
|
-
'test:integration': `run integration specs from ${integrationFolder} against PostgreSQL in a container`
|
|
1483
|
-
})
|
|
1484
|
-
];
|
|
1485
|
-
};
|
|
1486
|
-
const vitestScripts = {
|
|
1487
|
-
test: 'vitest run --reporter=dot --silent=passed-only',
|
|
1488
|
-
'test:coverage': 'vitest run --coverage --reporter=dot --silent=passed-only'
|
|
1489
|
-
};
|
|
1490
|
-
const vitestConfig = (rootFolder, inlineHandlersNext)=>{
|
|
1491
|
-
const folder = (subpath)=>JSON.stringify(external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), subpath));
|
|
1492
|
-
const server = inlineHandlersNext ? `,
|
|
1493
|
-
server: {
|
|
1494
|
-
deps: {
|
|
1495
|
-
// Imports \`next/headers\` without an extension, which only a bundler can resolve
|
|
1496
|
-
inline: ['@domain-first/handlers-next']
|
|
1497
|
-
}
|
|
1498
|
-
}` : '';
|
|
1499
|
-
return `import { configDefaults, defineConfig } from 'vitest/config';
|
|
1500
|
-
|
|
1501
|
-
export default defineConfig({
|
|
1502
|
-
resolve: {
|
|
1503
|
-
tsconfigPaths: true
|
|
1504
|
-
},
|
|
1505
|
-
test: {
|
|
1506
|
-
// Playwright runs end-to-end specs, test:integration runs integration ones
|
|
1507
|
-
exclude: [...configDefaults.exclude, 'specs/e2e/**', 'specs/integration/**'],
|
|
1508
|
-
coverage: {
|
|
1509
|
-
provider: 'v8',
|
|
1510
|
-
include: [${folder('bounded-contexts/**/*.ts')}, ${folder('shared/**/*.ts')}],
|
|
1511
|
-
exclude: [
|
|
1512
|
-
'**/*.spec.ts',
|
|
1513
|
-
${folder('shared/infrastructure/**')},
|
|
1514
|
-
${folder('bounded-contexts/*/infrastructure/**')},
|
|
1515
|
-
${folder('bounded-contexts/*/presentation/rest/**')},
|
|
1516
|
-
${folder('shared/wiring/**')},
|
|
1517
|
-
${folder('bounded-contexts/*/wiring/**')}
|
|
1518
|
-
],
|
|
1519
|
-
reporter: [['text', { skipFull: true }], 'html']
|
|
1520
|
-
}${server}
|
|
1521
|
-
}
|
|
1522
|
-
});
|
|
1523
|
-
`;
|
|
1524
|
-
};
|
|
1525
|
-
const addVitest = async ()=>{
|
|
1526
|
-
const config = ConfigFile.Instance.data;
|
|
1527
|
-
if (config.testingLibrary && 'vitest' !== config.testingLibrary && !await (0, prompts_namespaceObject.confirm)({
|
|
1528
|
-
message: `Replace testing library "${config.testingLibrary}" with vitest for generated tests?`,
|
|
1529
|
-
default: false
|
|
1530
|
-
})) return [];
|
|
1531
|
-
const root = new ProjectRoot().path;
|
|
1532
|
-
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
1533
|
-
const manifest = JSON.parse(manifestFile.data);
|
|
1534
|
-
const dependencies = {
|
|
1535
|
-
...manifest.dependencies,
|
|
1536
|
-
...manifest.devDependencies
|
|
1537
|
-
};
|
|
1538
|
-
const selected = await addPackageScripts(manifestFile, vitestScripts);
|
|
1539
|
-
const configFile = new File(external_node_path_default().join(root, 'vitest.config.ts'));
|
|
1540
|
-
const content = vitestConfig(config.rootFolder, Boolean(dependencies['@domain-first/handlers-next']));
|
|
1541
|
-
if (!configFile.exists || configFile.data !== content) configFile.data = content;
|
|
1542
|
-
if ('vitest' !== config.testingLibrary) ConfigFile.write({
|
|
1543
|
-
...config,
|
|
1544
|
-
testingLibrary: 'vitest'
|
|
1545
|
-
});
|
|
1546
|
-
addGitignoreEntry(root, '/coverage/');
|
|
1547
|
-
const missing = [
|
|
1548
|
-
'vitest',
|
|
1549
|
-
'@vitest/coverage-v8'
|
|
1550
|
-
].filter((name)=>!dependencies[name]);
|
|
1551
|
-
return [
|
|
1552
|
-
...missing.length ? [
|
|
1553
|
-
`npm install --save-dev ${missing.join(' ')}`
|
|
1554
|
-
] : [],
|
|
1555
|
-
...describeScripts(selected, {
|
|
1556
|
-
test: 'run unit tests',
|
|
1557
|
-
'test:coverage': 'run unit tests with a V8 coverage report in coverage/'
|
|
1558
|
-
})
|
|
1559
|
-
];
|
|
1560
|
-
};
|
|
1561
|
-
const withHandlersRest = ()=>ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers-rest');
|
|
1562
|
-
const integrations = [
|
|
1563
|
-
{
|
|
1564
|
-
name: 'Storybook (React + Vite)',
|
|
1565
|
-
run: addStorybook
|
|
1566
|
-
},
|
|
1567
|
-
{
|
|
1568
|
-
name: 'Prisma 8 (PostgreSQL, RC)',
|
|
1569
|
-
run: addPrisma
|
|
1570
|
-
},
|
|
1571
|
-
{
|
|
1572
|
-
name: 'Vitest',
|
|
1573
|
-
run: addVitest
|
|
1574
|
-
},
|
|
1575
|
-
{
|
|
1576
|
-
name: 'Playwright',
|
|
1577
|
-
run: addPlaywright
|
|
1578
|
-
},
|
|
1579
|
-
{
|
|
1580
|
-
name: 'Integration tests (Testcontainers, PostgreSQL)',
|
|
1581
|
-
run: addTestcontainers
|
|
1582
|
-
},
|
|
1583
|
-
{
|
|
1584
|
-
name: 'OpenAPI',
|
|
1585
|
-
run: addOpenapi,
|
|
1586
|
-
available: ()=>withHandlersRest()
|
|
1587
|
-
},
|
|
1588
|
-
{
|
|
1589
|
-
name: 'Orval (React Query client)',
|
|
1590
|
-
run: addOrval,
|
|
1591
|
-
available: ()=>withHandlersRest() && ConfigFile.Instance.data.useReact
|
|
1592
|
-
},
|
|
1593
|
-
{
|
|
1594
|
-
name: 'Missing domain-first packages',
|
|
1595
|
-
run: missingDomainFirstPackages
|
|
1596
|
-
}
|
|
1597
|
-
];
|
|
1598
|
-
const addIntegration = async ()=>{
|
|
1599
|
-
const integration = await (0, prompts_namespaceObject.select)({
|
|
1600
|
-
message: 'Integration:',
|
|
1601
|
-
choices: integrations.filter(({ available })=>available?.() ?? true).map((value)=>({
|
|
1602
|
-
name: value.name,
|
|
1603
|
-
value
|
|
1604
|
-
}))
|
|
1605
|
-
});
|
|
1606
|
-
const nextSteps = await integration.run();
|
|
1607
|
-
if (await savePendingChanges()) printNextSteps(nextSteps);
|
|
468
|
+
]).createFile(`${fileName}-page.tsx`, scaffold_react_page_reactPageContent(ClassName));
|
|
1608
469
|
};
|
|
1609
470
|
const wiring_layers = [
|
|
1610
471
|
'domain',
|
|
@@ -1686,7 +547,7 @@ const wiredClassNames = (source, wireName, initializerStart, branched)=>{
|
|
|
1686
547
|
const readWiredModule = (wireFile, contextPath)=>{
|
|
1687
548
|
const wiringRelativePath = external_node_path_default().relative(external_node_path_default().join(contextPath, 'wiring'), wireFile);
|
|
1688
549
|
if (isEndpointWire(wiringRelativePath)) return;
|
|
1689
|
-
const source = new
|
|
550
|
+
const source = new file_system_File(wireFile).data;
|
|
1690
551
|
const wireName = `wire${new UnknownFormatNaming(external_node_path_default().basename(wireFile, '.ts').replace(/^wire-/, '')).ClassName}`;
|
|
1691
552
|
const exportMatch = new RegExp(`export\\s+const\\s+${wireName}\\s*=\\s*`).exec(source);
|
|
1692
553
|
if (!exportMatch) return;
|
|
@@ -1749,7 +610,7 @@ const canDependOn = (consumer, candidate, rules = defaultDependencyRules)=>{
|
|
|
1749
610
|
return consumerKind && candidateKind ? rules[consumerKind].has(candidateKind) : layerRule(consumer, candidate);
|
|
1750
611
|
};
|
|
1751
612
|
const availableDependencies = (consumer, implementation, candidates, rules = configuredDependencyRules())=>{
|
|
1752
|
-
const wired = wiredDependencyNames(new
|
|
613
|
+
const wired = wiredDependencyNames(new file_system_File(consumer.wireFile).data, implementation.className);
|
|
1753
614
|
return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate, rules) && !wired.includes(candidate.wireName));
|
|
1754
615
|
};
|
|
1755
616
|
const relativeImport = (fromFile, toFile)=>{
|
|
@@ -1904,11 +765,11 @@ const addWireDependencies = (source, className, wireNames)=>{
|
|
|
1904
765
|
};
|
|
1905
766
|
const parameterName = (typeName)=>typeName.substring(0, 1).toLowerCase() + typeName.substring(1);
|
|
1906
767
|
const wireDependencies = (consumer, implementation, dependencies)=>{
|
|
1907
|
-
const wireFile = new
|
|
768
|
+
const wireFile = new file_system_File(consumer.wireFile);
|
|
1908
769
|
let wireSource = wireFile.data;
|
|
1909
770
|
for (const dependency of dependencies)wireSource = addImport(wireSource, `import { ${dependency.wireName} } from '${relativeImport(consumer.wireFile, dependency.wireFile)}'`);
|
|
1910
771
|
wireFile.update(addWireDependencies(wireSource, implementation.className, dependencies.map((x)=>x.wireName)));
|
|
1911
|
-
const classFile = new
|
|
772
|
+
const classFile = new file_system_File(implementation.file);
|
|
1912
773
|
let classSource = classFile.data;
|
|
1913
774
|
for (const dependency of dependencies)classSource = addImport(classSource, `import type { ${dependency.typeName} } from '${relativeImport(implementation.file, dependency.typeFile)}'`);
|
|
1914
775
|
classFile.update(addConstructorParameters(classSource, implementation.className, dependencies.map((x)=>`private readonly ${parameterName(x.typeName)}: ${x.typeName}`)));
|
|
@@ -2049,23 +910,23 @@ describe('in memory db', () => {
|
|
|
2049
910
|
})
|
|
2050
911
|
})
|
|
2051
912
|
`.trim();
|
|
2052
|
-
const in_memory_db_withWiring = ()=>
|
|
2053
|
-
const in_memory_db_sharedFolder = ()=>new
|
|
2054
|
-
|
|
913
|
+
const in_memory_db_withWiring = ()=>config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
914
|
+
const in_memory_db_sharedFolder = ()=>new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
915
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
2055
916
|
'shared'
|
|
2056
917
|
]);
|
|
2057
|
-
const serviceFile = ()=>new
|
|
918
|
+
const serviceFile = ()=>new file_system_File(in_memory_db_sharedFolder().path).subitem([
|
|
2058
919
|
'infrastructure',
|
|
2059
920
|
'services',
|
|
2060
921
|
'in-memory-db-infrastructure-service.ts'
|
|
2061
922
|
]);
|
|
2062
|
-
const in_memory_db_wireFile = ()=>new
|
|
923
|
+
const in_memory_db_wireFile = ()=>new file_system_File(in_memory_db_sharedFolder().path).subitem([
|
|
2063
924
|
'wiring',
|
|
2064
925
|
'infrastructure-services',
|
|
2065
926
|
'wire-in-memory-db-infrastructure-service.ts'
|
|
2066
927
|
]);
|
|
2067
928
|
const scaffoldInMemoryDb = (shared)=>{
|
|
2068
|
-
const { testingLibrary } =
|
|
929
|
+
const { testingLibrary } = config_file_ConfigFile.Instance.data;
|
|
2069
930
|
const servicesFolder = shared.subitem([
|
|
2070
931
|
'infrastructure',
|
|
2071
932
|
'services'
|
|
@@ -2077,7 +938,7 @@ const scaffoldInMemoryDb = (shared)=>{
|
|
|
2077
938
|
'infrastructure-services'
|
|
2078
939
|
]).createFile('wire-in-memory-db-infrastructure-service.ts', inMemoryDbWiring);
|
|
2079
940
|
};
|
|
2080
|
-
const usesInMemoryDb = (implementationType)=>Boolean(
|
|
941
|
+
const usesInMemoryDb = (implementationType)=>Boolean(config_file_ConfigFile.Instance.data.withInMemoryDb) && new UnknownFormatNaming(implementationType).fileName === inMemoryImplementationType && serviceFile().exists && (!in_memory_db_withWiring() || in_memory_db_wireFile().exists);
|
|
2081
942
|
const plural = (word)=>{
|
|
2082
943
|
if (/[^aeiou]y$/i.test(word)) return `${word.slice(0, -1)}ies`;
|
|
2083
944
|
if (/(s|x|z|ch|sh)$/i.test(word)) return `${word}es`;
|
|
@@ -2159,8 +1020,8 @@ const groupedChoices = (items, suggested = [])=>{
|
|
|
2159
1020
|
};
|
|
2160
1021
|
const groupedPageSize = 20;
|
|
2161
1022
|
const contextAndSharedModules = (boundedContextFolder)=>{
|
|
2162
|
-
const sharedFolder = new
|
|
2163
|
-
|
|
1023
|
+
const sharedFolder = new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
1024
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
2164
1025
|
'shared'
|
|
2165
1026
|
]);
|
|
2166
1027
|
const isShared = sharedFolder.path === boundedContextFolder.path;
|
|
@@ -2239,8 +1100,8 @@ const promptEndpointHandler = async (boundedContextFolder)=>{
|
|
|
2239
1100
|
const createPresentationService = (boundedContextFolder, name, classFile)=>{
|
|
2240
1101
|
const naming = new UnknownFormatNaming(name);
|
|
2241
1102
|
const className = `${naming.ClassName}PresentationService`;
|
|
2242
|
-
const scaffoldUnitTests = Boolean(
|
|
2243
|
-
const withWiring =
|
|
1103
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
1104
|
+
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2244
1105
|
const wiringFolder = boundedContextFolder.subitem([
|
|
2245
1106
|
'wiring',
|
|
2246
1107
|
'presentation-services'
|
|
@@ -2255,7 +1116,7 @@ export class ${className} {
|
|
|
2255
1116
|
}
|
|
2256
1117
|
`.trim());
|
|
2257
1118
|
if (scaffoldUnitTests) presentationServicesFolder.createFile(`${naming.fileName}-presentation-service.spec.ts`, `
|
|
2258
|
-
import { describe, test, expect, beforeEach } from '${
|
|
1119
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
2259
1120
|
${withWiring ? `import { type ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'
|
|
2260
1121
|
import { wire${naming.ClassName}PresentationService } from '../../wiring/presentation-services/wire-${naming.fileName}-presentation-service'` : `import { ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'`}
|
|
2261
1122
|
|
|
@@ -2314,7 +1175,7 @@ export class ${className} {
|
|
|
2314
1175
|
});
|
|
2315
1176
|
const findRestEndpointGenerator = (sharedFolder)=>{
|
|
2316
1177
|
const typeFile = external_node_path_default().join(sharedFolder.path, 'presentation', 'services', `${rest_endpoint_generator_name}-presentation-service.ts`);
|
|
2317
|
-
if (!new
|
|
1178
|
+
if (!new file_system_File(typeFile).exists) return;
|
|
2318
1179
|
return {
|
|
2319
1180
|
typeName: 'RestEndpointGeneratorPresentationService',
|
|
2320
1181
|
typeFile,
|
|
@@ -2323,7 +1184,7 @@ const findRestEndpointGenerator = (sharedFolder)=>{
|
|
|
2323
1184
|
};
|
|
2324
1185
|
};
|
|
2325
1186
|
const hasDependency = (root, name)=>{
|
|
2326
|
-
const manifestFile = new
|
|
1187
|
+
const manifestFile = new file_system_File(external_node_path_default().join(root, 'package.json'));
|
|
2327
1188
|
if (!manifestFile.exists) return false;
|
|
2328
1189
|
const manifest = JSON.parse(manifestFile.data);
|
|
2329
1190
|
return [
|
|
@@ -2348,7 +1209,7 @@ const initializeUseCase = async ()=>{
|
|
|
2348
1209
|
'@domain-first/handlers-rest'
|
|
2349
1210
|
]
|
|
2350
1211
|
});
|
|
2351
|
-
const withNextAdapter = domainFirstPackages.includes('@domain-first/handlers-rest') && hasDependency(new
|
|
1212
|
+
const withNextAdapter = domainFirstPackages.includes('@domain-first/handlers-rest') && hasDependency(new project_root_ProjectRoot().path, 'next') && await (0, prompts_namespaceObject.confirm)({
|
|
2352
1213
|
message: 'Use Next adapter for REST endpoints'
|
|
2353
1214
|
});
|
|
2354
1215
|
const defaultPersistenceLayerImplementation = await (0, prompts_namespaceObject.input)({
|
|
@@ -2376,7 +1237,7 @@ const initializeUseCase = async ()=>{
|
|
|
2376
1237
|
message: 'Unit testing library:',
|
|
2377
1238
|
default: 'vitest'
|
|
2378
1239
|
});
|
|
2379
|
-
|
|
1240
|
+
config_file_ConfigFile.write({
|
|
2380
1241
|
rootFolder: rootFolderName,
|
|
2381
1242
|
domainFirstPackages,
|
|
2382
1243
|
defaultPersistenceLayerImplementation,
|
|
@@ -2385,8 +1246,8 @@ const initializeUseCase = async ()=>{
|
|
|
2385
1246
|
storybookFramework,
|
|
2386
1247
|
testingLibrary
|
|
2387
1248
|
});
|
|
2388
|
-
const { path } = new
|
|
2389
|
-
const rootFolder = new
|
|
1249
|
+
const { path } = new project_root_ProjectRoot();
|
|
1250
|
+
const rootFolder = new file_system_Folder(path);
|
|
2390
1251
|
if (domainFirstPackages.includes('@domain-first/wire')) rootFolder.subitem([
|
|
2391
1252
|
rootFolderName,
|
|
2392
1253
|
'shared',
|
|
@@ -2607,16 +1468,16 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2607
1468
|
const renamed = rewritten.replace(classPattern, (_, use = '')=>`${use}${newClassName}`);
|
|
2608
1469
|
return moves.has(oldFile) && 'widget' === module.kind ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
2609
1470
|
};
|
|
2610
|
-
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new
|
|
1471
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile, reactFolder);
|
|
2611
1472
|
const updated = [];
|
|
2612
1473
|
for (const [file, content] of codeFiles){
|
|
2613
1474
|
const newFile = moves.get(file);
|
|
2614
1475
|
const next = rewrite(content, file, newFile ?? file);
|
|
2615
1476
|
if (newFile && newFile !== file) {
|
|
2616
|
-
new
|
|
2617
|
-
new
|
|
1477
|
+
new file_system_File(newFile).data = next;
|
|
1478
|
+
new file_system_File(file).delete(reactFolder);
|
|
2618
1479
|
} else if (next !== content) {
|
|
2619
|
-
new
|
|
1480
|
+
new file_system_File(file).update(next);
|
|
2620
1481
|
if (!newFile) updated.push(file);
|
|
2621
1482
|
}
|
|
2622
1483
|
}
|
|
@@ -2630,7 +1491,7 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2630
1491
|
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
2631
1492
|
const reactFolder = presentationReactFolder.path;
|
|
2632
1493
|
const modules = findReactModules(reactFolder, kind);
|
|
2633
|
-
if (!modules.length) return void console.log(`No ${kind}s generated by df-
|
|
1494
|
+
if (!modules.length) return void console.log(`No ${kind}s generated by df-scaffold were found.`);
|
|
2634
1495
|
const module = await (0, prompts_namespaceObject.select)({
|
|
2635
1496
|
message: 'page' === kind ? 'Page:' : 'Widget:',
|
|
2636
1497
|
choices: modules.map((value)=>({
|
|
@@ -2644,7 +1505,7 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
2644
1505
|
default: module.name,
|
|
2645
1506
|
validate: (value)=>validateMove(reactFolder, module, value)
|
|
2646
1507
|
});
|
|
2647
|
-
const root = new
|
|
1508
|
+
const root = new project_root_ProjectRoot().path;
|
|
2648
1509
|
const { moves, updated } = moveReactModule(root, reactFolder, module, name);
|
|
2649
1510
|
if (!moves.length && !updated.length) return void console.log('Nothing to change.');
|
|
2650
1511
|
const relative = (file)=>external_node_path_default().relative(root, file);
|
|
@@ -2669,7 +1530,7 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
|
2669
1530
|
message: 'Aggregate name:'
|
|
2670
1531
|
});
|
|
2671
1532
|
const aggregateNaming = new UnknownFormatNaming(aggregateName);
|
|
2672
|
-
const scaffoldUnitTests = Boolean(
|
|
1533
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
2673
1534
|
const withRepository = await (0, prompts_namespaceObject.confirm)({
|
|
2674
1535
|
message: 'With Repository'
|
|
2675
1536
|
});
|
|
@@ -2678,7 +1539,7 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
|
2678
1539
|
'aggregates',
|
|
2679
1540
|
aggregateName
|
|
2680
1541
|
]);
|
|
2681
|
-
const withTypes =
|
|
1542
|
+
const withTypes = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types');
|
|
2682
1543
|
aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.ts`, withTypes ? `
|
|
2683
1544
|
import { domainType } from '@domain-first/types'
|
|
2684
1545
|
|
|
@@ -2687,7 +1548,7 @@ export class ${aggregateNaming.ClassName} extends domainType() {
|
|
|
2687
1548
|
}`.trim() : `export class ${aggregateNaming.ClassName} {}`);
|
|
2688
1549
|
const barrelFile = aggregatesFolder.createFile("index.ts", `export * from './${aggregateNaming.fileName}.aggregate-root'`);
|
|
2689
1550
|
if (scaffoldUnitTests) aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.spec.ts`, `
|
|
2690
|
-
import { describe, test, expect, beforeEach } from '${
|
|
1551
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
2691
1552
|
import { ${aggregateNaming.ClassName} } from './${aggregateNaming.fileName}.aggregate-root'
|
|
2692
1553
|
|
|
2693
1554
|
let ${aggregateNaming.variableName}: ${aggregateNaming.ClassName}
|
|
@@ -2707,7 +1568,7 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
2707
1568
|
barrelFile.addLine(`export * from './${aggregateNaming.fileName}-repository'`);
|
|
2708
1569
|
const infrastructureImplementationType = await (0, prompts_namespaceObject.input)({
|
|
2709
1570
|
message: 'Repository infrastructure implementation type:',
|
|
2710
|
-
default:
|
|
1571
|
+
default: config_file_ConfigFile.Instance.data.defaultPersistenceLayerImplementation
|
|
2711
1572
|
});
|
|
2712
1573
|
let addTestImplementation = false;
|
|
2713
1574
|
let testImplementationType = '';
|
|
@@ -2732,7 +1593,7 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
2732
1593
|
naming.fileName
|
|
2733
1594
|
]);
|
|
2734
1595
|
const repositoryFileName = `${naming.fileName}-${aggregateName}-repository.ts`;
|
|
2735
|
-
if (usesInMemoryDb(implementation) && !
|
|
1596
|
+
if (usesInMemoryDb(implementation) && !config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2736
1597
|
const section = addInMemoryDbSection(aggregateNaming, aggregatesFolder.path);
|
|
2737
1598
|
repositoryFolder.createFile(repositoryFileName, `
|
|
2738
1599
|
${inMemoryDbTypeImport(repositoryFolder.subitem([
|
|
@@ -2758,8 +1619,8 @@ export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implement
|
|
|
2758
1619
|
if (scaffoldUnitTests) {
|
|
2759
1620
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
2760
1621
|
const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
|
|
2761
|
-
import { describe, test, expect, beforeEach } from '${
|
|
2762
|
-
${
|
|
1622
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
1623
|
+
${config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
|
|
2763
1624
|
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'
|
|
2764
1625
|
|
|
2765
1626
|
type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`}
|
|
@@ -2767,18 +1628,18 @@ type ${aggregateNaming.ClassName}Repository = ${implementationNaming.ClassName}$
|
|
|
2767
1628
|
let ${aggregateNaming.variableName}Repository: ${aggregateNaming.ClassName}Repository
|
|
2768
1629
|
|
|
2769
1630
|
beforeEach(() => {
|
|
2770
|
-
${aggregateNaming.variableName}Repository = ${
|
|
1631
|
+
${aggregateNaming.variableName}Repository = ${config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? `wire${aggregateNaming.ClassName}Repository()` : `new ${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository()`}
|
|
2771
1632
|
})
|
|
2772
1633
|
|
|
2773
1634
|
describe('${aggregateNaming.withSpaces} repository', () => {
|
|
2774
|
-
test('can be ${
|
|
1635
|
+
test('can be ${config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
|
|
2775
1636
|
expect(${aggregateNaming.variableName}Repository).toBeDefined()
|
|
2776
1637
|
})
|
|
2777
1638
|
})
|
|
2778
1639
|
`.trim());
|
|
2779
|
-
if (!
|
|
1640
|
+
if (!config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
|
|
2780
1641
|
}
|
|
2781
|
-
if (
|
|
1642
|
+
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2782
1643
|
const implementationNaming = new UnknownFormatNaming(infrastructureImplementationType);
|
|
2783
1644
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
2784
1645
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -2799,7 +1660,7 @@ export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
|
|
|
2799
1660
|
`.trim());
|
|
2800
1661
|
await wireNewModuleDependencies(boundedContextFolder, wireFile, (implementation, dependency)=>{
|
|
2801
1662
|
if (!isInMemoryDb(dependency)) return false;
|
|
2802
|
-
keepInMemoryDbSection(new
|
|
1663
|
+
keepInMemoryDbSection(new file_system_File(implementation.file), addInMemoryDbSection(aggregateNaming, aggregatesFolder.path));
|
|
2803
1664
|
wireInMemoryDb(wireFile, implementation.className);
|
|
2804
1665
|
return true;
|
|
2805
1666
|
});
|
|
@@ -2811,7 +1672,7 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
|
|
|
2811
1672
|
message: 'Name: '
|
|
2812
1673
|
});
|
|
2813
1674
|
const naming = new UnknownFormatNaming(name);
|
|
2814
|
-
const scaffoldUnitTests = Boolean(
|
|
1675
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
2815
1676
|
const wiringFolder = boundedContextFolder.subitem([
|
|
2816
1677
|
'wiring',
|
|
2817
1678
|
'application-ports'
|
|
@@ -2860,8 +1721,8 @@ export class ${currentNaming.ClassName} extends ${naming.ClassName} {
|
|
|
2860
1721
|
if (scaffoldUnitTests) {
|
|
2861
1722
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
2862
1723
|
applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
|
|
2863
|
-
import { describe, test, expect, beforeEach } from '${
|
|
2864
|
-
${
|
|
1724
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
1725
|
+
${config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? `import { type ${naming.ClassName} } from './${naming.fileName}'
|
|
2865
1726
|
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}'
|
|
2866
1727
|
|
|
2867
1728
|
type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`}
|
|
@@ -2869,17 +1730,17 @@ type ${naming.ClassName} = ${implementationNaming.ClassName}${naming.ClassName}`
|
|
|
2869
1730
|
let ${naming.variableName}: ${naming.ClassName}
|
|
2870
1731
|
|
|
2871
1732
|
beforeEach(() => {
|
|
2872
|
-
${naming.variableName} = ${
|
|
1733
|
+
${naming.variableName} = ${config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? `wire${naming.ClassName}()` : `new ${implementationNaming.ClassName}${naming.ClassName}()`}
|
|
2873
1734
|
})
|
|
2874
1735
|
|
|
2875
1736
|
describe('${naming.withSpaces}', () => {
|
|
2876
|
-
test('can be ${
|
|
1737
|
+
test('can be ${config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? 'wired' : 'created via constructor'}', () => {
|
|
2877
1738
|
expect(${naming.variableName}).toBeDefined()
|
|
2878
1739
|
})
|
|
2879
1740
|
})
|
|
2880
1741
|
`.trim());
|
|
2881
1742
|
}
|
|
2882
|
-
if (
|
|
1743
|
+
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2883
1744
|
const wireFile = wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
|
|
2884
1745
|
import { wireClass } from '@domain-first/wire'
|
|
2885
1746
|
import { envBranchedWire } from '../../../${'shared' === boundedContextFolder.name ? '' : '../'}shared/wiring/env-branched-wire'
|
|
@@ -2908,8 +1769,8 @@ const scaffoldNewApplicationService = async (boundedContextFolder)=>{
|
|
|
2908
1769
|
message: 'Name: '
|
|
2909
1770
|
});
|
|
2910
1771
|
const naming = new UnknownFormatNaming(name);
|
|
2911
|
-
const scaffoldUnitTests = Boolean(
|
|
2912
|
-
const withWiring =
|
|
1772
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
1773
|
+
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2913
1774
|
const wiringFolder = boundedContextFolder.subitem([
|
|
2914
1775
|
'wiring',
|
|
2915
1776
|
'application-services'
|
|
@@ -2924,7 +1785,7 @@ export class ${naming.ClassName}ApplicationService {
|
|
|
2924
1785
|
}
|
|
2925
1786
|
`.trim());
|
|
2926
1787
|
if (scaffoldUnitTests) applicationServicesFolder.createFile(`${naming.fileName}-application-service.spec.ts`, `
|
|
2927
|
-
import { describe, test, expect, beforeEach } from '${
|
|
1788
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
2928
1789
|
${withWiring ? `import { type ${naming.ClassName}ApplicationService } from './${naming.fileName}-application-service'
|
|
2929
1790
|
import { wire${naming.ClassName}ApplicationService } from '../../wiring/application-services/wire-${naming.fileName}-application-service'` : `import { ${naming.ClassName}ApplicationService } from './${naming.fileName}-application-service'`}
|
|
2930
1791
|
|
|
@@ -2958,14 +1819,14 @@ const scaffoldNewBoundedContextUseCase = async ()=>{
|
|
|
2958
1819
|
message: 'Name:',
|
|
2959
1820
|
validate: (x)=>!!x.length
|
|
2960
1821
|
});
|
|
2961
|
-
const { path } = new
|
|
2962
|
-
const rootFolder = new
|
|
1822
|
+
const { path } = new project_root_ProjectRoot();
|
|
1823
|
+
const rootFolder = new file_system_Folder(path);
|
|
2963
1824
|
const folder = rootFolder.subitem([
|
|
2964
|
-
|
|
1825
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
2965
1826
|
'bounded-contexts',
|
|
2966
1827
|
name
|
|
2967
1828
|
]);
|
|
2968
|
-
if (
|
|
1829
|
+
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/errors')) folder.subitem([
|
|
2969
1830
|
'domain',
|
|
2970
1831
|
'errors'
|
|
2971
1832
|
]).createFile('index.ts', `
|
|
@@ -2987,12 +1848,12 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
2987
1848
|
const commandName = await (0, prompts_namespaceObject.input)({
|
|
2988
1849
|
message: 'Name: '
|
|
2989
1850
|
});
|
|
2990
|
-
const scaffoldUnitTests = Boolean(
|
|
1851
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
2991
1852
|
const naming = new UnknownFormatNaming(commandName);
|
|
2992
|
-
const withWiring =
|
|
1853
|
+
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2993
1854
|
const implementationType = await (0, prompts_namespaceObject.input)({
|
|
2994
1855
|
message: 'Command infrastructure implementation type:',
|
|
2995
|
-
default:
|
|
1856
|
+
default: config_file_ConfigFile.Instance.data.defaultPersistenceLayerImplementation
|
|
2996
1857
|
});
|
|
2997
1858
|
let addTestImplementation = false;
|
|
2998
1859
|
let testImplementationType = '';
|
|
@@ -3011,7 +1872,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
3011
1872
|
const formatNaming = new UnknownFormatNaming(implementation);
|
|
3012
1873
|
const implementationFile = infrastructureFolder.subitem([
|
|
3013
1874
|
formatNaming.fileName
|
|
3014
|
-
]).createFile(`${formatNaming.fileName}-${naming.fileName}-command.ts`,
|
|
1875
|
+
]).createFile(`${formatNaming.fileName}-${naming.fileName}-command.ts`, config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
3015
1876
|
import { defineHandler } from '@domain-first/handlers'
|
|
3016
1877
|
import { ${naming.ClassName}Command } from '../../../application/commands/${naming.fileName}-command'
|
|
3017
1878
|
|
|
@@ -3039,7 +1900,7 @@ export class ${formatNaming.ClassName}${naming.ClassName}Command extends ${namin
|
|
|
3039
1900
|
`.trim());
|
|
3040
1901
|
if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Command`);
|
|
3041
1902
|
}
|
|
3042
|
-
if (
|
|
1903
|
+
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) commandsFolder.createFile(`${naming.fileName}-command.ts`, `
|
|
3043
1904
|
import type { Handler } from '@domain-first/handlers'
|
|
3044
1905
|
|
|
3045
1906
|
export abstract class ${naming.ClassName}Command {
|
|
@@ -3056,7 +1917,7 @@ export abstract class ${naming.ClassName}Command {
|
|
|
3056
1917
|
if (scaffoldUnitTests) {
|
|
3057
1918
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3058
1919
|
const specFile = commandsFolder.createFile(`${naming.fileName}-command.spec.ts`, `
|
|
3059
|
-
import { describe, test, expect, beforeEach } from '${
|
|
1920
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
3060
1921
|
${withWiring ? `import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
|
|
3061
1922
|
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'
|
|
3062
1923
|
|
|
@@ -3076,7 +1937,7 @@ describe('${naming.withSpaces} command', () => {
|
|
|
3076
1937
|
`.trim());
|
|
3077
1938
|
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
|
|
3078
1939
|
}
|
|
3079
|
-
if (
|
|
1940
|
+
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3080
1941
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3081
1942
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
3082
1943
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -3125,7 +1986,7 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
|
3125
1986
|
kindFolderName
|
|
3126
1987
|
]);
|
|
3127
1988
|
const fileName = `${naming.fileName}.${kind}`;
|
|
3128
|
-
const withTypes =
|
|
1989
|
+
const withTypes = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types');
|
|
3129
1990
|
folder.createFile(`${fileName}.ts`, withTypes ? `
|
|
3130
1991
|
import { domainType } from '@domain-first/types'
|
|
3131
1992
|
|
|
@@ -3135,7 +1996,7 @@ export class ${naming.ClassName} extends domainType() {
|
|
|
3135
1996
|
if (aggregate !== noAggregate) aggregatesFolder.subitem([
|
|
3136
1997
|
aggregate
|
|
3137
1998
|
]).file('index.ts').addLineIfMissing(`export * from './${kindFolderName}/${fileName}'`);
|
|
3138
|
-
const { testingLibrary } =
|
|
1999
|
+
const { testingLibrary } = config_file_ConfigFile.Instance.data;
|
|
3139
2000
|
if (testingLibrary) folder.createFile(`${fileName}.spec.ts`, `
|
|
3140
2001
|
import { describe, test, expect, beforeEach } from '${testingLibrary}'
|
|
3141
2002
|
import { ${naming.ClassName} } from './${fileName}'
|
|
@@ -3158,8 +2019,8 @@ const scaffoldNewDomainService = async (boundedContextFolder)=>{
|
|
|
3158
2019
|
message: 'Name:'
|
|
3159
2020
|
});
|
|
3160
2021
|
const naming = new UnknownFormatNaming(portName);
|
|
3161
|
-
const scaffoldUnitTests = Boolean(
|
|
3162
|
-
const withWiring =
|
|
2022
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
2023
|
+
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
3163
2024
|
const domainServicesFolder = boundedContextFolder.subitem([
|
|
3164
2025
|
'domain',
|
|
3165
2026
|
'services'
|
|
@@ -3170,7 +2031,7 @@ export class ${naming.ClassName}DomainService {
|
|
|
3170
2031
|
}
|
|
3171
2032
|
`.trim());
|
|
3172
2033
|
if (scaffoldUnitTests) domainServicesFolder.createFile(`${naming.fileName}-domain-service.spec.ts`, `
|
|
3173
|
-
import { describe, test, expect, beforeEach } from '${
|
|
2034
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
3174
2035
|
${withWiring ? `import { type ${naming.ClassName}DomainService } from './${naming.fileName}-domain-service'
|
|
3175
2036
|
import { wire${naming.ClassName}DomainService } from '../../wiring/domain-services/wire-${naming.fileName}-domain-service'` : `import { ${naming.ClassName}DomainService } from './${naming.fileName}-domain-service'`}
|
|
3176
2037
|
|
|
@@ -3203,8 +2064,8 @@ export const wire${naming.ClassName}DomainService = wireClass(
|
|
|
3203
2064
|
}
|
|
3204
2065
|
};
|
|
3205
2066
|
const errorNames = (boundedContextFolder)=>{
|
|
3206
|
-
const isShared = boundedContextFolder.path === new
|
|
3207
|
-
|
|
2067
|
+
const isShared = boundedContextFolder.path === new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
2068
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
3208
2069
|
'shared'
|
|
3209
2070
|
]).path;
|
|
3210
2071
|
return {
|
|
@@ -3279,7 +2140,7 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
3279
2140
|
controller = await (0, prompts_namespaceObject.input)({
|
|
3280
2141
|
message: 'Name: '
|
|
3281
2142
|
});
|
|
3282
|
-
if (
|
|
2143
|
+
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3283
2144
|
boundedContextFolder.subitem([
|
|
3284
2145
|
'wiring',
|
|
3285
2146
|
'presentation',
|
|
@@ -3326,7 +2187,7 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
3326
2187
|
method,
|
|
3327
2188
|
'endpoint'
|
|
3328
2189
|
].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
|
|
3329
|
-
const withWiring =
|
|
2190
|
+
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
3330
2191
|
const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
|
|
3331
2192
|
'..',
|
|
3332
2193
|
'..',
|
|
@@ -3384,8 +2245,8 @@ const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
|
|
|
3384
2245
|
message: 'Name: '
|
|
3385
2246
|
});
|
|
3386
2247
|
const naming = new UnknownFormatNaming(name);
|
|
3387
|
-
const scaffoldUnitTests = Boolean(
|
|
3388
|
-
const withWiring =
|
|
2248
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
2249
|
+
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
3389
2250
|
const wiringFolder = boundedContextFolder.subitem([
|
|
3390
2251
|
'wiring',
|
|
3391
2252
|
'infrastructure-services'
|
|
@@ -3400,7 +2261,7 @@ export class ${naming.ClassName}InfrastructureService {
|
|
|
3400
2261
|
}
|
|
3401
2262
|
`.trim());
|
|
3402
2263
|
if (scaffoldUnitTests) infrastructureServicesFolder.createFile(`${naming.fileName}-infrastructure-service.spec.ts`, `
|
|
3403
|
-
import { describe, test, expect, beforeEach } from '${
|
|
2264
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
3404
2265
|
${withWiring ? `import { type ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'
|
|
3405
2266
|
import { wire${naming.ClassName}InfrastructureService } from '../../wiring/infrastructure-services/wire-${naming.fileName}-infrastructure-service'` : `import { ${naming.ClassName}InfrastructureService } from './${naming.fileName}-infrastructure-service'`}
|
|
3406
2267
|
|
|
@@ -3441,12 +2302,12 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
3441
2302
|
const queryName = await (0, prompts_namespaceObject.input)({
|
|
3442
2303
|
message: 'Name: '
|
|
3443
2304
|
});
|
|
3444
|
-
const scaffoldUnitTests = Boolean(
|
|
2305
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
3445
2306
|
const naming = new UnknownFormatNaming(queryName);
|
|
3446
|
-
const withWiring =
|
|
2307
|
+
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
3447
2308
|
const implementationType = await (0, prompts_namespaceObject.input)({
|
|
3448
2309
|
message: 'Query infrastructure implementation type:',
|
|
3449
|
-
default:
|
|
2310
|
+
default: config_file_ConfigFile.Instance.data.defaultPersistenceLayerImplementation
|
|
3450
2311
|
});
|
|
3451
2312
|
let addTestImplementation = false;
|
|
3452
2313
|
let testImplementationType = '';
|
|
@@ -3465,7 +2326,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
3465
2326
|
const formatNaming = new UnknownFormatNaming(implementation);
|
|
3466
2327
|
const implementationFile = infrastructureFolder.subitem([
|
|
3467
2328
|
formatNaming.fileName
|
|
3468
|
-
]).createFile(`${formatNaming.fileName}-${naming.fileName}-query.ts`,
|
|
2329
|
+
]).createFile(`${formatNaming.fileName}-${naming.fileName}-query.ts`, config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
3469
2330
|
import { defineHandler } from '@domain-first/handlers'
|
|
3470
2331
|
import { ${naming.ClassName}Query } from '../../../application/queries/${naming.fileName}-query'
|
|
3471
2332
|
|
|
@@ -3493,7 +2354,7 @@ export class ${formatNaming.ClassName}${naming.ClassName}Query extends ${naming.
|
|
|
3493
2354
|
`.trim());
|
|
3494
2355
|
if (!withWiring && usesInMemoryDb(implementation)) injectInMemoryDb(implementationFile, `${formatNaming.ClassName}${naming.ClassName}Query`);
|
|
3495
2356
|
}
|
|
3496
|
-
if (
|
|
2357
|
+
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers')) queriesFolder.createFile(`${naming.fileName}-query.ts`, `
|
|
3497
2358
|
import type { Handler } from '@domain-first/handlers'
|
|
3498
2359
|
|
|
3499
2360
|
export abstract class ${naming.ClassName}Query {
|
|
@@ -3510,7 +2371,7 @@ export abstract class ${naming.ClassName}Query {
|
|
|
3510
2371
|
if (scaffoldUnitTests) {
|
|
3511
2372
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3512
2373
|
const specFile = queriesFolder.createFile(`${naming.fileName}-query.spec.ts`, `
|
|
3513
|
-
import { describe, test, expect, beforeEach } from '${
|
|
2374
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
3514
2375
|
${withWiring ? `import { type ${naming.ClassName}Query } from './${naming.fileName}-query'
|
|
3515
2376
|
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'
|
|
3516
2377
|
|
|
@@ -3530,7 +2391,7 @@ describe('${naming.withSpaces} query', () => {
|
|
|
3530
2391
|
`.trim());
|
|
3531
2392
|
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
|
|
3532
2393
|
}
|
|
3533
|
-
if (
|
|
2394
|
+
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
3534
2395
|
const implementationNaming = new UnknownFormatNaming(implementationType);
|
|
3535
2396
|
const testImplementationNaming = new UnknownFormatNaming(testImplementationType);
|
|
3536
2397
|
const wireFile = boundedContextFolder.subitem([
|
|
@@ -3561,9 +2422,9 @@ const scaffoldNewUseCase = async (boundedContextFolder)=>{
|
|
|
3561
2422
|
message: 'Name: '
|
|
3562
2423
|
});
|
|
3563
2424
|
const naming = new UnknownFormatNaming(useCaseName);
|
|
3564
|
-
const scaffoldUnitTests = Boolean(
|
|
3565
|
-
const withWiring =
|
|
3566
|
-
useCasesFolder.createFile(`${naming.fileName}-use-case.ts`,
|
|
2425
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
2426
|
+
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2427
|
+
useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
3567
2428
|
import { defineHandler } from '@domain-first/handlers'
|
|
3568
2429
|
|
|
3569
2430
|
export class ${naming.ClassName}UseCase {
|
|
@@ -3586,7 +2447,7 @@ export class ${naming.ClassName}UseCase {
|
|
|
3586
2447
|
}
|
|
3587
2448
|
`.trim());
|
|
3588
2449
|
if (scaffoldUnitTests) useCasesFolder.createFile(`${naming.fileName}-use-case.spec.ts`, `
|
|
3589
|
-
import { describe, test, expect, beforeEach } from '${
|
|
2450
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
3590
2451
|
${withWiring ? `import { type ${naming.ClassName}UseCase } from './${naming.fileName}-use-case'
|
|
3591
2452
|
import { wire${naming.ClassName}UseCase } from '../../wiring/use-cases/wire-${naming.fileName}-use-case'` : `import { ${naming.ClassName}UseCase } from './${naming.fileName}-use-case'`}
|
|
3592
2453
|
|
|
@@ -3651,7 +2512,7 @@ export const ${ClassName}: FC<${ClassName}Props> = (props) => {
|
|
|
3651
2512
|
return <></>
|
|
3652
2513
|
}
|
|
3653
2514
|
`.trim());
|
|
3654
|
-
const { storybookFramework } =
|
|
2515
|
+
const { storybookFramework } = config_file_ConfigFile.Instance.data;
|
|
3655
2516
|
if (storybookFramework) componentFolder.createFile(`${fileName}.stories.tsx`, `
|
|
3656
2517
|
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
3657
2518
|
import { ${ClassName} } from './${fileName}'
|
|
@@ -3739,7 +2600,7 @@ export const ${ClassName}WidgetUI: FC<${ClassName}WidgetUIProps> = (props) => {
|
|
|
3739
2600
|
return <></>
|
|
3740
2601
|
}
|
|
3741
2602
|
`.trim());
|
|
3742
|
-
const { storybookFramework } =
|
|
2603
|
+
const { storybookFramework } = config_file_ConfigFile.Instance.data;
|
|
3743
2604
|
if (storybookFramework) folder.subitem([
|
|
3744
2605
|
'ui'
|
|
3745
2606
|
]).createFile(`${uiFileName}.stories.tsx`, `
|
|
@@ -3806,14 +2667,14 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
3806
2667
|
}
|
|
3807
2668
|
};
|
|
3808
2669
|
const main = async ()=>{
|
|
3809
|
-
if (!
|
|
2670
|
+
if (!config_file_ConfigFile.exists) {
|
|
3810
2671
|
const nextSteps = await initializeUseCase();
|
|
3811
|
-
if (await
|
|
2672
|
+
if (await save_pending_changes_savePendingChanges()) print_next_steps_printNextSteps(nextSteps);
|
|
3812
2673
|
return;
|
|
3813
2674
|
}
|
|
3814
|
-
const rootPath = new
|
|
3815
|
-
const currentBoundedContextOptions = new
|
|
3816
|
-
|
|
2675
|
+
const rootPath = new project_root_ProjectRoot().path;
|
|
2676
|
+
const currentBoundedContextOptions = new file_system_Folder(rootPath).subitem([
|
|
2677
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
3817
2678
|
'bounded-contexts'
|
|
3818
2679
|
]).content.subfolderNames.map((name)=>({
|
|
3819
2680
|
name: `Bounded Context: ${name}`,
|
|
@@ -3825,7 +2686,7 @@ const main = async ()=>{
|
|
|
3825
2686
|
};
|
|
3826
2687
|
const options = [
|
|
3827
2688
|
...currentBoundedContextOptions,
|
|
3828
|
-
|
|
2689
|
+
config_file_ConfigFile.Instance.data.useReact ? {
|
|
3829
2690
|
name: 'Scaffold React module',
|
|
3830
2691
|
action: 'Scaffold React module'
|
|
3831
2692
|
} : void 0,
|
|
@@ -3833,11 +2694,7 @@ const main = async ()=>{
|
|
|
3833
2694
|
name: 'Shared Layer',
|
|
3834
2695
|
action: 'Scaffold in bounded context'
|
|
3835
2696
|
},
|
|
3836
|
-
scaffoldNewBoundedContext
|
|
3837
|
-
{
|
|
3838
|
-
name: 'Add integration',
|
|
3839
|
-
action: 'Add integration'
|
|
3840
|
-
}
|
|
2697
|
+
scaffoldNewBoundedContext
|
|
3841
2698
|
].filter((x)=>!!x);
|
|
3842
2699
|
const result = await (0, prompts_namespaceObject.select)({
|
|
3843
2700
|
message: '@domain-first/project-structure',
|
|
@@ -3845,12 +2702,10 @@ const main = async ()=>{
|
|
|
3845
2702
|
});
|
|
3846
2703
|
const { action, name } = options.find((x)=>x.name === result);
|
|
3847
2704
|
switch(action){
|
|
3848
|
-
case 'Add integration':
|
|
3849
|
-
return void await addIntegration();
|
|
3850
2705
|
case 'Scaffold React module':
|
|
3851
2706
|
{
|
|
3852
|
-
const reactFolder = new
|
|
3853
|
-
|
|
2707
|
+
const reactFolder = new file_system_Folder(rootPath).subitem([
|
|
2708
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
3854
2709
|
'presentation',
|
|
3855
2710
|
'react'
|
|
3856
2711
|
]);
|
|
@@ -3887,12 +2742,12 @@ const main = async ()=>{
|
|
|
3887
2742
|
case 'Scaffold in bounded context':
|
|
3888
2743
|
{
|
|
3889
2744
|
const specificContext = name.startsWith('Bounded');
|
|
3890
|
-
const boundedContextFolder = new
|
|
3891
|
-
|
|
2745
|
+
const boundedContextFolder = new file_system_Folder(new project_root_ProjectRoot().path).subitem(specificContext ? [
|
|
2746
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
3892
2747
|
'bounded-contexts',
|
|
3893
2748
|
name.substring(17)
|
|
3894
2749
|
] : [
|
|
3895
|
-
|
|
2750
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
3896
2751
|
'shared'
|
|
3897
2752
|
]);
|
|
3898
2753
|
const layer = await (0, prompts_namespaceObject.select)({
|
|
@@ -3902,7 +2757,7 @@ const main = async ()=>{
|
|
|
3902
2757
|
'Application',
|
|
3903
2758
|
'Infrastructure',
|
|
3904
2759
|
'Presentation',
|
|
3905
|
-
|
|
2760
|
+
config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? 'Wire dependency' : void 0
|
|
3906
2761
|
].filter((x)=>!!x)
|
|
3907
2762
|
});
|
|
3908
2763
|
if ('Wire dependency' === layer) return void await wireDependency(boundedContextFolder);
|
|
@@ -3978,7 +2833,7 @@ const main = async ()=>{
|
|
|
3978
2833
|
const action = await (0, prompts_namespaceObject.select)({
|
|
3979
2834
|
message: 'Presentation layer operation:',
|
|
3980
2835
|
choices: specificContext ? [
|
|
3981
|
-
|
|
2836
|
+
config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers-rest') ? 'New Handlers-REST Endpoint' : void 0,
|
|
3982
2837
|
'New Service'
|
|
3983
2838
|
].filter((x)=>x) : [
|
|
3984
2839
|
'New Service'
|
|
@@ -3999,7 +2854,7 @@ const main = async ()=>{
|
|
|
3999
2854
|
};
|
|
4000
2855
|
const run = async ()=>{
|
|
4001
2856
|
await main();
|
|
4002
|
-
await
|
|
2857
|
+
await save_pending_changes_savePendingChanges();
|
|
4003
2858
|
};
|
|
4004
2859
|
run();
|
|
4005
2860
|
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|