@domain-first/project-structure 2.9.1 → 2.10.1

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 CHANGED
@@ -84,7 +84,7 @@ A bounded context groups a business area and its implementation. Within it, each
84
84
  | `presentation/` | REST endpoints and presentation services. |
85
85
  | `wiring/` | Factories that construct components and select implementations, when `@domain-first/wire` is enabled. |
86
86
 
87
- The **Shared Layer** menu provides cross-context errors, application ports, and application, infrastructure, and presentation services under `<rootFolder>/shared`.
87
+ The **Shared Layer** menu provides cross-context errors, entities and value objects, application ports, and application, infrastructure, and presentation services under `<rootFolder>/shared`.
88
88
 
89
89
  A project using handler and wiring integrations can grow into this structure:
90
90
 
@@ -131,6 +131,7 @@ Choose a bounded context, then a layer:
131
131
  | Layer / menu option | Generated output |
132
132
  | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
133
133
  | Domain → New Aggregate | Aggregate root and barrel export; optional repository contract, primary and test implementations, tests, and repository wiring. |
134
+ | Domain → New Entity / New Value Object | Entity or value object class with tests, in the `entities/` or `value-objects/` folder of a chosen aggregate (exported from its barrel) or of the context's `domain/`. Also in the Shared Layer, under `shared/domain/`. |
134
135
  | Domain → Errors | Errors in the context namespace, nested namespaces, and exports. Uses `@domain-first/errors`. |
135
136
  | Domain → New Service | Domain service class, with optional tests and wiring. |
136
137
  | Application → New Use Case | Use case class; handler schemas and `handle` when enabled; optional tests and wiring. |
@@ -262,7 +263,7 @@ src/bounded-contexts/sales/
262
263
 
263
264
  Use lowercase kebab-case for entered names, such as `place-order` and `payment-gateway`. Names are used in paths, and class and variable names are derived from their hyphen-separated words: `place-order` becomes `PlaceOrderUseCase` for a use case.
264
265
 
265
- Generation writes files directly and can overwrite matching filenames without confirmation. Use a new name for a new component, and review the generated changes before continuing implementation.
266
+ Nothing is written until a run finishes. If the run would replace existing files, the CLI lists them and asks `Overwrite them?` (default: No). Answering No, or interrupting the CLI at any prompt, leaves the project unchanged. Lines added to existing barrels, error files, and wiring indexes are not overwrites and are never duplicated. Use a new name for a new component, and review the generated changes before continuing implementation.
266
267
 
267
268
  ## License
268
269
 
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Existing files a full rewrite would replace, whatever their content.
3
+ */
4
+ export declare const filesToOverwrite: () => string[];
5
+ export declare const writePendingChanges: () => void;
1
6
  declare class FileSystemItem {
2
7
  readonly path: string;
3
8
  constructor(path: string);
@@ -15,8 +20,13 @@ export declare class Folder extends FileSystemItem {
15
20
  file: (name: string) => File;
16
21
  }
17
22
  export declare class File extends FileSystemItem {
23
+ get exists(): boolean;
18
24
  get data(): string;
19
25
  set data(content: string);
20
26
  addLine: (newLine: string, separator?: string) => void;
27
+ /**
28
+ * Re-running a generator for the same name must not duplicate the line.
29
+ */
30
+ addLineIfMissing: (newLine: string, separator?: string) => void;
21
31
  }
22
32
  export {};
package/dist/index.cjs CHANGED
@@ -26,13 +26,31 @@ var __webpack_require__ = {};
26
26
  __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
27
27
  })();
28
28
  var __webpack_exports__ = {};
29
- const prompts_namespaceObject = require("@inquirer/prompts");
30
29
  const external_node_path_namespaceObject = require("node:path");
31
30
  var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
31
+ const prompts_namespaceObject = require("@inquirer/prompts");
32
32
  const external_zod_namespaceObject = require("zod");
33
33
  var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
34
34
  const external_node_fs_namespaceObject = require("node:fs");
35
35
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
36
+ const pendingFiles = new Map();
37
+ const pendingFolders = new Set();
38
+ const filesToOverwrite = ()=>[
39
+ ...pendingFiles
40
+ ].filter(([filePath, { replacesFile }])=>replacesFile && external_node_fs_default().existsSync(filePath)).map(([filePath])=>filePath);
41
+ const writePendingChanges = ()=>{
42
+ for (const folderPath of pendingFolders)external_node_fs_default().mkdirSync(folderPath, {
43
+ recursive: true
44
+ });
45
+ for (const [filePath, { content }] of pendingFiles){
46
+ external_node_fs_default().mkdirSync(external_node_path_default().dirname(filePath), {
47
+ recursive: true
48
+ });
49
+ external_node_fs_default().writeFileSync(filePath, content, 'utf8');
50
+ }
51
+ pendingFolders.clear();
52
+ pendingFiles.clear();
53
+ };
36
54
  class FileSystemItem {
37
55
  path;
38
56
  constructor(path){
@@ -45,9 +63,7 @@ class FileSystemItem {
45
63
  }
46
64
  class Folder extends FileSystemItem {
47
65
  createIfNotExisted = ()=>{
48
- external_node_fs_default().mkdirSync(this.path, {
49
- recursive: true
50
- });
66
+ pendingFolders.add(this.path);
51
67
  };
52
68
  get content() {
53
69
  if (!this.exists) return {
@@ -82,22 +98,34 @@ class Folder extends FileSystemItem {
82
98
  };
83
99
  }
84
100
  class File extends FileSystemItem {
101
+ get exists() {
102
+ return pendingFiles.has(this.path) || external_node_fs_default().existsSync(this.path);
103
+ }
85
104
  get data() {
105
+ const pendingFile = pendingFiles.get(this.path);
106
+ if (pendingFile) return pendingFile.content;
86
107
  if (!this.exists) throw new Error('File does not exist');
87
108
  return external_node_fs_default().readFileSync(this.path, 'utf-8');
88
109
  }
89
110
  set data(content) {
90
- external_node_fs_default().writeFileSync(this.path, content);
111
+ pendingFiles.set(this.path, {
112
+ content,
113
+ replacesFile: true
114
+ });
91
115
  }
92
116
  addLine = (newLine, separator = '\n')=>{
93
- let content = '';
94
- try {
95
- content = external_node_fs_default().readFileSync(this.path, 'utf8');
96
- } catch {}
97
- external_node_fs_default().writeFileSync(this.path, [
98
- content.trim(),
99
- newLine.trim()
100
- ].filter((x)=>!!x).join(separator), 'utf8');
117
+ const content = this.exists ? this.data : '';
118
+ pendingFiles.set(this.path, {
119
+ content: [
120
+ content.trim(),
121
+ newLine.trim()
122
+ ].filter((x)=>!!x).join(separator),
123
+ replacesFile: pendingFiles.get(this.path)?.replacesFile ?? false
124
+ });
125
+ };
126
+ addLineIfMissing = (newLine, separator = '\n')=>{
127
+ const alreadyAdded = this.exists && this.data.split('\n').some((line)=>line.trim() === newLine.trim());
128
+ if (!alreadyAdded) this.addLine(newLine, separator);
101
129
  };
102
130
  }
103
131
  class ProjectRoot {
@@ -719,6 +747,60 @@ test('can be ${withWiring ? 'wired' : 'created via constructor'}', () => {
719
747
  })
720
748
  `.trim());
721
749
  };
750
+ const noAggregate = 'No aggregate';
751
+ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
752
+ const name = await (0, prompts_namespaceObject.input)({
753
+ message: 'Name: '
754
+ });
755
+ const naming = new UnknownFormatNaming(name);
756
+ const aggregatesFolder = boundedContextFolder.subitem([
757
+ 'domain',
758
+ 'aggregates'
759
+ ]);
760
+ const aggregateNames = aggregatesFolder.content.subfolderNames;
761
+ const aggregate = aggregateNames.length ? await (0, prompts_namespaceObject.select)({
762
+ message: 'Aggregate:',
763
+ choices: [
764
+ ...aggregateNames,
765
+ noAggregate
766
+ ]
767
+ }) : noAggregate;
768
+ const kindFolderName = 'entity' === kind ? 'entities' : 'value-objects';
769
+ const folder = aggregate === noAggregate ? boundedContextFolder.subitem([
770
+ 'domain',
771
+ kindFolderName
772
+ ]) : aggregatesFolder.subitem([
773
+ aggregate,
774
+ kindFolderName
775
+ ]);
776
+ const fileName = `${naming.fileName}.${kind}`;
777
+ folder.createFile(`${fileName}.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types') ? `
778
+ import { domainType } from '@domain-first/types'
779
+
780
+ export class ${naming.ClassName} extends domainType() {
781
+
782
+ }`.trim() : `export class ${naming.ClassName} {}`);
783
+ if (aggregate !== noAggregate) aggregatesFolder.subitem([
784
+ aggregate
785
+ ]).file('index.ts').addLineIfMissing(`export * from './${kindFolderName}/${fileName}'`);
786
+ const { testingLibrary } = ConfigFile.Instance.data;
787
+ if (testingLibrary) folder.createFile(`${fileName}.spec.ts`, `
788
+ import { describe, test, expect, beforeEach } from '${testingLibrary}'
789
+ import { ${naming.ClassName} } from './${fileName}'
790
+
791
+ let ${naming.variableName}: ${naming.ClassName}
792
+
793
+ beforeEach(() => {
794
+ ${naming.variableName} = new ${naming.ClassName}()
795
+ })
796
+
797
+ describe('${naming.withSpaces}', () => {
798
+ test('can be instantiated via constructor', () => {
799
+ expect(${naming.variableName}).toBeDefined()
800
+ })
801
+ })
802
+ `.trim());
803
+ };
722
804
  const scaffoldNewDomainService = async (boundedContextFolder)=>{
723
805
  const portName = await (0, prompts_namespaceObject.input)({
724
806
  message: 'Name:'
@@ -785,7 +867,7 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
785
867
  message: 'Error name:'
786
868
  });
787
869
  const naming = new UnknownFormatNaming(errorName);
788
- currentErrorFolder.file('index.ts').addLine(`export const ${naming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${naming.fileName}')`, '\n\n');
870
+ currentErrorFolder.file('index.ts').addLineIfMissing(`export const ${naming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${naming.fileName}')`, '\n\n');
789
871
  return;
790
872
  }
791
873
  if ('New namespace' === selectedVariant) {
@@ -793,12 +875,12 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
793
875
  message: 'Namespace name:'
794
876
  });
795
877
  const { ClassName, fileName } = new UnknownFormatNaming(namespaceName);
796
- currentErrorFolder.createFile(`${fileName}.ts`, `
878
+ if (!currentErrorFolder.file(`${fileName}.ts`).exists) currentErrorFolder.createFile(`${fileName}.ts`, `
797
879
  import { errorNamespace } from '@domain-first/errors'
798
880
 
799
881
  export const ${ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors = errorNamespace('${boundedContextFolder.name}').subnamespace('${fileName}')
800
- `);
801
- currentErrorFolder.file('index.ts').addLine(`export * from './${fileName}'`, '\n\n');
882
+ `.trim());
883
+ currentErrorFolder.file('index.ts').addLineIfMissing(`export * from './${fileName}'`, '\n\n');
802
884
  return;
803
885
  }
804
886
  const namespace = selectedVariant.substring(23);
@@ -807,7 +889,7 @@ export const ${ClassName}${new UnknownFormatNaming(boundedContextFolder.name).Cl
807
889
  message: 'Error name:'
808
890
  });
809
891
  const { ClassName, fileName } = new UnknownFormatNaming(errorName);
810
- currentErrorFolder.file(`${namespace}.ts`).addLine(`export const ${ClassName}${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${fileName}')`, '\n\n');
892
+ currentErrorFolder.file(`${namespace}.ts`).addLineIfMissing(`export const ${ClassName}${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${fileName}')`, '\n\n');
811
893
  };
812
894
  const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
813
895
  const restPresentationFolder = boundedContextFolder.subitem([
@@ -1537,15 +1619,23 @@ const main = async ()=>{
1537
1619
  message: 'Domain layer operation:',
1538
1620
  choices: specificContext ? [
1539
1621
  'New Aggregate',
1622
+ 'New Entity',
1623
+ 'New Value Object',
1540
1624
  'Errors',
1541
1625
  'New Service'
1542
1626
  ] : [
1627
+ 'New Entity',
1628
+ 'New Value Object',
1543
1629
  'Errors'
1544
1630
  ]
1545
1631
  });
1546
1632
  switch(operation){
1547
1633
  case 'New Aggregate':
1548
1634
  return void await scaffoldNewAggregateUseCase(boundedContextFolder);
1635
+ case 'New Entity':
1636
+ return void await scaffoldNewDomainObject(boundedContextFolder, 'entity');
1637
+ case 'New Value Object':
1638
+ return void await scaffoldNewDomainObject(boundedContextFolder, 'value-object');
1549
1639
  case 'Errors':
1550
1640
  return void await scaffoldNewErrorUseCase(boundedContextFolder);
1551
1641
  case 'New Service':
@@ -1614,7 +1704,22 @@ const main = async ()=>{
1614
1704
  return;
1615
1705
  }
1616
1706
  };
1617
- main();
1707
+ const run = async ()=>{
1708
+ await main();
1709
+ const overwrittenFiles = filesToOverwrite();
1710
+ if (overwrittenFiles.length) {
1711
+ const root = new ProjectRoot().path;
1712
+ console.log('These files already exist and will be overwritten:');
1713
+ for (const filePath of overwrittenFiles)console.log(` ${external_node_path_default().relative(root, filePath)}`);
1714
+ const overwrite = await (0, prompts_namespaceObject.confirm)({
1715
+ message: 'Overwrite them?',
1716
+ default: false
1717
+ });
1718
+ if (!overwrite) return void console.log('Cancelled: nothing was written.');
1719
+ }
1720
+ writePendingChanges();
1721
+ };
1722
+ run();
1618
1723
  for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
1619
1724
  Object.defineProperty(exports, '__esModule', {
1620
1725
  value: true
package/dist/index.js CHANGED
@@ -1,8 +1,26 @@
1
1
  #!/usr/bin/env node
2
- import { checkbox as prompts_checkbox, confirm as prompts_confirm, input, select as prompts_select } from "@inquirer/prompts";
3
2
  import node_path from "node:path";
3
+ import { checkbox as prompts_checkbox, confirm as prompts_confirm, input, select as prompts_select } from "@inquirer/prompts";
4
4
  import zod from "zod";
5
5
  import node_fs from "node:fs";
6
+ const pendingFiles = new Map();
7
+ const pendingFolders = new Set();
8
+ const filesToOverwrite = ()=>[
9
+ ...pendingFiles
10
+ ].filter(([filePath, { replacesFile }])=>replacesFile && node_fs.existsSync(filePath)).map(([filePath])=>filePath);
11
+ const writePendingChanges = ()=>{
12
+ for (const folderPath of pendingFolders)node_fs.mkdirSync(folderPath, {
13
+ recursive: true
14
+ });
15
+ for (const [filePath, { content }] of pendingFiles){
16
+ node_fs.mkdirSync(node_path.dirname(filePath), {
17
+ recursive: true
18
+ });
19
+ node_fs.writeFileSync(filePath, content, 'utf8');
20
+ }
21
+ pendingFolders.clear();
22
+ pendingFiles.clear();
23
+ };
6
24
  class FileSystemItem {
7
25
  path;
8
26
  constructor(path){
@@ -15,9 +33,7 @@ class FileSystemItem {
15
33
  }
16
34
  class Folder extends FileSystemItem {
17
35
  createIfNotExisted = ()=>{
18
- node_fs.mkdirSync(this.path, {
19
- recursive: true
20
- });
36
+ pendingFolders.add(this.path);
21
37
  };
22
38
  get content() {
23
39
  if (!this.exists) return {
@@ -52,22 +68,34 @@ class Folder extends FileSystemItem {
52
68
  };
53
69
  }
54
70
  class File extends FileSystemItem {
71
+ get exists() {
72
+ return pendingFiles.has(this.path) || node_fs.existsSync(this.path);
73
+ }
55
74
  get data() {
75
+ const pendingFile = pendingFiles.get(this.path);
76
+ if (pendingFile) return pendingFile.content;
56
77
  if (!this.exists) throw new Error('File does not exist');
57
78
  return node_fs.readFileSync(this.path, 'utf-8');
58
79
  }
59
80
  set data(content) {
60
- node_fs.writeFileSync(this.path, content);
81
+ pendingFiles.set(this.path, {
82
+ content,
83
+ replacesFile: true
84
+ });
61
85
  }
62
86
  addLine = (newLine, separator = '\n')=>{
63
- let content = '';
64
- try {
65
- content = node_fs.readFileSync(this.path, 'utf8');
66
- } catch {}
67
- node_fs.writeFileSync(this.path, [
68
- content.trim(),
69
- newLine.trim()
70
- ].filter((x)=>!!x).join(separator), 'utf8');
87
+ const content = this.exists ? this.data : '';
88
+ pendingFiles.set(this.path, {
89
+ content: [
90
+ content.trim(),
91
+ newLine.trim()
92
+ ].filter((x)=>!!x).join(separator),
93
+ replacesFile: pendingFiles.get(this.path)?.replacesFile ?? false
94
+ });
95
+ };
96
+ addLineIfMissing = (newLine, separator = '\n')=>{
97
+ const alreadyAdded = this.exists && this.data.split('\n').some((line)=>line.trim() === newLine.trim());
98
+ if (!alreadyAdded) this.addLine(newLine, separator);
71
99
  };
72
100
  }
73
101
  class ProjectRoot {
@@ -689,6 +717,60 @@ test('can be ${withWiring ? 'wired' : 'created via constructor'}', () => {
689
717
  })
690
718
  `.trim());
691
719
  };
720
+ const noAggregate = 'No aggregate';
721
+ const scaffoldNewDomainObject = async (boundedContextFolder, kind)=>{
722
+ const name = await input({
723
+ message: 'Name: '
724
+ });
725
+ const naming = new UnknownFormatNaming(name);
726
+ const aggregatesFolder = boundedContextFolder.subitem([
727
+ 'domain',
728
+ 'aggregates'
729
+ ]);
730
+ const aggregateNames = aggregatesFolder.content.subfolderNames;
731
+ const aggregate = aggregateNames.length ? await prompts_select({
732
+ message: 'Aggregate:',
733
+ choices: [
734
+ ...aggregateNames,
735
+ noAggregate
736
+ ]
737
+ }) : noAggregate;
738
+ const kindFolderName = 'entity' === kind ? 'entities' : 'value-objects';
739
+ const folder = aggregate === noAggregate ? boundedContextFolder.subitem([
740
+ 'domain',
741
+ kindFolderName
742
+ ]) : aggregatesFolder.subitem([
743
+ aggregate,
744
+ kindFolderName
745
+ ]);
746
+ const fileName = `${naming.fileName}.${kind}`;
747
+ folder.createFile(`${fileName}.ts`, ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/types') ? `
748
+ import { domainType } from '@domain-first/types'
749
+
750
+ export class ${naming.ClassName} extends domainType() {
751
+
752
+ }`.trim() : `export class ${naming.ClassName} {}`);
753
+ if (aggregate !== noAggregate) aggregatesFolder.subitem([
754
+ aggregate
755
+ ]).file('index.ts').addLineIfMissing(`export * from './${kindFolderName}/${fileName}'`);
756
+ const { testingLibrary } = ConfigFile.Instance.data;
757
+ if (testingLibrary) folder.createFile(`${fileName}.spec.ts`, `
758
+ import { describe, test, expect, beforeEach } from '${testingLibrary}'
759
+ import { ${naming.ClassName} } from './${fileName}'
760
+
761
+ let ${naming.variableName}: ${naming.ClassName}
762
+
763
+ beforeEach(() => {
764
+ ${naming.variableName} = new ${naming.ClassName}()
765
+ })
766
+
767
+ describe('${naming.withSpaces}', () => {
768
+ test('can be instantiated via constructor', () => {
769
+ expect(${naming.variableName}).toBeDefined()
770
+ })
771
+ })
772
+ `.trim());
773
+ };
692
774
  const scaffoldNewDomainService = async (boundedContextFolder)=>{
693
775
  const portName = await input({
694
776
  message: 'Name:'
@@ -755,7 +837,7 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
755
837
  message: 'Error name:'
756
838
  });
757
839
  const naming = new UnknownFormatNaming(errorName);
758
- currentErrorFolder.file('index.ts').addLine(`export const ${naming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${naming.fileName}')`, '\n\n');
840
+ currentErrorFolder.file('index.ts').addLineIfMissing(`export const ${naming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${naming.fileName}')`, '\n\n');
759
841
  return;
760
842
  }
761
843
  if ('New namespace' === selectedVariant) {
@@ -763,12 +845,12 @@ const scaffoldNewErrorUseCase = async (boundedContextFolder)=>{
763
845
  message: 'Namespace name:'
764
846
  });
765
847
  const { ClassName, fileName } = new UnknownFormatNaming(namespaceName);
766
- currentErrorFolder.createFile(`${fileName}.ts`, `
848
+ if (!currentErrorFolder.file(`${fileName}.ts`).exists) currentErrorFolder.createFile(`${fileName}.ts`, `
767
849
  import { errorNamespace } from '@domain-first/errors'
768
850
 
769
851
  export const ${ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors = errorNamespace('${boundedContextFolder.name}').subnamespace('${fileName}')
770
- `);
771
- currentErrorFolder.file('index.ts').addLine(`export * from './${fileName}'`, '\n\n');
852
+ `.trim());
853
+ currentErrorFolder.file('index.ts').addLineIfMissing(`export * from './${fileName}'`, '\n\n');
772
854
  return;
773
855
  }
774
856
  const namespace = selectedVariant.substring(23);
@@ -777,7 +859,7 @@ export const ${ClassName}${new UnknownFormatNaming(boundedContextFolder.name).Cl
777
859
  message: 'Error name:'
778
860
  });
779
861
  const { ClassName, fileName } = new UnknownFormatNaming(errorName);
780
- currentErrorFolder.file(`${namespace}.ts`).addLine(`export const ${ClassName}${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${fileName}')`, '\n\n');
862
+ currentErrorFolder.file(`${namespace}.ts`).addLineIfMissing(`export const ${ClassName}${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Error = ${namespaceNaming.ClassName}${new UnknownFormatNaming(boundedContextFolder.name).ClassName}Errors.define('${fileName}')`, '\n\n');
781
863
  };
782
864
  const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
783
865
  const restPresentationFolder = boundedContextFolder.subitem([
@@ -1507,15 +1589,23 @@ const main = async ()=>{
1507
1589
  message: 'Domain layer operation:',
1508
1590
  choices: specificContext ? [
1509
1591
  'New Aggregate',
1592
+ 'New Entity',
1593
+ 'New Value Object',
1510
1594
  'Errors',
1511
1595
  'New Service'
1512
1596
  ] : [
1597
+ 'New Entity',
1598
+ 'New Value Object',
1513
1599
  'Errors'
1514
1600
  ]
1515
1601
  });
1516
1602
  switch(operation){
1517
1603
  case 'New Aggregate':
1518
1604
  return void await scaffoldNewAggregateUseCase(boundedContextFolder);
1605
+ case 'New Entity':
1606
+ return void await scaffoldNewDomainObject(boundedContextFolder, 'entity');
1607
+ case 'New Value Object':
1608
+ return void await scaffoldNewDomainObject(boundedContextFolder, 'value-object');
1519
1609
  case 'Errors':
1520
1610
  return void await scaffoldNewErrorUseCase(boundedContextFolder);
1521
1611
  case 'New Service':
@@ -1584,4 +1674,19 @@ const main = async ()=>{
1584
1674
  return;
1585
1675
  }
1586
1676
  };
1587
- main();
1677
+ const run = async ()=>{
1678
+ await main();
1679
+ const overwrittenFiles = filesToOverwrite();
1680
+ if (overwrittenFiles.length) {
1681
+ const root = new ProjectRoot().path;
1682
+ console.log('These files already exist and will be overwritten:');
1683
+ for (const filePath of overwrittenFiles)console.log(` ${node_path.relative(root, filePath)}`);
1684
+ const overwrite = await prompts_confirm({
1685
+ message: 'Overwrite them?',
1686
+ default: false
1687
+ });
1688
+ if (!overwrite) return void console.log('Cancelled: nothing was written.');
1689
+ }
1690
+ writePendingChanges();
1691
+ };
1692
+ run();
@@ -4,6 +4,7 @@ export * from './scaffold-new-application-port';
4
4
  export * from './scaffold-new-application-service';
5
5
  export * from './scaffold-new-bounded-context';
6
6
  export * from './scaffold-new-command';
7
+ export * from './scaffold-new-domain-object';
7
8
  export * from './scaffold-new-domain-service';
8
9
  export * from './scaffold-new-error';
9
10
  export * from './scaffold-new-handlers-rest-endpoint';
@@ -0,0 +1,2 @@
1
+ import type { Folder } from '../file-system';
2
+ export declare const scaffoldNewDomainObject: (boundedContextFolder: Folder, kind: "entity" | "value-object") => Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@domain-first/project-structure",
3
3
  "description": "Build and manage your Domain-First project structure with CLI",
4
- "version": "2.9.1",
4
+ "version": "2.10.1",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",