@domain-first/project-structure 6.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -19
- package/dist/201.js +46 -35
- package/dist/287.js +1685 -1612
- 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 +5 -0
- package/dist/index.cjs +100 -916
- package/dist/index.js +6 -46
- package/dist/init.cjs +868 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.js +36 -0
- package/dist/integration.cjs +412 -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/print-next-steps.d.ts +2 -2
- package/dist/react.cjs +915 -0
- package/dist/react.d.ts +2 -0
- package/dist/react.js +73 -0
- package/dist/use-cases/rest-endpoint-generator.d.ts +1 -1
- package/package.json +3 -1
- package/skills/df-ps-implement/SKILL.md +10 -55
- 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 +38 -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/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/init.cjs
ADDED
|
@@ -0,0 +1,868 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __webpack_require__ = {};
|
|
4
|
+
(()=>{
|
|
5
|
+
__webpack_require__.n = (module)=>{
|
|
6
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
7
|
+
__webpack_require__.d(getter, {
|
|
8
|
+
a: getter
|
|
9
|
+
});
|
|
10
|
+
return getter;
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
(()=>{
|
|
14
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
15
|
+
var define = (defs, kind)=>{
|
|
16
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
[kind]: defs[key]
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
define(getters, "get");
|
|
22
|
+
define(values, "value");
|
|
23
|
+
};
|
|
24
|
+
})();
|
|
25
|
+
(()=>{
|
|
26
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
const external_node_util_namespaceObject = require("node:util");
|
|
30
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
31
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
32
|
+
const external_zod_namespaceObject = require("zod");
|
|
33
|
+
var external_zod_default = /*#__PURE__*/ __webpack_require__.n(external_zod_namespaceObject);
|
|
34
|
+
const moduleKinds = [
|
|
35
|
+
'repositories',
|
|
36
|
+
'domain-services',
|
|
37
|
+
'application-ports',
|
|
38
|
+
'application-services',
|
|
39
|
+
'use-cases',
|
|
40
|
+
'commands',
|
|
41
|
+
'queries',
|
|
42
|
+
'infrastructure-services',
|
|
43
|
+
'presentation-services'
|
|
44
|
+
];
|
|
45
|
+
const domain = [
|
|
46
|
+
'repositories',
|
|
47
|
+
'domain-services'
|
|
48
|
+
];
|
|
49
|
+
const commandsAndQueries = [
|
|
50
|
+
'commands',
|
|
51
|
+
'queries'
|
|
52
|
+
];
|
|
53
|
+
const infrastructure = [
|
|
54
|
+
...domain,
|
|
55
|
+
'application-ports',
|
|
56
|
+
'infrastructure-services'
|
|
57
|
+
];
|
|
58
|
+
const defaultDependencies = {
|
|
59
|
+
'domain-services': [
|
|
60
|
+
'domain-services'
|
|
61
|
+
],
|
|
62
|
+
repositories: [
|
|
63
|
+
'domain-services',
|
|
64
|
+
'application-ports',
|
|
65
|
+
'infrastructure-services'
|
|
66
|
+
],
|
|
67
|
+
'application-ports': infrastructure,
|
|
68
|
+
'application-services': [
|
|
69
|
+
...domain,
|
|
70
|
+
'application-ports',
|
|
71
|
+
...commandsAndQueries
|
|
72
|
+
],
|
|
73
|
+
'use-cases': [
|
|
74
|
+
...domain,
|
|
75
|
+
'application-ports',
|
|
76
|
+
'application-services',
|
|
77
|
+
...commandsAndQueries
|
|
78
|
+
],
|
|
79
|
+
commands: [
|
|
80
|
+
'infrastructure-services'
|
|
81
|
+
],
|
|
82
|
+
queries: [
|
|
83
|
+
'infrastructure-services'
|
|
84
|
+
],
|
|
85
|
+
'infrastructure-services': infrastructure,
|
|
86
|
+
'presentation-services': [
|
|
87
|
+
'application-ports',
|
|
88
|
+
'application-services',
|
|
89
|
+
'use-cases',
|
|
90
|
+
...commandsAndQueries,
|
|
91
|
+
'presentation-services'
|
|
92
|
+
]
|
|
93
|
+
};
|
|
94
|
+
const kindSchema = external_zod_default()["enum"](moduleKinds);
|
|
95
|
+
const dependencyRulesSchema = external_zod_default().partialRecord(kindSchema, external_zod_default().union([
|
|
96
|
+
external_zod_default().array(kindSchema),
|
|
97
|
+
external_zod_default().object({
|
|
98
|
+
add: external_zod_default().array(kindSchema).optional(),
|
|
99
|
+
remove: external_zod_default().array(kindSchema).optional()
|
|
100
|
+
})
|
|
101
|
+
]));
|
|
102
|
+
const dependency_rules_resolveDependencyRules = (config = {})=>{
|
|
103
|
+
const entries = moduleKinds.map((kind)=>{
|
|
104
|
+
const override = config[kind];
|
|
105
|
+
if (Array.isArray(override)) return [
|
|
106
|
+
kind,
|
|
107
|
+
new Set(override)
|
|
108
|
+
];
|
|
109
|
+
const kinds = new Set([
|
|
110
|
+
...defaultDependencies[kind],
|
|
111
|
+
...override?.add ?? []
|
|
112
|
+
]);
|
|
113
|
+
for (const removed of override?.remove ?? [])kinds.delete(removed);
|
|
114
|
+
return [
|
|
115
|
+
kind,
|
|
116
|
+
kinds
|
|
117
|
+
];
|
|
118
|
+
});
|
|
119
|
+
return Object.fromEntries(entries);
|
|
120
|
+
};
|
|
121
|
+
dependency_rules_resolveDependencyRules();
|
|
122
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
123
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
124
|
+
const pendingFiles = new Map();
|
|
125
|
+
const pendingFolders = new Set();
|
|
126
|
+
const pendingMoves = new Map();
|
|
127
|
+
const pendingDeletions = new Map();
|
|
128
|
+
const filesToOverwrite = ()=>[
|
|
129
|
+
...pendingFiles
|
|
130
|
+
].filter(([filePath, { replacesFile }])=>replacesFile && external_node_fs_default().existsSync(filePath)).map(([filePath])=>filePath);
|
|
131
|
+
const file_system_withoutOverwrites = (generate)=>{
|
|
132
|
+
const before = new Map(pendingFiles);
|
|
133
|
+
const result = generate();
|
|
134
|
+
for (const [filePath, change] of pendingFiles){
|
|
135
|
+
if (before.get(filePath) === change || !change.replacesFile || !external_node_fs_default().existsSync(filePath)) continue;
|
|
136
|
+
const previous = before.get(filePath);
|
|
137
|
+
if (previous) pendingFiles.set(filePath, previous);
|
|
138
|
+
else pendingFiles.delete(filePath);
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
};
|
|
142
|
+
const file_system_discardPendingChanges = ()=>{
|
|
143
|
+
pendingFolders.clear();
|
|
144
|
+
pendingFiles.clear();
|
|
145
|
+
pendingMoves.clear();
|
|
146
|
+
pendingDeletions.clear();
|
|
147
|
+
};
|
|
148
|
+
const removeEmptyFolders = (folderPath, stopAt)=>{
|
|
149
|
+
let current = folderPath;
|
|
150
|
+
while(current.startsWith(`${stopAt}${external_node_path_default().sep}`) && external_node_fs_default().existsSync(current) && !external_node_fs_default().readdirSync(current).length){
|
|
151
|
+
external_node_fs_default().rmdirSync(current);
|
|
152
|
+
current = external_node_path_default().dirname(current);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const writePendingChanges = ()=>{
|
|
156
|
+
for (const folderPath of pendingFolders)external_node_fs_default().mkdirSync(folderPath, {
|
|
157
|
+
recursive: true
|
|
158
|
+
});
|
|
159
|
+
for (const [filePath, { content }] of pendingFiles){
|
|
160
|
+
external_node_fs_default().mkdirSync(external_node_path_default().dirname(filePath), {
|
|
161
|
+
recursive: true
|
|
162
|
+
});
|
|
163
|
+
external_node_fs_default().writeFileSync(filePath, content, 'utf8');
|
|
164
|
+
}
|
|
165
|
+
for (const [targetPath, { sourcePath }] of pendingMoves){
|
|
166
|
+
external_node_fs_default().mkdirSync(external_node_path_default().dirname(targetPath), {
|
|
167
|
+
recursive: true
|
|
168
|
+
});
|
|
169
|
+
external_node_fs_default().renameSync(sourcePath, targetPath);
|
|
170
|
+
}
|
|
171
|
+
for (const filePath of pendingDeletions.keys())external_node_fs_default().rmSync(filePath, {
|
|
172
|
+
force: true
|
|
173
|
+
});
|
|
174
|
+
for (const [filePath, stopAt] of pendingDeletions)removeEmptyFolders(external_node_path_default().dirname(filePath), stopAt);
|
|
175
|
+
for (const { sourcePath, stopAt } of pendingMoves.values())removeEmptyFolders(external_node_path_default().dirname(sourcePath), stopAt);
|
|
176
|
+
file_system_discardPendingChanges();
|
|
177
|
+
};
|
|
178
|
+
class FileSystemItem {
|
|
179
|
+
path;
|
|
180
|
+
constructor(path){
|
|
181
|
+
this.path = path;
|
|
182
|
+
}
|
|
183
|
+
subitem = (relativePath)=>new this.constructor(external_node_path_default().resolve(this.path, ...relativePath));
|
|
184
|
+
get exists() {
|
|
185
|
+
return external_node_fs_default().existsSync(this.path);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
class file_system_Folder extends FileSystemItem {
|
|
189
|
+
createIfNotExisted = ()=>{
|
|
190
|
+
pendingFolders.add(this.path);
|
|
191
|
+
};
|
|
192
|
+
get content() {
|
|
193
|
+
if (!this.exists) return {
|
|
194
|
+
subfolderNames: [],
|
|
195
|
+
fileNames: []
|
|
196
|
+
};
|
|
197
|
+
const content = external_node_fs_default().readdirSync(this.path, {
|
|
198
|
+
withFileTypes: true
|
|
199
|
+
});
|
|
200
|
+
return {
|
|
201
|
+
subfolderNames: content.filter((x)=>x.isDirectory()).map((x)=>x.name),
|
|
202
|
+
fileNames: content.filter((x)=>!x.isDirectory()).map((x)=>external_node_path_default().parse(x.name).name)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
get name() {
|
|
206
|
+
return external_node_path_default().basename(this.path);
|
|
207
|
+
}
|
|
208
|
+
createFile = (name, content)=>{
|
|
209
|
+
this.createIfNotExisted();
|
|
210
|
+
const file = new file_system_File(this.path).subitem([
|
|
211
|
+
name
|
|
212
|
+
]);
|
|
213
|
+
file.data = content;
|
|
214
|
+
return file;
|
|
215
|
+
};
|
|
216
|
+
file = (name)=>{
|
|
217
|
+
this.createIfNotExisted();
|
|
218
|
+
const file = new file_system_File(this.path).subitem([
|
|
219
|
+
name
|
|
220
|
+
]);
|
|
221
|
+
return file;
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
class file_system_File extends FileSystemItem {
|
|
225
|
+
get exists() {
|
|
226
|
+
return pendingFiles.has(this.path) || pendingMoves.has(this.path) || external_node_fs_default().existsSync(this.path) && !pendingDeletions.has(this.path);
|
|
227
|
+
}
|
|
228
|
+
delete = (stopAt)=>{
|
|
229
|
+
pendingDeletions.set(this.path, stopAt);
|
|
230
|
+
};
|
|
231
|
+
moveTo = (targetPath, stopAt)=>{
|
|
232
|
+
pendingMoves.set(targetPath, {
|
|
233
|
+
sourcePath: this.path,
|
|
234
|
+
stopAt
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
get data() {
|
|
238
|
+
const pendingFile = pendingFiles.get(this.path);
|
|
239
|
+
if (pendingFile) return pendingFile.content;
|
|
240
|
+
if (!this.exists) throw new Error('File does not exist');
|
|
241
|
+
return external_node_fs_default().readFileSync(this.path, 'utf-8');
|
|
242
|
+
}
|
|
243
|
+
set data(content) {
|
|
244
|
+
pendingFiles.set(this.path, {
|
|
245
|
+
content,
|
|
246
|
+
replacesFile: true
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
update = (content)=>{
|
|
250
|
+
pendingFiles.set(this.path, {
|
|
251
|
+
content,
|
|
252
|
+
replacesFile: pendingFiles.get(this.path)?.replacesFile ?? false
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
addLine = (newLine, separator = '\n')=>{
|
|
256
|
+
const content = this.exists ? this.data : '';
|
|
257
|
+
pendingFiles.set(this.path, {
|
|
258
|
+
content: [
|
|
259
|
+
content.trim(),
|
|
260
|
+
newLine.trim()
|
|
261
|
+
].filter((x)=>!!x).join(separator),
|
|
262
|
+
replacesFile: pendingFiles.get(this.path)?.replacesFile ?? false
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
addLineIfMissing = (newLine, separator = '\n')=>{
|
|
266
|
+
const alreadyAdded = this.exists && this.data.split('\n').some((line)=>line.trim() === newLine.trim());
|
|
267
|
+
if (!alreadyAdded) this.addLine(newLine, separator);
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
class project_root_ProjectRoot {
|
|
271
|
+
path;
|
|
272
|
+
constructor(){
|
|
273
|
+
let dir = process.cwd();
|
|
274
|
+
while(dir !== external_node_path_default().parse(dir).root){
|
|
275
|
+
if (external_node_fs_default().existsSync(external_node_path_default().join(dir, 'package.json'))) {
|
|
276
|
+
this.path = dir;
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
dir = external_node_path_default().dirname(dir);
|
|
280
|
+
}
|
|
281
|
+
throw new Error('No package.json was found');
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const lintChecks = [
|
|
285
|
+
'context-isolation',
|
|
286
|
+
'shared-kernel',
|
|
287
|
+
'layers',
|
|
288
|
+
'dependencies',
|
|
289
|
+
'react',
|
|
290
|
+
'clock'
|
|
291
|
+
];
|
|
292
|
+
const configFileName = 'domain-first.project-structure.config.json';
|
|
293
|
+
const configSchema = external_zod_default().object({
|
|
294
|
+
rootFolder: external_zod_default().string(),
|
|
295
|
+
domainFirstPackages: external_zod_default().array(external_zod_default()["enum"]([
|
|
296
|
+
'@domain-first/types',
|
|
297
|
+
'@domain-first/errors',
|
|
298
|
+
'@domain-first/handlers',
|
|
299
|
+
'@domain-first/wire',
|
|
300
|
+
'@domain-first/handlers-rest'
|
|
301
|
+
])),
|
|
302
|
+
defaultPersistenceLayerImplementation: external_zod_default().string(),
|
|
303
|
+
withInMemoryDb: external_zod_default().boolean().optional(),
|
|
304
|
+
useReact: external_zod_default().boolean(),
|
|
305
|
+
storybookFramework: external_zod_default().string().optional(),
|
|
306
|
+
testingLibrary: external_zod_default().string().optional(),
|
|
307
|
+
rules: external_zod_default().object({
|
|
308
|
+
dependencies: dependencyRulesSchema.optional(),
|
|
309
|
+
lint: external_zod_default().partialRecord(external_zod_default()["enum"](lintChecks), external_zod_default().boolean()).optional()
|
|
310
|
+
}).optional()
|
|
311
|
+
});
|
|
312
|
+
class config_file_ConfigFile {
|
|
313
|
+
data;
|
|
314
|
+
constructor(){
|
|
315
|
+
const filePath = config_file_ConfigFile.path;
|
|
316
|
+
const file = new file_system_File(filePath);
|
|
317
|
+
const configObject = JSON.parse(file.data);
|
|
318
|
+
this.data = configSchema.parse(configObject);
|
|
319
|
+
}
|
|
320
|
+
static get Instance() {
|
|
321
|
+
return new config_file_ConfigFile();
|
|
322
|
+
}
|
|
323
|
+
static get path() {
|
|
324
|
+
const { path: root } = new project_root_ProjectRoot();
|
|
325
|
+
return external_node_path_default().resolve(root, configFileName);
|
|
326
|
+
}
|
|
327
|
+
static get exists() {
|
|
328
|
+
return new file_system_File(config_file_ConfigFile.path).exists;
|
|
329
|
+
}
|
|
330
|
+
static write = (config)=>{
|
|
331
|
+
new file_system_File(config_file_ConfigFile.path).data = JSON.stringify(config, null, '\t');
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
const installCommand = /^\s*npm (?:i|install)((?:\s+(?:--save-dev|-D))?)\s+(.+)$/;
|
|
335
|
+
const mergeInstallCommands = (commands)=>{
|
|
336
|
+
const runtime = new Set();
|
|
337
|
+
const development = new Set();
|
|
338
|
+
const rest = [];
|
|
339
|
+
for (const command of commands){
|
|
340
|
+
const match = installCommand.exec(command);
|
|
341
|
+
if (!match) {
|
|
342
|
+
rest.push(command);
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
for (const name of match[2].trim().split(/\s+/))(match[1] ? development : runtime).add(name);
|
|
346
|
+
}
|
|
347
|
+
const devOnly = [
|
|
348
|
+
...development
|
|
349
|
+
].filter((name)=>!runtime.has(name));
|
|
350
|
+
return [
|
|
351
|
+
...runtime.size ? [
|
|
352
|
+
`npm install ${[
|
|
353
|
+
...runtime
|
|
354
|
+
].join(' ')}`
|
|
355
|
+
] : [],
|
|
356
|
+
...devOnly.length ? [
|
|
357
|
+
`npm install --save-dev ${devOnly.join(' ')}`
|
|
358
|
+
] : [],
|
|
359
|
+
...rest
|
|
360
|
+
];
|
|
361
|
+
};
|
|
362
|
+
const print_next_steps_printNextSteps = (nextSteps)=>{
|
|
363
|
+
const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
|
|
364
|
+
const commands = mergeInstallCommands(nextSteps.filter(isCommand));
|
|
365
|
+
const notes = nextSteps.filter((line)=>!isCommand(line));
|
|
366
|
+
const sections = [];
|
|
367
|
+
if (commands.length) sections.push([
|
|
368
|
+
'Run this command to install the required dependencies:',
|
|
369
|
+
(0, external_node_util_namespaceObject.styleText)([
|
|
370
|
+
'bold',
|
|
371
|
+
'cyan'
|
|
372
|
+
], commands.join(' && '))
|
|
373
|
+
].join('\n'));
|
|
374
|
+
if (notes.length) sections.push([
|
|
375
|
+
'Additional information:',
|
|
376
|
+
...notes.map((line)=>line.replace(/^(\s*Add )(!\S+)/, (_, prefix, path)=>prefix + (0, external_node_util_namespaceObject.styleText)([
|
|
377
|
+
'bold',
|
|
378
|
+
'cyan'
|
|
379
|
+
], path)))
|
|
380
|
+
].join('\n'));
|
|
381
|
+
if (sections.length) console.log(sections.join('\n\n'));
|
|
382
|
+
};
|
|
383
|
+
const prompts_namespaceObject = require("@inquirer/prompts");
|
|
384
|
+
const save_pending_changes_savePendingChanges = async ()=>{
|
|
385
|
+
const overwrittenFiles = filesToOverwrite();
|
|
386
|
+
if (overwrittenFiles.length) {
|
|
387
|
+
const root = new project_root_ProjectRoot().path;
|
|
388
|
+
console.log('These files already exist and will be overwritten:');
|
|
389
|
+
for (const filePath of overwrittenFiles)console.log(` ${external_node_path_default().relative(root, filePath)}`);
|
|
390
|
+
const overwrite = await (0, prompts_namespaceObject.confirm)({
|
|
391
|
+
message: 'Overwrite them?',
|
|
392
|
+
default: false
|
|
393
|
+
});
|
|
394
|
+
if (!overwrite) {
|
|
395
|
+
file_system_discardPendingChanges();
|
|
396
|
+
console.log('Cancelled: nothing was written.');
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
writePendingChanges();
|
|
401
|
+
return true;
|
|
402
|
+
};
|
|
403
|
+
const wiring_relativeImport = (fromFile, toFile)=>{
|
|
404
|
+
const relativePath = external_node_path_default().relative(external_node_path_default().dirname(fromFile), toFile).replace(/\.ts$/, '').split(external_node_path_default().sep).join('/');
|
|
405
|
+
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
406
|
+
};
|
|
407
|
+
const inMemoryDbService = `type Entry = {
|
|
408
|
+
id: unknown;
|
|
409
|
+
item: any;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
declare global {
|
|
413
|
+
var ___SHARED_IN_MEMORY_DB___: Record<string, Array<Entry>> | undefined;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
type Section<T, TId> = {
|
|
417
|
+
all: (predicate?: (x: T) => boolean) => T[];
|
|
418
|
+
first: (predicate: (x: T) => boolean) => T | null;
|
|
419
|
+
withId: (id: TId) => T | null;
|
|
420
|
+
lastAddedItem: () => T | null;
|
|
421
|
+
save: (payload: T extends { id: TId } ? T : [TId, T]) => void;
|
|
422
|
+
deleteById: (id: TId) => void;
|
|
423
|
+
delete: (predicate: (x: T) => boolean) => void;
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
type IdsAreEqual<TId> = (a: TId, b: TId) => boolean;
|
|
427
|
+
|
|
428
|
+
const comparisonMethodNames = ['equals', 'same', 'isSame', 'isEqual'] as const;
|
|
429
|
+
|
|
430
|
+
const defaultIdsAreEqual = (a: unknown, b: unknown): boolean => {
|
|
431
|
+
if (typeof a !== 'object' || a === null) {
|
|
432
|
+
return Object.is(a, b);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
for (const methodName of comparisonMethodNames) {
|
|
436
|
+
const method: unknown = (a as Record<string, unknown>)[methodName];
|
|
437
|
+
if (typeof method === 'function') {
|
|
438
|
+
return Boolean(method.call(a, b));
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return Object.is(a, b);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
const hasId = (x: unknown): x is { id: unknown } =>
|
|
446
|
+
typeof x === 'object' && x !== null && 'id' in x;
|
|
447
|
+
|
|
448
|
+
export class InMemoryDbInfrastructureService {
|
|
449
|
+
protected section<T extends { id: unknown }>(
|
|
450
|
+
key: string,
|
|
451
|
+
idsAreEqual?: IdsAreEqual<T['id']>
|
|
452
|
+
): Section<T, T['id']>;
|
|
453
|
+
protected section<T, TId>(
|
|
454
|
+
key: string,
|
|
455
|
+
idsAreEqual?: IdsAreEqual<TId>
|
|
456
|
+
): Section<T, TId>;
|
|
457
|
+
protected section<T, TId>(
|
|
458
|
+
key: string,
|
|
459
|
+
idsAreEqual: IdsAreEqual<TId> = defaultIdsAreEqual
|
|
460
|
+
): Section<T, TId> {
|
|
461
|
+
if (!globalThis.___SHARED_IN_MEMORY_DB___) {
|
|
462
|
+
globalThis.___SHARED_IN_MEMORY_DB___ = {};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (!globalThis.___SHARED_IN_MEMORY_DB___[key]) {
|
|
466
|
+
globalThis.___SHARED_IN_MEMORY_DB___[key] = [];
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const items = (): T[] =>
|
|
470
|
+
globalThis.___SHARED_IN_MEMORY_DB___![key].map(
|
|
471
|
+
(entry) => entry.item
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
return {
|
|
475
|
+
all: (predicate: (x: T) => boolean = () => true): T[] =>
|
|
476
|
+
items().filter(predicate),
|
|
477
|
+
first: (predicate: (x: T) => boolean): T | null =>
|
|
478
|
+
items().find(predicate) ?? null,
|
|
479
|
+
withId: (id: TId): T | null =>
|
|
480
|
+
items().find(
|
|
481
|
+
(x: T) => hasId(x) && idsAreEqual(x.id as TId, id)
|
|
482
|
+
) ?? null,
|
|
483
|
+
lastAddedItem: (): T | null =>
|
|
484
|
+
globalThis.___SHARED_IN_MEMORY_DB___![key].at(-1)?.item ?? null,
|
|
485
|
+
save: (payload: T extends { id: TId } ? T : [TId, T]) => {
|
|
486
|
+
const id = Array.isArray(payload) ? payload[0] : payload.id;
|
|
487
|
+
const item = Array.isArray(payload) ? payload[1] : payload;
|
|
488
|
+
const entries = globalThis.___SHARED_IN_MEMORY_DB___![key];
|
|
489
|
+
const existing = entries.find((entry) =>
|
|
490
|
+
idsAreEqual(entry.id as TId, id)
|
|
491
|
+
);
|
|
492
|
+
if (existing) {
|
|
493
|
+
existing.item = item;
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
entries.push({ id, item });
|
|
497
|
+
},
|
|
498
|
+
deleteById: (id: TId) => {
|
|
499
|
+
globalThis.___SHARED_IN_MEMORY_DB___![key] =
|
|
500
|
+
globalThis.___SHARED_IN_MEMORY_DB___![key].filter(
|
|
501
|
+
(entry) => !idsAreEqual(entry.id as TId, id)
|
|
502
|
+
);
|
|
503
|
+
},
|
|
504
|
+
delete: (predicate: (x: T) => boolean) => {
|
|
505
|
+
globalThis.___SHARED_IN_MEMORY_DB___![key] =
|
|
506
|
+
globalThis.___SHARED_IN_MEMORY_DB___![key].filter(
|
|
507
|
+
(entry) => !predicate(entry.item)
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
`;
|
|
514
|
+
const inMemoryDbWiring = `import { wireClass } from '@domain-first/wire';
|
|
515
|
+
import { InMemoryDbInfrastructureService } from '../../infrastructure/services/in-memory-db-infrastructure-service';
|
|
516
|
+
|
|
517
|
+
export const wireInMemoryDbInfrastructureService = wireClass(
|
|
518
|
+
InMemoryDbInfrastructureService,
|
|
519
|
+
[]
|
|
520
|
+
);
|
|
521
|
+
`;
|
|
522
|
+
const inMemoryDbSpec = (testingLibrary, withWiring)=>`
|
|
523
|
+
import { describe, test, expect, beforeEach } from '${testingLibrary}'
|
|
524
|
+
${withWiring ? `import { type InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'
|
|
525
|
+
import { wireInMemoryDbInfrastructureService } from '../../wiring/infrastructure-services/wire-in-memory-db-infrastructure-service'` : "import { InMemoryDbInfrastructureService } from './in-memory-db-infrastructure-service'"}
|
|
526
|
+
|
|
527
|
+
let inMemoryDbInfrastructureService: InMemoryDbInfrastructureService
|
|
528
|
+
|
|
529
|
+
beforeEach(() => {
|
|
530
|
+
inMemoryDbInfrastructureService = ${withWiring ? 'wireInMemoryDbInfrastructureService()' : 'new InMemoryDbInfrastructureService()'}
|
|
531
|
+
})
|
|
532
|
+
|
|
533
|
+
describe('in memory db', () => {
|
|
534
|
+
test('can be ${withWiring ? 'wired' : 'created'}', () => {
|
|
535
|
+
expect(inMemoryDbInfrastructureService).toBeDefined()
|
|
536
|
+
})
|
|
537
|
+
})
|
|
538
|
+
`.trim();
|
|
539
|
+
const in_memory_db_withWiring = ()=>config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
540
|
+
const in_memory_db_scaffoldInMemoryDb = (shared)=>{
|
|
541
|
+
const { testingLibrary } = config_file_ConfigFile.Instance.data;
|
|
542
|
+
const servicesFolder = shared.subitem([
|
|
543
|
+
'infrastructure',
|
|
544
|
+
'services'
|
|
545
|
+
]);
|
|
546
|
+
servicesFolder.createFile('in-memory-db-infrastructure-service.ts', inMemoryDbService);
|
|
547
|
+
if (testingLibrary) servicesFolder.createFile('in-memory-db-infrastructure-service.spec.ts', inMemoryDbSpec(testingLibrary, in_memory_db_withWiring()));
|
|
548
|
+
if (in_memory_db_withWiring()) shared.subitem([
|
|
549
|
+
'wiring',
|
|
550
|
+
'infrastructure-services'
|
|
551
|
+
]).createFile('wire-in-memory-db-infrastructure-service.ts', inMemoryDbWiring);
|
|
552
|
+
};
|
|
553
|
+
const hasDependency = (name)=>{
|
|
554
|
+
const manifestFile = new file_system_File(external_node_path_default().join(new project_root_ProjectRoot().path, 'package.json'));
|
|
555
|
+
if (!manifestFile.exists) return false;
|
|
556
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
557
|
+
return [
|
|
558
|
+
manifest.dependencies,
|
|
559
|
+
manifest.devDependencies,
|
|
560
|
+
manifest.optionalDependencies
|
|
561
|
+
].some((dependencies)=>dependencies && Object.hasOwn(dependencies, name));
|
|
562
|
+
};
|
|
563
|
+
const missingPackages = (packages)=>{
|
|
564
|
+
const missing = [
|
|
565
|
+
...new Set(packages)
|
|
566
|
+
].filter((name)=>!hasDependency(name));
|
|
567
|
+
return missing.length ? [
|
|
568
|
+
`npm i ${missing.join(' ')}`
|
|
569
|
+
] : [];
|
|
570
|
+
};
|
|
571
|
+
const missingDomainFirstPackages = ()=>missingPackages(config_file_ConfigFile.Instance.data.domainFirstPackages);
|
|
572
|
+
require("node:module");
|
|
573
|
+
class unknown_format_naming_UnknownFormatNaming {
|
|
574
|
+
rawSource;
|
|
575
|
+
camelCase;
|
|
576
|
+
PascalCase;
|
|
577
|
+
constructor(rawSource){
|
|
578
|
+
this.rawSource = rawSource;
|
|
579
|
+
const source = rawSource.trim();
|
|
580
|
+
if (!source.includes('-')) {
|
|
581
|
+
this.camelCase = source.substring(0, 1).toLowerCase() + source.substring(1);
|
|
582
|
+
this.PascalCase = source.substring(0, 1).toUpperCase() + source.substring(1);
|
|
583
|
+
}
|
|
584
|
+
const words = source.split('-').filter((word)=>!!word);
|
|
585
|
+
this.camelCase = words.map((word, index)=>0 === index ? word.toLowerCase() : word[0].toUpperCase() + word.slice(1).toLowerCase()).join('');
|
|
586
|
+
this.PascalCase = words.map((word)=>word[0].toUpperCase() + word.slice(1).toLowerCase()).join('');
|
|
587
|
+
}
|
|
588
|
+
get fileName() {
|
|
589
|
+
return this.rawSource;
|
|
590
|
+
}
|
|
591
|
+
get variableName() {
|
|
592
|
+
return this.camelCase;
|
|
593
|
+
}
|
|
594
|
+
get ClassName() {
|
|
595
|
+
return this.PascalCase;
|
|
596
|
+
}
|
|
597
|
+
get withSpaces() {
|
|
598
|
+
return this.fileName.replaceAll('-', ' ');
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
const createPresentationService = (boundedContextFolder, name, classFile)=>{
|
|
602
|
+
const naming = new unknown_format_naming_UnknownFormatNaming(name);
|
|
603
|
+
const className = `${naming.ClassName}PresentationService`;
|
|
604
|
+
const scaffoldUnitTests = Boolean(config_file_ConfigFile.Instance.data.testingLibrary);
|
|
605
|
+
const withWiring = config_file_ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
606
|
+
const wiringFolder = boundedContextFolder.subitem([
|
|
607
|
+
'wiring',
|
|
608
|
+
'presentation-services'
|
|
609
|
+
]);
|
|
610
|
+
const presentationServicesFolder = boundedContextFolder.subitem([
|
|
611
|
+
'presentation',
|
|
612
|
+
'services'
|
|
613
|
+
]);
|
|
614
|
+
presentationServicesFolder.createFile(`${naming.fileName}-presentation-service.ts`, classFile?.(className) ?? `
|
|
615
|
+
export class ${className} {
|
|
616
|
+
|
|
617
|
+
}
|
|
618
|
+
`.trim());
|
|
619
|
+
if (scaffoldUnitTests) presentationServicesFolder.createFile(`${naming.fileName}-presentation-service.spec.ts`, `
|
|
620
|
+
import { describe, test, expect, beforeEach } from '${config_file_ConfigFile.Instance.data.testingLibrary}'
|
|
621
|
+
${withWiring ? `import { type ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'
|
|
622
|
+
import { wire${naming.ClassName}PresentationService } from '../../wiring/presentation-services/wire-${naming.fileName}-presentation-service'` : `import { ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'`}
|
|
623
|
+
|
|
624
|
+
let ${naming.variableName}PresentationService: ${naming.ClassName}PresentationService
|
|
625
|
+
|
|
626
|
+
beforeEach(() => {
|
|
627
|
+
${naming.variableName}PresentationService = ${withWiring ? `wire${naming.ClassName}PresentationService()` : `new ${naming.ClassName}PresentationService()`}
|
|
628
|
+
})
|
|
629
|
+
|
|
630
|
+
describe('${naming.withSpaces}', () => {
|
|
631
|
+
test('can be ${withWiring ? 'wired' : 'created'}', () => {
|
|
632
|
+
expect(${naming.variableName}PresentationService).toBeDefined()
|
|
633
|
+
})
|
|
634
|
+
})
|
|
635
|
+
`.trim());
|
|
636
|
+
if (withWiring) return wiringFolder.createFile(`wire-${naming.fileName}-presentation-service.ts`, `
|
|
637
|
+
import { wireClass } from '@domain-first/wire'
|
|
638
|
+
import { ${naming.ClassName}PresentationService } from '../../presentation/services/${naming.fileName}-presentation-service'
|
|
639
|
+
|
|
640
|
+
export const wire${naming.ClassName}PresentationService = wireClass(
|
|
641
|
+
${naming.ClassName}PresentationService,
|
|
642
|
+
[]
|
|
643
|
+
)
|
|
644
|
+
`.trim());
|
|
645
|
+
};
|
|
646
|
+
const rest_endpoint_generator_name = 'rest-endpoint-generator';
|
|
647
|
+
const scaffoldRestEndpointGenerator = (sharedFolder, { withNextAdapter = false } = {})=>createPresentationService(sharedFolder, rest_endpoint_generator_name, (className)=>{
|
|
648
|
+
const adapter = withNextAdapter ? 'nextAdapter' : 'adapter';
|
|
649
|
+
return `
|
|
650
|
+
import {
|
|
651
|
+
${withNextAdapter ? '' : ' type Adapter,\n'} type EndpointGenerator,
|
|
652
|
+
createEndpoint,
|
|
653
|
+
invalidRequest
|
|
654
|
+
} from '@domain-first/handlers-rest'
|
|
655
|
+
${withNextAdapter ? "import { nextAdapter } from '@domain-first/handlers-next'" : `
|
|
656
|
+
/**
|
|
657
|
+
* The adapter of your HTTP framework.
|
|
658
|
+
*/
|
|
659
|
+
const adapter = undefined as unknown as Adapter<any[], any>`}
|
|
660
|
+
|
|
661
|
+
export class ${className} {
|
|
662
|
+
get withoutGuards(): EndpointGenerator {
|
|
663
|
+
return createEndpoint({
|
|
664
|
+
errors: [invalidRequest()]
|
|
665
|
+
})(${adapter}) as EndpointGenerator
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
`.trim();
|
|
669
|
+
});
|
|
670
|
+
const rest_endpoint_generator_findRestEndpointGenerator = (sharedFolder)=>{
|
|
671
|
+
const typeFile = external_node_path_default().join(sharedFolder.path, 'presentation', 'services', `${rest_endpoint_generator_name}-presentation-service.ts`);
|
|
672
|
+
if (!new file_system_File(typeFile).exists) return;
|
|
673
|
+
return {
|
|
674
|
+
typeName: 'RestEndpointGeneratorPresentationService',
|
|
675
|
+
typeFile,
|
|
676
|
+
wireName: 'wireRestEndpointGeneratorPresentationService',
|
|
677
|
+
wireFile: external_node_path_default().join(sharedFolder.path, 'wiring', 'presentation-services', `wire-${rest_endpoint_generator_name}-presentation-service.ts`)
|
|
678
|
+
};
|
|
679
|
+
};
|
|
680
|
+
const nextAppFolder = (root)=>[
|
|
681
|
+
'app',
|
|
682
|
+
'src/app'
|
|
683
|
+
].find((folder)=>new file_system_Folder(external_node_path_default().join(root, folder)).exists) ?? 'app';
|
|
684
|
+
const nextRoutePath = (root)=>external_node_path_default().posix.join(nextAppFolder(root), 'api/[...path]/route.ts');
|
|
685
|
+
const nextRoute = (restHandlersImport)=>`
|
|
686
|
+
import { nextEndpoints } from '@domain-first/handlers-next'
|
|
687
|
+
${restHandlersImport ? `import { restHandlers } from '${restHandlersImport}'
|
|
688
|
+
|
|
689
|
+
const handler = nextEndpoints(restHandlers)` : `
|
|
690
|
+
/**
|
|
691
|
+
* Pass the endpoints' handle here; their paths are relative to this route's folder.
|
|
692
|
+
*/
|
|
693
|
+
const handler = nextEndpoints([])`}
|
|
694
|
+
|
|
695
|
+
export const GET = handler
|
|
696
|
+
export const POST = handler
|
|
697
|
+
export const PUT = handler
|
|
698
|
+
export const PATCH = handler
|
|
699
|
+
export const DELETE = handler
|
|
700
|
+
`.trim();
|
|
701
|
+
const scaffoldNextRoute = (root)=>{
|
|
702
|
+
const { rootFolder, domainFirstPackages } = config_file_ConfigFile.Instance.data;
|
|
703
|
+
const routePath = nextRoutePath(root);
|
|
704
|
+
const routeFile = external_node_path_default().join(root, routePath);
|
|
705
|
+
if (new file_system_File(routeFile).exists) return [];
|
|
706
|
+
if (!domainFirstPackages.includes('@domain-first/wire')) {
|
|
707
|
+
new file_system_File(routeFile).data = nextRoute(void 0);
|
|
708
|
+
return [];
|
|
709
|
+
}
|
|
710
|
+
const restFolder = new file_system_Folder(root).subitem([
|
|
711
|
+
rootFolder,
|
|
712
|
+
'presentation',
|
|
713
|
+
'rest'
|
|
714
|
+
]);
|
|
715
|
+
new file_system_File(routeFile).data = nextRoute(wiring_relativeImport(routeFile, restFolder.path));
|
|
716
|
+
return new file_system_File(external_node_path_default().join(restFolder.path, 'index.ts')).exists ? [] : [
|
|
717
|
+
`${routePath} serves restHandlers from ${external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/rest/index.ts')}, which appears with the first REST endpoint — generate one with df-scaffold (Presentation → New Handlers-REST Endpoint) and the route compiles`
|
|
718
|
+
];
|
|
719
|
+
};
|
|
720
|
+
const askNextAdapter = async ()=>hasDependency('next') && await (0, prompts_namespaceObject.confirm)({
|
|
721
|
+
message: 'Use Next adapter for REST endpoints'
|
|
722
|
+
});
|
|
723
|
+
const scaffoldRestEndpointGeneratorFiles = ({ withNextAdapter })=>{
|
|
724
|
+
const root = new project_root_ProjectRoot().path;
|
|
725
|
+
const generatorExisted = rest_endpoint_generator_restEndpointGeneratorApplied();
|
|
726
|
+
const routeNotes = file_system_withoutOverwrites(()=>{
|
|
727
|
+
scaffoldRestEndpointGenerator(new file_system_Folder(root).subitem([
|
|
728
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
729
|
+
'shared-kernel'
|
|
730
|
+
]), {
|
|
731
|
+
withNextAdapter
|
|
732
|
+
});
|
|
733
|
+
return withNextAdapter ? scaffoldNextRoute(root) : [];
|
|
734
|
+
});
|
|
735
|
+
if (!withNextAdapter) return [];
|
|
736
|
+
return [
|
|
737
|
+
...missingPackages([
|
|
738
|
+
'@domain-first/handlers-next'
|
|
739
|
+
]),
|
|
740
|
+
...routeNotes,
|
|
741
|
+
...generatorExisted ? [
|
|
742
|
+
'the existing endpoint generator was kept — pass nextAdapter from @domain-first/handlers-next to its createEndpoint calls'
|
|
743
|
+
] : []
|
|
744
|
+
];
|
|
745
|
+
};
|
|
746
|
+
const rest_endpoint_generator_restEndpointGeneratorApplied = ()=>Boolean(rest_endpoint_generator_findRestEndpointGenerator(new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
747
|
+
config_file_ConfigFile.Instance.data.rootFolder,
|
|
748
|
+
'shared-kernel'
|
|
749
|
+
])));
|
|
750
|
+
const initializeUseCase = async ()=>{
|
|
751
|
+
const rootFolderName = await (0, prompts_namespaceObject.input)({
|
|
752
|
+
message: 'Root folder (use "/" for inner folders):',
|
|
753
|
+
default: 'src'
|
|
754
|
+
});
|
|
755
|
+
const domainFirstPackages = await (0, prompts_namespaceObject.checkbox)({
|
|
756
|
+
message: '@domain-first packages',
|
|
757
|
+
choices: [
|
|
758
|
+
'@domain-first/types',
|
|
759
|
+
'@domain-first/errors',
|
|
760
|
+
'@domain-first/handlers',
|
|
761
|
+
'@domain-first/wire',
|
|
762
|
+
'@domain-first/handlers-rest'
|
|
763
|
+
]
|
|
764
|
+
});
|
|
765
|
+
const withNextAdapter = domainFirstPackages.includes('@domain-first/handlers-rest') && await askNextAdapter();
|
|
766
|
+
const defaultPersistenceLayerImplementation = await (0, prompts_namespaceObject.input)({
|
|
767
|
+
message: 'Default persistence layer implementation:'
|
|
768
|
+
});
|
|
769
|
+
const withInMemoryDb = await (0, prompts_namespaceObject.confirm)({
|
|
770
|
+
message: 'Scaffold in-memory DB for test implementations'
|
|
771
|
+
});
|
|
772
|
+
const useReact = await (0, prompts_namespaceObject.confirm)({
|
|
773
|
+
message: 'Use React'
|
|
774
|
+
});
|
|
775
|
+
let storybookFramework;
|
|
776
|
+
const withStorybook = useReact ? await (0, prompts_namespaceObject.confirm)({
|
|
777
|
+
message: 'Use Storybook'
|
|
778
|
+
}) : false;
|
|
779
|
+
if (withStorybook) storybookFramework = await (0, prompts_namespaceObject.input)({
|
|
780
|
+
message: 'Storybook framework package:',
|
|
781
|
+
default: '@storybook/react-vite'
|
|
782
|
+
});
|
|
783
|
+
let testingLibrary;
|
|
784
|
+
const withTests = await (0, prompts_namespaceObject.confirm)({
|
|
785
|
+
message: 'Scaffold unit tests'
|
|
786
|
+
});
|
|
787
|
+
if (withTests) testingLibrary = await (0, prompts_namespaceObject.input)({
|
|
788
|
+
message: 'Unit testing library:',
|
|
789
|
+
default: 'vitest'
|
|
790
|
+
});
|
|
791
|
+
config_file_ConfigFile.write({
|
|
792
|
+
rootFolder: rootFolderName,
|
|
793
|
+
domainFirstPackages,
|
|
794
|
+
defaultPersistenceLayerImplementation,
|
|
795
|
+
withInMemoryDb,
|
|
796
|
+
useReact,
|
|
797
|
+
storybookFramework,
|
|
798
|
+
testingLibrary
|
|
799
|
+
});
|
|
800
|
+
const { path } = new project_root_ProjectRoot();
|
|
801
|
+
const rootFolder = new file_system_Folder(path);
|
|
802
|
+
if (domainFirstPackages.includes('@domain-first/wire')) rootFolder.subitem([
|
|
803
|
+
rootFolderName,
|
|
804
|
+
'shared-kernel',
|
|
805
|
+
'wiring'
|
|
806
|
+
]).createFile('env-branched-wire.ts', `
|
|
807
|
+
import { branchedWire } from '@domain-first/wire'
|
|
808
|
+
|
|
809
|
+
export const envBranchedWire = branchedWire(() => {
|
|
810
|
+
return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
|
|
811
|
+
});
|
|
812
|
+
`.trim());
|
|
813
|
+
if (withInMemoryDb) in_memory_db_scaffoldInMemoryDb(rootFolder.subitem([
|
|
814
|
+
rootFolderName,
|
|
815
|
+
'shared-kernel'
|
|
816
|
+
]));
|
|
817
|
+
const nextSteps = missingDomainFirstPackages();
|
|
818
|
+
if (domainFirstPackages.includes('@domain-first/handlers-rest')) nextSteps.push(...scaffoldRestEndpointGeneratorFiles({
|
|
819
|
+
withNextAdapter
|
|
820
|
+
}));
|
|
821
|
+
return nextSteps;
|
|
822
|
+
};
|
|
823
|
+
new Set([
|
|
824
|
+
'node_modules',
|
|
825
|
+
'.git',
|
|
826
|
+
'.next',
|
|
827
|
+
'dist',
|
|
828
|
+
'build',
|
|
829
|
+
'out',
|
|
830
|
+
'coverage',
|
|
831
|
+
'storybook-static'
|
|
832
|
+
]);
|
|
833
|
+
const help = `Usage: df-init
|
|
834
|
+
|
|
835
|
+
Initializes a Domain-First project: asks for the source folder, the
|
|
836
|
+
@domain-first packages, the default persistence implementation, the shared
|
|
837
|
+
in-memory DB, React, Storybook and the testing library, writes
|
|
838
|
+
domain-first.project-structure.config.json and scaffolds the Shared Kernel
|
|
839
|
+
files they need. Prints the install command; nothing is installed.
|
|
840
|
+
|
|
841
|
+
Options:
|
|
842
|
+
-h, --help show this help`;
|
|
843
|
+
const { values } = (0, external_node_util_namespaceObject.parseArgs)({
|
|
844
|
+
options: {
|
|
845
|
+
help: {
|
|
846
|
+
type: 'boolean',
|
|
847
|
+
short: 'h',
|
|
848
|
+
default: false
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
if (values.help) {
|
|
853
|
+
console.log(help);
|
|
854
|
+
process.exit(0);
|
|
855
|
+
}
|
|
856
|
+
if (config_file_ConfigFile.exists) {
|
|
857
|
+
console.log('domain-first.project-structure.config.json already exists: edit it or add Shared Kernel files with df-integration.');
|
|
858
|
+
process.exit(1);
|
|
859
|
+
}
|
|
860
|
+
const run = async ()=>{
|
|
861
|
+
const nextSteps = await initializeUseCase();
|
|
862
|
+
if (await save_pending_changes_savePendingChanges()) print_next_steps_printNextSteps(nextSteps);
|
|
863
|
+
};
|
|
864
|
+
run();
|
|
865
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
866
|
+
Object.defineProperty(exports, '__esModule', {
|
|
867
|
+
value: true
|
|
868
|
+
});
|