@domain-first/project-structure 8.11.0 → 8.13.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 +1115 -0
- package/dist/{201.js → 878.js} +453 -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 +113 -4
- package/dist/graph.js +1 -1
- package/dist/index.cjs +105 -81
- package/dist/index.js +1 -1
- package/dist/init.cjs +47 -6
- package/dist/init.js +1 -1
- package/dist/integration.cjs +105 -81
- package/dist/integration.js +1 -1
- package/dist/integrations/openapi.d.ts +13 -3
- package/dist/lint.cjs +119 -9
- package/dist/lint.js +1 -1
- package/dist/react-module-move.d.ts +18 -2
- package/dist/react.cjs +161 -133
- package/dist/svelte.cjs +161 -133
- package/dist/upgrade-svelte.d.ts +22 -0
- package/dist/upgrade-svelte.spec.d.ts +1 -0
- package/dist/upgrade.cjs +381 -41
- package/dist/upgrade.js +219 -13
- package/dist/use-cases/scaffold-svelte-modules.d.ts +3 -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 +16 -11
- package/skills/df-ps-svelte/references/generators.md +6 -5
- package/dist/115.js +0 -616
package/dist/287.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
-
import { Separator, checkbox as prompts_checkbox, confirm as prompts_confirm, input, search, select as prompts_select } from "@inquirer/prompts";
|
|
4
2
|
import node_fs from "node:fs";
|
|
5
3
|
import { styleText } from "node:util";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { checkbox as prompts_checkbox, confirm as prompts_confirm, input, select as prompts_select } from "@inquirer/prompts";
|
|
5
|
+
import { scaffoldBackendRules, frontendKindTitles, findWiredModules, UnknownFormatNaming, module_move_walk, Folder, projectImports, validateMove, writePendingChanges, splitContextSegments, stageModuleMove, addBranchedImplementation, hasNeighboringBoundedContext, findReactModules, implementationLabelSchema, boundedContextLocation, branchNameSchema, frontendKindLayouts, deleteReactModule, wireDependencies, ProjectRoot, pageRouteFolder, boundedContextsFolderName, crossContextImplementation, boundedContextName, availableDependencies, codeExtension, domainFirstPackages as config_file_domainFirstPackages, discardPendingChanges, routePageFile, escapeRegExp, implementationKinds, readWiredModule, toPosix, boundedContextNames, withoutOverwrites, validateBoundedContextName, filesToOverwrite, ConfigFile, relativeImport, routeFolder as react_module_move_routeFolder, wireBranches, moveReactModule, implementationType as wiring_implementationType, File, crossContextImportAllowed, isSuggestedFor, NestedName } from "./878.js";
|
|
6
|
+
import { defaultOpenapiPath, isNonInteractive, openapiScriptPath, describeScripts, interaction_checkbox, keepInMemoryDbSection, nextAppFolder, rootStaticSegments, inMemoryDbScaffolded, scaffoldInMemoryDb, isInMemoryDb, RequestError, hasDependency, missingPackages, assertAnswersConsumed, Separator, interaction_input, isPathParameterName, addPackageScripts, missingDomainFirstPackages, report, hasLegacyRootEndpoints, wireInMemoryDb, interaction_select, usesNext, svelteKitRoutesFolder, pathParameterAsName, inMemoryImplementationType, injectInMemoryDb, usesSvelteKit, answerFor, addOpenapi, inMemoryDbTypeImport, addInMemoryDbSection, restControllers, plural, interaction_confirm, inMemoryDbSectionMembers, usesInMemoryDb } from "./783.js";
|
|
8
7
|
const moduleId = (module)=>`${boundedContextLocation(module.typeFile)?.name ?? 'shared-kernel'}:${module.typeName}`;
|
|
9
8
|
const unitId = (unit)=>`${unit.kind}:${unit.aggregate ? `${unit.aggregate}/` : ''}${unit.name}`;
|
|
10
9
|
const savedImplementations = (kind, purpose)=>[
|
|
@@ -35,209 +34,6 @@ const rememberImplementation = (kind, purpose, label)=>{
|
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
36
|
};
|
|
38
|
-
const isSeparator = (choice)=>'function' == typeof Separator && choice instanceof Separator || 'object' == typeof choice && null !== choice && 'separator' === choice.type;
|
|
39
|
-
class RequestError extends Error {
|
|
40
|
-
code;
|
|
41
|
-
details;
|
|
42
|
-
constructor(code, message, details){
|
|
43
|
-
super(message), this.code = code, this.details = details;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const storage = new AsyncLocalStorage();
|
|
47
|
-
const isNonInteractive = ()=>Boolean(storage.getStore());
|
|
48
|
-
const runWithAnswers = async (answers, defaults, run)=>storage.run({
|
|
49
|
-
answers,
|
|
50
|
-
defaults,
|
|
51
|
-
used: new Set(),
|
|
52
|
-
messages: []
|
|
53
|
-
}, async ()=>{
|
|
54
|
-
const result = await run();
|
|
55
|
-
const state = storage.getStore();
|
|
56
|
-
assertAnswersConsumed();
|
|
57
|
-
return {
|
|
58
|
-
result,
|
|
59
|
-
messages: state.messages
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
const assertAnswersConsumed = ()=>{
|
|
63
|
-
const state = storage.getStore();
|
|
64
|
-
if (!state) return;
|
|
65
|
-
const unused = Object.keys(state.answers).filter((key)=>!state.used.has(key));
|
|
66
|
-
if (unused.length) throw new RequestError('UNUSED_PARAMETERS', 'Some parameters do not apply to this operation.', {
|
|
67
|
-
fields: unused
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
const answerFor = (key, fallback)=>{
|
|
71
|
-
const state = storage.getStore();
|
|
72
|
-
if (!state) return;
|
|
73
|
-
if (Object.hasOwn(state.answers, key)) {
|
|
74
|
-
state.used.add(key);
|
|
75
|
-
return state.answers[key];
|
|
76
|
-
}
|
|
77
|
-
return Object.hasOwn(state.defaults, key) ? state.defaults[key] : fallback;
|
|
78
|
-
};
|
|
79
|
-
const report = (...values)=>{
|
|
80
|
-
const state = storage.getStore();
|
|
81
|
-
if (state) state.messages.push(values.map(String).join(' '));
|
|
82
|
-
else console.log(...values);
|
|
83
|
-
};
|
|
84
|
-
const requireKey = (key)=>{
|
|
85
|
-
if (!key) throw new RequestError('UNSUPPORTED_PROMPT', 'This operation needs an answer that is not supported in non-interactive mode.');
|
|
86
|
-
return key;
|
|
87
|
-
};
|
|
88
|
-
const interaction_missing = (key)=>new RequestError('MISSING_PARAMETER', `Provide ${key}.`, {
|
|
89
|
-
field: key
|
|
90
|
-
});
|
|
91
|
-
const interaction_input = async (config)=>{
|
|
92
|
-
const { key, ...interactive } = config;
|
|
93
|
-
if (!isNonInteractive()) return input(interactive);
|
|
94
|
-
const field = requireKey(key);
|
|
95
|
-
const value = answerFor(field, config.default);
|
|
96
|
-
if ('string' != typeof value) throw interaction_missing(field);
|
|
97
|
-
const valid = await config.validate?.(value);
|
|
98
|
-
if (void 0 !== valid && true !== valid) throw new RequestError('INVALID_PARAMETER', 'string' == typeof valid ? valid : `Invalid ${field}.`, {
|
|
99
|
-
field
|
|
100
|
-
});
|
|
101
|
-
return value;
|
|
102
|
-
};
|
|
103
|
-
const interaction_confirm = async (config)=>{
|
|
104
|
-
const { key, requestRequired, ...interactive } = config;
|
|
105
|
-
if (!isNonInteractive()) return prompts_confirm(interactive);
|
|
106
|
-
const field = requireKey(key);
|
|
107
|
-
const value = answerFor(field, requestRequired ? void 0 : config.default ?? false);
|
|
108
|
-
if (void 0 === value) throw interaction_missing(field);
|
|
109
|
-
if ('boolean' != typeof value) throw new RequestError('INVALID_PARAMETER', `${field} must be a boolean.`, {
|
|
110
|
-
field
|
|
111
|
-
});
|
|
112
|
-
return value;
|
|
113
|
-
};
|
|
114
|
-
const choicesOf = (config)=>config.choices.filter((choice)=>!isSeparator(choice)).map((choice)=>'object' == typeof choice && null !== choice && 'value' in choice ? choice : {
|
|
115
|
-
value: choice
|
|
116
|
-
});
|
|
117
|
-
const choiceId = (choice, id)=>id?.(choice.value) ?? choice.value;
|
|
118
|
-
const resolveChoice = (value, choices, key, id)=>{
|
|
119
|
-
const matches = choices.filter((choice)=>Object.is(choice.value, value) || choiceId(choice, id) === value);
|
|
120
|
-
if (1 !== matches.length || matches[0].disabled) throw new RequestError('INVALID_CHOICE', `Invalid or unavailable choice for ${key}.`, {
|
|
121
|
-
field: key,
|
|
122
|
-
value,
|
|
123
|
-
choices: choices.filter((choice)=>!choice.disabled).map((choice)=>choiceId(choice, id))
|
|
124
|
-
});
|
|
125
|
-
return matches[0].value;
|
|
126
|
-
};
|
|
127
|
-
const searchThreshold = 10;
|
|
128
|
-
const choiceLabel = (choice)=>choice.name ?? String(choice.value);
|
|
129
|
-
const filterChoices = (choices, term)=>{
|
|
130
|
-
const text = (term ?? '').trim().toLowerCase();
|
|
131
|
-
const words = text.split(/\s+/).filter(Boolean);
|
|
132
|
-
if (!words.length) return [
|
|
133
|
-
...choices
|
|
134
|
-
];
|
|
135
|
-
const groups = [
|
|
136
|
-
{
|
|
137
|
-
matches: []
|
|
138
|
-
}
|
|
139
|
-
];
|
|
140
|
-
for (const choice of choices){
|
|
141
|
-
if (isSeparator(choice)) {
|
|
142
|
-
groups.push({
|
|
143
|
-
separator: choice,
|
|
144
|
-
matches: []
|
|
145
|
-
});
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
const normalized = 'object' == typeof choice && null !== choice && 'value' in choice ? choice : {
|
|
149
|
-
value: choice
|
|
150
|
-
};
|
|
151
|
-
const label = choiceLabel(normalized).toLowerCase();
|
|
152
|
-
if (words.every((word)=>label.includes(word))) groups.at(-1)?.matches.push({
|
|
153
|
-
choice: normalized,
|
|
154
|
-
prefix: label.startsWith(text)
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
const byPrefix = (items, prefix)=>[
|
|
158
|
-
...items.filter(prefix),
|
|
159
|
-
...items.filter((item)=>!prefix(item))
|
|
160
|
-
];
|
|
161
|
-
const [ungrouped, ...grouped] = groups;
|
|
162
|
-
return [
|
|
163
|
-
ungrouped,
|
|
164
|
-
...byPrefix(grouped.filter(({ matches })=>matches.length), ({ matches })=>matches.some(({ prefix })=>prefix))
|
|
165
|
-
].flatMap(({ separator, matches })=>[
|
|
166
|
-
...separator ? [
|
|
167
|
-
separator
|
|
168
|
-
] : [],
|
|
169
|
-
...byPrefix(matches, ({ prefix })=>prefix).map(({ choice })=>choice)
|
|
170
|
-
]);
|
|
171
|
-
};
|
|
172
|
-
const interaction_select = async (config)=>{
|
|
173
|
-
const { key, id, ...interactive } = config;
|
|
174
|
-
if (!isNonInteractive()) {
|
|
175
|
-
if (choicesOf(config).length <= searchThreshold) return prompts_select(interactive);
|
|
176
|
-
return search({
|
|
177
|
-
message: `${config.message.trimEnd()} (type to filter)`,
|
|
178
|
-
source: (term)=>filterChoices(config.choices, term),
|
|
179
|
-
pageSize: config.pageSize,
|
|
180
|
-
default: config.default
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
const field = requireKey(key);
|
|
184
|
-
const value = answerFor(field, config.default);
|
|
185
|
-
if (void 0 === value) throw interaction_missing(field);
|
|
186
|
-
return resolveChoice(value, choicesOf(config), field, id);
|
|
187
|
-
};
|
|
188
|
-
const interaction_checkbox = async (config)=>{
|
|
189
|
-
const { key, id, ...interactive } = config;
|
|
190
|
-
if (!isNonInteractive()) return prompts_checkbox(interactive);
|
|
191
|
-
const field = requireKey(key);
|
|
192
|
-
const choices = choicesOf(config);
|
|
193
|
-
const values = answerFor(field, choices.filter((choice)=>choice.checked && !choice.disabled).map((choice)=>choice.value));
|
|
194
|
-
if (!Array.isArray(values)) throw new RequestError('INVALID_PARAMETER', `${field} must be an array.`, {
|
|
195
|
-
field
|
|
196
|
-
});
|
|
197
|
-
const selected = values.map((value)=>resolveChoice(value, choices, field, id));
|
|
198
|
-
if (new Set(selected).size !== selected.length) throw new RequestError('INVALID_PARAMETER', `Duplicate choices for ${field}.`, {
|
|
199
|
-
field
|
|
200
|
-
});
|
|
201
|
-
if (config.required && !selected.length) throw interaction_missing(field);
|
|
202
|
-
return selected;
|
|
203
|
-
};
|
|
204
|
-
const addPackageScripts = async (file, additions)=>{
|
|
205
|
-
const original = file.data;
|
|
206
|
-
const manifest = JSON.parse(original);
|
|
207
|
-
const scripts = {
|
|
208
|
-
...manifest.scripts
|
|
209
|
-
};
|
|
210
|
-
const selected = {};
|
|
211
|
-
for (const [name, command] of Object.entries(additions)){
|
|
212
|
-
let target = name;
|
|
213
|
-
if (Object.hasOwn(scripts, name) && scripts[name] !== command) {
|
|
214
|
-
const action = await interaction_select({
|
|
215
|
-
key: `scriptConflicts.${name}`,
|
|
216
|
-
message: `Script "${name}" already exists: ${scripts[name]}`,
|
|
217
|
-
choices: [
|
|
218
|
-
'Keep existing',
|
|
219
|
-
'Replace',
|
|
220
|
-
'Use another name'
|
|
221
|
-
]
|
|
222
|
-
});
|
|
223
|
-
if ('Keep existing' === action) continue;
|
|
224
|
-
if ('Use another name' === action) target = await interaction_input({
|
|
225
|
-
key: `scriptNames.${name}`,
|
|
226
|
-
message: "New script name:",
|
|
227
|
-
validate: (value)=>!/^[a-zA-Z0-9:_-]+$/.test(value) || Object.hasOwn(scripts, value) || Object.hasOwn(additions, value) ? "Enter an unused script name (letters, numbers, :, _, -)." : true
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
scripts[target] = command;
|
|
231
|
-
selected[name] = target;
|
|
232
|
-
}
|
|
233
|
-
if (JSON.stringify(manifest.scripts) !== JSON.stringify(scripts)) {
|
|
234
|
-
manifest.scripts = scripts;
|
|
235
|
-
const indent = original.match(/\n([\t ]+)"/)?.[1] ?? ' ';
|
|
236
|
-
file.update(`${JSON.stringify(manifest, null, indent)}\n`);
|
|
237
|
-
}
|
|
238
|
-
return selected;
|
|
239
|
-
};
|
|
240
|
-
const describeScripts = (selected, descriptions)=>Object.entries(descriptions).filter(([name])=>selected[name]).map(([name, description])=>`npm run ${selected[name]} — ${description}`);
|
|
241
37
|
const runtimePackages = [
|
|
242
38
|
'drizzle-orm',
|
|
243
39
|
'pg',
|
|
@@ -385,733 +181,6 @@ const addInMemoryDb = ()=>{
|
|
|
385
181
|
return [];
|
|
386
182
|
};
|
|
387
183
|
const inMemoryDbApplied = ()=>Boolean(ConfigFile.Instance.data.backend?.withInMemoryDb) && inMemoryDbScaffolded();
|
|
388
|
-
const usesNext = ()=>ConfigFile.exists && ConfigFile.Instance.data.frontend?.react?.framework === 'next';
|
|
389
|
-
const nextAppFolder = (root)=>[
|
|
390
|
-
'app',
|
|
391
|
-
'src/app'
|
|
392
|
-
].find((folder)=>new Folder(node_path.join(root, folder)).exists) ?? 'app';
|
|
393
|
-
const usesSvelteKit = ()=>ConfigFile.exists && ConfigFile.Instance.data.frontend?.svelte?.framework === 'sveltekit';
|
|
394
|
-
const svelteKitRoutesFolder = (root)=>[
|
|
395
|
-
'src/routes',
|
|
396
|
-
'routes'
|
|
397
|
-
].find((folder)=>new Folder(node_path.join(root, folder)).exists) ?? 'src/routes';
|
|
398
|
-
const reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
399
|
-
${[
|
|
400
|
-
...imports,
|
|
401
|
-
"import { type FC } from 'react'"
|
|
402
|
-
].join('\n')}
|
|
403
|
-
|
|
404
|
-
export type ${ClassName}PageProps = {}
|
|
405
|
-
|
|
406
|
-
export const ${ClassName}Page: FC<${ClassName}PageProps> = (props) => {
|
|
407
|
-
return ${body}
|
|
408
|
-
}
|
|
409
|
-
`.trim();
|
|
410
|
-
const nextRouteContent = (ClassName, pageImport)=>`
|
|
411
|
-
import { ${ClassName}Page } from '${pageImport}'
|
|
412
|
-
|
|
413
|
-
export default function Page() {
|
|
414
|
-
return <${ClassName}Page />
|
|
415
|
-
}
|
|
416
|
-
`.trim();
|
|
417
|
-
const scaffoldNextRoute = (name, pagePath)=>{
|
|
418
|
-
const root = new ProjectRoot().path;
|
|
419
|
-
const route = node_path.join(root, nextAppFolder(root), ...name.folders, name.folderName, 'page.tsx');
|
|
420
|
-
const relativeRoute = node_path.relative(root, route).split(node_path.sep).join('/');
|
|
421
|
-
const routeFile = new File(route);
|
|
422
|
-
const content = nextRouteContent(name.ClassName, wiring_relativeImport(route, pagePath.replace(/\.tsx$/, '')));
|
|
423
|
-
if (routeFile.exists) return routeFile.data === content ? void 0 : `${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`;
|
|
424
|
-
routeFile.data = content;
|
|
425
|
-
};
|
|
426
|
-
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
427
|
-
const name = await interaction_input({
|
|
428
|
-
key: 'name',
|
|
429
|
-
message: 'Provide name (folders split by "/"):',
|
|
430
|
-
validate: NestedName.validate
|
|
431
|
-
});
|
|
432
|
-
const nestedName = new NestedName(name);
|
|
433
|
-
const { folders, ClassName, fileName } = nestedName;
|
|
434
|
-
const pageFile = presentationReactFolder.subitem([
|
|
435
|
-
'pages',
|
|
436
|
-
...folders
|
|
437
|
-
]).createFile(`${fileName}-page.tsx`, reactPageContent(ClassName));
|
|
438
|
-
if (usesNext()) {
|
|
439
|
-
const hint = scaffoldNextRoute(nestedName, pageFile.path);
|
|
440
|
-
if (hint) report(hint);
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
const frontendExtensions = {
|
|
444
|
-
react: {
|
|
445
|
-
component: '.tsx',
|
|
446
|
-
hook: '.ts'
|
|
447
|
-
},
|
|
448
|
-
svelte: {
|
|
449
|
-
component: '.svelte',
|
|
450
|
-
hook: '.svelte.ts'
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
const kindLayouts = (framework)=>{
|
|
454
|
-
const { component, hook } = frontendExtensions[framework];
|
|
455
|
-
return {
|
|
456
|
-
page: {
|
|
457
|
-
folder: 'pages',
|
|
458
|
-
nested: true,
|
|
459
|
-
inFolder: false,
|
|
460
|
-
ownFile: (fileBase)=>new RegExp(`^${escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
461
|
-
target: (reactFolder, { folders, fileName })=>node_path.join(reactFolder, 'pages', ...folders, `${fileName}-page${component}`),
|
|
462
|
-
classPrefix: '(use)?',
|
|
463
|
-
classSuffix: 'Page'
|
|
464
|
-
},
|
|
465
|
-
widget: {
|
|
466
|
-
folder: 'widgets',
|
|
467
|
-
nested: true,
|
|
468
|
-
inFolder: true,
|
|
469
|
-
target: (reactFolder, { folders, folderName })=>node_path.join(reactFolder, 'widgets', ...folders, folderName),
|
|
470
|
-
classPrefix: '(use)?',
|
|
471
|
-
classSuffix: 'Widget|UIModel',
|
|
472
|
-
storyTitle: (segments)=>[
|
|
473
|
-
'Widgets',
|
|
474
|
-
...segments
|
|
475
|
-
].join('/')
|
|
476
|
-
},
|
|
477
|
-
'ui-kit': {
|
|
478
|
-
folder: 'ui-kit',
|
|
479
|
-
nested: false,
|
|
480
|
-
inFolder: true,
|
|
481
|
-
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'ui-kit', fileName),
|
|
482
|
-
classPrefix: '()',
|
|
483
|
-
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
484
|
-
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
485
|
-
},
|
|
486
|
-
hook: {
|
|
487
|
-
folder: 'hooks',
|
|
488
|
-
nested: false,
|
|
489
|
-
inFolder: false,
|
|
490
|
-
ownFile: (fileBase)=>new RegExp(`^use-${escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
491
|
-
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'hooks', `use-${fileName}${hook}`),
|
|
492
|
-
classPrefix: '(use)',
|
|
493
|
-
classSuffix: '(?![\\w$])'
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
};
|
|
497
|
-
const reactKindLayouts = kindLayouts('react');
|
|
498
|
-
const svelteKindLayouts = kindLayouts('svelte');
|
|
499
|
-
const frontendKindLayouts = (framework)=>'svelte' === framework ? svelteKindLayouts : reactKindLayouts;
|
|
500
|
-
const reactKindTitles = {
|
|
501
|
-
page: [
|
|
502
|
-
'Page',
|
|
503
|
-
'pages'
|
|
504
|
-
],
|
|
505
|
-
widget: [
|
|
506
|
-
'Widget',
|
|
507
|
-
'widgets'
|
|
508
|
-
],
|
|
509
|
-
'ui-kit': [
|
|
510
|
-
'UI-kit component',
|
|
511
|
-
'UI-kit components'
|
|
512
|
-
],
|
|
513
|
-
hook: [
|
|
514
|
-
'Shared hook',
|
|
515
|
-
'shared hooks'
|
|
516
|
-
]
|
|
517
|
-
};
|
|
518
|
-
const reactModuleName = (kind, rawName)=>'hook' === kind ? rawName.trim().replace(/^use-/, '') : rawName;
|
|
519
|
-
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
520
|
-
const prefix = `${folders.join('-')}-`;
|
|
521
|
-
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
522
|
-
return [
|
|
523
|
-
...folders,
|
|
524
|
-
last
|
|
525
|
-
].join('/');
|
|
526
|
-
};
|
|
527
|
-
const declaredClassName = (filePaths, suffix, name)=>{
|
|
528
|
-
for (const filePath of filePaths){
|
|
529
|
-
if (!node_fs.existsSync(filePath)) continue;
|
|
530
|
-
const declared = node_fs.readFileSync(filePath, 'utf8').match(new RegExp(`(?:export\\s+(?:const|function)|\\bdefault\\s+as)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
531
|
-
if (declared) return declared;
|
|
532
|
-
}
|
|
533
|
-
return new NestedName(name).ClassName;
|
|
534
|
-
};
|
|
535
|
-
const findUiKit = (reactFolder, framework)=>{
|
|
536
|
-
const { component } = frontendExtensions[framework];
|
|
537
|
-
const root = node_path.join(reactFolder, 'ui-kit');
|
|
538
|
-
if (!node_fs.existsSync(root)) return [];
|
|
539
|
-
return node_fs.readdirSync(root, {
|
|
540
|
-
withFileTypes: true
|
|
541
|
-
}).filter((entry)=>entry.isDirectory() && node_fs.existsSync(node_path.join(root, entry.name, `${entry.name}${component}`))).map(({ name })=>({
|
|
542
|
-
kind: 'ui-kit',
|
|
543
|
-
name,
|
|
544
|
-
path: node_path.join(root, name),
|
|
545
|
-
fileBase: name,
|
|
546
|
-
ClassName: declaredClassName([
|
|
547
|
-
node_path.join(root, name, `${name}${component}`),
|
|
548
|
-
node_path.join(root, name, 'index.ts')
|
|
549
|
-
], '', name)
|
|
550
|
-
}));
|
|
551
|
-
};
|
|
552
|
-
const hookFile = {
|
|
553
|
-
react: /\.tsx?$/,
|
|
554
|
-
svelte: /\.svelte\.[jt]s$/
|
|
555
|
-
};
|
|
556
|
-
const findHooks = (reactFolder, framework)=>{
|
|
557
|
-
const root = node_path.join(reactFolder, 'hooks');
|
|
558
|
-
if (!node_fs.existsSync(root)) return [];
|
|
559
|
-
const extension = hookFile[framework];
|
|
560
|
-
return node_fs.readdirSync(root).filter((file)=>/^use-/.test(file) && extension.test(file) && !/\.(spec|test)\./.test(file)).map((file)=>{
|
|
561
|
-
const name = file.replace(/^use-/, '').replace(extension, '');
|
|
562
|
-
const content = node_fs.readFileSync(node_path.join(root, file), 'utf8');
|
|
563
|
-
return {
|
|
564
|
-
kind: 'hook',
|
|
565
|
-
name,
|
|
566
|
-
path: node_path.join(root, file),
|
|
567
|
-
fileBase: name,
|
|
568
|
-
ClassName: content.match(/export\s+(?:const|function)\s+use(\w+)\b/)?.[1] ?? new NestedName(name).ClassName
|
|
569
|
-
};
|
|
570
|
-
});
|
|
571
|
-
};
|
|
572
|
-
const findReactModules = (reactFolder, kind, framework = 'react')=>{
|
|
573
|
-
const { component } = frontendExtensions[framework];
|
|
574
|
-
const modules = 'ui-kit' === kind ? findUiKit(reactFolder, framework) : 'hook' === kind ? findHooks(reactFolder, framework) : 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith(`-page${component}`)).map((file)=>{
|
|
575
|
-
const folders = node_path.relative(node_path.join(reactFolder, 'pages'), node_path.dirname(file)).split(node_path.sep).filter((segment)=>!!segment);
|
|
576
|
-
const fileBase = node_path.basename(file, `-page${component}`);
|
|
577
|
-
const name = react_module_move_nestedName(folders, fileBase);
|
|
578
|
-
return {
|
|
579
|
-
kind,
|
|
580
|
-
name,
|
|
581
|
-
path: file,
|
|
582
|
-
fileBase,
|
|
583
|
-
ClassName: declaredClassName([
|
|
584
|
-
file
|
|
585
|
-
], 'Page', name)
|
|
586
|
-
};
|
|
587
|
-
}) : walk(node_path.join(reactFolder, 'widgets')).filter((file)=>file.endsWith(`-widget${component}`)).map((file)=>{
|
|
588
|
-
const folder = node_path.dirname(file);
|
|
589
|
-
const name = toPosix(node_path.relative(node_path.join(reactFolder, 'widgets'), folder));
|
|
590
|
-
return {
|
|
591
|
-
kind,
|
|
592
|
-
name,
|
|
593
|
-
path: folder,
|
|
594
|
-
fileBase: node_path.basename(file, `-widget${component}`),
|
|
595
|
-
ClassName: declaredClassName([
|
|
596
|
-
file,
|
|
597
|
-
node_path.join(folder, 'index.ts')
|
|
598
|
-
], 'Widget', name)
|
|
599
|
-
};
|
|
600
|
-
});
|
|
601
|
-
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
602
|
-
};
|
|
603
|
-
const targetPath = (reactFolder, module, rawName, framework)=>frontendKindLayouts(framework)[module.kind].target(reactFolder, new NestedName(reactModuleName(module.kind, rawName)));
|
|
604
|
-
const validateMove = (reactFolder, module, rawName, framework = 'react')=>{
|
|
605
|
-
const nameError = NestedName.validate(rawName);
|
|
606
|
-
if (true !== nameError) return nameError;
|
|
607
|
-
if (!reactKindLayouts[module.kind].nested && /[\\/]/.test(rawName)) return 'UI-kit components and shared hooks have no folders: enter a name without "/"';
|
|
608
|
-
const target = targetPath(reactFolder, module, rawName, framework);
|
|
609
|
-
if (target !== module.path && node_fs.existsSync(target)) return `${node_path.relative(reactFolder, target)} already exists`;
|
|
610
|
-
if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
|
|
611
|
-
return true;
|
|
612
|
-
};
|
|
613
|
-
const react_module_move_routeFolder = (appFolder, rawName)=>{
|
|
614
|
-
const { folders, folderName } = new NestedName(rawName);
|
|
615
|
-
return node_path.join(appFolder, ...folders, folderName);
|
|
616
|
-
};
|
|
617
|
-
const routeFiles = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(folder, {
|
|
618
|
-
withFileTypes: true
|
|
619
|
-
}).filter((entry)=>entry.isFile()).map((entry)=>node_path.join(folder, entry.name)) : [];
|
|
620
|
-
const moveReactModule = (projectRoot, reactFolder, module, rawName, route, framework = 'react')=>{
|
|
621
|
-
const layout = frontendKindLayouts(framework)[module.kind];
|
|
622
|
-
const newName = new NestedName(reactModuleName(module.kind, rawName));
|
|
623
|
-
const target = targetPath(reactFolder, module, rawName, framework);
|
|
624
|
-
const newClassName = newName.ClassName;
|
|
625
|
-
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.]|$)`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
626
|
-
const oldFolder = layout.inFolder ? module.path : node_path.dirname(module.path);
|
|
627
|
-
const newFolder = layout.inFolder ? target : node_path.dirname(target);
|
|
628
|
-
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));
|
|
629
|
-
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
630
|
-
const routeTarget = (candidate)=>{
|
|
631
|
-
if (!route) return;
|
|
632
|
-
const file = [
|
|
633
|
-
...routeFileSet
|
|
634
|
-
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
635
|
-
if (!file) return;
|
|
636
|
-
const moved = node_path.join(route.to, node_path.relative(route.from, file));
|
|
637
|
-
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
638
|
-
};
|
|
639
|
-
const movedPath = (candidate)=>{
|
|
640
|
-
const routed = routeTarget(candidate);
|
|
641
|
-
if (routed) return routed;
|
|
642
|
-
if (!ownsPath(candidate)) return;
|
|
643
|
-
const segments = node_path.relative(oldFolder, candidate).split(node_path.sep);
|
|
644
|
-
const last = segments.length - 1;
|
|
645
|
-
segments[last] = renameFile(segments[last]);
|
|
646
|
-
return node_path.join(newFolder, ...segments);
|
|
647
|
-
};
|
|
648
|
-
const moduleFiles = reactModuleFiles(module, framework);
|
|
649
|
-
const moves = new Map([
|
|
650
|
-
...moduleFiles,
|
|
651
|
-
...routeFileSet
|
|
652
|
-
].map((file)=>[
|
|
653
|
-
file,
|
|
654
|
-
movedPath(file) ?? file
|
|
655
|
-
]));
|
|
656
|
-
const classPattern = new RegExp(`(?<![\\w$])${layout.classPrefix}${escapeRegExp(module.ClassName)}(?=${layout.classSuffix})`, 'g');
|
|
657
|
-
const oldTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
658
|
-
module.ClassName
|
|
659
|
-
] : module.name.split('/').map((segment)=>new NestedName(segment).ClassName));
|
|
660
|
-
const titlePattern = oldTitle && new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
661
|
-
const newTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
662
|
-
newClassName
|
|
663
|
-
] : newName.classNameSegments);
|
|
664
|
-
return stageModuleMove({
|
|
665
|
-
projectRoot,
|
|
666
|
-
stopAt: reactFolder,
|
|
667
|
-
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
668
|
-
moves,
|
|
669
|
-
movedPath,
|
|
670
|
-
rename: (content, { moved })=>{
|
|
671
|
-
const renamed = content.replace(classPattern, (_, use)=>`${use ?? ''}${newClassName}`);
|
|
672
|
-
return moved && titlePattern ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
};
|
|
676
|
-
const routePageFile = {
|
|
677
|
-
react: 'page.tsx',
|
|
678
|
-
svelte: '+page.svelte'
|
|
679
|
-
};
|
|
680
|
-
const pageRouteFolder = (appFolder, page, framework = 'react')=>{
|
|
681
|
-
const folder = react_module_move_routeFolder(appFolder, page.name);
|
|
682
|
-
const routePage = node_path.join(folder, routePageFile[framework]);
|
|
683
|
-
return node_fs.existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(node_fs.readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
684
|
-
};
|
|
685
|
-
const reactModuleFiles = (module, framework)=>{
|
|
686
|
-
const layout = frontendKindLayouts(framework)[module.kind];
|
|
687
|
-
if (layout.inFolder) return walk(module.path);
|
|
688
|
-
const folder = node_path.dirname(module.path);
|
|
689
|
-
const own = layout.ownFile(module.fileBase);
|
|
690
|
-
return node_fs.readdirSync(folder, {
|
|
691
|
-
withFileTypes: true
|
|
692
|
-
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>node_path.join(folder, entry.name));
|
|
693
|
-
};
|
|
694
|
-
const importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
695
|
-
const deleteReactModule = (projectRoot, reactFolder, module, route, framework = 'react')=>{
|
|
696
|
-
const moduleFiles = reactModuleFiles(module, framework);
|
|
697
|
-
const routeFileList = route ? routeFiles(route.folder) : [];
|
|
698
|
-
const own = new Set([
|
|
699
|
-
...moduleFiles,
|
|
700
|
-
...routeFileList
|
|
701
|
-
]);
|
|
702
|
-
const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
|
|
703
|
-
const isModule = (resolved)=>stems.has(resolved) || moduleFiles.includes(resolved) || frontendKindLayouts(framework)[module.kind].inFolder && (resolved === module.path || resolved.startsWith(`${module.path}${node_path.sep}`));
|
|
704
|
-
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
705
|
-
const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
|
|
706
|
-
const usedBy = [];
|
|
707
|
-
for (const [file, content] of codeFiles)if (!own.has(file)) for (const [, , specifier] of content.matchAll(importSpecifier)){
|
|
708
|
-
const target = resolve(specifier, file)?.resolved;
|
|
709
|
-
if (target && isModule(target)) usedBy.push([
|
|
710
|
-
relative(file),
|
|
711
|
-
relative(target)
|
|
712
|
-
]);
|
|
713
|
-
}
|
|
714
|
-
if (usedBy.length) return {
|
|
715
|
-
usedBy
|
|
716
|
-
};
|
|
717
|
-
for (const file of moduleFiles)new File(file).delete(reactFolder);
|
|
718
|
-
for (const file of routeFileList)new File(file).delete(route.appFolder);
|
|
719
|
-
return {
|
|
720
|
-
deleted: [
|
|
721
|
-
...moduleFiles,
|
|
722
|
-
...routeFileList
|
|
723
|
-
]
|
|
724
|
-
};
|
|
725
|
-
};
|
|
726
|
-
const svelteComponentContent = (propsType)=>`
|
|
727
|
-
<script lang="ts" module>
|
|
728
|
-
export type ${propsType} = {}
|
|
729
|
-
</script>
|
|
730
|
-
|
|
731
|
-
<script lang="ts">
|
|
732
|
-
let props: ${propsType} = $props()
|
|
733
|
-
</script>
|
|
734
|
-
`.trim();
|
|
735
|
-
const svelteStory = (storybookFramework, componentName, componentFile, title)=>`
|
|
736
|
-
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
737
|
-
import ${componentName} from './${componentFile}'
|
|
738
|
-
|
|
739
|
-
const meta = {
|
|
740
|
-
title: '${title}',
|
|
741
|
-
component: ${componentName}
|
|
742
|
-
} satisfies Meta<typeof ${componentName}>
|
|
743
|
-
|
|
744
|
-
export default meta
|
|
745
|
-
|
|
746
|
-
type Story = StoryObj<typeof meta>
|
|
747
|
-
|
|
748
|
-
export const Default: Story = {
|
|
749
|
-
args: {}
|
|
750
|
-
}
|
|
751
|
-
`.trim();
|
|
752
|
-
const scaffold_svelte_modules_storybookFramework = ()=>ConfigFile.Instance.data.frontend?.svelte?.storybookFramework;
|
|
753
|
-
const svelteKitRouteContent = (ClassName, pageImport)=>`
|
|
754
|
-
<script lang="ts">
|
|
755
|
-
import ${ClassName}Page from '${pageImport}'
|
|
756
|
-
</script>
|
|
757
|
-
|
|
758
|
-
<${ClassName}Page />
|
|
759
|
-
`.trim();
|
|
760
|
-
const relativeImport = (fromFile, toFile)=>{
|
|
761
|
-
const relative = node_path.relative(node_path.dirname(fromFile), toFile).split(node_path.sep).join('/');
|
|
762
|
-
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
763
|
-
};
|
|
764
|
-
const scaffoldSvelteKitRoute = (name, pagePath)=>{
|
|
765
|
-
const root = new ProjectRoot().path;
|
|
766
|
-
const route = node_path.join(root, svelteKitRoutesFolder(root), ...name.folders, name.folderName, routePageFile.svelte);
|
|
767
|
-
const relativeRoute = node_path.relative(root, route).split(node_path.sep).join('/');
|
|
768
|
-
const routeFile = new File(route);
|
|
769
|
-
const content = svelteKitRouteContent(name.ClassName, relativeImport(route, pagePath));
|
|
770
|
-
if (routeFile.exists) return routeFile.data === content ? void 0 : `${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`;
|
|
771
|
-
routeFile.data = content;
|
|
772
|
-
};
|
|
773
|
-
const scaffoldSveltePage = async (presentationSvelteFolder)=>{
|
|
774
|
-
const name = await interaction_input({
|
|
775
|
-
key: 'name',
|
|
776
|
-
message: 'Provide name (folders split by "/"):',
|
|
777
|
-
validate: NestedName.validate
|
|
778
|
-
});
|
|
779
|
-
const nestedName = new NestedName(name);
|
|
780
|
-
const { folders, ClassName, fileName } = nestedName;
|
|
781
|
-
const pageFile = presentationSvelteFolder.subitem([
|
|
782
|
-
'pages',
|
|
783
|
-
...folders
|
|
784
|
-
]).createFile(`${fileName}-page.svelte`, svelteComponentContent(`${ClassName}PageProps`));
|
|
785
|
-
if (usesSvelteKit()) {
|
|
786
|
-
const hint = scaffoldSvelteKitRoute(nestedName, pageFile.path);
|
|
787
|
-
if (hint) report(hint);
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
const scaffoldSvelteWidget = async (presentationSvelteFolder)=>{
|
|
791
|
-
const widgetName = await interaction_input({
|
|
792
|
-
key: 'name',
|
|
793
|
-
message: 'Name (folders split by "/"): ',
|
|
794
|
-
validate: NestedName.validate
|
|
795
|
-
});
|
|
796
|
-
const widgetType = await interaction_select({
|
|
797
|
-
choices: [
|
|
798
|
-
'monolithic',
|
|
799
|
-
'with separated ui',
|
|
800
|
-
'headless'
|
|
801
|
-
],
|
|
802
|
-
key: 'widgetType',
|
|
803
|
-
message: 'Type: '
|
|
804
|
-
});
|
|
805
|
-
const { folders, folderName, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
|
|
806
|
-
const folder = presentationSvelteFolder.subitem([
|
|
807
|
-
'widgets',
|
|
808
|
-
...folders,
|
|
809
|
-
folderName
|
|
810
|
-
]);
|
|
811
|
-
const storyTitle = [
|
|
812
|
-
'Widgets',
|
|
813
|
-
...classNameSegments
|
|
814
|
-
].join('/');
|
|
815
|
-
const widgetFileName = `${fileName}-widget`;
|
|
816
|
-
const uiFileName = `${fileName}-widget-ui`;
|
|
817
|
-
const uiModelFileName = `use-${fileName}-ui-model`;
|
|
818
|
-
if ('monolithic' === widgetType) {
|
|
819
|
-
folder.createFile('index.ts', `
|
|
820
|
-
export { default as ${ClassName}Widget } from './${widgetFileName}.svelte'
|
|
821
|
-
export type { ${ClassName}WidgetProps } from './${widgetFileName}.svelte'
|
|
822
|
-
`.trim());
|
|
823
|
-
folder.createFile(`${widgetFileName}.svelte`, svelteComponentContent(`${ClassName}WidgetProps`));
|
|
824
|
-
return;
|
|
825
|
-
}
|
|
826
|
-
folder.createFile('index.ts', `
|
|
827
|
-
export { default as ${ClassName}Widget } from './${widgetFileName}.svelte'
|
|
828
|
-
export type { ${ClassName}WidgetProps } from './types'
|
|
829
|
-
`.trim());
|
|
830
|
-
if ('with separated ui' === widgetType) {
|
|
831
|
-
folder.createFile('types.ts', `
|
|
832
|
-
export type ${ClassName}WidgetProps = { }
|
|
833
|
-
|
|
834
|
-
export type ${ClassName}WidgetUIProps = { }
|
|
835
|
-
`.trim());
|
|
836
|
-
folder.createFile(`${widgetFileName}.svelte`, `
|
|
837
|
-
<script lang="ts">
|
|
838
|
-
import type { ${ClassName}WidgetProps } from './types'
|
|
839
|
-
import ${ClassName}WidgetUI from './ui/${uiFileName}.svelte'
|
|
840
|
-
import { use${ClassName}UIModel } from './hooks/${uiModelFileName}.svelte'
|
|
841
|
-
|
|
842
|
-
let props: ${ClassName}WidgetProps = $props()
|
|
843
|
-
const uiModel = use${ClassName}UIModel(props)
|
|
844
|
-
</script>
|
|
845
|
-
|
|
846
|
-
<${ClassName}WidgetUI {...uiModel} />
|
|
847
|
-
`.trim());
|
|
848
|
-
folder.subitem([
|
|
849
|
-
'ui'
|
|
850
|
-
]).createFile(`${uiFileName}.svelte`, `
|
|
851
|
-
<script lang="ts">
|
|
852
|
-
import type { ${ClassName}WidgetUIProps } from '../types'
|
|
853
|
-
|
|
854
|
-
let props: ${ClassName}WidgetUIProps = $props()
|
|
855
|
-
</script>
|
|
856
|
-
`.trim());
|
|
857
|
-
const framework = scaffold_svelte_modules_storybookFramework();
|
|
858
|
-
if (framework) folder.subitem([
|
|
859
|
-
'ui'
|
|
860
|
-
]).createFile(`${uiFileName}.stories.ts`, svelteStory(framework, `${ClassName}WidgetUI`, `${uiFileName}.svelte`, storyTitle));
|
|
861
|
-
folder.subitem([
|
|
862
|
-
'hooks'
|
|
863
|
-
]).createFile(`${uiModelFileName}.svelte.ts`, `
|
|
864
|
-
import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
|
|
865
|
-
|
|
866
|
-
export const use${ClassName}UIModel = (widgetProps: ${ClassName}WidgetProps): ${ClassName}WidgetUIProps => {
|
|
867
|
-
return {}
|
|
868
|
-
}
|
|
869
|
-
`.trim());
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
folder.createFile('types.ts', `
|
|
873
|
-
import type { Component } from 'svelte'
|
|
874
|
-
|
|
875
|
-
export type ${ClassName}WidgetUIProps = { }
|
|
876
|
-
|
|
877
|
-
export type ${ClassName}WidgetProps = {
|
|
878
|
-
UI: Component<${ClassName}WidgetUIProps>
|
|
879
|
-
}
|
|
880
|
-
`.trim());
|
|
881
|
-
folder.createFile(`${widgetFileName}.svelte`, `
|
|
882
|
-
<script lang="ts">
|
|
883
|
-
import type { ${ClassName}WidgetProps } from './types'
|
|
884
|
-
import { use${ClassName}UIModel } from './hooks/${uiModelFileName}.svelte'
|
|
885
|
-
|
|
886
|
-
let { UI, ...widgetProps }: ${ClassName}WidgetProps = $props()
|
|
887
|
-
const uiModel = use${ClassName}UIModel(widgetProps)
|
|
888
|
-
</script>
|
|
889
|
-
|
|
890
|
-
<UI {...uiModel} />
|
|
891
|
-
`.trim());
|
|
892
|
-
folder.subitem([
|
|
893
|
-
'hooks'
|
|
894
|
-
]).createFile(`${uiModelFileName}.svelte.ts`, `
|
|
895
|
-
import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
|
|
896
|
-
|
|
897
|
-
export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps, 'UI'>): ${ClassName}WidgetUIProps => {
|
|
898
|
-
return {}
|
|
899
|
-
}
|
|
900
|
-
`.trim());
|
|
901
|
-
};
|
|
902
|
-
const scaffoldSvelteUIKitComponent = async (presentationSvelteFolder)=>{
|
|
903
|
-
const name = await interaction_input({
|
|
904
|
-
key: 'name',
|
|
905
|
-
message: 'Name: '
|
|
906
|
-
});
|
|
907
|
-
const { ClassName, fileName } = new UnknownFormatNaming(name);
|
|
908
|
-
const componentFolder = presentationSvelteFolder.subitem([
|
|
909
|
-
'ui-kit',
|
|
910
|
-
fileName
|
|
911
|
-
]);
|
|
912
|
-
componentFolder.createFile('index.ts', `
|
|
913
|
-
export { default as ${ClassName} } from './${fileName}.svelte'
|
|
914
|
-
export type { ${ClassName}Props } from './${fileName}.svelte'
|
|
915
|
-
`.trim());
|
|
916
|
-
componentFolder.createFile(`${fileName}.svelte`, svelteComponentContent(`${ClassName}Props`));
|
|
917
|
-
const framework = scaffold_svelte_modules_storybookFramework();
|
|
918
|
-
if (framework) componentFolder.createFile(`${fileName}.stories.ts`, svelteStory(framework, ClassName, `${fileName}.svelte`, `UI-kit/${ClassName}`));
|
|
919
|
-
};
|
|
920
|
-
const scaffoldSvelteSharedHook = async (presentationSvelteFolder)=>{
|
|
921
|
-
const name = await interaction_input({
|
|
922
|
-
key: 'name',
|
|
923
|
-
message: 'Name without "use" (e.g. debounce): '
|
|
924
|
-
});
|
|
925
|
-
const { ClassName, fileName } = new UnknownFormatNaming(name.trim().replace(/^use-/, ''));
|
|
926
|
-
presentationSvelteFolder.subitem([
|
|
927
|
-
'hooks'
|
|
928
|
-
]).createFile(`use-${fileName}.svelte.ts`, `
|
|
929
|
-
export const use${ClassName} = () => {
|
|
930
|
-
return {}
|
|
931
|
-
}
|
|
932
|
-
`.trim());
|
|
933
|
-
};
|
|
934
|
-
const openapiScriptPath = "scripts/generate-openapi.ts";
|
|
935
|
-
const defaultOpenapiPath = ()=>usesNext() ? 'public/openapi.json' : usesSvelteKit() ? 'static/openapi.json' : 'openapi.json';
|
|
936
|
-
const extractorPackages = [
|
|
937
|
-
'ts-morph',
|
|
938
|
-
'@microsoft/tsdoc'
|
|
939
|
-
];
|
|
940
|
-
const swaggerPagePath = (rootFolder, framework = 'react')=>node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'svelte' === framework ? 'presentation/svelte/pages/swagger-page.svelte' : 'presentation/react/pages/swagger-page.tsx');
|
|
941
|
-
const specImportOf = (pagePath, outputPath)=>{
|
|
942
|
-
const specImport = node_path.posix.relative(node_path.posix.dirname(pagePath), outputPath);
|
|
943
|
-
return specImport.startsWith('.') ? specImport : `./${specImport}`;
|
|
944
|
-
};
|
|
945
|
-
const swaggerPage = (rootFolder, outputPath, withNext = false)=>{
|
|
946
|
-
const page = reactPageContent('Swagger', {
|
|
947
|
-
imports: [
|
|
948
|
-
"import 'swagger-ui-react/swagger-ui.css'",
|
|
949
|
-
"import SwaggerUI from 'swagger-ui-react'",
|
|
950
|
-
`import spec from '${specImportOf(swaggerPagePath(rootFolder), outputPath)}' with { type: 'json' }`
|
|
951
|
-
],
|
|
952
|
-
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
953
|
-
});
|
|
954
|
-
return withNext ? `'use client'\n\n${page}` : page;
|
|
955
|
-
};
|
|
956
|
-
const svelteSwaggerPage = (rootFolder, outputPath)=>`
|
|
957
|
-
<script lang="ts" module>
|
|
958
|
-
export type SwaggerPageProps = {}
|
|
959
|
-
</script>
|
|
960
|
-
|
|
961
|
-
<script lang="ts">
|
|
962
|
-
import 'swagger-ui/dist/swagger-ui.css'
|
|
963
|
-
import { onMount } from 'svelte'
|
|
964
|
-
import spec from '${specImportOf(swaggerPagePath(rootFolder, 'svelte'), outputPath)}'
|
|
965
|
-
|
|
966
|
-
let props: SwaggerPageProps = $props()
|
|
967
|
-
let container: HTMLDivElement
|
|
968
|
-
|
|
969
|
-
onMount(async () => {
|
|
970
|
-
const { default: SwaggerUI } = await import('swagger-ui')
|
|
971
|
-
SwaggerUI({ domNode: container, spec, displayOperationId: true })
|
|
972
|
-
})
|
|
973
|
-
</script>
|
|
974
|
-
|
|
975
|
-
<div bind:this={container}></div>
|
|
976
|
-
`.trim();
|
|
977
|
-
const swaggerPackages = {
|
|
978
|
-
react: {
|
|
979
|
-
dependency: 'swagger-ui-react',
|
|
980
|
-
types: '@types/swagger-ui-react'
|
|
981
|
-
},
|
|
982
|
-
svelte: {
|
|
983
|
-
dependency: 'swagger-ui',
|
|
984
|
-
types: '@types/swagger-ui'
|
|
985
|
-
}
|
|
986
|
-
};
|
|
987
|
-
const openapiScripts = {
|
|
988
|
-
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
989
|
-
};
|
|
990
|
-
const splitPath = (value)=>value.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
991
|
-
const apiTitle = (packageName)=>{
|
|
992
|
-
const words = String(packageName ?? '').replace(/^@[^/]*\//, '').split(/[^a-zA-Z0-9]+/).filter((word)=>!!word).map((word)=>word[0].toUpperCase() + word.slice(1));
|
|
993
|
-
return [
|
|
994
|
-
...words,
|
|
995
|
-
'API'
|
|
996
|
-
].join(' ');
|
|
997
|
-
};
|
|
998
|
-
const openapiGenerator = (rootFolder, title, routePrefix, outputPath, withExtractor = false)=>{
|
|
999
|
-
const restFolder = node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/rest');
|
|
1000
|
-
const restImport = node_path.posix.relative(node_path.posix.dirname(openapiScriptPath), restFolder);
|
|
1001
|
-
const prefixSegments = splitPath(routePrefix);
|
|
1002
|
-
const apiRoutePrefix = prefixSegments.length ? `\n apiRoutePrefix: [${prefixSegments.map((segment)=>`'${segment}'`).join(', ')}],` : '';
|
|
1003
|
-
const extractorImport = `./${node_path.posix.relative(node_path.posix.dirname(openapiScriptPath), openapiExtractorPath.replace(/\.ts$/, ''))}`;
|
|
1004
|
-
const handlers = withExtractor ? `
|
|
1005
|
-
const extractOpenApiDataFromEndpointLogic =
|
|
1006
|
-
createOpenApiDataFromEndpointLogicExtractor();
|
|
1007
|
-
|
|
1008
|
-
const handlers = restHandlers.map((x) => ({
|
|
1009
|
-
...x,
|
|
1010
|
-
metadata: {
|
|
1011
|
-
...x.metadata,
|
|
1012
|
-
openApiMetadata: {
|
|
1013
|
-
...extractOpenApiDataFromEndpointLogic(x.metadata.route),
|
|
1014
|
-
...(x.metadata.openApiMetadata ?? {})
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}));
|
|
1018
|
-
` : '';
|
|
1019
|
-
return `import { generateOpenAPI } from '@domain-first/handlers-rest';
|
|
1020
|
-
import { restHandlers } from '${restImport.startsWith('.') ? restImport : `./${restImport}`}';${withExtractor ? `\nimport { createOpenApiDataFromEndpointLogicExtractor } from '${extractorImport}';` : ''}
|
|
1021
|
-
${handlers}
|
|
1022
|
-
generateOpenAPI(${withExtractor ? 'handlers' : 'restHandlers'}, {
|
|
1023
|
-
document: { info: { title: '${title}', version: '1.0.0' } },${apiRoutePrefix}
|
|
1024
|
-
outputFile: { path: '${outputPath}' }
|
|
1025
|
-
});
|
|
1026
|
-
`;
|
|
1027
|
-
};
|
|
1028
|
-
const addOpenapi = async ()=>{
|
|
1029
|
-
const { rootFolder } = ConfigFile.Instance.data.project;
|
|
1030
|
-
const root = new ProjectRoot().path;
|
|
1031
|
-
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
1032
|
-
const manifest = JSON.parse(manifestFile.data);
|
|
1033
|
-
const dependencies = {
|
|
1034
|
-
...manifest.dependencies,
|
|
1035
|
-
...manifest.devDependencies
|
|
1036
|
-
};
|
|
1037
|
-
const routePrefix = await interaction_input({
|
|
1038
|
-
key: 'routePrefix',
|
|
1039
|
-
message: 'Route prefix the REST handlers are served under:',
|
|
1040
|
-
default: '/api'
|
|
1041
|
-
});
|
|
1042
|
-
const outputPath = await interaction_input({
|
|
1043
|
-
key: 'openapiPath',
|
|
1044
|
-
message: 'OpenAPI document path:',
|
|
1045
|
-
default: defaultOpenapiPath(),
|
|
1046
|
-
validate: (value)=>splitPath(value).length ? true : 'Path is required'
|
|
1047
|
-
});
|
|
1048
|
-
const withExtractor = await interaction_confirm({
|
|
1049
|
-
key: 'withExtractor',
|
|
1050
|
-
message: "Fill operationId, summary and description from the endpoint logic TSDoc?",
|
|
1051
|
-
default: true
|
|
1052
|
-
});
|
|
1053
|
-
const { frontend } = ConfigFile.Instance.data;
|
|
1054
|
-
const framework = frontend?.svelte ? 'svelte' : frontend?.react ? 'react' : void 0;
|
|
1055
|
-
const withSwaggerPage = !!framework && await interaction_confirm({
|
|
1056
|
-
key: 'swaggerPage',
|
|
1057
|
-
message: 'Add a Swagger UI page?',
|
|
1058
|
-
default: true
|
|
1059
|
-
});
|
|
1060
|
-
const selected = await addPackageScripts(manifestFile, openapiScripts);
|
|
1061
|
-
if (withExtractor) {
|
|
1062
|
-
const extractorFile = new File(node_path.join(root, openapiExtractorPath));
|
|
1063
|
-
const extractor = openapiExtractor(rootFolder);
|
|
1064
|
-
if (!extractorFile.exists || extractorFile.data !== extractor) extractorFile.data = extractor;
|
|
1065
|
-
}
|
|
1066
|
-
const generatorFile = new File(node_path.join(root, openapiScriptPath));
|
|
1067
|
-
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
1068
|
-
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
1069
|
-
const routeFile = withSwaggerPage && 'react' === framework && usesNext() ? `${nextAppFolder(root)}/swagger/page.tsx` : withSwaggerPage && 'svelte' === framework && usesSvelteKit() ? `${svelteKitRoutesFolder(root)}/swagger/+page.svelte` : void 0;
|
|
1070
|
-
let routeHint;
|
|
1071
|
-
if (withSwaggerPage) {
|
|
1072
|
-
const pagePath = node_path.join(root, swaggerPagePath(rootFolder, framework));
|
|
1073
|
-
const pageFile = new File(pagePath);
|
|
1074
|
-
const page = 'svelte' === framework ? svelteSwaggerPage(rootFolder, splitPath(outputPath).join('/')) : swaggerPage(rootFolder, splitPath(outputPath).join('/'), !!routeFile);
|
|
1075
|
-
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
1076
|
-
if (routeFile) routeHint = ('svelte' === framework ? scaffoldSvelteKitRoute : scaffoldNextRoute)(new NestedName('swagger'), pagePath);
|
|
1077
|
-
}
|
|
1078
|
-
const packages = swaggerPackages[framework ?? 'react'];
|
|
1079
|
-
const resolveJsonModule = withSwaggerPage ? compilerOption(node_path.join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
1080
|
-
const hasRestHandlers = new File(node_path.join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
1081
|
-
const missingExtractorPackages = withExtractor ? extractorPackages.filter((name)=>!dependencies[name]) : [];
|
|
1082
|
-
return [
|
|
1083
|
-
...dependencies['@domain-first/handlers-rest'] ? [] : [
|
|
1084
|
-
'npm install @domain-first/handlers-rest'
|
|
1085
|
-
],
|
|
1086
|
-
...dependencies.tsx ? [] : [
|
|
1087
|
-
'npm install --save-dev tsx'
|
|
1088
|
-
],
|
|
1089
|
-
...missingExtractorPackages.length ? [
|
|
1090
|
-
`npm install --save-dev ${missingExtractorPackages.join(' ')}`
|
|
1091
|
-
] : [],
|
|
1092
|
-
...withSwaggerPage && !dependencies[packages.dependency] ? [
|
|
1093
|
-
`npm install ${packages.dependency}`
|
|
1094
|
-
] : [],
|
|
1095
|
-
...withSwaggerPage && !dependencies[packages.types] ? [
|
|
1096
|
-
`npm install --save-dev ${packages.types}`
|
|
1097
|
-
] : [],
|
|
1098
|
-
...true === resolveJsonModule || null === resolveJsonModule ? [] : [
|
|
1099
|
-
'set "resolveJsonModule": true in compilerOptions of tsconfig.json — the Swagger UI page imports the OpenAPI document as JSON'
|
|
1100
|
-
],
|
|
1101
|
-
...describeScripts(selected, {
|
|
1102
|
-
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
1103
|
-
}),
|
|
1104
|
-
...withSwaggerPage && !routeFile ? [
|
|
1105
|
-
`SwaggerPage from ${swaggerPagePath(rootFolder, framework)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
1106
|
-
] : [],
|
|
1107
|
-
...routeFile ? [
|
|
1108
|
-
routeHint ?? `/swagger shows ${splitPath(outputPath).join('/')} once it is generated — the route is ${routeFile}`
|
|
1109
|
-
] : [],
|
|
1110
|
-
...hasRestHandlers ? [] : [
|
|
1111
|
-
`restHandlers appear in ${node_path.posix.join(rootFolder, 'presentation/rest/index.ts')} with the first REST endpoint generated with @domain-first/wire`
|
|
1112
|
-
]
|
|
1113
|
-
];
|
|
1114
|
-
};
|
|
1115
184
|
const addGitignoreEntry = (root, entry)=>{
|
|
1116
185
|
const gitignore = new File(node_path.join(root, '.gitignore'));
|
|
1117
186
|
const ignored = gitignore.exists ? gitignore.data : '';
|
|
@@ -1290,7 +359,7 @@ const addOrval = async ()=>{
|
|
|
1290
359
|
message: 'Generate:',
|
|
1291
360
|
choices: [
|
|
1292
361
|
{
|
|
1293
|
-
name: 'svelte' === framework ? 'Svelte Query
|
|
362
|
+
name: 'svelte' === framework ? 'Svelte Query (createQuery)' : 'React Query hooks',
|
|
1294
363
|
value: 'hooks',
|
|
1295
364
|
checked: true
|
|
1296
365
|
},
|
|
@@ -1883,7 +952,7 @@ const scaffoldCatchAllRoute = (root, adapter)=>{
|
|
|
1883
952
|
'presentation',
|
|
1884
953
|
'rest'
|
|
1885
954
|
]);
|
|
1886
|
-
new File(routeFile).data = catchAllRoute(adapter,
|
|
955
|
+
new File(routeFile).data = catchAllRoute(adapter, relativeImport(routeFile, restFolder.path));
|
|
1887
956
|
return new File(node_path.join(restFolder.path, 'index.ts')).exists ? [] : [
|
|
1888
957
|
`${routePath} serves restHandlers from ${node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/rest/index.ts')}, which appears with the first REST endpoint — generate one with df-scaffold (Presentation → New Handlers-REST Endpoint) and the route compiles`
|
|
1889
958
|
];
|
|
@@ -2213,7 +1282,7 @@ const aggregateOwnFiles = (name)=>[
|
|
|
2213
1282
|
`${name}-repository.spec.ts`,
|
|
2214
1283
|
'index.ts'
|
|
2215
1284
|
];
|
|
2216
|
-
const
|
|
1285
|
+
const kindLayouts = {
|
|
2217
1286
|
aggregate: {
|
|
2218
1287
|
title: 'Aggregates',
|
|
2219
1288
|
core: (ClassName)=>`${ClassName}Repository`,
|
|
@@ -2270,7 +1339,7 @@ const projectRootOf = (folder)=>{
|
|
|
2270
1339
|
}
|
|
2271
1340
|
};
|
|
2272
1341
|
const integrationSpecFile = (unit, label)=>{
|
|
2273
|
-
const layout =
|
|
1342
|
+
const layout = kindLayouts[unit.kind];
|
|
2274
1343
|
const place = {
|
|
2275
1344
|
ownerPath: unit.ownerPath,
|
|
2276
1345
|
name: unit.name
|
|
@@ -2296,9 +1365,9 @@ const subfolders = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(fo
|
|
|
2296
1365
|
}).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name).sort() : [];
|
|
2297
1366
|
const namesBySuffix = (folder, suffix)=>node_fs.existsSync(folder) ? node_fs.readdirSync(folder).filter((file)=>file.endsWith(suffix) && !file.endsWith('.spec.ts')).map((file)=>file.slice(0, -suffix.length)).sort() : [];
|
|
2298
1367
|
const labelsOf = (ownerPath, kind, name)=>{
|
|
2299
|
-
const { implementations } =
|
|
1368
|
+
const { implementations } = kindLayouts[kind];
|
|
2300
1369
|
if (!implementations) return [];
|
|
2301
|
-
return subfolders(node_path.join(ownerPath, implementations)).filter((label)=>
|
|
1370
|
+
return subfolders(node_path.join(ownerPath, implementations)).filter((label)=>kindLayouts[kind].files({
|
|
2302
1371
|
ownerPath,
|
|
2303
1372
|
name
|
|
2304
1373
|
}, [
|
|
@@ -2336,7 +1405,7 @@ const findBackendUnits = (ownerPath)=>{
|
|
|
2336
1405
|
const kebabName = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
2337
1406
|
const lowerFirst = (value)=>value[0].toLowerCase() + value.slice(1);
|
|
2338
1407
|
const unitMoves = (unit, target)=>{
|
|
2339
|
-
const layout =
|
|
1408
|
+
const layout = kindLayouts[unit.kind];
|
|
2340
1409
|
const from = layout.files(unit, unit.labels);
|
|
2341
1410
|
const to = layout.files(target, unit.labels);
|
|
2342
1411
|
const moves = new Map();
|
|
@@ -2357,13 +1426,13 @@ const unitMoves = (unit, target)=>{
|
|
|
2357
1426
|
const oldFolder = node_path.join(unit.ownerPath, 'domain/aggregates', unit.name);
|
|
2358
1427
|
const newFolder = node_path.join(target.ownerPath, 'domain/aggregates', target.name);
|
|
2359
1428
|
const own = new Set(aggregateOwnFiles(unit.name).map((file)=>node_path.join(oldFolder, file)));
|
|
2360
|
-
for (const file of
|
|
1429
|
+
for (const file of module_move_walk(oldFolder))if (!own.has(file)) moves.set(file, node_path.join(newFolder, node_path.relative(oldFolder, file)));
|
|
2361
1430
|
}
|
|
2362
1431
|
return moves;
|
|
2363
1432
|
};
|
|
2364
1433
|
const validateBackendMove = (unit, target, sharedKernelPath)=>{
|
|
2365
1434
|
if (!kebabName.test(target.name)) return 'Use kebab-case: lowercase words split by "-", e.g. place-order';
|
|
2366
|
-
if (target.ownerPath === sharedKernelPath && !
|
|
1435
|
+
if (target.ownerPath === sharedKernelPath && !kindLayouts[unit.kind].sharedKernel) return `${kindLayouts[unit.kind].title} are not part of the Shared Kernel`;
|
|
2367
1436
|
if (target.ownerPath === unit.ownerPath && target.name === unit.name && target.aggregate === unit.aggregate) return 'Nothing to change: enter a new name or pick another place';
|
|
2368
1437
|
for (const [from, to] of unitMoves(unit, target))if (to !== from && node_fs.existsSync(to)) return `${node_path.relative(target.ownerPath, to)} already exists`;
|
|
2369
1438
|
return true;
|
|
@@ -2392,7 +1461,7 @@ const isolationAllows = (rootFolderPath, from, to)=>{
|
|
|
2392
1461
|
return inside('domain/errors') || from.replace(codeExtension, '') === inMemoryDbFile(rootFolderPath).replace(codeExtension, '') && inside('domain');
|
|
2393
1462
|
};
|
|
2394
1463
|
const moveBackendUnit = (projectRoot, rootFolderPath, unit, target)=>{
|
|
2395
|
-
const layout =
|
|
1464
|
+
const layout = kindLayouts[unit.kind];
|
|
2396
1465
|
const moves = unitMoves(unit, target);
|
|
2397
1466
|
const withoutExtension = new Map([
|
|
2398
1467
|
...moves
|
|
@@ -2537,7 +1606,7 @@ const projectRelative = (fromFile, toFile)=>{
|
|
|
2537
1606
|
const relative = toPosix(node_path.relative(node_path.dirname(fromFile), toFile.replace(codeExtension, '')));
|
|
2538
1607
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
2539
1608
|
};
|
|
2540
|
-
const
|
|
1609
|
+
const importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
2541
1610
|
const importLine = /^\s*(?:import|export)\b[^'"\n]*\bfrom\s*(['"])([^'"\n]+)\1;?\s*$/;
|
|
2542
1611
|
const deleteBackendUnit = (projectRoot, rootFolderPath, unit)=>{
|
|
2543
1612
|
const files = [
|
|
@@ -2579,7 +1648,7 @@ const deleteBackendUnit = (projectRoot, rootFolderPath, unit)=>{
|
|
|
2579
1648
|
for (const [file, original] of codeFiles){
|
|
2580
1649
|
if (fileSet.has(file)) continue;
|
|
2581
1650
|
const content = cleaned.get(file) ?? original;
|
|
2582
|
-
for (const [, , specifier] of content.matchAll(
|
|
1651
|
+
for (const [, , specifier] of content.matchAll(importSpecifier)){
|
|
2583
1652
|
const target = resolved(specifier, file);
|
|
2584
1653
|
if (target && isUnit(target)) usedBy.push([
|
|
2585
1654
|
relative(file),
|
|
@@ -2614,18 +1683,18 @@ const contractKinds = [
|
|
|
2614
1683
|
];
|
|
2615
1684
|
const implementations_withWiring = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
2616
1685
|
const withHandlers = ()=>ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers');
|
|
2617
|
-
const contractFile = (unit)=>'aggregate' === unit.kind ? `domain/aggregates/${unit.name}/${unit.name}-repository.ts` :
|
|
1686
|
+
const contractFile = (unit)=>'aggregate' === unit.kind ? `domain/aggregates/${unit.name}/${unit.name}-repository.ts` : kindLayouts[unit.kind].files(unit, [])[0];
|
|
2618
1687
|
const findContracts = (ownerPath)=>findBackendUnits(ownerPath).filter((unit)=>contractKinds.includes(unit.kind) && node_fs.existsSync(node_path.join(ownerPath, contractFile(unit))));
|
|
2619
1688
|
const implementationWireName = (label)=>`wire${new UnknownFormatNaming(label).ClassName}Implementation`;
|
|
2620
|
-
const contractClassName = (unit)=>
|
|
1689
|
+
const contractClassName = (unit)=>kindLayouts[unit.kind].core(new UnknownFormatNaming(unit.name).ClassName);
|
|
2621
1690
|
const implementationClassName = (unit, label)=>`${new UnknownFormatNaming(label).ClassName}${contractClassName(unit)}`;
|
|
2622
1691
|
const implementationFile = (unit, label)=>{
|
|
2623
|
-
const { implementations } =
|
|
2624
|
-
return
|
|
1692
|
+
const { implementations } = kindLayouts[unit.kind];
|
|
1693
|
+
return kindLayouts[unit.kind].files(unit, [
|
|
2625
1694
|
label
|
|
2626
1695
|
]).find((file)=>file.startsWith(`${implementations}/`));
|
|
2627
1696
|
};
|
|
2628
|
-
const contractWireFile = (unit)=>
|
|
1697
|
+
const contractWireFile = (unit)=>kindLayouts[unit.kind].files(unit, []).find((file)=>file.startsWith('wiring/'));
|
|
2629
1698
|
const handlerImplementation = (ContractName, ClassName, contractImport)=>withHandlers() ? `
|
|
2630
1699
|
import { defineHandler } from '@domain-first/handlers'
|
|
2631
1700
|
import { ${ContractName} } from '${contractImport}'
|
|
@@ -2791,7 +1860,7 @@ const scaffoldIntegrationSpec = (unit, label)=>{
|
|
|
2791
1860
|
if (!specPath) return;
|
|
2792
1861
|
const spec = new File(specPath);
|
|
2793
1862
|
if (spec.exists) return;
|
|
2794
|
-
const layout =
|
|
1863
|
+
const layout = kindLayouts[unit.kind];
|
|
2795
1864
|
const naming = new UnknownFormatNaming(unit.name);
|
|
2796
1865
|
const core = layout.core(naming.ClassName);
|
|
2797
1866
|
const files = layout.files({
|
|
@@ -3448,10 +2517,10 @@ const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3448
2517
|
key: 'module',
|
|
3449
2518
|
id: unitId,
|
|
3450
2519
|
message: 'Module to delete:',
|
|
3451
|
-
choices: Object.keys(
|
|
2520
|
+
choices: Object.keys(kindLayouts).flatMap((kind)=>{
|
|
3452
2521
|
const group = units.filter((x)=>x.kind === kind);
|
|
3453
2522
|
return group.length ? [
|
|
3454
|
-
new Separator(`── ${
|
|
2523
|
+
new Separator(`── ${kindLayouts[group[0].kind].title}`),
|
|
3455
2524
|
...group.map((value)=>({
|
|
3456
2525
|
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
3457
2526
|
value
|
|
@@ -3515,11 +2584,11 @@ const frameworkTitles = {
|
|
|
3515
2584
|
const deleteReactModuleUseCase = async (presentationReactFolder, kind, framework = 'react')=>{
|
|
3516
2585
|
const reactFolder = presentationReactFolder.path;
|
|
3517
2586
|
const modules = findReactModules(reactFolder, kind, framework);
|
|
3518
|
-
if (!modules.length) return void report(`No ${
|
|
2587
|
+
if (!modules.length) return void report(`No ${frontendKindTitles(framework)[kind][1]} generated by ${frameworkTitles[framework].cli} were found.`);
|
|
3519
2588
|
const module = await interaction_select({
|
|
3520
2589
|
key: 'module',
|
|
3521
2590
|
id: (value)=>value.name,
|
|
3522
|
-
message: `${
|
|
2591
|
+
message: `${frontendKindTitles(framework)[kind][0]} to delete:`,
|
|
3523
2592
|
choices: modules.map((value)=>({
|
|
3524
2593
|
name: value.name,
|
|
3525
2594
|
value,
|
|
@@ -3878,10 +2947,10 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3878
2947
|
key: 'module',
|
|
3879
2948
|
id: unitId,
|
|
3880
2949
|
message: 'Module:',
|
|
3881
|
-
choices: Object.keys(
|
|
2950
|
+
choices: Object.keys(kindLayouts).flatMap((kind)=>{
|
|
3882
2951
|
const group = units.filter((x)=>x.kind === kind);
|
|
3883
2952
|
return group.length ? [
|
|
3884
|
-
new Separator(`── ${
|
|
2953
|
+
new Separator(`── ${kindLayouts[group[0].kind].title}`),
|
|
3885
2954
|
...group.map((value)=>({
|
|
3886
2955
|
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
3887
2956
|
value
|
|
@@ -3895,7 +2964,7 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3895
2964
|
const places = [
|
|
3896
2965
|
unit.ownerPath,
|
|
3897
2966
|
...contexts,
|
|
3898
|
-
...
|
|
2967
|
+
...kindLayouts[unit.kind].sharedKernel ? [
|
|
3899
2968
|
sharedKernelPath
|
|
3900
2969
|
] : []
|
|
3901
2970
|
].filter((place, index, all)=>all.indexOf(place) === index);
|
|
@@ -3986,11 +3055,11 @@ const promptRouteMove = async (root, page, newName, framework)=>{
|
|
|
3986
3055
|
const moveReactModuleUseCase = async (presentationReactFolder, kind, framework = 'react')=>{
|
|
3987
3056
|
const reactFolder = presentationReactFolder.path;
|
|
3988
3057
|
const modules = findReactModules(reactFolder, kind, framework);
|
|
3989
|
-
if (!modules.length) return void report(`No ${
|
|
3058
|
+
if (!modules.length) return void report(`No ${frontendKindTitles(framework)[kind][1]} generated by ${frameworkTitles[framework].cli} were found.`);
|
|
3990
3059
|
const module = await interaction_select({
|
|
3991
3060
|
key: 'module',
|
|
3992
3061
|
id: (value)=>value.name,
|
|
3993
|
-
message: `${
|
|
3062
|
+
message: `${frontendKindTitles(framework)[kind][0]}:`,
|
|
3994
3063
|
choices: modules.map((value)=>({
|
|
3995
3064
|
name: value.name,
|
|
3996
3065
|
value,
|
|
@@ -4729,8 +3798,8 @@ const scaffoldNewHandlersRestEndpoint = async (boundedContextFolder)=>{
|
|
|
4729
3798
|
const handler = withWiring ? await promptEndpointHandler(boundedContextFolder) : void 0;
|
|
4730
3799
|
const endpointFile = node_path.join(endpointFolder.path, `${method.toUpperCase()}.ts`);
|
|
4731
3800
|
endpointFolder.createFile(`${method.toUpperCase()}.ts`, `
|
|
4732
|
-
${endpointGenerator ? `import type { ${endpointGenerator.typeName} } from '${
|
|
4733
|
-
import type { ${handler.typeName} } from '${
|
|
3801
|
+
${endpointGenerator ? `import type { ${endpointGenerator.typeName} } from '${relativeImport(endpointFile, endpointGenerator.typeFile)}'` : "import { EndpointGenerator } from '@domain-first/handlers-rest'"}${handler ? `
|
|
3802
|
+
import type { ${handler.typeName} } from '${relativeImport(endpointFile, handler.typeFile)}'` : ''}
|
|
4734
3803
|
|
|
4735
3804
|
export class ${endpointClassName} {
|
|
4736
3805
|
constructor(
|
|
@@ -4762,8 +3831,8 @@ export class ${endpointClassName} {
|
|
|
4762
3831
|
].filter((x)=>!!x) : [];
|
|
4763
3832
|
wiringFolder.createFile(`${wireNaming.fileName}.ts`, `
|
|
4764
3833
|
import { wireClass } from '@domain-first/wire'
|
|
4765
|
-
import { ${endpointClassName} } from '${
|
|
4766
|
-
${dependencies.map((x)=>`import { ${x.wireName} } from '${
|
|
3834
|
+
import { ${endpointClassName} } from '${relativeImport(wireFile, endpointFile)}'
|
|
3835
|
+
${dependencies.map((x)=>`import { ${x.wireName} } from '${relativeImport(wireFile, x.wireFile)}'`).join('\n')}
|
|
4767
3836
|
|
|
4768
3837
|
export const wire${endpointClassName} = wireClass(
|
|
4769
3838
|
${endpointClassName},
|
|
@@ -4887,7 +3956,7 @@ const scaffoldNewImplementation = async (ownerFolder)=>{
|
|
|
4887
3956
|
}) && primaryRole;
|
|
4888
3957
|
const before = readWiredModule(wireFile.path, ownerFolder.path);
|
|
4889
3958
|
wireFile.update(addBranchedImplementation(wireFile.data, wireName, {
|
|
4890
|
-
importLine: `import { ${className} } from '${
|
|
3959
|
+
importLine: `import { ${className} } from '${relativeImport(wireFile.path, file.path)}'`,
|
|
4891
3960
|
className,
|
|
4892
3961
|
wireName: implementationWireName(label),
|
|
4893
3962
|
environments: chosenEnvironments
|
|
@@ -5315,4 +4384,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
5315
4384
|
break;
|
|
5316
4385
|
}
|
|
5317
4386
|
};
|
|
5318
|
-
export {
|
|
4387
|
+
export { addIntegration, configurationSections, deleteBackendUnitUseCase, deleteReactModuleUseCase, findBackendUnits, findContracts, findRestEndpointGenerator, frameworkTitles, helperImplementationTypes, initializeUseCase, integrationDescriptions, integrationIds, integrationSpecFile, integrationSpecsAvailable, moduleId, moveBackendUnitUseCase, moveReactModuleUseCase, printNextSteps, rootControllerChoice, savePendingChanges, savedImplementations, scaffoldNewAggregateUseCase, scaffoldNewApplicationPort, scaffoldNewApplicationService, scaffoldNewBoundedContextUseCase, scaffoldNewCommand, scaffoldNewDomainObject, scaffoldNewDomainService, scaffoldNewErrorUseCase, scaffoldNewHandlersRestEndpoint, scaffoldNewImplementation, scaffoldNewInfrastructureHelper, scaffoldNewInfrastructureService, scaffoldNewPresentationService, scaffoldNewQuery, scaffoldNewUseCase, scaffoldReactSharedHook, scaffoldReactUIKitComponent, scaffoldReactWidget, systemImplementationChoices, unitId, wireDependency };
|