@domain-first/project-structure 2.1.0 → 2.3.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/dist/config-file.d.ts +1 -0
- package/dist/index.cjs +75 -3
- package/dist/index.js +75 -3
- package/dist/unknown-format-naming.d.ts +1 -0
- package/package.json +1 -1
package/dist/config-file.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare const configSchema: z.ZodObject<{
|
|
|
10
10
|
}>>;
|
|
11
11
|
defaultPersistenceLayerImplementation: z.ZodString;
|
|
12
12
|
useReact: z.ZodBoolean;
|
|
13
|
+
testingLibrary: z.ZodOptional<z.ZodString>;
|
|
13
14
|
}, z.core.$strip>;
|
|
14
15
|
export declare class ConfigFile {
|
|
15
16
|
readonly data: z.infer<typeof configSchema>;
|
package/dist/index.cjs
CHANGED
|
@@ -125,7 +125,8 @@ const configSchema = external_zod_default().object({
|
|
|
125
125
|
'@domain-first/handlers-rest'
|
|
126
126
|
])),
|
|
127
127
|
defaultPersistenceLayerImplementation: external_zod_default().string(),
|
|
128
|
-
useReact: external_zod_default().boolean()
|
|
128
|
+
useReact: external_zod_default().boolean(),
|
|
129
|
+
testingLibrary: external_zod_default().string().optional()
|
|
129
130
|
});
|
|
130
131
|
class ConfigFile {
|
|
131
132
|
data;
|
|
@@ -170,11 +171,20 @@ const initializeUseCase = async ()=>{
|
|
|
170
171
|
const useReact = await (0, prompts_namespaceObject.confirm)({
|
|
171
172
|
message: 'Use React'
|
|
172
173
|
});
|
|
174
|
+
let testingLibrary;
|
|
175
|
+
const withTests = await (0, prompts_namespaceObject.confirm)({
|
|
176
|
+
message: 'Scaffold unit tests'
|
|
177
|
+
});
|
|
178
|
+
if (withTests) testingLibrary = await (0, prompts_namespaceObject.input)({
|
|
179
|
+
message: 'Unit testing library:',
|
|
180
|
+
default: 'vitest'
|
|
181
|
+
});
|
|
173
182
|
ConfigFile.write({
|
|
174
183
|
rootFolder: rootFolderName,
|
|
175
184
|
domainFirstPackages,
|
|
176
185
|
defaultPersistenceLayerImplementation,
|
|
177
|
-
useReact
|
|
186
|
+
useReact,
|
|
187
|
+
testingLibrary
|
|
178
188
|
});
|
|
179
189
|
const { path } = new ProjectRoot();
|
|
180
190
|
const rootFolder = new Folder(path);
|
|
@@ -225,12 +235,19 @@ class UnknownFormatNaming {
|
|
|
225
235
|
get ClassName() {
|
|
226
236
|
return this.PascalCase;
|
|
227
237
|
}
|
|
238
|
+
get withSpaces() {
|
|
239
|
+
return this.fileName.replaceAll('-', ' ');
|
|
240
|
+
}
|
|
228
241
|
}
|
|
229
242
|
const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
230
243
|
const aggregateName = await (0, prompts_namespaceObject.input)({
|
|
231
244
|
message: 'Aggregate name:'
|
|
232
245
|
});
|
|
233
246
|
const aggregateNaming = new UnknownFormatNaming(aggregateName);
|
|
247
|
+
let scaffoldUnitTests;
|
|
248
|
+
if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
|
|
249
|
+
message: 'Scaffold unit-tests'
|
|
250
|
+
});
|
|
234
251
|
const withRepository = await (0, prompts_namespaceObject.confirm)({
|
|
235
252
|
message: 'With Repository'
|
|
236
253
|
});
|
|
@@ -246,9 +263,42 @@ export class ${aggregateNaming.ClassName} extends domainType() {
|
|
|
246
263
|
|
|
247
264
|
}`.trim() : `export class ${aggregateNaming.ClassName} {}`);
|
|
248
265
|
const barrelFile = aggregatesFolder.createFile("index.ts", `export * from './${aggregateNaming.fileName}.aggregate-root'`);
|
|
266
|
+
if (scaffoldUnitTests) aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.spec.ts`, `
|
|
267
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
|
|
268
|
+
import { ${aggregateNaming.ClassName} } from './${aggregateNaming.fileName}.aggregate-root'
|
|
269
|
+
|
|
270
|
+
let ${aggregateNaming.variableName}: ${aggregateNaming.ClassName}
|
|
271
|
+
|
|
272
|
+
beforeEach(() => {
|
|
273
|
+
${aggregateNaming.variableName} = new ${aggregateNaming.ClassName}()
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
describe('${aggregateNaming.withSpaces}', () => {
|
|
277
|
+
test('can be instantiated via constructor', () => {
|
|
278
|
+
expect(${aggregateNaming.variableName}).toBeDefined()
|
|
279
|
+
})
|
|
280
|
+
})
|
|
281
|
+
`);
|
|
249
282
|
if (withRepository) {
|
|
250
283
|
aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.ts`, `export abstract class ${aggregateNaming.ClassName}Repository { }`);
|
|
251
284
|
barrelFile.addLine(`export * from './${aggregateNaming.fileName}-repository'`);
|
|
285
|
+
if (scaffoldUnitTests) aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
|
|
286
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
|
|
287
|
+
import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
|
|
288
|
+
import type { ${aggregateNaming.ClassName}Repository } from './${aggregateNaming.fileName}-repository'
|
|
289
|
+
|
|
290
|
+
let ${aggregateNaming.variableName}Repository: ${aggregateNaming.ClassName}Repository
|
|
291
|
+
|
|
292
|
+
beforeEach(() => {
|
|
293
|
+
${aggregateNaming.variableName}Repository = wire${aggregateNaming.ClassName}Repository()
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
describe('${aggregateNaming.withSpaces} repository', () => {
|
|
297
|
+
test('can be wired', () => {
|
|
298
|
+
expect(${aggregateNaming.variableName}Repository).toBeDefined()
|
|
299
|
+
})
|
|
300
|
+
})
|
|
301
|
+
`.trim());
|
|
252
302
|
const infrastructureImplementationType = await (0, prompts_namespaceObject.input)({
|
|
253
303
|
message: 'Repository infrastructure implementation type:',
|
|
254
304
|
default: 'prisma'
|
|
@@ -310,6 +360,10 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
|
|
|
310
360
|
message: 'Name: '
|
|
311
361
|
});
|
|
312
362
|
const naming = new UnknownFormatNaming(name);
|
|
363
|
+
let scaffoldUnitTests;
|
|
364
|
+
if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await (0, prompts_namespaceObject.confirm)({
|
|
365
|
+
message: 'Scaffold unit-tests'
|
|
366
|
+
});
|
|
313
367
|
const wiringFolder = boundedContextFolder.subitem([
|
|
314
368
|
'wiring',
|
|
315
369
|
'ports'
|
|
@@ -323,8 +377,26 @@ export abstract class ${naming.ClassName} {
|
|
|
323
377
|
|
|
324
378
|
}
|
|
325
379
|
`.trim());
|
|
380
|
+
if (scaffoldUnitTests) applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
|
|
381
|
+
import { define, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
|
|
382
|
+
import { type ${naming.ClassName} } from './${naming.fileName}'
|
|
383
|
+
import { wire${naming.ClassName} } from '../../wiring/ports/wire-${naming.fileName}'
|
|
384
|
+
|
|
385
|
+
let ${naming.variableName}: ${naming.ClassName}
|
|
386
|
+
|
|
387
|
+
beforeEach(() => {
|
|
388
|
+
${naming.variableName} = wire${naming.ClassName}()
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
define('${naming.withSpaces}', () => {
|
|
392
|
+
test('can be wired', () => {
|
|
393
|
+
expect(${naming.variableName}).toBeDefined()
|
|
394
|
+
})
|
|
395
|
+
})
|
|
396
|
+
`.trim());
|
|
326
397
|
const implementationType = await (0, prompts_namespaceObject.input)({
|
|
327
|
-
message: 'Adapter implementation type:'
|
|
398
|
+
message: 'Adapter implementation type:',
|
|
399
|
+
default: 'api'
|
|
328
400
|
});
|
|
329
401
|
const addTestImplementation = await (0, prompts_namespaceObject.confirm)({
|
|
330
402
|
message: 'With test implementation'
|
package/dist/index.js
CHANGED
|
@@ -95,7 +95,8 @@ const configSchema = zod.object({
|
|
|
95
95
|
'@domain-first/handlers-rest'
|
|
96
96
|
])),
|
|
97
97
|
defaultPersistenceLayerImplementation: zod.string(),
|
|
98
|
-
useReact: zod.boolean()
|
|
98
|
+
useReact: zod.boolean(),
|
|
99
|
+
testingLibrary: zod.string().optional()
|
|
99
100
|
});
|
|
100
101
|
class ConfigFile {
|
|
101
102
|
data;
|
|
@@ -140,11 +141,20 @@ const initializeUseCase = async ()=>{
|
|
|
140
141
|
const useReact = await prompts_confirm({
|
|
141
142
|
message: 'Use React'
|
|
142
143
|
});
|
|
144
|
+
let testingLibrary;
|
|
145
|
+
const withTests = await prompts_confirm({
|
|
146
|
+
message: 'Scaffold unit tests'
|
|
147
|
+
});
|
|
148
|
+
if (withTests) testingLibrary = await input({
|
|
149
|
+
message: 'Unit testing library:',
|
|
150
|
+
default: 'vitest'
|
|
151
|
+
});
|
|
143
152
|
ConfigFile.write({
|
|
144
153
|
rootFolder: rootFolderName,
|
|
145
154
|
domainFirstPackages,
|
|
146
155
|
defaultPersistenceLayerImplementation,
|
|
147
|
-
useReact
|
|
156
|
+
useReact,
|
|
157
|
+
testingLibrary
|
|
148
158
|
});
|
|
149
159
|
const { path } = new ProjectRoot();
|
|
150
160
|
const rootFolder = new Folder(path);
|
|
@@ -195,12 +205,19 @@ class UnknownFormatNaming {
|
|
|
195
205
|
get ClassName() {
|
|
196
206
|
return this.PascalCase;
|
|
197
207
|
}
|
|
208
|
+
get withSpaces() {
|
|
209
|
+
return this.fileName.replaceAll('-', ' ');
|
|
210
|
+
}
|
|
198
211
|
}
|
|
199
212
|
const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
200
213
|
const aggregateName = await input({
|
|
201
214
|
message: 'Aggregate name:'
|
|
202
215
|
});
|
|
203
216
|
const aggregateNaming = new UnknownFormatNaming(aggregateName);
|
|
217
|
+
let scaffoldUnitTests;
|
|
218
|
+
if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
|
|
219
|
+
message: 'Scaffold unit-tests'
|
|
220
|
+
});
|
|
204
221
|
const withRepository = await prompts_confirm({
|
|
205
222
|
message: 'With Repository'
|
|
206
223
|
});
|
|
@@ -216,9 +233,42 @@ export class ${aggregateNaming.ClassName} extends domainType() {
|
|
|
216
233
|
|
|
217
234
|
}`.trim() : `export class ${aggregateNaming.ClassName} {}`);
|
|
218
235
|
const barrelFile = aggregatesFolder.createFile("index.ts", `export * from './${aggregateNaming.fileName}.aggregate-root'`);
|
|
236
|
+
if (scaffoldUnitTests) aggregatesFolder.createFile(`${aggregateNaming.fileName}.aggregate-root.spec.ts`, `
|
|
237
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
|
|
238
|
+
import { ${aggregateNaming.ClassName} } from './${aggregateNaming.fileName}.aggregate-root'
|
|
239
|
+
|
|
240
|
+
let ${aggregateNaming.variableName}: ${aggregateNaming.ClassName}
|
|
241
|
+
|
|
242
|
+
beforeEach(() => {
|
|
243
|
+
${aggregateNaming.variableName} = new ${aggregateNaming.ClassName}()
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
describe('${aggregateNaming.withSpaces}', () => {
|
|
247
|
+
test('can be instantiated via constructor', () => {
|
|
248
|
+
expect(${aggregateNaming.variableName}).toBeDefined()
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
`);
|
|
219
252
|
if (withRepository) {
|
|
220
253
|
aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.ts`, `export abstract class ${aggregateNaming.ClassName}Repository { }`);
|
|
221
254
|
barrelFile.addLine(`export * from './${aggregateNaming.fileName}-repository'`);
|
|
255
|
+
if (scaffoldUnitTests) aggregatesFolder.createFile(`${aggregateNaming.fileName}-repository.spec.ts`, `
|
|
256
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
|
|
257
|
+
import { wire${aggregateNaming.ClassName}Repository } from '../../../wiring/repositories/wire-${aggregateNaming.fileName}-repository'
|
|
258
|
+
import type { ${aggregateNaming.ClassName}Repository } from './${aggregateNaming.fileName}-repository'
|
|
259
|
+
|
|
260
|
+
let ${aggregateNaming.variableName}Repository: ${aggregateNaming.ClassName}Repository
|
|
261
|
+
|
|
262
|
+
beforeEach(() => {
|
|
263
|
+
${aggregateNaming.variableName}Repository = wire${aggregateNaming.ClassName}Repository()
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
describe('${aggregateNaming.withSpaces} repository', () => {
|
|
267
|
+
test('can be wired', () => {
|
|
268
|
+
expect(${aggregateNaming.variableName}Repository).toBeDefined()
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
`.trim());
|
|
222
272
|
const infrastructureImplementationType = await input({
|
|
223
273
|
message: 'Repository infrastructure implementation type:',
|
|
224
274
|
default: 'prisma'
|
|
@@ -280,6 +330,10 @@ const scaffoldNewApplicationPort = async (boundedContextFolder)=>{
|
|
|
280
330
|
message: 'Name: '
|
|
281
331
|
});
|
|
282
332
|
const naming = new UnknownFormatNaming(name);
|
|
333
|
+
let scaffoldUnitTests;
|
|
334
|
+
if (ConfigFile.Instance.data.testingLibrary) scaffoldUnitTests = await prompts_confirm({
|
|
335
|
+
message: 'Scaffold unit-tests'
|
|
336
|
+
});
|
|
283
337
|
const wiringFolder = boundedContextFolder.subitem([
|
|
284
338
|
'wiring',
|
|
285
339
|
'ports'
|
|
@@ -293,8 +347,26 @@ export abstract class ${naming.ClassName} {
|
|
|
293
347
|
|
|
294
348
|
}
|
|
295
349
|
`.trim());
|
|
350
|
+
if (scaffoldUnitTests) applicationPortsFolder.createFile(`${naming.fileName}.spec.ts`, `
|
|
351
|
+
import { define, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
|
|
352
|
+
import { type ${naming.ClassName} } from './${naming.fileName}'
|
|
353
|
+
import { wire${naming.ClassName} } from '../../wiring/ports/wire-${naming.fileName}'
|
|
354
|
+
|
|
355
|
+
let ${naming.variableName}: ${naming.ClassName}
|
|
356
|
+
|
|
357
|
+
beforeEach(() => {
|
|
358
|
+
${naming.variableName} = wire${naming.ClassName}()
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
define('${naming.withSpaces}', () => {
|
|
362
|
+
test('can be wired', () => {
|
|
363
|
+
expect(${naming.variableName}).toBeDefined()
|
|
364
|
+
})
|
|
365
|
+
})
|
|
366
|
+
`.trim());
|
|
296
367
|
const implementationType = await input({
|
|
297
|
-
message: 'Adapter implementation type:'
|
|
368
|
+
message: 'Adapter implementation type:',
|
|
369
|
+
default: 'api'
|
|
298
370
|
});
|
|
299
371
|
const addTestImplementation = await prompts_confirm({
|
|
300
372
|
message: 'With test implementation'
|