@domain-first/project-structure 8.3.0 → 8.5.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 -4
- package/dist/287.js +118 -30
- package/dist/38.js +23 -11
- package/dist/561.js +59 -33
- package/dist/870.js +2 -1
- package/dist/agent-cli.d.ts +24 -2
- package/dist/agent-requests.d.ts +44 -0
- package/dist/config-file.d.ts +4 -1
- package/dist/graph.cjs +2 -1
- package/dist/index.cjs +148 -33
- package/dist/init.cjs +2 -1
- package/dist/integration.cjs +177 -62
- package/dist/lint.cjs +27 -13
- package/dist/lint.js +2 -1
- package/dist/react-module-move.d.ts +26 -3
- package/dist/react.cjs +190 -63
- package/dist/react.js +13 -1
- package/dist/upgrade-steps.d.ts +1 -1
- package/dist/upgrade.cjs +2 -1
- package/package.json +1 -1
- package/skills/df-ps-implement/SKILL.md +2 -1
- package/skills/df-ps-react/SKILL.md +4 -4
- package/skills/df-ps-react/references/generators.md +4 -0
- package/skills/df-ps-scaffold/SKILL.md +1 -1
- package/skills/df-ps-scaffold/references/agent-operations.md +4 -0
- package/skills/df-ps-scaffold/references/choosing-components.md +2 -1
- package/skills/df-ps-scaffold/references/units/port.md +2 -2
package/dist/integration.cjs
CHANGED
|
@@ -369,7 +369,8 @@ const lintChecks = [
|
|
|
369
369
|
'layers',
|
|
370
370
|
'dependencies',
|
|
371
371
|
'react',
|
|
372
|
-
'clock'
|
|
372
|
+
'clock',
|
|
373
|
+
'config'
|
|
373
374
|
];
|
|
374
375
|
const config_file_configFileName = 'domain-first.project-structure.config.json';
|
|
375
376
|
const projectConfigSchema = external_zod_default().object({
|
|
@@ -3127,68 +3128,68 @@ const named = {
|
|
|
3127
3128
|
...agent_requests_owner,
|
|
3128
3129
|
name: agent_requests_name
|
|
3129
3130
|
};
|
|
3130
|
-
const
|
|
3131
|
+
const agent_requests_operation = (value, shape)=>external_zod_default().strictObject({
|
|
3131
3132
|
operation: external_zod_default().literal(value),
|
|
3132
3133
|
...shape
|
|
3133
3134
|
});
|
|
3134
3135
|
const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operation', [
|
|
3135
|
-
|
|
3136
|
+
agent_requests_operation('bounded-context', {
|
|
3136
3137
|
...common,
|
|
3137
3138
|
name: agent_requests_name.refine((value)=>'shared-kernel' !== value, 'shared-kernel is reserved for the Shared Kernel.')
|
|
3138
3139
|
}),
|
|
3139
|
-
|
|
3140
|
+
agent_requests_operation('aggregate', {
|
|
3140
3141
|
...named,
|
|
3141
3142
|
withRepository: external_zod_default().boolean().optional(),
|
|
3142
3143
|
implementation: agent_requests_implementation.optional(),
|
|
3143
3144
|
testImplementation: agent_requests_implementation.optional(),
|
|
3144
3145
|
...agent_requests_wired
|
|
3145
3146
|
}),
|
|
3146
|
-
|
|
3147
|
+
agent_requests_operation('entity', {
|
|
3147
3148
|
...named,
|
|
3148
3149
|
aggregate: agent_requests_name.optional()
|
|
3149
3150
|
}),
|
|
3150
|
-
|
|
3151
|
+
agent_requests_operation('value-object', {
|
|
3151
3152
|
...named,
|
|
3152
3153
|
aggregate: agent_requests_name.optional()
|
|
3153
3154
|
}),
|
|
3154
|
-
|
|
3155
|
+
agent_requests_operation('error', {
|
|
3155
3156
|
...named,
|
|
3156
3157
|
namespace: agent_requests_name.optional()
|
|
3157
3158
|
}),
|
|
3158
|
-
|
|
3159
|
-
|
|
3159
|
+
agent_requests_operation('error-namespace', named),
|
|
3160
|
+
agent_requests_operation('domain-service', {
|
|
3160
3161
|
...named,
|
|
3161
3162
|
...agent_requests_wired
|
|
3162
3163
|
}),
|
|
3163
|
-
|
|
3164
|
+
agent_requests_operation('application-service', {
|
|
3164
3165
|
...named,
|
|
3165
3166
|
...agent_requests_wired
|
|
3166
3167
|
}),
|
|
3167
|
-
|
|
3168
|
+
agent_requests_operation('infrastructure-service', {
|
|
3168
3169
|
...named,
|
|
3169
3170
|
...agent_requests_wired
|
|
3170
3171
|
}),
|
|
3171
|
-
|
|
3172
|
+
agent_requests_operation('presentation-service', {
|
|
3172
3173
|
...named,
|
|
3173
3174
|
...agent_requests_wired
|
|
3174
3175
|
}),
|
|
3175
|
-
|
|
3176
|
+
agent_requests_operation('use-case', {
|
|
3176
3177
|
...named,
|
|
3177
3178
|
...agent_requests_wired
|
|
3178
3179
|
}),
|
|
3179
|
-
|
|
3180
|
+
agent_requests_operation('command', {
|
|
3180
3181
|
...named,
|
|
3181
3182
|
...agent_requests_implementations
|
|
3182
3183
|
}),
|
|
3183
|
-
|
|
3184
|
+
agent_requests_operation('query', {
|
|
3184
3185
|
...named,
|
|
3185
3186
|
...agent_requests_implementations
|
|
3186
3187
|
}),
|
|
3187
|
-
|
|
3188
|
+
agent_requests_operation('port', {
|
|
3188
3189
|
...named,
|
|
3189
3190
|
...agent_requests_implementations
|
|
3190
3191
|
}),
|
|
3191
|
-
|
|
3192
|
+
agent_requests_operation('implementation', {
|
|
3192
3193
|
...common,
|
|
3193
3194
|
...agent_requests_owner,
|
|
3194
3195
|
contract: agent_requests_id.describe('Exact contract ID from --describe.'),
|
|
@@ -3196,7 +3197,7 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
|
|
|
3196
3197
|
environments: external_zod_default().array(agent_requests_name).min(1).optional().describe('Required when the contract wire is envBranchedWire; omit it otherwise.'),
|
|
3197
3198
|
...agent_requests_wired
|
|
3198
3199
|
}),
|
|
3199
|
-
|
|
3200
|
+
agent_requests_operation('endpoint', {
|
|
3200
3201
|
...common,
|
|
3201
3202
|
...agent_requests_owner,
|
|
3202
3203
|
controller: agent_requests_name,
|
|
@@ -3210,18 +3211,18 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
|
|
|
3210
3211
|
path: external_zod_default().string().regex(/^(?:\/?(?:[a-zA-Z0-9_-]+|:[a-zA-Z][a-zA-Z0-9_]*))*\/?$/),
|
|
3211
3212
|
handler: agent_requests_id.optional().describe('Exact handler module ID from --describe. Required when the context has wired queries, commands or use cases; omit it otherwise.')
|
|
3212
3213
|
}),
|
|
3213
|
-
|
|
3214
|
+
agent_requests_operation('wire-dependency', {
|
|
3214
3215
|
...common,
|
|
3215
3216
|
...agent_requests_owner,
|
|
3216
3217
|
module: agent_requests_id.describe('Exact wiring target ID, including implementation class, from --describe.'),
|
|
3217
3218
|
dependencies: agent_requests_dependencies
|
|
3218
3219
|
}),
|
|
3219
|
-
|
|
3220
|
+
agent_requests_operation('delete', {
|
|
3220
3221
|
...common,
|
|
3221
3222
|
...agent_requests_owner,
|
|
3222
3223
|
module: agent_requests_id.describe('Exact unit ID from --describe. Refused while other files use it.')
|
|
3223
3224
|
}),
|
|
3224
|
-
|
|
3225
|
+
agent_requests_operation('move', {
|
|
3225
3226
|
...common,
|
|
3226
3227
|
...agent_requests_owner,
|
|
3227
3228
|
module: agent_requests_id.describe('Exact unit ID from --describe.'),
|
|
@@ -3231,11 +3232,11 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
|
|
|
3231
3232
|
})
|
|
3232
3233
|
]);
|
|
3233
3234
|
const reactRequestSchema = external_zod_default().discriminatedUnion('operation', [
|
|
3234
|
-
|
|
3235
|
+
agent_requests_operation('page', {
|
|
3235
3236
|
...common,
|
|
3236
3237
|
name: agent_requests_nestedName
|
|
3237
3238
|
}),
|
|
3238
|
-
|
|
3239
|
+
agent_requests_operation('widget', {
|
|
3239
3240
|
...common,
|
|
3240
3241
|
name: agent_requests_nestedName,
|
|
3241
3242
|
widgetType: external_zod_default()["enum"]([
|
|
@@ -3244,37 +3245,55 @@ const reactRequestSchema = external_zod_default().discriminatedUnion('operation'
|
|
|
3244
3245
|
'headless'
|
|
3245
3246
|
]).optional()
|
|
3246
3247
|
}),
|
|
3247
|
-
|
|
3248
|
+
agent_requests_operation('ui-kit-component', {
|
|
3248
3249
|
...common,
|
|
3249
3250
|
name: agent_requests_name
|
|
3250
3251
|
}),
|
|
3251
|
-
|
|
3252
|
+
agent_requests_operation('shared-hook', {
|
|
3252
3253
|
...common,
|
|
3253
3254
|
name: agent_requests_name
|
|
3254
3255
|
}),
|
|
3255
|
-
|
|
3256
|
+
agent_requests_operation('move-page', {
|
|
3256
3257
|
...common,
|
|
3257
3258
|
module: agent_requests_nestedName,
|
|
3258
3259
|
name: agent_requests_nestedName,
|
|
3259
3260
|
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.')
|
|
3260
3261
|
}),
|
|
3261
|
-
|
|
3262
|
+
agent_requests_operation('delete-page', {
|
|
3262
3263
|
...common,
|
|
3263
3264
|
module: agent_requests_nestedName,
|
|
3264
3265
|
deleteRoute: external_zod_default().boolean().optional().describe("With Next.js and the page's own route: delete it too (default true). Omit it without such a route.")
|
|
3265
3266
|
}),
|
|
3266
|
-
|
|
3267
|
+
agent_requests_operation('delete-widget', {
|
|
3267
3268
|
...common,
|
|
3268
3269
|
module: agent_requests_nestedName
|
|
3269
3270
|
}),
|
|
3270
|
-
|
|
3271
|
+
agent_requests_operation('move-ui-kit-component', {
|
|
3272
|
+
...common,
|
|
3273
|
+
module: agent_requests_name,
|
|
3274
|
+
name: agent_requests_name
|
|
3275
|
+
}),
|
|
3276
|
+
agent_requests_operation('move-shared-hook', {
|
|
3277
|
+
...common,
|
|
3278
|
+
module: agent_requests_name,
|
|
3279
|
+
name: agent_requests_name
|
|
3280
|
+
}),
|
|
3281
|
+
agent_requests_operation('delete-ui-kit-component', {
|
|
3282
|
+
...common,
|
|
3283
|
+
module: agent_requests_name
|
|
3284
|
+
}),
|
|
3285
|
+
agent_requests_operation('delete-shared-hook', {
|
|
3286
|
+
...common,
|
|
3287
|
+
module: agent_requests_name
|
|
3288
|
+
}),
|
|
3289
|
+
agent_requests_operation('move-widget', {
|
|
3271
3290
|
...common,
|
|
3272
3291
|
module: agent_requests_nestedName,
|
|
3273
3292
|
name: agent_requests_nestedName
|
|
3274
3293
|
})
|
|
3275
3294
|
]);
|
|
3276
3295
|
const agent_requests_relativePath = external_zod_default().string().regex(/^[a-zA-Z0-9_.-]+(?:\/[a-zA-Z0-9_.-]+)*$/).refine((value)=>!value.split('/').some((part)=>'.' === part || '..' === part), 'Use a project-relative path without . or .. segments.');
|
|
3277
|
-
const integrationRequestSchema =
|
|
3296
|
+
const integrationRequestSchema = agent_requests_operation('add', {
|
|
3278
3297
|
...common,
|
|
3279
3298
|
integrations: external_zod_default().array(external_zod_default()["enum"](integrationIds)).min(1),
|
|
3280
3299
|
nextAdapter: external_zod_default().boolean().optional(),
|
|
@@ -3972,6 +3991,66 @@ const inMemoryRepositoryWiring = (ownerFolder, unit, wireFile)=>(implementation,
|
|
|
3972
3991
|
wireInMemoryDb(wireFile, implementation.className);
|
|
3973
3992
|
return true;
|
|
3974
3993
|
};
|
|
3994
|
+
const reactKindLayouts = {
|
|
3995
|
+
page: {
|
|
3996
|
+
folder: 'pages',
|
|
3997
|
+
nested: true,
|
|
3998
|
+
inFolder: false,
|
|
3999
|
+
ownFile: (fileBase)=>new RegExp(`^${escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
4000
|
+
target: (reactFolder, { folders, fileName })=>external_node_path_default().join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`),
|
|
4001
|
+
classPrefix: '(use)?',
|
|
4002
|
+
classSuffix: 'Page'
|
|
4003
|
+
},
|
|
4004
|
+
widget: {
|
|
4005
|
+
folder: 'widgets',
|
|
4006
|
+
nested: true,
|
|
4007
|
+
inFolder: true,
|
|
4008
|
+
target: (reactFolder, { folders, folderName })=>external_node_path_default().join(reactFolder, 'widgets', ...folders, folderName),
|
|
4009
|
+
classPrefix: '(use)?',
|
|
4010
|
+
classSuffix: 'Widget|UIModel',
|
|
4011
|
+
storyTitle: (segments)=>[
|
|
4012
|
+
'Widgets',
|
|
4013
|
+
...segments
|
|
4014
|
+
].join('/')
|
|
4015
|
+
},
|
|
4016
|
+
'ui-kit': {
|
|
4017
|
+
folder: 'ui-kit',
|
|
4018
|
+
nested: false,
|
|
4019
|
+
inFolder: true,
|
|
4020
|
+
target: (reactFolder, { fileName })=>external_node_path_default().join(reactFolder, 'ui-kit', fileName),
|
|
4021
|
+
classPrefix: '()',
|
|
4022
|
+
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
4023
|
+
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
4024
|
+
},
|
|
4025
|
+
hook: {
|
|
4026
|
+
folder: 'hooks',
|
|
4027
|
+
nested: false,
|
|
4028
|
+
inFolder: false,
|
|
4029
|
+
ownFile: (fileBase)=>new RegExp(`^use-${escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
4030
|
+
target: (reactFolder, { fileName })=>external_node_path_default().join(reactFolder, 'hooks', `use-${fileName}.ts`),
|
|
4031
|
+
classPrefix: '(use)',
|
|
4032
|
+
classSuffix: '(?![\\w$])'
|
|
4033
|
+
}
|
|
4034
|
+
};
|
|
4035
|
+
const reactKindTitles = {
|
|
4036
|
+
page: [
|
|
4037
|
+
'Page',
|
|
4038
|
+
'pages'
|
|
4039
|
+
],
|
|
4040
|
+
widget: [
|
|
4041
|
+
'Widget',
|
|
4042
|
+
'widgets'
|
|
4043
|
+
],
|
|
4044
|
+
'ui-kit': [
|
|
4045
|
+
'UI-kit component',
|
|
4046
|
+
'UI-kit components'
|
|
4047
|
+
],
|
|
4048
|
+
hook: [
|
|
4049
|
+
'Shared hook',
|
|
4050
|
+
'shared hooks'
|
|
4051
|
+
]
|
|
4052
|
+
};
|
|
4053
|
+
const reactModuleName = (kind, rawName)=>'hook' === kind ? rawName.trim().replace(/^use-/, '') : rawName;
|
|
3975
4054
|
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
3976
4055
|
const prefix = `${folders.join('-')}-`;
|
|
3977
4056
|
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
@@ -3985,8 +4064,36 @@ const declaredClassName = (filePath, suffix, name)=>{
|
|
|
3985
4064
|
const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
3986
4065
|
return declared ?? new NestedName(name).ClassName;
|
|
3987
4066
|
};
|
|
4067
|
+
const findUiKit = (reactFolder)=>{
|
|
4068
|
+
const root = external_node_path_default().join(reactFolder, 'ui-kit');
|
|
4069
|
+
if (!external_node_fs_default().existsSync(root)) return [];
|
|
4070
|
+
return external_node_fs_default().readdirSync(root, {
|
|
4071
|
+
withFileTypes: true
|
|
4072
|
+
}).filter((entry)=>entry.isDirectory() && external_node_fs_default().existsSync(external_node_path_default().join(root, entry.name, `${entry.name}.tsx`))).map(({ name })=>({
|
|
4073
|
+
kind: 'ui-kit',
|
|
4074
|
+
name,
|
|
4075
|
+
path: external_node_path_default().join(root, name),
|
|
4076
|
+
fileBase: name,
|
|
4077
|
+
ClassName: declaredClassName(external_node_path_default().join(root, name, `${name}.tsx`), '', name)
|
|
4078
|
+
}));
|
|
4079
|
+
};
|
|
4080
|
+
const findHooks = (reactFolder)=>{
|
|
4081
|
+
const root = external_node_path_default().join(reactFolder, 'hooks');
|
|
4082
|
+
if (!external_node_fs_default().existsSync(root)) return [];
|
|
4083
|
+
return external_node_fs_default().readdirSync(root).filter((file)=>/^use-.+\.tsx?$/.test(file) && !/\.(spec|test)\./.test(file)).map((file)=>{
|
|
4084
|
+
const name = file.replace(/^use-/, '').replace(/\.tsx?$/, '');
|
|
4085
|
+
const content = external_node_fs_default().readFileSync(external_node_path_default().join(root, file), 'utf8');
|
|
4086
|
+
return {
|
|
4087
|
+
kind: 'hook',
|
|
4088
|
+
name,
|
|
4089
|
+
path: external_node_path_default().join(root, file),
|
|
4090
|
+
fileBase: name,
|
|
4091
|
+
ClassName: content.match(/export\s+(?:const|function)\s+use(\w+)\b/)?.[1] ?? new NestedName(name).ClassName
|
|
4092
|
+
};
|
|
4093
|
+
});
|
|
4094
|
+
};
|
|
3988
4095
|
const findReactModules = (reactFolder, kind)=>{
|
|
3989
|
-
const modules = 'page' === kind ? module_move_walk(external_node_path_default().join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
4096
|
+
const modules = 'ui-kit' === kind ? findUiKit(reactFolder) : 'hook' === kind ? findHooks(reactFolder) : 'page' === kind ? module_move_walk(external_node_path_default().join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
3990
4097
|
const folders = external_node_path_default().relative(external_node_path_default().join(reactFolder, 'pages'), external_node_path_default().dirname(file)).split(external_node_path_default().sep).filter((segment)=>!!segment);
|
|
3991
4098
|
const fileBase = external_node_path_default().basename(file, '-page.tsx');
|
|
3992
4099
|
const name = react_module_move_nestedName(folders, fileBase);
|
|
@@ -4010,13 +4117,11 @@ const findReactModules = (reactFolder, kind)=>{
|
|
|
4010
4117
|
});
|
|
4011
4118
|
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
4012
4119
|
};
|
|
4013
|
-
const react_module_move_targetPath = (reactFolder, module, rawName)=>
|
|
4014
|
-
const { folders, folderName, fileName } = new NestedName(rawName);
|
|
4015
|
-
return 'page' === module.kind ? external_node_path_default().join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`) : external_node_path_default().join(reactFolder, 'widgets', ...folders, folderName);
|
|
4016
|
-
};
|
|
4120
|
+
const react_module_move_targetPath = (reactFolder, module, rawName)=>reactKindLayouts[module.kind].target(reactFolder, new NestedName(reactModuleName(module.kind, rawName)));
|
|
4017
4121
|
const validateMove = (reactFolder, module, rawName)=>{
|
|
4018
4122
|
const nameError = NestedName.validate(rawName);
|
|
4019
4123
|
if (true !== nameError) return nameError;
|
|
4124
|
+
if (!reactKindLayouts[module.kind].nested && /[\\/]/.test(rawName)) return 'UI-kit components and shared hooks have no folders: enter a name without "/"';
|
|
4020
4125
|
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
4021
4126
|
if (target !== module.path && external_node_fs_default().existsSync(target)) return `${external_node_path_default().relative(reactFolder, target)} already exists`;
|
|
4022
4127
|
if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
|
|
@@ -4030,13 +4135,14 @@ const routeFiles = (folder)=>external_node_fs_default().existsSync(folder) ? ext
|
|
|
4030
4135
|
withFileTypes: true
|
|
4031
4136
|
}).filter((entry)=>entry.isFile()).map((entry)=>external_node_path_default().join(folder, entry.name)) : [];
|
|
4032
4137
|
const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
4033
|
-
const
|
|
4138
|
+
const layout = reactKindLayouts[module.kind];
|
|
4139
|
+
const newName = new NestedName(reactModuleName(module.kind, rawName));
|
|
4034
4140
|
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
4035
4141
|
const newClassName = newName.ClassName;
|
|
4036
|
-
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.])`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
4037
|
-
const oldFolder =
|
|
4038
|
-
const newFolder =
|
|
4039
|
-
const ownsPath = (candidate)=>
|
|
4142
|
+
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.]|$)`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
4143
|
+
const oldFolder = layout.inFolder ? module.path : external_node_path_default().dirname(module.path);
|
|
4144
|
+
const newFolder = layout.inFolder ? target : external_node_path_default().dirname(target);
|
|
4145
|
+
const ownsPath = (candidate)=>layout.inFolder ? candidate === oldFolder || candidate.startsWith(`${oldFolder}${external_node_path_default().sep}`) : external_node_path_default().dirname(candidate) === oldFolder && layout.ownFile(module.fileBase).test(external_node_path_default().basename(candidate));
|
|
4040
4146
|
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
4041
4147
|
const routeTarget = (candidate)=>{
|
|
4042
4148
|
if (!route) return;
|
|
@@ -4056,7 +4162,7 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
|
4056
4162
|
segments[last] = renameFile(segments[last]);
|
|
4057
4163
|
return external_node_path_default().join(newFolder, ...segments);
|
|
4058
4164
|
};
|
|
4059
|
-
const moduleFiles =
|
|
4165
|
+
const moduleFiles = reactModuleFiles(module);
|
|
4060
4166
|
const moves = new Map([
|
|
4061
4167
|
...moduleFiles,
|
|
4062
4168
|
...routeFileSet
|
|
@@ -4064,14 +4170,14 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
|
4064
4170
|
file,
|
|
4065
4171
|
movedPath(file) ?? file
|
|
4066
4172
|
]));
|
|
4067
|
-
const
|
|
4068
|
-
const
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
const
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
].
|
|
4173
|
+
const classPattern = new RegExp(`(?<![\\w$])${layout.classPrefix}${escapeRegExp(module.ClassName)}(?=${layout.classSuffix})`, 'g');
|
|
4174
|
+
const oldTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
4175
|
+
module.ClassName
|
|
4176
|
+
] : module.name.split('/').map((segment)=>new NestedName(segment).ClassName));
|
|
4177
|
+
const titlePattern = oldTitle && new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
4178
|
+
const newTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
4179
|
+
newClassName
|
|
4180
|
+
] : newName.classNameSegments);
|
|
4075
4181
|
return stageModuleMove({
|
|
4076
4182
|
projectRoot,
|
|
4077
4183
|
stopAt: reactFolder,
|
|
@@ -4079,8 +4185,8 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
|
4079
4185
|
moves,
|
|
4080
4186
|
movedPath,
|
|
4081
4187
|
rename: (content, { moved })=>{
|
|
4082
|
-
const renamed = content.replace(classPattern, (_, use
|
|
4083
|
-
return moved &&
|
|
4188
|
+
const renamed = content.replace(classPattern, (_, use)=>`${use ?? ''}${newClassName}`);
|
|
4189
|
+
return moved && titlePattern ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
4084
4190
|
}
|
|
4085
4191
|
});
|
|
4086
4192
|
};
|
|
@@ -4090,9 +4196,10 @@ const pageRouteFolder = (appFolder, page)=>{
|
|
|
4090
4196
|
return external_node_fs_default().existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(external_node_fs_default().readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
4091
4197
|
};
|
|
4092
4198
|
const reactModuleFiles = (module)=>{
|
|
4093
|
-
|
|
4199
|
+
const layout = reactKindLayouts[module.kind];
|
|
4200
|
+
if (layout.inFolder) return module_move_walk(module.path);
|
|
4094
4201
|
const folder = external_node_path_default().dirname(module.path);
|
|
4095
|
-
const own =
|
|
4202
|
+
const own = layout.ownFile(module.fileBase);
|
|
4096
4203
|
return external_node_fs_default().readdirSync(folder, {
|
|
4097
4204
|
withFileTypes: true
|
|
4098
4205
|
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>external_node_path_default().join(folder, entry.name));
|
|
@@ -4106,7 +4213,7 @@ const deleteReactModule = (projectRoot, reactFolder, module, route)=>{
|
|
|
4106
4213
|
...routeFileList
|
|
4107
4214
|
]);
|
|
4108
4215
|
const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
|
|
4109
|
-
const isModule = (resolved)=>stems.has(resolved) ||
|
|
4216
|
+
const isModule = (resolved)=>stems.has(resolved) || reactKindLayouts[module.kind].inFolder && (resolved === module.path || resolved.startsWith(`${module.path}${external_node_path_default().sep}`));
|
|
4110
4217
|
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
4111
4218
|
const relative = (file)=>toPosix(external_node_path_default().relative(projectRoot, file));
|
|
4112
4219
|
const usedBy = [];
|
|
@@ -4197,11 +4304,11 @@ const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
4197
4304
|
const deleteReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
4198
4305
|
const reactFolder = presentationReactFolder.path;
|
|
4199
4306
|
const modules = findReactModules(reactFolder, kind);
|
|
4200
|
-
if (!modules.length) return void report(`No ${kind}
|
|
4307
|
+
if (!modules.length) return void report(`No ${reactKindTitles[kind][1]} generated by df-react were found.`);
|
|
4201
4308
|
const module = await interaction_select({
|
|
4202
4309
|
key: 'module',
|
|
4203
4310
|
id: (value)=>value.name,
|
|
4204
|
-
message:
|
|
4311
|
+
message: `${reactKindTitles[kind][0]} to delete:`,
|
|
4205
4312
|
choices: modules.map((value)=>({
|
|
4206
4313
|
name: value.name,
|
|
4207
4314
|
value,
|
|
@@ -4367,11 +4474,11 @@ const promptRouteMove = async (root, page, newName)=>{
|
|
|
4367
4474
|
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
4368
4475
|
const reactFolder = presentationReactFolder.path;
|
|
4369
4476
|
const modules = findReactModules(reactFolder, kind);
|
|
4370
|
-
if (!modules.length) return void report(`No ${kind}
|
|
4477
|
+
if (!modules.length) return void report(`No ${reactKindTitles[kind][1]} generated by df-react were found.`);
|
|
4371
4478
|
const module = await interaction_select({
|
|
4372
4479
|
key: 'module',
|
|
4373
4480
|
id: (value)=>value.name,
|
|
4374
|
-
message:
|
|
4481
|
+
message: `${reactKindTitles[kind][0]}:`,
|
|
4375
4482
|
choices: modules.map((value)=>({
|
|
4376
4483
|
name: value.name,
|
|
4377
4484
|
value,
|
|
@@ -4380,7 +4487,7 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
4380
4487
|
});
|
|
4381
4488
|
const name = await interaction_input({
|
|
4382
4489
|
key: 'name',
|
|
4383
|
-
message: 'New name (folders split by "/"):',
|
|
4490
|
+
message: reactKindLayouts[kind].nested ? 'New name (folders split by "/"):' : 'New name:',
|
|
4384
4491
|
default: module.name,
|
|
4385
4492
|
validate: (value)=>validateMove(reactFolder, module, value)
|
|
4386
4493
|
});
|
|
@@ -5736,7 +5843,9 @@ const describeAgentCommand = (command)=>{
|
|
|
5736
5843
|
integrations: integrationDescriptionsSafe(configured),
|
|
5737
5844
|
reactModules: config?.frontend?.react ? [
|
|
5738
5845
|
'page',
|
|
5739
|
-
'widget'
|
|
5846
|
+
'widget',
|
|
5847
|
+
'ui-kit',
|
|
5848
|
+
'hook'
|
|
5740
5849
|
].flatMap((kind)=>findReactModules(external_node_path_default().join(root, config.project.rootFolder, 'presentation/react'), kind).map((module)=>({
|
|
5741
5850
|
kind,
|
|
5742
5851
|
name: module.name,
|
|
@@ -5846,7 +5955,9 @@ const executeReact = async (request)=>{
|
|
|
5846
5955
|
config_file_ConfigFile.Instance.data.project.rootFolder,
|
|
5847
5956
|
'presentation/react'
|
|
5848
5957
|
]);
|
|
5849
|
-
|
|
5958
|
+
const kindOf = (operation)=>operation.endsWith('-page') ? 'page' : operation.endsWith('-widget') ? 'widget' : operation.endsWith('-ui-kit-component') ? 'ui-kit' : operation.endsWith('-shared-hook') ? 'hook' : void 0;
|
|
5959
|
+
const kind = /^(move|delete)-/.test(request.operation) ? kindOf(request.operation) : void 0;
|
|
5960
|
+
if (kind && !findReactModules(folder.path, kind).length) throw new RequestError('TARGET_NOT_FOUND', `No React ${reactKindTitles[kind][1]} here.`);
|
|
5850
5961
|
const actions = {
|
|
5851
5962
|
page: ()=>scaffoldReactPage(folder),
|
|
5852
5963
|
widget: ()=>scaffoldReactWidget(folder),
|
|
@@ -5855,7 +5966,11 @@ const executeReact = async (request)=>{
|
|
|
5855
5966
|
'move-page': ()=>moveReactModuleUseCase(folder, 'page'),
|
|
5856
5967
|
'move-widget': ()=>moveReactModuleUseCase(folder, 'widget'),
|
|
5857
5968
|
'delete-page': ()=>deleteReactModuleUseCase(folder, 'page'),
|
|
5858
|
-
'delete-widget': ()=>deleteReactModuleUseCase(folder, 'widget')
|
|
5969
|
+
'delete-widget': ()=>deleteReactModuleUseCase(folder, 'widget'),
|
|
5970
|
+
'move-ui-kit-component': ()=>moveReactModuleUseCase(folder, 'ui-kit'),
|
|
5971
|
+
'move-shared-hook': ()=>moveReactModuleUseCase(folder, 'hook'),
|
|
5972
|
+
'delete-ui-kit-component': ()=>deleteReactModuleUseCase(folder, 'ui-kit'),
|
|
5973
|
+
'delete-shared-hook': ()=>deleteReactModuleUseCase(folder, 'hook')
|
|
5859
5974
|
};
|
|
5860
5975
|
return actions[request.operation]();
|
|
5861
5976
|
};
|
package/dist/lint.cjs
CHANGED
|
@@ -238,7 +238,8 @@ const lintChecks = [
|
|
|
238
238
|
'layers',
|
|
239
239
|
'dependencies',
|
|
240
240
|
'react',
|
|
241
|
-
'clock'
|
|
241
|
+
'clock',
|
|
242
|
+
'config'
|
|
242
243
|
];
|
|
243
244
|
const configFileName = 'domain-first.project-structure.config.json';
|
|
244
245
|
const projectConfigSchema = external_zod_default().object({
|
|
@@ -891,7 +892,19 @@ const wiringViolations = (projectRoot, rootFolder, rules)=>{
|
|
|
891
892
|
}
|
|
892
893
|
return violations;
|
|
893
894
|
};
|
|
894
|
-
const
|
|
895
|
+
const directReadChecks = [
|
|
896
|
+
{
|
|
897
|
+
check: 'clock',
|
|
898
|
+
pattern: /\bnew\s+Date\s*\(\s*\)|\bDate\.now\s*\(/g,
|
|
899
|
+
rule: 'domain or application reads the current time directly (use the clock port):'
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
check: 'config',
|
|
903
|
+
pattern: /\bprocess\s*\??\.\s*env\b|\bprocess\s*\[\s*(['"`])env\1\s*\]|\bimport\.meta\.env\b/g,
|
|
904
|
+
rule: 'domain or application reads environment variables directly (use the config port):'
|
|
905
|
+
}
|
|
906
|
+
];
|
|
907
|
+
const directReadViolations = (projectRoot, rootFolder)=>{
|
|
895
908
|
const root = external_node_path_default().resolve(projectRoot, rootFolder);
|
|
896
909
|
const folders = [
|
|
897
910
|
external_node_path_default().join(root, 'shared-kernel'),
|
|
@@ -902,21 +915,21 @@ const clockViolations = (projectRoot, rootFolder)=>{
|
|
|
902
915
|
]);
|
|
903
916
|
return folders.flatMap(sourceFiles).filter((file)=>!isSpec(file)).flatMap((file)=>{
|
|
904
917
|
const source = external_node_fs_default().readFileSync(file, 'utf8');
|
|
905
|
-
return [
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
918
|
+
return directReadChecks.flatMap(({ check, pattern, rule })=>[
|
|
919
|
+
...source.matchAll(pattern)
|
|
920
|
+
].map((match)=>({
|
|
921
|
+
check,
|
|
922
|
+
rule,
|
|
923
|
+
file,
|
|
924
|
+
line: lineAt(source, match.index),
|
|
925
|
+
text: match[0]
|
|
926
|
+
})));
|
|
914
927
|
});
|
|
915
928
|
};
|
|
916
929
|
const lintProject = (projectRoot, rootFolder, { rules = defaultDependencyRules, checks = {} } = {})=>[
|
|
917
930
|
...importViolations(projectRoot, rootFolder, rules),
|
|
918
931
|
...wiringViolations(projectRoot, rootFolder, rules),
|
|
919
|
-
...
|
|
932
|
+
...directReadViolations(projectRoot, rootFolder)
|
|
920
933
|
].filter((x)=>false !== checks[x.check]);
|
|
921
934
|
const formatViolations = (violations, projectRoot)=>{
|
|
922
935
|
const groups = new Map();
|
|
@@ -935,7 +948,8 @@ const help = `Usage: df-lint [rootFolder]
|
|
|
935
948
|
|
|
936
949
|
Reports what breaks the Domain-First rules in the project:
|
|
937
950
|
bounded context isolation, layers, dependency rules (imports and wiring),
|
|
938
|
-
React modules, and reading the time
|
|
951
|
+
React modules, and reading the time or environment variables without
|
|
952
|
+
the clock and config ports.
|
|
939
953
|
rootFolder defaults to the one in domain-first.project-structure.config.json,
|
|
940
954
|
whose optional \`backend.rules\` change the dependency rules and turn checks off.
|
|
941
955
|
Exits with 1 when something is found.
|
package/dist/lint.js
CHANGED
|
@@ -6,7 +6,8 @@ const help = `Usage: df-lint [rootFolder]
|
|
|
6
6
|
|
|
7
7
|
Reports what breaks the Domain-First rules in the project:
|
|
8
8
|
bounded context isolation, layers, dependency rules (imports and wiring),
|
|
9
|
-
React modules, and reading the time
|
|
9
|
+
React modules, and reading the time or environment variables without
|
|
10
|
+
the clock and config ports.
|
|
10
11
|
rootFolder defaults to the one in domain-first.project-structure.config.json,
|
|
11
12
|
whose optional \`backend.rules\` change the dependency rules and turn checks off.
|
|
12
13
|
Exits with 1 when something is found.
|
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import { type MovePlan } from './module-move';
|
|
2
|
+
import { NestedName } from './nested-name';
|
|
2
3
|
export type { MovePlan } from './module-move';
|
|
3
|
-
export type ReactModuleKind = 'page' | 'widget';
|
|
4
|
+
export type ReactModuleKind = 'page' | 'widget' | 'ui-kit' | 'hook';
|
|
4
5
|
export type ReactModule = {
|
|
5
6
|
kind: ReactModuleKind;
|
|
6
|
-
/**
|
|
7
|
+
/** Name, nested for pages and widgets, e.g. `admin/users`. */
|
|
7
8
|
name: string;
|
|
8
|
-
/** The page file
|
|
9
|
+
/** The page or hook file; the widget or UI-kit folder. */
|
|
9
10
|
path: string;
|
|
10
11
|
/** The name part of file names, e.g. `admin-users` in `admin-users-page.tsx`. */
|
|
11
12
|
fileBase: string;
|
|
12
13
|
ClassName: string;
|
|
13
14
|
};
|
|
15
|
+
type ReactKindLayout = {
|
|
16
|
+
/** Folder under `presentation/react`. */
|
|
17
|
+
folder: string;
|
|
18
|
+
/** Names may contain folders (`admin/users`). */
|
|
19
|
+
nested: boolean;
|
|
20
|
+
/** The module is a folder (widget, UI-kit) rather than files. */
|
|
21
|
+
inFolder: boolean;
|
|
22
|
+
/** For file modules: the files of a module, by file base. */
|
|
23
|
+
ownFile?: (fileBase: string) => RegExp;
|
|
24
|
+
/** Where a module of this name lives. */
|
|
25
|
+
target: (reactFolder: string, name: NestedName) => string;
|
|
26
|
+
/** Code names: a prefix group and what follows the class name. */
|
|
27
|
+
classPrefix: string;
|
|
28
|
+
classSuffix: string;
|
|
29
|
+
/** Generated story title, followed by renames. */
|
|
30
|
+
storyTitle?: (segments: string[]) => string;
|
|
31
|
+
};
|
|
32
|
+
export declare const reactKindLayouts: Record<ReactModuleKind, ReactKindLayout>;
|
|
33
|
+
/** How menus name each kind, singular and plural. */
|
|
34
|
+
export declare const reactKindTitles: Record<ReactModuleKind, [string, string]>;
|
|
35
|
+
/** A hook's name is entered without `use-`, as its generator takes it. */
|
|
36
|
+
export declare const reactModuleName: (kind: ReactModuleKind, rawName: string) => string;
|
|
14
37
|
export declare const findReactModules: (reactFolder: string, kind: ReactModuleKind) => ReactModule[];
|
|
15
38
|
export declare const validateMove: (reactFolder: string, module: ReactModule, rawName: string) => string | true;
|
|
16
39
|
/** A Next.js App Router route folder moved with a page. */
|