@domain-first/project-structure 8.11.0 → 8.12.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 +1 -1
- package/dist/287.js +36 -967
- package/dist/364.js +3 -3
- package/dist/38.js +4 -3
- package/dist/561.js +76 -67
- package/dist/783.js +1147 -0
- package/dist/{201.js → 878.js} +455 -1
- package/dist/agent-cli.d.ts +5 -5
- package/dist/agent-requests.d.ts +9 -9
- package/dist/frontend-modules.d.ts +6 -1
- package/dist/graph.cjs +115 -4
- package/dist/graph.js +1 -1
- package/dist/index.cjs +129 -71
- package/dist/index.js +1 -1
- package/dist/init.cjs +49 -6
- package/dist/init.js +1 -1
- package/dist/integration.cjs +129 -71
- package/dist/integration.js +1 -1
- package/dist/integrations/openapi.d.ts +13 -3
- package/dist/lint.cjs +121 -9
- package/dist/lint.js +1 -1
- package/dist/react-module-move.d.ts +20 -2
- package/dist/react.cjs +185 -123
- package/dist/svelte.cjs +185 -123
- package/dist/upgrade-svelte.d.ts +15 -0
- package/dist/upgrade-svelte.spec.d.ts +1 -0
- package/dist/upgrade.cjs +296 -41
- package/dist/upgrade.js +132 -13
- package/dist/use-cases/scaffold-svelte-modules.d.ts +7 -2
- package/package.json +1 -1
- package/skills/df-ps-scaffold/SKILL.md +2 -2
- package/skills/df-ps-scaffold/references/agent-operations.md +2 -2
- package/skills/df-ps-svelte/SKILL.md +14 -9
- package/skills/df-ps-svelte/references/generators.md +5 -5
- package/dist/115.js +0 -616
package/dist/{201.js → 878.js}
RENAMED
|
@@ -1041,4 +1041,458 @@ const compilerOption = (configFile, name, seen = new Set())=>{
|
|
|
1041
1041
|
if (void 0 !== value) return value;
|
|
1042
1042
|
}
|
|
1043
1043
|
};
|
|
1044
|
-
|
|
1044
|
+
const ignoredFolders = new Set([
|
|
1045
|
+
'node_modules',
|
|
1046
|
+
'.git',
|
|
1047
|
+
'.next',
|
|
1048
|
+
'.svelte-kit',
|
|
1049
|
+
'dist',
|
|
1050
|
+
'build',
|
|
1051
|
+
'out',
|
|
1052
|
+
'coverage',
|
|
1053
|
+
'storybook-static'
|
|
1054
|
+
]);
|
|
1055
|
+
const codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx|svelte)$/;
|
|
1056
|
+
const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1057
|
+
const module_move_walk = (folder)=>{
|
|
1058
|
+
if (!node_fs.existsSync(folder)) return [];
|
|
1059
|
+
return node_fs.readdirSync(folder, {
|
|
1060
|
+
withFileTypes: true
|
|
1061
|
+
}).flatMap((entry)=>{
|
|
1062
|
+
const entryPath = node_path.join(folder, entry.name);
|
|
1063
|
+
if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : module_move_walk(entryPath);
|
|
1064
|
+
return entry.isFile() ? [
|
|
1065
|
+
entryPath
|
|
1066
|
+
] : [];
|
|
1067
|
+
});
|
|
1068
|
+
};
|
|
1069
|
+
const toPosix = (value)=>value.split(node_path.sep).join('/');
|
|
1070
|
+
const readAliases = (projectRoot)=>{
|
|
1071
|
+
const tsconfig = node_path.join(projectRoot, 'tsconfig.json');
|
|
1072
|
+
if (!node_fs.existsSync(tsconfig)) return [];
|
|
1073
|
+
try {
|
|
1074
|
+
const { compilerOptions = {} } = JSON.parse(stripJsonComments(node_fs.readFileSync(tsconfig, 'utf8')));
|
|
1075
|
+
const base = node_path.resolve(projectRoot, compilerOptions.baseUrl ?? '.');
|
|
1076
|
+
return Object.entries(compilerOptions.paths ?? {}).filter(([pattern, targets])=>pattern.endsWith('*') && targets[0]?.endsWith('*')).map(([pattern, [target]])=>({
|
|
1077
|
+
prefix: pattern.slice(0, -1),
|
|
1078
|
+
target: node_path.resolve(base, target.slice(0, -1))
|
|
1079
|
+
}));
|
|
1080
|
+
} catch {
|
|
1081
|
+
return [];
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
|
|
1085
|
+
const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
|
|
1086
|
+
const importPaths = (file)=>{
|
|
1087
|
+
const withoutExtension = file.replace(codeExtension, '');
|
|
1088
|
+
return 'index' === node_path.basename(withoutExtension) ? [
|
|
1089
|
+
withoutExtension,
|
|
1090
|
+
node_path.dirname(withoutExtension)
|
|
1091
|
+
] : [
|
|
1092
|
+
withoutExtension
|
|
1093
|
+
];
|
|
1094
|
+
};
|
|
1095
|
+
const projectImports = (projectRoot)=>{
|
|
1096
|
+
const aliases = readAliases(projectRoot);
|
|
1097
|
+
const resolve = (specifier, fromFile)=>{
|
|
1098
|
+
if (specifier.startsWith('.')) return {
|
|
1099
|
+
resolved: node_path.resolve(node_path.dirname(fromFile), specifier),
|
|
1100
|
+
alias: void 0
|
|
1101
|
+
};
|
|
1102
|
+
const alias = aliases.find(({ prefix })=>specifier.startsWith(prefix));
|
|
1103
|
+
return alias ? {
|
|
1104
|
+
resolved: node_path.resolve(alias.target, specifier.slice(alias.prefix.length)),
|
|
1105
|
+
alias
|
|
1106
|
+
} : void 0;
|
|
1107
|
+
};
|
|
1108
|
+
const specifierFor = (fromFile, toPath, alias)=>{
|
|
1109
|
+
const aliased = alias && toPosix(node_path.relative(alias.target, toPath));
|
|
1110
|
+
if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
|
|
1111
|
+
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toPath));
|
|
1112
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
1113
|
+
};
|
|
1114
|
+
const codeFiles = new Map(module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
1115
|
+
file,
|
|
1116
|
+
node_fs.readFileSync(file, 'utf8')
|
|
1117
|
+
]));
|
|
1118
|
+
const importsOf = (file)=>[
|
|
1119
|
+
...(codeFiles.get(file) ?? '').matchAll(specifierPattern)
|
|
1120
|
+
].map(([, , , specifier])=>resolve(specifier, file)?.resolved).filter((resolved)=>!!resolved);
|
|
1121
|
+
return {
|
|
1122
|
+
resolve,
|
|
1123
|
+
specifierFor,
|
|
1124
|
+
codeFiles,
|
|
1125
|
+
importsOf
|
|
1126
|
+
};
|
|
1127
|
+
};
|
|
1128
|
+
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
1129
|
+
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
1130
|
+
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
1131
|
+
const barrels = new Set();
|
|
1132
|
+
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
1133
|
+
for(let found = true; found;){
|
|
1134
|
+
found = false;
|
|
1135
|
+
for (const [file, content] of codeFiles){
|
|
1136
|
+
if (moves.has(file) || isBarrel(file)) continue;
|
|
1137
|
+
const reExportsModule = [
|
|
1138
|
+
...content.matchAll(reExportPattern)
|
|
1139
|
+
].some(([, , specifier])=>{
|
|
1140
|
+
const resolution = resolve(specifier, file);
|
|
1141
|
+
return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
|
|
1142
|
+
});
|
|
1143
|
+
if (reExportsModule) {
|
|
1144
|
+
for (const importPath of importPaths(file))barrels.add(importPath);
|
|
1145
|
+
found = true;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
const rewrite = (content, oldFile, newFile)=>{
|
|
1150
|
+
let referencesModule = false;
|
|
1151
|
+
const rewritten = content.replace(specifierPattern, (match, keyword, quote, specifier)=>{
|
|
1152
|
+
const resolution = resolve(specifier, oldFile);
|
|
1153
|
+
if (!resolution) return match;
|
|
1154
|
+
const moved = movedPath(resolution.resolved);
|
|
1155
|
+
if (moved || isBarrel(resolution.resolved)) referencesModule = true;
|
|
1156
|
+
if (!moved && oldFile === newFile) return match;
|
|
1157
|
+
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
1158
|
+
return `${keyword}${quote}${next}${quote}`;
|
|
1159
|
+
});
|
|
1160
|
+
const changed = everyFile(rewritten);
|
|
1161
|
+
if (!referencesModule && !moves.has(oldFile)) return changed;
|
|
1162
|
+
return rename(changed, {
|
|
1163
|
+
moved: moves.has(oldFile)
|
|
1164
|
+
});
|
|
1165
|
+
};
|
|
1166
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile, stopFor(file));
|
|
1167
|
+
const updated = [];
|
|
1168
|
+
for (const [file, content] of codeFiles){
|
|
1169
|
+
const newFile = moves.get(file);
|
|
1170
|
+
const next = rewrite(content, file, newFile ?? file);
|
|
1171
|
+
if (newFile && newFile !== file) {
|
|
1172
|
+
new File(newFile).data = next;
|
|
1173
|
+
new File(file).delete(stopFor(file));
|
|
1174
|
+
} else if (next !== content) {
|
|
1175
|
+
new File(file).update(next);
|
|
1176
|
+
if (!newFile) updated.push(file);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
return {
|
|
1180
|
+
moves: [
|
|
1181
|
+
...moves
|
|
1182
|
+
].filter(([from, to])=>from !== to),
|
|
1183
|
+
updated
|
|
1184
|
+
};
|
|
1185
|
+
};
|
|
1186
|
+
const frontendExtensions = {
|
|
1187
|
+
react: {
|
|
1188
|
+
component: '.tsx',
|
|
1189
|
+
hook: '.ts'
|
|
1190
|
+
},
|
|
1191
|
+
svelte: {
|
|
1192
|
+
component: '.svelte',
|
|
1193
|
+
hook: '.svelte.ts'
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
const frontendLogicNaming = {
|
|
1197
|
+
react: {
|
|
1198
|
+
prefix: 'use',
|
|
1199
|
+
shared: [
|
|
1200
|
+
'hooks'
|
|
1201
|
+
],
|
|
1202
|
+
widgetModel: 'hooks'
|
|
1203
|
+
},
|
|
1204
|
+
svelte: {
|
|
1205
|
+
prefix: 'create',
|
|
1206
|
+
shared: [
|
|
1207
|
+
'shared',
|
|
1208
|
+
'model'
|
|
1209
|
+
],
|
|
1210
|
+
widgetModel: 'model'
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
const kindLayouts = (framework)=>{
|
|
1214
|
+
const { component, hook } = frontendExtensions[framework];
|
|
1215
|
+
const { prefix, shared } = frontendLogicNaming[framework];
|
|
1216
|
+
return {
|
|
1217
|
+
page: {
|
|
1218
|
+
folder: 'pages',
|
|
1219
|
+
nested: true,
|
|
1220
|
+
inFolder: false,
|
|
1221
|
+
ownFile: (fileBase)=>new RegExp(`^${escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
1222
|
+
target: (reactFolder, { folders, fileName })=>node_path.join(reactFolder, 'pages', ...folders, `${fileName}-page${component}`),
|
|
1223
|
+
classPrefix: `(${prefix})?`,
|
|
1224
|
+
classSuffix: 'Page'
|
|
1225
|
+
},
|
|
1226
|
+
widget: {
|
|
1227
|
+
folder: 'widgets',
|
|
1228
|
+
nested: true,
|
|
1229
|
+
inFolder: true,
|
|
1230
|
+
target: (reactFolder, { folders, folderName })=>node_path.join(reactFolder, 'widgets', ...folders, folderName),
|
|
1231
|
+
classPrefix: `(${prefix})?`,
|
|
1232
|
+
classSuffix: 'Widget|UIModel',
|
|
1233
|
+
storyTitle: (segments)=>[
|
|
1234
|
+
'Widgets',
|
|
1235
|
+
...segments
|
|
1236
|
+
].join('/')
|
|
1237
|
+
},
|
|
1238
|
+
'ui-kit': {
|
|
1239
|
+
folder: 'ui-kit',
|
|
1240
|
+
nested: false,
|
|
1241
|
+
inFolder: true,
|
|
1242
|
+
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'ui-kit', fileName),
|
|
1243
|
+
classPrefix: '()',
|
|
1244
|
+
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
1245
|
+
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
1246
|
+
},
|
|
1247
|
+
hook: {
|
|
1248
|
+
folder: shared.join('/'),
|
|
1249
|
+
nested: false,
|
|
1250
|
+
inFolder: false,
|
|
1251
|
+
ownFile: (fileBase)=>new RegExp(`^${prefix}-${escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
1252
|
+
target: (reactFolder, { fileName })=>node_path.join(reactFolder, ...shared, `${prefix}-${fileName}${hook}`),
|
|
1253
|
+
classPrefix: `(${prefix})`,
|
|
1254
|
+
classSuffix: '(?![\\w$])'
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
};
|
|
1258
|
+
const reactKindLayouts = kindLayouts('react');
|
|
1259
|
+
const svelteKindLayouts = kindLayouts('svelte');
|
|
1260
|
+
const frontendKindLayouts = (framework)=>'svelte' === framework ? svelteKindLayouts : reactKindLayouts;
|
|
1261
|
+
const reactKindTitles = {
|
|
1262
|
+
page: [
|
|
1263
|
+
'Page',
|
|
1264
|
+
'pages'
|
|
1265
|
+
],
|
|
1266
|
+
widget: [
|
|
1267
|
+
'Widget',
|
|
1268
|
+
'widgets'
|
|
1269
|
+
],
|
|
1270
|
+
'ui-kit': [
|
|
1271
|
+
'UI-kit component',
|
|
1272
|
+
'UI-kit components'
|
|
1273
|
+
],
|
|
1274
|
+
hook: [
|
|
1275
|
+
'Shared hook',
|
|
1276
|
+
'shared hooks'
|
|
1277
|
+
]
|
|
1278
|
+
};
|
|
1279
|
+
const svelteKindTitles = {
|
|
1280
|
+
...reactKindTitles,
|
|
1281
|
+
hook: [
|
|
1282
|
+
'Shared model',
|
|
1283
|
+
'shared models'
|
|
1284
|
+
]
|
|
1285
|
+
};
|
|
1286
|
+
const frontendKindTitles = (framework)=>'svelte' === framework ? svelteKindTitles : reactKindTitles;
|
|
1287
|
+
const reactModuleName = (kind, rawName, framework = 'react')=>'hook' === kind ? rawName.trim().replace(new RegExp(`^${frontendLogicNaming[framework].prefix}-`), '') : rawName;
|
|
1288
|
+
const nestedName = (folders, fileBase)=>{
|
|
1289
|
+
const prefix = `${folders.join('-')}-`;
|
|
1290
|
+
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
1291
|
+
return [
|
|
1292
|
+
...folders,
|
|
1293
|
+
last
|
|
1294
|
+
].join('/');
|
|
1295
|
+
};
|
|
1296
|
+
const declaredClassName = (filePaths, suffix, name)=>{
|
|
1297
|
+
for (const filePath of filePaths){
|
|
1298
|
+
if (!node_fs.existsSync(filePath)) continue;
|
|
1299
|
+
const declared = node_fs.readFileSync(filePath, 'utf8').match(new RegExp(`(?:export\\s+(?:const|function)|\\bdefault\\s+as)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
1300
|
+
if (declared) return declared;
|
|
1301
|
+
}
|
|
1302
|
+
return new NestedName(name).ClassName;
|
|
1303
|
+
};
|
|
1304
|
+
const findUiKit = (reactFolder, framework)=>{
|
|
1305
|
+
const { component } = frontendExtensions[framework];
|
|
1306
|
+
const root = node_path.join(reactFolder, 'ui-kit');
|
|
1307
|
+
if (!node_fs.existsSync(root)) return [];
|
|
1308
|
+
return node_fs.readdirSync(root, {
|
|
1309
|
+
withFileTypes: true
|
|
1310
|
+
}).filter((entry)=>entry.isDirectory() && node_fs.existsSync(node_path.join(root, entry.name, `${entry.name}${component}`))).map(({ name })=>({
|
|
1311
|
+
kind: 'ui-kit',
|
|
1312
|
+
name,
|
|
1313
|
+
path: node_path.join(root, name),
|
|
1314
|
+
fileBase: name,
|
|
1315
|
+
ClassName: declaredClassName([
|
|
1316
|
+
node_path.join(root, name, `${name}${component}`),
|
|
1317
|
+
node_path.join(root, name, 'index.ts')
|
|
1318
|
+
], '', name)
|
|
1319
|
+
}));
|
|
1320
|
+
};
|
|
1321
|
+
const hookFile = {
|
|
1322
|
+
react: /\.tsx?$/,
|
|
1323
|
+
svelte: /\.svelte\.[jt]s$/
|
|
1324
|
+
};
|
|
1325
|
+
const findHooks = (reactFolder, framework)=>{
|
|
1326
|
+
const { prefix, shared } = frontendLogicNaming[framework];
|
|
1327
|
+
const root = node_path.join(reactFolder, ...shared);
|
|
1328
|
+
if (!node_fs.existsSync(root)) return [];
|
|
1329
|
+
const extension = hookFile[framework];
|
|
1330
|
+
const ownPrefix = new RegExp(`^${prefix}-`);
|
|
1331
|
+
return node_fs.readdirSync(root).filter((file)=>ownPrefix.test(file) && extension.test(file) && !/\.(spec|test)\./.test(file)).map((file)=>{
|
|
1332
|
+
const name = file.replace(ownPrefix, '').replace(extension, '');
|
|
1333
|
+
const content = node_fs.readFileSync(node_path.join(root, file), 'utf8');
|
|
1334
|
+
return {
|
|
1335
|
+
kind: 'hook',
|
|
1336
|
+
name,
|
|
1337
|
+
path: node_path.join(root, file),
|
|
1338
|
+
fileBase: name,
|
|
1339
|
+
ClassName: content.match(new RegExp(`export\\s+(?:const|function)\\s+${prefix}(\\w+)\\b`))?.[1] ?? new NestedName(name).ClassName
|
|
1340
|
+
};
|
|
1341
|
+
});
|
|
1342
|
+
};
|
|
1343
|
+
const findReactModules = (reactFolder, kind, framework = 'react')=>{
|
|
1344
|
+
const { component } = frontendExtensions[framework];
|
|
1345
|
+
const modules = 'ui-kit' === kind ? findUiKit(reactFolder, framework) : 'hook' === kind ? findHooks(reactFolder, framework) : 'page' === kind ? module_move_walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith(`-page${component}`)).map((file)=>{
|
|
1346
|
+
const folders = node_path.relative(node_path.join(reactFolder, 'pages'), node_path.dirname(file)).split(node_path.sep).filter((segment)=>!!segment);
|
|
1347
|
+
const fileBase = node_path.basename(file, `-page${component}`);
|
|
1348
|
+
const name = nestedName(folders, fileBase);
|
|
1349
|
+
return {
|
|
1350
|
+
kind,
|
|
1351
|
+
name,
|
|
1352
|
+
path: file,
|
|
1353
|
+
fileBase,
|
|
1354
|
+
ClassName: declaredClassName([
|
|
1355
|
+
file
|
|
1356
|
+
], 'Page', name)
|
|
1357
|
+
};
|
|
1358
|
+
}) : module_move_walk(node_path.join(reactFolder, 'widgets')).filter((file)=>file.endsWith(`-widget${component}`)).map((file)=>{
|
|
1359
|
+
const folder = node_path.dirname(file);
|
|
1360
|
+
const name = toPosix(node_path.relative(node_path.join(reactFolder, 'widgets'), folder));
|
|
1361
|
+
return {
|
|
1362
|
+
kind,
|
|
1363
|
+
name,
|
|
1364
|
+
path: folder,
|
|
1365
|
+
fileBase: node_path.basename(file, `-widget${component}`),
|
|
1366
|
+
ClassName: declaredClassName([
|
|
1367
|
+
file,
|
|
1368
|
+
node_path.join(folder, 'index.ts')
|
|
1369
|
+
], 'Widget', name)
|
|
1370
|
+
};
|
|
1371
|
+
});
|
|
1372
|
+
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
1373
|
+
};
|
|
1374
|
+
const react_module_move_targetPath = (reactFolder, module, rawName, framework)=>frontendKindLayouts(framework)[module.kind].target(reactFolder, new NestedName(reactModuleName(module.kind, rawName, framework)));
|
|
1375
|
+
const validateMove = (reactFolder, module, rawName, framework = 'react')=>{
|
|
1376
|
+
const nameError = NestedName.validate(rawName);
|
|
1377
|
+
if (true !== nameError) return nameError;
|
|
1378
|
+
if (!frontendKindLayouts(framework)[module.kind].nested && /[\\/]/.test(rawName)) return `UI-kit components and ${frontendKindTitles(framework).hook[1]} have no folders: enter a name without "/"`;
|
|
1379
|
+
const target = react_module_move_targetPath(reactFolder, module, rawName, framework);
|
|
1380
|
+
if (target !== module.path && node_fs.existsSync(target)) return `${node_path.relative(reactFolder, target)} already exists`;
|
|
1381
|
+
if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
|
|
1382
|
+
return true;
|
|
1383
|
+
};
|
|
1384
|
+
const routeFolder = (appFolder, rawName)=>{
|
|
1385
|
+
const { folders, folderName } = new NestedName(rawName);
|
|
1386
|
+
return node_path.join(appFolder, ...folders, folderName);
|
|
1387
|
+
};
|
|
1388
|
+
const routeFiles = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(folder, {
|
|
1389
|
+
withFileTypes: true
|
|
1390
|
+
}).filter((entry)=>entry.isFile()).map((entry)=>node_path.join(folder, entry.name)) : [];
|
|
1391
|
+
const moveReactModule = (projectRoot, reactFolder, module, rawName, route, framework = 'react')=>{
|
|
1392
|
+
const layout = frontendKindLayouts(framework)[module.kind];
|
|
1393
|
+
const newName = new NestedName(reactModuleName(module.kind, rawName, framework));
|
|
1394
|
+
const { prefix } = frontendLogicNaming[framework];
|
|
1395
|
+
const target = react_module_move_targetPath(reactFolder, module, rawName, framework);
|
|
1396
|
+
const newClassName = newName.ClassName;
|
|
1397
|
+
const renameFile = (name)=>name.replace(new RegExp(`^(${prefix}-)?${escapeRegExp(module.fileBase)}(?=[-.]|$)`), (_, own = '')=>`${own}${newName.fileName}`);
|
|
1398
|
+
const oldFolder = layout.inFolder ? module.path : node_path.dirname(module.path);
|
|
1399
|
+
const newFolder = layout.inFolder ? target : node_path.dirname(target);
|
|
1400
|
+
const ownsPath = (candidate)=>layout.inFolder ? candidate === oldFolder || candidate.startsWith(`${oldFolder}${node_path.sep}`) : node_path.dirname(candidate) === oldFolder && layout.ownFile(module.fileBase).test(node_path.basename(candidate));
|
|
1401
|
+
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
1402
|
+
const routeTarget = (candidate)=>{
|
|
1403
|
+
if (!route) return;
|
|
1404
|
+
const file = [
|
|
1405
|
+
...routeFileSet
|
|
1406
|
+
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
1407
|
+
if (!file) return;
|
|
1408
|
+
const moved = node_path.join(route.to, node_path.relative(route.from, file));
|
|
1409
|
+
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
1410
|
+
};
|
|
1411
|
+
const movedPath = (candidate)=>{
|
|
1412
|
+
const routed = routeTarget(candidate);
|
|
1413
|
+
if (routed) return routed;
|
|
1414
|
+
if (!ownsPath(candidate)) return;
|
|
1415
|
+
const segments = node_path.relative(oldFolder, candidate).split(node_path.sep);
|
|
1416
|
+
const last = segments.length - 1;
|
|
1417
|
+
segments[last] = renameFile(segments[last]);
|
|
1418
|
+
return node_path.join(newFolder, ...segments);
|
|
1419
|
+
};
|
|
1420
|
+
const moduleFiles = reactModuleFiles(module, framework);
|
|
1421
|
+
const moves = new Map([
|
|
1422
|
+
...moduleFiles,
|
|
1423
|
+
...routeFileSet
|
|
1424
|
+
].map((file)=>[
|
|
1425
|
+
file,
|
|
1426
|
+
movedPath(file) ?? file
|
|
1427
|
+
]));
|
|
1428
|
+
const classPattern = new RegExp(`(?<![\\w$])${layout.classPrefix}${escapeRegExp(module.ClassName)}(?=${layout.classSuffix})`, 'g');
|
|
1429
|
+
const oldTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
1430
|
+
module.ClassName
|
|
1431
|
+
] : module.name.split('/').map((segment)=>new NestedName(segment).ClassName));
|
|
1432
|
+
const titlePattern = oldTitle && new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
1433
|
+
const newTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
1434
|
+
newClassName
|
|
1435
|
+
] : newName.classNameSegments);
|
|
1436
|
+
return stageModuleMove({
|
|
1437
|
+
projectRoot,
|
|
1438
|
+
stopAt: reactFolder,
|
|
1439
|
+
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
1440
|
+
moves,
|
|
1441
|
+
movedPath,
|
|
1442
|
+
rename: (content, { moved })=>{
|
|
1443
|
+
const renamed = content.replace(classPattern, (_, use)=>`${use ?? ''}${newClassName}`);
|
|
1444
|
+
return moved && titlePattern ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
1445
|
+
}
|
|
1446
|
+
});
|
|
1447
|
+
};
|
|
1448
|
+
const routePageFile = {
|
|
1449
|
+
react: 'page.tsx',
|
|
1450
|
+
svelte: '+page.svelte'
|
|
1451
|
+
};
|
|
1452
|
+
const pageRouteFolder = (appFolder, page, framework = 'react')=>{
|
|
1453
|
+
const folder = routeFolder(appFolder, page.name);
|
|
1454
|
+
const routePage = node_path.join(folder, routePageFile[framework]);
|
|
1455
|
+
return node_fs.existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(node_fs.readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
1456
|
+
};
|
|
1457
|
+
const reactModuleFiles = (module, framework)=>{
|
|
1458
|
+
const layout = frontendKindLayouts(framework)[module.kind];
|
|
1459
|
+
if (layout.inFolder) return module_move_walk(module.path);
|
|
1460
|
+
const folder = node_path.dirname(module.path);
|
|
1461
|
+
const own = layout.ownFile(module.fileBase);
|
|
1462
|
+
return node_fs.readdirSync(folder, {
|
|
1463
|
+
withFileTypes: true
|
|
1464
|
+
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>node_path.join(folder, entry.name));
|
|
1465
|
+
};
|
|
1466
|
+
const importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
1467
|
+
const deleteReactModule = (projectRoot, reactFolder, module, route, framework = 'react')=>{
|
|
1468
|
+
const moduleFiles = reactModuleFiles(module, framework);
|
|
1469
|
+
const routeFileList = route ? routeFiles(route.folder) : [];
|
|
1470
|
+
const own = new Set([
|
|
1471
|
+
...moduleFiles,
|
|
1472
|
+
...routeFileList
|
|
1473
|
+
]);
|
|
1474
|
+
const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
|
|
1475
|
+
const isModule = (resolved)=>stems.has(resolved) || moduleFiles.includes(resolved) || frontendKindLayouts(framework)[module.kind].inFolder && (resolved === module.path || resolved.startsWith(`${module.path}${node_path.sep}`));
|
|
1476
|
+
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
1477
|
+
const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
|
|
1478
|
+
const usedBy = [];
|
|
1479
|
+
for (const [file, content] of codeFiles)if (!own.has(file)) for (const [, , specifier] of content.matchAll(importSpecifier)){
|
|
1480
|
+
const target = resolve(specifier, file)?.resolved;
|
|
1481
|
+
if (target && isModule(target)) usedBy.push([
|
|
1482
|
+
relative(file),
|
|
1483
|
+
relative(target)
|
|
1484
|
+
]);
|
|
1485
|
+
}
|
|
1486
|
+
if (usedBy.length) return {
|
|
1487
|
+
usedBy
|
|
1488
|
+
};
|
|
1489
|
+
for (const file of moduleFiles)new File(file).delete(reactFolder);
|
|
1490
|
+
for (const file of routeFileList)new File(file).delete(route.appFolder);
|
|
1491
|
+
return {
|
|
1492
|
+
deleted: [
|
|
1493
|
+
...moduleFiles,
|
|
1494
|
+
...routeFileList
|
|
1495
|
+
]
|
|
1496
|
+
};
|
|
1497
|
+
};
|
|
1498
|
+
export { ConfigFile, File, Folder, NestedName, ProjectRoot, UnknownFormatNaming, addBranchedImplementation, addClassMember, addConstructorParameters, addImport, addWireDependencies, availableDependencies, boundedContextLocation, boundedContextName, boundedContextNames, boundedContextPath, boundedContextsFolderName, branchNameSchema, canDependOn, codeExtension, compilerOption, configFileName, configSchema, configuredDependencyRules, crossContextImplementation, crossContextImportAllowed, defaultDependencyRules, deleteReactModule, discardPendingChanges, domainFirstPackages, escapeRegExp, fileModuleKind, filesToOverwrite, findReactModules, findWiredModules, frontendKindLayouts, frontendKindTitles, frontendLogicNaming, hasNeighboringBoundedContext, implementationKinds, implementationLabelSchema, implementationType, isCrossContextImplementation, isOutdatedConfig, isSuggestedFor, moduleKindOf, module_move_walk, moveReactModule, namedImportFiles, outdatedConfigMessage, pageRouteFolder, pendingChanges, projectImports, readWiredModule, relativeImport, routeFolder, routePageFile, rulesSchema, scaffoldBackendRules, splitContextSegments, stageModuleMove, toPosix, validateBoundedContextName, validateMove, wireBranches, wireDependencies, wiredDependencyNames, wiring_layers, withoutOverwrites, writePendingChanges };
|
package/dist/agent-cli.d.ts
CHANGED
|
@@ -236,7 +236,7 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
|
|
|
236
236
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
237
237
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
238
238
|
}, z.core.$strict>, z.ZodObject<{
|
|
239
|
-
operation: z.ZodLiteral<"shared-hook">;
|
|
239
|
+
operation: z.ZodLiteral<"shared-hook" | "shared-model">;
|
|
240
240
|
name: z.ZodString;
|
|
241
241
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
242
242
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -265,7 +265,7 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
|
|
|
265
265
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
266
266
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
267
267
|
}, z.core.$strict>, z.ZodObject<{
|
|
268
|
-
operation: z.ZodLiteral<"move-shared-hook">;
|
|
268
|
+
operation: z.ZodLiteral<"move-shared-hook" | "move-shared-model">;
|
|
269
269
|
module: z.ZodString;
|
|
270
270
|
name: z.ZodString;
|
|
271
271
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -276,7 +276,7 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
|
|
|
276
276
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
277
277
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
278
278
|
}, z.core.$strict>, z.ZodObject<{
|
|
279
|
-
operation: z.ZodLiteral<"delete-shared-hook">;
|
|
279
|
+
operation: z.ZodLiteral<"delete-shared-hook" | "delete-shared-model">;
|
|
280
280
|
module: z.ZodString;
|
|
281
281
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
282
282
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -430,12 +430,12 @@ export declare const describeAgentCommand: (command: AgentCommand) => {
|
|
|
430
430
|
available: boolean;
|
|
431
431
|
}[];
|
|
432
432
|
reactModules: {
|
|
433
|
-
kind:
|
|
433
|
+
kind: string;
|
|
434
434
|
name: string;
|
|
435
435
|
file: string;
|
|
436
436
|
}[];
|
|
437
437
|
svelteModules: {
|
|
438
|
-
kind:
|
|
438
|
+
kind: string;
|
|
439
439
|
name: string;
|
|
440
440
|
file: string;
|
|
441
441
|
}[];
|
package/dist/agent-requests.d.ts
CHANGED
|
@@ -215,7 +215,7 @@ export declare const reactRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
215
215
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
216
216
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
217
217
|
}, z.core.$strict>, z.ZodObject<{
|
|
218
|
-
operation: z.ZodLiteral<"shared-hook">;
|
|
218
|
+
operation: z.ZodLiteral<"shared-hook" | "shared-model">;
|
|
219
219
|
name: z.ZodString;
|
|
220
220
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
221
221
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -244,7 +244,7 @@ export declare const reactRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
244
244
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
245
245
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
246
246
|
}, z.core.$strict>, z.ZodObject<{
|
|
247
|
-
operation: z.ZodLiteral<"move-shared-hook">;
|
|
247
|
+
operation: z.ZodLiteral<"move-shared-hook" | "move-shared-model">;
|
|
248
248
|
module: z.ZodString;
|
|
249
249
|
name: z.ZodString;
|
|
250
250
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -255,7 +255,7 @@ export declare const reactRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
255
255
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
256
256
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
257
257
|
}, z.core.$strict>, z.ZodObject<{
|
|
258
|
-
operation: z.ZodLiteral<"delete-shared-hook">;
|
|
258
|
+
operation: z.ZodLiteral<"delete-shared-hook" | "delete-shared-model">;
|
|
259
259
|
module: z.ZodString;
|
|
260
260
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
261
261
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -287,7 +287,7 @@ export declare const svelteRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
287
287
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
288
288
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
289
289
|
}, z.core.$strict>, z.ZodObject<{
|
|
290
|
-
operation: z.ZodLiteral<"shared-hook">;
|
|
290
|
+
operation: z.ZodLiteral<"shared-hook" | "shared-model">;
|
|
291
291
|
name: z.ZodString;
|
|
292
292
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
293
293
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -316,7 +316,7 @@ export declare const svelteRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
316
316
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
317
317
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
318
318
|
}, z.core.$strict>, z.ZodObject<{
|
|
319
|
-
operation: z.ZodLiteral<"move-shared-hook">;
|
|
319
|
+
operation: z.ZodLiteral<"move-shared-hook" | "move-shared-model">;
|
|
320
320
|
module: z.ZodString;
|
|
321
321
|
name: z.ZodString;
|
|
322
322
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -327,7 +327,7 @@ export declare const svelteRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
327
327
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
328
328
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
329
329
|
}, z.core.$strict>, z.ZodObject<{
|
|
330
|
-
operation: z.ZodLiteral<"delete-shared-hook">;
|
|
330
|
+
operation: z.ZodLiteral<"delete-shared-hook" | "delete-shared-model">;
|
|
331
331
|
module: z.ZodString;
|
|
332
332
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
333
333
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -591,7 +591,7 @@ export declare const requestSchemaFor: (command: AgentCommand) => z.ZodDiscrimin
|
|
|
591
591
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
592
592
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
593
593
|
}, z.core.$strict>, z.ZodObject<{
|
|
594
|
-
operation: z.ZodLiteral<"shared-hook">;
|
|
594
|
+
operation: z.ZodLiteral<"shared-hook" | "shared-model">;
|
|
595
595
|
name: z.ZodString;
|
|
596
596
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
597
597
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -620,7 +620,7 @@ export declare const requestSchemaFor: (command: AgentCommand) => z.ZodDiscrimin
|
|
|
620
620
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
621
621
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
622
622
|
}, z.core.$strict>, z.ZodObject<{
|
|
623
|
-
operation: z.ZodLiteral<"move-shared-hook">;
|
|
623
|
+
operation: z.ZodLiteral<"move-shared-hook" | "move-shared-model">;
|
|
624
624
|
module: z.ZodString;
|
|
625
625
|
name: z.ZodString;
|
|
626
626
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -631,7 +631,7 @@ export declare const requestSchemaFor: (command: AgentCommand) => z.ZodDiscrimin
|
|
|
631
631
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
632
632
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
633
633
|
}, z.core.$strict>, z.ZodObject<{
|
|
634
|
-
operation: z.ZodLiteral<"delete-shared-hook">;
|
|
634
|
+
operation: z.ZodLiteral<"delete-shared-hook" | "delete-shared-model">;
|
|
635
635
|
module: z.ZodString;
|
|
636
636
|
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
637
637
|
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { Folder } from './file-system';
|
|
2
2
|
import type { FrontendFramework } from './react-module-move';
|
|
3
|
+
/**
|
|
4
|
+
* The operation name of reusable logic: React shared hooks, Svelte shared
|
|
5
|
+
* models (`createN` in `shared/model`).
|
|
6
|
+
*/
|
|
7
|
+
export declare const sharedLogicOperation: Record<FrontendFramework, string>;
|
|
3
8
|
/**
|
|
4
9
|
* Operations on frontend modules by their agent operation name; menus and
|
|
5
10
|
* `--request` run the same ones.
|
|
6
11
|
*/
|
|
7
12
|
export declare const frontendOperations: (folder: Folder, framework: FrontendFramework) => Record<string, () => Promise<unknown>>;
|
|
8
13
|
/** Menu items of df-react and df-svelte → agent operations. */
|
|
9
|
-
export declare const frontendMenu: [string, string][];
|
|
14
|
+
export declare const frontendMenu: (framework: FrontendFramework) => [string, string][];
|