@domain-first/project-structure 2.18.1 → 3.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 +34 -2
- package/dist/index.cjs +602 -533
- package/dist/index.js +601 -532
- package/dist/print-next-steps.d.ts +5 -0
- package/dist/use-cases/initialize.d.ts +4 -1
- package/dist/use-cases/rest-endpoint-generator.d.ts +20 -0
- package/dist/use-cases/rest-endpoint-generator.spec.d.ts +1 -0
- package/dist/use-cases/scaffold-new-presentation-service.d.ts +5 -0
- package/dist/use-cases/wire-dependency.d.ts +3 -8
- package/dist/wiring.d.ts +0 -4
- package/package.json +1 -1
- package/skills/df-ps-implement/SKILL.md +2 -2
- package/skills/df-ps-scaffold/SKILL.md +1 -1
- package/skills/df-ps-scaffold/references/generators.md +5 -5
package/dist/index.cjs
CHANGED
|
@@ -219,6 +219,28 @@ class ConfigFile {
|
|
|
219
219
|
new File(ConfigFile.path).data = JSON.stringify(config, null, '\t');
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
+
const external_node_util_namespaceObject = require("node:util");
|
|
223
|
+
const printNextSteps = (nextSteps)=>{
|
|
224
|
+
const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
|
|
225
|
+
const commands = nextSteps.filter(isCommand);
|
|
226
|
+
const notes = nextSteps.filter((line)=>!isCommand(line));
|
|
227
|
+
const sections = [];
|
|
228
|
+
if (commands.length) sections.push([
|
|
229
|
+
'Run these commands to install the required dependencies:',
|
|
230
|
+
...commands.map((line)=>(0, external_node_util_namespaceObject.styleText)([
|
|
231
|
+
'bold',
|
|
232
|
+
'cyan'
|
|
233
|
+
], line))
|
|
234
|
+
].join('\n'));
|
|
235
|
+
if (notes.length) sections.push([
|
|
236
|
+
'Additional information:',
|
|
237
|
+
...notes.map((line)=>line.replace(/^(\s*Add )(!\S+)/, (_, prefix, path)=>prefix + (0, external_node_util_namespaceObject.styleText)([
|
|
238
|
+
'bold',
|
|
239
|
+
'cyan'
|
|
240
|
+
], path)))
|
|
241
|
+
].join('\n'));
|
|
242
|
+
if (sections.length) console.log(sections.join('\n\n'));
|
|
243
|
+
};
|
|
222
244
|
const savePendingChanges = async ()=>{
|
|
223
245
|
const overwrittenFiles = filesToOverwrite();
|
|
224
246
|
if (overwrittenFiles.length) {
|
|
@@ -238,7 +260,6 @@ const savePendingChanges = async ()=>{
|
|
|
238
260
|
writePendingChanges();
|
|
239
261
|
return true;
|
|
240
262
|
};
|
|
241
|
-
const external_node_util_namespaceObject = require("node:util");
|
|
242
263
|
const missingDomainFirstPackages = ()=>{
|
|
243
264
|
const packages = ConfigFile.Instance.data.domainFirstPackages;
|
|
244
265
|
const manifest = JSON.parse(new File(external_node_path_default().join(new ProjectRoot().path, 'package.json')).data);
|
|
@@ -1162,97 +1183,7 @@ const addIntegration = async ()=>{
|
|
|
1162
1183
|
}))
|
|
1163
1184
|
});
|
|
1164
1185
|
const nextSteps = await integration.run();
|
|
1165
|
-
if (await savePendingChanges())
|
|
1166
|
-
const isCommand = (line)=>/^\s*(?:npm (?:i|install)|npx playwright install)\b/.test(line);
|
|
1167
|
-
const commands = nextSteps.filter(isCommand);
|
|
1168
|
-
const notes = nextSteps.filter((line)=>!isCommand(line));
|
|
1169
|
-
const sections = [];
|
|
1170
|
-
if (commands.length) sections.push([
|
|
1171
|
-
'Run these commands to install the required dependencies:',
|
|
1172
|
-
...commands.map((line)=>(0, external_node_util_namespaceObject.styleText)([
|
|
1173
|
-
'bold',
|
|
1174
|
-
'cyan'
|
|
1175
|
-
], line))
|
|
1176
|
-
].join('\n'));
|
|
1177
|
-
if (notes.length) sections.push([
|
|
1178
|
-
'Additional information:',
|
|
1179
|
-
...notes.map((line)=>line.replace(/^(\s*Add )(!\S+)/, (_, prefix, path)=>prefix + (0, external_node_util_namespaceObject.styleText)([
|
|
1180
|
-
'bold',
|
|
1181
|
-
'cyan'
|
|
1182
|
-
], path)))
|
|
1183
|
-
].join('\n'));
|
|
1184
|
-
if (sections.length) console.log(sections.join('\n\n'));
|
|
1185
|
-
}
|
|
1186
|
-
};
|
|
1187
|
-
const initializeUseCase = async ()=>{
|
|
1188
|
-
const rootFolderName = await (0, prompts_namespaceObject.input)({
|
|
1189
|
-
message: 'Root folder (use "/" for inner folders):',
|
|
1190
|
-
default: 'src'
|
|
1191
|
-
});
|
|
1192
|
-
const domainFirstPackages = await (0, prompts_namespaceObject.checkbox)({
|
|
1193
|
-
message: '@domain-first packages',
|
|
1194
|
-
choices: [
|
|
1195
|
-
'@domain-first/types',
|
|
1196
|
-
'@domain-first/errors',
|
|
1197
|
-
'@domain-first/handlers',
|
|
1198
|
-
'@domain-first/wire',
|
|
1199
|
-
'@domain-first/handlers-rest'
|
|
1200
|
-
]
|
|
1201
|
-
});
|
|
1202
|
-
const defaultPersistenceLayerImplementation = await (0, prompts_namespaceObject.input)({
|
|
1203
|
-
message: 'Default persistence layer implementation:'
|
|
1204
|
-
});
|
|
1205
|
-
const useReact = await (0, prompts_namespaceObject.confirm)({
|
|
1206
|
-
message: 'Use React'
|
|
1207
|
-
});
|
|
1208
|
-
let storybookFramework;
|
|
1209
|
-
const withStorybook = useReact ? await (0, prompts_namespaceObject.confirm)({
|
|
1210
|
-
message: 'Use Storybook'
|
|
1211
|
-
}) : false;
|
|
1212
|
-
if (withStorybook) storybookFramework = await (0, prompts_namespaceObject.input)({
|
|
1213
|
-
message: 'Storybook framework package:',
|
|
1214
|
-
default: '@storybook/react-vite'
|
|
1215
|
-
});
|
|
1216
|
-
let testingLibrary;
|
|
1217
|
-
const withTests = await (0, prompts_namespaceObject.confirm)({
|
|
1218
|
-
message: 'Scaffold unit tests'
|
|
1219
|
-
});
|
|
1220
|
-
if (withTests) testingLibrary = await (0, prompts_namespaceObject.input)({
|
|
1221
|
-
message: 'Unit testing library:',
|
|
1222
|
-
default: 'vitest'
|
|
1223
|
-
});
|
|
1224
|
-
ConfigFile.write({
|
|
1225
|
-
rootFolder: rootFolderName,
|
|
1226
|
-
domainFirstPackages,
|
|
1227
|
-
defaultPersistenceLayerImplementation,
|
|
1228
|
-
useReact,
|
|
1229
|
-
storybookFramework,
|
|
1230
|
-
testingLibrary
|
|
1231
|
-
});
|
|
1232
|
-
const { path } = new ProjectRoot();
|
|
1233
|
-
const rootFolder = new Folder(path);
|
|
1234
|
-
if (domainFirstPackages.includes('@domain-first/wire')) rootFolder.subitem([
|
|
1235
|
-
rootFolderName,
|
|
1236
|
-
'shared',
|
|
1237
|
-
'wiring'
|
|
1238
|
-
]).createFile('env-branched-wire.ts', `
|
|
1239
|
-
import { branchedWire } from '@domain-first/wire'
|
|
1240
|
-
|
|
1241
|
-
export const envBranchedWire = branchedWire(() => {
|
|
1242
|
-
return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
|
|
1243
|
-
});
|
|
1244
|
-
`.trim());
|
|
1245
|
-
if (domainFirstPackages.includes('@domain-first/errors')) rootFolder.subitem([
|
|
1246
|
-
rootFolderName,
|
|
1247
|
-
'shared'
|
|
1248
|
-
]).subitem([
|
|
1249
|
-
'domain',
|
|
1250
|
-
'errors'
|
|
1251
|
-
]).createFile('index.ts', `
|
|
1252
|
-
import { errorNamespace } from '@domain-first/errors'
|
|
1253
|
-
|
|
1254
|
-
export const SharedErrors = errorNamespace('shared')
|
|
1255
|
-
`.trim());
|
|
1186
|
+
if (await savePendingChanges()) printNextSteps(nextSteps);
|
|
1256
1187
|
};
|
|
1257
1188
|
class UnknownFormatNaming {
|
|
1258
1189
|
rawSource;
|
|
@@ -1282,328 +1213,65 @@ class UnknownFormatNaming {
|
|
|
1282
1213
|
return this.fileName.replaceAll('-', ' ');
|
|
1283
1214
|
}
|
|
1284
1215
|
}
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
const ignoredFolders = new Set([
|
|
1308
|
-
'node_modules',
|
|
1309
|
-
'.git',
|
|
1310
|
-
'.next',
|
|
1311
|
-
'dist',
|
|
1312
|
-
'build',
|
|
1313
|
-
'out',
|
|
1314
|
-
'coverage',
|
|
1315
|
-
'storybook-static'
|
|
1316
|
-
]);
|
|
1317
|
-
const codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx)$/;
|
|
1318
|
-
const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1319
|
-
const react_module_move_walk = (folder)=>{
|
|
1320
|
-
if (!external_node_fs_default().existsSync(folder)) return [];
|
|
1321
|
-
return external_node_fs_default().readdirSync(folder, {
|
|
1322
|
-
withFileTypes: true
|
|
1323
|
-
}).flatMap((entry)=>{
|
|
1324
|
-
const entryPath = external_node_path_default().join(folder, entry.name);
|
|
1325
|
-
if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : react_module_move_walk(entryPath);
|
|
1326
|
-
return entry.isFile() ? [
|
|
1327
|
-
entryPath
|
|
1328
|
-
] : [];
|
|
1329
|
-
});
|
|
1330
|
-
};
|
|
1331
|
-
const toPosix = (value)=>value.split(external_node_path_default().sep).join('/');
|
|
1332
|
-
const nestedName = (folders, fileBase)=>{
|
|
1333
|
-
const prefix = `${folders.join('-')}-`;
|
|
1334
|
-
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
1335
|
-
return [
|
|
1336
|
-
...folders,
|
|
1337
|
-
last
|
|
1338
|
-
].join('/');
|
|
1339
|
-
};
|
|
1340
|
-
const declaredClassName = (filePath, suffix, name)=>{
|
|
1341
|
-
const content = external_node_fs_default().readFileSync(filePath, 'utf8');
|
|
1342
|
-
const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
1343
|
-
return declared ?? new NestedName(name).ClassName;
|
|
1344
|
-
};
|
|
1345
|
-
const findReactModules = (reactFolder, kind)=>{
|
|
1346
|
-
const modules = 'page' === kind ? react_module_move_walk(external_node_path_default().join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
1347
|
-
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);
|
|
1348
|
-
const fileBase = external_node_path_default().basename(file, '-page.tsx');
|
|
1349
|
-
const name = nestedName(folders, fileBase);
|
|
1350
|
-
return {
|
|
1351
|
-
kind,
|
|
1352
|
-
name,
|
|
1353
|
-
path: file,
|
|
1354
|
-
fileBase,
|
|
1355
|
-
ClassName: declaredClassName(file, 'Page', name)
|
|
1356
|
-
};
|
|
1357
|
-
}) : react_module_move_walk(external_node_path_default().join(reactFolder, 'widgets')).filter((file)=>file.endsWith('-widget.tsx')).map((file)=>{
|
|
1358
|
-
const folder = external_node_path_default().dirname(file);
|
|
1359
|
-
const name = toPosix(external_node_path_default().relative(external_node_path_default().join(reactFolder, 'widgets'), folder));
|
|
1360
|
-
return {
|
|
1361
|
-
kind,
|
|
1362
|
-
name,
|
|
1363
|
-
path: folder,
|
|
1364
|
-
fileBase: external_node_path_default().basename(file, '-widget.tsx'),
|
|
1365
|
-
ClassName: declaredClassName(file, 'Widget', name)
|
|
1366
|
-
};
|
|
1367
|
-
});
|
|
1368
|
-
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
1216
|
+
const wiring_layers = [
|
|
1217
|
+
'domain',
|
|
1218
|
+
'application',
|
|
1219
|
+
'infrastructure',
|
|
1220
|
+
'presentation'
|
|
1221
|
+
];
|
|
1222
|
+
const visibleLayers = {
|
|
1223
|
+
domain: [
|
|
1224
|
+
'domain'
|
|
1225
|
+
],
|
|
1226
|
+
application: [
|
|
1227
|
+
'domain',
|
|
1228
|
+
'application'
|
|
1229
|
+
],
|
|
1230
|
+
infrastructure: [
|
|
1231
|
+
'domain',
|
|
1232
|
+
'infrastructure'
|
|
1233
|
+
],
|
|
1234
|
+
presentation: [
|
|
1235
|
+
'application',
|
|
1236
|
+
'presentation'
|
|
1237
|
+
]
|
|
1369
1238
|
};
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1372
|
-
|
|
1239
|
+
const branchedTypeFiles = {
|
|
1240
|
+
repositories: (fileBase)=>[
|
|
1241
|
+
'domain',
|
|
1242
|
+
'aggregates',
|
|
1243
|
+
fileBase.replace(/-repository$/, ''),
|
|
1244
|
+
`${fileBase}.ts`
|
|
1245
|
+
],
|
|
1246
|
+
commands: (fileBase)=>[
|
|
1247
|
+
'application',
|
|
1248
|
+
'commands',
|
|
1249
|
+
'execution',
|
|
1250
|
+
`${fileBase}.ts`
|
|
1251
|
+
],
|
|
1252
|
+
queries: (fileBase)=>[
|
|
1253
|
+
'application',
|
|
1254
|
+
'queries',
|
|
1255
|
+
'execution',
|
|
1256
|
+
`${fileBase}.ts`
|
|
1257
|
+
],
|
|
1258
|
+
'application-ports': (fileBase)=>[
|
|
1259
|
+
'application',
|
|
1260
|
+
'ports',
|
|
1261
|
+
`${fileBase}.ts`
|
|
1262
|
+
]
|
|
1373
1263
|
};
|
|
1374
|
-
const
|
|
1375
|
-
const
|
|
1376
|
-
|
|
1377
|
-
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
1378
|
-
if (target !== module.path && external_node_fs_default().existsSync(target)) return `${external_node_path_default().relative(reactFolder, target)} already exists`;
|
|
1379
|
-
if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
|
|
1380
|
-
return true;
|
|
1264
|
+
const layerOf = (file, contextPath)=>{
|
|
1265
|
+
const [firstSegment] = external_node_path_default().relative(contextPath, file).split(external_node_path_default().sep);
|
|
1266
|
+
return wiring_layers.find((layer)=>layer === firstSegment);
|
|
1381
1267
|
};
|
|
1382
|
-
const
|
|
1383
|
-
const
|
|
1384
|
-
const
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
const { compilerOptions = {} } = JSON.parse(stripJsonComments(external_node_fs_default().readFileSync(tsconfig, 'utf8')));
|
|
1388
|
-
const base = external_node_path_default().resolve(projectRoot, compilerOptions.baseUrl ?? '.');
|
|
1389
|
-
return Object.entries(compilerOptions.paths ?? {}).filter(([pattern, targets])=>pattern.endsWith('*') && targets[0]?.endsWith('*')).map(([pattern, [target]])=>({
|
|
1390
|
-
prefix: pattern.slice(0, -1),
|
|
1391
|
-
target: external_node_path_default().resolve(base, target.slice(0, -1))
|
|
1392
|
-
}));
|
|
1393
|
-
} catch {
|
|
1394
|
-
return [];
|
|
1268
|
+
const namedImports = (source, fromFile)=>{
|
|
1269
|
+
const result = new Map();
|
|
1270
|
+
for (const [, names, importPath] of source.matchAll(/import\s*(?:type\s*)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g))for (const name of names.split(',')){
|
|
1271
|
+
const cleanName = name.replace(/^\s*type\s+/, '').trim();
|
|
1272
|
+
if (cleanName) result.set(cleanName, `${external_node_path_default().resolve(external_node_path_default().dirname(fromFile), importPath)}.ts`);
|
|
1395
1273
|
}
|
|
1396
|
-
|
|
1397
|
-
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
|
|
1398
|
-
const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
|
|
1399
|
-
const importPaths = (file)=>{
|
|
1400
|
-
const withoutExtension = file.replace(codeExtension, '');
|
|
1401
|
-
return 'index' === external_node_path_default().basename(withoutExtension) ? [
|
|
1402
|
-
withoutExtension,
|
|
1403
|
-
external_node_path_default().dirname(withoutExtension)
|
|
1404
|
-
] : [
|
|
1405
|
-
withoutExtension
|
|
1406
|
-
];
|
|
1407
|
-
};
|
|
1408
|
-
const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
1409
|
-
const newName = new NestedName(rawName);
|
|
1410
|
-
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
1411
|
-
const newClassName = newName.ClassName;
|
|
1412
|
-
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.])`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
1413
|
-
const oldFolder = 'page' === module.kind ? external_node_path_default().dirname(module.path) : module.path;
|
|
1414
|
-
const newFolder = 'page' === module.kind ? external_node_path_default().dirname(target) : target;
|
|
1415
|
-
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}`);
|
|
1416
|
-
const movedPath = (candidate)=>{
|
|
1417
|
-
if (!ownsPath(candidate)) return;
|
|
1418
|
-
const segments = external_node_path_default().relative(oldFolder, candidate).split(external_node_path_default().sep);
|
|
1419
|
-
const last = segments.length - 1;
|
|
1420
|
-
segments[last] = renameFile(segments[last]);
|
|
1421
|
-
return external_node_path_default().join(newFolder, ...segments);
|
|
1422
|
-
};
|
|
1423
|
-
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);
|
|
1424
|
-
const moves = new Map(moduleFiles.map((file)=>[
|
|
1425
|
-
file,
|
|
1426
|
-
movedPath(file) ?? file
|
|
1427
|
-
]));
|
|
1428
|
-
const aliases = readAliases(projectRoot);
|
|
1429
|
-
const resolve = (specifier, fromFile)=>{
|
|
1430
|
-
if (specifier.startsWith('.')) return {
|
|
1431
|
-
resolved: external_node_path_default().resolve(external_node_path_default().dirname(fromFile), specifier),
|
|
1432
|
-
alias: void 0
|
|
1433
|
-
};
|
|
1434
|
-
const alias = aliases.find(({ prefix })=>specifier.startsWith(prefix));
|
|
1435
|
-
return alias ? {
|
|
1436
|
-
resolved: external_node_path_default().resolve(alias.target, specifier.slice(alias.prefix.length)),
|
|
1437
|
-
alias
|
|
1438
|
-
} : void 0;
|
|
1439
|
-
};
|
|
1440
|
-
const specifierFor = (fromFile, toPath, alias)=>{
|
|
1441
|
-
const aliased = alias && toPosix(external_node_path_default().relative(alias.target, toPath));
|
|
1442
|
-
if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
|
|
1443
|
-
const relative = toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toPath));
|
|
1444
|
-
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
1445
|
-
};
|
|
1446
|
-
const suffixes = 'page' === module.kind ? 'Page' : 'Widget|UIModel';
|
|
1447
|
-
const classPattern = new RegExp(`(?<![\\w$])(use)?${escapeRegExp(module.ClassName)}(?=${suffixes})`, 'g');
|
|
1448
|
-
const oldTitle = `Widgets/${module.name.split('/').map((segment)=>new NestedName(segment).ClassName).join('/')}`;
|
|
1449
|
-
const titlePattern = new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
1450
|
-
const newTitle = [
|
|
1451
|
-
'Widgets',
|
|
1452
|
-
...newName.classNameSegments
|
|
1453
|
-
].join('/');
|
|
1454
|
-
const codeFiles = new Map(react_module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
1455
|
-
file,
|
|
1456
|
-
external_node_fs_default().readFileSync(file, 'utf8')
|
|
1457
|
-
]));
|
|
1458
|
-
const barrels = new Set();
|
|
1459
|
-
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
1460
|
-
for(let found = true; found;){
|
|
1461
|
-
found = false;
|
|
1462
|
-
for (const [file, content] of codeFiles){
|
|
1463
|
-
if (moves.has(file) || isBarrel(file)) continue;
|
|
1464
|
-
const reExportsModule = [
|
|
1465
|
-
...content.matchAll(reExportPattern)
|
|
1466
|
-
].some(([, , specifier])=>{
|
|
1467
|
-
const resolution = resolve(specifier, file);
|
|
1468
|
-
return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
|
|
1469
|
-
});
|
|
1470
|
-
if (reExportsModule) {
|
|
1471
|
-
for (const importPath of importPaths(file))barrels.add(importPath);
|
|
1472
|
-
found = true;
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
const rewrite = (content, oldFile, newFile)=>{
|
|
1477
|
-
let referencesModule = false;
|
|
1478
|
-
const rewritten = content.replace(specifierPattern, (match, keyword, quote, specifier)=>{
|
|
1479
|
-
const resolution = resolve(specifier, oldFile);
|
|
1480
|
-
if (!resolution) return match;
|
|
1481
|
-
const moved = movedPath(resolution.resolved);
|
|
1482
|
-
if (moved || isBarrel(resolution.resolved)) referencesModule = true;
|
|
1483
|
-
if (!moved && oldFile === newFile) return match;
|
|
1484
|
-
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
1485
|
-
return `${keyword}${quote}${next}${quote}`;
|
|
1486
|
-
});
|
|
1487
|
-
if (!referencesModule && !moves.has(oldFile)) return content;
|
|
1488
|
-
const renamed = rewritten.replace(classPattern, (_, use = '')=>`${use}${newClassName}`);
|
|
1489
|
-
return moves.has(oldFile) && 'widget' === module.kind ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
1490
|
-
};
|
|
1491
|
-
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile, reactFolder);
|
|
1492
|
-
const updated = [];
|
|
1493
|
-
for (const [file, content] of codeFiles){
|
|
1494
|
-
const newFile = moves.get(file);
|
|
1495
|
-
const next = rewrite(content, file, newFile ?? file);
|
|
1496
|
-
if (newFile && newFile !== file) {
|
|
1497
|
-
new File(newFile).data = next;
|
|
1498
|
-
new File(file).delete(reactFolder);
|
|
1499
|
-
} else if (next !== content) {
|
|
1500
|
-
new File(file).update(next);
|
|
1501
|
-
if (!newFile) updated.push(file);
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
return {
|
|
1505
|
-
moves: [
|
|
1506
|
-
...moves
|
|
1507
|
-
].filter(([from, to])=>from !== to),
|
|
1508
|
-
updated
|
|
1509
|
-
};
|
|
1510
|
-
};
|
|
1511
|
-
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
1512
|
-
const reactFolder = presentationReactFolder.path;
|
|
1513
|
-
const modules = findReactModules(reactFolder, kind);
|
|
1514
|
-
if (!modules.length) return void console.log(`No ${kind}s generated by df-ps were found.`);
|
|
1515
|
-
const module = await (0, prompts_namespaceObject.select)({
|
|
1516
|
-
message: 'page' === kind ? 'Page:' : 'Widget:',
|
|
1517
|
-
choices: modules.map((value)=>({
|
|
1518
|
-
name: value.name,
|
|
1519
|
-
value,
|
|
1520
|
-
description: external_node_path_default().relative(reactFolder, value.path)
|
|
1521
|
-
}))
|
|
1522
|
-
});
|
|
1523
|
-
const name = await (0, prompts_namespaceObject.input)({
|
|
1524
|
-
message: 'New name (folders split by "/"):',
|
|
1525
|
-
default: module.name,
|
|
1526
|
-
validate: (value)=>validateMove(reactFolder, module, value)
|
|
1527
|
-
});
|
|
1528
|
-
const root = new ProjectRoot().path;
|
|
1529
|
-
const { moves, updated } = moveReactModule(root, reactFolder, module, name);
|
|
1530
|
-
if (!moves.length && !updated.length) return void console.log('Nothing to change.');
|
|
1531
|
-
const relative = (file)=>external_node_path_default().relative(root, file);
|
|
1532
|
-
console.log([
|
|
1533
|
-
'Files to move:',
|
|
1534
|
-
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
1535
|
-
...updated.length ? [
|
|
1536
|
-
'Files with updated imports:',
|
|
1537
|
-
...updated.map((file)=>` ${relative(file)}`)
|
|
1538
|
-
] : []
|
|
1539
|
-
].join('\n'));
|
|
1540
|
-
if (!await (0, prompts_namespaceObject.confirm)({
|
|
1541
|
-
message: 'Apply?',
|
|
1542
|
-
default: true
|
|
1543
|
-
})) {
|
|
1544
|
-
discardPendingChanges();
|
|
1545
|
-
console.log('Cancelled: nothing was written.');
|
|
1546
|
-
}
|
|
1547
|
-
};
|
|
1548
|
-
const wiring_layers = [
|
|
1549
|
-
'domain',
|
|
1550
|
-
'application',
|
|
1551
|
-
'infrastructure',
|
|
1552
|
-
'presentation'
|
|
1553
|
-
];
|
|
1554
|
-
const visibleLayers = {
|
|
1555
|
-
domain: [
|
|
1556
|
-
'domain'
|
|
1557
|
-
],
|
|
1558
|
-
application: [
|
|
1559
|
-
'domain',
|
|
1560
|
-
'application'
|
|
1561
|
-
],
|
|
1562
|
-
infrastructure: [
|
|
1563
|
-
'domain',
|
|
1564
|
-
'infrastructure'
|
|
1565
|
-
],
|
|
1566
|
-
presentation: [
|
|
1567
|
-
'application',
|
|
1568
|
-
'presentation'
|
|
1569
|
-
]
|
|
1570
|
-
};
|
|
1571
|
-
const branchedTypeFiles = {
|
|
1572
|
-
repositories: (fileBase)=>[
|
|
1573
|
-
'domain',
|
|
1574
|
-
'aggregates',
|
|
1575
|
-
fileBase.replace(/-repository$/, ''),
|
|
1576
|
-
`${fileBase}.ts`
|
|
1577
|
-
],
|
|
1578
|
-
commands: (fileBase)=>[
|
|
1579
|
-
'application',
|
|
1580
|
-
'commands',
|
|
1581
|
-
'execution',
|
|
1582
|
-
`${fileBase}.ts`
|
|
1583
|
-
],
|
|
1584
|
-
queries: (fileBase)=>[
|
|
1585
|
-
'application',
|
|
1586
|
-
'queries',
|
|
1587
|
-
'execution',
|
|
1588
|
-
`${fileBase}.ts`
|
|
1589
|
-
],
|
|
1590
|
-
'application-ports': (fileBase)=>[
|
|
1591
|
-
'application',
|
|
1592
|
-
'ports',
|
|
1593
|
-
`${fileBase}.ts`
|
|
1594
|
-
]
|
|
1595
|
-
};
|
|
1596
|
-
const layerOf = (file, contextPath)=>{
|
|
1597
|
-
const [firstSegment] = external_node_path_default().relative(contextPath, file).split(external_node_path_default().sep);
|
|
1598
|
-
return wiring_layers.find((layer)=>layer === firstSegment);
|
|
1599
|
-
};
|
|
1600
|
-
const namedImports = (source, fromFile)=>{
|
|
1601
|
-
const result = new Map();
|
|
1602
|
-
for (const [, names, importPath] of source.matchAll(/import\s*(?:type\s*)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g))for (const name of names.split(',')){
|
|
1603
|
-
const cleanName = name.replace(/^\s*type\s+/, '').trim();
|
|
1604
|
-
if (cleanName) result.set(cleanName, `${external_node_path_default().resolve(external_node_path_default().dirname(fromFile), importPath)}.ts`);
|
|
1605
|
-
}
|
|
1606
|
-
return result;
|
|
1274
|
+
return result;
|
|
1607
1275
|
};
|
|
1608
1276
|
const isEndpointWire = (wiringRelativePath)=>wiringRelativePath.startsWith([
|
|
1609
1277
|
'presentation',
|
|
@@ -1691,7 +1359,6 @@ const kindRules = {
|
|
|
1691
1359
|
};
|
|
1692
1360
|
const wiring_implementationType = (consumer, implementation)=>consumer.branched ? external_node_path_default().basename(external_node_path_default().dirname(implementation.file)) : void 0;
|
|
1693
1361
|
const isSuggestedFor = (candidate, implementation)=>'infrastructure' === candidate.layer && `-${external_node_path_default().basename(candidate.typeFile, '.ts')}-`.includes(`-${implementation}-`);
|
|
1694
|
-
const isSuggestedEndpointGenerator = (candidate)=>candidate.typeName.toLowerCase().includes('endpoint');
|
|
1695
1362
|
const canDependOn = (consumer, candidate)=>visibleLayers[consumer.implementationsLayer].includes(candidate.layer) && (kindRules[consumer.kind]?.(candidate, consumer) ?? true);
|
|
1696
1363
|
const availableDependencies = (consumer, implementation, candidates)=>{
|
|
1697
1364
|
const wired = wiredDependencyNames(new File(consumer.wireFile).data, implementation.className);
|
|
@@ -1906,78 +1573,524 @@ const contextAndSharedModules = (boundedContextFolder)=>{
|
|
|
1906
1573
|
}))
|
|
1907
1574
|
];
|
|
1908
1575
|
};
|
|
1909
|
-
const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations)=>{
|
|
1910
|
-
const options = contextAndSharedModules(boundedContextFolder);
|
|
1911
|
-
let asked = false;
|
|
1912
|
-
for (const implementation of implementations){
|
|
1913
|
-
const available = availableDependencies(consumer, implementation, options.map((x)=>x.module));
|
|
1914
|
-
const candidates = options.filter((x)=>available.includes(x.module));
|
|
1915
|
-
if (!candidates.length) continue;
|
|
1916
|
-
asked = true;
|
|
1917
|
-
const type = wiring_implementationType(consumer, implementation);
|
|
1918
|
-
const suggested = type ? candidates.filter((x)=>isSuggestedFor(x.module, type)) : [];
|
|
1919
|
-
const dependencies = await (0, prompts_namespaceObject.checkbox)({
|
|
1920
|
-
message: consumer.branched ? `Dependencies for ${implementation.className}:` : 'Dependencies:',
|
|
1921
|
-
choices: groupedChoices(candidates, suggested),
|
|
1922
|
-
pageSize: groupedPageSize,
|
|
1923
|
-
loop: false
|
|
1576
|
+
const promptDependencies = async (boundedContextFolder, consumer, implementations = consumer.implementations)=>{
|
|
1577
|
+
const options = contextAndSharedModules(boundedContextFolder);
|
|
1578
|
+
let asked = false;
|
|
1579
|
+
for (const implementation of implementations){
|
|
1580
|
+
const available = availableDependencies(consumer, implementation, options.map((x)=>x.module));
|
|
1581
|
+
const candidates = options.filter((x)=>available.includes(x.module));
|
|
1582
|
+
if (!candidates.length) continue;
|
|
1583
|
+
asked = true;
|
|
1584
|
+
const type = wiring_implementationType(consumer, implementation);
|
|
1585
|
+
const suggested = type ? candidates.filter((x)=>isSuggestedFor(x.module, type)) : [];
|
|
1586
|
+
const dependencies = await (0, prompts_namespaceObject.checkbox)({
|
|
1587
|
+
message: consumer.branched ? `Dependencies for ${implementation.className}:` : 'Dependencies:',
|
|
1588
|
+
choices: groupedChoices(candidates, suggested),
|
|
1589
|
+
pageSize: groupedPageSize,
|
|
1590
|
+
loop: false
|
|
1591
|
+
});
|
|
1592
|
+
if (dependencies.length) wireDependencies(consumer, implementation, dependencies.map((x)=>x.module));
|
|
1593
|
+
}
|
|
1594
|
+
return asked;
|
|
1595
|
+
};
|
|
1596
|
+
const wireNewModuleDependencies = async (boundedContextFolder, wireFile)=>{
|
|
1597
|
+
const consumer = readWiredModule(wireFile.path, boundedContextFolder.path);
|
|
1598
|
+
if (consumer) await promptDependencies(boundedContextFolder, consumer);
|
|
1599
|
+
};
|
|
1600
|
+
const wireDependency = async (boundedContextFolder)=>{
|
|
1601
|
+
const modules = findWiredModules(boundedContextFolder.path);
|
|
1602
|
+
if (!modules.length) return void console.log('No wired modules here yet.');
|
|
1603
|
+
const { module: consumer, implementation } = await (0, prompts_namespaceObject.select)({
|
|
1604
|
+
message: 'Module:',
|
|
1605
|
+
choices: groupedChoices(modules.flatMap((x)=>x.implementations.map((implementation)=>{
|
|
1606
|
+
const type = wiring_implementationType(x, implementation);
|
|
1607
|
+
return {
|
|
1608
|
+
module: x,
|
|
1609
|
+
label: type ? `${x.typeName} (${type})` : x.typeName,
|
|
1610
|
+
implementation
|
|
1611
|
+
};
|
|
1612
|
+
}))),
|
|
1613
|
+
pageSize: groupedPageSize,
|
|
1614
|
+
loop: false
|
|
1615
|
+
});
|
|
1616
|
+
if (!await promptDependencies(boundedContextFolder, consumer, [
|
|
1617
|
+
implementation
|
|
1618
|
+
])) console.log('No dependencies available for this module.');
|
|
1619
|
+
};
|
|
1620
|
+
const promptEndpointHandler = async (boundedContextFolder)=>{
|
|
1621
|
+
const handlers = findWiredModules(boundedContextFolder.path).filter((x)=>[
|
|
1622
|
+
'queries',
|
|
1623
|
+
'commands',
|
|
1624
|
+
'use-cases'
|
|
1625
|
+
].includes(x.kind)).map((x)=>({
|
|
1626
|
+
module: x,
|
|
1627
|
+
label: x.typeName
|
|
1628
|
+
}));
|
|
1629
|
+
return handlers.length ? (await (0, prompts_namespaceObject.select)({
|
|
1630
|
+
message: 'Handler:',
|
|
1631
|
+
choices: groupedChoices(handlers),
|
|
1632
|
+
pageSize: groupedPageSize,
|
|
1633
|
+
loop: false
|
|
1634
|
+
})).module : void 0;
|
|
1635
|
+
};
|
|
1636
|
+
const createPresentationService = (boundedContextFolder, name, classFile)=>{
|
|
1637
|
+
const naming = new UnknownFormatNaming(name);
|
|
1638
|
+
const className = `${naming.ClassName}PresentationService`;
|
|
1639
|
+
const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
|
|
1640
|
+
const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
1641
|
+
const wiringFolder = boundedContextFolder.subitem([
|
|
1642
|
+
'wiring',
|
|
1643
|
+
'presentation-services'
|
|
1644
|
+
]);
|
|
1645
|
+
const presentationServicesFolder = boundedContextFolder.subitem([
|
|
1646
|
+
'presentation',
|
|
1647
|
+
'services'
|
|
1648
|
+
]);
|
|
1649
|
+
presentationServicesFolder.createFile(`${naming.fileName}-presentation-service.ts`, classFile?.(className) ?? `
|
|
1650
|
+
export class ${className} {
|
|
1651
|
+
|
|
1652
|
+
}
|
|
1653
|
+
`.trim());
|
|
1654
|
+
if (scaffoldUnitTests) presentationServicesFolder.createFile(`${naming.fileName}-presentation-service.spec.ts`, `
|
|
1655
|
+
import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
|
|
1656
|
+
${withWiring ? `import { type ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'
|
|
1657
|
+
import { wire${naming.ClassName}PresentationService } from '../../wiring/presentation-services/wire-${naming.fileName}-presentation-service'` : `import { ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'`}
|
|
1658
|
+
|
|
1659
|
+
let ${naming.variableName}PresentationService: ${naming.ClassName}PresentationService
|
|
1660
|
+
|
|
1661
|
+
beforeEach(() => {
|
|
1662
|
+
${naming.variableName}PresentationService = ${withWiring ? `wire${naming.ClassName}PresentationService()` : `new ${naming.ClassName}PresentationService()`}
|
|
1663
|
+
})
|
|
1664
|
+
|
|
1665
|
+
describe('${naming.withSpaces}', () => {
|
|
1666
|
+
test('can be ${withWiring ? 'wired' : 'created'}', () => {
|
|
1667
|
+
expect(${naming.variableName}PresentationService).toBeDefined()
|
|
1668
|
+
})
|
|
1669
|
+
})
|
|
1670
|
+
`.trim());
|
|
1671
|
+
if (withWiring) return wiringFolder.createFile(`wire-${naming.fileName}-presentation-service.ts`, `
|
|
1672
|
+
import { wireClass } from '@domain-first/wire'
|
|
1673
|
+
import { ${naming.ClassName}PresentationService } from '../../presentation/services/${naming.fileName}-presentation-service'
|
|
1674
|
+
|
|
1675
|
+
export const wire${naming.ClassName}PresentationService = wireClass(
|
|
1676
|
+
${naming.ClassName}PresentationService,
|
|
1677
|
+
[]
|
|
1678
|
+
)
|
|
1679
|
+
`.trim());
|
|
1680
|
+
};
|
|
1681
|
+
const scaffoldNewPresentationService = async (boundedContextFolder)=>{
|
|
1682
|
+
const name = await (0, prompts_namespaceObject.input)({
|
|
1683
|
+
message: 'Name: '
|
|
1684
|
+
});
|
|
1685
|
+
const wireFile = createPresentationService(boundedContextFolder, name);
|
|
1686
|
+
if (wireFile) await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
1687
|
+
};
|
|
1688
|
+
const rest_endpoint_generator_name = 'rest-endpoint-generator';
|
|
1689
|
+
const scaffoldRestEndpointGenerator = (sharedFolder, { withNextAdapter = false } = {})=>createPresentationService(sharedFolder, rest_endpoint_generator_name, (className)=>{
|
|
1690
|
+
const adapter = withNextAdapter ? 'nextAdapter' : 'adapter';
|
|
1691
|
+
return `
|
|
1692
|
+
import {
|
|
1693
|
+
${withNextAdapter ? '' : ' type Adapter,\n'} type EndpointGenerator,
|
|
1694
|
+
type ErrorStatuses,
|
|
1695
|
+
createEndpoint,
|
|
1696
|
+
InputMappingError,
|
|
1697
|
+
RequestParsingError
|
|
1698
|
+
} from '@domain-first/handlers-rest'
|
|
1699
|
+
${withNextAdapter ? "import { nextAdapter } from '@domain-first/handlers-next'" : `
|
|
1700
|
+
/**
|
|
1701
|
+
* The adapter of your HTTP framework.
|
|
1702
|
+
*/
|
|
1703
|
+
const adapter = undefined as unknown as Adapter<any[], any>`}
|
|
1704
|
+
|
|
1705
|
+
export class ${className} {
|
|
1706
|
+
/**
|
|
1707
|
+
* Default errors of a client request, to spread into a generator's
|
|
1708
|
+
* own checks.
|
|
1709
|
+
*/
|
|
1710
|
+
private get defaultClientRequestErrors(): ErrorStatuses[number]['checks'] {
|
|
1711
|
+
return [RequestParsingError.is, InputMappingError.is]
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
get withoutGuards(): EndpointGenerator {
|
|
1715
|
+
return createEndpoint({
|
|
1716
|
+
errorStatuses: {
|
|
1717
|
+
400: {
|
|
1718
|
+
checks: this.defaultClientRequestErrors,
|
|
1719
|
+
description: 'Invalid request'
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
})(${adapter}) as EndpointGenerator
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
`.trim();
|
|
1726
|
+
});
|
|
1727
|
+
const findRestEndpointGenerator = (sharedFolder)=>{
|
|
1728
|
+
const typeFile = external_node_path_default().join(sharedFolder.path, 'presentation', 'services', `${rest_endpoint_generator_name}-presentation-service.ts`);
|
|
1729
|
+
if (!new File(typeFile).exists) return;
|
|
1730
|
+
return {
|
|
1731
|
+
typeName: 'RestEndpointGeneratorPresentationService',
|
|
1732
|
+
typeFile,
|
|
1733
|
+
wireName: 'wireRestEndpointGeneratorPresentationService',
|
|
1734
|
+
wireFile: external_node_path_default().join(sharedFolder.path, 'wiring', 'presentation-services', `wire-${rest_endpoint_generator_name}-presentation-service.ts`)
|
|
1735
|
+
};
|
|
1736
|
+
};
|
|
1737
|
+
const hasDependency = (root, name)=>{
|
|
1738
|
+
const manifestFile = new File(external_node_path_default().join(root, 'package.json'));
|
|
1739
|
+
if (!manifestFile.exists) return false;
|
|
1740
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
1741
|
+
return [
|
|
1742
|
+
manifest.dependencies,
|
|
1743
|
+
manifest.devDependencies,
|
|
1744
|
+
manifest.optionalDependencies
|
|
1745
|
+
].some((dependencies)=>dependencies && Object.hasOwn(dependencies, name));
|
|
1746
|
+
};
|
|
1747
|
+
const initializeUseCase = async ()=>{
|
|
1748
|
+
const nextSteps = [];
|
|
1749
|
+
const rootFolderName = await (0, prompts_namespaceObject.input)({
|
|
1750
|
+
message: 'Root folder (use "/" for inner folders):',
|
|
1751
|
+
default: 'src'
|
|
1752
|
+
});
|
|
1753
|
+
const domainFirstPackages = await (0, prompts_namespaceObject.checkbox)({
|
|
1754
|
+
message: '@domain-first packages',
|
|
1755
|
+
choices: [
|
|
1756
|
+
'@domain-first/types',
|
|
1757
|
+
'@domain-first/errors',
|
|
1758
|
+
'@domain-first/handlers',
|
|
1759
|
+
'@domain-first/wire',
|
|
1760
|
+
'@domain-first/handlers-rest'
|
|
1761
|
+
]
|
|
1762
|
+
});
|
|
1763
|
+
const withNextAdapter = domainFirstPackages.includes('@domain-first/handlers-rest') && hasDependency(new ProjectRoot().path, 'next') && await (0, prompts_namespaceObject.confirm)({
|
|
1764
|
+
message: 'Use Next adapter for REST endpoints'
|
|
1765
|
+
});
|
|
1766
|
+
const defaultPersistenceLayerImplementation = await (0, prompts_namespaceObject.input)({
|
|
1767
|
+
message: 'Default persistence layer implementation:'
|
|
1768
|
+
});
|
|
1769
|
+
const useReact = await (0, prompts_namespaceObject.confirm)({
|
|
1770
|
+
message: 'Use React'
|
|
1771
|
+
});
|
|
1772
|
+
let storybookFramework;
|
|
1773
|
+
const withStorybook = useReact ? await (0, prompts_namespaceObject.confirm)({
|
|
1774
|
+
message: 'Use Storybook'
|
|
1775
|
+
}) : false;
|
|
1776
|
+
if (withStorybook) storybookFramework = await (0, prompts_namespaceObject.input)({
|
|
1777
|
+
message: 'Storybook framework package:',
|
|
1778
|
+
default: '@storybook/react-vite'
|
|
1779
|
+
});
|
|
1780
|
+
let testingLibrary;
|
|
1781
|
+
const withTests = await (0, prompts_namespaceObject.confirm)({
|
|
1782
|
+
message: 'Scaffold unit tests'
|
|
1783
|
+
});
|
|
1784
|
+
if (withTests) testingLibrary = await (0, prompts_namespaceObject.input)({
|
|
1785
|
+
message: 'Unit testing library:',
|
|
1786
|
+
default: 'vitest'
|
|
1787
|
+
});
|
|
1788
|
+
ConfigFile.write({
|
|
1789
|
+
rootFolder: rootFolderName,
|
|
1790
|
+
domainFirstPackages,
|
|
1791
|
+
defaultPersistenceLayerImplementation,
|
|
1792
|
+
useReact,
|
|
1793
|
+
storybookFramework,
|
|
1794
|
+
testingLibrary
|
|
1795
|
+
});
|
|
1796
|
+
const { path } = new ProjectRoot();
|
|
1797
|
+
const rootFolder = new Folder(path);
|
|
1798
|
+
if (domainFirstPackages.includes('@domain-first/wire')) rootFolder.subitem([
|
|
1799
|
+
rootFolderName,
|
|
1800
|
+
'shared',
|
|
1801
|
+
'wiring'
|
|
1802
|
+
]).createFile('env-branched-wire.ts', `
|
|
1803
|
+
import { branchedWire } from '@domain-first/wire'
|
|
1804
|
+
|
|
1805
|
+
export const envBranchedWire = branchedWire(() => {
|
|
1806
|
+
return process.env.NODE_ENV ?? 'development' as 'test' | 'development' | 'production'
|
|
1807
|
+
});
|
|
1808
|
+
`.trim());
|
|
1809
|
+
if (domainFirstPackages.includes('@domain-first/errors')) rootFolder.subitem([
|
|
1810
|
+
rootFolderName,
|
|
1811
|
+
'shared'
|
|
1812
|
+
]).subitem([
|
|
1813
|
+
'domain',
|
|
1814
|
+
'errors'
|
|
1815
|
+
]).createFile('index.ts', `
|
|
1816
|
+
import { errorNamespace } from '@domain-first/errors'
|
|
1817
|
+
|
|
1818
|
+
export const SharedErrors = errorNamespace('shared')
|
|
1819
|
+
`.trim());
|
|
1820
|
+
if (domainFirstPackages.includes('@domain-first/handlers-rest')) {
|
|
1821
|
+
scaffoldRestEndpointGenerator(rootFolder.subitem([
|
|
1822
|
+
rootFolderName,
|
|
1823
|
+
'shared'
|
|
1824
|
+
]), {
|
|
1825
|
+
withNextAdapter
|
|
1826
|
+
});
|
|
1827
|
+
if (withNextAdapter && !hasDependency(path, '@domain-first/handlers-next')) nextSteps.push('npm i @domain-first/handlers-next');
|
|
1828
|
+
}
|
|
1829
|
+
return nextSteps;
|
|
1830
|
+
};
|
|
1831
|
+
const splitSegments = (rawSource)=>rawSource.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
1832
|
+
class NestedName {
|
|
1833
|
+
folders;
|
|
1834
|
+
folderName;
|
|
1835
|
+
fileName;
|
|
1836
|
+
ClassName;
|
|
1837
|
+
classNameSegments;
|
|
1838
|
+
constructor(rawSource){
|
|
1839
|
+
const segments = splitSegments(rawSource);
|
|
1840
|
+
this.folders = segments.slice(0, -1);
|
|
1841
|
+
this.folderName = new UnknownFormatNaming(segments.at(-1) ?? '').fileName;
|
|
1842
|
+
this.fileName = segments.map((segment)=>new UnknownFormatNaming(segment).fileName).join('-');
|
|
1843
|
+
this.classNameSegments = segments.map((segment)=>new UnknownFormatNaming(segment).ClassName);
|
|
1844
|
+
this.ClassName = this.classNameSegments.join('');
|
|
1845
|
+
}
|
|
1846
|
+
static validate = (rawSource)=>{
|
|
1847
|
+
const segments = splitSegments(rawSource);
|
|
1848
|
+
if (!segments.length) return 'Name is required';
|
|
1849
|
+
if (segments.some((segment)=>'.' === segment || '..' === segment)) return 'Use a path relative to the folder, without "." or ".."';
|
|
1850
|
+
return true;
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1853
|
+
const ignoredFolders = new Set([
|
|
1854
|
+
'node_modules',
|
|
1855
|
+
'.git',
|
|
1856
|
+
'.next',
|
|
1857
|
+
'dist',
|
|
1858
|
+
'build',
|
|
1859
|
+
'out',
|
|
1860
|
+
'coverage',
|
|
1861
|
+
'storybook-static'
|
|
1862
|
+
]);
|
|
1863
|
+
const codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx)$/;
|
|
1864
|
+
const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1865
|
+
const react_module_move_walk = (folder)=>{
|
|
1866
|
+
if (!external_node_fs_default().existsSync(folder)) return [];
|
|
1867
|
+
return external_node_fs_default().readdirSync(folder, {
|
|
1868
|
+
withFileTypes: true
|
|
1869
|
+
}).flatMap((entry)=>{
|
|
1870
|
+
const entryPath = external_node_path_default().join(folder, entry.name);
|
|
1871
|
+
if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : react_module_move_walk(entryPath);
|
|
1872
|
+
return entry.isFile() ? [
|
|
1873
|
+
entryPath
|
|
1874
|
+
] : [];
|
|
1875
|
+
});
|
|
1876
|
+
};
|
|
1877
|
+
const toPosix = (value)=>value.split(external_node_path_default().sep).join('/');
|
|
1878
|
+
const nestedName = (folders, fileBase)=>{
|
|
1879
|
+
const prefix = `${folders.join('-')}-`;
|
|
1880
|
+
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
1881
|
+
return [
|
|
1882
|
+
...folders,
|
|
1883
|
+
last
|
|
1884
|
+
].join('/');
|
|
1885
|
+
};
|
|
1886
|
+
const declaredClassName = (filePath, suffix, name)=>{
|
|
1887
|
+
const content = external_node_fs_default().readFileSync(filePath, 'utf8');
|
|
1888
|
+
const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
1889
|
+
return declared ?? new NestedName(name).ClassName;
|
|
1890
|
+
};
|
|
1891
|
+
const findReactModules = (reactFolder, kind)=>{
|
|
1892
|
+
const modules = 'page' === kind ? react_module_move_walk(external_node_path_default().join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
1893
|
+
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);
|
|
1894
|
+
const fileBase = external_node_path_default().basename(file, '-page.tsx');
|
|
1895
|
+
const name = nestedName(folders, fileBase);
|
|
1896
|
+
return {
|
|
1897
|
+
kind,
|
|
1898
|
+
name,
|
|
1899
|
+
path: file,
|
|
1900
|
+
fileBase,
|
|
1901
|
+
ClassName: declaredClassName(file, 'Page', name)
|
|
1902
|
+
};
|
|
1903
|
+
}) : react_module_move_walk(external_node_path_default().join(reactFolder, 'widgets')).filter((file)=>file.endsWith('-widget.tsx')).map((file)=>{
|
|
1904
|
+
const folder = external_node_path_default().dirname(file);
|
|
1905
|
+
const name = toPosix(external_node_path_default().relative(external_node_path_default().join(reactFolder, 'widgets'), folder));
|
|
1906
|
+
return {
|
|
1907
|
+
kind,
|
|
1908
|
+
name,
|
|
1909
|
+
path: folder,
|
|
1910
|
+
fileBase: external_node_path_default().basename(file, '-widget.tsx'),
|
|
1911
|
+
ClassName: declaredClassName(file, 'Widget', name)
|
|
1912
|
+
};
|
|
1913
|
+
});
|
|
1914
|
+
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
1915
|
+
};
|
|
1916
|
+
const react_module_move_targetPath = (reactFolder, module, rawName)=>{
|
|
1917
|
+
const { folders, folderName, fileName } = new NestedName(rawName);
|
|
1918
|
+
return 'page' === module.kind ? external_node_path_default().join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`) : external_node_path_default().join(reactFolder, 'widgets', ...folders, folderName);
|
|
1919
|
+
};
|
|
1920
|
+
const validateMove = (reactFolder, module, rawName)=>{
|
|
1921
|
+
const nameError = NestedName.validate(rawName);
|
|
1922
|
+
if (true !== nameError) return nameError;
|
|
1923
|
+
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
1924
|
+
if (target !== module.path && external_node_fs_default().existsSync(target)) return `${external_node_path_default().relative(reactFolder, target)} already exists`;
|
|
1925
|
+
if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
|
|
1926
|
+
return true;
|
|
1927
|
+
};
|
|
1928
|
+
const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
|
|
1929
|
+
const readAliases = (projectRoot)=>{
|
|
1930
|
+
const tsconfig = external_node_path_default().join(projectRoot, 'tsconfig.json');
|
|
1931
|
+
if (!external_node_fs_default().existsSync(tsconfig)) return [];
|
|
1932
|
+
try {
|
|
1933
|
+
const { compilerOptions = {} } = JSON.parse(stripJsonComments(external_node_fs_default().readFileSync(tsconfig, 'utf8')));
|
|
1934
|
+
const base = external_node_path_default().resolve(projectRoot, compilerOptions.baseUrl ?? '.');
|
|
1935
|
+
return Object.entries(compilerOptions.paths ?? {}).filter(([pattern, targets])=>pattern.endsWith('*') && targets[0]?.endsWith('*')).map(([pattern, [target]])=>({
|
|
1936
|
+
prefix: pattern.slice(0, -1),
|
|
1937
|
+
target: external_node_path_default().resolve(base, target.slice(0, -1))
|
|
1938
|
+
}));
|
|
1939
|
+
} catch {
|
|
1940
|
+
return [];
|
|
1941
|
+
}
|
|
1942
|
+
};
|
|
1943
|
+
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
|
|
1944
|
+
const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
|
|
1945
|
+
const importPaths = (file)=>{
|
|
1946
|
+
const withoutExtension = file.replace(codeExtension, '');
|
|
1947
|
+
return 'index' === external_node_path_default().basename(withoutExtension) ? [
|
|
1948
|
+
withoutExtension,
|
|
1949
|
+
external_node_path_default().dirname(withoutExtension)
|
|
1950
|
+
] : [
|
|
1951
|
+
withoutExtension
|
|
1952
|
+
];
|
|
1953
|
+
};
|
|
1954
|
+
const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
1955
|
+
const newName = new NestedName(rawName);
|
|
1956
|
+
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
1957
|
+
const newClassName = newName.ClassName;
|
|
1958
|
+
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.])`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
1959
|
+
const oldFolder = 'page' === module.kind ? external_node_path_default().dirname(module.path) : module.path;
|
|
1960
|
+
const newFolder = 'page' === module.kind ? external_node_path_default().dirname(target) : target;
|
|
1961
|
+
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}`);
|
|
1962
|
+
const movedPath = (candidate)=>{
|
|
1963
|
+
if (!ownsPath(candidate)) return;
|
|
1964
|
+
const segments = external_node_path_default().relative(oldFolder, candidate).split(external_node_path_default().sep);
|
|
1965
|
+
const last = segments.length - 1;
|
|
1966
|
+
segments[last] = renameFile(segments[last]);
|
|
1967
|
+
return external_node_path_default().join(newFolder, ...segments);
|
|
1968
|
+
};
|
|
1969
|
+
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);
|
|
1970
|
+
const moves = new Map(moduleFiles.map((file)=>[
|
|
1971
|
+
file,
|
|
1972
|
+
movedPath(file) ?? file
|
|
1973
|
+
]));
|
|
1974
|
+
const aliases = readAliases(projectRoot);
|
|
1975
|
+
const resolve = (specifier, fromFile)=>{
|
|
1976
|
+
if (specifier.startsWith('.')) return {
|
|
1977
|
+
resolved: external_node_path_default().resolve(external_node_path_default().dirname(fromFile), specifier),
|
|
1978
|
+
alias: void 0
|
|
1979
|
+
};
|
|
1980
|
+
const alias = aliases.find(({ prefix })=>specifier.startsWith(prefix));
|
|
1981
|
+
return alias ? {
|
|
1982
|
+
resolved: external_node_path_default().resolve(alias.target, specifier.slice(alias.prefix.length)),
|
|
1983
|
+
alias
|
|
1984
|
+
} : void 0;
|
|
1985
|
+
};
|
|
1986
|
+
const specifierFor = (fromFile, toPath, alias)=>{
|
|
1987
|
+
const aliased = alias && toPosix(external_node_path_default().relative(alias.target, toPath));
|
|
1988
|
+
if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
|
|
1989
|
+
const relative = toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toPath));
|
|
1990
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
1991
|
+
};
|
|
1992
|
+
const suffixes = 'page' === module.kind ? 'Page' : 'Widget|UIModel';
|
|
1993
|
+
const classPattern = new RegExp(`(?<![\\w$])(use)?${escapeRegExp(module.ClassName)}(?=${suffixes})`, 'g');
|
|
1994
|
+
const oldTitle = `Widgets/${module.name.split('/').map((segment)=>new NestedName(segment).ClassName).join('/')}`;
|
|
1995
|
+
const titlePattern = new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
1996
|
+
const newTitle = [
|
|
1997
|
+
'Widgets',
|
|
1998
|
+
...newName.classNameSegments
|
|
1999
|
+
].join('/');
|
|
2000
|
+
const codeFiles = new Map(react_module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
2001
|
+
file,
|
|
2002
|
+
external_node_fs_default().readFileSync(file, 'utf8')
|
|
2003
|
+
]));
|
|
2004
|
+
const barrels = new Set();
|
|
2005
|
+
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
2006
|
+
for(let found = true; found;){
|
|
2007
|
+
found = false;
|
|
2008
|
+
for (const [file, content] of codeFiles){
|
|
2009
|
+
if (moves.has(file) || isBarrel(file)) continue;
|
|
2010
|
+
const reExportsModule = [
|
|
2011
|
+
...content.matchAll(reExportPattern)
|
|
2012
|
+
].some(([, , specifier])=>{
|
|
2013
|
+
const resolution = resolve(specifier, file);
|
|
2014
|
+
return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
|
|
2015
|
+
});
|
|
2016
|
+
if (reExportsModule) {
|
|
2017
|
+
for (const importPath of importPaths(file))barrels.add(importPath);
|
|
2018
|
+
found = true;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
const rewrite = (content, oldFile, newFile)=>{
|
|
2023
|
+
let referencesModule = false;
|
|
2024
|
+
const rewritten = content.replace(specifierPattern, (match, keyword, quote, specifier)=>{
|
|
2025
|
+
const resolution = resolve(specifier, oldFile);
|
|
2026
|
+
if (!resolution) return match;
|
|
2027
|
+
const moved = movedPath(resolution.resolved);
|
|
2028
|
+
if (moved || isBarrel(resolution.resolved)) referencesModule = true;
|
|
2029
|
+
if (!moved && oldFile === newFile) return match;
|
|
2030
|
+
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
2031
|
+
return `${keyword}${quote}${next}${quote}`;
|
|
1924
2032
|
});
|
|
1925
|
-
if (
|
|
2033
|
+
if (!referencesModule && !moves.has(oldFile)) return content;
|
|
2034
|
+
const renamed = rewritten.replace(classPattern, (_, use = '')=>`${use}${newClassName}`);
|
|
2035
|
+
return moves.has(oldFile) && 'widget' === module.kind ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
2036
|
+
};
|
|
2037
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile, reactFolder);
|
|
2038
|
+
const updated = [];
|
|
2039
|
+
for (const [file, content] of codeFiles){
|
|
2040
|
+
const newFile = moves.get(file);
|
|
2041
|
+
const next = rewrite(content, file, newFile ?? file);
|
|
2042
|
+
if (newFile && newFile !== file) {
|
|
2043
|
+
new File(newFile).data = next;
|
|
2044
|
+
new File(file).delete(reactFolder);
|
|
2045
|
+
} else if (next !== content) {
|
|
2046
|
+
new File(file).update(next);
|
|
2047
|
+
if (!newFile) updated.push(file);
|
|
2048
|
+
}
|
|
1926
2049
|
}
|
|
1927
|
-
return asked;
|
|
1928
|
-
};
|
|
1929
|
-
const wireNewModuleDependencies = async (boundedContextFolder, wireFile)=>{
|
|
1930
|
-
const consumer = readWiredModule(wireFile.path, boundedContextFolder.path);
|
|
1931
|
-
if (consumer) await promptDependencies(boundedContextFolder, consumer);
|
|
1932
|
-
};
|
|
1933
|
-
const wireDependency = async (boundedContextFolder)=>{
|
|
1934
|
-
const modules = findWiredModules(boundedContextFolder.path);
|
|
1935
|
-
if (!modules.length) return void console.log('No wired modules here yet.');
|
|
1936
|
-
const { module: consumer, implementation } = await (0, prompts_namespaceObject.select)({
|
|
1937
|
-
message: 'Module:',
|
|
1938
|
-
choices: groupedChoices(modules.flatMap((x)=>x.implementations.map((implementation)=>{
|
|
1939
|
-
const type = wiring_implementationType(x, implementation);
|
|
1940
|
-
return {
|
|
1941
|
-
module: x,
|
|
1942
|
-
label: type ? `${x.typeName} (${type})` : x.typeName,
|
|
1943
|
-
implementation
|
|
1944
|
-
};
|
|
1945
|
-
}))),
|
|
1946
|
-
pageSize: groupedPageSize,
|
|
1947
|
-
loop: false
|
|
1948
|
-
});
|
|
1949
|
-
if (!await promptDependencies(boundedContextFolder, consumer, [
|
|
1950
|
-
implementation
|
|
1951
|
-
])) console.log('No dependencies available for this module.');
|
|
1952
|
-
};
|
|
1953
|
-
const promptEndpointDependencies = async (boundedContextFolder)=>{
|
|
1954
|
-
const options = contextAndSharedModules(boundedContextFolder);
|
|
1955
|
-
const generators = options.filter((x)=>'presentation-services' === x.module.kind);
|
|
1956
|
-
const handlers = findWiredModules(boundedContextFolder.path).filter((x)=>[
|
|
1957
|
-
'queries',
|
|
1958
|
-
'commands',
|
|
1959
|
-
'use-cases'
|
|
1960
|
-
].includes(x.kind)).map((x)=>({
|
|
1961
|
-
module: x,
|
|
1962
|
-
label: x.typeName
|
|
1963
|
-
}));
|
|
1964
|
-
const endpointGenerator = generators.length ? (await (0, prompts_namespaceObject.select)({
|
|
1965
|
-
message: 'Endpoint generator:',
|
|
1966
|
-
choices: groupedChoices(generators, generators.filter((x)=>isSuggestedEndpointGenerator(x.module))),
|
|
1967
|
-
pageSize: groupedPageSize,
|
|
1968
|
-
loop: false
|
|
1969
|
-
})).module : void 0;
|
|
1970
|
-
const handler = handlers.length ? (await (0, prompts_namespaceObject.select)({
|
|
1971
|
-
message: 'Handler:',
|
|
1972
|
-
choices: groupedChoices(handlers),
|
|
1973
|
-
pageSize: groupedPageSize,
|
|
1974
|
-
loop: false
|
|
1975
|
-
})).module : void 0;
|
|
1976
2050
|
return {
|
|
1977
|
-
|
|
1978
|
-
|
|
2051
|
+
moves: [
|
|
2052
|
+
...moves
|
|
2053
|
+
].filter(([from, to])=>from !== to),
|
|
2054
|
+
updated
|
|
1979
2055
|
};
|
|
1980
2056
|
};
|
|
2057
|
+
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
2058
|
+
const reactFolder = presentationReactFolder.path;
|
|
2059
|
+
const modules = findReactModules(reactFolder, kind);
|
|
2060
|
+
if (!modules.length) return void console.log(`No ${kind}s generated by df-ps were found.`);
|
|
2061
|
+
const module = await (0, prompts_namespaceObject.select)({
|
|
2062
|
+
message: 'page' === kind ? 'Page:' : 'Widget:',
|
|
2063
|
+
choices: modules.map((value)=>({
|
|
2064
|
+
name: value.name,
|
|
2065
|
+
value,
|
|
2066
|
+
description: external_node_path_default().relative(reactFolder, value.path)
|
|
2067
|
+
}))
|
|
2068
|
+
});
|
|
2069
|
+
const name = await (0, prompts_namespaceObject.input)({
|
|
2070
|
+
message: 'New name (folders split by "/"):',
|
|
2071
|
+
default: module.name,
|
|
2072
|
+
validate: (value)=>validateMove(reactFolder, module, value)
|
|
2073
|
+
});
|
|
2074
|
+
const root = new ProjectRoot().path;
|
|
2075
|
+
const { moves, updated } = moveReactModule(root, reactFolder, module, name);
|
|
2076
|
+
if (!moves.length && !updated.length) return void console.log('Nothing to change.');
|
|
2077
|
+
const relative = (file)=>external_node_path_default().relative(root, file);
|
|
2078
|
+
console.log([
|
|
2079
|
+
'Files to move:',
|
|
2080
|
+
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
|
2081
|
+
...updated.length ? [
|
|
2082
|
+
'Files with updated imports:',
|
|
2083
|
+
...updated.map((file)=>` ${relative(file)}`)
|
|
2084
|
+
] : []
|
|
2085
|
+
].join('\n'));
|
|
2086
|
+
if (!await (0, prompts_namespaceObject.confirm)({
|
|
2087
|
+
message: 'Apply?',
|
|
2088
|
+
default: true
|
|
2089
|
+
})) {
|
|
2090
|
+
discardPendingChanges();
|
|
2091
|
+
console.log('Cancelled: nothing was written.');
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
1981
2094
|
const scaffoldNewAggregateUseCase = async (boundedContextFolder)=>{
|
|
1982
2095
|
const aggregateName = await (0, prompts_namespaceObject.input)({
|
|
1983
2096
|
message: 'Aggregate name:'
|
|
@@ -2674,10 +2787,12 @@ export const restHandlers = restWires.map(x => x().handle)
|
|
|
2674
2787
|
'endpoint'
|
|
2675
2788
|
].map((segment)=>segment.startsWith(':') ? pathParameterAsName(segment) : new UnknownFormatNaming(segment).ClassName).join('');
|
|
2676
2789
|
const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2677
|
-
const
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2790
|
+
const endpointGenerator = findRestEndpointGenerator(boundedContextFolder.subitem([
|
|
2791
|
+
'..',
|
|
2792
|
+
'..',
|
|
2793
|
+
'shared'
|
|
2794
|
+
]));
|
|
2795
|
+
const handler = withWiring ? await promptEndpointHandler(boundedContextFolder) : void 0;
|
|
2681
2796
|
const endpointFile = external_node_path_default().join(endpointFolder.path, `${method.toUpperCase()}.ts`);
|
|
2682
2797
|
endpointFolder.createFile(`${method.toUpperCase()}.ts`, `
|
|
2683
2798
|
${endpointGenerator ? `import type { ${endpointGenerator.typeName} } from '${relativeImport(endpointFile, endpointGenerator.typeFile)}'` : "import { EndpointGenerator } from '@domain-first/handlers-rest'"}${handler ? `
|
|
@@ -2774,56 +2889,6 @@ export const wire${naming.ClassName}InfrastructureService = wireClass(
|
|
|
2774
2889
|
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
2775
2890
|
}
|
|
2776
2891
|
};
|
|
2777
|
-
const scaffoldNewPresentationService = async (boundedContextFolder)=>{
|
|
2778
|
-
const name = await (0, prompts_namespaceObject.input)({
|
|
2779
|
-
message: 'Name: '
|
|
2780
|
-
});
|
|
2781
|
-
const naming = new UnknownFormatNaming(name);
|
|
2782
|
-
const scaffoldUnitTests = Boolean(ConfigFile.Instance.data.testingLibrary);
|
|
2783
|
-
const withWiring = ConfigFile.Instance.data.domainFirstPackages.includes('@domain-first/wire');
|
|
2784
|
-
const wiringFolder = boundedContextFolder.subitem([
|
|
2785
|
-
'wiring',
|
|
2786
|
-
'presentation-services'
|
|
2787
|
-
]);
|
|
2788
|
-
const presentationServicesFolder = boundedContextFolder.subitem([
|
|
2789
|
-
'presentation',
|
|
2790
|
-
'services'
|
|
2791
|
-
]);
|
|
2792
|
-
presentationServicesFolder.createFile(`${naming.fileName}-presentation-service.ts`, `
|
|
2793
|
-
export class ${naming.ClassName}PresentationService {
|
|
2794
|
-
|
|
2795
|
-
}
|
|
2796
|
-
`.trim());
|
|
2797
|
-
if (scaffoldUnitTests) presentationServicesFolder.createFile(`${naming.fileName}-presentation-service.spec.ts`, `
|
|
2798
|
-
import { describe, test, expect, beforeEach } from '${ConfigFile.Instance.data.testingLibrary}'
|
|
2799
|
-
${withWiring ? `import { type ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'
|
|
2800
|
-
import { wire${naming.ClassName}PresentationService } from '../../wiring/presentation-services/wire-${naming.fileName}-presentation-service'` : `import { ${naming.ClassName}PresentationService } from './${naming.fileName}-presentation-service'`}
|
|
2801
|
-
|
|
2802
|
-
let ${naming.variableName}PresentationService: ${naming.ClassName}PresentationService
|
|
2803
|
-
|
|
2804
|
-
beforeEach(() => {
|
|
2805
|
-
${naming.variableName}PresentationService = ${withWiring ? `wire${naming.ClassName}PresentationService()` : `new ${naming.ClassName}PresentationService()`}
|
|
2806
|
-
})
|
|
2807
|
-
|
|
2808
|
-
describe('${naming.withSpaces}', () => {
|
|
2809
|
-
test('can be ${withWiring ? 'wired' : 'created'}', () => {
|
|
2810
|
-
expect(${naming.variableName}PresentationService).toBeDefined()
|
|
2811
|
-
})
|
|
2812
|
-
})
|
|
2813
|
-
`.trim());
|
|
2814
|
-
if (withWiring) {
|
|
2815
|
-
const wireFile = wiringFolder.createFile(`wire-${naming.fileName}-presentation-service.ts`, `
|
|
2816
|
-
import { wireClass } from '@domain-first/wire'
|
|
2817
|
-
import { ${naming.ClassName}PresentationService } from '../../presentation/services/${naming.fileName}-presentation-service'
|
|
2818
|
-
|
|
2819
|
-
export const wire${naming.ClassName}PresentationService = wireClass(
|
|
2820
|
-
${naming.ClassName}PresentationService,
|
|
2821
|
-
[]
|
|
2822
|
-
)
|
|
2823
|
-
`.trim());
|
|
2824
|
-
await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
2825
|
-
}
|
|
2826
|
-
};
|
|
2827
2892
|
const scaffoldNewQuery = async (boundedContextFolder)=>{
|
|
2828
2893
|
const queriesFolder = boundedContextFolder.subitem([
|
|
2829
2894
|
'application',
|
|
@@ -3293,7 +3358,11 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
3293
3358
|
}
|
|
3294
3359
|
};
|
|
3295
3360
|
const main = async ()=>{
|
|
3296
|
-
if (!ConfigFile.exists)
|
|
3361
|
+
if (!ConfigFile.exists) {
|
|
3362
|
+
const nextSteps = await initializeUseCase();
|
|
3363
|
+
if (await savePendingChanges()) printNextSteps(nextSteps);
|
|
3364
|
+
return;
|
|
3365
|
+
}
|
|
3297
3366
|
const rootPath = new ProjectRoot().path;
|
|
3298
3367
|
const currentBoundedContextOptions = new Folder(rootPath).subitem([
|
|
3299
3368
|
ConfigFile.Instance.data.rootFolder,
|