@domain-first/project-structure 6.0.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -19
- package/dist/201.js +46 -35
- package/dist/287.js +1762 -1250
- package/dist/backend-module-move.d.ts +53 -0
- package/dist/backend-module-move.spec.d.ts +1 -0
- package/dist/config-file.d.ts +2 -2
- package/dist/dependency-rules.d.ts +1 -1
- package/dist/file-system.d.ts +5 -0
- package/dist/in-memory-db.d.ts +9 -0
- package/dist/index.cjs +534 -804
- package/dist/index.js +9 -47
- package/dist/init.cjs +913 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.js +36 -0
- package/dist/integration.cjs +457 -33
- package/dist/integration.js +4 -4
- package/dist/integrations/in-memory-db.d.ts +6 -0
- package/dist/integrations/index.d.ts +2 -0
- package/dist/integrations/missing-domain-first-packages.d.ts +8 -0
- package/dist/integrations/rest-endpoint-generator.d.ts +18 -0
- package/dist/integrations/rest-endpoint-generator.spec.d.ts +1 -0
- package/dist/lint.cjs +8 -8
- package/dist/lint.js +7 -7
- package/dist/module-move.d.ts +58 -0
- package/dist/print-next-steps.d.ts +2 -2
- package/dist/react-module-move.d.ts +2 -6
- package/dist/react.cjs +986 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +73 -0
- package/dist/use-cases/index.d.ts +1 -0
- package/dist/use-cases/move-backend-unit.d.ts +7 -0
- package/dist/use-cases/rest-endpoint-generator.d.ts +1 -1
- package/package.json +3 -1
- package/skills/df-ps-implement/SKILL.md +11 -56
- package/skills/df-ps-plan-feature/SKILL.md +6 -6
- package/skills/df-ps-project-scripts/SKILL.md +1 -1
- package/skills/df-ps-react/SKILL.md +82 -0
- package/skills/df-ps-react/references/generators.md +80 -0
- package/skills/df-ps-scaffold/SKILL.md +39 -20
- package/skills/df-ps-scaffold/references/choosing-components.md +7 -28
- package/skills/df-ps-scaffold/references/generators.md +6 -179
- package/skills/df-ps-scaffold/references/units/aggregate.md +47 -0
- package/skills/df-ps-scaffold/references/units/bounded-context.md +13 -0
- package/skills/df-ps-scaffold/references/units/command-query.md +32 -0
- package/skills/df-ps-scaffold/references/units/endpoint.md +28 -0
- package/skills/df-ps-scaffold/references/units/entity-value-object.md +27 -0
- package/skills/df-ps-scaffold/references/units/errors.md +26 -0
- package/skills/df-ps-scaffold/references/units/move-or-rename.md +21 -0
- package/skills/df-ps-scaffold/references/units/port.md +23 -0
- package/skills/df-ps-scaffold/references/units/services.md +28 -0
- package/skills/df-ps-scaffold/references/units/use-case.md +25 -0
- package/skills/df-ps-scaffold/references/units/wire-dependency.md +15 -0
- package/skills/df-ps-scaffold/scripts/drive.mjs +12 -4
package/dist/index.cjs
CHANGED
|
@@ -130,7 +130,7 @@ const pendingDeletions = new Map();
|
|
|
130
130
|
const filesToOverwrite = ()=>[
|
|
131
131
|
...pendingFiles
|
|
132
132
|
].filter(([filePath, { replacesFile }])=>replacesFile && external_node_fs_default().existsSync(filePath)).map(([filePath])=>filePath);
|
|
133
|
-
const
|
|
133
|
+
const file_system_discardPendingChanges = ()=>{
|
|
134
134
|
pendingFolders.clear();
|
|
135
135
|
pendingFiles.clear();
|
|
136
136
|
pendingMoves.clear();
|
|
@@ -164,7 +164,7 @@ const writePendingChanges = ()=>{
|
|
|
164
164
|
});
|
|
165
165
|
for (const [filePath, stopAt] of pendingDeletions)removeEmptyFolders(external_node_path_default().dirname(filePath), stopAt);
|
|
166
166
|
for (const { sourcePath, stopAt } of pendingMoves.values())removeEmptyFolders(external_node_path_default().dirname(sourcePath), stopAt);
|
|
167
|
-
|
|
167
|
+
file_system_discardPendingChanges();
|
|
168
168
|
};
|
|
169
169
|
class FileSystemItem {
|
|
170
170
|
path;
|
|
@@ -274,7 +274,7 @@ class project_root_ProjectRoot {
|
|
|
274
274
|
}
|
|
275
275
|
const lintChecks = [
|
|
276
276
|
'context-isolation',
|
|
277
|
-
'shared-
|
|
277
|
+
'shared-kernel',
|
|
278
278
|
'layers',
|
|
279
279
|
'dependencies',
|
|
280
280
|
'react',
|
|
@@ -323,56 +323,6 @@ class config_file_ConfigFile {
|
|
|
323
323
|
};
|
|
324
324
|
}
|
|
325
325
|
const configuredDependencyRules = ()=>resolveDependencyRules(config_file_ConfigFile.exists ? config_file_ConfigFile.Instance.data.rules?.dependencies : void 0);
|
|
326
|
-
const external_node_util_namespaceObject = require("node:util");
|
|
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)=>{
|
|
356
|
-
const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
|
|
357
|
-
const commands = mergeInstallCommands(nextSteps.filter(isCommand));
|
|
358
|
-
const notes = nextSteps.filter((line)=>!isCommand(line));
|
|
359
|
-
const sections = [];
|
|
360
|
-
if (commands.length) sections.push([
|
|
361
|
-
'Run these commands to install the required dependencies:',
|
|
362
|
-
...commands.map((line)=>(0, external_node_util_namespaceObject.styleText)([
|
|
363
|
-
'bold',
|
|
364
|
-
'cyan'
|
|
365
|
-
], line))
|
|
366
|
-
].join('\n'));
|
|
367
|
-
if (notes.length) sections.push([
|
|
368
|
-
'Additional information:',
|
|
369
|
-
...notes.map((line)=>line.replace(/^(\s*Add )(!\S+)/, (_, prefix, path)=>prefix + (0, external_node_util_namespaceObject.styleText)([
|
|
370
|
-
'bold',
|
|
371
|
-
'cyan'
|
|
372
|
-
], path)))
|
|
373
|
-
].join('\n'));
|
|
374
|
-
if (sections.length) console.log(sections.join('\n\n'));
|
|
375
|
-
};
|
|
376
326
|
const save_pending_changes_savePendingChanges = async ()=>{
|
|
377
327
|
const overwrittenFiles = filesToOverwrite();
|
|
378
328
|
if (overwrittenFiles.length) {
|
|
@@ -384,7 +334,7 @@ const save_pending_changes_savePendingChanges = async ()=>{
|
|
|
384
334
|
default: false
|
|
385
335
|
});
|
|
386
336
|
if (!overwrite) {
|
|
387
|
-
|
|
337
|
+
file_system_discardPendingChanges();
|
|
388
338
|
console.log('Cancelled: nothing was written.');
|
|
389
339
|
return false;
|
|
390
340
|
}
|
|
@@ -392,9 +342,7 @@ const save_pending_changes_savePendingChanges = async ()=>{
|
|
|
392
342
|
writePendingChanges();
|
|
393
343
|
return true;
|
|
394
344
|
};
|
|
395
|
-
|
|
396
|
-
const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
|
|
397
|
-
class UnknownFormatNaming {
|
|
345
|
+
class unknown_format_naming_UnknownFormatNaming {
|
|
398
346
|
rawSource;
|
|
399
347
|
camelCase;
|
|
400
348
|
PascalCase;
|
|
@@ -422,51 +370,6 @@ class UnknownFormatNaming {
|
|
|
422
370
|
return this.fileName.replaceAll('-', ' ');
|
|
423
371
|
}
|
|
424
372
|
}
|
|
425
|
-
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
426
|
-
class NestedName {
|
|
427
|
-
folders;
|
|
428
|
-
folderName;
|
|
429
|
-
fileName;
|
|
430
|
-
ClassName;
|
|
431
|
-
classNameSegments;
|
|
432
|
-
constructor(rawSource){
|
|
433
|
-
const segments = splitSegments(rawSource);
|
|
434
|
-
this.folders = segments.slice(0, -1);
|
|
435
|
-
this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
436
|
-
this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
|
|
437
|
-
this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
|
|
438
|
-
this.ClassName = this.classNameSegments.join('');
|
|
439
|
-
}
|
|
440
|
-
static validate = (rawSource)=>{
|
|
441
|
-
const segments = splitSegments(rawSource);
|
|
442
|
-
if (!segments.length) return 'Name is required';
|
|
443
|
-
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
444
|
-
return true;
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
const scaffold_react_page_reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
448
|
-
${[
|
|
449
|
-
...imports,
|
|
450
|
-
"import { type FC } from 'react'"
|
|
451
|
-
].join('\n')}
|
|
452
|
-
|
|
453
|
-
export type ${ClassName}PageProps = {}
|
|
454
|
-
|
|
455
|
-
export const ${ClassName}Page: FC<${ClassName}PageProps> = (props) => {
|
|
456
|
-
return ${body}
|
|
457
|
-
}
|
|
458
|
-
`.trim();
|
|
459
|
-
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
460
|
-
const name = await (0, prompts_namespaceObject.input)({
|
|
461
|
-
message: 'Provide name (folders split by "/"):',
|
|
462
|
-
validate: NestedName.validate
|
|
463
|
-
});
|
|
464
|
-
const { folders, ClassName, fileName } = new NestedName(name);
|
|
465
|
-
presentationReactFolder.subitem([
|
|
466
|
-
'pages',
|
|
467
|
-
...folders
|
|
468
|
-
]).createFile(`${fileName}-page.tsx`, scaffold_react_page_reactPageContent(ClassName));
|
|
469
|
-
};
|
|
470
373
|
const wiring_layers = [
|
|
471
374
|
'domain',
|
|
472
375
|
'application',
|
|
@@ -518,7 +421,7 @@ const layerOf = (file, contextPath)=>{
|
|
|
518
421
|
const [firstSegment] = external_node_path_default().relative(contextPath, file).split(external_node_path_default().sep);
|
|
519
422
|
return wiring_layers.find((layer)=>layer === firstSegment);
|
|
520
423
|
};
|
|
521
|
-
const
|
|
424
|
+
const wiring_namedImports = (source, fromFile)=>{
|
|
522
425
|
const result = new Map();
|
|
523
426
|
for (const [, names, importPath] of source.matchAll(/import\s*(?:type\s*)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g))for (const name of names.split(',')){
|
|
524
427
|
const cleanName = name.replace(/^\s*type\s+/, '').trim();
|
|
@@ -548,11 +451,11 @@ const readWiredModule = (wireFile, contextPath)=>{
|
|
|
548
451
|
const wiringRelativePath = external_node_path_default().relative(external_node_path_default().join(contextPath, 'wiring'), wireFile);
|
|
549
452
|
if (isEndpointWire(wiringRelativePath)) return;
|
|
550
453
|
const source = new file_system_File(wireFile).data;
|
|
551
|
-
const wireName = `wire${new
|
|
454
|
+
const wireName = `wire${new unknown_format_naming_UnknownFormatNaming(external_node_path_default().basename(wireFile, '.ts').replace(/^wire-/, '')).ClassName}`;
|
|
552
455
|
const exportMatch = new RegExp(`export\\s+const\\s+${wireName}\\s*=\\s*`).exec(source);
|
|
553
456
|
if (!exportMatch) return;
|
|
554
457
|
const branched = source.slice(exportMatch.index + exportMatch[0].length).startsWith('envBranchedWire(');
|
|
555
|
-
const imports =
|
|
458
|
+
const imports = wiring_namedImports(source, wireFile);
|
|
556
459
|
const implementations = wiredClassNames(source, wireName, exportMatch.index + exportMatch[0].length, branched).flatMap((className)=>{
|
|
557
460
|
const file = imports.get(className);
|
|
558
461
|
return file ? [
|
|
@@ -613,7 +516,7 @@ const availableDependencies = (consumer, implementation, candidates, rules = con
|
|
|
613
516
|
const wired = wiredDependencyNames(new file_system_File(consumer.wireFile).data, implementation.className);
|
|
614
517
|
return candidates.filter((candidate)=>candidate.wireFile !== consumer.wireFile && canDependOn(consumer, candidate, rules) && !wired.includes(candidate.wireName));
|
|
615
518
|
};
|
|
616
|
-
const
|
|
519
|
+
const wiring_relativeImport = (fromFile, toFile)=>{
|
|
617
520
|
const relativePath = external_node_path_default().relative(external_node_path_default().dirname(fromFile), toFile).replace(/\.ts$/, '').split(external_node_path_default().sep).join('/');
|
|
618
521
|
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
619
522
|
};
|
|
@@ -767,153 +670,21 @@ const parameterName = (typeName)=>typeName.substring(0, 1).toLowerCase() + typeN
|
|
|
767
670
|
const wireDependencies = (consumer, implementation, dependencies)=>{
|
|
768
671
|
const wireFile = new file_system_File(consumer.wireFile);
|
|
769
672
|
let wireSource = wireFile.data;
|
|
770
|
-
for (const dependency of dependencies)wireSource = addImport(wireSource, `import { ${dependency.wireName} } from '${
|
|
673
|
+
for (const dependency of dependencies)wireSource = addImport(wireSource, `import { ${dependency.wireName} } from '${wiring_relativeImport(consumer.wireFile, dependency.wireFile)}'`);
|
|
771
674
|
wireFile.update(addWireDependencies(wireSource, implementation.className, dependencies.map((x)=>x.wireName)));
|
|
772
675
|
const classFile = new file_system_File(implementation.file);
|
|
773
676
|
let classSource = classFile.data;
|
|
774
|
-
for (const dependency of dependencies)classSource = addImport(classSource, `import type { ${dependency.typeName} } from '${
|
|
677
|
+
for (const dependency of dependencies)classSource = addImport(classSource, `import type { ${dependency.typeName} } from '${wiring_relativeImport(implementation.file, dependency.typeFile)}'`);
|
|
775
678
|
classFile.update(addConstructorParameters(classSource, implementation.className, dependencies.map((x)=>`private readonly ${parameterName(x.typeName)}: ${x.typeName}`)));
|
|
776
679
|
};
|
|
777
680
|
const inMemoryImplementationType = 'in-memory';
|
|
778
681
|
const in_memory_db_className = 'InMemoryDbInfrastructureService';
|
|
779
682
|
const in_memory_db_wireName = 'wireInMemoryDbInfrastructureService';
|
|
780
683
|
const in_memory_db_parameterName = 'inMemoryDbInfrastructureService';
|
|
781
|
-
const inMemoryDbService = `type Entry = {
|
|
782
|
-
id: unknown;
|
|
783
|
-
item: any;
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
declare global {
|
|
787
|
-
var ___SHARED_IN_MEMORY_DB___: Record<string, Array<Entry>> | undefined;
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
type Section<T, TId> = {
|
|
791
|
-
all: (predicate?: (x: T) => boolean) => T[];
|
|
792
|
-
first: (predicate: (x: T) => boolean) => T | null;
|
|
793
|
-
withId: (id: TId) => T | null;
|
|
794
|
-
lastAddedItem: () => T | null;
|
|
795
|
-
save: (payload: T extends { id: TId } ? T : [TId, T]) => void;
|
|
796
|
-
deleteById: (id: TId) => void;
|
|
797
|
-
delete: (predicate: (x: T) => boolean) => void;
|
|
798
|
-
};
|
|
799
|
-
|
|
800
|
-
type IdsAreEqual<TId> = (a: TId, b: TId) => boolean;
|
|
801
|
-
|
|
802
|
-
const comparisonMethodNames = ['equals', 'same', 'isSame', 'isEqual'] as const;
|
|
803
|
-
|
|
804
|
-
const defaultIdsAreEqual = (a: unknown, b: unknown): boolean => {
|
|
805
|
-
if (typeof a !== 'object' || a === null) {
|
|
806
|
-
return Object.is(a, b);
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
for (const methodName of comparisonMethodNames) {
|
|
810
|
-
const method: unknown = (a as Record<string, unknown>)[methodName];
|
|
811
|
-
if (typeof method === 'function') {
|
|
812
|
-
return Boolean(method.call(a, b));
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
return Object.is(a, b);
|
|
817
|
-
};
|
|
818
|
-
|
|
819
|
-
const hasId = (x: unknown): x is { id: unknown } =>
|
|
820
|
-
typeof x === 'object' && x !== null && 'id' in x;
|
|
821
|
-
|
|
822
|
-
export class InMemoryDbInfrastructureService {
|
|
823
|
-
protected section<T extends { id: unknown }>(
|
|
824
|
-
key: string,
|
|
825
|
-
idsAreEqual?: IdsAreEqual<T['id']>
|
|
826
|
-
): Section<T, T['id']>;
|
|
827
|
-
protected section<T, TId>(
|
|
828
|
-
key: string,
|
|
829
|
-
idsAreEqual?: IdsAreEqual<TId>
|
|
830
|
-
): Section<T, TId>;
|
|
831
|
-
protected section<T, TId>(
|
|
832
|
-
key: string,
|
|
833
|
-
idsAreEqual: IdsAreEqual<TId> = defaultIdsAreEqual
|
|
834
|
-
): Section<T, TId> {
|
|
835
|
-
if (!globalThis.___SHARED_IN_MEMORY_DB___) {
|
|
836
|
-
globalThis.___SHARED_IN_MEMORY_DB___ = {};
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
if (!globalThis.___SHARED_IN_MEMORY_DB___[key]) {
|
|
840
|
-
globalThis.___SHARED_IN_MEMORY_DB___[key] = [];
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
const items = (): T[] =>
|
|
844
|
-
globalThis.___SHARED_IN_MEMORY_DB___![key].map(
|
|
845
|
-
(entry) => entry.item
|
|
846
|
-
);
|
|
847
|
-
|
|
848
|
-
return {
|
|
849
|
-
all: (predicate: (x: T) => boolean = () => true): T[] =>
|
|
850
|
-
items().filter(predicate),
|
|
851
|
-
first: (predicate: (x: T) => boolean): T | null =>
|
|
852
|
-
items().find(predicate) ?? null,
|
|
853
|
-
withId: (id: TId): T | null =>
|
|
854
|
-
items().find(
|
|
855
|
-
(x: T) => hasId(x) && idsAreEqual(x.id as TId, id)
|
|
856
|
-
) ?? null,
|
|
857
|
-
lastAddedItem: (): T | null =>
|
|
858
|
-
globalThis.___SHARED_IN_MEMORY_DB___![key].at(-1)?.item ?? null,
|
|
859
|
-
save: (payload: T extends { id: TId } ? T : [TId, T]) => {
|
|
860
|
-
const id = Array.isArray(payload) ? payload[0] : payload.id;
|
|
861
|
-
const item = Array.isArray(payload) ? payload[1] : payload;
|
|
862
|
-
const entries = globalThis.___SHARED_IN_MEMORY_DB___![key];
|
|
863
|
-
const existing = entries.find((entry) =>
|
|
864
|
-
idsAreEqual(entry.id as TId, id)
|
|
865
|
-
);
|
|
866
|
-
if (existing) {
|
|
867
|
-
existing.item = item;
|
|
868
|
-
return;
|
|
869
|
-
}
|
|
870
|
-
entries.push({ id, item });
|
|
871
|
-
},
|
|
872
|
-
deleteById: (id: TId) => {
|
|
873
|
-
globalThis.___SHARED_IN_MEMORY_DB___![key] =
|
|
874
|
-
globalThis.___SHARED_IN_MEMORY_DB___![key].filter(
|
|
875
|
-
(entry) => !idsAreEqual(entry.id as TId, id)
|
|
876
|
-
);
|
|
877
|
-
},
|
|
878
|
-
delete: (predicate: (x: T) => boolean) => {
|
|
879
|
-
globalThis.___SHARED_IN_MEMORY_DB___![key] =
|
|
880
|
-
globalThis.___SHARED_IN_MEMORY_DB___![key].filter(
|
|
881
|
-
(entry) => !predicate(entry.item)
|
|
882
|
-
);
|
|
883
|
-
}
|
|
884
|
-
};
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
`;
|
|
888
|
-
const inMemoryDbWiring = `import { wireClass } from '@domain-first/wire';
|
|
889
|
-
import { InMemoryDbInfrastructureService } from '../../infrastructure/services/in-memory-db-infrastructure-service';
|
|
890
|
-
|
|
891
|
-
export const wireInMemoryDbInfrastructureService = wireClass(
|
|
892
|
-
InMemoryDbInfrastructureService,
|
|
893
|
-
[]
|
|
894
|
-
);
|
|
895
|
-
`;
|
|
896
|
-
const inMemoryDbSpec = (testingLibrary, withWiring)=>`
|
|
897
|
-
import { describe, test, expect, beforeEach } from '${testingLibrary}'
|
|
898
|
-
${withWiring ? `import { type InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'
|
|
899
|
-
import { wireInMemoryDbInfrastructureService } from '../../wiring/infrastructure-services/wire-in-memory-db-infrastructure-service'` : "import { InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'"}
|
|
900
|
-
|
|
901
|
-
let inMemoryDbInfrastructureService: InMemoryDbInfrastructureService
|
|
902
|
-
|
|
903
|
-
beforeEach(() => {
|
|
904
|
-
inMemoryDbInfrastructureService = ${withWiring ? 'wireInMemoryDbInfrastructureService()' : 'new InMemoryDbInfrastructureService()'}
|
|
905
|
-
})
|
|
906
|
-
|
|
907
|
-
describe('in memory db', () => {
|
|
908
|
-
test('can be ${withWiring ? 'wired' : 'created'}', () => {
|
|
909
|
-
expect(inMemoryDbInfrastructureService).toBeDefined()
|
|
910
|
-
})
|
|
911
|
-
})
|
|
912
|
-
`.trim();
|
|
913
684
|
const in_memory_db_withWiring = ()=>config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
914
685
|
const in_memory_db_sharedFolder = ()=>new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
915
686
|
config_file_ConfigFile.Instance.data.rootFolder,
|
|
916
|
-
'shared'
|
|
687
|
+
'shared-kernel'
|
|
917
688
|
]);
|
|
918
689
|
const serviceFile = ()=>new file_system_File(in_memory_db_sharedFolder().path).subitem([
|
|
919
690
|
'infrastructure',
|
|
@@ -925,20 +696,8 @@ const in_memory_db_wireFile = ()=>new file_system_File(in_memory_db_sharedFolder
|
|
|
925
696
|
'infrastructure-services',
|
|
926
697
|
'wire-in-memory-db-infrastructure-service.ts'
|
|
927
698
|
]);
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
const servicesFolder = shared.subitem([
|
|
931
|
-
'infrastructure',
|
|
932
|
-
'services'
|
|
933
|
-
]);
|
|
934
|
-
servicesFolder.createFile('in-memory-db-infrastructure-service.ts', inMemoryDbService);
|
|
935
|
-
if (testingLibrary) servicesFolder.createFile('in-memory-db-infrastructure-service.spec.ts', inMemoryDbSpec(testingLibrary, in_memory_db_withWiring()));
|
|
936
|
-
if (in_memory_db_withWiring()) shared.subitem([
|
|
937
|
-
'wiring',
|
|
938
|
-
'infrastructure-services'
|
|
939
|
-
]).createFile('wire-in-memory-db-infrastructure-service.ts', inMemoryDbWiring);
|
|
940
|
-
};
|
|
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);
|
|
699
|
+
const in_memory_db_inMemoryDbScaffolded = ()=>serviceFile().exists && (!in_memory_db_withWiring() || in_memory_db_wireFile().exists);
|
|
700
|
+
const usesInMemoryDb = (implementationType)=>Boolean(config_file_ConfigFile.Instance.data.withInMemoryDb) && new unknown_format_naming_UnknownFormatNaming(implementationType).fileName === inMemoryImplementationType && in_memory_db_inMemoryDbScaffolded();
|
|
942
701
|
const plural = (word)=>{
|
|
943
702
|
if (/[^aeiou]y$/i.test(word)) return `${word.slice(0, -1)}ies`;
|
|
944
703
|
if (/(s|x|z|ch|sh)$/i.test(word)) return `${word}es`;
|
|
@@ -946,14 +705,14 @@ const plural = (word)=>{
|
|
|
946
705
|
};
|
|
947
706
|
const addInMemoryDbSection = (typeNaming, typeImportTarget)=>{
|
|
948
707
|
const file = serviceFile();
|
|
949
|
-
const sectionNaming = new
|
|
708
|
+
const sectionNaming = new unknown_format_naming_UnknownFormatNaming(plural(typeNaming.fileName));
|
|
950
709
|
const field = sectionNaming.variableName;
|
|
951
710
|
if (new RegExp(`\\b${field}\\s*=\\s*this\\.section\\b`).test(file.data)) return field;
|
|
952
|
-
const withImport = addImport(file.data, `import type { ${typeNaming.ClassName} } from '${
|
|
711
|
+
const withImport = addImport(file.data, `import type { ${typeNaming.ClassName} } from '${wiring_relativeImport(file.path, typeImportTarget)}';`);
|
|
953
712
|
file.update(addClassMember(withImport, in_memory_db_className, `${field} = this.section<${typeNaming.ClassName}>('${sectionNaming.fileName.toUpperCase()}');`));
|
|
954
713
|
return field;
|
|
955
714
|
};
|
|
956
|
-
const inMemoryDbTypeImport = (fromFile)=>`import type { ${in_memory_db_className} } from '${
|
|
715
|
+
const inMemoryDbTypeImport = (fromFile)=>`import type { ${in_memory_db_className} } from '${wiring_relativeImport(fromFile, serviceFile().path)}'`;
|
|
957
716
|
const inMemoryDbSectionMembers = (field, derived)=>`
|
|
958
717
|
private readonly data: ${in_memory_db_className}['${field}']
|
|
959
718
|
|
|
@@ -971,13 +730,15 @@ const injectInMemoryDb = (classFile, implementationName)=>{
|
|
|
971
730
|
]));
|
|
972
731
|
};
|
|
973
732
|
const wireInMemoryDb = (consumerWireFile, implementationName)=>{
|
|
974
|
-
consumerWireFile.update(addWireDependencies(addImport(consumerWireFile.data, `import { ${in_memory_db_wireName} } from '${
|
|
733
|
+
consumerWireFile.update(addWireDependencies(addImport(consumerWireFile.data, `import { ${in_memory_db_wireName} } from '${wiring_relativeImport(consumerWireFile.path, in_memory_db_wireFile().path)}'`), implementationName, [
|
|
975
734
|
in_memory_db_wireName
|
|
976
735
|
]));
|
|
977
736
|
};
|
|
978
737
|
const passInMemoryDb = (specFile, implementationName)=>{
|
|
979
|
-
specFile.update(addImport(specFile.data, `import { ${in_memory_db_className} } from '${
|
|
738
|
+
specFile.update(addImport(specFile.data, `import { ${in_memory_db_className} } from '${wiring_relativeImport(specFile.path, serviceFile().path)}'`).replace(`new ${implementationName}()`, `new ${implementationName}(new ${in_memory_db_className}())`));
|
|
980
739
|
};
|
|
740
|
+
require("node:module");
|
|
741
|
+
const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
|
|
981
742
|
const kindTitles = {
|
|
982
743
|
repositories: 'Repositories',
|
|
983
744
|
'domain-services': 'Domain services',
|
|
@@ -1022,7 +783,7 @@ const groupedPageSize = 20;
|
|
|
1022
783
|
const contextAndSharedModules = (boundedContextFolder)=>{
|
|
1023
784
|
const sharedFolder = new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
1024
785
|
config_file_ConfigFile.Instance.data.rootFolder,
|
|
1025
|
-
'shared'
|
|
786
|
+
'shared-kernel'
|
|
1026
787
|
]);
|
|
1027
788
|
const isShared = sharedFolder.path === boundedContextFolder.path;
|
|
1028
789
|
return [
|
|
@@ -1032,7 +793,7 @@ const contextAndSharedModules = (boundedContextFolder)=>{
|
|
|
1032
793
|
})),
|
|
1033
794
|
...isShared ? [] : findWiredModules(sharedFolder.path).map((x)=>({
|
|
1034
795
|
module: x,
|
|
1035
|
-
label: `${x.typeName} (shared)`
|
|
796
|
+
label: `${x.typeName} (shared-kernel)`
|
|
1036
797
|
}))
|
|
1037
798
|
];
|
|
1038
799
|
};
|
|
@@ -1097,8 +858,8 @@ const promptEndpointHandler = async (boundedContextFolder)=>{
|
|
|
1097
858
|
loop: false
|
|
1098
859
|
})).module : void 0;
|
|
1099
860
|
};
|
|
1100
|
-
const
|
|
1101
|
-
const naming = new
|
|
861
|
+
const scaffold_new_presentation_service_createPresentationService = (boundedContextFolder, name, classFile)=>{
|
|
862
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(name);
|
|
1102
863
|
const className = `${naming.ClassName}PresentationService`;
|
|
1103
864
|
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
1104
865
|
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
@@ -1146,34 +907,11 @@ const scaffoldNewPresentationService = async (boundedContextFolder)=>{
|
|
|
1146
907
|
const name = await (0, prompts_namespaceObject.input)({
|
|
1147
908
|
message: 'Name: '
|
|
1148
909
|
});
|
|
1149
|
-
const wireFile =
|
|
910
|
+
const wireFile = scaffold_new_presentation_service_createPresentationService(boundedContextFolder, name);
|
|
1150
911
|
if (wireFile) await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
1151
912
|
};
|
|
1152
913
|
const rest_endpoint_generator_name = 'rest-endpoint-generator';
|
|
1153
|
-
const
|
|
1154
|
-
const adapter = withNextAdapter ? 'nextAdapter' : 'adapter';
|
|
1155
|
-
return `
|
|
1156
|
-
import {
|
|
1157
|
-
${withNextAdapter ? '' : ' type Adapter,\n'} type EndpointGenerator,
|
|
1158
|
-
createEndpoint,
|
|
1159
|
-
invalidRequest
|
|
1160
|
-
} from '@domain-first/handlers-rest'
|
|
1161
|
-
${withNextAdapter ? "import { nextAdapter } from '@domain-first/handlers-next'" : `
|
|
1162
|
-
/**
|
|
1163
|
-
* The adapter of your HTTP framework.
|
|
1164
|
-
*/
|
|
1165
|
-
const adapter = undefined as unknown as Adapter<any[], any>`}
|
|
1166
|
-
|
|
1167
|
-
export class ${className} {
|
|
1168
|
-
get withoutGuards(): EndpointGenerator {
|
|
1169
|
-
return createEndpoint({
|
|
1170
|
-
errors: [invalidRequest()]
|
|
1171
|
-
})(${adapter}) as EndpointGenerator
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
`.trim();
|
|
1175
|
-
});
|
|
1176
|
-
const findRestEndpointGenerator = (sharedFolder)=>{
|
|
914
|
+
const rest_endpoint_generator_findRestEndpointGenerator = (sharedFolder)=>{
|
|
1177
915
|
const typeFile = external_node_path_default().join(sharedFolder.path, 'presentation', 'services', `${rest_endpoint_generator_name}-presentation-service.ts`);
|
|
1178
916
|
if (!new file_system_File(typeFile).exists) return;
|
|
1179
917
|
return {
|
|
@@ -1183,108 +921,7 @@ const findRestEndpointGenerator = (sharedFolder)=>{
|
|
|
1183
921
|
wireFile: external_node_path_default().join(sharedFolder.path, 'wiring', 'presentation-services', `wire-${rest_endpoint_generator_name}-presentation-service.ts`)
|
|
1184
922
|
};
|
|
1185
923
|
};
|
|
1186
|
-
|
|
1187
|
-
const manifestFile = new file_system_File(external_node_path_default().join(root, 'package.json'));
|
|
1188
|
-
if (!manifestFile.exists) return false;
|
|
1189
|
-
const manifest = JSON.parse(manifestFile.data);
|
|
1190
|
-
return [
|
|
1191
|
-
manifest.dependencies,
|
|
1192
|
-
manifest.devDependencies,
|
|
1193
|
-
manifest.optionalDependencies
|
|
1194
|
-
].some((dependencies)=>dependencies && Object.hasOwn(dependencies, name));
|
|
1195
|
-
};
|
|
1196
|
-
const initializeUseCase = async ()=>{
|
|
1197
|
-
const nextSteps = [];
|
|
1198
|
-
const rootFolderName = await (0, prompts_namespaceObject.input)({
|
|
1199
|
-
message: 'Root folder (use "/" for inner folders):',
|
|
1200
|
-
default: 'src'
|
|
1201
|
-
});
|
|
1202
|
-
const domainFirstPackages = await (0, prompts_namespaceObject.checkbox)({
|
|
1203
|
-
message: '@domain-first packages',
|
|
1204
|
-
choices: [
|
|
1205
|
-
'@domain-first/types',
|
|
1206
|
-
'@domain-first/errors',
|
|
1207
|
-
'@domain-first/handlers',
|
|
1208
|
-
'@domain-first/wire',
|
|
1209
|
-
'@domain-first/handlers-rest'
|
|
1210
|
-
]
|
|
1211
|
-
});
|
|
1212
|
-
const withNextAdapter = domainFirstPackages.includes('@domain-first/handlers-rest') && hasDependency(new project_root_ProjectRoot().path, 'next') && await (0, prompts_namespaceObject.confirm)({
|
|
1213
|
-
message: 'Use Next adapter for REST endpoints'
|
|
1214
|
-
});
|
|
1215
|
-
const defaultPersistenceLayerImplementation = await (0, prompts_namespaceObject.input)({
|
|
1216
|
-
message: 'Default persistence layer implementation:'
|
|
1217
|
-
});
|
|
1218
|
-
const withInMemoryDb = await (0, prompts_namespaceObject.confirm)({
|
|
1219
|
-
message: 'Scaffold in-memory DB for test implementations'
|
|
1220
|
-
});
|
|
1221
|
-
const useReact = await (0, prompts_namespaceObject.confirm)({
|
|
1222
|
-
message: 'Use React'
|
|
1223
|
-
});
|
|
1224
|
-
let storybookFramework;
|
|
1225
|
-
const withStorybook = useReact ? await (0, prompts_namespaceObject.confirm)({
|
|
1226
|
-
message: 'Use Storybook'
|
|
1227
|
-
}) : false;
|
|
1228
|
-
if (withStorybook) storybookFramework = await (0, prompts_namespaceObject.input)({
|
|
1229
|
-
message: 'Storybook framework package:',
|
|
1230
|
-
default: '@storybook/react-vite'
|
|
1231
|
-
});
|
|
1232
|
-
let testingLibrary;
|
|
1233
|
-
const withTests = await (0, prompts_namespaceObject.confirm)({
|
|
1234
|
-
message: 'Scaffold unit tests'
|
|
1235
|
-
});
|
|
1236
|
-
if (withTests) testingLibrary = await (0, prompts_namespaceObject.input)({
|
|
1237
|
-
message: 'Unit testing library:',
|
|
1238
|
-
default: 'vitest'
|
|
1239
|
-
});
|
|
1240
|
-
config_file_ConfigFile.write({
|
|
1241
|
-
rootFolder: rootFolderName,
|
|
1242
|
-
domainFirstPackages,
|
|
1243
|
-
defaultPersistenceLayerImplementation,
|
|
1244
|
-
withInMemoryDb,
|
|
1245
|
-
useReact,
|
|
1246
|
-
storybookFramework,
|
|
1247
|
-
testingLibrary
|
|
1248
|
-
});
|
|
1249
|
-
const { path } = new project_root_ProjectRoot();
|
|
1250
|
-
const rootFolder = new file_system_Folder(path);
|
|
1251
|
-
if (domainFirstPackages.includes('@domain-first/wire')) rootFolder.subitem([
|
|
1252
|
-
rootFolderName,
|
|
1253
|
-
'shared',
|
|
1254
|
-
'wiring'
|
|
1255
|
-
]).createFile('env-branched-wire.ts', `
|
|
1256
|
-
import { branchedWire } from '@domain-first/wire'
|
|
1257
|
-
|
|
1258
|
-
export const envBranchedWire = branchedWire(() => {
|
|
1259
|
-
return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
|
|
1260
|
-
});
|
|
1261
|
-
`.trim());
|
|
1262
|
-
if (withInMemoryDb) scaffoldInMemoryDb(rootFolder.subitem([
|
|
1263
|
-
rootFolderName,
|
|
1264
|
-
'shared'
|
|
1265
|
-
]));
|
|
1266
|
-
if (domainFirstPackages.includes('@domain-first/errors')) rootFolder.subitem([
|
|
1267
|
-
rootFolderName,
|
|
1268
|
-
'shared'
|
|
1269
|
-
]).subitem([
|
|
1270
|
-
'domain',
|
|
1271
|
-
'errors'
|
|
1272
|
-
]).createFile('index.ts', `
|
|
1273
|
-
import { errorNamespace } from '@domain-first/errors'
|
|
1274
|
-
|
|
1275
|
-
export const SharedErrors = errorNamespace('shared')
|
|
1276
|
-
`.trim());
|
|
1277
|
-
if (domainFirstPackages.includes('@domain-first/handlers-rest')) {
|
|
1278
|
-
scaffoldRestEndpointGenerator(rootFolder.subitem([
|
|
1279
|
-
rootFolderName,
|
|
1280
|
-
'shared'
|
|
1281
|
-
]), {
|
|
1282
|
-
withNextAdapter
|
|
1283
|
-
});
|
|
1284
|
-
if (withNextAdapter && !hasDependency(path, '@domain-first/handlers-next')) nextSteps.push('npm i @domain-first/handlers-next');
|
|
1285
|
-
}
|
|
1286
|
-
return nextSteps;
|
|
1287
|
-
};
|
|
924
|
+
require("node:util");
|
|
1288
925
|
const ignoredFolders = new Set([
|
|
1289
926
|
'node_modules',
|
|
1290
927
|
'.git',
|
|
@@ -1296,70 +933,20 @@ const ignoredFolders = new Set([
|
|
|
1296
933
|
'storybook-static'
|
|
1297
934
|
]);
|
|
1298
935
|
const codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx)$/;
|
|
1299
|
-
const
|
|
1300
|
-
const
|
|
936
|
+
const module_move_escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
937
|
+
const module_move_walk = (folder)=>{
|
|
1301
938
|
if (!external_node_fs_default().existsSync(folder)) return [];
|
|
1302
939
|
return external_node_fs_default().readdirSync(folder, {
|
|
1303
940
|
withFileTypes: true
|
|
1304
941
|
}).flatMap((entry)=>{
|
|
1305
942
|
const entryPath = external_node_path_default().join(folder, entry.name);
|
|
1306
|
-
if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] :
|
|
943
|
+
if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : module_move_walk(entryPath);
|
|
1307
944
|
return entry.isFile() ? [
|
|
1308
945
|
entryPath
|
|
1309
946
|
] : [];
|
|
1310
947
|
});
|
|
1311
948
|
};
|
|
1312
|
-
const
|
|
1313
|
-
const nestedName = (folders, fileBase)=>{
|
|
1314
|
-
const prefix = `${folders.join('-')}-`;
|
|
1315
|
-
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
1316
|
-
return [
|
|
1317
|
-
...folders,
|
|
1318
|
-
last
|
|
1319
|
-
].join('/');
|
|
1320
|
-
};
|
|
1321
|
-
const declaredClassName = (filePath, suffix, name)=>{
|
|
1322
|
-
const content = external_node_fs_default().readFileSync(filePath, 'utf8');
|
|
1323
|
-
const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
1324
|
-
return declared ?? new NestedName(name).ClassName;
|
|
1325
|
-
};
|
|
1326
|
-
const findReactModules = (reactFolder, kind)=>{
|
|
1327
|
-
const modules = 'page' === kind ? react_module_move_walk(external_node_path_default().join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
1328
|
-
const folders = external_node_path_default().relative(external_node_path_default().join(reactFolder, 'pages'), external_node_path_default().dirname(file)).split(external_node_path_default().sep).filter((segment)=>!!segment);
|
|
1329
|
-
const fileBase = external_node_path_default().basename(file, '-page.tsx');
|
|
1330
|
-
const name = nestedName(folders, fileBase);
|
|
1331
|
-
return {
|
|
1332
|
-
kind,
|
|
1333
|
-
name,
|
|
1334
|
-
path: file,
|
|
1335
|
-
fileBase,
|
|
1336
|
-
ClassName: declaredClassName(file, 'Page', name)
|
|
1337
|
-
};
|
|
1338
|
-
}) : react_module_move_walk(external_node_path_default().join(reactFolder, 'widgets')).filter((file)=>file.endsWith('-widget.tsx')).map((file)=>{
|
|
1339
|
-
const folder = external_node_path_default().dirname(file);
|
|
1340
|
-
const name = toPosix(external_node_path_default().relative(external_node_path_default().join(reactFolder, 'widgets'), folder));
|
|
1341
|
-
return {
|
|
1342
|
-
kind,
|
|
1343
|
-
name,
|
|
1344
|
-
path: folder,
|
|
1345
|
-
fileBase: external_node_path_default().basename(file, '-widget.tsx'),
|
|
1346
|
-
ClassName: declaredClassName(file, 'Widget', name)
|
|
1347
|
-
};
|
|
1348
|
-
});
|
|
1349
|
-
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
1350
|
-
};
|
|
1351
|
-
const react_module_move_targetPath = (reactFolder, module, rawName)=>{
|
|
1352
|
-
const { folders, folderName, fileName } = new NestedName(rawName);
|
|
1353
|
-
return 'page' === module.kind ? external_node_path_default().join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`) : external_node_path_default().join(reactFolder, 'widgets', ...folders, folderName);
|
|
1354
|
-
};
|
|
1355
|
-
const validateMove = (reactFolder, module, rawName)=>{
|
|
1356
|
-
const nameError = NestedName.validate(rawName);
|
|
1357
|
-
if (true !== nameError) return nameError;
|
|
1358
|
-
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
1359
|
-
if (target !== module.path && external_node_fs_default().existsSync(target)) return `${external_node_path_default().relative(reactFolder, target)} already exists`;
|
|
1360
|
-
if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
|
|
1361
|
-
return true;
|
|
1362
|
-
};
|
|
949
|
+
const module_move_toPosix = (value)=>value.split(external_node_path_default().sep).join('/');
|
|
1363
950
|
const readAliases = (projectRoot)=>{
|
|
1364
951
|
const tsconfig = external_node_path_default().join(projectRoot, 'tsconfig.json');
|
|
1365
952
|
if (!external_node_fs_default().existsSync(tsconfig)) return [];
|
|
@@ -1385,26 +972,7 @@ const importPaths = (file)=>{
|
|
|
1385
972
|
withoutExtension
|
|
1386
973
|
];
|
|
1387
974
|
};
|
|
1388
|
-
const
|
|
1389
|
-
const newName = new NestedName(rawName);
|
|
1390
|
-
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
1391
|
-
const newClassName = newName.ClassName;
|
|
1392
|
-
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.])`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
1393
|
-
const oldFolder = 'page' === module.kind ? external_node_path_default().dirname(module.path) : module.path;
|
|
1394
|
-
const newFolder = 'page' === module.kind ? external_node_path_default().dirname(target) : target;
|
|
1395
|
-
const ownsPath = (candidate)=>'page' === module.kind ? external_node_path_default().dirname(candidate) === oldFolder && new RegExp(`^${escapeRegExp(module.fileBase)}-page(?:\\.|$)`).test(external_node_path_default().basename(candidate)) : candidate === oldFolder || candidate.startsWith(`${oldFolder}${external_node_path_default().sep}`);
|
|
1396
|
-
const movedPath = (candidate)=>{
|
|
1397
|
-
if (!ownsPath(candidate)) return;
|
|
1398
|
-
const segments = external_node_path_default().relative(oldFolder, candidate).split(external_node_path_default().sep);
|
|
1399
|
-
const last = segments.length - 1;
|
|
1400
|
-
segments[last] = renameFile(segments[last]);
|
|
1401
|
-
return external_node_path_default().join(newFolder, ...segments);
|
|
1402
|
-
};
|
|
1403
|
-
const moduleFiles = 'page' === module.kind ? external_node_fs_default().readdirSync(oldFolder).map((name)=>external_node_path_default().join(oldFolder, name)).filter((file)=>external_node_fs_default().statSync(file).isFile() && ownsPath(file)) : react_module_move_walk(oldFolder);
|
|
1404
|
-
const moves = new Map(moduleFiles.map((file)=>[
|
|
1405
|
-
file,
|
|
1406
|
-
movedPath(file) ?? file
|
|
1407
|
-
]));
|
|
975
|
+
const projectImports = (projectRoot)=>{
|
|
1408
976
|
const aliases = readAliases(projectRoot);
|
|
1409
977
|
const resolve = (specifier, fromFile)=>{
|
|
1410
978
|
if (specifier.startsWith('.')) return {
|
|
@@ -1418,23 +986,27 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
1418
986
|
} : void 0;
|
|
1419
987
|
};
|
|
1420
988
|
const specifierFor = (fromFile, toPath, alias)=>{
|
|
1421
|
-
const aliased = alias &&
|
|
989
|
+
const aliased = alias && module_move_toPosix(external_node_path_default().relative(alias.target, toPath));
|
|
1422
990
|
if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
|
|
1423
|
-
const relative =
|
|
991
|
+
const relative = module_move_toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toPath));
|
|
1424
992
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
1425
993
|
};
|
|
1426
|
-
const
|
|
1427
|
-
const classPattern = new RegExp(`(?<![\\w$])(use)?${escapeRegExp(module.ClassName)}(?=${suffixes})`, 'g');
|
|
1428
|
-
const oldTitle = `Widgets/${module.name.split('/').map((segment)=>new NestedName(segment).ClassName).join('/')}`;
|
|
1429
|
-
const titlePattern = new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
1430
|
-
const newTitle = [
|
|
1431
|
-
'Widgets',
|
|
1432
|
-
...newName.classNameSegments
|
|
1433
|
-
].join('/');
|
|
1434
|
-
const codeFiles = new Map(react_module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
994
|
+
const codeFiles = new Map(module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
1435
995
|
file,
|
|
1436
996
|
external_node_fs_default().readFileSync(file, 'utf8')
|
|
1437
997
|
]));
|
|
998
|
+
const importsOf = (file)=>[
|
|
999
|
+
...(codeFiles.get(file) ?? '').matchAll(specifierPattern)
|
|
1000
|
+
].map(([, , , specifier])=>resolve(specifier, file)?.resolved).filter((resolved)=>!!resolved);
|
|
1001
|
+
return {
|
|
1002
|
+
resolve,
|
|
1003
|
+
specifierFor,
|
|
1004
|
+
codeFiles,
|
|
1005
|
+
importsOf
|
|
1006
|
+
};
|
|
1007
|
+
};
|
|
1008
|
+
const module_move_stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content })=>{
|
|
1009
|
+
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
1438
1010
|
const barrels = new Set();
|
|
1439
1011
|
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
1440
1012
|
for(let found = true; found;){
|
|
@@ -1464,18 +1036,20 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
1464
1036
|
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
1465
1037
|
return `${keyword}${quote}${next}${quote}`;
|
|
1466
1038
|
});
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
return
|
|
1039
|
+
const changed = everyFile(rewritten);
|
|
1040
|
+
if (!referencesModule && !moves.has(oldFile)) return changed;
|
|
1041
|
+
return rename(changed, {
|
|
1042
|
+
moved: moves.has(oldFile)
|
|
1043
|
+
});
|
|
1470
1044
|
};
|
|
1471
|
-
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile,
|
|
1045
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile, stopAt);
|
|
1472
1046
|
const updated = [];
|
|
1473
1047
|
for (const [file, content] of codeFiles){
|
|
1474
1048
|
const newFile = moves.get(file);
|
|
1475
1049
|
const next = rewrite(content, file, newFile ?? file);
|
|
1476
1050
|
if (newFile && newFile !== file) {
|
|
1477
1051
|
new file_system_File(newFile).data = next;
|
|
1478
|
-
new file_system_File(file).delete(
|
|
1052
|
+
new file_system_File(file).delete(stopAt);
|
|
1479
1053
|
} else if (next !== content) {
|
|
1480
1054
|
new file_system_File(file).update(next);
|
|
1481
1055
|
if (!newFile) updated.push(file);
|
|
@@ -1488,40 +1062,416 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
1488
1062
|
updated
|
|
1489
1063
|
};
|
|
1490
1064
|
};
|
|
1491
|
-
const
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1065
|
+
const serviceLayout = (layer)=>({
|
|
1066
|
+
title: `${layer[0].toUpperCase()}${layer.slice(1)} services`,
|
|
1067
|
+
core: (ClassName)=>`${ClassName}${layer[0].toUpperCase()}${layer.slice(1)}Service`,
|
|
1068
|
+
files: ({ name })=>[
|
|
1069
|
+
`${layer}/services/${name}-${layer}-service.ts`,
|
|
1070
|
+
`${layer}/services/${name}-${layer}-service.spec.ts`,
|
|
1071
|
+
`wiring/${layer}-services/wire-${name}-${layer}-service.ts`
|
|
1072
|
+
],
|
|
1073
|
+
wired: true,
|
|
1074
|
+
sharedKernel: true
|
|
1075
|
+
});
|
|
1076
|
+
const handlerLayout = (kind)=>{
|
|
1077
|
+
const folder = 'command' === kind ? 'commands' : 'queries';
|
|
1078
|
+
const Suffix = 'command' === kind ? 'Command' : 'Query';
|
|
1079
|
+
return {
|
|
1080
|
+
title: 'command' === kind ? 'Commands' : 'Queries',
|
|
1081
|
+
core: (ClassName)=>`${ClassName}${Suffix}`,
|
|
1082
|
+
files: ({ name }, labels)=>[
|
|
1083
|
+
`application/${folder}/${name}-${kind}.ts`,
|
|
1084
|
+
`application/${folder}/${name}-${kind}.spec.ts`,
|
|
1085
|
+
...labels.map((label)=>`infrastructure/${folder}/${label}/${label}-${name}-${kind}.ts`),
|
|
1086
|
+
`wiring/${folder}/wire-${name}-${kind}.ts`
|
|
1087
|
+
],
|
|
1088
|
+
implementations: `infrastructure/${folder}`,
|
|
1089
|
+
wired: true,
|
|
1090
|
+
sharedKernel: false
|
|
1091
|
+
};
|
|
1092
|
+
};
|
|
1093
|
+
const domainModelLayout = (kind)=>{
|
|
1094
|
+
const folder = 'entity' === kind ? 'entities' : 'value-objects';
|
|
1095
|
+
return {
|
|
1096
|
+
title: 'entity' === kind ? 'Entities' : 'Value objects',
|
|
1097
|
+
core: (ClassName)=>ClassName,
|
|
1098
|
+
files: ({ name, aggregate })=>{
|
|
1099
|
+
const base = aggregate ? `domain/aggregates/${aggregate}/${folder}` : `domain/${folder}`;
|
|
1100
|
+
return [
|
|
1101
|
+
`${base}/${name}.${kind}.ts`,
|
|
1102
|
+
`${base}/${name}.${kind}.spec.ts`
|
|
1103
|
+
];
|
|
1104
|
+
},
|
|
1105
|
+
wired: false,
|
|
1106
|
+
sharedKernel: true
|
|
1107
|
+
};
|
|
1108
|
+
};
|
|
1109
|
+
const aggregateOwnFiles = (name)=>[
|
|
1110
|
+
`${name}.aggregate-root.ts`,
|
|
1111
|
+
`${name}.aggregate-root.spec.ts`,
|
|
1112
|
+
`${name}-repository.ts`,
|
|
1113
|
+
`${name}-repository.spec.ts`,
|
|
1114
|
+
'index.ts'
|
|
1115
|
+
];
|
|
1116
|
+
const kindLayouts = {
|
|
1117
|
+
aggregate: {
|
|
1118
|
+
title: 'Aggregates',
|
|
1119
|
+
core: (ClassName)=>`${ClassName}Repository`,
|
|
1120
|
+
files: ({ name }, labels)=>[
|
|
1121
|
+
...aggregateOwnFiles(name).map((file)=>`domain/aggregates/${name}/${file}`),
|
|
1122
|
+
...labels.map((label)=>`infrastructure/repositories/${label}/${label}-${name}-repository.ts`),
|
|
1123
|
+
`wiring/repositories/wire-${name}-repository.ts`
|
|
1124
|
+
],
|
|
1125
|
+
implementations: 'infrastructure/repositories',
|
|
1126
|
+
wired: true,
|
|
1127
|
+
sharedKernel: false
|
|
1128
|
+
},
|
|
1129
|
+
entity: domainModelLayout('entity'),
|
|
1130
|
+
'value-object': domainModelLayout('value-object'),
|
|
1131
|
+
'domain-service': serviceLayout('domain'),
|
|
1132
|
+
'application-service': serviceLayout('application'),
|
|
1133
|
+
'infrastructure-service': serviceLayout('infrastructure'),
|
|
1134
|
+
'presentation-service': serviceLayout('presentation'),
|
|
1135
|
+
'use-case': {
|
|
1136
|
+
title: 'Use cases',
|
|
1137
|
+
core: (ClassName)=>`${ClassName}UseCase`,
|
|
1138
|
+
files: ({ name })=>[
|
|
1139
|
+
`application/use-cases/${name}-use-case.ts`,
|
|
1140
|
+
`application/use-cases/${name}-use-case.spec.ts`,
|
|
1141
|
+
`wiring/use-cases/wire-${name}-use-case.ts`
|
|
1142
|
+
],
|
|
1143
|
+
wired: true,
|
|
1144
|
+
sharedKernel: false
|
|
1145
|
+
},
|
|
1146
|
+
command: handlerLayout('command'),
|
|
1147
|
+
query: handlerLayout('query'),
|
|
1148
|
+
port: {
|
|
1149
|
+
title: 'Ports',
|
|
1150
|
+
core: (ClassName)=>ClassName,
|
|
1151
|
+
files: ({ name }, labels)=>[
|
|
1152
|
+
`application/ports/${name}.ts`,
|
|
1153
|
+
`application/ports/${name}.spec.ts`,
|
|
1154
|
+
...labels.map((label)=>`infrastructure/application-adapters/${label}/${label}-${name}.ts`),
|
|
1155
|
+
`wiring/application-ports/wire-${name}.ts`
|
|
1156
|
+
],
|
|
1157
|
+
implementations: 'infrastructure/application-adapters',
|
|
1158
|
+
wired: true,
|
|
1159
|
+
sharedKernel: true
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
const subfolders = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
|
|
1163
|
+
withFileTypes: true
|
|
1164
|
+
}).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name).sort() : [];
|
|
1165
|
+
const namesBySuffix = (folder, suffix)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder).filter((file)=>file.endsWith(suffix) && !file.endsWith('.spec.ts')).map((file)=>file.slice(0, -suffix.length)).sort() : [];
|
|
1166
|
+
const labelsOf = (ownerPath, kind, name)=>{
|
|
1167
|
+
const { implementations } = kindLayouts[kind];
|
|
1168
|
+
if (!implementations) return [];
|
|
1169
|
+
return subfolders(external_node_path_default().join(ownerPath, implementations)).filter((label)=>kindLayouts[kind].files({
|
|
1170
|
+
ownerPath,
|
|
1171
|
+
name
|
|
1172
|
+
}, [
|
|
1173
|
+
label
|
|
1174
|
+
]).some((file)=>file.startsWith(`${implementations}/`) && external_node_fs_default().existsSync(external_node_path_default().join(ownerPath, file))));
|
|
1175
|
+
};
|
|
1176
|
+
const aggregatesOf = (ownerPath)=>subfolders(external_node_path_default().join(ownerPath, 'domain/aggregates')).filter((name)=>external_node_fs_default().existsSync(external_node_path_default().join(ownerPath, 'domain/aggregates', name, `${name}.aggregate-root.ts`)));
|
|
1177
|
+
const findBackendUnits = (ownerPath)=>{
|
|
1178
|
+
const unit = (kind, name, aggregate)=>({
|
|
1179
|
+
kind,
|
|
1180
|
+
name,
|
|
1181
|
+
ownerPath,
|
|
1182
|
+
aggregate,
|
|
1183
|
+
labels: labelsOf(ownerPath, kind, name)
|
|
1184
|
+
});
|
|
1185
|
+
const aggregates = aggregatesOf(ownerPath);
|
|
1186
|
+
const inAggregates = (kind)=>aggregates.flatMap((aggregate)=>namesBySuffix(external_node_path_default().join(ownerPath, 'domain/aggregates', aggregate, 'entity' === kind ? 'entities' : 'value-objects'), `.${kind}.ts`).map((name)=>unit(kind, name, aggregate)));
|
|
1187
|
+
const at = (folder, suffix, kind)=>namesBySuffix(external_node_path_default().join(ownerPath, folder), suffix).map((name)=>unit(kind, name));
|
|
1188
|
+
return [
|
|
1189
|
+
...aggregates.map((name)=>unit('aggregate', name)),
|
|
1190
|
+
...inAggregates('entity'),
|
|
1191
|
+
...at('domain/entities', '.entity.ts', 'entity'),
|
|
1192
|
+
...inAggregates('value-object'),
|
|
1193
|
+
...at('domain/value-objects', '.value-object.ts', 'value-object'),
|
|
1194
|
+
...at('domain/services', '-domain-service.ts', 'domain-service'),
|
|
1195
|
+
...at('application/ports', '.ts', 'port'),
|
|
1196
|
+
...at('application/queries', '-query.ts', 'query'),
|
|
1197
|
+
...at('application/commands', '-command.ts', 'command'),
|
|
1198
|
+
...at('application/use-cases', '-use-case.ts', 'use-case'),
|
|
1199
|
+
...at('application/services', '-application-service.ts', 'application-service'),
|
|
1200
|
+
...at('infrastructure/services', '-infrastructure-service.ts', 'infrastructure-service'),
|
|
1201
|
+
...at('presentation/services', '-presentation-service.ts', 'presentation-service')
|
|
1202
|
+
];
|
|
1203
|
+
};
|
|
1204
|
+
const kebabName = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
1205
|
+
const lowerFirst = (value)=>value[0].toLowerCase() + value.slice(1);
|
|
1206
|
+
const unitMoves = (unit, target)=>{
|
|
1207
|
+
const layout = kindLayouts[unit.kind];
|
|
1208
|
+
const from = layout.files(unit, unit.labels);
|
|
1209
|
+
const to = layout.files(target, unit.labels);
|
|
1210
|
+
const moves = new Map();
|
|
1211
|
+
from.forEach((file, index)=>{
|
|
1212
|
+
const oldPath = external_node_path_default().join(unit.ownerPath, file);
|
|
1213
|
+
if (external_node_fs_default().existsSync(oldPath)) moves.set(oldPath, external_node_path_default().join(target.ownerPath, to[index]));
|
|
1214
|
+
});
|
|
1215
|
+
if ('aggregate' === unit.kind) {
|
|
1216
|
+
const oldFolder = external_node_path_default().join(unit.ownerPath, 'domain/aggregates', unit.name);
|
|
1217
|
+
const newFolder = external_node_path_default().join(target.ownerPath, 'domain/aggregates', target.name);
|
|
1218
|
+
const own = new Set(aggregateOwnFiles(unit.name).map((file)=>external_node_path_default().join(oldFolder, file)));
|
|
1219
|
+
for (const file of module_move_walk(oldFolder))if (!own.has(file)) moves.set(file, external_node_path_default().join(newFolder, external_node_path_default().relative(oldFolder, file)));
|
|
1220
|
+
}
|
|
1221
|
+
return moves;
|
|
1222
|
+
};
|
|
1223
|
+
const validateBackendMove = (unit, target, sharedKernelPath)=>{
|
|
1224
|
+
if (!kebabName.test(target.name)) return 'Use kebab-case: lowercase words split by "-", e.g. place-order';
|
|
1225
|
+
if (target.ownerPath === sharedKernelPath && !kindLayouts[unit.kind].sharedKernel) return `${kindLayouts[unit.kind].title} are not part of the Shared Kernel`;
|
|
1226
|
+
if (target.ownerPath === unit.ownerPath && target.name === unit.name && target.aggregate === unit.aggregate) return 'Nothing to change: enter a new name or pick another place';
|
|
1227
|
+
for (const [from, to] of unitMoves(unit, target))if (to !== from && external_node_fs_default().existsSync(to)) return `${external_node_path_default().relative(target.ownerPath, to)} already exists`;
|
|
1228
|
+
return true;
|
|
1229
|
+
};
|
|
1230
|
+
const ownerOf = (rootFolderPath, file)=>{
|
|
1231
|
+
const [area, context] = external_node_path_default().relative(rootFolderPath, file).split(external_node_path_default().sep);
|
|
1232
|
+
if ('bounded-contexts' === area && context) return {
|
|
1233
|
+
context,
|
|
1234
|
+
path: external_node_path_default().join(rootFolderPath, area, context)
|
|
1235
|
+
};
|
|
1236
|
+
if ('shared-kernel' === area) return {
|
|
1237
|
+
context: void 0,
|
|
1238
|
+
path: external_node_path_default().join(rootFolderPath, area)
|
|
1239
|
+
};
|
|
1240
|
+
};
|
|
1241
|
+
const inMemoryDbFile = (rootFolderPath)=>external_node_path_default().join(rootFolderPath, 'shared-kernel/infrastructure/services/in-memory-db-infrastructure-service.ts');
|
|
1242
|
+
const isolationAllows = (rootFolderPath, from, to)=>{
|
|
1243
|
+
const fromOwner = ownerOf(rootFolderPath, from);
|
|
1244
|
+
const toOwner = ownerOf(rootFolderPath, to);
|
|
1245
|
+
if (!fromOwner || !toOwner?.context) return true;
|
|
1246
|
+
if (fromOwner.context) return fromOwner.context === toOwner.context;
|
|
1247
|
+
const inside = (folder)=>to === external_node_path_default().join(toOwner.path, folder) || to.startsWith(external_node_path_default().join(toOwner.path, folder) + external_node_path_default().sep);
|
|
1248
|
+
return inside('domain/errors') || from.replace(codeExtension, '') === inMemoryDbFile(rootFolderPath).replace(codeExtension, '') && inside('domain');
|
|
1249
|
+
};
|
|
1250
|
+
const moveBackendUnit = (projectRoot, rootFolderPath, unit, target)=>{
|
|
1251
|
+
const layout = kindLayouts[unit.kind];
|
|
1252
|
+
const moves = unitMoves(unit, target);
|
|
1253
|
+
const withoutExtension = new Map([
|
|
1254
|
+
...moves
|
|
1255
|
+
].map(([from, to])=>[
|
|
1256
|
+
from.replace(codeExtension, ''),
|
|
1257
|
+
to.replace(codeExtension, '')
|
|
1258
|
+
]));
|
|
1259
|
+
const folders = 'aggregate' === unit.kind ? [
|
|
1260
|
+
[
|
|
1261
|
+
external_node_path_default().join(unit.ownerPath, 'domain/aggregates', unit.name),
|
|
1262
|
+
external_node_path_default().join(target.ownerPath, 'domain/aggregates', target.name)
|
|
1263
|
+
]
|
|
1264
|
+
] : [];
|
|
1265
|
+
const movedPath = (candidate)=>{
|
|
1266
|
+
const extension = candidate.match(codeExtension)?.[0];
|
|
1267
|
+
if (extension) return moves.get(candidate);
|
|
1268
|
+
return withoutExtension.get(candidate) ?? folders.find(([from])=>from === candidate)?.[1];
|
|
1269
|
+
};
|
|
1270
|
+
const { codeFiles, importsOf, resolve } = projectImports(projectRoot);
|
|
1271
|
+
const oldNaming = new unknown_format_naming_UnknownFormatNaming(unit.name);
|
|
1272
|
+
const newNaming = new unknown_format_naming_UnknownFormatNaming(target.name);
|
|
1273
|
+
const leavesAggregate = !!unit.aggregate && (unit.aggregate !== target.aggregate || unit.ownerPath !== target.ownerPath);
|
|
1274
|
+
const oldAggregateFolder = unit.aggregate && external_node_path_default().join(unit.ownerPath, 'domain/aggregates', unit.aggregate);
|
|
1275
|
+
const isOldBarrel = (resolved)=>!!oldAggregateFolder && (resolved === oldAggregateFolder || resolved === external_node_path_default().join(oldAggregateFolder, 'index'));
|
|
1276
|
+
const mainFile = [
|
|
1277
|
+
...moves.keys()
|
|
1278
|
+
][0];
|
|
1279
|
+
const newMainFile = moves.get(mainFile);
|
|
1280
|
+
const namedImports = /import\s+(type\s+)?\{([^}]*)\}\s*from\s*(['"])([^'"\n]+)\3;?/g;
|
|
1281
|
+
const barrelImporters = leavesAggregate ? [
|
|
1282
|
+
...codeFiles
|
|
1283
|
+
].filter(([file, content])=>!moves.has(file) && [
|
|
1284
|
+
...content.matchAll(namedImports)
|
|
1285
|
+
].some(([, , names, , specifier])=>isOldBarrel(resolve(specifier, file)?.resolved) && new RegExp(`(?<![\\w$])${oldNaming.ClassName}(?![\\w$])`).test(names))) : [];
|
|
1286
|
+
const violations = [];
|
|
1287
|
+
const relative = (file)=>module_move_toPosix(external_node_path_default().relative(projectRoot, file));
|
|
1288
|
+
for (const file of codeFiles.keys()){
|
|
1289
|
+
const from = moves.get(file) ?? file;
|
|
1290
|
+
for (const imported of importsOf(file)){
|
|
1291
|
+
const to = movedPath(imported);
|
|
1292
|
+
if (moves.has(file) || to) {
|
|
1293
|
+
if (!isolationAllows(rootFolderPath, from, to ?? imported)) violations.push([
|
|
1294
|
+
relative(from),
|
|
1295
|
+
relative(to ?? imported)
|
|
1296
|
+
]);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
for (const [file] of barrelImporters)if (!isolationAllows(rootFolderPath, file, newMainFile)) violations.push([
|
|
1301
|
+
relative(file),
|
|
1302
|
+
relative(newMainFile)
|
|
1303
|
+
]);
|
|
1304
|
+
if (violations.length) return {
|
|
1305
|
+
violations
|
|
1306
|
+
};
|
|
1307
|
+
const word = (form)=>`(?<![\\w$])${module_move_escapeRegExp(form)}(?![\\w$])`;
|
|
1308
|
+
const oldCore = layout.core(oldNaming.ClassName);
|
|
1309
|
+
const newCore = layout.core(newNaming.ClassName);
|
|
1310
|
+
const prefixes = [
|
|
1311
|
+
...unit.labels.map((label)=>new unknown_format_naming_UnknownFormatNaming(label).ClassName),
|
|
1312
|
+
...layout.wired ? [
|
|
1313
|
+
'wire'
|
|
1314
|
+
] : []
|
|
1315
|
+
];
|
|
1316
|
+
const renames = [
|
|
1317
|
+
{
|
|
1318
|
+
pattern: new RegExp(`(?<![\\w$])(${prefixes.map(module_move_escapeRegExp).join('|')})?${module_move_escapeRegExp(oldCore)}(?![\\w$])`, 'g'),
|
|
1319
|
+
to: `$1${newCore}`
|
|
1320
|
+
},
|
|
1321
|
+
{
|
|
1322
|
+
pattern: new RegExp(word(lowerFirst(oldCore)), 'g'),
|
|
1323
|
+
to: lowerFirst(newCore)
|
|
1324
|
+
},
|
|
1325
|
+
{
|
|
1326
|
+
pattern: new RegExp(`(describe\\(\\s*['"\`])${module_move_escapeRegExp(oldNaming.withSpaces)}(?=[ '"\`])`, 'g'),
|
|
1327
|
+
to: `$1${newNaming.withSpaces}`,
|
|
1328
|
+
movedOnly: true
|
|
1329
|
+
}
|
|
1330
|
+
];
|
|
1331
|
+
if ('aggregate' === unit.kind) renames.push({
|
|
1332
|
+
pattern: new RegExp(word(oldNaming.ClassName), 'g'),
|
|
1333
|
+
to: newNaming.ClassName
|
|
1334
|
+
}, {
|
|
1335
|
+
pattern: new RegExp(word(oldNaming.variableName), 'g'),
|
|
1336
|
+
to: newNaming.variableName,
|
|
1337
|
+
movedOnly: true
|
|
1338
|
+
});
|
|
1339
|
+
if ('entity' === unit.kind || 'value-object' === unit.kind) renames.push({
|
|
1340
|
+
pattern: new RegExp(word(oldNaming.variableName), 'g'),
|
|
1341
|
+
to: newNaming.variableName,
|
|
1342
|
+
movedOnly: true
|
|
1343
|
+
});
|
|
1344
|
+
const oldSection = new unknown_format_naming_UnknownFormatNaming(plural(unit.name));
|
|
1345
|
+
const newSection = new unknown_format_naming_UnknownFormatNaming(plural(target.name));
|
|
1346
|
+
const renamesSection = 'aggregate' === unit.kind && unit.name !== target.name;
|
|
1347
|
+
const everyFile = (content)=>renamesSection ? content.replace(new RegExp(`(InMemoryDbInfrastructureService\\[\\s*['"])${oldSection.variableName}(?=['"]\\s*\\])`, 'g'), `$1${newSection.variableName}`).replace(new RegExp(`(inMemoryDbInfrastructureService\\s*\\.\\s*)${oldSection.variableName}(?![\\w$])`, 'g'), `$1${newSection.variableName}`).replace(new RegExp(`(?<![\\w$.])${oldSection.variableName}(\\s*=\\s*this\\.section<[^>]*>\\(\\s*['"])${oldSection.fileName.toUpperCase()}(?=['"])`, 'g'), `${newSection.variableName}$1${newSection.fileName.toUpperCase()}`) : content;
|
|
1348
|
+
const plan = module_move_stageModuleMove({
|
|
1349
|
+
projectRoot,
|
|
1350
|
+
stopAt: rootFolderPath,
|
|
1351
|
+
moves,
|
|
1352
|
+
movedPath,
|
|
1353
|
+
rename: (content, { moved })=>renames.reduce((result, { pattern, to, movedOnly })=>movedOnly && !moved ? result : result.replace(pattern, to), content),
|
|
1354
|
+
everyFile
|
|
1355
|
+
});
|
|
1356
|
+
if (leavesAggregate && oldAggregateFolder) {
|
|
1357
|
+
const indexFile = new file_system_File(external_node_path_default().join(oldAggregateFolder, 'index.ts'));
|
|
1358
|
+
const exportLine = /^export\s+\*\s+from\s+(['"])([^'"\n]+)\1;?\s*$/;
|
|
1359
|
+
indexFile.update(indexFile.data.split('\n').filter((line)=>{
|
|
1360
|
+
const specifier = line.match(exportLine)?.[2];
|
|
1361
|
+
return !specifier || external_node_path_default().resolve(external_node_path_default().dirname(indexFile.path), specifier) !== newMainFile.replace(codeExtension, '');
|
|
1362
|
+
}).join('\n'));
|
|
1363
|
+
if (!plan.updated.includes(indexFile.path)) plan.updated.push(indexFile.path);
|
|
1364
|
+
for (const [file] of barrelImporters){
|
|
1365
|
+
const importer = new file_system_File(file);
|
|
1366
|
+
let content = importer.data;
|
|
1367
|
+
for (const match of content.matchAll(namedImports)){
|
|
1368
|
+
const [statement, typeOnly = '', names, quote, specifier] = match;
|
|
1369
|
+
if (!isOldBarrel(resolve(specifier, file)?.resolved)) continue;
|
|
1370
|
+
const items = names.split(',').map((item)=>item.trim()).filter((item)=>!!item);
|
|
1371
|
+
const own = new RegExp(`^(?:type\\s+)?${newNaming.ClassName}(?:\\s+as\\s+[\\w$]+)?$`);
|
|
1372
|
+
const moved = items.filter((item)=>own.test(item));
|
|
1373
|
+
if (!moved.length) continue;
|
|
1374
|
+
const rest = items.filter((item)=>!own.test(item));
|
|
1375
|
+
const direct = `import ${typeOnly}{ ${moved.join(', ')} } from ${quote}${projectRelative(file, newMainFile)}${quote}`;
|
|
1376
|
+
content = content.replace(statement, rest.length ? `import ${typeOnly}{ ${rest.join(', ')} } from ${quote}${specifier}${quote}\n${direct}` : direct);
|
|
1377
|
+
}
|
|
1378
|
+
importer.update(content);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
if (target.aggregate && (target.aggregate !== unit.aggregate || target.ownerPath !== unit.ownerPath)) {
|
|
1382
|
+
const kindFolder = 'entity' === unit.kind ? 'entities' : 'value-objects';
|
|
1383
|
+
const indexFile = new file_system_File(external_node_path_default().join(target.ownerPath, 'domain/aggregates', target.aggregate, 'index.ts'));
|
|
1384
|
+
indexFile.addLineIfMissing(`export * from './${kindFolder}/${target.name}.${unit.kind}'`);
|
|
1385
|
+
if (!plan.updated.includes(indexFile.path)) plan.updated.push(indexFile.path);
|
|
1386
|
+
}
|
|
1387
|
+
return plan;
|
|
1388
|
+
};
|
|
1389
|
+
const projectRelative = (fromFile, toFile)=>{
|
|
1390
|
+
const relative = module_move_toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toFile.replace(codeExtension, '')));
|
|
1391
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
1392
|
+
};
|
|
1393
|
+
const noAggregate = 'No aggregate';
|
|
1394
|
+
const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
1395
|
+
const root = new project_root_ProjectRoot().path;
|
|
1396
|
+
const rootFolderPath = external_node_path_default().join(root, config_file_ConfigFile.Instance.data.rootFolder);
|
|
1397
|
+
const sharedKernelPath = external_node_path_default().join(rootFolderPath, 'shared-kernel');
|
|
1398
|
+
const units = findBackendUnits(ownerFolder.path);
|
|
1399
|
+
if (!units.length) return void console.log('No modules generated by df-scaffold were found here.');
|
|
1400
|
+
const unit = await (0, prompts_namespaceObject.select)({
|
|
1401
|
+
message: 'Module:',
|
|
1402
|
+
choices: Object.keys(kindLayouts).flatMap((kind)=>{
|
|
1403
|
+
const group = units.filter((x)=>x.kind === kind);
|
|
1404
|
+
return group.length ? [
|
|
1405
|
+
new prompts_namespaceObject.Separator(`── ${kindLayouts[group[0].kind].title}`),
|
|
1406
|
+
...group.map((value)=>({
|
|
1407
|
+
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
1408
|
+
value
|
|
1409
|
+
}))
|
|
1410
|
+
] : [];
|
|
1411
|
+
}),
|
|
1412
|
+
pageSize: 20
|
|
1413
|
+
});
|
|
1414
|
+
const placeName = (ownerPath)=>ownerPath === sharedKernelPath ? 'Shared Kernel' : `Bounded Context: ${external_node_path_default().basename(ownerPath)}`;
|
|
1415
|
+
const contexts = new file_system_Folder(rootFolderPath).subitem([
|
|
1416
|
+
'bounded-contexts'
|
|
1417
|
+
]).content.subfolderNames.map((name)=>external_node_path_default().join(rootFolderPath, 'bounded-contexts', name));
|
|
1418
|
+
const places = [
|
|
1419
|
+
unit.ownerPath,
|
|
1420
|
+
...contexts,
|
|
1421
|
+
...kindLayouts[unit.kind].sharedKernel ? [
|
|
1422
|
+
sharedKernelPath
|
|
1423
|
+
] : []
|
|
1424
|
+
].filter((place, index, all)=>all.indexOf(place) === index);
|
|
1425
|
+
const ownerPath = await (0, prompts_namespaceObject.select)({
|
|
1426
|
+
message: 'Move to:',
|
|
1427
|
+
choices: places.map((value)=>({
|
|
1428
|
+
name: value === unit.ownerPath ? `${placeName(value)} (stays)` : placeName(value),
|
|
1429
|
+
value
|
|
1501
1430
|
}))
|
|
1502
1431
|
});
|
|
1432
|
+
let aggregate;
|
|
1433
|
+
const aggregates = ownerPath === sharedKernelPath ? [] : aggregatesOf(ownerPath);
|
|
1434
|
+
if (('entity' === unit.kind || 'value-object' === unit.kind) && aggregates.length) {
|
|
1435
|
+
const picked = await (0, prompts_namespaceObject.select)({
|
|
1436
|
+
message: 'Aggregate:',
|
|
1437
|
+
choices: [
|
|
1438
|
+
noAggregate,
|
|
1439
|
+
...aggregates
|
|
1440
|
+
],
|
|
1441
|
+
default: ownerPath === unit.ownerPath && unit.aggregate ? unit.aggregate : noAggregate
|
|
1442
|
+
});
|
|
1443
|
+
aggregate = picked === noAggregate ? void 0 : picked;
|
|
1444
|
+
}
|
|
1445
|
+
const target = (name)=>({
|
|
1446
|
+
ownerPath,
|
|
1447
|
+
aggregate,
|
|
1448
|
+
name: name.trim()
|
|
1449
|
+
});
|
|
1503
1450
|
const name = await (0, prompts_namespaceObject.input)({
|
|
1504
|
-
message: 'New name
|
|
1505
|
-
default:
|
|
1506
|
-
validate: (value)=>
|
|
1451
|
+
message: 'New name:',
|
|
1452
|
+
default: unit.name,
|
|
1453
|
+
validate: (value)=>validateBackendMove(unit, target(value), sharedKernelPath)
|
|
1507
1454
|
});
|
|
1508
|
-
const
|
|
1509
|
-
|
|
1510
|
-
|
|
1455
|
+
const result = moveBackendUnit(root, rootFolderPath, unit, target(name));
|
|
1456
|
+
if (result.violations) return void console.log([
|
|
1457
|
+
"Nothing was moved: these imports would cross a bounded context boundary.",
|
|
1458
|
+
...result.violations.map(([from, to])=>` ${from} → ${to}`),
|
|
1459
|
+
'Give the other context its own query or command, or move what it depends on first.'
|
|
1460
|
+
].join('\n'));
|
|
1511
1461
|
const relative = (file)=>external_node_path_default().relative(root, file);
|
|
1512
1462
|
console.log([
|
|
1513
1463
|
'Files to move:',
|
|
1514
|
-
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
1515
|
-
...updated.length ? [
|
|
1516
|
-
'Files with updated imports:',
|
|
1517
|
-
...updated.map((file)=>` ${relative(file)}`)
|
|
1464
|
+
...result.moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
1465
|
+
...result.updated.length ? [
|
|
1466
|
+
'Files with updated imports and names:',
|
|
1467
|
+
...result.updated.map((file)=>` ${relative(file)}`)
|
|
1518
1468
|
] : []
|
|
1519
1469
|
].join('\n'));
|
|
1520
1470
|
if (!await (0, prompts_namespaceObject.confirm)({
|
|
1521
1471
|
message: 'Apply?',
|
|
1522
1472
|
default: true
|
|
1523
1473
|
})) {
|
|
1524
|
-
|
|
1474
|
+
file_system_discardPendingChanges();
|
|
1525
1475
|
console.log('Cancelled: nothing was written.');
|
|
1526
1476
|
}
|
|
1527
1477
|
};
|
|
@@ -1529,7 +1479,7 @@ const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
|
1529
1479
|
const aggregateName = await (0, prompts_namespaceObject.input)({
|
|
1530
1480
|
message: 'Aggregate name:'
|
|
1531
1481
|
});
|
|
1532
|
-
const aggregateNaming = new
|
|
1482
|
+
const aggregateNaming = new unknown_format_naming_UnknownFormatNaming(aggregateName);
|
|
1533
1483
|
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
1534
1484
|
const withRepository = await (0, prompts_namespaceObject.confirm)({
|
|
1535
1485
|
message: 'With Repository'
|
|
@@ -1588,7 +1538,7 @@ describe('${aggregateNaming.withSpaces}', () => {
|
|
|
1588
1538
|
testImplementationType
|
|
1589
1539
|
].filter((x)=>!!x);
|
|
1590
1540
|
for (const implementation of implementationTypes){
|
|
1591
|
-
const naming = new
|
|
1541
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(implementation);
|
|
1592
1542
|
const repositoryFolder = infrastructureRepositoriesFolder.subitem([
|
|
1593
1543
|
naming.fileName
|
|
1594
1544
|
]);
|
|
@@ -1617,7 +1567,7 @@ export class ${naming.ClassName}${aggregateNaming.ClassName}Repository implement
|
|
|
1617
1567
|
`.trim());
|
|
1618
1568
|
}
|
|
1619
1569
|
if (scaffoldUnitTests) {
|
|
1620
|
-
const implementationNaming = new
|
|
1570
|
+
const implementationNaming = new unknown_format_naming_UnknownFormatNaming(infrastructureImplementationType);
|
|
1621
1571
|
const specFile = aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
|
|
1622
1572
|
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
1623
1573
|
${config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? `import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
|
|
@@ -1640,17 +1590,17 @@ describe('${aggregateNaming.withSpaces} repository', () => {
|
|
|
1640
1590
|
if (!config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') && usesInMemoryDb(infrastructureImplementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${aggregateNaming.ClassName}Repository`);
|
|
1641
1591
|
}
|
|
1642
1592
|
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
1643
|
-
const implementationNaming = new
|
|
1644
|
-
const testImplementationNaming = new
|
|
1593
|
+
const implementationNaming = new unknown_format_naming_UnknownFormatNaming(infrastructureImplementationType);
|
|
1594
|
+
const testImplementationNaming = new unknown_format_naming_UnknownFormatNaming(testImplementationType);
|
|
1645
1595
|
const wireFile = boundedContextFolder.subitem([
|
|
1646
1596
|
'wiring',
|
|
1647
1597
|
'repositories'
|
|
1648
1598
|
]).createFile(`wire-${aggregateNaming.fileName}-repository.ts`, `
|
|
1649
1599
|
import { wireClass } from '@domain-first/wire'
|
|
1650
|
-
import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
|
|
1651
|
-
${implementationTypes.map((x)=>new
|
|
1600
|
+
import { envBranchedWire } from '../../../../shared-kernel/wiring/env-branched-wire'
|
|
1601
|
+
${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${aggregateNaming.ClassName}Repository } from '../../infrastructure/repositories/${fileName}/${fileName}-${aggregateNaming.fileName}-repository'`).join('\n')}
|
|
1652
1602
|
|
|
1653
|
-
${implementationTypes.map((x)=>new
|
|
1603
|
+
${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${aggregateNaming.ClassName}Repository, [])`).join('\n\n')}
|
|
1654
1604
|
|
|
1655
1605
|
export const wire${aggregateNaming.ClassName}Repository = envBranchedWire({
|
|
1656
1606
|
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
@@ -1671,7 +1621,7 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
|
|
|
1671
1621
|
const name = await (0, prompts_namespaceObject.input)({
|
|
1672
1622
|
message: 'Name: '
|
|
1673
1623
|
});
|
|
1674
|
-
const naming = new
|
|
1624
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(name);
|
|
1675
1625
|
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
1676
1626
|
const wiringFolder = boundedContextFolder.subitem([
|
|
1677
1627
|
'wiring',
|
|
@@ -1707,7 +1657,7 @@ export abstract class ${naming.ClassName} {
|
|
|
1707
1657
|
testImplementationType
|
|
1708
1658
|
].filter((x)=>!!x);
|
|
1709
1659
|
for (const implementation of implementationTypes){
|
|
1710
|
-
const currentNaming = new
|
|
1660
|
+
const currentNaming = new unknown_format_naming_UnknownFormatNaming(`${implementation}-${naming.fileName}`);
|
|
1711
1661
|
infrastructureFolder.subitem([
|
|
1712
1662
|
implementation
|
|
1713
1663
|
]).createFile(`${currentNaming.fileName}.ts`, `
|
|
@@ -1719,7 +1669,7 @@ export class ${currentNaming.ClassName} extends ${naming.ClassName} {
|
|
|
1719
1669
|
`.trim());
|
|
1720
1670
|
}
|
|
1721
1671
|
if (scaffoldUnitTests) {
|
|
1722
|
-
const implementationNaming = new
|
|
1672
|
+
const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
|
|
1723
1673
|
applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
|
|
1724
1674
|
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
1725
1675
|
${config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? `import { type ${naming.ClassName} } from './${naming.fileName}'
|
|
@@ -1743,21 +1693,21 @@ describe('${naming.withSpaces}', () => {
|
|
|
1743
1693
|
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
1744
1694
|
const wireFile = wiringFolder.createFile(`wire-${naming.fileName}.ts`, `
|
|
1745
1695
|
import { wireClass } from '@domain-first/wire'
|
|
1746
|
-
import { envBranchedWire } from '../../../${'shared' === boundedContextFolder.name ? '' : '../'}shared/wiring/env-branched-wire'
|
|
1696
|
+
import { envBranchedWire } from '../../../${'shared-kernel' === boundedContextFolder.name ? '' : '../'}shared-kernel/wiring/env-branched-wire'
|
|
1747
1697
|
${implementationTypes.map((x)=>({
|
|
1748
|
-
naming: new
|
|
1698
|
+
naming: new unknown_format_naming_UnknownFormatNaming(`${x}-${naming.fileName}`),
|
|
1749
1699
|
implementation: x
|
|
1750
1700
|
})).map(({ naming: { ClassName, fileName }, implementation })=>`import { ${ClassName} } from '../../infrastructure/application-adapters/${implementation}/${fileName}'`).join('\n')}
|
|
1751
1701
|
|
|
1752
1702
|
${implementationTypes.map((x)=>({
|
|
1753
|
-
naming: new
|
|
1703
|
+
naming: new unknown_format_naming_UnknownFormatNaming(`${x}-${naming.fileName}`),
|
|
1754
1704
|
implementation: x
|
|
1755
|
-
})).map(({ naming: { ClassName }, implementation })=>`const wire${new
|
|
1705
|
+
})).map(({ naming: { ClassName }, implementation })=>`const wire${new unknown_format_naming_UnknownFormatNaming(implementation).ClassName}Implementation = wireClass(${ClassName}, [])`).join('\n\n')}
|
|
1756
1706
|
|
|
1757
1707
|
export const wire${naming.ClassName} = envBranchedWire({
|
|
1758
|
-
test: wire${new
|
|
1759
|
-
development: wire${new
|
|
1760
|
-
production: wire${new
|
|
1708
|
+
test: wire${new unknown_format_naming_UnknownFormatNaming(`${implementationTypes.at(-1)}-implementation`).ClassName},
|
|
1709
|
+
development: wire${new unknown_format_naming_UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName},
|
|
1710
|
+
production: wire${new unknown_format_naming_UnknownFormatNaming(`${implementationTypes.at(0)}-implementation`).ClassName}
|
|
1761
1711
|
})
|
|
1762
1712
|
|
|
1763
1713
|
`.trim());
|
|
@@ -1768,7 +1718,7 @@ const scaffoldNewApplicationService = async (boundedContextFolder)=>{
|
|
|
1768
1718
|
const name = await (0, prompts_namespaceObject.input)({
|
|
1769
1719
|
message: 'Name: '
|
|
1770
1720
|
});
|
|
1771
|
-
const naming = new
|
|
1721
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(name);
|
|
1772
1722
|
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
1773
1723
|
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
1774
1724
|
const wiringFolder = boundedContextFolder.subitem([
|
|
@@ -1826,14 +1776,6 @@ const scaffoldNewBoundedContextUseCase = async ()=>{
|
|
|
1826
1776
|
'bounded-contexts',
|
|
1827
1777
|
name
|
|
1828
1778
|
]);
|
|
1829
|
-
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/errors')) folder.subitem([
|
|
1830
|
-
'domain',
|
|
1831
|
-
'errors'
|
|
1832
|
-
]).createFile('index.ts', `
|
|
1833
|
-
import { errorNamespace } from '@domain-first/errors'
|
|
1834
|
-
|
|
1835
|
-
export const ${new UnknownFormatNaming(name).ClassName}Errors = errorNamespace('${name}')
|
|
1836
|
-
`.trim());
|
|
1837
1779
|
folder.createIfNotExisted();
|
|
1838
1780
|
};
|
|
1839
1781
|
const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
@@ -1849,7 +1791,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
1849
1791
|
message: 'Name: '
|
|
1850
1792
|
});
|
|
1851
1793
|
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
1852
|
-
const naming = new
|
|
1794
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(commandName);
|
|
1853
1795
|
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
1854
1796
|
const implementationType = await (0, prompts_namespaceObject.input)({
|
|
1855
1797
|
message: 'Command infrastructure implementation type:',
|
|
@@ -1869,7 +1811,7 @@ const scaffoldNewCommand = async (boundedContextFolder)=>{
|
|
|
1869
1811
|
testImplementationType
|
|
1870
1812
|
].filter((x)=>!!x);
|
|
1871
1813
|
for (const implementation of implementationTypes){
|
|
1872
|
-
const formatNaming = new
|
|
1814
|
+
const formatNaming = new unknown_format_naming_UnknownFormatNaming(implementation);
|
|
1873
1815
|
const implementationFile = infrastructureFolder.subitem([
|
|
1874
1816
|
formatNaming.fileName
|
|
1875
1817
|
]).createFile(`${formatNaming.fileName}-${naming.fileName}-command.ts`, config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
@@ -1915,7 +1857,7 @@ export abstract class ${naming.ClassName}Command {
|
|
|
1915
1857
|
|
|
1916
1858
|
}`.trim());
|
|
1917
1859
|
if (scaffoldUnitTests) {
|
|
1918
|
-
const implementationNaming = new
|
|
1860
|
+
const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
|
|
1919
1861
|
const specFile = commandsFolder.createFile(`${naming.fileName}-command.spec.ts`, `
|
|
1920
1862
|
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
1921
1863
|
${withWiring ? `import { type ${naming.ClassName}Command } from './${naming.fileName}-command'
|
|
@@ -1938,17 +1880,17 @@ describe('${naming.withSpaces} command', () => {
|
|
|
1938
1880
|
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Command`);
|
|
1939
1881
|
}
|
|
1940
1882
|
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
1941
|
-
const implementationNaming = new
|
|
1942
|
-
const testImplementationNaming = new
|
|
1883
|
+
const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
|
|
1884
|
+
const testImplementationNaming = new unknown_format_naming_UnknownFormatNaming(testImplementationType);
|
|
1943
1885
|
const wireFile = boundedContextFolder.subitem([
|
|
1944
1886
|
'wiring',
|
|
1945
1887
|
'commands'
|
|
1946
1888
|
]).createFile(`wire-${naming.fileName}-command.ts`, `
|
|
1947
1889
|
import { wireClass } from '@domain-first/wire'
|
|
1948
|
-
import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
|
|
1949
|
-
${implementationTypes.map((x)=>new
|
|
1890
|
+
import { envBranchedWire } from '../../../../shared-kernel/wiring/env-branched-wire'
|
|
1891
|
+
${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${naming.ClassName}Command } from '../../infrastructure/commands/${fileName}/${fileName}-${naming.fileName}-command'`).join('\n')}
|
|
1950
1892
|
|
|
1951
|
-
${implementationTypes.map((x)=>new
|
|
1893
|
+
${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Command, [])`).join('\n\n')}
|
|
1952
1894
|
|
|
1953
1895
|
export const wire${naming.ClassName}Command = envBranchedWire({
|
|
1954
1896
|
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
@@ -1959,12 +1901,12 @@ export const wire${naming.ClassName}Command = envBranchedWire({
|
|
|
1959
1901
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
1960
1902
|
}
|
|
1961
1903
|
};
|
|
1962
|
-
const
|
|
1904
|
+
const scaffold_new_domain_object_noAggregate = 'No aggregate';
|
|
1963
1905
|
const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
1964
1906
|
const name = await (0, prompts_namespaceObject.input)({
|
|
1965
1907
|
message: 'Name: '
|
|
1966
1908
|
});
|
|
1967
|
-
const naming = new
|
|
1909
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(name);
|
|
1968
1910
|
const aggregatesFolder = boundedContextFolder.subitem([
|
|
1969
1911
|
'domain',
|
|
1970
1912
|
'aggregates'
|
|
@@ -1974,11 +1916,11 @@ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
|
|
|
1974
1916
|
message: 'Aggregate:',
|
|
1975
1917
|
choices: [
|
|
1976
1918
|
...aggregateNames,
|
|
1977
|
-
|
|
1919
|
+
scaffold_new_domain_object_noAggregate
|
|
1978
1920
|
]
|
|
1979
|
-
}) :
|
|
1921
|
+
}) : scaffold_new_domain_object_noAggregate;
|
|
1980
1922
|
const kindFolderName = 'entity' === kind ? 'entities' : 'value-objects';
|
|
1981
|
-
const folder = aggregate ===
|
|
1923
|
+
const folder = aggregate === scaffold_new_domain_object_noAggregate ? boundedContextFolder.subitem([
|
|
1982
1924
|
'domain',
|
|
1983
1925
|
kindFolderName
|
|
1984
1926
|
]) : aggregatesFolder.subitem([
|
|
@@ -1993,7 +1935,7 @@ import { domainType } from '@domain-first/types'
|
|
|
1993
1935
|
export class ${naming.ClassName} extends domainType() {
|
|
1994
1936
|
|
|
1995
1937
|
}`.trim() : `export class ${naming.ClassName} {}`);
|
|
1996
|
-
if (aggregate !==
|
|
1938
|
+
if (aggregate !== scaffold_new_domain_object_noAggregate) aggregatesFolder.subitem([
|
|
1997
1939
|
aggregate
|
|
1998
1940
|
]).file('index.ts').addLineIfMissing(`export * from './${kindFolderName}/${fileName}'`);
|
|
1999
1941
|
const { testingLibrary } = config_file_ConfigFile.Instance.data;
|
|
@@ -2018,7 +1960,7 @@ const scaffoldNewDomainService = async (boundedContextFolder)=>{
|
|
|
2018
1960
|
const portName = await (0, prompts_namespaceObject.input)({
|
|
2019
1961
|
message: 'Name:'
|
|
2020
1962
|
});
|
|
2021
|
-
const naming = new
|
|
1963
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(portName);
|
|
2022
1964
|
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
2023
1965
|
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2024
1966
|
const domainServicesFolder = boundedContextFolder.subitem([
|
|
@@ -2066,14 +2008,26 @@ export const wire${naming.ClassName}DomainService = wireClass(
|
|
|
2066
2008
|
const errorNames = (boundedContextFolder)=>{
|
|
2067
2009
|
const isShared = boundedContextFolder.path === new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
2068
2010
|
config_file_ConfigFile.Instance.data.rootFolder,
|
|
2069
|
-
'shared'
|
|
2011
|
+
'shared-kernel'
|
|
2070
2012
|
]).path;
|
|
2071
2013
|
return {
|
|
2072
|
-
namespace: (namespaceName)=>`${namespaceName}${isShared ? '
|
|
2073
|
-
error: (errorName)=>`${errorName}${isShared ? '
|
|
2014
|
+
namespace: (namespaceName)=>`${namespaceName}${isShared ? 'SharedKernel' : ''}Errors`,
|
|
2015
|
+
error: (errorName)=>`${errorName}${isShared ? 'SharedKernelError' : ''}`
|
|
2074
2016
|
};
|
|
2075
2017
|
};
|
|
2076
|
-
const
|
|
2018
|
+
const namespacePattern = /export\s+const\s+(\w+)\s*=\s*errorNamespace\b/;
|
|
2019
|
+
const exportedNamespace = (file, fallback)=>namespacePattern.exec(file.data)?.[1] ?? fallback;
|
|
2020
|
+
const rootNamespace = (indexFile, namespace, code)=>{
|
|
2021
|
+
const content = indexFile.exists ? indexFile.data.trim() : '';
|
|
2022
|
+
const existing = namespacePattern.exec(content)?.[1];
|
|
2023
|
+
if (existing) return existing;
|
|
2024
|
+
indexFile.update([
|
|
2025
|
+
"import { errorNamespace } from '@domain-first/errors'",
|
|
2026
|
+
`export const ${namespace} = errorNamespace('${code}')`,
|
|
2027
|
+
content
|
|
2028
|
+
].filter((x)=>!!x).join('\n\n'));
|
|
2029
|
+
return namespace;
|
|
2030
|
+
};
|
|
2077
2031
|
const errorClass = (className, namespace, code)=>`export class ${className} extends ${namespace}.define('${code}') {}`;
|
|
2078
2032
|
const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
2079
2033
|
const currentErrorFolder = boundedContextFolder.subitem([
|
|
@@ -2081,7 +2035,7 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
2081
2035
|
'errors'
|
|
2082
2036
|
]);
|
|
2083
2037
|
const names = errorNames(boundedContextFolder);
|
|
2084
|
-
const contextNaming = new
|
|
2038
|
+
const contextNaming = new unknown_format_naming_UnknownFormatNaming(boundedContextFolder.name);
|
|
2085
2039
|
const currentErrorNamespaces = currentErrorFolder.content.fileNames.filter((x)=>'index' !== x);
|
|
2086
2040
|
const variants = [
|
|
2087
2041
|
'New error without namespace',
|
|
@@ -2096,16 +2050,16 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
|
|
|
2096
2050
|
const errorName = await (0, prompts_namespaceObject.input)({
|
|
2097
2051
|
message: 'Error name:'
|
|
2098
2052
|
});
|
|
2099
|
-
const naming = new
|
|
2053
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(errorName);
|
|
2100
2054
|
const indexFile = currentErrorFolder.file('index.ts');
|
|
2101
|
-
indexFile.addLineIfMissing(errorClass(names.error(naming.ClassName),
|
|
2055
|
+
indexFile.addLineIfMissing(errorClass(names.error(naming.ClassName), rootNamespace(indexFile, `${contextNaming.ClassName}Errors`, boundedContextFolder.name), naming.fileName), '\n\n');
|
|
2102
2056
|
return;
|
|
2103
2057
|
}
|
|
2104
2058
|
if ('New namespace' === selectedVariant) {
|
|
2105
2059
|
const namespaceName = await (0, prompts_namespaceObject.input)({
|
|
2106
2060
|
message: 'Namespace name:'
|
|
2107
2061
|
});
|
|
2108
|
-
const { ClassName, fileName } = new
|
|
2062
|
+
const { ClassName, fileName } = new unknown_format_naming_UnknownFormatNaming(namespaceName);
|
|
2109
2063
|
if (!currentErrorFolder.file(`${fileName}.ts`).exists) currentErrorFolder.createFile(`${fileName}.ts`, `
|
|
2110
2064
|
import { errorNamespace } from '@domain-first/errors'
|
|
2111
2065
|
|
|
@@ -2115,11 +2069,11 @@ export const ${names.namespace(ClassName)} = errorNamespace('${boundedContextFol
|
|
|
2115
2069
|
return;
|
|
2116
2070
|
}
|
|
2117
2071
|
const namespace = selectedVariant.substring(23);
|
|
2118
|
-
const namespaceNaming = new
|
|
2072
|
+
const namespaceNaming = new unknown_format_naming_UnknownFormatNaming(namespace);
|
|
2119
2073
|
const errorName = await (0, prompts_namespaceObject.input)({
|
|
2120
2074
|
message: 'Error name:'
|
|
2121
2075
|
});
|
|
2122
|
-
const { ClassName, fileName } = new
|
|
2076
|
+
const { ClassName, fileName } = new unknown_format_naming_UnknownFormatNaming(errorName);
|
|
2123
2077
|
const namespaceFile = currentErrorFolder.file(`${namespace}.ts`);
|
|
2124
2078
|
namespaceFile.addLineIfMissing(errorClass(names.error(`${namespaceNaming.ClassName}${ClassName}`), exportedNamespace(namespaceFile, names.namespace(namespaceNaming.ClassName)), fileName), '\n\n');
|
|
2125
2079
|
};
|
|
@@ -2186,18 +2140,18 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
2186
2140
|
...routeSegments,
|
|
2187
2141
|
method,
|
|
2188
2142
|
'endpoint'
|
|
2189
|
-
].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new
|
|
2143
|
+
].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new unknown_format_naming_UnknownFormatNaming(segment).ClassName).join('');
|
|
2190
2144
|
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2191
|
-
const endpointGenerator =
|
|
2145
|
+
const endpointGenerator = rest_endpoint_generator_findRestEndpointGenerator(boundedContextFolder.subitem([
|
|
2192
2146
|
'..',
|
|
2193
2147
|
'..',
|
|
2194
|
-
'shared'
|
|
2148
|
+
'shared-kernel'
|
|
2195
2149
|
]));
|
|
2196
2150
|
const handler = withWiring ? await promptEndpointHandler(boundedContextFolder) : void 0;
|
|
2197
2151
|
const endpointFile = external_node_path_default().join(endpointFolder.path, `${method.toUpperCase()}.ts`);
|
|
2198
2152
|
endpointFolder.createFile(`${method.toUpperCase()}.ts`, `
|
|
2199
|
-
${endpointGenerator ? `import type { ${endpointGenerator.typeName} } from '${
|
|
2200
|
-
import type { ${handler.typeName} } from '${
|
|
2153
|
+
${endpointGenerator ? `import type { ${endpointGenerator.typeName} } from '${wiring_relativeImport(endpointFile, endpointGenerator.typeFile)}'` : "import { EndpointGenerator } from '@domain-first/handlers-rest'"}${handler ? `
|
|
2154
|
+
import type { ${handler.typeName} } from '${wiring_relativeImport(endpointFile, handler.typeFile)}'` : ''}
|
|
2201
2155
|
|
|
2202
2156
|
export class ${endpointClassName} {
|
|
2203
2157
|
constructor(
|
|
@@ -2221,7 +2175,7 @@ export class ${endpointClassName} {
|
|
|
2221
2175
|
controller
|
|
2222
2176
|
]);
|
|
2223
2177
|
const wireNameBase = `wire-${nameBase}`;
|
|
2224
|
-
const wireNaming = new
|
|
2178
|
+
const wireNaming = new unknown_format_naming_UnknownFormatNaming(wireNameBase);
|
|
2225
2179
|
const wireFile = external_node_path_default().join(wiringFolder.path, `${wireNaming.fileName}.ts`);
|
|
2226
2180
|
const dependencies = endpointGenerator ? [
|
|
2227
2181
|
endpointGenerator,
|
|
@@ -2229,8 +2183,8 @@ export class ${endpointClassName} {
|
|
|
2229
2183
|
].filter((x)=>!!x) : [];
|
|
2230
2184
|
wiringFolder.createFile(`${wireNaming.fileName}.ts`, `
|
|
2231
2185
|
import { wireClass } from '@domain-first/wire'
|
|
2232
|
-
import { ${endpointClassName} } from '${
|
|
2233
|
-
${dependencies.map((x)=>`import { ${x.wireName} } from '${
|
|
2186
|
+
import { ${endpointClassName} } from '${wiring_relativeImport(wireFile, endpointFile)}'
|
|
2187
|
+
${dependencies.map((x)=>`import { ${x.wireName} } from '${wiring_relativeImport(wireFile, x.wireFile)}'`).join('\n')}
|
|
2234
2188
|
|
|
2235
2189
|
export const wire${endpointClassName} = wireClass(
|
|
2236
2190
|
${endpointClassName},
|
|
@@ -2244,7 +2198,7 @@ const scaffoldNewInfrastructureService = async (boundedContextFolder)=>{
|
|
|
2244
2198
|
const name = await (0, prompts_namespaceObject.input)({
|
|
2245
2199
|
message: 'Name: '
|
|
2246
2200
|
});
|
|
2247
|
-
const naming = new
|
|
2201
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(name);
|
|
2248
2202
|
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
2249
2203
|
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2250
2204
|
const wiringFolder = boundedContextFolder.subitem([
|
|
@@ -2303,7 +2257,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
2303
2257
|
message: 'Name: '
|
|
2304
2258
|
});
|
|
2305
2259
|
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
2306
|
-
const naming = new
|
|
2260
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(queryName);
|
|
2307
2261
|
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2308
2262
|
const implementationType = await (0, prompts_namespaceObject.input)({
|
|
2309
2263
|
message: 'Query infrastructure implementation type:',
|
|
@@ -2323,7 +2277,7 @@ const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
|
2323
2277
|
testImplementationType
|
|
2324
2278
|
].filter((x)=>!!x);
|
|
2325
2279
|
for (const implementation of implementationTypes){
|
|
2326
|
-
const formatNaming = new
|
|
2280
|
+
const formatNaming = new unknown_format_naming_UnknownFormatNaming(implementation);
|
|
2327
2281
|
const implementationFile = infrastructureFolder.subitem([
|
|
2328
2282
|
formatNaming.fileName
|
|
2329
2283
|
]).createFile(`${formatNaming.fileName}-${naming.fileName}-query.ts`, config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
@@ -2369,7 +2323,7 @@ export abstract class ${naming.ClassName}Query {
|
|
|
2369
2323
|
|
|
2370
2324
|
}`.trim());
|
|
2371
2325
|
if (scaffoldUnitTests) {
|
|
2372
|
-
const implementationNaming = new
|
|
2326
|
+
const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
|
|
2373
2327
|
const specFile = queriesFolder.createFile(`${naming.fileName}-query.spec.ts`, `
|
|
2374
2328
|
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
2375
2329
|
${withWiring ? `import { type ${naming.ClassName}Query } from './${naming.fileName}-query'
|
|
@@ -2392,17 +2346,17 @@ describe('${naming.withSpaces} query', () => {
|
|
|
2392
2346
|
if (!withWiring && usesInMemoryDb(implementationType)) passInMemoryDb(specFile, `${implementationNaming.ClassName}${naming.ClassName}Query`);
|
|
2393
2347
|
}
|
|
2394
2348
|
if (config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire')) {
|
|
2395
|
-
const implementationNaming = new
|
|
2396
|
-
const testImplementationNaming = new
|
|
2349
|
+
const implementationNaming = new unknown_format_naming_UnknownFormatNaming(implementationType);
|
|
2350
|
+
const testImplementationNaming = new unknown_format_naming_UnknownFormatNaming(testImplementationType);
|
|
2397
2351
|
const wireFile = boundedContextFolder.subitem([
|
|
2398
2352
|
'wiring',
|
|
2399
2353
|
'queries'
|
|
2400
2354
|
]).createFile(`wire-${naming.fileName}-query.ts`, `
|
|
2401
2355
|
import { wireClass } from '@domain-first/wire'
|
|
2402
|
-
import { envBranchedWire } from '../../../../shared/wiring/env-branched-wire'
|
|
2403
|
-
${implementationTypes.map((x)=>new
|
|
2356
|
+
import { envBranchedWire } from '../../../../shared-kernel/wiring/env-branched-wire'
|
|
2357
|
+
${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName, fileName })=>`import { ${ClassName}${naming.ClassName}Query } from '../../infrastructure/queries/${fileName}/${fileName}-${naming.fileName}-query'`).join('\n')}
|
|
2404
2358
|
|
|
2405
|
-
${implementationTypes.map((x)=>new
|
|
2359
|
+
${implementationTypes.map((x)=>new unknown_format_naming_UnknownFormatNaming(x)).map(({ ClassName })=>`const wire${ClassName}Implementation = wireClass(${ClassName}${naming.ClassName}Query, [])`).join('\n\n')}
|
|
2406
2360
|
|
|
2407
2361
|
export const wire${naming.ClassName}Query = envBranchedWire({
|
|
2408
2362
|
test: wire${addTestImplementation ? testImplementationNaming.ClassName : implementationNaming.ClassName}Implementation,
|
|
@@ -2421,7 +2375,7 @@ const scaffoldNewUseCase = async (boundedContextFolder)=>{
|
|
|
2421
2375
|
const useCaseName = await (0, prompts_namespaceObject.input)({
|
|
2422
2376
|
message: 'Name: '
|
|
2423
2377
|
});
|
|
2424
|
-
const naming = new
|
|
2378
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(useCaseName);
|
|
2425
2379
|
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
2426
2380
|
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2427
2381
|
useCasesFolder.createFile(`${naming.fileName}-use-case.ts`, config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/handlers') ? `
|
|
@@ -2480,197 +2434,10 @@ export const wire${naming.ClassName}UseCase = wireClass(
|
|
|
2480
2434
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
2481
2435
|
}
|
|
2482
2436
|
};
|
|
2483
|
-
const scaffoldReactSharedHook = async (presentationReactFolder)=>{
|
|
2484
|
-
const name = await (0, prompts_namespaceObject.input)({
|
|
2485
|
-
message: 'Name without "use" (e.g. debounce): '
|
|
2486
|
-
});
|
|
2487
|
-
const { ClassName, fileName } = new UnknownFormatNaming(name.trim().replace(/^use-/, ''));
|
|
2488
|
-
presentationReactFolder.subitem([
|
|
2489
|
-
'hooks'
|
|
2490
|
-
]).createFile(`use-${fileName}.ts`, `
|
|
2491
|
-
export const use${ClassName} = () => {
|
|
2492
|
-
return {}
|
|
2493
|
-
}
|
|
2494
|
-
`.trim());
|
|
2495
|
-
};
|
|
2496
|
-
const scaffoldReactUIKitComponent = async (presentationReactFolder)=>{
|
|
2497
|
-
const name = await (0, prompts_namespaceObject.input)({
|
|
2498
|
-
message: 'Name: '
|
|
2499
|
-
});
|
|
2500
|
-
const { ClassName, fileName } = new UnknownFormatNaming(name);
|
|
2501
|
-
const componentFolder = presentationReactFolder.subitem([
|
|
2502
|
-
'ui-kit',
|
|
2503
|
-
fileName
|
|
2504
|
-
]);
|
|
2505
|
-
componentFolder.createFile('index.ts', `export * from './${fileName}'`);
|
|
2506
|
-
componentFolder.createFile(`${fileName}.tsx`, `
|
|
2507
|
-
import { type FC } from 'react'
|
|
2508
|
-
|
|
2509
|
-
export type ${ClassName}Props = {}
|
|
2510
|
-
|
|
2511
|
-
export const ${ClassName}: FC<${ClassName}Props> = (props) => {
|
|
2512
|
-
return <></>
|
|
2513
|
-
}
|
|
2514
|
-
`.trim());
|
|
2515
|
-
const { storybookFramework } = config_file_ConfigFile.Instance.data;
|
|
2516
|
-
if (storybookFramework) componentFolder.createFile(`${fileName}.stories.tsx`, `
|
|
2517
|
-
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
2518
|
-
import { ${ClassName} } from './${fileName}'
|
|
2519
|
-
|
|
2520
|
-
const meta = {
|
|
2521
|
-
title: 'UI-kit/${ClassName}',
|
|
2522
|
-
component: ${ClassName}
|
|
2523
|
-
} satisfies Meta<typeof ${ClassName}>
|
|
2524
|
-
|
|
2525
|
-
export default meta
|
|
2526
|
-
|
|
2527
|
-
type Story = StoryObj<typeof meta>
|
|
2528
|
-
|
|
2529
|
-
export const Default: Story = {
|
|
2530
|
-
args: {}
|
|
2531
|
-
}
|
|
2532
|
-
`.trim());
|
|
2533
|
-
};
|
|
2534
|
-
const scaffoldReactWidget = async (presentationReactFolder)=>{
|
|
2535
|
-
const widgetName = await (0, prompts_namespaceObject.input)({
|
|
2536
|
-
message: 'Name (folders split by "/"): ',
|
|
2537
|
-
validate: NestedName.validate
|
|
2538
|
-
});
|
|
2539
|
-
const widgetType = await (0, prompts_namespaceObject.select)({
|
|
2540
|
-
choices: [
|
|
2541
|
-
'monolithic',
|
|
2542
|
-
'with separated ui',
|
|
2543
|
-
'headless'
|
|
2544
|
-
],
|
|
2545
|
-
message: 'Type: '
|
|
2546
|
-
});
|
|
2547
|
-
const { folders, folderName, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
|
|
2548
|
-
const folder = presentationReactFolder.subitem([
|
|
2549
|
-
'widgets',
|
|
2550
|
-
...folders,
|
|
2551
|
-
folderName
|
|
2552
|
-
]);
|
|
2553
|
-
const storyTitle = [
|
|
2554
|
-
'Widgets',
|
|
2555
|
-
...classNameSegments
|
|
2556
|
-
].join('/');
|
|
2557
|
-
const widgetFileName = `${fileName}-widget`;
|
|
2558
|
-
const uiFileName = `${fileName}-widget-ui`;
|
|
2559
|
-
const uiModelFileName = `use-${fileName}-ui-model`;
|
|
2560
|
-
folder.createFile('index.ts', `export * from './${widgetFileName}'`);
|
|
2561
|
-
switch(widgetType){
|
|
2562
|
-
case 'monolithic':
|
|
2563
|
-
folder.createFile(`${widgetFileName}.tsx`, `
|
|
2564
|
-
import { type FC } from 'react'
|
|
2565
|
-
|
|
2566
|
-
export type ${ClassName}WidgetProps = {}
|
|
2567
|
-
|
|
2568
|
-
export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
|
|
2569
|
-
return <></>
|
|
2570
|
-
}
|
|
2571
|
-
`.trim());
|
|
2572
|
-
break;
|
|
2573
|
-
case 'with separated ui':
|
|
2574
|
-
{
|
|
2575
|
-
folder.createFile('types.ts', `
|
|
2576
|
-
export type ${ClassName}WidgetProps = { }
|
|
2577
|
-
|
|
2578
|
-
export type ${ClassName}WidgetUIProps = { }
|
|
2579
|
-
`.trim());
|
|
2580
|
-
folder.createFile(`${widgetFileName}.tsx`, `
|
|
2581
|
-
import { type FC } from 'react'
|
|
2582
|
-
import type { ${ClassName}WidgetProps } from './types'
|
|
2583
|
-
import { ${ClassName}WidgetUI } from './ui/${uiFileName}'
|
|
2584
|
-
import { use${ClassName}UIModel } from './hooks/${uiModelFileName}'
|
|
2585
|
-
|
|
2586
|
-
export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
|
|
2587
|
-
const uiModel = use${ClassName}UIModel(props)
|
|
2588
|
-
return <${ClassName}WidgetUI {...uiModel} />
|
|
2589
|
-
}
|
|
2590
|
-
|
|
2591
|
-
export type { ${ClassName}WidgetProps }
|
|
2592
|
-
`.trim());
|
|
2593
|
-
folder.subitem([
|
|
2594
|
-
'ui'
|
|
2595
|
-
]).createFile(`${uiFileName}.tsx`, `
|
|
2596
|
-
import { FC } from 'react'
|
|
2597
|
-
import type { ${ClassName}WidgetUIProps } from '../types'
|
|
2598
|
-
|
|
2599
|
-
export const ${ClassName}WidgetUI: FC<${ClassName}WidgetUIProps> = (props) => {
|
|
2600
|
-
return <></>
|
|
2601
|
-
}
|
|
2602
|
-
`.trim());
|
|
2603
|
-
const { storybookFramework } = config_file_ConfigFile.Instance.data;
|
|
2604
|
-
if (storybookFramework) folder.subitem([
|
|
2605
|
-
'ui'
|
|
2606
|
-
]).createFile(`${uiFileName}.stories.tsx`, `
|
|
2607
|
-
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
2608
|
-
import { ${ClassName}WidgetUI } from './${uiFileName}'
|
|
2609
|
-
|
|
2610
|
-
const meta = {
|
|
2611
|
-
title: '${storyTitle}',
|
|
2612
|
-
component: ${ClassName}WidgetUI
|
|
2613
|
-
} satisfies Meta<typeof ${ClassName}WidgetUI>
|
|
2614
|
-
|
|
2615
|
-
export default meta
|
|
2616
|
-
|
|
2617
|
-
type Story = StoryObj<typeof meta>
|
|
2618
|
-
|
|
2619
|
-
export const Default: Story = {
|
|
2620
|
-
args: {}
|
|
2621
|
-
}
|
|
2622
|
-
`.trim());
|
|
2623
|
-
folder.subitem([
|
|
2624
|
-
'hooks'
|
|
2625
|
-
]).createFile(`${uiModelFileName}.ts`, `
|
|
2626
|
-
import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
|
|
2627
|
-
|
|
2628
|
-
export const use${ClassName}UIModel = (widgetProps: ${ClassName}WidgetProps): ${ClassName}WidgetUIProps => {
|
|
2629
|
-
return {}
|
|
2630
|
-
}
|
|
2631
|
-
`.trim());
|
|
2632
|
-
break;
|
|
2633
|
-
}
|
|
2634
|
-
case 'headless':
|
|
2635
|
-
folder.createFile('types.ts', `
|
|
2636
|
-
import { type FC } from 'react'
|
|
2637
|
-
|
|
2638
|
-
export type ${ClassName}WidgetUIProps = { }
|
|
2639
|
-
|
|
2640
|
-
export type ${ClassName}WidgetProps = {
|
|
2641
|
-
UI: FC<${ClassName}WidgetUIProps>
|
|
2642
|
-
}
|
|
2643
|
-
|
|
2644
|
-
`.trim());
|
|
2645
|
-
folder.createFile(`${widgetFileName}.tsx`, `
|
|
2646
|
-
import { type FC } from 'react'
|
|
2647
|
-
import type { ${ClassName}WidgetProps } from './types'
|
|
2648
|
-
import { use${ClassName}UIModel } from './hooks/${uiModelFileName}'
|
|
2649
|
-
|
|
2650
|
-
export const ${ClassName}Widget: FC<${ClassName}WidgetProps> = (props) => {
|
|
2651
|
-
const uiModel = use${ClassName}UIModel(props)
|
|
2652
|
-
return <props.UI {...uiModel} />
|
|
2653
|
-
}
|
|
2654
|
-
|
|
2655
|
-
export type { ${ClassName}WidgetProps }
|
|
2656
|
-
`.trim());
|
|
2657
|
-
folder.subitem([
|
|
2658
|
-
'hooks'
|
|
2659
|
-
]).createFile(`${uiModelFileName}.ts`, `
|
|
2660
|
-
import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
|
|
2661
|
-
|
|
2662
|
-
export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps, 'UI'>): ${ClassName}WidgetUIProps => {
|
|
2663
|
-
return {}
|
|
2664
|
-
}
|
|
2665
|
-
`.trim());
|
|
2666
|
-
break;
|
|
2667
|
-
}
|
|
2668
|
-
};
|
|
2669
2437
|
const main = async ()=>{
|
|
2670
2438
|
if (!config_file_ConfigFile.exists) {
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
return;
|
|
2439
|
+
console.log('No domain-first.project-structure.config.json found: run df-init first to initialize the project.');
|
|
2440
|
+
process.exit(1);
|
|
2674
2441
|
}
|
|
2675
2442
|
const rootPath = new project_root_ProjectRoot().path;
|
|
2676
2443
|
const currentBoundedContextOptions = new file_system_Folder(rootPath).subitem([
|
|
@@ -2686,57 +2453,18 @@ const main = async ()=>{
|
|
|
2686
2453
|
};
|
|
2687
2454
|
const options = [
|
|
2688
2455
|
...currentBoundedContextOptions,
|
|
2689
|
-
config_file_ConfigFile.Instance.data.useReact ? {
|
|
2690
|
-
name: 'Scaffold React module',
|
|
2691
|
-
action: 'Scaffold React module'
|
|
2692
|
-
} : void 0,
|
|
2693
2456
|
{
|
|
2694
|
-
name: 'Shared
|
|
2457
|
+
name: 'Shared Kernel',
|
|
2695
2458
|
action: 'Scaffold in bounded context'
|
|
2696
2459
|
},
|
|
2697
2460
|
scaffoldNewBoundedContext
|
|
2698
|
-
]
|
|
2461
|
+
];
|
|
2699
2462
|
const result = await (0, prompts_namespaceObject.select)({
|
|
2700
2463
|
message: '@domain-first/project-structure',
|
|
2701
2464
|
choices: options.map((x)=>x.name)
|
|
2702
2465
|
});
|
|
2703
2466
|
const { action, name } = options.find((x)=>x.name === result);
|
|
2704
2467
|
switch(action){
|
|
2705
|
-
case 'Scaffold React module':
|
|
2706
|
-
{
|
|
2707
|
-
const reactFolder = new file_system_Folder(rootPath).subitem([
|
|
2708
|
-
config_file_ConfigFile.Instance.data.rootFolder,
|
|
2709
|
-
'presentation',
|
|
2710
|
-
'react'
|
|
2711
|
-
]);
|
|
2712
|
-
const action = await (0, prompts_namespaceObject.select)({
|
|
2713
|
-
message: 'Module: ',
|
|
2714
|
-
choices: [
|
|
2715
|
-
'New widget',
|
|
2716
|
-
'New page',
|
|
2717
|
-
'New UI-kit component',
|
|
2718
|
-
'New shared hook',
|
|
2719
|
-
'Move or rename widget',
|
|
2720
|
-
'Move or rename page'
|
|
2721
|
-
]
|
|
2722
|
-
});
|
|
2723
|
-
switch(action){
|
|
2724
|
-
case 'New widget':
|
|
2725
|
-
return void await scaffoldReactWidget(reactFolder);
|
|
2726
|
-
case 'New page':
|
|
2727
|
-
return void await scaffoldReactPage(reactFolder);
|
|
2728
|
-
case 'New UI-kit component':
|
|
2729
|
-
return void await scaffoldReactUIKitComponent(reactFolder);
|
|
2730
|
-
case 'New shared hook':
|
|
2731
|
-
return void await scaffoldReactSharedHook(reactFolder);
|
|
2732
|
-
case 'Move or rename widget':
|
|
2733
|
-
return void await moveReactModuleUseCase(reactFolder, 'widget');
|
|
2734
|
-
case 'Move or rename page':
|
|
2735
|
-
return void await moveReactModuleUseCase(reactFolder, 'page');
|
|
2736
|
-
default:
|
|
2737
|
-
return;
|
|
2738
|
-
}
|
|
2739
|
-
}
|
|
2740
2468
|
case 'Scaffold new bounded context':
|
|
2741
2469
|
return void await scaffoldNewBoundedContextUseCase();
|
|
2742
2470
|
case 'Scaffold in bounded context':
|
|
@@ -2748,7 +2476,7 @@ const main = async ()=>{
|
|
|
2748
2476
|
name.substring(17)
|
|
2749
2477
|
] : [
|
|
2750
2478
|
config_file_ConfigFile.Instance.data.rootFolder,
|
|
2751
|
-
'shared'
|
|
2479
|
+
'shared-kernel'
|
|
2752
2480
|
]);
|
|
2753
2481
|
const layer = await (0, prompts_namespaceObject.select)({
|
|
2754
2482
|
message: 'Layer:',
|
|
@@ -2757,10 +2485,12 @@ const main = async ()=>{
|
|
|
2757
2485
|
'Application',
|
|
2758
2486
|
'Infrastructure',
|
|
2759
2487
|
'Presentation',
|
|
2760
|
-
config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? 'Wire dependency' : void 0
|
|
2488
|
+
config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire') ? 'Wire dependency' : void 0,
|
|
2489
|
+
'Move or rename'
|
|
2761
2490
|
].filter((x)=>!!x)
|
|
2762
2491
|
});
|
|
2763
2492
|
if ('Wire dependency' === layer) return void await wireDependency(boundedContextFolder);
|
|
2493
|
+
if ('Move or rename' === layer) return void await moveBackendUnitUseCase(boundedContextFolder);
|
|
2764
2494
|
if ('Domain' === layer) {
|
|
2765
2495
|
const operation = await (0, prompts_namespaceObject.select)({
|
|
2766
2496
|
message: 'Domain layer operation:',
|