@domain-first/project-structure 8.1.1 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -2
- package/dist/201.js +1 -1
- package/dist/287.js +278 -9
- package/dist/38.js +268 -0
- package/dist/561.js +22 -5
- package/dist/agent-cli.d.ts +17 -0
- package/dist/agent-requests.d.ts +34 -0
- package/dist/backend-module-move.d.ts +16 -0
- package/dist/graph.cjs +933 -0
- package/dist/graph.d.ts +2 -0
- package/dist/graph.js +337 -0
- package/dist/index.cjs +300 -12
- package/dist/index.js +4 -2
- package/dist/init.cjs +111 -57
- package/dist/integration.cjs +297 -11
- package/dist/interaction.d.ts +9 -0
- package/dist/interaction.spec.d.ts +1 -0
- package/dist/lint.js +8 -273
- package/dist/project-graph.d.ts +53 -0
- package/dist/project-graph.spec.d.ts +1 -0
- package/dist/project-lint.d.ts +10 -0
- package/dist/react-module-move.d.ts +21 -0
- package/dist/react.cjs +304 -12
- package/dist/react.js +8 -2
- package/dist/use-cases/delete-backend-unit.d.ts +6 -0
- package/dist/use-cases/delete-react-module.d.ts +8 -0
- package/dist/use-cases/index.d.ts +2 -0
- package/package.json +3 -2
- package/skills/df-ps-plan-feature/SKILL.md +2 -0
- package/skills/df-ps-react/SKILL.md +5 -3
- package/skills/df-ps-react/references/generators.md +4 -0
- package/skills/df-ps-scaffold/SKILL.md +5 -4
- package/skills/df-ps-scaffold/references/agent-mode.md +1 -0
- package/skills/df-ps-scaffold/references/agent-operations.md +3 -0
- package/skills/df-ps-scaffold/references/units/delete.md +19 -0
- package/skills/df-ps-scaffold/scripts/drive.mjs +5 -0
package/README.md
CHANGED
|
@@ -194,7 +194,7 @@ export const wirePlaceOrderUseCase = wireClass(PlaceOrderUseCase, [
|
|
|
194
194
|
]);
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
-
Only the dependencies that respect the layers are offered: a use case can't take another use case, the domain can't take the application. To add a dependency later, choose **Wire dependency** in the context menu.
|
|
197
|
+
Only the dependencies that respect the layers are offered: a use case can't take another use case, the domain can't take the application. To add a dependency later, choose **Wire dependency** in the context menu. Menus with more than ten choices, such as the module list, take a search: type part of a name to filter.
|
|
198
198
|
|
|
199
199
|
### How to add an implementation
|
|
200
200
|
|
|
@@ -204,6 +204,10 @@ Choose **Infrastructure → New Implementation** to give an existing repository,
|
|
|
204
204
|
|
|
205
205
|
Choose **Move or rename** in the context menu: rename an aggregate, entity, value object, service, port, query, command or use case, move it to another bounded context or to the Shared Kernel, or move an entity in or out of an aggregate. Its files, implementations, wire, specs and every import and derived name in the project follow it: `OrderRepository`, `PrismaOrderRepository`, `wireOrderRepository`, the `orderRepository` parameter of a use case, the in-memory DB section. A move that would introduce a forbidden import between contexts is refused, with the list of imports that would cross the boundary.
|
|
206
206
|
|
|
207
|
+
### How to delete a module
|
|
208
|
+
|
|
209
|
+
Choose **Delete** in the context menu and pick the module. All its files go: the contract, implementations, wire and specs, an aggregate with its whole folder, plus the lines generators added for it elsewhere (an entity's re-export in its aggregate, an aggregate's in-memory DB section). While another file still imports it, nothing is deleted and the CLI lists those imports, so nothing is left broken.
|
|
210
|
+
|
|
207
211
|
### How to add errors
|
|
208
212
|
|
|
209
213
|
Choose **Domain → Errors** to add an error to the context namespace, create a nested namespace, or add an error to it. The context namespace (`SalesErrors = errorNamespace('sales')` in `domain/errors/index.ts`) is created with the first error added without a namespace.
|
|
@@ -265,7 +269,7 @@ admin/panel/users → pages/admin/panel/admin-panel-users-page.tsx (AdminPane
|
|
|
265
269
|
|
|
266
270
|
With Next.js, a new page also gets its App Router route, `app/admin/panel/users/page.tsx`, which renders `AdminPanelUsersPage`. An existing route is never overwritten.
|
|
267
271
|
|
|
268
|
-
**Move or rename page** and **Move or rename widget** move the files and update every import in the project. With Next.js, moving a page also offers to move its route, `app/admin/users/` → `app/backoffice/users/`, since its URL changes with it.
|
|
272
|
+
**Move or rename page** and **Move or rename widget** move the files and update every import in the project. **Delete page** and **Delete widget** remove them once nothing imports them, a Next.js page's own route included if you say so. With Next.js, moving a page also offers to move its route, `app/admin/users/` → `app/backoffice/users/`, since its URL changes with it.
|
|
269
273
|
|
|
270
274
|
### How to add tooling
|
|
271
275
|
|
|
@@ -308,6 +312,17 @@ Defaults and details: [Dependency rules](API.md#dependency-rules), [`df-lint`](A
|
|
|
308
312
|
}
|
|
309
313
|
```
|
|
310
314
|
|
|
315
|
+
### How to see the structure
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
npx df-graph # bounded contexts and the Shared Kernel
|
|
319
|
+
npx df-graph --context sales # the modules of one context by layer
|
|
320
|
+
npx df-graph --html # open the rendered charts in the browser
|
|
321
|
+
npx df-graph --out docs/ARCHITECTURE.md
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
`df-graph` reads the wiring and draws Mermaid charts: which contexts reach each other through cross-context ports, which use the Shared Kernel, and inside a context, what each module depends on. It prints the chart, opens a rendered page with `--html` (Mermaid comes from a CDN), or writes `--out` in the format of the extension: `.md` for GitHub, which renders the chart, `.mmd`, `.json` or `.html`. `--json` gives the same graph to tools and agents.
|
|
325
|
+
|
|
311
326
|
### How to upgrade to a new major version
|
|
312
327
|
|
|
313
328
|
After upgrading the package to a new major version, run:
|
package/dist/201.js
CHANGED
|
@@ -499,4 +499,4 @@ const compilerOption = (configFile, name, seen = new Set())=>{
|
|
|
499
499
|
if (void 0 !== value) return value;
|
|
500
500
|
}
|
|
501
501
|
};
|
|
502
|
-
export { UnknownFormatNaming, addBranchedImplementation, addClassMember, addConstructorParameters, addImport, addWireDependencies, availableDependencies, boundedContextLocation, canDependOn, compilerOption, crossContextImplementation, crossContextImportAllowed, findWiredModules, hasNeighboringBoundedContext, implementationType, isCrossContextImplementation, isSuggestedFor, moduleKindOf, namedImportFiles, readWiredModule, relativeImport, stripJsonComments, wireBranches, wireDependencies, wiredDependencyNames };
|
|
502
|
+
export { UnknownFormatNaming, addBranchedImplementation, addClassMember, addConstructorParameters, addImport, addWireDependencies, availableDependencies, boundedContextLocation, canDependOn, compilerOption, crossContextImplementation, crossContextImportAllowed, findWiredModules, hasNeighboringBoundedContext, implementationType, isCrossContextImplementation, isSuggestedFor, moduleKindOf, namedImportFiles, readWiredModule, relativeImport, stripJsonComments, wireBranches, wireDependencies, wiredDependencyNames, wiring_layers };
|
package/dist/287.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
-
import { Separator, checkbox as prompts_checkbox, confirm as prompts_confirm, input, select as prompts_select } from "@inquirer/prompts";
|
|
3
|
+
import { Separator, checkbox as prompts_checkbox, confirm as prompts_confirm, input, search, select as prompts_select } from "@inquirer/prompts";
|
|
4
4
|
import { styleText } from "node:util";
|
|
5
5
|
import node_fs from "node:fs";
|
|
6
6
|
import { addImport, availableDependencies, compilerOption, findWiredModules, UnknownFormatNaming, readWiredModule, stripJsonComments, addClassMember, hasNeighboringBoundedContext, addBranchedImplementation, addWireDependencies, boundedContextLocation, addConstructorParameters, relativeImport, wireBranches, wireDependencies, implementationType as wiring_implementationType, crossContextImportAllowed, crossContextImplementation, isSuggestedFor } from "./201.js";
|
|
@@ -246,6 +246,7 @@ const addInMemoryDb = ()=>{
|
|
|
246
246
|
return [];
|
|
247
247
|
};
|
|
248
248
|
const inMemoryDbApplied = ()=>Boolean(ConfigFile.Instance.data.backend?.withInMemoryDb) && inMemoryDbScaffolded();
|
|
249
|
+
const isSeparator = (choice)=>'function' == typeof Separator && choice instanceof Separator || 'object' == typeof choice && null !== choice && 'separator' === choice.type;
|
|
249
250
|
class RequestError extends Error {
|
|
250
251
|
code;
|
|
251
252
|
details;
|
|
@@ -321,7 +322,7 @@ const interaction_confirm = async (config)=>{
|
|
|
321
322
|
});
|
|
322
323
|
return value;
|
|
323
324
|
};
|
|
324
|
-
const choicesOf = (config)=>config.choices.filter((choice)=>!(choice
|
|
325
|
+
const choicesOf = (config)=>config.choices.filter((choice)=>!isSeparator(choice)).map((choice)=>'object' == typeof choice && null !== choice && 'value' in choice ? choice : {
|
|
325
326
|
value: choice
|
|
326
327
|
});
|
|
327
328
|
const choiceId = (choice, id)=>id?.(choice.value) ?? choice.value;
|
|
@@ -334,9 +335,62 @@ const resolveChoice = (value, choices, key, id)=>{
|
|
|
334
335
|
});
|
|
335
336
|
return matches[0].value;
|
|
336
337
|
};
|
|
338
|
+
const searchThreshold = 10;
|
|
339
|
+
const choiceLabel = (choice)=>choice.name ?? String(choice.value);
|
|
340
|
+
const filterChoices = (choices, term)=>{
|
|
341
|
+
const text = (term ?? '').trim().toLowerCase();
|
|
342
|
+
const words = text.split(/\s+/).filter(Boolean);
|
|
343
|
+
if (!words.length) return [
|
|
344
|
+
...choices
|
|
345
|
+
];
|
|
346
|
+
const groups = [
|
|
347
|
+
{
|
|
348
|
+
matches: []
|
|
349
|
+
}
|
|
350
|
+
];
|
|
351
|
+
for (const choice of choices){
|
|
352
|
+
if (isSeparator(choice)) {
|
|
353
|
+
groups.push({
|
|
354
|
+
separator: choice,
|
|
355
|
+
matches: []
|
|
356
|
+
});
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
const normalized = 'object' == typeof choice && null !== choice && 'value' in choice ? choice : {
|
|
360
|
+
value: choice
|
|
361
|
+
};
|
|
362
|
+
const label = choiceLabel(normalized).toLowerCase();
|
|
363
|
+
if (words.every((word)=>label.includes(word))) groups.at(-1)?.matches.push({
|
|
364
|
+
choice: normalized,
|
|
365
|
+
prefix: label.startsWith(text)
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
const byPrefix = (items, prefix)=>[
|
|
369
|
+
...items.filter(prefix),
|
|
370
|
+
...items.filter((item)=>!prefix(item))
|
|
371
|
+
];
|
|
372
|
+
const [ungrouped, ...grouped] = groups;
|
|
373
|
+
return [
|
|
374
|
+
ungrouped,
|
|
375
|
+
...byPrefix(grouped.filter(({ matches })=>matches.length), ({ matches })=>matches.some(({ prefix })=>prefix))
|
|
376
|
+
].flatMap(({ separator, matches })=>[
|
|
377
|
+
...separator ? [
|
|
378
|
+
separator
|
|
379
|
+
] : [],
|
|
380
|
+
...byPrefix(matches, ({ prefix })=>prefix).map(({ choice })=>choice)
|
|
381
|
+
]);
|
|
382
|
+
};
|
|
337
383
|
const interaction_select = async (config)=>{
|
|
338
384
|
const { key, id, ...interactive } = config;
|
|
339
|
-
if (!isNonInteractive())
|
|
385
|
+
if (!isNonInteractive()) {
|
|
386
|
+
if (choicesOf(config).length <= searchThreshold) return prompts_select(interactive);
|
|
387
|
+
return search({
|
|
388
|
+
message: `${config.message.trimEnd()} (type to filter)`,
|
|
389
|
+
source: (term)=>filterChoices(config.choices, term),
|
|
390
|
+
pageSize: config.pageSize,
|
|
391
|
+
default: config.default
|
|
392
|
+
});
|
|
393
|
+
}
|
|
340
394
|
const field = requireKey(key);
|
|
341
395
|
const value = answerFor(field, config.default);
|
|
342
396
|
if (void 0 === value) throw interaction_missing(field);
|
|
@@ -2597,6 +2651,75 @@ const projectRelative = (fromFile, toFile)=>{
|
|
|
2597
2651
|
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toFile.replace(codeExtension, '')));
|
|
2598
2652
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
2599
2653
|
};
|
|
2654
|
+
const importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
2655
|
+
const importLine = /^\s*(?:import|export)\b[^'"\n]*\bfrom\s*(['"])([^'"\n]+)\1;?\s*$/;
|
|
2656
|
+
const deleteBackendUnit = (projectRoot, rootFolderPath, unit)=>{
|
|
2657
|
+
const files = [
|
|
2658
|
+
...unitMoves(unit, unit).keys()
|
|
2659
|
+
];
|
|
2660
|
+
const fileSet = new Set(files);
|
|
2661
|
+
const stems = new Set(files.map((file)=>file.replace(codeExtension, '')));
|
|
2662
|
+
const aggregateFolder = 'aggregate' === unit.kind ? node_path.join(unit.ownerPath, 'domain/aggregates', unit.name) : void 0;
|
|
2663
|
+
const parentAggregate = unit.aggregate ? node_path.join(unit.ownerPath, 'domain/aggregates', unit.aggregate) : void 0;
|
|
2664
|
+
const isUnit = (resolved)=>stems.has(resolved) || !!aggregateFolder && (resolved === aggregateFolder || resolved.startsWith(`${aggregateFolder}${node_path.sep}`));
|
|
2665
|
+
const isParentBarrel = (resolved)=>!!parentAggregate && (resolved === parentAggregate || resolved === node_path.join(parentAggregate, 'index'));
|
|
2666
|
+
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
2667
|
+
const resolved = (specifier, file)=>resolve(specifier, file)?.resolved;
|
|
2668
|
+
const withoutUnitImports = (content, file)=>content.split('\n').filter((line)=>{
|
|
2669
|
+
const specifier = line.match(importLine)?.[2];
|
|
2670
|
+
const target = specifier && resolved(specifier, file);
|
|
2671
|
+
return !(target && isUnit(target));
|
|
2672
|
+
}).join('\n');
|
|
2673
|
+
const cleaned = new Map();
|
|
2674
|
+
const inMemoryDb = inMemoryDbFile(rootFolderPath);
|
|
2675
|
+
if ('aggregate' === unit.kind && codeFiles.has(inMemoryDb)) {
|
|
2676
|
+
const section = new UnknownFormatNaming(plural(unit.name));
|
|
2677
|
+
const original = codeFiles.get(inMemoryDb);
|
|
2678
|
+
const content = withoutUnitImports(original.replace(new RegExp(`^[ \\t]*${escapeRegExp(section.variableName)}\\s*=\\s*this\\.section<[^\\n]*\\n?`, 'm'), ''), inMemoryDb);
|
|
2679
|
+
if (content !== original) cleaned.set(inMemoryDb, content);
|
|
2680
|
+
}
|
|
2681
|
+
if (parentAggregate) {
|
|
2682
|
+
const index = node_path.join(parentAggregate, 'index.ts');
|
|
2683
|
+
const original = codeFiles.get(index);
|
|
2684
|
+
if (void 0 !== original) {
|
|
2685
|
+
const content = withoutUnitImports(original, index);
|
|
2686
|
+
if (content !== original) cleaned.set(index, content);
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
const ClassName = new UnknownFormatNaming(unit.name).ClassName;
|
|
2690
|
+
const namedImports = /import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*(['"])([^'"\n]+)\2/g;
|
|
2691
|
+
const usedBy = [];
|
|
2692
|
+
const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
|
|
2693
|
+
for (const [file, original] of codeFiles){
|
|
2694
|
+
if (fileSet.has(file)) continue;
|
|
2695
|
+
const content = cleaned.get(file) ?? original;
|
|
2696
|
+
for (const [, , specifier] of content.matchAll(importSpecifier)){
|
|
2697
|
+
const target = resolved(specifier, file);
|
|
2698
|
+
if (target && isUnit(target)) usedBy.push([
|
|
2699
|
+
relative(file),
|
|
2700
|
+
relative(target)
|
|
2701
|
+
]);
|
|
2702
|
+
}
|
|
2703
|
+
for (const [, names, , specifier] of content.matchAll(namedImports)){
|
|
2704
|
+
const target = resolved(specifier, file);
|
|
2705
|
+
if (target && isParentBarrel(target) && new RegExp(`(?<![\\w$])${ClassName}(?![\\w$])`).test(names)) usedBy.push([
|
|
2706
|
+
relative(file),
|
|
2707
|
+
`${relative(target)} (${ClassName})`
|
|
2708
|
+
]);
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
if (usedBy.length) return {
|
|
2712
|
+
usedBy
|
|
2713
|
+
};
|
|
2714
|
+
for (const file of files)new File(file).delete(rootFolderPath);
|
|
2715
|
+
for (const [file, content] of cleaned)new File(file).update(content);
|
|
2716
|
+
return {
|
|
2717
|
+
deleted: files,
|
|
2718
|
+
updated: [
|
|
2719
|
+
...cleaned.keys()
|
|
2720
|
+
]
|
|
2721
|
+
};
|
|
2722
|
+
};
|
|
2600
2723
|
const contractKinds = [
|
|
2601
2724
|
'aggregate',
|
|
2602
2725
|
'command',
|
|
@@ -2780,7 +2903,7 @@ const validateMove = (reactFolder, module, rawName)=>{
|
|
|
2780
2903
|
if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
|
|
2781
2904
|
return true;
|
|
2782
2905
|
};
|
|
2783
|
-
const
|
|
2906
|
+
const react_module_move_routeFolder = (appFolder, rawName)=>{
|
|
2784
2907
|
const { folders, folderName } = new NestedName(rawName);
|
|
2785
2908
|
return node_path.join(appFolder, ...folders, folderName);
|
|
2786
2909
|
};
|
|
@@ -2842,6 +2965,51 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
|
2842
2965
|
}
|
|
2843
2966
|
});
|
|
2844
2967
|
};
|
|
2968
|
+
const pageRouteFolder = (appFolder, page)=>{
|
|
2969
|
+
const folder = react_module_move_routeFolder(appFolder, page.name);
|
|
2970
|
+
const routePage = node_path.join(folder, 'page.tsx');
|
|
2971
|
+
return node_fs.existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(node_fs.readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
2972
|
+
};
|
|
2973
|
+
const reactModuleFiles = (module)=>{
|
|
2974
|
+
if ('widget' === module.kind) return walk(module.path);
|
|
2975
|
+
const folder = node_path.dirname(module.path);
|
|
2976
|
+
const own = new RegExp(`^${escapeRegExp(module.fileBase)}-page(?:\\.|$)`);
|
|
2977
|
+
return node_fs.readdirSync(folder, {
|
|
2978
|
+
withFileTypes: true
|
|
2979
|
+
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>node_path.join(folder, entry.name));
|
|
2980
|
+
};
|
|
2981
|
+
const react_module_move_importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
2982
|
+
const deleteReactModule = (projectRoot, reactFolder, module, route)=>{
|
|
2983
|
+
const moduleFiles = reactModuleFiles(module);
|
|
2984
|
+
const routeFileList = route ? routeFiles(route.folder) : [];
|
|
2985
|
+
const own = new Set([
|
|
2986
|
+
...moduleFiles,
|
|
2987
|
+
...routeFileList
|
|
2988
|
+
]);
|
|
2989
|
+
const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
|
|
2990
|
+
const isModule = (resolved)=>stems.has(resolved) || 'widget' === module.kind && (resolved === module.path || resolved.startsWith(`${module.path}${node_path.sep}`));
|
|
2991
|
+
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
2992
|
+
const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
|
|
2993
|
+
const usedBy = [];
|
|
2994
|
+
for (const [file, content] of codeFiles)if (!own.has(file)) for (const [, , specifier] of content.matchAll(react_module_move_importSpecifier)){
|
|
2995
|
+
const target = resolve(specifier, file)?.resolved;
|
|
2996
|
+
if (target && isModule(target)) usedBy.push([
|
|
2997
|
+
relative(file),
|
|
2998
|
+
relative(target)
|
|
2999
|
+
]);
|
|
3000
|
+
}
|
|
3001
|
+
if (usedBy.length) return {
|
|
3002
|
+
usedBy
|
|
3003
|
+
};
|
|
3004
|
+
for (const file of moduleFiles)new File(file).delete(reactFolder);
|
|
3005
|
+
for (const file of routeFileList)new File(file).delete(route.appFolder);
|
|
3006
|
+
return {
|
|
3007
|
+
deleted: [
|
|
3008
|
+
...moduleFiles,
|
|
3009
|
+
...routeFileList
|
|
3010
|
+
]
|
|
3011
|
+
};
|
|
3012
|
+
};
|
|
2845
3013
|
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
2846
3014
|
if ('ports' === kind) return crossContext ? [
|
|
2847
3015
|
{
|
|
@@ -2856,6 +3024,108 @@ const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
|
2856
3024
|
}
|
|
2857
3025
|
] : [];
|
|
2858
3026
|
};
|
|
3027
|
+
const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
3028
|
+
const root = new ProjectRoot().path;
|
|
3029
|
+
const rootFolderPath = node_path.join(root, ConfigFile.Instance.data.project.rootFolder);
|
|
3030
|
+
const units = findBackendUnits(ownerFolder.path);
|
|
3031
|
+
if (!units.length) return void report('No modules generated by df-scaffold were found here.');
|
|
3032
|
+
const unit = await interaction_select({
|
|
3033
|
+
key: 'module',
|
|
3034
|
+
id: unitId,
|
|
3035
|
+
message: 'Module to delete:',
|
|
3036
|
+
choices: Object.keys(kindLayouts).flatMap((kind)=>{
|
|
3037
|
+
const group = units.filter((x)=>x.kind === kind);
|
|
3038
|
+
return group.length ? [
|
|
3039
|
+
new Separator(`── ${kindLayouts[group[0].kind].title}`),
|
|
3040
|
+
...group.map((value)=>({
|
|
3041
|
+
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
3042
|
+
value
|
|
3043
|
+
}))
|
|
3044
|
+
] : [];
|
|
3045
|
+
}),
|
|
3046
|
+
pageSize: 20
|
|
3047
|
+
});
|
|
3048
|
+
const result = deleteBackendUnit(root, rootFolderPath, unit);
|
|
3049
|
+
if (result.usedBy) {
|
|
3050
|
+
if (isNonInteractive()) throw new RequestError('DELETE_NOT_ALLOWED', 'Other files still use the module.', {
|
|
3051
|
+
usedBy: result.usedBy
|
|
3052
|
+
});
|
|
3053
|
+
report([
|
|
3054
|
+
'Nothing was deleted: these files still use it.',
|
|
3055
|
+
...result.usedBy.map(([file, used])=>` ${file} → ${used}`),
|
|
3056
|
+
'Remove those uses first (Wire dependency edits wiring; imports and constructor parameters are yours).'
|
|
3057
|
+
].join('\n'));
|
|
3058
|
+
return;
|
|
3059
|
+
}
|
|
3060
|
+
const relative = (file)=>node_path.relative(root, file);
|
|
3061
|
+
report([
|
|
3062
|
+
'Files to delete:',
|
|
3063
|
+
...result.deleted.map((file)=>` ${relative(file)}`),
|
|
3064
|
+
...result.updated.length ? [
|
|
3065
|
+
'Files to update:',
|
|
3066
|
+
...result.updated.map((file)=>` ${relative(file)}`)
|
|
3067
|
+
] : []
|
|
3068
|
+
].join('\n'));
|
|
3069
|
+
if (!await interaction_confirm({
|
|
3070
|
+
key: 'apply',
|
|
3071
|
+
message: 'Delete?',
|
|
3072
|
+
default: false
|
|
3073
|
+
})) {
|
|
3074
|
+
discardPendingChanges();
|
|
3075
|
+
report('Cancelled: nothing was deleted.');
|
|
3076
|
+
}
|
|
3077
|
+
};
|
|
3078
|
+
const deleteReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
3079
|
+
const reactFolder = presentationReactFolder.path;
|
|
3080
|
+
const modules = findReactModules(reactFolder, kind);
|
|
3081
|
+
if (!modules.length) return void report(`No ${kind}s generated by df-react were found.`);
|
|
3082
|
+
const module = await interaction_select({
|
|
3083
|
+
key: 'module',
|
|
3084
|
+
id: (value)=>value.name,
|
|
3085
|
+
message: 'page' === kind ? 'Page to delete:' : 'Widget to delete:',
|
|
3086
|
+
choices: modules.map((value)=>({
|
|
3087
|
+
name: value.name,
|
|
3088
|
+
value,
|
|
3089
|
+
description: node_path.relative(reactFolder, value.path)
|
|
3090
|
+
}))
|
|
3091
|
+
});
|
|
3092
|
+
const root = new ProjectRoot().path;
|
|
3093
|
+
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3094
|
+
const appFolder = node_path.join(root, nextAppFolder(root));
|
|
3095
|
+
const routeFolder = 'page' === kind && usesNext() ? pageRouteFolder(appFolder, module) : void 0;
|
|
3096
|
+
const withRoute = !!routeFolder && await interaction_confirm({
|
|
3097
|
+
key: 'deleteRoute',
|
|
3098
|
+
message: `Delete its Next.js route too: ${relative(routeFolder)}? Its URL stops working.`,
|
|
3099
|
+
default: true
|
|
3100
|
+
});
|
|
3101
|
+
const result = deleteReactModule(root, reactFolder, module, withRoute && routeFolder ? {
|
|
3102
|
+
appFolder,
|
|
3103
|
+
folder: routeFolder
|
|
3104
|
+
} : void 0);
|
|
3105
|
+
if (result.usedBy) {
|
|
3106
|
+
if (isNonInteractive()) throw new RequestError('DELETE_NOT_ALLOWED', `Other files still use the ${kind}.`, {
|
|
3107
|
+
usedBy: result.usedBy
|
|
3108
|
+
});
|
|
3109
|
+
report([
|
|
3110
|
+
'Nothing was deleted: these files still use it.',
|
|
3111
|
+
...result.usedBy.map(([file, used])=>` ${file} → ${used}`),
|
|
3112
|
+
'Remove those uses first.'
|
|
3113
|
+
].join('\n'));
|
|
3114
|
+
return;
|
|
3115
|
+
}
|
|
3116
|
+
report([
|
|
3117
|
+
'Files to delete:',
|
|
3118
|
+
...result.deleted.map((file)=>` ${relative(file)}`)
|
|
3119
|
+
].join('\n'));
|
|
3120
|
+
if (!await interaction_confirm({
|
|
3121
|
+
key: 'apply',
|
|
3122
|
+
message: 'Delete?',
|
|
3123
|
+
default: false
|
|
3124
|
+
})) {
|
|
3125
|
+
discardPendingChanges();
|
|
3126
|
+
report('Cancelled: nothing was deleted.');
|
|
3127
|
+
}
|
|
3128
|
+
};
|
|
2859
3129
|
const configurationSections = [
|
|
2860
3130
|
'project',
|
|
2861
3131
|
'backend',
|
|
@@ -3235,11 +3505,10 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3235
3505
|
const promptRouteMove = async (root, page, newName)=>{
|
|
3236
3506
|
if (!usesNext()) return;
|
|
3237
3507
|
const appFolder = node_path.join(root, nextAppFolder(root));
|
|
3238
|
-
const from =
|
|
3239
|
-
const to =
|
|
3508
|
+
const from = pageRouteFolder(appFolder, page);
|
|
3509
|
+
const to = react_module_move_routeFolder(appFolder, newName);
|
|
3240
3510
|
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3241
|
-
|
|
3242
|
-
if (from === to || !node_fs.existsSync(routePage) || !new RegExp(`\\b${page.ClassName}Page\\b`).test(node_fs.readFileSync(routePage, 'utf8'))) return;
|
|
3511
|
+
if (!from || from === to) return;
|
|
3243
3512
|
if (node_fs.existsSync(node_path.join(to, 'page.tsx'))) return void report(`${relative(to)}/page.tsx already exists: the route ${relative(from)} stays.`);
|
|
3244
3513
|
const move = await interaction_confirm({
|
|
3245
3514
|
key: 'moveRoute',
|
|
@@ -4525,4 +4794,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
4525
4794
|
break;
|
|
4526
4795
|
}
|
|
4527
4796
|
};
|
|
4528
|
-
export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
|
|
4797
|
+
export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, deleteBackendUnitUseCase, deleteReactModuleUseCase, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
|