@domain-first/project-structure 8.10.1 → 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 +17 -7
- package/dist/287.js +406 -788
- package/dist/364.js +79 -0
- package/dist/38.js +31 -14
- package/dist/561.js +179 -96
- package/dist/783.js +1147 -0
- package/dist/{201.js → 878.js} +465 -2
- package/dist/agent-cli.d.ts +17 -6
- package/dist/agent-requests.d.ts +82 -8
- package/dist/config-file.d.ts +25 -1
- package/dist/frontend-cli.d.ts +3 -0
- package/dist/frontend-modules.d.ts +14 -0
- package/dist/graph.cjs +125 -5
- package/dist/graph.js +1 -1
- package/dist/index.cjs +3545 -2930
- package/dist/index.js +1 -1
- package/dist/init.cjs +368 -83
- package/dist/init.js +1 -1
- package/dist/integration.cjs +3545 -2930
- package/dist/integration.js +1 -1
- package/dist/integrations/openapi.d.ts +19 -2
- package/dist/integrations/orval.d.ts +31 -4
- package/dist/integrations/rest-endpoint-generator.d.ts +11 -7
- package/dist/integrations/storybook.d.ts +19 -1
- package/dist/lint.cjs +159 -22
- package/dist/lint.js +2 -2
- package/dist/page-router.d.ts +18 -0
- package/dist/react-module-move.d.ts +47 -14
- package/dist/react.cjs +1645 -999
- package/dist/react.js +2 -102
- package/dist/rest-adapters.d.ts +13 -0
- package/dist/svelte-agent-cli.spec.d.ts +1 -0
- package/dist/svelte.cjs +7373 -0
- package/dist/svelte.d.ts +2 -0
- package/dist/svelte.js +3 -0
- package/dist/sveltekit-app.d.ts +7 -0
- package/dist/upgrade-steps.d.ts +6 -1
- package/dist/upgrade-svelte.d.ts +15 -0
- package/dist/upgrade-svelte.spec.d.ts +1 -0
- package/dist/upgrade.cjs +307 -42
- package/dist/upgrade.js +132 -13
- package/dist/use-cases/add-integration.d.ts +1 -1
- package/dist/use-cases/delete-react-module.d.ts +4 -4
- package/dist/use-cases/index.d.ts +1 -0
- package/dist/use-cases/move-react-module.d.ts +2 -2
- package/dist/use-cases/rest-endpoint-generator.d.ts +6 -4
- package/dist/use-cases/scaffold-svelte-modules.d.ts +27 -0
- package/package.json +2 -1
- package/skills/df-ps-implement/SKILL.md +3 -3
- package/skills/df-ps-plan-feature/SKILL.md +1 -1
- package/skills/df-ps-scaffold/SKILL.md +9 -8
- package/skills/df-ps-scaffold/references/agent-mode.md +1 -1
- package/skills/df-ps-scaffold/references/agent-operations.md +8 -4
- package/skills/df-ps-scaffold/references/generators.md +1 -1
- package/skills/df-ps-scaffold/references/work-plan.md +1 -1
- package/skills/df-ps-svelte/SKILL.md +54 -0
- package/skills/df-ps-svelte/references/generators.md +56 -0
- package/dist/115.js +0 -615
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,200 +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 reactPageContent = (ClassName, { imports = [], body = '<></>' } = {})=>`
|
|
394
|
-
${[
|
|
395
|
-
...imports,
|
|
396
|
-
"import { type FC } from 'react'"
|
|
397
|
-
].join('\n')}
|
|
398
|
-
|
|
399
|
-
export type ${ClassName}PageProps = {}
|
|
400
|
-
|
|
401
|
-
export const ${ClassName}Page: FC<${ClassName}PageProps> = (props) => {
|
|
402
|
-
return ${body}
|
|
403
|
-
}
|
|
404
|
-
`.trim();
|
|
405
|
-
const nextRouteContent = (ClassName, pageImport)=>`
|
|
406
|
-
import { ${ClassName}Page } from '${pageImport}'
|
|
407
|
-
|
|
408
|
-
export default function Page() {
|
|
409
|
-
return <${ClassName}Page />
|
|
410
|
-
}
|
|
411
|
-
`.trim();
|
|
412
|
-
const scaffoldNextRoute = (name, pagePath)=>{
|
|
413
|
-
const root = new ProjectRoot().path;
|
|
414
|
-
const route = node_path.join(root, nextAppFolder(root), ...name.folders, name.folderName, 'page.tsx');
|
|
415
|
-
const relativeRoute = node_path.relative(root, route).split(node_path.sep).join('/');
|
|
416
|
-
const routeFile = new File(route);
|
|
417
|
-
const content = nextRouteContent(name.ClassName, relativeImport(route, pagePath.replace(/\.tsx$/, '')));
|
|
418
|
-
if (routeFile.exists) return routeFile.data === content ? void 0 : `${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`;
|
|
419
|
-
routeFile.data = content;
|
|
420
|
-
};
|
|
421
|
-
const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
422
|
-
const name = await interaction_input({
|
|
423
|
-
key: 'name',
|
|
424
|
-
message: 'Provide name (folders split by "/"):',
|
|
425
|
-
validate: NestedName.validate
|
|
426
|
-
});
|
|
427
|
-
const nestedName = new NestedName(name);
|
|
428
|
-
const { folders, ClassName, fileName } = nestedName;
|
|
429
|
-
const pageFile = presentationReactFolder.subitem([
|
|
430
|
-
'pages',
|
|
431
|
-
...folders
|
|
432
|
-
]).createFile(`${fileName}-page.tsx`, reactPageContent(ClassName));
|
|
433
|
-
if (usesNext()) {
|
|
434
|
-
const hint = scaffoldNextRoute(nestedName, pageFile.path);
|
|
435
|
-
if (hint) report(hint);
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
const openapiScriptPath = "scripts/generate-openapi.ts";
|
|
439
|
-
const defaultOpenapiPath = (withNext)=>withNext ? 'public/openapi.json' : 'openapi.json';
|
|
440
|
-
const extractorPackages = [
|
|
441
|
-
'ts-morph',
|
|
442
|
-
'@microsoft/tsdoc'
|
|
443
|
-
];
|
|
444
|
-
const swaggerPagePath = (rootFolder)=>node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/react/pages/swagger-page.tsx');
|
|
445
|
-
const swaggerPage = (rootFolder, outputPath, withNext = false)=>{
|
|
446
|
-
const specImport = node_path.posix.relative(node_path.posix.dirname(swaggerPagePath(rootFolder)), outputPath);
|
|
447
|
-
const page = reactPageContent('Swagger', {
|
|
448
|
-
imports: [
|
|
449
|
-
"import 'swagger-ui-react/swagger-ui.css'",
|
|
450
|
-
"import SwaggerUI from 'swagger-ui-react'",
|
|
451
|
-
`import spec from '${specImport.startsWith('.') ? specImport : `./${specImport}`}' with { type: 'json' }`
|
|
452
|
-
],
|
|
453
|
-
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
454
|
-
});
|
|
455
|
-
return withNext ? `'use client'\n\n${page}` : page;
|
|
456
|
-
};
|
|
457
|
-
const openapiScripts = {
|
|
458
|
-
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
459
|
-
};
|
|
460
|
-
const splitPath = (value)=>value.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment);
|
|
461
|
-
const apiTitle = (packageName)=>{
|
|
462
|
-
const words = String(packageName ?? '').replace(/^@[^/]*\//, '').split(/[^a-zA-Z0-9]+/).filter((word)=>!!word).map((word)=>word[0].toUpperCase() + word.slice(1));
|
|
463
|
-
return [
|
|
464
|
-
...words,
|
|
465
|
-
'API'
|
|
466
|
-
].join(' ');
|
|
467
|
-
};
|
|
468
|
-
const openapiGenerator = (rootFolder, title, routePrefix, outputPath, withExtractor = false)=>{
|
|
469
|
-
const restFolder = node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'presentation/rest');
|
|
470
|
-
const restImport = node_path.posix.relative(node_path.posix.dirname(openapiScriptPath), restFolder);
|
|
471
|
-
const prefixSegments = splitPath(routePrefix);
|
|
472
|
-
const apiRoutePrefix = prefixSegments.length ? `\n apiRoutePrefix: [${prefixSegments.map((segment)=>`'${segment}'`).join(', ')}],` : '';
|
|
473
|
-
const extractorImport = `./${node_path.posix.relative(node_path.posix.dirname(openapiScriptPath), openapiExtractorPath.replace(/\.ts$/, ''))}`;
|
|
474
|
-
const handlers = withExtractor ? `
|
|
475
|
-
const extractOpenApiDataFromEndpointLogic =
|
|
476
|
-
createOpenApiDataFromEndpointLogicExtractor();
|
|
477
|
-
|
|
478
|
-
const handlers = restHandlers.map((x) => ({
|
|
479
|
-
...x,
|
|
480
|
-
metadata: {
|
|
481
|
-
...x.metadata,
|
|
482
|
-
openApiMetadata: {
|
|
483
|
-
...extractOpenApiDataFromEndpointLogic(x.metadata.route),
|
|
484
|
-
...(x.metadata.openApiMetadata ?? {})
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}));
|
|
488
|
-
` : '';
|
|
489
|
-
return `import { generateOpenAPI } from '@domain-first/handlers-rest';
|
|
490
|
-
import { restHandlers } from '${restImport.startsWith('.') ? restImport : `./${restImport}`}';${withExtractor ? `\nimport { createOpenApiDataFromEndpointLogicExtractor } from '${extractorImport}';` : ''}
|
|
491
|
-
${handlers}
|
|
492
|
-
generateOpenAPI(${withExtractor ? 'handlers' : 'restHandlers'}, {
|
|
493
|
-
document: { info: { title: '${title}', version: '1.0.0' } },${apiRoutePrefix}
|
|
494
|
-
outputFile: { path: '${outputPath}' }
|
|
495
|
-
});
|
|
496
|
-
`;
|
|
497
|
-
};
|
|
498
|
-
const addOpenapi = async ()=>{
|
|
499
|
-
const { rootFolder } = ConfigFile.Instance.data.project;
|
|
500
|
-
const root = new ProjectRoot().path;
|
|
501
|
-
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
502
|
-
const manifest = JSON.parse(manifestFile.data);
|
|
503
|
-
const dependencies = {
|
|
504
|
-
...manifest.dependencies,
|
|
505
|
-
...manifest.devDependencies
|
|
506
|
-
};
|
|
507
|
-
const routePrefix = await interaction_input({
|
|
508
|
-
key: 'routePrefix',
|
|
509
|
-
message: 'Route prefix the REST handlers are served under:',
|
|
510
|
-
default: '/api'
|
|
511
|
-
});
|
|
512
|
-
const outputPath = await interaction_input({
|
|
513
|
-
key: 'openapiPath',
|
|
514
|
-
message: 'OpenAPI document path:',
|
|
515
|
-
default: defaultOpenapiPath(usesNext()),
|
|
516
|
-
validate: (value)=>splitPath(value).length ? true : 'Path is required'
|
|
517
|
-
});
|
|
518
|
-
const withExtractor = await interaction_confirm({
|
|
519
|
-
key: 'withExtractor',
|
|
520
|
-
message: "Fill operationId, summary and description from the endpoint logic TSDoc?",
|
|
521
|
-
default: true
|
|
522
|
-
});
|
|
523
|
-
const withSwaggerPage = Boolean(ConfigFile.Instance.data.frontend?.react) && await interaction_confirm({
|
|
524
|
-
key: 'swaggerPage',
|
|
525
|
-
message: 'Add a Swagger UI page?',
|
|
526
|
-
default: true
|
|
527
|
-
});
|
|
528
|
-
const selected = await addPackageScripts(manifestFile, openapiScripts);
|
|
529
|
-
if (withExtractor) {
|
|
530
|
-
const extractorFile = new File(node_path.join(root, openapiExtractorPath));
|
|
531
|
-
const extractor = openapiExtractor(rootFolder);
|
|
532
|
-
if (!extractorFile.exists || extractorFile.data !== extractor) extractorFile.data = extractor;
|
|
533
|
-
}
|
|
534
|
-
const generatorFile = new File(node_path.join(root, openapiScriptPath));
|
|
535
|
-
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
536
|
-
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
537
|
-
const withNextRoute = withSwaggerPage && usesNext();
|
|
538
|
-
let nextRouteHint;
|
|
539
|
-
if (withSwaggerPage) {
|
|
540
|
-
const pagePath = node_path.join(root, swaggerPagePath(rootFolder));
|
|
541
|
-
const pageFile = new File(pagePath);
|
|
542
|
-
const page = swaggerPage(rootFolder, splitPath(outputPath).join('/'), withNextRoute);
|
|
543
|
-
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
544
|
-
if (withNextRoute) nextRouteHint = scaffoldNextRoute(new NestedName('swagger'), pagePath);
|
|
545
|
-
}
|
|
546
|
-
const resolveJsonModule = withSwaggerPage ? compilerOption(node_path.join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
547
|
-
const hasRestHandlers = new File(node_path.join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
548
|
-
const missingExtractorPackages = withExtractor ? extractorPackages.filter((name)=>!dependencies[name]) : [];
|
|
549
|
-
return [
|
|
550
|
-
...dependencies['@domain-first/handlers-rest'] ? [] : [
|
|
551
|
-
'npm install @domain-first/handlers-rest'
|
|
552
|
-
],
|
|
553
|
-
...dependencies.tsx ? [] : [
|
|
554
|
-
'npm install --save-dev tsx'
|
|
555
|
-
],
|
|
556
|
-
...missingExtractorPackages.length ? [
|
|
557
|
-
`npm install --save-dev ${missingExtractorPackages.join(' ')}`
|
|
558
|
-
] : [],
|
|
559
|
-
...withSwaggerPage && !dependencies['swagger-ui-react'] ? [
|
|
560
|
-
'npm install swagger-ui-react'
|
|
561
|
-
] : [],
|
|
562
|
-
...withSwaggerPage && !dependencies['@types/swagger-ui-react'] ? [
|
|
563
|
-
'npm install --save-dev @types/swagger-ui-react'
|
|
564
|
-
] : [],
|
|
565
|
-
...true === resolveJsonModule || null === resolveJsonModule ? [] : [
|
|
566
|
-
'set "resolveJsonModule": true in compilerOptions of tsconfig.json — the Swagger UI page imports the OpenAPI document as JSON'
|
|
567
|
-
],
|
|
568
|
-
...describeScripts(selected, {
|
|
569
|
-
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
570
|
-
}),
|
|
571
|
-
...withSwaggerPage && !withNextRoute ? [
|
|
572
|
-
`SwaggerPage from ${swaggerPagePath(rootFolder)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
573
|
-
] : [],
|
|
574
|
-
...withNextRoute ? [
|
|
575
|
-
nextRouteHint ?? `/swagger shows ${splitPath(outputPath).join('/')} once it is generated — the route is ${nextAppFolder(root)}/swagger/page.tsx`
|
|
576
|
-
] : [],
|
|
577
|
-
...hasRestHandlers ? [] : [
|
|
578
|
-
`restHandlers appear in ${node_path.posix.join(rootFolder, 'presentation/rest/index.ts')} with the first REST endpoint generated with @domain-first/wire`
|
|
579
|
-
]
|
|
580
|
-
];
|
|
581
|
-
};
|
|
582
184
|
const addGitignoreEntry = (root, entry)=>{
|
|
583
185
|
const gitignore = new File(node_path.join(root, '.gitignore'));
|
|
584
186
|
const ignored = gitignore.exists ? gitignore.data : '';
|
|
@@ -586,20 +188,28 @@ const addGitignoreEntry = (root, entry)=>{
|
|
|
586
188
|
const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
|
|
587
189
|
gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${entry}${newline}`);
|
|
588
190
|
};
|
|
589
|
-
const dataLayerFolder = (rootFolder, target)=>node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'hooks' === target ?
|
|
590
|
-
const orvalScripts = (rootFolder, targets)=>({
|
|
591
|
-
'client:orval': targets.map((target)=>`orval --config ${JSON.stringify(`${dataLayerFolder(rootFolder, target)}/orval.config.ts`)}`).join(' && ')
|
|
191
|
+
const dataLayerFolder = (rootFolder, target, framework = 'react')=>node_path.posix.join(rootFolder.replaceAll('\\', '/'), 'hooks' === target ? `presentation/${framework}/data-layer` : 'presentation/data-layer');
|
|
192
|
+
const orvalScripts = (rootFolder, targets, framework = 'react')=>({
|
|
193
|
+
'client:orval': targets.map((target)=>`orval --config ${JSON.stringify(`${dataLayerFolder(rootFolder, target, framework)}/orval.config.ts`)}`).join(' && ')
|
|
592
194
|
});
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
195
|
+
const orvalBaseUrls = {
|
|
196
|
+
next: 'process.env.NEXT_PUBLIC_API_BASE_URL ?? ""',
|
|
197
|
+
svelte: 'import.meta.env.VITE_API_BASE_URL ?? ""'
|
|
198
|
+
};
|
|
199
|
+
const orvalConfig = (rootFolder, openapiPath, baseUrlSource, target = 'hooks', mutatorPath = './api-client/mutator.ts', framework = 'react')=>{
|
|
200
|
+
const inputPath = node_path.posix.relative(dataLayerFolder(rootFolder, target, framework), openapiPath);
|
|
201
|
+
const baseUrl = baseUrlSource ? `
|
|
596
202
|
baseUrl: {
|
|
597
|
-
runtime: '
|
|
203
|
+
runtime: '${orvalBaseUrls[baseUrlSource]}'
|
|
598
204
|
},` : '';
|
|
205
|
+
const svelteQuery = 'hooks' === target && 'svelte' === framework;
|
|
599
206
|
const client = 'hooks' === target ? `
|
|
600
|
-
client: 'react-query',
|
|
207
|
+
client: '${svelteQuery ? 'svelte-query' : 'react-query'}',
|
|
601
208
|
httpClient: 'fetch',` : `
|
|
602
209
|
client: 'fetch',`;
|
|
210
|
+
const packageJson = svelteQuery ? `
|
|
211
|
+
// Svelte Query 6 (runes) even before it is installed; an installed version wins
|
|
212
|
+
packageJson: './${svelteQueryPackageJsonFile}',` : '';
|
|
603
213
|
const query = 'hooks' === target ? `,
|
|
604
214
|
query: {
|
|
605
215
|
version: 5
|
|
@@ -612,7 +222,7 @@ export default defineConfig({
|
|
|
612
222
|
output: {
|
|
613
223
|
mode: 'tags-split',
|
|
614
224
|
target: './orval',
|
|
615
|
-
schemas: './orval/model',${client}${baseUrl}
|
|
225
|
+
schemas: './orval/model',${client}${packageJson}${baseUrl}
|
|
616
226
|
clean: true,
|
|
617
227
|
override: {
|
|
618
228
|
mutator: {
|
|
@@ -628,6 +238,14 @@ export default defineConfig({
|
|
|
628
238
|
});
|
|
629
239
|
`;
|
|
630
240
|
};
|
|
241
|
+
const svelteQueryPackageJsonFile = 'orval.package.json';
|
|
242
|
+
const svelteQueryPackageJson = `${JSON.stringify({
|
|
243
|
+
private: true,
|
|
244
|
+
dependencies: {
|
|
245
|
+
'@tanstack/svelte-query': '^6.0.0'
|
|
246
|
+
}
|
|
247
|
+
}, null, 4)}
|
|
248
|
+
`;
|
|
631
249
|
const orvalMutator = `/** Error of the generated requests, with the parsed response body. */
|
|
632
250
|
export class ApiError<Body = unknown> extends Error {
|
|
633
251
|
constructor(
|
|
@@ -674,6 +292,43 @@ export const QueryProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
|
|
674
292
|
);
|
|
675
293
|
};
|
|
676
294
|
`;
|
|
295
|
+
const svelteQueryProvider = (withSvelteKit)=>`<script lang="ts">
|
|
296
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
|
|
297
|
+
import type { Snippet } from 'svelte'${withSvelteKit ? "\n import { browser } from '$app/environment'" : ''}
|
|
298
|
+
|
|
299
|
+
let { children }: { children: Snippet } = $props()
|
|
300
|
+
|
|
301
|
+
// One client per app instance; a module-level client would be shared between requests on the server
|
|
302
|
+
const queryClient = new QueryClient(${withSvelteKit ? `{
|
|
303
|
+
defaultOptions: { queries: { enabled: browser } }
|
|
304
|
+
}` : ''})
|
|
305
|
+
</script>
|
|
306
|
+
|
|
307
|
+
<QueryClientProvider client={queryClient}>
|
|
308
|
+
{@render children()}
|
|
309
|
+
</QueryClientProvider>
|
|
310
|
+
`;
|
|
311
|
+
const svelteKitQueryLayout = (providerImport)=>`<script lang="ts">
|
|
312
|
+
import type { Snippet } from 'svelte'
|
|
313
|
+
import QueryProvider from '${providerImport}'
|
|
314
|
+
|
|
315
|
+
let { children }: { children: Snippet } = $props()
|
|
316
|
+
</script>
|
|
317
|
+
|
|
318
|
+
<QueryProvider>
|
|
319
|
+
{@render children()}
|
|
320
|
+
</QueryProvider>
|
|
321
|
+
`;
|
|
322
|
+
const connectSvelteKitProvider = (root, providerPath)=>{
|
|
323
|
+
const layoutPath = node_path.posix.join(svelteKitRoutesFolder(root), '+layout.svelte');
|
|
324
|
+
const layout = new File(node_path.join(root, layoutPath));
|
|
325
|
+
if (!layout.exists) {
|
|
326
|
+
const providerImport = node_path.posix.relative(node_path.posix.dirname(layoutPath), providerPath);
|
|
327
|
+
layout.data = svelteKitQueryLayout(providerImport.startsWith('.') ? providerImport : `./${providerImport}`);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
return layout.data.includes('QueryProvider') ? void 0 : `Wrap {@render children()} of ${layoutPath} in QueryProvider from ${providerPath}`;
|
|
331
|
+
};
|
|
677
332
|
const openapiOutputPath = (root)=>{
|
|
678
333
|
const generator = new File(node_path.join(root, openapiScriptPath));
|
|
679
334
|
if (!generator.exists) return;
|
|
@@ -681,7 +336,7 @@ const openapiOutputPath = (root)=>{
|
|
|
681
336
|
};
|
|
682
337
|
const addOrval = async ()=>{
|
|
683
338
|
const { project: { rootFolder }, frontend } = ConfigFile.Instance.data;
|
|
684
|
-
const
|
|
339
|
+
const framework = frontend?.svelte ? 'svelte' : frontend?.react ? 'react' : void 0;
|
|
685
340
|
const root = new ProjectRoot().path;
|
|
686
341
|
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
687
342
|
const manifest = JSON.parse(manifestFile.data);
|
|
@@ -689,20 +344,22 @@ const addOrval = async ()=>{
|
|
|
689
344
|
...manifest.dependencies,
|
|
690
345
|
...manifest.devDependencies
|
|
691
346
|
};
|
|
692
|
-
const
|
|
347
|
+
const withSvelteKit = usesSvelteKit();
|
|
348
|
+
const baseUrl = 'svelte' === framework ? 'svelte' : usesNext() ? 'next' : void 0;
|
|
349
|
+
const hooksFramework = framework ?? 'react';
|
|
693
350
|
const generatedOpenapiPath = openapiOutputPath(root);
|
|
694
351
|
const openapiPath = await interaction_input({
|
|
695
352
|
key: 'openapiPath',
|
|
696
353
|
message: 'OpenAPI document path:',
|
|
697
|
-
default: generatedOpenapiPath ?? defaultOpenapiPath(
|
|
354
|
+
default: generatedOpenapiPath ?? defaultOpenapiPath(),
|
|
698
355
|
validate: (value)=>value.trim() ? true : 'Path is required'
|
|
699
356
|
});
|
|
700
|
-
const targets =
|
|
357
|
+
const targets = framework ? await interaction_checkbox({
|
|
701
358
|
key: 'targets',
|
|
702
359
|
message: 'Generate:',
|
|
703
360
|
choices: [
|
|
704
361
|
{
|
|
705
|
-
name: 'React Query hooks',
|
|
362
|
+
name: 'svelte' === framework ? 'Svelte Query (createQuery)' : 'React Query hooks',
|
|
706
363
|
value: 'hooks',
|
|
707
364
|
checked: true
|
|
708
365
|
},
|
|
@@ -715,16 +372,23 @@ const addOrval = async ()=>{
|
|
|
715
372
|
}) : [
|
|
716
373
|
'client'
|
|
717
374
|
];
|
|
718
|
-
const selected = await addPackageScripts(manifestFile, orvalScripts(rootFolder, targets));
|
|
375
|
+
const selected = await addPackageScripts(manifestFile, orvalScripts(rootFolder, targets, hooksFramework));
|
|
376
|
+
const layer = (target)=>dataLayerFolder(rootFolder, target, hooksFramework);
|
|
377
|
+
const providerFile = 'svelte' === hooksFramework ? 'query-provider.svelte' : 'query-provider.tsx';
|
|
378
|
+
const providerContent = 'svelte' === hooksFramework ? svelteQueryProvider(withSvelteKit) : queryProvider;
|
|
719
379
|
const document = node_path.posix.normalize(openapiPath.trim().replaceAll('\\', '/'));
|
|
720
380
|
const withClient = targets.includes('client');
|
|
721
381
|
for (const target of targets){
|
|
722
|
-
const dataLayer =
|
|
382
|
+
const dataLayer = layer(target);
|
|
723
383
|
const sharedMutator = 'hooks' === target && withClient;
|
|
724
|
-
const mutatorPath = sharedMutator ? `${node_path.posix.relative(dataLayer,
|
|
384
|
+
const mutatorPath = sharedMutator ? `${node_path.posix.relative(dataLayer, layer('client'))}/api-client/mutator.ts` : void 0;
|
|
725
385
|
const configFile = new File(node_path.join(root, dataLayer, 'orval.config.ts'));
|
|
726
|
-
const content = orvalConfig(rootFolder, document,
|
|
386
|
+
const content = orvalConfig(rootFolder, document, baseUrl, target, mutatorPath, hooksFramework);
|
|
727
387
|
if (!configFile.exists || configFile.data !== content) configFile.data = content;
|
|
388
|
+
if ('hooks' === target && 'svelte' === hooksFramework) {
|
|
389
|
+
const versions = new File(node_path.join(root, dataLayer, svelteQueryPackageJsonFile));
|
|
390
|
+
if (!versions.exists || versions.data !== svelteQueryPackageJson) versions.data = svelteQueryPackageJson;
|
|
391
|
+
}
|
|
728
392
|
for (const [name, fileContent] of [
|
|
729
393
|
...sharedMutator ? [] : [
|
|
730
394
|
[
|
|
@@ -734,8 +398,8 @@ const addOrval = async ()=>{
|
|
|
734
398
|
],
|
|
735
399
|
...'hooks' === target ? [
|
|
736
400
|
[
|
|
737
|
-
|
|
738
|
-
|
|
401
|
+
providerFile,
|
|
402
|
+
providerContent
|
|
739
403
|
]
|
|
740
404
|
] : []
|
|
741
405
|
]){
|
|
@@ -744,10 +408,14 @@ const addOrval = async ()=>{
|
|
|
744
408
|
}
|
|
745
409
|
addGitignoreEntry(root, `/${dataLayer}/orval/`);
|
|
746
410
|
}
|
|
747
|
-
const
|
|
411
|
+
const withHooks = targets.includes('hooks');
|
|
412
|
+
const providerPath = `${layer('hooks')}/${providerFile}`;
|
|
413
|
+
const layoutNote = withHooks && 'svelte' === hooksFramework && withSvelteKit ? connectSvelteKitProvider(root, providerPath) : void 0;
|
|
414
|
+
const queryPackage = 'svelte' === hooksFramework ? '@tanstack/svelte-query' : '@tanstack/react-query';
|
|
415
|
+
const generated = targets.map((target)=>'hooks' === target ? `${'svelte' === hooksFramework ? 'Svelte' : 'React'} Query hooks in ${layer('hooks')}/orval` : `a typed API client in ${layer('client')}/orval`);
|
|
748
416
|
const missing = (names)=>names.filter((name)=>!dependencies[name]);
|
|
749
|
-
const runtime = missing(
|
|
750
|
-
|
|
417
|
+
const runtime = missing(withHooks ? [
|
|
418
|
+
queryPackage
|
|
751
419
|
] : []);
|
|
752
420
|
const development = missing([
|
|
753
421
|
'orval'
|
|
@@ -762,8 +430,11 @@ const addOrval = async ()=>{
|
|
|
762
430
|
...describeScripts(selected, {
|
|
763
431
|
'client:orval': `generate ${generated.join(' and ')} from ${openapiPath.trim()}`
|
|
764
432
|
}),
|
|
765
|
-
...
|
|
766
|
-
`Wrap your app in QueryProvider from ${
|
|
433
|
+
...withHooks && !('svelte' === hooksFramework && withSvelteKit) ? [
|
|
434
|
+
`Wrap your app in QueryProvider from ${providerPath}`
|
|
435
|
+
] : [],
|
|
436
|
+
...layoutNote ? [
|
|
437
|
+
layoutNote
|
|
767
438
|
] : [],
|
|
768
439
|
...generatedOpenapiPath ? [] : [
|
|
769
440
|
'npx df-integration → OpenAPI generates the OpenAPI document the client is built from'
|
|
@@ -1003,6 +674,22 @@ const addPrisma = async ()=>{
|
|
|
1003
674
|
})
|
|
1004
675
|
];
|
|
1005
676
|
};
|
|
677
|
+
const rest_adapters_restAdapters = {
|
|
678
|
+
next: {
|
|
679
|
+
package: '@domain-first/handlers-next',
|
|
680
|
+
adapter: 'nextAdapter',
|
|
681
|
+
endpoints: 'nextEndpoints',
|
|
682
|
+
key: 'nextAdapter',
|
|
683
|
+
routePath: (root)=>node_path.posix.join(nextAppFolder(root), 'api/[...path]/route.ts')
|
|
684
|
+
},
|
|
685
|
+
svelte: {
|
|
686
|
+
package: '@domain-first/handlers-svelte',
|
|
687
|
+
adapter: 'svelteAdapter',
|
|
688
|
+
endpoints: 'svelteEndpoints',
|
|
689
|
+
key: 'svelteAdapter',
|
|
690
|
+
routePath: (root)=>node_path.posix.join(svelteKitRoutesFolder(root), 'api/[...path]/+server.ts')
|
|
691
|
+
}
|
|
692
|
+
};
|
|
1006
693
|
const kindTitles = {
|
|
1007
694
|
repositories: 'Repositories',
|
|
1008
695
|
'domain-services': 'Domain services',
|
|
@@ -1197,15 +884,16 @@ const scaffoldNewPresentationService = async (boundedContextFolder)=>{
|
|
|
1197
884
|
if (wireFile) await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
1198
885
|
};
|
|
1199
886
|
const rest_endpoint_generator_name = 'rest-endpoint-generator';
|
|
1200
|
-
const scaffoldRestEndpointGenerator = (sharedFolder, {
|
|
1201
|
-
const
|
|
887
|
+
const scaffoldRestEndpointGenerator = (sharedFolder, { adapter: framework } = {})=>createPresentationService(sharedFolder, rest_endpoint_generator_name, (className)=>{
|
|
888
|
+
const known = framework && rest_adapters_restAdapters[framework];
|
|
889
|
+
const adapter = known ? known.adapter : 'adapter';
|
|
1202
890
|
return `
|
|
1203
891
|
import {
|
|
1204
|
-
${
|
|
892
|
+
${known ? '' : ' type Adapter,\n'} type EndpointGenerator,
|
|
1205
893
|
createEndpoint,
|
|
1206
894
|
invalidRequest
|
|
1207
895
|
} from '@domain-first/handlers-rest'
|
|
1208
|
-
${
|
|
896
|
+
${known ? `import { ${known.adapter} } from '${known.package}'` : `
|
|
1209
897
|
/**
|
|
1210
898
|
* The adapter of your HTTP framework.
|
|
1211
899
|
*/
|
|
@@ -1230,16 +918,17 @@ const findRestEndpointGenerator = (sharedFolder)=>{
|
|
|
1230
918
|
wireFile: node_path.join(sharedFolder.path, 'wiring', 'presentation-services', `wire-${rest_endpoint_generator_name}-presentation-service.ts`)
|
|
1231
919
|
};
|
|
1232
920
|
};
|
|
1233
|
-
const
|
|
1234
|
-
const
|
|
1235
|
-
|
|
921
|
+
const catchAllRoute = (adapter, restHandlersImport)=>{
|
|
922
|
+
const { endpoints, package: packageName } = rest_adapters_restAdapters[adapter];
|
|
923
|
+
return `
|
|
924
|
+
import { ${endpoints} } from '${packageName}'
|
|
1236
925
|
${restHandlersImport ? `import { restHandlers } from '${restHandlersImport}'
|
|
1237
926
|
|
|
1238
|
-
const handler =
|
|
927
|
+
const handler = ${endpoints}(restHandlers)` : `
|
|
1239
928
|
/**
|
|
1240
929
|
* Pass the endpoints' handle here; their paths are relative to this route's folder.
|
|
1241
930
|
*/
|
|
1242
|
-
const handler =
|
|
931
|
+
const handler = ${endpoints}([])`}
|
|
1243
932
|
|
|
1244
933
|
export const GET = handler
|
|
1245
934
|
export const POST = handler
|
|
@@ -1247,14 +936,15 @@ export const PUT = handler
|
|
|
1247
936
|
export const PATCH = handler
|
|
1248
937
|
export const DELETE = handler
|
|
1249
938
|
`.trim();
|
|
1250
|
-
|
|
939
|
+
};
|
|
940
|
+
const scaffoldCatchAllRoute = (root, adapter)=>{
|
|
1251
941
|
const { rootFolder } = ConfigFile.Instance.data.project;
|
|
1252
942
|
const { domainFirstPackages } = ConfigFile.backend;
|
|
1253
|
-
const routePath =
|
|
943
|
+
const routePath = rest_adapters_restAdapters[adapter].routePath(root);
|
|
1254
944
|
const routeFile = node_path.join(root, routePath);
|
|
1255
945
|
if (new File(routeFile).exists) return [];
|
|
1256
946
|
if (!domainFirstPackages.includes('@domain-first/wire')) {
|
|
1257
|
-
new File(routeFile).data =
|
|
947
|
+
new File(routeFile).data = catchAllRoute(adapter, void 0);
|
|
1258
948
|
return [];
|
|
1259
949
|
}
|
|
1260
950
|
const restFolder = new Folder(root).subitem([
|
|
@@ -1262,16 +952,21 @@ const rest_endpoint_generator_scaffoldNextRoute = (root)=>{
|
|
|
1262
952
|
'presentation',
|
|
1263
953
|
'rest'
|
|
1264
954
|
]);
|
|
1265
|
-
new File(routeFile).data =
|
|
955
|
+
new File(routeFile).data = catchAllRoute(adapter, relativeImport(routeFile, restFolder.path));
|
|
1266
956
|
return new File(node_path.join(restFolder.path, 'index.ts')).exists ? [] : [
|
|
1267
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`
|
|
1268
958
|
];
|
|
1269
959
|
};
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
}
|
|
1274
|
-
|
|
960
|
+
const frameworkRestAdapter = ()=>usesNext() ? 'next' : usesSvelteKit() ? 'svelte' : void 0;
|
|
961
|
+
const askRestAdapter = async ({ adapter = frameworkRestAdapter() } = {})=>{
|
|
962
|
+
if (!adapter) return;
|
|
963
|
+
const { key, package: packageName } = rest_adapters_restAdapters[adapter];
|
|
964
|
+
return await interaction_confirm({
|
|
965
|
+
key,
|
|
966
|
+
message: `Use ${packageName} for REST endpoints`
|
|
967
|
+
}) ? adapter : void 0;
|
|
968
|
+
};
|
|
969
|
+
const scaffoldRestEndpointGeneratorFiles = ({ adapter })=>{
|
|
1275
970
|
const root = new ProjectRoot().path;
|
|
1276
971
|
const generatorExisted = restEndpointGeneratorApplied();
|
|
1277
972
|
const routeNotes = withoutOverwrites(()=>{
|
|
@@ -1279,29 +974,100 @@ const scaffoldRestEndpointGeneratorFiles = ({ withNextAdapter })=>{
|
|
|
1279
974
|
ConfigFile.Instance.data.project.rootFolder,
|
|
1280
975
|
'shared-kernel'
|
|
1281
976
|
]), {
|
|
1282
|
-
|
|
977
|
+
adapter
|
|
1283
978
|
});
|
|
1284
|
-
return
|
|
979
|
+
return adapter ? scaffoldCatchAllRoute(root, adapter) : [];
|
|
1285
980
|
});
|
|
1286
|
-
if (!
|
|
981
|
+
if (!adapter) return [];
|
|
982
|
+
const { adapter: adapterName, package: packageName } = rest_adapters_restAdapters[adapter];
|
|
1287
983
|
return [
|
|
1288
984
|
...missingPackages([
|
|
1289
|
-
|
|
985
|
+
packageName
|
|
1290
986
|
]),
|
|
1291
987
|
...routeNotes,
|
|
1292
988
|
...generatorExisted ? [
|
|
1293
|
-
|
|
989
|
+
`the existing endpoint generator was kept — pass ${adapterName} from ${packageName} to its createEndpoint calls`
|
|
1294
990
|
] : []
|
|
1295
991
|
];
|
|
1296
992
|
};
|
|
1297
993
|
const addRestEndpointGenerator = async ()=>scaffoldRestEndpointGeneratorFiles({
|
|
1298
|
-
|
|
994
|
+
adapter: await askRestAdapter()
|
|
1299
995
|
});
|
|
1300
996
|
const restEndpointGeneratorApplied = ()=>Boolean(findRestEndpointGenerator(new Folder(new ProjectRoot().path).subitem([
|
|
1301
997
|
ConfigFile.Instance.data.project.rootFolder,
|
|
1302
998
|
'shared-kernel'
|
|
1303
999
|
])));
|
|
1304
1000
|
const storybookFrameworkPackage = '@storybook/react-vite';
|
|
1001
|
+
const svelteStorybookPackages = {
|
|
1002
|
+
svelte: '@storybook/svelte-vite',
|
|
1003
|
+
sveltekit: '@storybook/sveltekit'
|
|
1004
|
+
};
|
|
1005
|
+
const storybookPackageFor = (framework)=>'svelte' === framework || 'sveltekit' === framework ? svelteStorybookPackages[framework] : storybookFrameworkPackage;
|
|
1006
|
+
const storybookFamily = ()=>ConfigFile.Instance.data.frontend?.svelte ? 'svelte' : 'react';
|
|
1007
|
+
const storybookTitle = ()=>ConfigFile.exists && ConfigFile.Instance.data.frontend?.svelte ? 'sveltekit' === ConfigFile.Instance.data.frontend.svelte.framework ? 'Storybook (SvelteKit)' : 'Storybook (Svelte + Vite)' : 'Storybook (React + Vite)';
|
|
1008
|
+
const storybookFolder = ()=>`presentation/${storybookFamily()}/.storybook`;
|
|
1009
|
+
const storybookPreview = (frameworkPackage)=>`import type { Preview } from '${frameworkPackage}';
|
|
1010
|
+
|
|
1011
|
+
const preview: Preview = {
|
|
1012
|
+
parameters: {
|
|
1013
|
+
controls: {
|
|
1014
|
+
matchers: {
|
|
1015
|
+
color: /(background|color)$/i,
|
|
1016
|
+
date: /Date$/i
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
|
|
1022
|
+
export default preview;
|
|
1023
|
+
`;
|
|
1024
|
+
const svelteStorybookFiles = (relativeProjectRoot, frameworkPackage)=>{
|
|
1025
|
+
const withPlugin = frameworkPackage === svelteStorybookPackages.svelte;
|
|
1026
|
+
return {
|
|
1027
|
+
'main.ts': `import { resolve } from 'node:path';
|
|
1028
|
+
import type { StorybookConfig } from '${frameworkPackage}';
|
|
1029
|
+
|
|
1030
|
+
const projectRoot = resolve(import.meta.dirname, ${JSON.stringify(relativeProjectRoot)});
|
|
1031
|
+
|
|
1032
|
+
const config: StorybookConfig = {
|
|
1033
|
+
stories: ['../**/*.mdx', '../**/*.stories.@(ts|svelte)'],
|
|
1034
|
+
framework: {
|
|
1035
|
+
name: '${frameworkPackage}',
|
|
1036
|
+
options: {}
|
|
1037
|
+
},
|
|
1038
|
+
core: {
|
|
1039
|
+
disableTelemetry: true
|
|
1040
|
+
},
|
|
1041
|
+
async viteFinal(viteConfig) {
|
|
1042
|
+
const { mergeConfig } = await import('vite');
|
|
1043
|
+
${withPlugin ? ` const { svelte } = await import('@sveltejs/vite-plugin-svelte');
|
|
1044
|
+
const hasSvelte = (viteConfig.plugins ?? [])
|
|
1045
|
+
.flat(Infinity)
|
|
1046
|
+
.some(
|
|
1047
|
+
(plugin) =>
|
|
1048
|
+
!!plugin &&
|
|
1049
|
+
typeof plugin === 'object' &&
|
|
1050
|
+
'name' in plugin &&
|
|
1051
|
+
String(plugin.name).startsWith('vite-plugin-svelte')
|
|
1052
|
+
);
|
|
1053
|
+
|
|
1054
|
+
return mergeConfig(viteConfig, {
|
|
1055
|
+
plugins: hasSvelte ? [] : [svelte()],` : `
|
|
1056
|
+
return mergeConfig(viteConfig, {`}
|
|
1057
|
+
resolve: {
|
|
1058
|
+
alias: {
|
|
1059
|
+
'@': projectRoot
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1066
|
+
export default config;
|
|
1067
|
+
`,
|
|
1068
|
+
'preview.ts': storybookPreview(frameworkPackage)
|
|
1069
|
+
};
|
|
1070
|
+
};
|
|
1305
1071
|
const storybookFiles = (relativeProjectRoot)=>({
|
|
1306
1072
|
'main.ts': `import { resolve } from 'node:path';
|
|
1307
1073
|
import react from '@vitejs/plugin-react';
|
|
@@ -1334,32 +1100,79 @@ const config: StorybookConfig = {
|
|
|
1334
1100
|
|
|
1335
1101
|
export default config;
|
|
1336
1102
|
`,
|
|
1337
|
-
'preview.ts':
|
|
1338
|
-
|
|
1339
|
-
const preview: Preview = {
|
|
1340
|
-
parameters: {
|
|
1341
|
-
controls: {
|
|
1342
|
-
matchers: {
|
|
1343
|
-
color: /(background|color)$/i,
|
|
1344
|
-
date: /Date$/i
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
};
|
|
1349
|
-
|
|
1350
|
-
export default preview;
|
|
1351
|
-
`
|
|
1103
|
+
'preview.ts': storybookPreview(storybookFrameworkPackage)
|
|
1352
1104
|
});
|
|
1353
|
-
const storybookScripts = (rootFolder)=>{
|
|
1354
|
-
const folder = node_path.posix.join(rootFolder.replaceAll('\\', '/'),
|
|
1105
|
+
const storybookScripts = (rootFolder, family = 'react')=>{
|
|
1106
|
+
const folder = node_path.posix.join(rootFolder.replaceAll('\\', '/'), `presentation/${family}`);
|
|
1355
1107
|
const quote = (value)=>JSON.stringify(value);
|
|
1356
1108
|
return {
|
|
1357
1109
|
storybook: `storybook dev -p 6006 -c ${quote(`${folder}/.storybook`)}`,
|
|
1358
1110
|
'build-storybook': `storybook build -c ${quote(`${folder}/.storybook`)} -o ${quote(`${folder}/storybook-static`)}`
|
|
1359
1111
|
};
|
|
1360
1112
|
};
|
|
1113
|
+
const addSvelteStorybook = async ()=>{
|
|
1114
|
+
const config = ConfigFile.Instance.data;
|
|
1115
|
+
const svelte = config.frontend?.svelte ?? {};
|
|
1116
|
+
const frameworkPackage = svelteStorybookPackages['sveltekit' === svelte.framework ? 'sveltekit' : 'svelte'];
|
|
1117
|
+
const root = new ProjectRoot().path;
|
|
1118
|
+
const manifestFile = new File(node_path.join(root, 'package.json'));
|
|
1119
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
1120
|
+
const selected = await addPackageScripts(manifestFile, storybookScripts(config.project.rootFolder, 'svelte'));
|
|
1121
|
+
const folder = new Folder(root).subitem([
|
|
1122
|
+
config.project.rootFolder,
|
|
1123
|
+
'presentation',
|
|
1124
|
+
'svelte',
|
|
1125
|
+
'.storybook'
|
|
1126
|
+
]);
|
|
1127
|
+
for (const [name, content] of Object.entries(svelteStorybookFiles(node_path.relative(folder.path, root).split(node_path.sep).join('/'), frameworkPackage))){
|
|
1128
|
+
const file = new File(node_path.join(folder.path, name));
|
|
1129
|
+
if (!file.exists || file.data !== content) file.data = content;
|
|
1130
|
+
}
|
|
1131
|
+
if (svelte.storybookFramework !== frameworkPackage) ConfigFile.update({
|
|
1132
|
+
frontend: {
|
|
1133
|
+
...config.frontend,
|
|
1134
|
+
svelte: {
|
|
1135
|
+
...svelte,
|
|
1136
|
+
storybookFramework: frameworkPackage
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
const buildFolder = node_path.posix.join(config.project.rootFolder.replaceAll('\\', '/'), 'presentation/svelte/storybook-static');
|
|
1141
|
+
addGitignoreEntry(root, `/${buildFolder}/`);
|
|
1142
|
+
const dependencies = {
|
|
1143
|
+
...manifest.dependencies,
|
|
1144
|
+
...manifest.devDependencies
|
|
1145
|
+
};
|
|
1146
|
+
const missing = [
|
|
1147
|
+
'storybook',
|
|
1148
|
+
frameworkPackage,
|
|
1149
|
+
'vite',
|
|
1150
|
+
...frameworkPackage === svelteStorybookPackages.svelte ? [
|
|
1151
|
+
'@sveltejs/vite-plugin-svelte'
|
|
1152
|
+
] : []
|
|
1153
|
+
].filter((name)=>!dependencies[name]);
|
|
1154
|
+
const missingSvelte = ('sveltekit' === svelte.framework ? [
|
|
1155
|
+
'@sveltejs/kit',
|
|
1156
|
+
'svelte'
|
|
1157
|
+
] : [
|
|
1158
|
+
'svelte'
|
|
1159
|
+
]).filter((name)=>!dependencies[name]);
|
|
1160
|
+
return [
|
|
1161
|
+
...missing.length ? [
|
|
1162
|
+
`npm install --save-dev ${missing.join(' ')}`
|
|
1163
|
+
] : [],
|
|
1164
|
+
...missingSvelte.length ? [
|
|
1165
|
+
`npm install ${missingSvelte.join(' ')}`
|
|
1166
|
+
] : [],
|
|
1167
|
+
...describeScripts(selected, {
|
|
1168
|
+
storybook: 'start Storybook on http://localhost:6006',
|
|
1169
|
+
'build-storybook': `build static Storybook into ${buildFolder}`
|
|
1170
|
+
})
|
|
1171
|
+
];
|
|
1172
|
+
};
|
|
1361
1173
|
const addStorybook = async ()=>{
|
|
1362
1174
|
const config = ConfigFile.Instance.data;
|
|
1175
|
+
if (config.frontend?.svelte) return addSvelteStorybook();
|
|
1363
1176
|
if ((!config.frontend?.react || config.frontend?.react?.storybookFramework && config.frontend?.react?.storybookFramework !== storybookFrameworkPackage) && !await interaction_confirm({
|
|
1364
1177
|
key: 'configureReact',
|
|
1365
1178
|
requestRequired: true,
|
|
@@ -1613,7 +1426,7 @@ const unitMoves = (unit, target)=>{
|
|
|
1613
1426
|
const oldFolder = node_path.join(unit.ownerPath, 'domain/aggregates', unit.name);
|
|
1614
1427
|
const newFolder = node_path.join(target.ownerPath, 'domain/aggregates', target.name);
|
|
1615
1428
|
const own = new Set(aggregateOwnFiles(unit.name).map((file)=>node_path.join(oldFolder, file)));
|
|
1616
|
-
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)));
|
|
1617
1430
|
}
|
|
1618
1431
|
return moves;
|
|
1619
1432
|
};
|
|
@@ -2582,10 +2395,10 @@ const integrationIds = [
|
|
|
2582
2395
|
const integrations = [
|
|
2583
2396
|
{
|
|
2584
2397
|
id: 'storybook',
|
|
2585
|
-
name:
|
|
2398
|
+
name: storybookTitle,
|
|
2586
2399
|
group: 'frontend',
|
|
2587
2400
|
run: addStorybook,
|
|
2588
|
-
applied: ()=>createdInRoot(
|
|
2401
|
+
applied: ()=>createdInRoot(`${storybookFolder()}/main.ts`)
|
|
2589
2402
|
},
|
|
2590
2403
|
{
|
|
2591
2404
|
id: 'rest-endpoint-generator',
|
|
@@ -2651,9 +2464,10 @@ const integrations = [
|
|
|
2651
2464
|
group: 'frontend',
|
|
2652
2465
|
run: addOrval,
|
|
2653
2466
|
available: ()=>withHandlersRest(),
|
|
2654
|
-
applied: ()=>createdInRoot('presentation/react/data-layer/orval.config.ts') || createdInRoot('presentation/data-layer/orval.config.ts')
|
|
2467
|
+
applied: ()=>createdInRoot('presentation/react/data-layer/orval.config.ts') || createdInRoot('presentation/svelte/data-layer/orval.config.ts') || createdInRoot('presentation/data-layer/orval.config.ts')
|
|
2655
2468
|
}
|
|
2656
2469
|
];
|
|
2470
|
+
const nameOf = ({ name })=>'string' == typeof name ? name : name();
|
|
2657
2471
|
const addIntegration = async ({ save = true } = {})=>{
|
|
2658
2472
|
const available = integrations.filter(({ group, available })=>('backend' !== group || Boolean(ConfigFile.Instance.data.backend)) && (available?.() ?? true)).map((value)=>({
|
|
2659
2473
|
value,
|
|
@@ -2667,7 +2481,7 @@ const addIntegration = async ({ save = true } = {})=>{
|
|
|
2667
2481
|
return items.length ? [
|
|
2668
2482
|
new Separator(title),
|
|
2669
2483
|
...items.map(({ value })=>({
|
|
2670
|
-
name: `${value
|
|
2484
|
+
name: `${nameOf(value)} · ${value.group}`,
|
|
2671
2485
|
value
|
|
2672
2486
|
}))
|
|
2673
2487
|
] : [];
|
|
@@ -2690,269 +2504,10 @@ const addIntegration = async ({ save = true } = {})=>{
|
|
|
2690
2504
|
};
|
|
2691
2505
|
const integrationDescriptions = ()=>integrations.map((integration)=>({
|
|
2692
2506
|
id: integration.id,
|
|
2693
|
-
name: integration
|
|
2507
|
+
name: nameOf(integration),
|
|
2694
2508
|
group: integration.group,
|
|
2695
2509
|
available: ('backend' !== integration.group || Boolean(ConfigFile.Instance.data.backend)) && (integration.available?.() ?? true)
|
|
2696
2510
|
}));
|
|
2697
|
-
const reactKindLayouts = {
|
|
2698
|
-
page: {
|
|
2699
|
-
folder: 'pages',
|
|
2700
|
-
nested: true,
|
|
2701
|
-
inFolder: false,
|
|
2702
|
-
ownFile: (fileBase)=>new RegExp(`^${escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
2703
|
-
target: (reactFolder, { folders, fileName })=>node_path.join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`),
|
|
2704
|
-
classPrefix: '(use)?',
|
|
2705
|
-
classSuffix: 'Page'
|
|
2706
|
-
},
|
|
2707
|
-
widget: {
|
|
2708
|
-
folder: 'widgets',
|
|
2709
|
-
nested: true,
|
|
2710
|
-
inFolder: true,
|
|
2711
|
-
target: (reactFolder, { folders, folderName })=>node_path.join(reactFolder, 'widgets', ...folders, folderName),
|
|
2712
|
-
classPrefix: '(use)?',
|
|
2713
|
-
classSuffix: 'Widget|UIModel',
|
|
2714
|
-
storyTitle: (segments)=>[
|
|
2715
|
-
'Widgets',
|
|
2716
|
-
...segments
|
|
2717
|
-
].join('/')
|
|
2718
|
-
},
|
|
2719
|
-
'ui-kit': {
|
|
2720
|
-
folder: 'ui-kit',
|
|
2721
|
-
nested: false,
|
|
2722
|
-
inFolder: true,
|
|
2723
|
-
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'ui-kit', fileName),
|
|
2724
|
-
classPrefix: '()',
|
|
2725
|
-
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
2726
|
-
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
2727
|
-
},
|
|
2728
|
-
hook: {
|
|
2729
|
-
folder: 'hooks',
|
|
2730
|
-
nested: false,
|
|
2731
|
-
inFolder: false,
|
|
2732
|
-
ownFile: (fileBase)=>new RegExp(`^use-${escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
2733
|
-
target: (reactFolder, { fileName })=>node_path.join(reactFolder, 'hooks', `use-${fileName}.ts`),
|
|
2734
|
-
classPrefix: '(use)',
|
|
2735
|
-
classSuffix: '(?![\\w$])'
|
|
2736
|
-
}
|
|
2737
|
-
};
|
|
2738
|
-
const reactKindTitles = {
|
|
2739
|
-
page: [
|
|
2740
|
-
'Page',
|
|
2741
|
-
'pages'
|
|
2742
|
-
],
|
|
2743
|
-
widget: [
|
|
2744
|
-
'Widget',
|
|
2745
|
-
'widgets'
|
|
2746
|
-
],
|
|
2747
|
-
'ui-kit': [
|
|
2748
|
-
'UI-kit component',
|
|
2749
|
-
'UI-kit components'
|
|
2750
|
-
],
|
|
2751
|
-
hook: [
|
|
2752
|
-
'Shared hook',
|
|
2753
|
-
'shared hooks'
|
|
2754
|
-
]
|
|
2755
|
-
};
|
|
2756
|
-
const reactModuleName = (kind, rawName)=>'hook' === kind ? rawName.trim().replace(/^use-/, '') : rawName;
|
|
2757
|
-
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
2758
|
-
const prefix = `${folders.join('-')}-`;
|
|
2759
|
-
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
2760
|
-
return [
|
|
2761
|
-
...folders,
|
|
2762
|
-
last
|
|
2763
|
-
].join('/');
|
|
2764
|
-
};
|
|
2765
|
-
const declaredClassName = (filePath, suffix, name)=>{
|
|
2766
|
-
const content = node_fs.readFileSync(filePath, 'utf8');
|
|
2767
|
-
const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
2768
|
-
return declared ?? new NestedName(name).ClassName;
|
|
2769
|
-
};
|
|
2770
|
-
const findUiKit = (reactFolder)=>{
|
|
2771
|
-
const root = node_path.join(reactFolder, 'ui-kit');
|
|
2772
|
-
if (!node_fs.existsSync(root)) return [];
|
|
2773
|
-
return node_fs.readdirSync(root, {
|
|
2774
|
-
withFileTypes: true
|
|
2775
|
-
}).filter((entry)=>entry.isDirectory() && node_fs.existsSync(node_path.join(root, entry.name, `${entry.name}.tsx`))).map(({ name })=>({
|
|
2776
|
-
kind: 'ui-kit',
|
|
2777
|
-
name,
|
|
2778
|
-
path: node_path.join(root, name),
|
|
2779
|
-
fileBase: name,
|
|
2780
|
-
ClassName: declaredClassName(node_path.join(root, name, `${name}.tsx`), '', name)
|
|
2781
|
-
}));
|
|
2782
|
-
};
|
|
2783
|
-
const findHooks = (reactFolder)=>{
|
|
2784
|
-
const root = node_path.join(reactFolder, 'hooks');
|
|
2785
|
-
if (!node_fs.existsSync(root)) return [];
|
|
2786
|
-
return node_fs.readdirSync(root).filter((file)=>/^use-.+\.tsx?$/.test(file) && !/\.(spec|test)\./.test(file)).map((file)=>{
|
|
2787
|
-
const name = file.replace(/^use-/, '').replace(/\.tsx?$/, '');
|
|
2788
|
-
const content = node_fs.readFileSync(node_path.join(root, file), 'utf8');
|
|
2789
|
-
return {
|
|
2790
|
-
kind: 'hook',
|
|
2791
|
-
name,
|
|
2792
|
-
path: node_path.join(root, file),
|
|
2793
|
-
fileBase: name,
|
|
2794
|
-
ClassName: content.match(/export\s+(?:const|function)\s+use(\w+)\b/)?.[1] ?? new NestedName(name).ClassName
|
|
2795
|
-
};
|
|
2796
|
-
});
|
|
2797
|
-
};
|
|
2798
|
-
const findReactModules = (reactFolder, kind)=>{
|
|
2799
|
-
const modules = 'ui-kit' === kind ? findUiKit(reactFolder) : 'hook' === kind ? findHooks(reactFolder) : 'page' === kind ? walk(node_path.join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
2800
|
-
const folders = node_path.relative(node_path.join(reactFolder, 'pages'), node_path.dirname(file)).split(node_path.sep).filter((segment)=>!!segment);
|
|
2801
|
-
const fileBase = node_path.basename(file, '-page.tsx');
|
|
2802
|
-
const name = react_module_move_nestedName(folders, fileBase);
|
|
2803
|
-
return {
|
|
2804
|
-
kind,
|
|
2805
|
-
name,
|
|
2806
|
-
path: file,
|
|
2807
|
-
fileBase,
|
|
2808
|
-
ClassName: declaredClassName(file, 'Page', name)
|
|
2809
|
-
};
|
|
2810
|
-
}) : walk(node_path.join(reactFolder, 'widgets')).filter((file)=>file.endsWith('-widget.tsx')).map((file)=>{
|
|
2811
|
-
const folder = node_path.dirname(file);
|
|
2812
|
-
const name = toPosix(node_path.relative(node_path.join(reactFolder, 'widgets'), folder));
|
|
2813
|
-
return {
|
|
2814
|
-
kind,
|
|
2815
|
-
name,
|
|
2816
|
-
path: folder,
|
|
2817
|
-
fileBase: node_path.basename(file, '-widget.tsx'),
|
|
2818
|
-
ClassName: declaredClassName(file, 'Widget', name)
|
|
2819
|
-
};
|
|
2820
|
-
});
|
|
2821
|
-
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
2822
|
-
};
|
|
2823
|
-
const targetPath = (reactFolder, module, rawName)=>reactKindLayouts[module.kind].target(reactFolder, new NestedName(reactModuleName(module.kind, rawName)));
|
|
2824
|
-
const validateMove = (reactFolder, module, rawName)=>{
|
|
2825
|
-
const nameError = NestedName.validate(rawName);
|
|
2826
|
-
if (true !== nameError) return nameError;
|
|
2827
|
-
if (!reactKindLayouts[module.kind].nested && /[\\/]/.test(rawName)) return 'UI-kit components and shared hooks have no folders: enter a name without "/"';
|
|
2828
|
-
const target = targetPath(reactFolder, module, rawName);
|
|
2829
|
-
if (target !== module.path && node_fs.existsSync(target)) return `${node_path.relative(reactFolder, target)} already exists`;
|
|
2830
|
-
if (target.startsWith(`${module.path}${node_path.sep}`)) return 'A widget cannot be moved into itself';
|
|
2831
|
-
return true;
|
|
2832
|
-
};
|
|
2833
|
-
const react_module_move_routeFolder = (appFolder, rawName)=>{
|
|
2834
|
-
const { folders, folderName } = new NestedName(rawName);
|
|
2835
|
-
return node_path.join(appFolder, ...folders, folderName);
|
|
2836
|
-
};
|
|
2837
|
-
const routeFiles = (folder)=>node_fs.existsSync(folder) ? node_fs.readdirSync(folder, {
|
|
2838
|
-
withFileTypes: true
|
|
2839
|
-
}).filter((entry)=>entry.isFile()).map((entry)=>node_path.join(folder, entry.name)) : [];
|
|
2840
|
-
const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
2841
|
-
const layout = reactKindLayouts[module.kind];
|
|
2842
|
-
const newName = new NestedName(reactModuleName(module.kind, rawName));
|
|
2843
|
-
const target = targetPath(reactFolder, module, rawName);
|
|
2844
|
-
const newClassName = newName.ClassName;
|
|
2845
|
-
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.]|$)`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
2846
|
-
const oldFolder = layout.inFolder ? module.path : node_path.dirname(module.path);
|
|
2847
|
-
const newFolder = layout.inFolder ? target : node_path.dirname(target);
|
|
2848
|
-
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));
|
|
2849
|
-
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
2850
|
-
const routeTarget = (candidate)=>{
|
|
2851
|
-
if (!route) return;
|
|
2852
|
-
const file = [
|
|
2853
|
-
...routeFileSet
|
|
2854
|
-
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
2855
|
-
if (!file) return;
|
|
2856
|
-
const moved = node_path.join(route.to, node_path.relative(route.from, file));
|
|
2857
|
-
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
2858
|
-
};
|
|
2859
|
-
const movedPath = (candidate)=>{
|
|
2860
|
-
const routed = routeTarget(candidate);
|
|
2861
|
-
if (routed) return routed;
|
|
2862
|
-
if (!ownsPath(candidate)) return;
|
|
2863
|
-
const segments = node_path.relative(oldFolder, candidate).split(node_path.sep);
|
|
2864
|
-
const last = segments.length - 1;
|
|
2865
|
-
segments[last] = renameFile(segments[last]);
|
|
2866
|
-
return node_path.join(newFolder, ...segments);
|
|
2867
|
-
};
|
|
2868
|
-
const moduleFiles = reactModuleFiles(module);
|
|
2869
|
-
const moves = new Map([
|
|
2870
|
-
...moduleFiles,
|
|
2871
|
-
...routeFileSet
|
|
2872
|
-
].map((file)=>[
|
|
2873
|
-
file,
|
|
2874
|
-
movedPath(file) ?? file
|
|
2875
|
-
]));
|
|
2876
|
-
const classPattern = new RegExp(`(?<![\\w$])${layout.classPrefix}${escapeRegExp(module.ClassName)}(?=${layout.classSuffix})`, 'g');
|
|
2877
|
-
const oldTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
2878
|
-
module.ClassName
|
|
2879
|
-
] : module.name.split('/').map((segment)=>new NestedName(segment).ClassName));
|
|
2880
|
-
const titlePattern = oldTitle && new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
2881
|
-
const newTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
2882
|
-
newClassName
|
|
2883
|
-
] : newName.classNameSegments);
|
|
2884
|
-
return stageModuleMove({
|
|
2885
|
-
projectRoot,
|
|
2886
|
-
stopAt: reactFolder,
|
|
2887
|
-
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
2888
|
-
moves,
|
|
2889
|
-
movedPath,
|
|
2890
|
-
rename: (content, { moved })=>{
|
|
2891
|
-
const renamed = content.replace(classPattern, (_, use)=>`${use ?? ''}${newClassName}`);
|
|
2892
|
-
return moved && titlePattern ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
2893
|
-
}
|
|
2894
|
-
});
|
|
2895
|
-
};
|
|
2896
|
-
const pageRouteFolder = (appFolder, page)=>{
|
|
2897
|
-
const folder = react_module_move_routeFolder(appFolder, page.name);
|
|
2898
|
-
const routePage = node_path.join(folder, 'page.tsx');
|
|
2899
|
-
return node_fs.existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(node_fs.readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
2900
|
-
};
|
|
2901
|
-
const reactModuleFiles = (module)=>{
|
|
2902
|
-
const layout = reactKindLayouts[module.kind];
|
|
2903
|
-
if (layout.inFolder) return walk(module.path);
|
|
2904
|
-
const folder = node_path.dirname(module.path);
|
|
2905
|
-
const own = layout.ownFile(module.fileBase);
|
|
2906
|
-
return node_fs.readdirSync(folder, {
|
|
2907
|
-
withFileTypes: true
|
|
2908
|
-
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>node_path.join(folder, entry.name));
|
|
2909
|
-
};
|
|
2910
|
-
const react_module_move_importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
2911
|
-
const deleteReactModule = (projectRoot, reactFolder, module, route)=>{
|
|
2912
|
-
const moduleFiles = reactModuleFiles(module);
|
|
2913
|
-
const routeFileList = route ? routeFiles(route.folder) : [];
|
|
2914
|
-
const own = new Set([
|
|
2915
|
-
...moduleFiles,
|
|
2916
|
-
...routeFileList
|
|
2917
|
-
]);
|
|
2918
|
-
const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
|
|
2919
|
-
const isModule = (resolved)=>stems.has(resolved) || reactKindLayouts[module.kind].inFolder && (resolved === module.path || resolved.startsWith(`${module.path}${node_path.sep}`));
|
|
2920
|
-
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
2921
|
-
const relative = (file)=>toPosix(node_path.relative(projectRoot, file));
|
|
2922
|
-
const usedBy = [];
|
|
2923
|
-
for (const [file, content] of codeFiles)if (!own.has(file)) for (const [, , specifier] of content.matchAll(react_module_move_importSpecifier)){
|
|
2924
|
-
const target = resolve(specifier, file)?.resolved;
|
|
2925
|
-
if (target && isModule(target)) usedBy.push([
|
|
2926
|
-
relative(file),
|
|
2927
|
-
relative(target)
|
|
2928
|
-
]);
|
|
2929
|
-
}
|
|
2930
|
-
if (usedBy.length) return {
|
|
2931
|
-
usedBy
|
|
2932
|
-
};
|
|
2933
|
-
for (const file of moduleFiles)new File(file).delete(reactFolder);
|
|
2934
|
-
for (const file of routeFileList)new File(file).delete(route.appFolder);
|
|
2935
|
-
return {
|
|
2936
|
-
deleted: [
|
|
2937
|
-
...moduleFiles,
|
|
2938
|
-
...routeFileList
|
|
2939
|
-
]
|
|
2940
|
-
};
|
|
2941
|
-
};
|
|
2942
|
-
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
2943
|
-
if ('ports' === kind) return crossContext ? [
|
|
2944
|
-
{
|
|
2945
|
-
name: 'System: cross-context (calls handlers in another bounded context)',
|
|
2946
|
-
value: crossContextImplementation
|
|
2947
|
-
}
|
|
2948
|
-
] : [];
|
|
2949
|
-
return ConfigFile.exists && usesInMemoryDb('in-memory') ? [
|
|
2950
|
-
{
|
|
2951
|
-
name: 'System: in-memory (uses the shared in-memory database)',
|
|
2952
|
-
value: 'in-memory'
|
|
2953
|
-
}
|
|
2954
|
-
] : [];
|
|
2955
|
-
};
|
|
2956
2511
|
const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
2957
2512
|
const root = new ProjectRoot().path;
|
|
2958
2513
|
const rootFolderPath = node_path.join(root, ConfigFile.Instance.data.project.rootFolder);
|
|
@@ -3004,14 +2559,36 @@ const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3004
2559
|
report('Cancelled: nothing was deleted.');
|
|
3005
2560
|
}
|
|
3006
2561
|
};
|
|
3007
|
-
const
|
|
2562
|
+
const pageRouter = (framework)=>{
|
|
2563
|
+
if ('react' === framework) return usesNext() ? {
|
|
2564
|
+
title: 'Next.js',
|
|
2565
|
+
folder: nextAppFolder,
|
|
2566
|
+
pageFile: routePageFile.react
|
|
2567
|
+
} : void 0;
|
|
2568
|
+
return usesSvelteKit() ? {
|
|
2569
|
+
title: 'SvelteKit',
|
|
2570
|
+
folder: svelteKitRoutesFolder,
|
|
2571
|
+
pageFile: routePageFile.svelte
|
|
2572
|
+
} : void 0;
|
|
2573
|
+
};
|
|
2574
|
+
const frameworkTitles = {
|
|
2575
|
+
react: {
|
|
2576
|
+
title: 'React',
|
|
2577
|
+
cli: 'df-react'
|
|
2578
|
+
},
|
|
2579
|
+
svelte: {
|
|
2580
|
+
title: 'Svelte',
|
|
2581
|
+
cli: 'df-svelte'
|
|
2582
|
+
}
|
|
2583
|
+
};
|
|
2584
|
+
const deleteReactModuleUseCase = async (presentationReactFolder, kind, framework = 'react')=>{
|
|
3008
2585
|
const reactFolder = presentationReactFolder.path;
|
|
3009
|
-
const modules = findReactModules(reactFolder, kind);
|
|
3010
|
-
if (!modules.length) return void report(`No ${
|
|
2586
|
+
const modules = findReactModules(reactFolder, kind, framework);
|
|
2587
|
+
if (!modules.length) return void report(`No ${frontendKindTitles(framework)[kind][1]} generated by ${frameworkTitles[framework].cli} were found.`);
|
|
3011
2588
|
const module = await interaction_select({
|
|
3012
2589
|
key: 'module',
|
|
3013
2590
|
id: (value)=>value.name,
|
|
3014
|
-
message: `${
|
|
2591
|
+
message: `${frontendKindTitles(framework)[kind][0]} to delete:`,
|
|
3015
2592
|
choices: modules.map((value)=>({
|
|
3016
2593
|
name: value.name,
|
|
3017
2594
|
value,
|
|
@@ -3020,17 +2597,18 @@ const deleteReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
3020
2597
|
});
|
|
3021
2598
|
const root = new ProjectRoot().path;
|
|
3022
2599
|
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3023
|
-
const
|
|
3024
|
-
const
|
|
2600
|
+
const router = 'page' === kind ? pageRouter(framework) : void 0;
|
|
2601
|
+
const appFolder = router && node_path.join(root, router.folder(root));
|
|
2602
|
+
const routeFolder = router && appFolder ? pageRouteFolder(appFolder, module, framework) : void 0;
|
|
3025
2603
|
const withRoute = !!routeFolder && await interaction_confirm({
|
|
3026
2604
|
key: 'deleteRoute',
|
|
3027
|
-
message: `Delete its
|
|
2605
|
+
message: `Delete its ${router?.title} route too: ${relative(routeFolder)}? Its URL stops working.`,
|
|
3028
2606
|
default: true
|
|
3029
2607
|
});
|
|
3030
|
-
const result = deleteReactModule(root, reactFolder, module, withRoute && routeFolder ? {
|
|
2608
|
+
const result = deleteReactModule(root, reactFolder, module, withRoute && routeFolder && appFolder ? {
|
|
3031
2609
|
appFolder,
|
|
3032
2610
|
folder: routeFolder
|
|
3033
|
-
} : void 0);
|
|
2611
|
+
} : void 0, framework);
|
|
3034
2612
|
if (result.usedBy) {
|
|
3035
2613
|
if (isNonInteractive()) throw new RequestError('DELETE_NOT_ALLOWED', `Other files still use the ${kind}.`, {
|
|
3036
2614
|
usedBy: result.usedBy
|
|
@@ -3195,9 +2773,27 @@ const configureBackend = async (config)=>{
|
|
|
3195
2773
|
if (envBranches && !envBranchedWireExisted) notes.push(`${rootFolderName}/shared-kernel/wiring/env-branched-wire.ts doesn't compile until you write currentBranch: return the branch this process runs in (${envBranches.names.join(', ')})`);
|
|
3196
2774
|
return notes;
|
|
3197
2775
|
};
|
|
2776
|
+
const frontendPackages = {
|
|
2777
|
+
react: [
|
|
2778
|
+
'react',
|
|
2779
|
+
'react-dom'
|
|
2780
|
+
],
|
|
2781
|
+
next: [
|
|
2782
|
+
'next',
|
|
2783
|
+
'react',
|
|
2784
|
+
'react-dom'
|
|
2785
|
+
],
|
|
2786
|
+
svelte: [
|
|
2787
|
+
'svelte'
|
|
2788
|
+
],
|
|
2789
|
+
sveltekit: [
|
|
2790
|
+
'@sveltejs/kit',
|
|
2791
|
+
'svelte'
|
|
2792
|
+
]
|
|
2793
|
+
};
|
|
2794
|
+
const savedFrontendChoice = ({ frontend })=>frontend?.react?.framework ?? frontend?.svelte?.framework ?? (frontend?.react ? 'react' : frontend?.svelte ? 'svelte' : void 0);
|
|
3198
2795
|
const configureFrontend = async (config)=>{
|
|
3199
|
-
const
|
|
3200
|
-
const framework = await prompts_select({
|
|
2796
|
+
const choice = await prompts_select({
|
|
3201
2797
|
message: 'Frontend framework:',
|
|
3202
2798
|
choices: [
|
|
3203
2799
|
{
|
|
@@ -3207,51 +2803,58 @@ const configureFrontend = async (config)=>{
|
|
|
3207
2803
|
{
|
|
3208
2804
|
name: 'Next.js',
|
|
3209
2805
|
value: 'next'
|
|
2806
|
+
},
|
|
2807
|
+
{
|
|
2808
|
+
name: 'Svelte',
|
|
2809
|
+
value: 'svelte'
|
|
2810
|
+
},
|
|
2811
|
+
{
|
|
2812
|
+
name: 'SvelteKit',
|
|
2813
|
+
value: 'sveltekit'
|
|
3210
2814
|
}
|
|
3211
2815
|
],
|
|
3212
|
-
default:
|
|
2816
|
+
default: savedFrontendChoice(config) ?? (hasDependency('next') ? 'next' : hasDependency('@sveltejs/kit') ? 'sveltekit' : hasDependency('svelte') ? 'svelte' : 'react')
|
|
3213
2817
|
});
|
|
3214
|
-
const
|
|
3215
|
-
|
|
3216
|
-
|
|
2818
|
+
const family = 'react' === choice || 'next' === choice ? 'react' : 'svelte';
|
|
2819
|
+
const adapter = 'next' === choice ? 'next' : 'sveltekit' === choice ? 'svelte' : void 0;
|
|
2820
|
+
const restAdapter = adapter && config.backend ? {
|
|
2821
|
+
adapter: await askRestAdapter({
|
|
2822
|
+
adapter
|
|
2823
|
+
})
|
|
2824
|
+
} : {
|
|
2825
|
+
adapter: void 0
|
|
2826
|
+
};
|
|
2827
|
+
const current = config.frontend?.[family];
|
|
3217
2828
|
const withStorybook = await prompts_confirm({
|
|
3218
2829
|
message: 'Use Storybook',
|
|
3219
|
-
default:
|
|
2830
|
+
default: current ? Boolean(current.storybookFramework) : true
|
|
3220
2831
|
});
|
|
3221
|
-
const
|
|
2832
|
+
const { react, svelte, ...otherSettings } = config.frontend ?? {};
|
|
3222
2833
|
ConfigFile.update({
|
|
3223
2834
|
frontend: {
|
|
3224
|
-
...
|
|
3225
|
-
|
|
3226
|
-
...
|
|
3227
|
-
framework,
|
|
3228
|
-
storybookFramework
|
|
2835
|
+
...otherSettings,
|
|
2836
|
+
[family]: {
|
|
2837
|
+
...current,
|
|
2838
|
+
framework: choice,
|
|
2839
|
+
storybookFramework: withStorybook ? storybookPackageFor(choice) : void 0
|
|
3229
2840
|
}
|
|
3230
2841
|
}
|
|
3231
2842
|
});
|
|
3232
2843
|
return {
|
|
3233
|
-
|
|
2844
|
+
restAdapter,
|
|
3234
2845
|
nextSteps: [
|
|
3235
|
-
...missingPackages(
|
|
3236
|
-
'next',
|
|
3237
|
-
'react',
|
|
3238
|
-
'react-dom'
|
|
3239
|
-
] : [
|
|
3240
|
-
'react',
|
|
3241
|
-
'react-dom'
|
|
3242
|
-
]),
|
|
2846
|
+
...missingPackages(frontendPackages[choice]),
|
|
3243
2847
|
...withStorybook ? await addStorybook() : []
|
|
3244
2848
|
]
|
|
3245
2849
|
};
|
|
3246
2850
|
};
|
|
3247
|
-
const configureRest = async (
|
|
2851
|
+
const configureRest = async (restAdapter)=>{
|
|
3248
2852
|
const backend = ConfigFile.Instance.data.backend;
|
|
3249
2853
|
if (!backend) return [];
|
|
3250
2854
|
const withRest = backend.domainFirstPackages.includes('@domain-first/handlers-rest');
|
|
3251
|
-
const
|
|
3252
|
-
if (
|
|
3253
|
-
if (
|
|
3254
|
-
if (withNextAdapter && !withRest) ConfigFile.update({
|
|
2855
|
+
const adapter = restAdapter?.adapter ?? (restAdapter ? void 0 : await askRestAdapter());
|
|
2856
|
+
if (!withRest && !adapter) return [];
|
|
2857
|
+
if (adapter && !withRest) ConfigFile.update({
|
|
3255
2858
|
backend: {
|
|
3256
2859
|
...backend,
|
|
3257
2860
|
domainFirstPackages: [
|
|
@@ -3261,7 +2864,7 @@ const configureRest = async (withNextAdapter)=>{
|
|
|
3261
2864
|
}
|
|
3262
2865
|
});
|
|
3263
2866
|
return scaffoldRestEndpointGeneratorFiles({
|
|
3264
|
-
|
|
2867
|
+
adapter
|
|
3265
2868
|
});
|
|
3266
2869
|
};
|
|
3267
2870
|
const initializeUseCase = async (section)=>{
|
|
@@ -3298,7 +2901,7 @@ const initializeUseCase = async (section)=>{
|
|
|
3298
2901
|
}
|
|
3299
2902
|
const nextSteps = [];
|
|
3300
2903
|
let backendConfigured = false;
|
|
3301
|
-
let
|
|
2904
|
+
let restAdapter;
|
|
3302
2905
|
for (const currentSection of sections){
|
|
3303
2906
|
console.log(`\n${currentSection[0].toUpperCase()}${currentSection.slice(1)} configuration`);
|
|
3304
2907
|
if (!section && sections.length > 1 && !await prompts_confirm({
|
|
@@ -3321,14 +2924,14 @@ const initializeUseCase = async (section)=>{
|
|
|
3321
2924
|
case 'frontend':
|
|
3322
2925
|
{
|
|
3323
2926
|
const frontend = await configureFrontend(config);
|
|
3324
|
-
|
|
2927
|
+
restAdapter = frontend.restAdapter;
|
|
3325
2928
|
nextSteps.push(...frontend.nextSteps);
|
|
3326
2929
|
break;
|
|
3327
2930
|
}
|
|
3328
2931
|
}
|
|
3329
2932
|
}
|
|
3330
|
-
if (backendConfigured ||
|
|
3331
|
-
const restSteps = await configureRest(
|
|
2933
|
+
if (backendConfigured || restAdapter?.adapter) {
|
|
2934
|
+
const restSteps = await configureRest(restAdapter);
|
|
3332
2935
|
nextSteps.push(...missingDomainFirstPackages(), ...restSteps);
|
|
3333
2936
|
}
|
|
3334
2937
|
return nextSteps;
|
|
@@ -3429,17 +3032,18 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
3429
3032
|
report('Cancelled: nothing was written.');
|
|
3430
3033
|
}
|
|
3431
3034
|
};
|
|
3432
|
-
const promptRouteMove = async (root, page, newName)=>{
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
const
|
|
3035
|
+
const promptRouteMove = async (root, page, newName, framework)=>{
|
|
3036
|
+
const router = pageRouter(framework);
|
|
3037
|
+
if (!router) return;
|
|
3038
|
+
const appFolder = node_path.join(root, router.folder(root));
|
|
3039
|
+
const from = pageRouteFolder(appFolder, page, framework);
|
|
3436
3040
|
const to = react_module_move_routeFolder(appFolder, newName);
|
|
3437
3041
|
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3438
3042
|
if (!from || from === to) return;
|
|
3439
|
-
if (node_fs.existsSync(node_path.join(to,
|
|
3043
|
+
if (node_fs.existsSync(node_path.join(to, router.pageFile))) return void report(`${relative(to)}/${router.pageFile} already exists: the route ${relative(from)} stays.`);
|
|
3440
3044
|
const move = await interaction_confirm({
|
|
3441
3045
|
key: 'moveRoute',
|
|
3442
|
-
message: `Move the
|
|
3046
|
+
message: `Move the ${router.title} route too: ${relative(from)} → ${relative(to)}? Its URL changes.`,
|
|
3443
3047
|
default: true
|
|
3444
3048
|
});
|
|
3445
3049
|
return move ? {
|
|
@@ -3448,14 +3052,14 @@ const promptRouteMove = async (root, page, newName)=>{
|
|
|
3448
3052
|
to
|
|
3449
3053
|
} : void 0;
|
|
3450
3054
|
};
|
|
3451
|
-
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
3055
|
+
const moveReactModuleUseCase = async (presentationReactFolder, kind, framework = 'react')=>{
|
|
3452
3056
|
const reactFolder = presentationReactFolder.path;
|
|
3453
|
-
const modules = findReactModules(reactFolder, kind);
|
|
3454
|
-
if (!modules.length) return void report(`No ${
|
|
3057
|
+
const modules = findReactModules(reactFolder, kind, framework);
|
|
3058
|
+
if (!modules.length) return void report(`No ${frontendKindTitles(framework)[kind][1]} generated by ${frameworkTitles[framework].cli} were found.`);
|
|
3455
3059
|
const module = await interaction_select({
|
|
3456
3060
|
key: 'module',
|
|
3457
3061
|
id: (value)=>value.name,
|
|
3458
|
-
message: `${
|
|
3062
|
+
message: `${frontendKindTitles(framework)[kind][0]}:`,
|
|
3459
3063
|
choices: modules.map((value)=>({
|
|
3460
3064
|
name: value.name,
|
|
3461
3065
|
value,
|
|
@@ -3464,14 +3068,14 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
3464
3068
|
});
|
|
3465
3069
|
const name = await interaction_input({
|
|
3466
3070
|
key: 'name',
|
|
3467
|
-
message:
|
|
3071
|
+
message: frontendKindLayouts(framework)[kind].nested ? 'New name (folders split by "/"):' : 'New name:',
|
|
3468
3072
|
default: module.name,
|
|
3469
|
-
validate: (value)=>validateMove(reactFolder, module, value)
|
|
3073
|
+
validate: (value)=>validateMove(reactFolder, module, value, framework)
|
|
3470
3074
|
});
|
|
3471
3075
|
const root = new ProjectRoot().path;
|
|
3472
3076
|
const relative = (file)=>node_path.relative(root, file).split(node_path.sep).join('/');
|
|
3473
|
-
const route = 'page' === kind ? await promptRouteMove(root, module, name) : void 0;
|
|
3474
|
-
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route);
|
|
3077
|
+
const route = 'page' === kind ? await promptRouteMove(root, module, name, framework) : void 0;
|
|
3078
|
+
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route, framework);
|
|
3475
3079
|
if (!moves.length && !updated.length) return void report('Nothing to change.');
|
|
3476
3080
|
report([
|
|
3477
3081
|
'Files to move:',
|
|
@@ -3490,6 +3094,20 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
3490
3094
|
report('Cancelled: nothing was written.');
|
|
3491
3095
|
}
|
|
3492
3096
|
};
|
|
3097
|
+
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
3098
|
+
if ('ports' === kind) return crossContext ? [
|
|
3099
|
+
{
|
|
3100
|
+
name: 'System: cross-context (calls handlers in another bounded context)',
|
|
3101
|
+
value: crossContextImplementation
|
|
3102
|
+
}
|
|
3103
|
+
] : [];
|
|
3104
|
+
return ConfigFile.exists && usesInMemoryDb('in-memory') ? [
|
|
3105
|
+
{
|
|
3106
|
+
name: 'System: in-memory (uses the shared in-memory database)',
|
|
3107
|
+
value: 'in-memory'
|
|
3108
|
+
}
|
|
3109
|
+
] : [];
|
|
3110
|
+
};
|
|
3493
3111
|
const enterImplementationTypeOnce = Symbol('enter-implementation-type-once');
|
|
3494
3112
|
const implementationTypeEntryChoices = [
|
|
3495
3113
|
{
|
|
@@ -4766,4 +4384,4 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
4766
4384
|
break;
|
|
4767
4385
|
}
|
|
4768
4386
|
};
|
|
4769
|
-
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 };
|