@domain-first/project-structure 8.2.0 → 8.4.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 +5 -1
- package/dist/287.js +333 -30
- package/dist/561.js +75 -32
- package/dist/agent-cli.d.ts +40 -1
- package/dist/agent-requests.d.ts +78 -0
- package/dist/backend-module-move.d.ts +16 -0
- package/dist/index.cjs +383 -35
- package/dist/index.js +4 -2
- package/dist/init.cjs +55 -55
- package/dist/integration.cjs +406 -60
- package/dist/react-module-move.d.ts +47 -3
- package/dist/react.cjs +425 -61
- package/dist/react.js +20 -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 +1 -1
- package/skills/df-ps-react/SKILL.md +5 -3
- package/skills/df-ps-react/references/generators.md +8 -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 +7 -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
|
@@ -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. UI-kit components and shared hooks can be moved, renamed and deleted the same way. 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
|
|
package/dist/287.js
CHANGED
|
@@ -2651,6 +2651,75 @@ const projectRelative = (fromFile, toFile)=>{
|
|
|
2651
2651
|
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toFile.replace(codeExtension, '')));
|
|
2652
2652
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
2653
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
|
+
};
|
|
2654
2723
|
const contractKinds = [
|
|
2655
2724
|
'aggregate',
|
|
2656
2725
|
'command',
|
|
@@ -2784,6 +2853,66 @@ const inMemoryRepositoryWiring = (ownerFolder, unit, wireFile)=>(implementation,
|
|
|
2784
2853
|
wireInMemoryDb(wireFile, implementation.className);
|
|
2785
2854
|
return true;
|
|
2786
2855
|
};
|
|
2856
|
+
const reactKindLayouts = {
|
|
2857
|
+
page: {
|
|
2858
|
+
folder: 'pages',
|
|
2859
|
+
nested: true,
|
|
2860
|
+
inFolder: false,
|
|
2861
|
+
ownFile: (fileBase)=>new RegExp(`^${escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
2862
|
+
target: (reactFolder, { folders, fileName })=>node_path.join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`),
|
|
2863
|
+
classPrefix: '(use)?',
|
|
2864
|
+
classSuffix: 'Page'
|
|
2865
|
+
},
|
|
2866
|
+
widget: {
|
|
2867
|
+
folder: 'widgets',
|
|
2868
|
+
nested: true,
|
|
2869
|
+
inFolder: true,
|
|
2870
|
+
target: (reactFolder, { folders, folderName })=>node_path.join(reactFolder, 'widgets', ...folders, folderName),
|
|
2871
|
+
classPrefix: '(use)?',
|
|
2872
|
+
classSuffix: 'Widget|UIModel',
|
|
2873
|
+
storyTitle: (segments)=>[
|
|
2874
|
+
'Widgets',
|
|
2875
|
+
...segments
|
|
2876
|
+
].join('/')
|
|
2877
|
+
},
|
|
2878
|
+
'ui-kit': {
|
|
2879
|
+
folder: 'ui-kit',
|
|
2880
|
+
nested: false,
|
|
2881
|
+
inFolder: true,
|
|
2882
|
+
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'ui-kit', fileName),
|
|
2883
|
+
classPrefix: '()',
|
|
2884
|
+
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
2885
|
+
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
2886
|
+
},
|
|
2887
|
+
hook: {
|
|
2888
|
+
folder: 'hooks',
|
|
2889
|
+
nested: false,
|
|
2890
|
+
inFolder: false,
|
|
2891
|
+
ownFile: (fileBase)=>new RegExp(`^use-${escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
2892
|
+
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'hooks', `use-${fileName}.ts`),
|
|
2893
|
+
classPrefix: '(use)',
|
|
2894
|
+
classSuffix: '(?![\\w$])'
|
|
2895
|
+
}
|
|
2896
|
+
};
|
|
2897
|
+
const reactKindTitles = {
|
|
2898
|
+
page: [
|
|
2899
|
+
'Page',
|
|
2900
|
+
'pages'
|
|
2901
|
+
],
|
|
2902
|
+
widget: [
|
|
2903
|
+
'Widget',
|
|
2904
|
+
'widgets'
|
|
2905
|
+
],
|
|
2906
|
+
'ui-kit': [
|
|
2907
|
+
'UI-kit component',
|
|
2908
|
+
'UI-kit components'
|
|
2909
|
+
],
|
|
2910
|
+
hook: [
|
|
2911
|
+
'Shared hook',
|
|
2912
|
+
'shared hooks'
|
|
2913
|
+
]
|
|
2914
|
+
};
|
|
2915
|
+
const reactModuleName = (kind, rawName)=>'hook' === kind ? rawName.trim().replace(/^use-/, '') : rawName;
|
|
2787
2916
|
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
2788
2917
|
const prefix = `${folders.join('-')}-`;
|
|
2789
2918
|
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
@@ -2797,8 +2926,36 @@ const declaredClassName = (filePath, suffix, name)=>{
|
|
|
2797
2926
|
const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
2798
2927
|
return declared ?? new NestedName(name).ClassName;
|
|
2799
2928
|
};
|
|
2929
|
+
const findUiKit = (reactFolder)=>{
|
|
2930
|
+
const root = node_path.join(reactFolder, 'ui-kit');
|
|
2931
|
+
if (!node_fs.existsSync(root)) return [];
|
|
2932
|
+
return node_fs.readdirSync(root, {
|
|
2933
|
+
withFileTypes: true
|
|
2934
|
+
}).filter((entry)=>entry.isDirectory() && node_fs.existsSync(node_path.join(root, entry.name, `${entry.name}.tsx`))).map(({ name })=>({
|
|
2935
|
+
kind: 'ui-kit',
|
|
2936
|
+
name,
|
|
2937
|
+
path: node_path.join(root, name),
|
|
2938
|
+
fileBase: name,
|
|
2939
|
+
ClassName: declaredClassName(node_path.join(root, name, `${name}.tsx`), '', name)
|
|
2940
|
+
}));
|
|
2941
|
+
};
|
|
2942
|
+
const findHooks = (reactFolder)=>{
|
|
2943
|
+
const root = node_path.join(reactFolder, 'hooks');
|
|
2944
|
+
if (!node_fs.existsSync(root)) return [];
|
|
2945
|
+
return node_fs.readdirSync(root).filter((file)=>/^use-.+\.tsx?$/.test(file) && !/\.(spec|test)\./.test(file)).map((file)=>{
|
|
2946
|
+
const name = file.replace(/^use-/, '').replace(/\.tsx?$/, '');
|
|
2947
|
+
const content = node_fs.readFileSync(node_path.join(root, file), 'utf8');
|
|
2948
|
+
return {
|
|
2949
|
+
kind: 'hook',
|
|
2950
|
+
name,
|
|
2951
|
+
path: node_path.join(root, file),
|
|
2952
|
+
fileBase: name,
|
|
2953
|
+
ClassName: content.match(/export\s+(?:const|function)\s+use(\w+)\b/)?.[1] ?? new NestedName(name).ClassName
|
|
2954
|
+
};
|
|
2955
|
+
});
|
|
2956
|
+
};
|
|
2800
2957
|
const findReactModules = (reactFolder, kind)=>{
|
|
2801
|
-
const modules = 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
2958
|
+
const modules = 'ui-kit' === kind ? findUiKit(reactFolder) : 'hook' === kind ? findHooks(reactFolder) : 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
2802
2959
|
const folders = node_path.relative(node_path.join(reactFolder, 'pages'), node_path.dirname(file)).split(node_path.sep).filter((segment)=>!!segment);
|
|
2803
2960
|
const fileBase = node_path.basename(file, '-page.tsx');
|
|
2804
2961
|
const name = react_module_move_nestedName(folders, fileBase);
|
|
@@ -2822,19 +2979,17 @@ const findReactModules = (reactFolder, kind)=>{
|
|
|
2822
2979
|
});
|
|
2823
2980
|
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
2824
2981
|
};
|
|
2825
|
-
const targetPath = (reactFolder, module, rawName)=>
|
|
2826
|
-
const { folders, folderName, fileName } = new NestedName(rawName);
|
|
2827
|
-
return 'page' === module.kind ? node_path.join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`) : node_path.join(reactFolder, 'widgets', ...folders, folderName);
|
|
2828
|
-
};
|
|
2982
|
+
const targetPath = (reactFolder, module, rawName)=>reactKindLayouts[module.kind].target(reactFolder, new NestedName(reactModuleName(module.kind, rawName)));
|
|
2829
2983
|
const validateMove = (reactFolder, module, rawName)=>{
|
|
2830
2984
|
const nameError = NestedName.validate(rawName);
|
|
2831
2985
|
if (true !== nameError) return nameError;
|
|
2986
|
+
if (!reactKindLayouts[module.kind].nested && /[\\/]/.test(rawName)) return 'UI-kit components and shared hooks have no folders: enter a name without "/"';
|
|
2832
2987
|
const target = targetPath(reactFolder, module, rawName);
|
|
2833
2988
|
if (target !== module.path && node_fs.existsSync(target)) return `${node_path.relative(reactFolder, target)} already exists`;
|
|
2834
2989
|
if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
|
|
2835
2990
|
return true;
|
|
2836
2991
|
};
|
|
2837
|
-
const
|
|
2992
|
+
const react_module_move_routeFolder = (appFolder, rawName)=>{
|
|
2838
2993
|
const { folders, folderName } = new NestedName(rawName);
|
|
2839
2994
|
return node_path.join(appFolder, ...folders, folderName);
|
|
2840
2995
|
};
|
|
@@ -2842,13 +2997,14 @@ const routeFiles = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(fo
|
|
|
2842
2997
|
withFileTypes: true
|
|
2843
2998
|
}).filter((entry)=>entry.isFile()).map((entry)=>node_path.join(folder, entry.name)) : [];
|
|
2844
2999
|
const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
2845
|
-
const
|
|
3000
|
+
const layout = reactKindLayouts[module.kind];
|
|
3001
|
+
const newName = new NestedName(reactModuleName(module.kind, rawName));
|
|
2846
3002
|
const target = targetPath(reactFolder, module, rawName);
|
|
2847
3003
|
const newClassName = newName.ClassName;
|
|
2848
|
-
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.])`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
2849
|
-
const oldFolder =
|
|
2850
|
-
const newFolder =
|
|
2851
|
-
const ownsPath = (candidate)=>
|
|
3004
|
+
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.]|$)`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
3005
|
+
const oldFolder = layout.inFolder ? module.path : node_path.dirname(module.path);
|
|
3006
|
+
const newFolder = layout.inFolder ? target : node_path.dirname(target);
|
|
3007
|
+
const ownsPath = (candidate)=>layout.inFolder ? candidate === oldFolder || candidate.startsWith(`${oldFolder}${node_path.sep}`) : node_path.dirname(candidate) === oldFolder && layout.ownFile(module.fileBase).test(node_path.basename(candidate));
|
|
2852
3008
|
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
2853
3009
|
const routeTarget = (candidate)=>{
|
|
2854
3010
|
if (!route) return;
|
|
@@ -2868,7 +3024,7 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
|
2868
3024
|
segments[last] = renameFile(segments[last]);
|
|
2869
3025
|
return node_path.join(newFolder, ...segments);
|
|
2870
3026
|
};
|
|
2871
|
-
const moduleFiles =
|
|
3027
|
+
const moduleFiles = reactModuleFiles(module);
|
|
2872
3028
|
const moves = new Map([
|
|
2873
3029
|
...moduleFiles,
|
|
2874
3030
|
...routeFileSet
|
|
@@ -2876,14 +3032,14 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
|
2876
3032
|
file,
|
|
2877
3033
|
movedPath(file) ?? file
|
|
2878
3034
|
]));
|
|
2879
|
-
const
|
|
2880
|
-
const
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
const
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
].
|
|
3035
|
+
const classPattern = new RegExp(`(?<![\\w$])${layout.classPrefix}${escapeRegExp(module.ClassName)}(?=${layout.classSuffix})`, 'g');
|
|
3036
|
+
const oldTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
3037
|
+
module.ClassName
|
|
3038
|
+
] : module.name.split('/').map((segment)=>new NestedName(segment).ClassName));
|
|
3039
|
+
const titlePattern = oldTitle && new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
3040
|
+
const newTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
3041
|
+
newClassName
|
|
3042
|
+
] : newName.classNameSegments);
|
|
2887
3043
|
return stageModuleMove({
|
|
2888
3044
|
projectRoot,
|
|
2889
3045
|
stopAt: reactFolder,
|
|
@@ -2891,11 +3047,57 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
|
2891
3047
|
moves,
|
|
2892
3048
|
movedPath,
|
|
2893
3049
|
rename: (content, { moved })=>{
|
|
2894
|
-
const renamed = content.replace(classPattern, (_, use
|
|
2895
|
-
return moved &&
|
|
3050
|
+
const renamed = content.replace(classPattern, (_, use)=>`${use ?? ''}${newClassName}`);
|
|
3051
|
+
return moved && titlePattern ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
2896
3052
|
}
|
|
2897
3053
|
});
|
|
2898
3054
|
};
|
|
3055
|
+
const pageRouteFolder = (appFolder, page)=>{
|
|
3056
|
+
const folder = react_module_move_routeFolder(appFolder, page.name);
|
|
3057
|
+
const routePage = node_path.join(folder, 'page.tsx');
|
|
3058
|
+
return node_fs.existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(node_fs.readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
3059
|
+
};
|
|
3060
|
+
const reactModuleFiles = (module)=>{
|
|
3061
|
+
const layout = reactKindLayouts[module.kind];
|
|
3062
|
+
if (layout.inFolder) return walk(module.path);
|
|
3063
|
+
const folder = node_path.dirname(module.path);
|
|
3064
|
+
const own = layout.ownFile(module.fileBase);
|
|
3065
|
+
return node_fs.readdirSync(folder, {
|
|
3066
|
+
withFileTypes: true
|
|
3067
|
+
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>node_path.join(folder, entry.name));
|
|
3068
|
+
};
|
|
3069
|
+
const react_module_move_importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
3070
|
+
const deleteReactModule = (projectRoot, reactFolder, module, route)=>{
|
|
3071
|
+
const moduleFiles = reactModuleFiles(module);
|
|
3072
|
+
const routeFileList = route ? routeFiles(route.folder) : [];
|
|
3073
|
+
const own = new Set([
|
|
3074
|
+
...moduleFiles,
|
|
3075
|
+
...routeFileList
|
|
3076
|
+
]);
|
|
3077
|
+
const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
|
|
3078
|
+
const isModule = (resolved)=>stems.has(resolved) || reactKindLayouts[module.kind].inFolder && (resolved === module.path || resolved.startsWith(`${module.path}${node_path.sep}`));
|
|
3079
|
+
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
3080
|
+
const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
|
|
3081
|
+
const usedBy = [];
|
|
3082
|
+
for (const [file, content] of codeFiles)if (!own.has(file)) for (const [, , specifier] of content.matchAll(react_module_move_importSpecifier)){
|
|
3083
|
+
const target = resolve(specifier, file)?.resolved;
|
|
3084
|
+
if (target && isModule(target)) usedBy.push([
|
|
3085
|
+
relative(file),
|
|
3086
|
+
relative(target)
|
|
3087
|
+
]);
|
|
3088
|
+
}
|
|
3089
|
+
if (usedBy.length) return {
|
|
3090
|
+
usedBy
|
|
3091
|
+
};
|
|
3092
|
+
for (const file of moduleFiles)new File(file).delete(reactFolder);
|
|
3093
|
+
for (const file of routeFileList)new File(file).delete(route.appFolder);
|
|
3094
|
+
return {
|
|
3095
|
+
deleted: [
|
|
3096
|
+
...moduleFiles,
|
|
3097
|
+
...routeFileList
|
|
3098
|
+
]
|
|
3099
|
+
};
|
|
3100
|
+
};
|
|
2899
3101
|
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
2900
3102
|
if ('ports' === kind) return crossContext ? [
|
|
2901
3103
|
{
|
|
@@ -2910,6 +3112,108 @@ const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
|
2910
3112
|
}
|
|
2911
3113
|
] : [];
|
|
2912
3114
|
};
|
|
3115
|
+
const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
3116
|
+
const root = new ProjectRoot().path;
|
|
3117
|
+
const rootFolderPath = node_path.join(root, ConfigFile.Instance.data.project.rootFolder);
|
|
3118
|
+
const units = findBackendUnits(ownerFolder.path);
|
|
3119
|
+
if (!units.length) return void report('No modules generated by df-scaffold were found here.');
|
|
3120
|
+
const unit = await interaction_select({
|
|
3121
|
+
key: 'module',
|
|
3122
|
+
id: unitId,
|
|
3123
|
+
message: 'Module to delete:',
|
|
3124
|
+
choices: Object.keys(kindLayouts).flatMap((kind)=>{
|
|
3125
|
+
const group = units.filter((x)=>x.kind === kind);
|
|
3126
|
+
return group.length ? [
|
|
3127
|
+
new Separator(`── ${kindLayouts[group[0].kind].title}`),
|
|
3128
|
+
...group.map((value)=>({
|
|
3129
|
+
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
3130
|
+
value
|
|
3131
|
+
}))
|
|
3132
|
+
] : [];
|
|
3133
|
+
}),
|
|
3134
|
+
pageSize: 20
|
|
3135
|
+
});
|
|
3136
|
+
const result = deleteBackendUnit(root, rootFolderPath, unit);
|
|
3137
|
+
if (result.usedBy) {
|
|
3138
|
+
if (isNonInteractive()) throw new RequestError('DELETE_NOT_ALLOWED', 'Other files still use the module.', {
|
|
3139
|
+
usedBy: result.usedBy
|
|
3140
|
+
});
|
|
3141
|
+
report([
|
|
3142
|
+
'Nothing was deleted: these files still use it.',
|
|
3143
|
+
...result.usedBy.map(([file, used])=>` ${file} → ${used}`),
|
|
3144
|
+
'Remove those uses first (Wire dependency edits wiring; imports and constructor parameters are yours).'
|
|
3145
|
+
].join('\n'));
|
|
3146
|
+
return;
|
|
3147
|
+
}
|
|
3148
|
+
const relative = (file)=>node_path.relative(root, file);
|
|
3149
|
+
report([
|
|
3150
|
+
'Files to delete:',
|
|
3151
|
+
...result.deleted.map((file)=>` ${relative(file)}`),
|
|
3152
|
+
...result.updated.length ? [
|
|
3153
|
+
'Files to update:',
|
|
3154
|
+
...result.updated.map((file)=>` ${relative(file)}`)
|
|
3155
|
+
] : []
|
|
3156
|
+
].join('\n'));
|
|
3157
|
+
if (!await interaction_confirm({
|
|
3158
|
+
key: 'apply',
|
|
3159
|
+
message: 'Delete?',
|
|
3160
|
+
default: false
|
|
3161
|
+
})) {
|
|
3162
|
+
discardPendingChanges();
|
|
3163
|
+
report('Cancelled: nothing was deleted.');
|
|
3164
|
+
}
|
|
3165
|
+
};
|
|
3166
|
+
const deleteReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
3167
|
+
const reactFolder = presentationReactFolder.path;
|
|
3168
|
+
const modules = findReactModules(reactFolder, kind);
|
|
3169
|
+
if (!modules.length) return void report(`No ${reactKindTitles[kind][1]} generated by df-react were found.`);
|
|
3170
|
+
const module = await interaction_select({
|
|
3171
|
+
key: 'module',
|
|
3172
|
+
id: (value)=>value.name,
|
|
3173
|
+
message: `${reactKindTitles[kind][0]} to delete:`,
|
|
3174
|
+
choices: modules.map((value)=>({
|
|
3175
|
+
name: value.name,
|
|
3176
|
+
value,
|
|
3177
|
+
description: node_path.relative(reactFolder, value.path)
|
|
3178
|
+
}))
|
|
3179
|
+
});
|
|
3180
|
+
const root = new ProjectRoot().path;
|
|
3181
|
+
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3182
|
+
const appFolder = node_path.join(root, nextAppFolder(root));
|
|
3183
|
+
const routeFolder = 'page' === kind && usesNext() ? pageRouteFolder(appFolder, module) : void 0;
|
|
3184
|
+
const withRoute = !!routeFolder && await interaction_confirm({
|
|
3185
|
+
key: 'deleteRoute',
|
|
3186
|
+
message: `Delete its Next.js route too: ${relative(routeFolder)}? Its URL stops working.`,
|
|
3187
|
+
default: true
|
|
3188
|
+
});
|
|
3189
|
+
const result = deleteReactModule(root, reactFolder, module, withRoute && routeFolder ? {
|
|
3190
|
+
appFolder,
|
|
3191
|
+
folder: routeFolder
|
|
3192
|
+
} : void 0);
|
|
3193
|
+
if (result.usedBy) {
|
|
3194
|
+
if (isNonInteractive()) throw new RequestError('DELETE_NOT_ALLOWED', `Other files still use the ${kind}.`, {
|
|
3195
|
+
usedBy: result.usedBy
|
|
3196
|
+
});
|
|
3197
|
+
report([
|
|
3198
|
+
'Nothing was deleted: these files still use it.',
|
|
3199
|
+
...result.usedBy.map(([file, used])=>` ${file} → ${used}`),
|
|
3200
|
+
'Remove those uses first.'
|
|
3201
|
+
].join('\n'));
|
|
3202
|
+
return;
|
|
3203
|
+
}
|
|
3204
|
+
report([
|
|
3205
|
+
'Files to delete:',
|
|
3206
|
+
...result.deleted.map((file)=>` ${relative(file)}`)
|
|
3207
|
+
].join('\n'));
|
|
3208
|
+
if (!await interaction_confirm({
|
|
3209
|
+
key: 'apply',
|
|
3210
|
+
message: 'Delete?',
|
|
3211
|
+
default: false
|
|
3212
|
+
})) {
|
|
3213
|
+
discardPendingChanges();
|
|
3214
|
+
report('Cancelled: nothing was deleted.');
|
|
3215
|
+
}
|
|
3216
|
+
};
|
|
2913
3217
|
const configurationSections = [
|
|
2914
3218
|
'project',
|
|
2915
3219
|
'backend',
|
|
@@ -3289,11 +3593,10 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3289
3593
|
const promptRouteMove = async (root, page, newName)=>{
|
|
3290
3594
|
if (!usesNext()) return;
|
|
3291
3595
|
const appFolder = node_path.join(root, nextAppFolder(root));
|
|
3292
|
-
const from =
|
|
3293
|
-
const to =
|
|
3596
|
+
const from = pageRouteFolder(appFolder, page);
|
|
3597
|
+
const to = react_module_move_routeFolder(appFolder, newName);
|
|
3294
3598
|
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3295
|
-
|
|
3296
|
-
if (from === to || !node_fs.existsSync(routePage) || !new RegExp(`\\b${page.ClassName}Page\\b`).test(node_fs.readFileSync(routePage, 'utf8'))) return;
|
|
3599
|
+
if (!from || from === to) return;
|
|
3297
3600
|
if (node_fs.existsSync(node_path.join(to, 'page.tsx'))) return void report(`${relative(to)}/page.tsx already exists: the route ${relative(from)} stays.`);
|
|
3298
3601
|
const move = await interaction_confirm({
|
|
3299
3602
|
key: 'moveRoute',
|
|
@@ -3309,11 +3612,11 @@ const promptRouteMove = async (root, page, newName)=>{
|
|
|
3309
3612
|
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
3310
3613
|
const reactFolder = presentationReactFolder.path;
|
|
3311
3614
|
const modules = findReactModules(reactFolder, kind);
|
|
3312
|
-
if (!modules.length) return void report(`No ${kind}
|
|
3615
|
+
if (!modules.length) return void report(`No ${reactKindTitles[kind][1]} generated by df-react were found.`);
|
|
3313
3616
|
const module = await interaction_select({
|
|
3314
3617
|
key: 'module',
|
|
3315
3618
|
id: (value)=>value.name,
|
|
3316
|
-
message:
|
|
3619
|
+
message: `${reactKindTitles[kind][0]}:`,
|
|
3317
3620
|
choices: modules.map((value)=>({
|
|
3318
3621
|
name: value.name,
|
|
3319
3622
|
value,
|
|
@@ -3322,7 +3625,7 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
3322
3625
|
});
|
|
3323
3626
|
const name = await interaction_input({
|
|
3324
3627
|
key: 'name',
|
|
3325
|
-
message: 'New name (folders split by "/"):',
|
|
3628
|
+
message: reactKindLayouts[kind].nested ? 'New name (folders split by "/"):' : 'New name:',
|
|
3326
3629
|
default: module.name,
|
|
3327
3630
|
validate: (value)=>validateMove(reactFolder, module, value)
|
|
3328
3631
|
});
|
|
@@ -4579,4 +4882,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
4579
4882
|
break;
|
|
4580
4883
|
}
|
|
4581
4884
|
};
|
|
4582
|
-
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 };
|
|
4885
|
+
export { RequestError, addIntegration, assertAnswersConsumed, configurationSections, deleteBackendUnitUseCase, deleteReactModuleUseCase, findBackendUnits, findContracts, findReactModules, findRestEndpointGenerator, initializeUseCase, integrationDescriptions, integrationIds, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, reactKindTitles, runWithAnswers, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactPage, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
|