@domain-first/project-structure 8.0.0 → 8.1.1
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 +1 -1
- package/dist/287.js +52 -7
- package/dist/561.js +2 -1
- package/dist/agent-cli.d.ts +1 -0
- package/dist/agent-requests.d.ts +2 -0
- package/dist/index.cjs +54 -8
- package/dist/integration.cjs +54 -8
- package/dist/module-move.d.ts +6 -2
- package/dist/react-module-move.d.ts +17 -2
- package/dist/react.cjs +54 -8
- package/package.json +1 -1
- package/skills/df-ps-plan-feature/SKILL.md +40 -8
- package/skills/df-ps-react/SKILL.md +2 -2
- package/skills/df-ps-scaffold/SKILL.md +64 -22
- package/skills/df-ps-scaffold/references/agent-operations.md +1 -1
- package/skills/df-ps-scaffold/references/units/endpoint.md +1 -1
- package/skills/df-ps-scaffold/references/units/move-or-rename.md +2 -2
package/README.md
CHANGED
|
@@ -265,7 +265,7 @@ admin/panel/users → pages/admin/panel/admin-panel-users-page.tsx (AdminPane
|
|
|
265
265
|
|
|
266
266
|
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
267
|
|
|
268
|
-
**Move or rename page** and **Move or rename widget** move the files and update every import in the project.
|
|
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.
|
|
269
269
|
|
|
270
270
|
### How to add tooling
|
|
271
271
|
|
package/dist/287.js
CHANGED
|
@@ -2211,7 +2211,8 @@ const projectImports = (projectRoot)=>{
|
|
|
2211
2211
|
importsOf
|
|
2212
2212
|
};
|
|
2213
2213
|
};
|
|
2214
|
-
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content })=>{
|
|
2214
|
+
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
2215
|
+
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
2215
2216
|
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
2216
2217
|
const barrels = new Set();
|
|
2217
2218
|
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
@@ -2248,14 +2249,14 @@ const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyF
|
|
|
2248
2249
|
moved: moves.has(oldFile)
|
|
2249
2250
|
});
|
|
2250
2251
|
};
|
|
2251
|
-
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile,
|
|
2252
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile, stopFor(file));
|
|
2252
2253
|
const updated = [];
|
|
2253
2254
|
for (const [file, content] of codeFiles){
|
|
2254
2255
|
const newFile = moves.get(file);
|
|
2255
2256
|
const next = rewrite(content, file, newFile ?? file);
|
|
2256
2257
|
if (newFile && newFile !== file) {
|
|
2257
2258
|
new File(newFile).data = next;
|
|
2258
|
-
new File(file).delete(
|
|
2259
|
+
new File(file).delete(stopFor(file));
|
|
2259
2260
|
} else if (next !== content) {
|
|
2260
2261
|
new File(file).update(next);
|
|
2261
2262
|
if (!newFile) updated.push(file);
|
|
@@ -2779,7 +2780,14 @@ const validateMove = (reactFolder, module, rawName)=>{
|
|
|
2779
2780
|
if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
|
|
2780
2781
|
return true;
|
|
2781
2782
|
};
|
|
2782
|
-
const
|
|
2783
|
+
const routeFolder = (appFolder, rawName)=>{
|
|
2784
|
+
const { folders, folderName } = new NestedName(rawName);
|
|
2785
|
+
return node_path.join(appFolder, ...folders, folderName);
|
|
2786
|
+
};
|
|
2787
|
+
const routeFiles = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(folder, {
|
|
2788
|
+
withFileTypes: true
|
|
2789
|
+
}).filter((entry)=>entry.isFile()).map((entry)=>node_path.join(folder, entry.name)) : [];
|
|
2790
|
+
const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
2783
2791
|
const newName = new NestedName(rawName);
|
|
2784
2792
|
const target = targetPath(reactFolder, module, rawName);
|
|
2785
2793
|
const newClassName = newName.ClassName;
|
|
@@ -2787,7 +2795,19 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2787
2795
|
const oldFolder = 'page' === module.kind ? node_path.dirname(module.path) : module.path;
|
|
2788
2796
|
const newFolder = 'page' === module.kind ? node_path.dirname(target) : target;
|
|
2789
2797
|
const ownsPath = (candidate)=>'page' === module.kind ? node_path.dirname(candidate) === oldFolder && new RegExp(`^${escapeRegExp(module.fileBase)}-page(?:\\.|$)`).test(node_path.basename(candidate)) : candidate === oldFolder || candidate.startsWith(`${oldFolder}${node_path.sep}`);
|
|
2798
|
+
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
2799
|
+
const routeTarget = (candidate)=>{
|
|
2800
|
+
if (!route) return;
|
|
2801
|
+
const file = [
|
|
2802
|
+
...routeFileSet
|
|
2803
|
+
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
2804
|
+
if (!file) return;
|
|
2805
|
+
const moved = node_path.join(route.to, node_path.relative(route.from, file));
|
|
2806
|
+
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
2807
|
+
};
|
|
2790
2808
|
const movedPath = (candidate)=>{
|
|
2809
|
+
const routed = routeTarget(candidate);
|
|
2810
|
+
if (routed) return routed;
|
|
2791
2811
|
if (!ownsPath(candidate)) return;
|
|
2792
2812
|
const segments = node_path.relative(oldFolder, candidate).split(node_path.sep);
|
|
2793
2813
|
const last = segments.length - 1;
|
|
@@ -2795,7 +2815,10 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2795
2815
|
return node_path.join(newFolder, ...segments);
|
|
2796
2816
|
};
|
|
2797
2817
|
const moduleFiles = 'page' === module.kind ? node_fs.readdirSync(oldFolder).map((name)=>node_path.join(oldFolder, name)).filter((file)=>node_fs.statSync(file).isFile() && ownsPath(file)) : walk(oldFolder);
|
|
2798
|
-
const moves = new Map(
|
|
2818
|
+
const moves = new Map([
|
|
2819
|
+
...moduleFiles,
|
|
2820
|
+
...routeFileSet
|
|
2821
|
+
].map((file)=>[
|
|
2799
2822
|
file,
|
|
2800
2823
|
movedPath(file) ?? file
|
|
2801
2824
|
]));
|
|
@@ -2810,6 +2833,7 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
2810
2833
|
return stageModuleMove({
|
|
2811
2834
|
projectRoot,
|
|
2812
2835
|
stopAt: reactFolder,
|
|
2836
|
+
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
2813
2837
|
moves,
|
|
2814
2838
|
movedPath,
|
|
2815
2839
|
rename: (content, { moved })=>{
|
|
@@ -3208,6 +3232,26 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3208
3232
|
report('Cancelled: nothing was written.');
|
|
3209
3233
|
}
|
|
3210
3234
|
};
|
|
3235
|
+
const promptRouteMove = async (root, page, newName)=>{
|
|
3236
|
+
if (!usesNext()) return;
|
|
3237
|
+
const appFolder = node_path.join(root, nextAppFolder(root));
|
|
3238
|
+
const from = routeFolder(appFolder, page.name);
|
|
3239
|
+
const to = routeFolder(appFolder, newName);
|
|
3240
|
+
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3241
|
+
const routePage = node_path.join(from, 'page.tsx');
|
|
3242
|
+
if (from === to || !node_fs.existsSync(routePage) || !new RegExp(`\\b${page.ClassName}Page\\b`).test(node_fs.readFileSync(routePage, 'utf8'))) return;
|
|
3243
|
+
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
|
+
const move = await interaction_confirm({
|
|
3245
|
+
key: 'moveRoute',
|
|
3246
|
+
message: `Move the Next.js route too: ${relative(from)} → ${relative(to)}? Its URL changes.`,
|
|
3247
|
+
default: true
|
|
3248
|
+
});
|
|
3249
|
+
return move ? {
|
|
3250
|
+
appFolder,
|
|
3251
|
+
from,
|
|
3252
|
+
to
|
|
3253
|
+
} : void 0;
|
|
3254
|
+
};
|
|
3211
3255
|
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
3212
3256
|
const reactFolder = presentationReactFolder.path;
|
|
3213
3257
|
const modules = findReactModules(reactFolder, kind);
|
|
@@ -3229,9 +3273,10 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
3229
3273
|
validate: (value)=>validateMove(reactFolder, module, value)
|
|
3230
3274
|
});
|
|
3231
3275
|
const root = new ProjectRoot().path;
|
|
3232
|
-
const
|
|
3276
|
+
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3277
|
+
const route = 'page' === kind ? await promptRouteMove(root, module, name) : void 0;
|
|
3278
|
+
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route);
|
|
3233
3279
|
if (!moves.length && !updated.length) return void report('Nothing to change.');
|
|
3234
|
-
const relative = (file)=>node_path.relative(root, file);
|
|
3235
3280
|
report([
|
|
3236
3281
|
'Files to move:',
|
|
3237
3282
|
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
package/dist/561.js
CHANGED
|
@@ -156,7 +156,8 @@ const reactRequestSchema = zod.discriminatedUnion('operation', [
|
|
|
156
156
|
operation('move-page', {
|
|
157
157
|
...common,
|
|
158
158
|
module: nestedName,
|
|
159
|
-
name: nestedName
|
|
159
|
+
name: nestedName,
|
|
160
|
+
moveRoute: zod.boolean().optional().describe('With Next.js and a route at the page path: move it too (default true). Omit it without such a route.')
|
|
160
161
|
}),
|
|
161
162
|
operation('move-widget', {
|
|
162
163
|
...common,
|
package/dist/agent-cli.d.ts
CHANGED
|
@@ -221,6 +221,7 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
|
|
|
221
221
|
operation: z.ZodLiteral<"move-page">;
|
|
222
222
|
module: z.ZodString;
|
|
223
223
|
name: z.ZodString;
|
|
224
|
+
moveRoute: z.ZodOptional<z.ZodBoolean>;
|
|
224
225
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
225
226
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
226
227
|
}, z.core.$strict>, z.ZodObject<{
|
package/dist/agent-requests.d.ts
CHANGED
|
@@ -200,6 +200,7 @@ export declare const reactRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
200
200
|
operation: z.ZodLiteral<"move-page">;
|
|
201
201
|
module: z.ZodString;
|
|
202
202
|
name: z.ZodString;
|
|
203
|
+
moveRoute: z.ZodOptional<z.ZodBoolean>;
|
|
203
204
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
204
205
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
205
206
|
}, z.core.$strict>, z.ZodObject<{
|
|
@@ -444,6 +445,7 @@ export declare const requestSchemaFor: (command: AgentCommand) => z.ZodDiscrimin
|
|
|
444
445
|
operation: z.ZodLiteral<"move-page">;
|
|
445
446
|
module: z.ZodString;
|
|
446
447
|
name: z.ZodString;
|
|
448
|
+
moveRoute: z.ZodOptional<z.ZodBoolean>;
|
|
447
449
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
448
450
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
449
451
|
}, z.core.$strict>, z.ZodObject<{
|
package/dist/index.cjs
CHANGED
|
@@ -3196,7 +3196,8 @@ const reactRequestSchema = external_zod_default().discriminatedUnion('operation'
|
|
|
3196
3196
|
agent_requests_operation('move-page', {
|
|
3197
3197
|
...common,
|
|
3198
3198
|
module: agent_requests_nestedName,
|
|
3199
|
-
name: agent_requests_nestedName
|
|
3199
|
+
name: agent_requests_nestedName,
|
|
3200
|
+
moveRoute: external_zod_default().boolean().optional().describe('With Next.js and a route at the page path: move it too (default true). Omit it without such a route.')
|
|
3200
3201
|
}),
|
|
3201
3202
|
agent_requests_operation('move-widget', {
|
|
3202
3203
|
...common,
|
|
@@ -3315,7 +3316,8 @@ const projectImports = (projectRoot)=>{
|
|
|
3315
3316
|
importsOf
|
|
3316
3317
|
};
|
|
3317
3318
|
};
|
|
3318
|
-
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content })=>{
|
|
3319
|
+
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
3320
|
+
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
3319
3321
|
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
3320
3322
|
const barrels = new Set();
|
|
3321
3323
|
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
@@ -3352,14 +3354,14 @@ const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyF
|
|
|
3352
3354
|
moved: moves.has(oldFile)
|
|
3353
3355
|
});
|
|
3354
3356
|
};
|
|
3355
|
-
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile,
|
|
3357
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile, stopFor(file));
|
|
3356
3358
|
const updated = [];
|
|
3357
3359
|
for (const [file, content] of codeFiles){
|
|
3358
3360
|
const newFile = moves.get(file);
|
|
3359
3361
|
const next = rewrite(content, file, newFile ?? file);
|
|
3360
3362
|
if (newFile && newFile !== file) {
|
|
3361
3363
|
new file_system_File(newFile).data = next;
|
|
3362
|
-
new file_system_File(file).delete(
|
|
3364
|
+
new file_system_File(file).delete(stopFor(file));
|
|
3363
3365
|
} else if (next !== content) {
|
|
3364
3366
|
new file_system_File(file).update(next);
|
|
3365
3367
|
if (!newFile) updated.push(file);
|
|
@@ -3883,7 +3885,14 @@ const validateMove = (reactFolder, module, rawName)=>{
|
|
|
3883
3885
|
if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
|
|
3884
3886
|
return true;
|
|
3885
3887
|
};
|
|
3886
|
-
const
|
|
3888
|
+
const routeFolder = (appFolder, rawName)=>{
|
|
3889
|
+
const { folders, folderName } = new NestedName(rawName);
|
|
3890
|
+
return external_node_path_default().join(appFolder, ...folders, folderName);
|
|
3891
|
+
};
|
|
3892
|
+
const routeFiles = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
|
|
3893
|
+
withFileTypes: true
|
|
3894
|
+
}).filter((entry)=>entry.isFile()).map((entry)=>external_node_path_default().join(folder, entry.name)) : [];
|
|
3895
|
+
const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
3887
3896
|
const newName = new NestedName(rawName);
|
|
3888
3897
|
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
3889
3898
|
const newClassName = newName.ClassName;
|
|
@@ -3891,7 +3900,19 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
3891
3900
|
const oldFolder = 'page' === module.kind ? external_node_path_default().dirname(module.path) : module.path;
|
|
3892
3901
|
const newFolder = 'page' === module.kind ? external_node_path_default().dirname(target) : target;
|
|
3893
3902
|
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}`);
|
|
3903
|
+
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
3904
|
+
const routeTarget = (candidate)=>{
|
|
3905
|
+
if (!route) return;
|
|
3906
|
+
const file = [
|
|
3907
|
+
...routeFileSet
|
|
3908
|
+
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
3909
|
+
if (!file) return;
|
|
3910
|
+
const moved = external_node_path_default().join(route.to, external_node_path_default().relative(route.from, file));
|
|
3911
|
+
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
3912
|
+
};
|
|
3894
3913
|
const movedPath = (candidate)=>{
|
|
3914
|
+
const routed = routeTarget(candidate);
|
|
3915
|
+
if (routed) return routed;
|
|
3895
3916
|
if (!ownsPath(candidate)) return;
|
|
3896
3917
|
const segments = external_node_path_default().relative(oldFolder, candidate).split(external_node_path_default().sep);
|
|
3897
3918
|
const last = segments.length - 1;
|
|
@@ -3899,7 +3920,10 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
3899
3920
|
return external_node_path_default().join(newFolder, ...segments);
|
|
3900
3921
|
};
|
|
3901
3922
|
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)) : module_move_walk(oldFolder);
|
|
3902
|
-
const moves = new Map(
|
|
3923
|
+
const moves = new Map([
|
|
3924
|
+
...moduleFiles,
|
|
3925
|
+
...routeFileSet
|
|
3926
|
+
].map((file)=>[
|
|
3903
3927
|
file,
|
|
3904
3928
|
movedPath(file) ?? file
|
|
3905
3929
|
]));
|
|
@@ -3914,6 +3938,7 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
3914
3938
|
return stageModuleMove({
|
|
3915
3939
|
projectRoot,
|
|
3916
3940
|
stopAt: reactFolder,
|
|
3941
|
+
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
3917
3942
|
moves,
|
|
3918
3943
|
movedPath,
|
|
3919
3944
|
rename: (content, { moved })=>{
|
|
@@ -4036,6 +4061,26 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
4036
4061
|
report('Cancelled: nothing was written.');
|
|
4037
4062
|
}
|
|
4038
4063
|
};
|
|
4064
|
+
const promptRouteMove = async (root, page, newName)=>{
|
|
4065
|
+
if (!usesNext()) return;
|
|
4066
|
+
const appFolder = external_node_path_default().join(root, nextAppFolder(root));
|
|
4067
|
+
const from = routeFolder(appFolder, page.name);
|
|
4068
|
+
const to = routeFolder(appFolder, newName);
|
|
4069
|
+
const relative = (file)=>external_node_path_default().relative(root, file).split(external_node_path_default().sep).join('/');
|
|
4070
|
+
const routePage = external_node_path_default().join(from, 'page.tsx');
|
|
4071
|
+
if (from === to || !external_node_fs_default().existsSync(routePage) || !new RegExp(`\\b${page.ClassName}Page\\b`).test(external_node_fs_default().readFileSync(routePage, 'utf8'))) return;
|
|
4072
|
+
if (external_node_fs_default().existsSync(external_node_path_default().join(to, 'page.tsx'))) return void report(`${relative(to)}/page.tsx already exists: the route ${relative(from)} stays.`);
|
|
4073
|
+
const move = await interaction_confirm({
|
|
4074
|
+
key: 'moveRoute',
|
|
4075
|
+
message: `Move the Next.js route too: ${relative(from)} → ${relative(to)}? Its URL changes.`,
|
|
4076
|
+
default: true
|
|
4077
|
+
});
|
|
4078
|
+
return move ? {
|
|
4079
|
+
appFolder,
|
|
4080
|
+
from,
|
|
4081
|
+
to
|
|
4082
|
+
} : void 0;
|
|
4083
|
+
};
|
|
4039
4084
|
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
4040
4085
|
const reactFolder = presentationReactFolder.path;
|
|
4041
4086
|
const modules = findReactModules(reactFolder, kind);
|
|
@@ -4057,9 +4102,10 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
4057
4102
|
validate: (value)=>validateMove(reactFolder, module, value)
|
|
4058
4103
|
});
|
|
4059
4104
|
const root = new project_root_ProjectRoot().path;
|
|
4060
|
-
const
|
|
4105
|
+
const relative = (file)=>external_node_path_default().relative(root, file).split(external_node_path_default().sep).join('/');
|
|
4106
|
+
const route = 'page' === kind ? await promptRouteMove(root, module, name) : void 0;
|
|
4107
|
+
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route);
|
|
4061
4108
|
if (!moves.length && !updated.length) return void report('Nothing to change.');
|
|
4062
|
-
const relative = (file)=>external_node_path_default().relative(root, file);
|
|
4063
4109
|
report([
|
|
4064
4110
|
'Files to move:',
|
|
4065
4111
|
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
package/dist/integration.cjs
CHANGED
|
@@ -3196,7 +3196,8 @@ const reactRequestSchema = external_zod_default().discriminatedUnion('operation'
|
|
|
3196
3196
|
operation('move-page', {
|
|
3197
3197
|
...common,
|
|
3198
3198
|
module: agent_requests_nestedName,
|
|
3199
|
-
name: agent_requests_nestedName
|
|
3199
|
+
name: agent_requests_nestedName,
|
|
3200
|
+
moveRoute: external_zod_default().boolean().optional().describe('With Next.js and a route at the page path: move it too (default true). Omit it without such a route.')
|
|
3200
3201
|
}),
|
|
3201
3202
|
operation('move-widget', {
|
|
3202
3203
|
...common,
|
|
@@ -3315,7 +3316,8 @@ const projectImports = (projectRoot)=>{
|
|
|
3315
3316
|
importsOf
|
|
3316
3317
|
};
|
|
3317
3318
|
};
|
|
3318
|
-
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content })=>{
|
|
3319
|
+
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
3320
|
+
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
3319
3321
|
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
3320
3322
|
const barrels = new Set();
|
|
3321
3323
|
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
@@ -3352,14 +3354,14 @@ const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyF
|
|
|
3352
3354
|
moved: moves.has(oldFile)
|
|
3353
3355
|
});
|
|
3354
3356
|
};
|
|
3355
|
-
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile,
|
|
3357
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile, stopFor(file));
|
|
3356
3358
|
const updated = [];
|
|
3357
3359
|
for (const [file, content] of codeFiles){
|
|
3358
3360
|
const newFile = moves.get(file);
|
|
3359
3361
|
const next = rewrite(content, file, newFile ?? file);
|
|
3360
3362
|
if (newFile && newFile !== file) {
|
|
3361
3363
|
new file_system_File(newFile).data = next;
|
|
3362
|
-
new file_system_File(file).delete(
|
|
3364
|
+
new file_system_File(file).delete(stopFor(file));
|
|
3363
3365
|
} else if (next !== content) {
|
|
3364
3366
|
new file_system_File(file).update(next);
|
|
3365
3367
|
if (!newFile) updated.push(file);
|
|
@@ -3883,7 +3885,14 @@ const validateMove = (reactFolder, module, rawName)=>{
|
|
|
3883
3885
|
if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
|
|
3884
3886
|
return true;
|
|
3885
3887
|
};
|
|
3886
|
-
const
|
|
3888
|
+
const routeFolder = (appFolder, rawName)=>{
|
|
3889
|
+
const { folders, folderName } = new NestedName(rawName);
|
|
3890
|
+
return external_node_path_default().join(appFolder, ...folders, folderName);
|
|
3891
|
+
};
|
|
3892
|
+
const routeFiles = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
|
|
3893
|
+
withFileTypes: true
|
|
3894
|
+
}).filter((entry)=>entry.isFile()).map((entry)=>external_node_path_default().join(folder, entry.name)) : [];
|
|
3895
|
+
const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
3887
3896
|
const newName = new NestedName(rawName);
|
|
3888
3897
|
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
3889
3898
|
const newClassName = newName.ClassName;
|
|
@@ -3891,7 +3900,19 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
3891
3900
|
const oldFolder = 'page' === module.kind ? external_node_path_default().dirname(module.path) : module.path;
|
|
3892
3901
|
const newFolder = 'page' === module.kind ? external_node_path_default().dirname(target) : target;
|
|
3893
3902
|
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}`);
|
|
3903
|
+
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
3904
|
+
const routeTarget = (candidate)=>{
|
|
3905
|
+
if (!route) return;
|
|
3906
|
+
const file = [
|
|
3907
|
+
...routeFileSet
|
|
3908
|
+
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
3909
|
+
if (!file) return;
|
|
3910
|
+
const moved = external_node_path_default().join(route.to, external_node_path_default().relative(route.from, file));
|
|
3911
|
+
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
3912
|
+
};
|
|
3894
3913
|
const movedPath = (candidate)=>{
|
|
3914
|
+
const routed = routeTarget(candidate);
|
|
3915
|
+
if (routed) return routed;
|
|
3895
3916
|
if (!ownsPath(candidate)) return;
|
|
3896
3917
|
const segments = external_node_path_default().relative(oldFolder, candidate).split(external_node_path_default().sep);
|
|
3897
3918
|
const last = segments.length - 1;
|
|
@@ -3899,7 +3920,10 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
3899
3920
|
return external_node_path_default().join(newFolder, ...segments);
|
|
3900
3921
|
};
|
|
3901
3922
|
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)) : module_move_walk(oldFolder);
|
|
3902
|
-
const moves = new Map(
|
|
3923
|
+
const moves = new Map([
|
|
3924
|
+
...moduleFiles,
|
|
3925
|
+
...routeFileSet
|
|
3926
|
+
].map((file)=>[
|
|
3903
3927
|
file,
|
|
3904
3928
|
movedPath(file) ?? file
|
|
3905
3929
|
]));
|
|
@@ -3914,6 +3938,7 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
3914
3938
|
return stageModuleMove({
|
|
3915
3939
|
projectRoot,
|
|
3916
3940
|
stopAt: reactFolder,
|
|
3941
|
+
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
3917
3942
|
moves,
|
|
3918
3943
|
movedPath,
|
|
3919
3944
|
rename: (content, { moved })=>{
|
|
@@ -4036,6 +4061,26 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
4036
4061
|
report('Cancelled: nothing was written.');
|
|
4037
4062
|
}
|
|
4038
4063
|
};
|
|
4064
|
+
const promptRouteMove = async (root, page, newName)=>{
|
|
4065
|
+
if (!usesNext()) return;
|
|
4066
|
+
const appFolder = external_node_path_default().join(root, nextAppFolder(root));
|
|
4067
|
+
const from = routeFolder(appFolder, page.name);
|
|
4068
|
+
const to = routeFolder(appFolder, newName);
|
|
4069
|
+
const relative = (file)=>external_node_path_default().relative(root, file).split(external_node_path_default().sep).join('/');
|
|
4070
|
+
const routePage = external_node_path_default().join(from, 'page.tsx');
|
|
4071
|
+
if (from === to || !external_node_fs_default().existsSync(routePage) || !new RegExp(`\\b${page.ClassName}Page\\b`).test(external_node_fs_default().readFileSync(routePage, 'utf8'))) return;
|
|
4072
|
+
if (external_node_fs_default().existsSync(external_node_path_default().join(to, 'page.tsx'))) return void report(`${relative(to)}/page.tsx already exists: the route ${relative(from)} stays.`);
|
|
4073
|
+
const move = await interaction_confirm({
|
|
4074
|
+
key: 'moveRoute',
|
|
4075
|
+
message: `Move the Next.js route too: ${relative(from)} → ${relative(to)}? Its URL changes.`,
|
|
4076
|
+
default: true
|
|
4077
|
+
});
|
|
4078
|
+
return move ? {
|
|
4079
|
+
appFolder,
|
|
4080
|
+
from,
|
|
4081
|
+
to
|
|
4082
|
+
} : void 0;
|
|
4083
|
+
};
|
|
4039
4084
|
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
4040
4085
|
const reactFolder = presentationReactFolder.path;
|
|
4041
4086
|
const modules = findReactModules(reactFolder, kind);
|
|
@@ -4057,9 +4102,10 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
4057
4102
|
validate: (value)=>validateMove(reactFolder, module, value)
|
|
4058
4103
|
});
|
|
4059
4104
|
const root = new project_root_ProjectRoot().path;
|
|
4060
|
-
const
|
|
4105
|
+
const relative = (file)=>external_node_path_default().relative(root, file).split(external_node_path_default().sep).join('/');
|
|
4106
|
+
const route = 'page' === kind ? await promptRouteMove(root, module, name) : void 0;
|
|
4107
|
+
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route);
|
|
4061
4108
|
if (!moves.length && !updated.length) return void report('Nothing to change.');
|
|
4062
|
-
const relative = (file)=>external_node_path_default().relative(root, file);
|
|
4063
4109
|
report([
|
|
4064
4110
|
'Files to move:',
|
|
4065
4111
|
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
package/dist/module-move.d.ts
CHANGED
|
@@ -31,8 +31,12 @@ export type MovePlan = {
|
|
|
31
31
|
};
|
|
32
32
|
export type ModuleMove = {
|
|
33
33
|
projectRoot: string;
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Folders emptied by the move are removed up to this one (exclusive),
|
|
36
|
+
* or up to the folder `stopAtFor` gives for a file outside it.
|
|
37
|
+
*/
|
|
35
38
|
stopAt: string;
|
|
39
|
+
stopAtFor?: (file: string) => string | undefined;
|
|
36
40
|
/** Old path → new path of every file of the module. */
|
|
37
41
|
moves: Map<string, string>;
|
|
38
42
|
/**
|
|
@@ -54,5 +58,5 @@ export type ModuleMove = {
|
|
|
54
58
|
* Stages the move with pending changes: files of the module, its imports
|
|
55
59
|
* of other files, and every import of it in the project.
|
|
56
60
|
*/
|
|
57
|
-
export declare const stageModuleMove: ({ projectRoot, stopAt, moves, movedPath, rename, everyFile }: ModuleMove) => MovePlan;
|
|
61
|
+
export declare const stageModuleMove: ({ projectRoot, stopAt, moves, movedPath, rename, everyFile, stopAtFor }: ModuleMove) => MovePlan;
|
|
58
62
|
export {};
|
|
@@ -13,8 +13,23 @@ export type ReactModule = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare const findReactModules: (reactFolder: string, kind: ReactModuleKind) => ReactModule[];
|
|
15
15
|
export declare const validateMove: (reactFolder: string, module: ReactModule, rawName: string) => string | true;
|
|
16
|
+
/** A Next.js App Router route folder moved with a page. */
|
|
17
|
+
export type RouteMove = {
|
|
18
|
+
/** The App Router folder, e.g. `<root>/app`. */
|
|
19
|
+
appFolder: string;
|
|
20
|
+
from: string;
|
|
21
|
+
to: string;
|
|
22
|
+
};
|
|
23
|
+
/** The route folder of a nested page name: `admin/users` → `<app>/admin/users`. */
|
|
24
|
+
export declare const routeFolder: (appFolder: string, rawName: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* The files of a route segment itself: `page.tsx`, `layout.tsx` and the
|
|
27
|
+
* like. Subfolders are other routes and stay.
|
|
28
|
+
*/
|
|
29
|
+
export declare const routeFiles: (folder: string) => string[];
|
|
16
30
|
/**
|
|
17
31
|
* Stages the move with pending changes: files of the module, its imports
|
|
18
|
-
* of other files, and every import of it in the project.
|
|
32
|
+
* of other files, and every import of it in the project. With `route`, the
|
|
33
|
+
* files of that Next.js route folder move too.
|
|
19
34
|
*/
|
|
20
|
-
export declare const moveReactModule: (projectRoot: string, reactFolder: string, module: ReactModule, rawName: string) => MovePlan;
|
|
35
|
+
export declare const moveReactModule: (projectRoot: string, reactFolder: string, module: ReactModule, rawName: string, route?: RouteMove) => MovePlan;
|
package/dist/react.cjs
CHANGED
|
@@ -3196,7 +3196,8 @@ const reactRequestSchema = external_zod_default().discriminatedUnion('operation'
|
|
|
3196
3196
|
operation('move-page', {
|
|
3197
3197
|
...common,
|
|
3198
3198
|
module: agent_requests_nestedName,
|
|
3199
|
-
name: agent_requests_nestedName
|
|
3199
|
+
name: agent_requests_nestedName,
|
|
3200
|
+
moveRoute: external_zod_default().boolean().optional().describe('With Next.js and a route at the page path: move it too (default true). Omit it without such a route.')
|
|
3200
3201
|
}),
|
|
3201
3202
|
operation('move-widget', {
|
|
3202
3203
|
...common,
|
|
@@ -3315,7 +3316,8 @@ const projectImports = (projectRoot)=>{
|
|
|
3315
3316
|
importsOf
|
|
3316
3317
|
};
|
|
3317
3318
|
};
|
|
3318
|
-
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content })=>{
|
|
3319
|
+
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
3320
|
+
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
3319
3321
|
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
3320
3322
|
const barrels = new Set();
|
|
3321
3323
|
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
@@ -3352,14 +3354,14 @@ const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyF
|
|
|
3352
3354
|
moved: moves.has(oldFile)
|
|
3353
3355
|
});
|
|
3354
3356
|
};
|
|
3355
|
-
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile,
|
|
3357
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile, stopFor(file));
|
|
3356
3358
|
const updated = [];
|
|
3357
3359
|
for (const [file, content] of codeFiles){
|
|
3358
3360
|
const newFile = moves.get(file);
|
|
3359
3361
|
const next = rewrite(content, file, newFile ?? file);
|
|
3360
3362
|
if (newFile && newFile !== file) {
|
|
3361
3363
|
new file_system_File(newFile).data = next;
|
|
3362
|
-
new file_system_File(file).delete(
|
|
3364
|
+
new file_system_File(file).delete(stopFor(file));
|
|
3363
3365
|
} else if (next !== content) {
|
|
3364
3366
|
new file_system_File(file).update(next);
|
|
3365
3367
|
if (!newFile) updated.push(file);
|
|
@@ -3883,7 +3885,14 @@ const validateMove = (reactFolder, module, rawName)=>{
|
|
|
3883
3885
|
if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
|
|
3884
3886
|
return true;
|
|
3885
3887
|
};
|
|
3886
|
-
const
|
|
3888
|
+
const routeFolder = (appFolder, rawName)=>{
|
|
3889
|
+
const { folders, folderName } = new NestedName(rawName);
|
|
3890
|
+
return external_node_path_default().join(appFolder, ...folders, folderName);
|
|
3891
|
+
};
|
|
3892
|
+
const routeFiles = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
|
|
3893
|
+
withFileTypes: true
|
|
3894
|
+
}).filter((entry)=>entry.isFile()).map((entry)=>external_node_path_default().join(folder, entry.name)) : [];
|
|
3895
|
+
const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
3887
3896
|
const newName = new NestedName(rawName);
|
|
3888
3897
|
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
3889
3898
|
const newClassName = newName.ClassName;
|
|
@@ -3891,7 +3900,19 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
3891
3900
|
const oldFolder = 'page' === module.kind ? external_node_path_default().dirname(module.path) : module.path;
|
|
3892
3901
|
const newFolder = 'page' === module.kind ? external_node_path_default().dirname(target) : target;
|
|
3893
3902
|
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}`);
|
|
3903
|
+
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
3904
|
+
const routeTarget = (candidate)=>{
|
|
3905
|
+
if (!route) return;
|
|
3906
|
+
const file = [
|
|
3907
|
+
...routeFileSet
|
|
3908
|
+
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
3909
|
+
if (!file) return;
|
|
3910
|
+
const moved = external_node_path_default().join(route.to, external_node_path_default().relative(route.from, file));
|
|
3911
|
+
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
3912
|
+
};
|
|
3894
3913
|
const movedPath = (candidate)=>{
|
|
3914
|
+
const routed = routeTarget(candidate);
|
|
3915
|
+
if (routed) return routed;
|
|
3895
3916
|
if (!ownsPath(candidate)) return;
|
|
3896
3917
|
const segments = external_node_path_default().relative(oldFolder, candidate).split(external_node_path_default().sep);
|
|
3897
3918
|
const last = segments.length - 1;
|
|
@@ -3899,7 +3920,10 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
3899
3920
|
return external_node_path_default().join(newFolder, ...segments);
|
|
3900
3921
|
};
|
|
3901
3922
|
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)) : module_move_walk(oldFolder);
|
|
3902
|
-
const moves = new Map(
|
|
3923
|
+
const moves = new Map([
|
|
3924
|
+
...moduleFiles,
|
|
3925
|
+
...routeFileSet
|
|
3926
|
+
].map((file)=>[
|
|
3903
3927
|
file,
|
|
3904
3928
|
movedPath(file) ?? file
|
|
3905
3929
|
]));
|
|
@@ -3914,6 +3938,7 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
3914
3938
|
return stageModuleMove({
|
|
3915
3939
|
projectRoot,
|
|
3916
3940
|
stopAt: reactFolder,
|
|
3941
|
+
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
3917
3942
|
moves,
|
|
3918
3943
|
movedPath,
|
|
3919
3944
|
rename: (content, { moved })=>{
|
|
@@ -4036,6 +4061,26 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
4036
4061
|
report('Cancelled: nothing was written.');
|
|
4037
4062
|
}
|
|
4038
4063
|
};
|
|
4064
|
+
const promptRouteMove = async (root, page, newName)=>{
|
|
4065
|
+
if (!usesNext()) return;
|
|
4066
|
+
const appFolder = external_node_path_default().join(root, nextAppFolder(root));
|
|
4067
|
+
const from = routeFolder(appFolder, page.name);
|
|
4068
|
+
const to = routeFolder(appFolder, newName);
|
|
4069
|
+
const relative = (file)=>external_node_path_default().relative(root, file).split(external_node_path_default().sep).join('/');
|
|
4070
|
+
const routePage = external_node_path_default().join(from, 'page.tsx');
|
|
4071
|
+
if (from === to || !external_node_fs_default().existsSync(routePage) || !new RegExp(`\\b${page.ClassName}Page\\b`).test(external_node_fs_default().readFileSync(routePage, 'utf8'))) return;
|
|
4072
|
+
if (external_node_fs_default().existsSync(external_node_path_default().join(to, 'page.tsx'))) return void report(`${relative(to)}/page.tsx already exists: the route ${relative(from)} stays.`);
|
|
4073
|
+
const move = await interaction_confirm({
|
|
4074
|
+
key: 'moveRoute',
|
|
4075
|
+
message: `Move the Next.js route too: ${relative(from)} → ${relative(to)}? Its URL changes.`,
|
|
4076
|
+
default: true
|
|
4077
|
+
});
|
|
4078
|
+
return move ? {
|
|
4079
|
+
appFolder,
|
|
4080
|
+
from,
|
|
4081
|
+
to
|
|
4082
|
+
} : void 0;
|
|
4083
|
+
};
|
|
4039
4084
|
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
4040
4085
|
const reactFolder = presentationReactFolder.path;
|
|
4041
4086
|
const modules = findReactModules(reactFolder, kind);
|
|
@@ -4057,9 +4102,10 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
4057
4102
|
validate: (value)=>validateMove(reactFolder, module, value)
|
|
4058
4103
|
});
|
|
4059
4104
|
const root = new project_root_ProjectRoot().path;
|
|
4060
|
-
const
|
|
4105
|
+
const relative = (file)=>external_node_path_default().relative(root, file).split(external_node_path_default().sep).join('/');
|
|
4106
|
+
const route = 'page' === kind ? await promptRouteMove(root, module, name) : void 0;
|
|
4107
|
+
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route);
|
|
4061
4108
|
if (!moves.length && !updated.length) return void report('Nothing to change.');
|
|
4062
|
-
const relative = (file)=>external_node_path_default().relative(root, file);
|
|
4063
4109
|
report([
|
|
4064
4110
|
'Files to move:',
|
|
4065
4111
|
...moves.map(([from, to])=>` ${relative(from)} → ${relative(to)}`),
|
package/package.json
CHANGED
|
@@ -54,20 +54,52 @@ Never: pick silently, put one context's domain logic in `shared-kernel/`, create
|
|
|
54
54
|
|
|
55
55
|
## 4. Present the plan
|
|
56
56
|
|
|
57
|
-
One message
|
|
57
|
+
One message in the `df-ps-scaffold` rule 1 format, then stop. The architecture lives in it: each context block's "Why here" is the ownership decision of step 3, each row's Why the component choice of step 2, and open decisions go to Question.
|
|
58
58
|
|
|
59
59
|
```markdown
|
|
60
|
-
**
|
|
61
|
-
**Contexts:** `reviews` (new): reviews and their moderation. `sales`: unchanged; `reviews` reads purchases from the shared database.
|
|
60
|
+
**Plan: product reviews**
|
|
62
61
|
|
|
63
|
-
**
|
|
64
|
-
(df-ps-scaffold format: new contexts first; mark (new) and (provisional))
|
|
62
|
+
**Scaffolding**
|
|
65
63
|
|
|
66
|
-
**
|
|
64
|
+
**reviews (new)**
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
Why here: reviews have their own lifecycle and moderation; no context owns them.
|
|
67
|
+
|
|
68
|
+
What will be scaffolded:
|
|
69
|
+
|
|
70
|
+
| Layer | Type | Name | Details | Why |
|
|
71
|
+
| --- | --- | --- | --- | --- |
|
|
72
|
+
| **domain** | aggregate | review | repository prisma, in-memory in tests | consistency boundary with moderation |
|
|
73
|
+
| | error | not-a-buyer | | only buyers may review |
|
|
74
|
+
| **application** | port | customer-purchases | prisma (same database) | purchases live in sales |
|
|
75
|
+
| | use case | submit-review | deps: ReviewRepository, CustomerPurchases | checks purchase, then saves |
|
|
76
|
+
| **presentation** | endpoint | POST products/:id/reviews | → submit-review | UI calls it over HTTP |
|
|
77
|
+
|
|
78
|
+
**React**
|
|
79
|
+
|
|
80
|
+
Why here: buyers write a review on the product page.
|
|
81
|
+
|
|
82
|
+
What will be scaffolded:
|
|
83
|
+
|
|
84
|
+
| Layer | Type | Name | Details | Why |
|
|
85
|
+
| --- | --- | --- | --- | --- |
|
|
86
|
+
| **presentation** | widget | products/review-form | with separated ui | form has its own state |
|
|
87
|
+
| | page | products/details | add the widget | form goes on this screen |
|
|
88
|
+
|
|
89
|
+
**Writing by hand**
|
|
90
|
+
- review: schema (id, productId, authorId, rating, text, status), method publish()
|
|
91
|
+
- customer-purchases adapter: purchases query → HasPurchased
|
|
92
|
+
- submit-review: input { productId, rating, text }, NotABuyer when no purchase
|
|
93
|
+
|
|
94
|
+
**Running**
|
|
95
|
+
- after domain: npm run prisma:migration:plan -- --name add-reviews (applied by the user)
|
|
96
|
+
- after the endpoint: npm run openapi && npm run client:orval
|
|
97
|
+
|
|
98
|
+
**Question**
|
|
99
|
+
1. Separate reviews context (recommended) or part of catalog?
|
|
70
100
|
2. Must reviews be moderated before publishing?
|
|
101
|
+
|
|
102
|
+
Reply "ok" to start.
|
|
71
103
|
```
|
|
72
104
|
|
|
73
105
|
- Ask only what changes structure or domain behavior. Decide names and details yourself.
|
|
@@ -12,7 +12,7 @@ React modules live in `<rootFolder>/presentation/react/` (`…/react/` below) an
|
|
|
12
12
|
1. Read `domain-first.project-structure.config.json`: source root is `project.rootFolder`; React is enabled by `frontend.react`; `frontend.react.framework` is `react` or `next`, and both use `df-react`. Stories use `frontend.react.storybookFramework` (initialization uses `@storybook/react-vite` for both React and Next.js via the shared Storybook integration). A config of an earlier major version (`CONFIG_OUTDATED`): ask the user to run `npx df-upgrade`; never run it yourself. Without the config, tell the user to run `npx df-init`; without React configured, tell them to run `npx df-init --section frontend`. Initialization and configuration belong to the human: do not run `df-init` or edit these settings yourself.
|
|
13
13
|
2. A feature that also needs backend work → plan it with `df-ps-plan-feature`; React runs come last in the plan.
|
|
14
14
|
3. Choose a module for each piece of UI ("Choosing the module").
|
|
15
|
-
4. Show the work plan in the `df-ps-scaffold` rule 1 format and **stop until it's approved**.
|
|
15
|
+
4. Show the work plan in the `df-ps-scaffold` rule 1 format (the React block) and **stop until it's approved**. Type is page, widget, ui-kit component, hook, page move or widget move; Details holds the widget type and, for a page move with Next.js, whether the route moves.
|
|
16
16
|
5. Run the generators with `df-react --request` JSON in plan order (shared hooks → UI-kit → widgets → pages); check each output.
|
|
17
17
|
6. Implement ("Implementing"), after the backend and the regenerated API client.
|
|
18
18
|
7. Run `npx df-lint` and the project's tsc/lint/tests. Report against the plan.
|
|
@@ -60,7 +60,7 @@ If the CLI cannot run, report the failure and give the user the prepared JSON co
|
|
|
60
60
|
|
|
61
61
|
### Moving and renaming
|
|
62
62
|
|
|
63
|
-
Moving or renaming a page or widget is a df-react run (`Move or rename page` / `Move or rename widget`): it creates the files at the new paths, so it needs an approved plan. Don't move, rename, or copy their files by hand, and don't rename their `<Name>Page…`, `<Name>Widget…`, or `use<Name>UIModel` by hand: df-react keeps file names, code names, story titles, and imports in sync. List each move as a run: old → new name, the files to move (`→`), and the files whose imports change (`~`).
|
|
63
|
+
Moving or renaming a page or widget is a df-react run (`Move or rename page` / `Move or rename widget`): it creates the files at the new paths, so it needs an approved plan. With Next.js, moving a page can also move its App Router route and so change its URL: state in the plan whether the route moves (`moveRoute`), and ask the user when the request doesn't say. Don't move, rename, or copy their files by hand, and don't rename their `<Name>Page…`, `<Name>Widget…`, or `use<Name>UIModel` by hand: df-react keeps file names, code names, story titles, and imports in sync. List each move as a run: old → new name, the files to move (`→`), and the files whose imports change (`~`).
|
|
64
64
|
|
|
65
65
|
### Files you may create by hand
|
|
66
66
|
|
|
@@ -30,34 +30,76 @@ Tasks that only edit existing files (a bug fix, a new field, a changed rule) don
|
|
|
30
30
|
Show the plan in this format and stop:
|
|
31
31
|
|
|
32
32
|
```markdown
|
|
33
|
-
**
|
|
33
|
+
**Plan: order cancellation**
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
| --- | ----- | -------------------------- | ----------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
37
|
-
| 1 | sales | Domain → New Aggregate | order | repo prisma + in-memory | + …/domain/aggregates/order/{order.aggregate-root.ts, index.ts, order-repository.ts, specs}<br>+ …/infrastructure/repositories/{prisma,in-memory}/…<br>+ …/wiring/repositories/wire-order-repository.ts |
|
|
38
|
-
| 2 | sales | Domain → New Entity | order-line | aggregate order | + …/domain/aggregates/order/entities/{order-line.entity.ts, spec}<br>~ …/domain/aggregates/order/index.ts |
|
|
39
|
-
| 3 | sales | Application → New Use Case | place-order | deps: OrderRepository | + …/application/use-cases/place-order-use-case.ts, spec<br>+ …/wiring/use-cases/wire-place-order-use-case.ts |
|
|
40
|
-
| 4 | react | Move or rename widget | users → admin/users | | → …/widgets/admin/users/{admin-users-widget.tsx, ui/admin-users-widget-ui.tsx, hooks/use-admin-users-ui-model.ts, …}<br>~ …/pages/users-page.tsx (import) |
|
|
35
|
+
**Scaffolding**
|
|
41
36
|
|
|
42
|
-
|
|
37
|
+
**sales**
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
- `place-order-use-case.ts`: schemas, handler
|
|
39
|
+
Why here: cancelling changes the order's status; orders belong to sales.
|
|
46
40
|
|
|
47
|
-
|
|
41
|
+
What will be scaffolded:
|
|
48
42
|
|
|
49
|
-
|
|
43
|
+
| Layer | Type | Name | Details | Why |
|
|
44
|
+
| --- | --- | --- | --- | --- |
|
|
45
|
+
| **domain** | error | order-already-shipped | | shipped orders can't be cancelled |
|
|
46
|
+
| **application** | command | cancel-order | prisma, fake in tests | one atomic status change |
|
|
47
|
+
| | query | cancellable-orders | prisma | read-only list for the UI |
|
|
48
|
+
| **presentation** | endpoint | POST orders/:id/cancel | → cancel-order | UI calls it over HTTP |
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
**billing**
|
|
51
|
+
|
|
52
|
+
Why here: refunds are payments; payments belong to billing.
|
|
53
|
+
|
|
54
|
+
What will be scaffolded:
|
|
55
|
+
|
|
56
|
+
| Layer | Type | Name | Details | Why |
|
|
57
|
+
| --- | --- | --- | --- | --- |
|
|
58
|
+
| **application** | port | order-refunds | cross-context, stub in tests | paid amount lives in sales |
|
|
59
|
+
| | use case | refund-cancelled-order | deps: OrderRefunds, PaymentGateway | read order, then call provider |
|
|
60
|
+
|
|
61
|
+
**React**
|
|
62
|
+
|
|
63
|
+
Why here: the user cancels from the order screen.
|
|
64
|
+
|
|
65
|
+
What will be scaffolded:
|
|
66
|
+
|
|
67
|
+
| Layer | Type | Name | Details | Why |
|
|
68
|
+
| --- | --- | --- | --- | --- |
|
|
69
|
+
| **presentation** | widget | orders/cancel-order | with separated ui | dialog has its own state |
|
|
70
|
+
| | page | orders/details | add the widget | button goes on this screen |
|
|
71
|
+
|
|
72
|
+
**Writing by hand**
|
|
73
|
+
- cancel-order: input { orderId }, output { status }
|
|
74
|
+
- prisma implementation: update status, throw OrderAlreadyShipped
|
|
75
|
+
- endpoint: :id → orderId, OrderAlreadyShipped → 409
|
|
76
|
+
- order-refunds adapter: sales:OrderSummaryQuery result → RefundableAmount
|
|
77
|
+
|
|
78
|
+
**Running**
|
|
79
|
+
- after the endpoint: npm run openapi && npm run client:orval
|
|
80
|
+
|
|
81
|
+
**Question**
|
|
82
|
+
1. Refund right on cancel, or after a manager confirms?
|
|
83
|
+
|
|
84
|
+
Reply "ok" to start.
|
|
53
85
|
```
|
|
54
86
|
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
87
|
+
- Write the plan in the user's language (headings and sentences); module names, types, commands and paths stay as in the code. Omit empty sections.
|
|
88
|
+
- **Scaffolding** has one block per owner, in run order: new contexts first, marked `(new)` (and `(provisional)` with the reason when ownership is a reversible default), then existing contexts, `shared-kernel`, React last.
|
|
89
|
+
- **Why here**: one short sentence on why this owner, not another: the data or rule the context owns; for `shared-kernel`, why several contexts share it; for React, why the UI changes.
|
|
90
|
+
- **What will be scaffolded**: one table per owner, one row per `df-scaffold`/`df-react` run. Layers in order domain → application → infrastructure → presentation, the layer in bold only on its first row. Repositories go with their aggregate in domain; commands, queries and ports in application (their implementations are Details); endpoints and React modules in presentation.
|
|
91
|
+
- **Type**: the unit: aggregate, entity, value object, error, error namespace, service, port, command, query, use case, implementation, endpoint, wire dependency, move; for React: page, widget, ui-kit component, hook, page move, widget move.
|
|
92
|
+
- **Name**: the entered name; for a move `old → new`; for an implementation the contract; for wire dependency the module.
|
|
93
|
+
- **Details**: only what changes behavior: implementation types (`(saved)` when saved for future runs), the test implementation, dependencies (`deps: OrderRepository`), environments, widget type, the endpoint's handler, whether a Next.js route moves (`route moves: /a → /b`). No file paths, no CLI menu paths.
|
|
94
|
+
- **Why**: at most six words: why this kind of module (`choosing-components.md`).
|
|
95
|
+
- **Writing by hand**: members, schemas, mappings. Not full code.
|
|
96
|
+
- **Running**: every command that generates files (migrations, OpenAPI, API client, other codegen), with what it produces and when. Use the project's own scripts; find them in `package.json` and configs. Their output needs no approval of its own and is never edited; scripts that change a database are run only by the user. Details: the project's scripts skill (`project-scripts`), if there is one.
|
|
97
|
+
- **Overwrites**, only when a run would replace existing files (`overwriteRequired` of a `dryRun`): list those files.
|
|
98
|
+
- **Exception requests**, only for hand-created files: `<path>` (rule 2, #n) with the reason. Any other file needs its own request with a reason.
|
|
99
|
+
- **Question**, only for open decisions that change structure or domain behavior. Open questions block approval: answers first, then the updated plan.
|
|
100
|
+
- The last line says what reply starts the work.
|
|
59
101
|
- Approval must be explicit ("ok", "да", "делай"…). A question or silence isn't approval. Changes to the plan → show the updated plan and ask again.
|
|
60
|
-
- After approval, do exactly the plan. An extra
|
|
102
|
+
- After approval, do exactly the plan. An extra module or file, or a different name/option → stop and get the delta approved. Edits to existing files needed along the way don't need approval; list them in the final report.
|
|
61
103
|
|
|
62
104
|
### 2. New files only through df-scaffold
|
|
63
105
|
|
|
@@ -81,7 +123,7 @@ Moving or renaming a module (aggregate, entity, value object, service, port, que
|
|
|
81
123
|
|
|
82
124
|
With `@domain-first/wire`, every new dependency of a wired class (a constructor parameter plus its wire) is added by `df-scaffold`: the generator's `Dependencies:` step for a new module, `Wire dependency` for an existing one, and the `Handler:` pick for an endpoint (its generator is added automatically). Don't add constructor parameters or wire entries by hand, and don't reorder or remove the ones `df-scaffold` added.
|
|
83
125
|
|
|
84
|
-
- List each module's dependencies in
|
|
126
|
+
- List each module's dependencies in its plan row's Details (`deps: OrderRepository`); for an existing module, add a `wire dependency` row.
|
|
85
127
|
- A dependency the CLI doesn't offer is forbidden by the project's dependency rules (the defaults, changed by `backend.rules.dependencies` in the config) or by context isolation: change the design (a port, a query or command, an infrastructure service) instead of adding it by hand.
|
|
86
128
|
- A value that isn't a wired module (a database or SDK client, a config value) lives in an infrastructure service named after the implementation label (`prisma`, `in-memory-db`, `stripe`): the service creates or reads it itself (`readonly client = new PrismaClient()`), with no constructor parameter for it. Implementations get the service through `df-scaffold`, where it shows up under `Suggested`. Wrap the service's wire in `memoWire(...)` when one instance must be shared (a connection pool, an in-memory store). No `wireValue(...)`. A domain or application module never gets such a value directly: it depends on a port whose adapter uses the service.
|
|
87
129
|
- An endpoint generated with `handler: never` gets its handler by re-running the endpoint generator once the handler exists, as an approved overwrite.
|
|
@@ -143,9 +185,9 @@ node scripts/drive.mjs "pick:Bounded Context: sales" pick:Domain "pick:New Aggre
|
|
|
143
185
|
|
|
144
186
|
Implementation-type menus contain saved names and active system choices, without automatic `api` or `mock` presets. Use `pick:prisma` only when saved for that category, `"pick:System: cross-context"` for a port with a neighboring context, or `"pick:System: in-memory"` for a repository/command/query with the shared DB integration ready. New ordinary names take two steps: `"pick:Enter implementation type and save for future use" text:redis` or `"pick:Enter implementation type for this run only" text:redis`. Use the complete manual-entry label to distinguish saving from run-only input. `default` accepts the selected choice.
|
|
145
187
|
|
|
146
|
-
Custom types entered with the save action update `backend.implementations` in `domain-first.project-structure.config.json`;
|
|
188
|
+
Custom types entered with the save action update `backend.implementations` in `domain-first.project-structure.config.json`; mark the type `(saved)` in the plan row's Details. The run-only action generates code without adding saved choices. These generator-managed choice updates are allowed; project/backend/frontend setup remains a human task. Changes are staged with the generated code and cancelled with it. Repository, command, query and port choices are independent; read that category's saved `primary`/`test` lists before preparing answers.
|
|
147
189
|
|
|
148
|
-
Check every run: exit code 0, no `WARNING`/`ABORTED`, and exactly the planned
|
|
190
|
+
Check every run: exit code 0, no `WARNING`/`ABORTED`, and exactly the files its unit file lists for the planned options. "Still waiting for input" means too few steps; nothing was written. If the raw output ends at `Overwrite them?`, the run would replace files the plan's Overwrites didn't list: show the user the listed files and ask, never just add `yes`. If prompts get out of sync, retry with `--delay 1200`.
|
|
149
191
|
|
|
150
192
|
## Menu map
|
|
151
193
|
|
|
@@ -116,7 +116,7 @@ The owner configures frontend first. React and Next.js use the same operations.
|
|
|
116
116
|
| `widget` | `name` | Nested names allowed. `widgetType`: `separated` (default), `headless`, `monolithic`; use the JSON value `separated`, not the menu label `with separated ui`. |
|
|
117
117
|
| `ui-kit-component` | `name` | Single kebab-case name; stories follow config. |
|
|
118
118
|
| `shared-hook` | `name` | Single kebab-case name, preferably without `use-`; a leading `use-` is stripped. |
|
|
119
|
-
| `move-page` | `module`, `name` | `module` is the existing nested page name from discovery; `name` is the target nested name. With Next.js
|
|
119
|
+
| `move-page` | `module`, `name` | `module` is the existing nested page name from discovery; `name` is the target nested name. With Next.js and a route at the page path that renders the page, `moveRoute` (default true) moves that route folder's own files to the new path, changing the URL; `false` keeps the route with its import updated. Omit `moveRoute` when there is no such route. |
|
|
120
120
|
| `move-widget` | `module`, `name` | Same for widgets. Files, imports, code names and generated story titles follow the move. |
|
|
121
121
|
|
|
122
122
|
All support `dryRun` and `overwrite`. Use CLI moves even for a rename or folder regrouping; an existing target or a move into itself is rejected.
|
|
@@ -25,4 +25,4 @@ The same controller, path, and method replace the existing endpoint (after `Over
|
|
|
25
25
|
4. Complete `get handle()`: pick the generating getter that fits the endpoint (`this.endpointGenerator.withoutGuards(...)`, or one with the needed guards), then `.input(...)`, `.mapInput(...)`, optional `.output(...)`, `.mapOutput(...)`.
|
|
26
26
|
5. Register `restHandlers` from `<rootFolder>/presentation/rest/index.ts` in the server bootstrap (`df-ps-scaffold` `SKILL.md`, rule 2, exception 5). With the Next adapter and wire, `app/api/[...path]/route.ts` (or `src/app/…`) already serves them through `nextEndpoints(restHandlers)`; it compiles once the first endpoint exists.
|
|
27
27
|
|
|
28
|
-
After new endpoints, regenerate the OpenAPI document and the API client with the project's scripts (
|
|
28
|
+
After new endpoints, regenerate the OpenAPI document and the API client with the project's scripts (Running in the plan).
|
|
@@ -12,9 +12,9 @@ Prompts: `Module:` (select, grouped by kind; entities and value objects of an ag
|
|
|
12
12
|
|
|
13
13
|
Every file of the module moves (contract, implementations, wire, specs; an aggregate with its whole folder), every import of it follows, and derived names change in the module and its importers: `OrderRepository`, `PrismaOrderRepository`, `wireOrderRepository`, dependents' `orderRepository` parameters, an aggregate's in-memory DB section. An entity leaving its aggregate is no longer re-exported there; its importers import its file.
|
|
14
14
|
|
|
15
|
-
Before `Apply?` the CLI lists the files to move and to update: check
|
|
15
|
+
Before `Apply?` the CLI lists the files to move and to update: check that they are the module's files and its importers. A move that would introduce a forbidden context import prints `Nothing was moved: these imports would cross a bounded context boundary.` with the imports: nothing changed. Fix the design instead (`../choosing-components.md`, step 9: the consuming context gets a port with a cross-context adapter), or move the dependency first.
|
|
16
16
|
|
|
17
|
-
In the plan,
|
|
17
|
+
In the plan, a move is a row of the owner it leaves: Type `move`, Name `old → new`, Details what else changes (`to billing`, `into aggregate order`, `out of aggregate order`).
|
|
18
18
|
|
|
19
19
|
## Implement
|
|
20
20
|
|