@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/react.cjs
CHANGED
|
@@ -481,6 +481,7 @@ const lintChecks = [
|
|
|
481
481
|
'layers',
|
|
482
482
|
'dependencies',
|
|
483
483
|
'react',
|
|
484
|
+
'svelte',
|
|
484
485
|
'clock',
|
|
485
486
|
'config'
|
|
486
487
|
];
|
|
@@ -525,8 +526,16 @@ const reactConfigSchema = external_zod_default().object({
|
|
|
525
526
|
]).optional(),
|
|
526
527
|
storybookFramework: external_zod_default().string().optional()
|
|
527
528
|
}).passthrough();
|
|
529
|
+
const svelteConfigSchema = external_zod_default().object({
|
|
530
|
+
framework: external_zod_default()["enum"]([
|
|
531
|
+
'svelte',
|
|
532
|
+
'sveltekit'
|
|
533
|
+
]).optional(),
|
|
534
|
+
storybookFramework: external_zod_default().string().optional()
|
|
535
|
+
}).passthrough();
|
|
528
536
|
const frontendConfigSchema = external_zod_default().object({
|
|
529
|
-
react: reactConfigSchema.optional()
|
|
537
|
+
react: reactConfigSchema.optional(),
|
|
538
|
+
svelte: svelteConfigSchema.optional()
|
|
530
539
|
}).passthrough();
|
|
531
540
|
const configSchema = external_zod_default().object({
|
|
532
541
|
project: projectConfigSchema,
|
|
@@ -1591,6 +1600,11 @@ const nextAppFolder = (root)=>[
|
|
|
1591
1600
|
'app',
|
|
1592
1601
|
'src/app'
|
|
1593
1602
|
].find((folder)=>new file_system_Folder(external_node_path_default().join(root, folder)).exists) ?? 'app';
|
|
1603
|
+
const usesSvelteKit = ()=>config_file_ConfigFile.exists && config_file_ConfigFile.Instance.data.frontend?.svelte?.framework === 'sveltekit';
|
|
1604
|
+
const svelteKitRoutesFolder = (root)=>[
|
|
1605
|
+
'src/routes',
|
|
1606
|
+
'routes'
|
|
1607
|
+
].find((folder)=>new file_system_Folder(external_node_path_default().join(root, folder)).exists) ?? 'src/routes';
|
|
1594
1608
|
const external_node_module_namespaceObject = require("node:module");
|
|
1595
1609
|
const stripJsonComments = (source)=>source.replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (_, text)=>text ? text : '').replace(/,(\s*[}\]])/g, '$1');
|
|
1596
1610
|
const resolveExtends = (fromFile, target)=>{
|
|
@@ -1670,196 +1684,915 @@ const scaffoldReactPage = async (presentationReactFolder)=>{
|
|
|
1670
1684
|
if (hint) report(hint);
|
|
1671
1685
|
}
|
|
1672
1686
|
};
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
];
|
|
1698
|
-
return [
|
|
1699
|
-
path.join(restFolder, ...endpointPath),
|
|
1700
|
-
path.join(restFolder, '(root)', ...endpointPath)
|
|
1701
|
-
];
|
|
1702
|
-
})
|
|
1703
|
-
.map((file) => project.getSourceFile(file))
|
|
1704
|
-
.find((file) => !!file);
|
|
1705
|
-
`;
|
|
1706
|
-
const openapiExtractor = (rootFolder)=>`import path from 'node:path';
|
|
1707
|
-
import {
|
|
1708
|
-
type DocNode,
|
|
1709
|
-
DocPlainText,
|
|
1710
|
-
TSDocConfiguration,
|
|
1711
|
-
TSDocParser,
|
|
1712
|
-
TSDocTagDefinition,
|
|
1713
|
-
TSDocTagSyntaxKind
|
|
1714
|
-
} from '@microsoft/tsdoc';
|
|
1715
|
-
import { Node, Project, type SourceFile, SyntaxKind } from 'ts-morph';
|
|
1716
|
-
|
|
1717
|
-
type BlockTag = \`@\${string}\`;
|
|
1718
|
-
|
|
1719
|
-
type OpenApiDataTags = {
|
|
1720
|
-
/** Omit to take the summary from the comment text before the first tag. */
|
|
1721
|
-
summary?: BlockTag;
|
|
1722
|
-
description?: BlockTag;
|
|
1687
|
+
const ignoredFolders = new Set([
|
|
1688
|
+
'node_modules',
|
|
1689
|
+
'.git',
|
|
1690
|
+
'.next',
|
|
1691
|
+
'.svelte-kit',
|
|
1692
|
+
'dist',
|
|
1693
|
+
'build',
|
|
1694
|
+
'out',
|
|
1695
|
+
'coverage',
|
|
1696
|
+
'storybook-static'
|
|
1697
|
+
]);
|
|
1698
|
+
const codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx|svelte)$/;
|
|
1699
|
+
const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1700
|
+
const module_move_walk = (folder)=>{
|
|
1701
|
+
if (!external_node_fs_default().existsSync(folder)) return [];
|
|
1702
|
+
return external_node_fs_default().readdirSync(folder, {
|
|
1703
|
+
withFileTypes: true
|
|
1704
|
+
}).flatMap((entry)=>{
|
|
1705
|
+
const entryPath = external_node_path_default().join(folder, entry.name);
|
|
1706
|
+
if (entry.isDirectory()) return ignoredFolders.has(entry.name) ? [] : module_move_walk(entryPath);
|
|
1707
|
+
return entry.isFile() ? [
|
|
1708
|
+
entryPath
|
|
1709
|
+
] : [];
|
|
1710
|
+
});
|
|
1723
1711
|
};
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
.getChildNodes()
|
|
1738
|
-
.map((child) => {
|
|
1739
|
-
if (child instanceof DocPlainText) {
|
|
1740
|
-
return child.text;
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
return getText(child);
|
|
1744
|
-
})
|
|
1745
|
-
.join('');
|
|
1746
|
-
|
|
1747
|
-
const getRawCommentText = (comment: string): string =>
|
|
1748
|
-
comment
|
|
1749
|
-
.replace(/^\\/\\*\\*/, '')
|
|
1750
|
-
.replace(/\\*\\/$/, '')
|
|
1751
|
-
.split(/\\r?\\n/)
|
|
1752
|
-
.map((line) => line.replace(/^\\s*\\*\\s?/, ''))
|
|
1753
|
-
.join('\\n');
|
|
1754
|
-
|
|
1755
|
-
// TSDoc treats an unknown tag as summary content, so every block tag of the
|
|
1756
|
-
// comment has to be registered for the summary section to end before it.
|
|
1757
|
-
const parseSummary = (comment: string): string | undefined => {
|
|
1758
|
-
const configuration = new TSDocConfiguration();
|
|
1759
|
-
const tagNames = getRawCommentText(comment).matchAll(/(?:^|\\n)\\s*(@\\w+)/g);
|
|
1760
|
-
|
|
1761
|
-
for (const [, tagName] of tagNames) {
|
|
1762
|
-
if (!configuration.tryGetTagDefinition(tagName)) {
|
|
1763
|
-
configuration.addTagDefinition(
|
|
1764
|
-
new TSDocTagDefinition({
|
|
1765
|
-
tagName,
|
|
1766
|
-
syntaxKind: TSDocTagSyntaxKind.BlockTag
|
|
1767
|
-
})
|
|
1768
|
-
);
|
|
1769
|
-
}
|
|
1712
|
+
const toPosix = (value)=>value.split(external_node_path_default().sep).join('/');
|
|
1713
|
+
const readAliases = (projectRoot)=>{
|
|
1714
|
+
const tsconfig = external_node_path_default().join(projectRoot, 'tsconfig.json');
|
|
1715
|
+
if (!external_node_fs_default().existsSync(tsconfig)) return [];
|
|
1716
|
+
try {
|
|
1717
|
+
const { compilerOptions = {} } = JSON.parse(stripJsonComments(external_node_fs_default().readFileSync(tsconfig, 'utf8')));
|
|
1718
|
+
const base = external_node_path_default().resolve(projectRoot, compilerOptions.baseUrl ?? '.');
|
|
1719
|
+
return Object.entries(compilerOptions.paths ?? {}).filter(([pattern, targets])=>pattern.endsWith('*') && targets[0]?.endsWith('*')).map(([pattern, [target]])=>({
|
|
1720
|
+
prefix: pattern.slice(0, -1),
|
|
1721
|
+
target: external_node_path_default().resolve(base, target.slice(0, -1))
|
|
1722
|
+
}));
|
|
1723
|
+
} catch {
|
|
1724
|
+
return [];
|
|
1770
1725
|
}
|
|
1771
|
-
|
|
1772
|
-
const { docComment } = new TSDocParser(configuration).parseString(comment);
|
|
1773
|
-
|
|
1774
|
-
return getText(docComment.summarySection).trim() || undefined;
|
|
1775
1726
|
};
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
const
|
|
1779
|
-
const
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
)
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1727
|
+
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
|
|
1728
|
+
const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
|
|
1729
|
+
const importPaths = (file)=>{
|
|
1730
|
+
const withoutExtension = file.replace(codeExtension, '');
|
|
1731
|
+
return 'index' === external_node_path_default().basename(withoutExtension) ? [
|
|
1732
|
+
withoutExtension,
|
|
1733
|
+
external_node_path_default().dirname(withoutExtension)
|
|
1734
|
+
] : [
|
|
1735
|
+
withoutExtension
|
|
1736
|
+
];
|
|
1786
1737
|
};
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
.
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
.
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
if (!endpointFile) {
|
|
1819
|
-
return undefined;
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
const declaration = findHandlerClass(endpointFile);
|
|
1823
|
-
const operationId = declaration?.getName();
|
|
1824
|
-
const comment = declaration?.getJsDocs().at(-1)?.getText();
|
|
1825
|
-
|
|
1826
|
-
if (!comment) {
|
|
1827
|
-
return { operationId };
|
|
1828
|
-
}
|
|
1829
|
-
|
|
1830
|
-
return {
|
|
1831
|
-
summary: summaryTag
|
|
1832
|
-
? getTagText(comment, summaryTag)
|
|
1833
|
-
: parseSummary(comment),
|
|
1834
|
-
description: getTagText(comment, descriptionTag),
|
|
1835
|
-
operationId
|
|
1836
|
-
};
|
|
1837
|
-
} catch (e: unknown) {
|
|
1838
|
-
console.error(e);
|
|
1839
|
-
return undefined;
|
|
1840
|
-
}
|
|
1738
|
+
const projectImports = (projectRoot)=>{
|
|
1739
|
+
const aliases = readAliases(projectRoot);
|
|
1740
|
+
const resolve = (specifier, fromFile)=>{
|
|
1741
|
+
if (specifier.startsWith('.')) return {
|
|
1742
|
+
resolved: external_node_path_default().resolve(external_node_path_default().dirname(fromFile), specifier),
|
|
1743
|
+
alias: void 0
|
|
1744
|
+
};
|
|
1745
|
+
const alias = aliases.find(({ prefix })=>specifier.startsWith(prefix));
|
|
1746
|
+
return alias ? {
|
|
1747
|
+
resolved: external_node_path_default().resolve(alias.target, specifier.slice(alias.prefix.length)),
|
|
1748
|
+
alias
|
|
1749
|
+
} : void 0;
|
|
1750
|
+
};
|
|
1751
|
+
const specifierFor = (fromFile, toPath, alias)=>{
|
|
1752
|
+
const aliased = alias && toPosix(external_node_path_default().relative(alias.target, toPath));
|
|
1753
|
+
if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
|
|
1754
|
+
const relative = toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toPath));
|
|
1755
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
1756
|
+
};
|
|
1757
|
+
const codeFiles = new Map(module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
1758
|
+
file,
|
|
1759
|
+
external_node_fs_default().readFileSync(file, 'utf8')
|
|
1760
|
+
]));
|
|
1761
|
+
const importsOf = (file)=>[
|
|
1762
|
+
...(codeFiles.get(file) ?? '').matchAll(specifierPattern)
|
|
1763
|
+
].map(([, , , specifier])=>resolve(specifier, file)?.resolved).filter((resolved)=>!!resolved);
|
|
1764
|
+
return {
|
|
1765
|
+
resolve,
|
|
1766
|
+
specifierFor,
|
|
1767
|
+
codeFiles,
|
|
1768
|
+
importsOf
|
|
1841
1769
|
};
|
|
1842
1770
|
};
|
|
1843
|
-
|
|
1844
|
-
const
|
|
1845
|
-
const
|
|
1846
|
-
const
|
|
1847
|
-
'
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
const
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1771
|
+
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
1772
|
+
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
1773
|
+
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
1774
|
+
const barrels = new Set();
|
|
1775
|
+
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
1776
|
+
for(let found = true; found;){
|
|
1777
|
+
found = false;
|
|
1778
|
+
for (const [file, content] of codeFiles){
|
|
1779
|
+
if (moves.has(file) || isBarrel(file)) continue;
|
|
1780
|
+
const reExportsModule = [
|
|
1781
|
+
...content.matchAll(reExportPattern)
|
|
1782
|
+
].some(([, , specifier])=>{
|
|
1783
|
+
const resolution = resolve(specifier, file);
|
|
1784
|
+
return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
|
|
1785
|
+
});
|
|
1786
|
+
if (reExportsModule) {
|
|
1787
|
+
for (const importPath of importPaths(file))barrels.add(importPath);
|
|
1788
|
+
found = true;
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
const rewrite = (content, oldFile, newFile)=>{
|
|
1793
|
+
let referencesModule = false;
|
|
1794
|
+
const rewritten = content.replace(specifierPattern, (match, keyword, quote, specifier)=>{
|
|
1795
|
+
const resolution = resolve(specifier, oldFile);
|
|
1796
|
+
if (!resolution) return match;
|
|
1797
|
+
const moved = movedPath(resolution.resolved);
|
|
1798
|
+
if (moved || isBarrel(resolution.resolved)) referencesModule = true;
|
|
1799
|
+
if (!moved && oldFile === newFile) return match;
|
|
1800
|
+
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
1801
|
+
return `${keyword}${quote}${next}${quote}`;
|
|
1802
|
+
});
|
|
1803
|
+
const changed = everyFile(rewritten);
|
|
1804
|
+
if (!referencesModule && !moves.has(oldFile)) return changed;
|
|
1805
|
+
return rename(changed, {
|
|
1806
|
+
moved: moves.has(oldFile)
|
|
1807
|
+
});
|
|
1808
|
+
};
|
|
1809
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile, stopFor(file));
|
|
1810
|
+
const updated = [];
|
|
1811
|
+
for (const [file, content] of codeFiles){
|
|
1812
|
+
const newFile = moves.get(file);
|
|
1813
|
+
const next = rewrite(content, file, newFile ?? file);
|
|
1814
|
+
if (newFile && newFile !== file) {
|
|
1815
|
+
new file_system_File(newFile).data = next;
|
|
1816
|
+
new file_system_File(file).delete(stopFor(file));
|
|
1817
|
+
} else if (next !== content) {
|
|
1818
|
+
new file_system_File(file).update(next);
|
|
1819
|
+
if (!newFile) updated.push(file);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return {
|
|
1823
|
+
moves: [
|
|
1824
|
+
...moves
|
|
1825
|
+
].filter(([from, to])=>from !== to),
|
|
1826
|
+
updated
|
|
1827
|
+
};
|
|
1828
|
+
};
|
|
1829
|
+
const frontendExtensions = {
|
|
1830
|
+
react: {
|
|
1831
|
+
component: '.tsx',
|
|
1832
|
+
hook: '.ts'
|
|
1833
|
+
},
|
|
1834
|
+
svelte: {
|
|
1835
|
+
component: '.svelte',
|
|
1836
|
+
hook: '.svelte.ts'
|
|
1837
|
+
}
|
|
1838
|
+
};
|
|
1839
|
+
const frontendLogicNaming = {
|
|
1840
|
+
react: {
|
|
1841
|
+
prefix: 'use',
|
|
1842
|
+
shared: [
|
|
1843
|
+
'hooks'
|
|
1844
|
+
],
|
|
1845
|
+
widgetModel: 'hooks'
|
|
1846
|
+
},
|
|
1847
|
+
svelte: {
|
|
1848
|
+
prefix: 'create',
|
|
1849
|
+
shared: [
|
|
1850
|
+
'shared',
|
|
1851
|
+
'model'
|
|
1852
|
+
],
|
|
1853
|
+
widgetModel: 'model'
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
const kindLayouts = (framework)=>{
|
|
1857
|
+
const { component, hook } = frontendExtensions[framework];
|
|
1858
|
+
const { prefix, shared } = frontendLogicNaming[framework];
|
|
1859
|
+
return {
|
|
1860
|
+
page: {
|
|
1861
|
+
folder: 'pages',
|
|
1862
|
+
nested: true,
|
|
1863
|
+
inFolder: false,
|
|
1864
|
+
ownFile: (fileBase)=>new RegExp(`^${escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
1865
|
+
target: (reactFolder, { folders, fileName })=>external_node_path_default().join(reactFolder, 'pages', ...folders, `${fileName}-page${component}`),
|
|
1866
|
+
classPrefix: `(${prefix})?`,
|
|
1867
|
+
classSuffix: 'Page'
|
|
1868
|
+
},
|
|
1869
|
+
widget: {
|
|
1870
|
+
folder: 'widgets',
|
|
1871
|
+
nested: true,
|
|
1872
|
+
inFolder: true,
|
|
1873
|
+
target: (reactFolder, { folders, folderName })=>external_node_path_default().join(reactFolder, 'widgets', ...folders, folderName),
|
|
1874
|
+
classPrefix: `(${prefix})?`,
|
|
1875
|
+
classSuffix: 'Widget|UIModel',
|
|
1876
|
+
storyTitle: (segments)=>[
|
|
1877
|
+
'Widgets',
|
|
1878
|
+
...segments
|
|
1879
|
+
].join('/')
|
|
1880
|
+
},
|
|
1881
|
+
'ui-kit': {
|
|
1882
|
+
folder: 'ui-kit',
|
|
1883
|
+
nested: false,
|
|
1884
|
+
inFolder: true,
|
|
1885
|
+
target: (reactFolder, { fileName })=>external_node_path_default().join(reactFolder, 'ui-kit', fileName),
|
|
1886
|
+
classPrefix: '()',
|
|
1887
|
+
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
1888
|
+
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
1889
|
+
},
|
|
1890
|
+
hook: {
|
|
1891
|
+
folder: shared.join('/'),
|
|
1892
|
+
nested: false,
|
|
1893
|
+
inFolder: false,
|
|
1894
|
+
ownFile: (fileBase)=>new RegExp(`^${prefix}-${escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
1895
|
+
target: (reactFolder, { fileName })=>external_node_path_default().join(reactFolder, ...shared, `${prefix}-${fileName}${hook}`),
|
|
1896
|
+
classPrefix: `(${prefix})`,
|
|
1897
|
+
classSuffix: '(?![\\w$])'
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
};
|
|
1901
|
+
const reactKindLayouts = kindLayouts('react');
|
|
1902
|
+
const svelteKindLayouts = kindLayouts('svelte');
|
|
1903
|
+
const frontendKindLayouts = (framework)=>'svelte' === framework ? svelteKindLayouts : reactKindLayouts;
|
|
1904
|
+
const reactKindTitles = {
|
|
1905
|
+
page: [
|
|
1906
|
+
'Page',
|
|
1907
|
+
'pages'
|
|
1908
|
+
],
|
|
1909
|
+
widget: [
|
|
1910
|
+
'Widget',
|
|
1911
|
+
'widgets'
|
|
1912
|
+
],
|
|
1913
|
+
'ui-kit': [
|
|
1914
|
+
'UI-kit component',
|
|
1915
|
+
'UI-kit components'
|
|
1916
|
+
],
|
|
1917
|
+
hook: [
|
|
1918
|
+
'Shared hook',
|
|
1919
|
+
'shared hooks'
|
|
1920
|
+
]
|
|
1921
|
+
};
|
|
1922
|
+
const svelteKindTitles = {
|
|
1923
|
+
...reactKindTitles,
|
|
1924
|
+
hook: [
|
|
1925
|
+
'Shared model',
|
|
1926
|
+
'shared models'
|
|
1927
|
+
]
|
|
1928
|
+
};
|
|
1929
|
+
const frontendKindTitles = (framework)=>'svelte' === framework ? svelteKindTitles : reactKindTitles;
|
|
1930
|
+
const reactModuleName = (kind, rawName, framework = 'react')=>'hook' === kind ? rawName.trim().replace(new RegExp(`^${frontendLogicNaming[framework].prefix}-`), '') : rawName;
|
|
1931
|
+
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
1932
|
+
const prefix = `${folders.join('-')}-`;
|
|
1933
|
+
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
1934
|
+
return [
|
|
1935
|
+
...folders,
|
|
1936
|
+
last
|
|
1937
|
+
].join('/');
|
|
1938
|
+
};
|
|
1939
|
+
const declaredClassName = (filePaths, suffix, name)=>{
|
|
1940
|
+
for (const filePath of filePaths){
|
|
1941
|
+
if (!external_node_fs_default().existsSync(filePath)) continue;
|
|
1942
|
+
const declared = external_node_fs_default().readFileSync(filePath, 'utf8').match(new RegExp(`(?:export\\s+(?:const|function)|\\bdefault\\s+as)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
1943
|
+
if (declared) return declared;
|
|
1944
|
+
}
|
|
1945
|
+
return new NestedName(name).ClassName;
|
|
1946
|
+
};
|
|
1947
|
+
const findUiKit = (reactFolder, framework)=>{
|
|
1948
|
+
const { component } = frontendExtensions[framework];
|
|
1949
|
+
const root = external_node_path_default().join(reactFolder, 'ui-kit');
|
|
1950
|
+
if (!external_node_fs_default().existsSync(root)) return [];
|
|
1951
|
+
return external_node_fs_default().readdirSync(root, {
|
|
1952
|
+
withFileTypes: true
|
|
1953
|
+
}).filter((entry)=>entry.isDirectory() && external_node_fs_default().existsSync(external_node_path_default().join(root, entry.name, `${entry.name}${component}`))).map(({ name })=>({
|
|
1954
|
+
kind: 'ui-kit',
|
|
1955
|
+
name,
|
|
1956
|
+
path: external_node_path_default().join(root, name),
|
|
1957
|
+
fileBase: name,
|
|
1958
|
+
ClassName: declaredClassName([
|
|
1959
|
+
external_node_path_default().join(root, name, `${name}${component}`),
|
|
1960
|
+
external_node_path_default().join(root, name, 'index.ts')
|
|
1961
|
+
], '', name)
|
|
1962
|
+
}));
|
|
1963
|
+
};
|
|
1964
|
+
const hookFile = {
|
|
1965
|
+
react: /\.tsx?$/,
|
|
1966
|
+
svelte: /\.svelte\.[jt]s$/
|
|
1967
|
+
};
|
|
1968
|
+
const findHooks = (reactFolder, framework)=>{
|
|
1969
|
+
const { prefix, shared } = frontendLogicNaming[framework];
|
|
1970
|
+
const root = external_node_path_default().join(reactFolder, ...shared);
|
|
1971
|
+
if (!external_node_fs_default().existsSync(root)) return [];
|
|
1972
|
+
const extension = hookFile[framework];
|
|
1973
|
+
const ownPrefix = new RegExp(`^${prefix}-`);
|
|
1974
|
+
return external_node_fs_default().readdirSync(root).filter((file)=>ownPrefix.test(file) && extension.test(file) && !/\.(spec|test)\./.test(file)).map((file)=>{
|
|
1975
|
+
const name = file.replace(ownPrefix, '').replace(extension, '');
|
|
1976
|
+
const content = external_node_fs_default().readFileSync(external_node_path_default().join(root, file), 'utf8');
|
|
1977
|
+
return {
|
|
1978
|
+
kind: 'hook',
|
|
1979
|
+
name,
|
|
1980
|
+
path: external_node_path_default().join(root, file),
|
|
1981
|
+
fileBase: name,
|
|
1982
|
+
ClassName: content.match(new RegExp(`export\\s+(?:const|function)\\s+${prefix}(\\w+)\\b`))?.[1] ?? new NestedName(name).ClassName
|
|
1983
|
+
};
|
|
1984
|
+
});
|
|
1985
|
+
};
|
|
1986
|
+
const findReactModules = (reactFolder, kind, framework = 'react')=>{
|
|
1987
|
+
const { component } = frontendExtensions[framework];
|
|
1988
|
+
const modules = 'ui-kit' === kind ? findUiKit(reactFolder, framework) : 'hook' === kind ? findHooks(reactFolder, framework) : 'page' === kind ? module_move_walk(external_node_path_default().join(reactFolder, 'pages')).filter((file)=>file.endsWith(`-page${component}`)).map((file)=>{
|
|
1989
|
+
const folders = external_node_path_default().relative(external_node_path_default().join(reactFolder, 'pages'), external_node_path_default().dirname(file)).split(external_node_path_default().sep).filter((segment)=>!!segment);
|
|
1990
|
+
const fileBase = external_node_path_default().basename(file, `-page${component}`);
|
|
1991
|
+
const name = react_module_move_nestedName(folders, fileBase);
|
|
1992
|
+
return {
|
|
1993
|
+
kind,
|
|
1994
|
+
name,
|
|
1995
|
+
path: file,
|
|
1996
|
+
fileBase,
|
|
1997
|
+
ClassName: declaredClassName([
|
|
1998
|
+
file
|
|
1999
|
+
], 'Page', name)
|
|
2000
|
+
};
|
|
2001
|
+
}) : module_move_walk(external_node_path_default().join(reactFolder, 'widgets')).filter((file)=>file.endsWith(`-widget${component}`)).map((file)=>{
|
|
2002
|
+
const folder = external_node_path_default().dirname(file);
|
|
2003
|
+
const name = toPosix(external_node_path_default().relative(external_node_path_default().join(reactFolder, 'widgets'), folder));
|
|
2004
|
+
return {
|
|
2005
|
+
kind,
|
|
2006
|
+
name,
|
|
2007
|
+
path: folder,
|
|
2008
|
+
fileBase: external_node_path_default().basename(file, `-widget${component}`),
|
|
2009
|
+
ClassName: declaredClassName([
|
|
2010
|
+
file,
|
|
2011
|
+
external_node_path_default().join(folder, 'index.ts')
|
|
2012
|
+
], 'Widget', name)
|
|
2013
|
+
};
|
|
2014
|
+
});
|
|
2015
|
+
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
2016
|
+
};
|
|
2017
|
+
const react_module_move_targetPath = (reactFolder, module, rawName, framework)=>frontendKindLayouts(framework)[module.kind].target(reactFolder, new NestedName(reactModuleName(module.kind, rawName, framework)));
|
|
2018
|
+
const validateMove = (reactFolder, module, rawName, framework = 'react')=>{
|
|
2019
|
+
const nameError = NestedName.validate(rawName);
|
|
2020
|
+
if (true !== nameError) return nameError;
|
|
2021
|
+
if (!frontendKindLayouts(framework)[module.kind].nested && /[\\/]/.test(rawName)) return `UI-kit components and ${frontendKindTitles(framework).hook[1]} have no folders: enter a name without "/"`;
|
|
2022
|
+
const target = react_module_move_targetPath(reactFolder, module, rawName, framework);
|
|
2023
|
+
if (target !== module.path && external_node_fs_default().existsSync(target)) return `${external_node_path_default().relative(reactFolder, target)} already exists`;
|
|
2024
|
+
if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
|
|
2025
|
+
return true;
|
|
2026
|
+
};
|
|
2027
|
+
const react_module_move_routeFolder = (appFolder, rawName)=>{
|
|
2028
|
+
const { folders, folderName } = new NestedName(rawName);
|
|
2029
|
+
return external_node_path_default().join(appFolder, ...folders, folderName);
|
|
2030
|
+
};
|
|
2031
|
+
const routeFiles = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
|
|
2032
|
+
withFileTypes: true
|
|
2033
|
+
}).filter((entry)=>entry.isFile()).map((entry)=>external_node_path_default().join(folder, entry.name)) : [];
|
|
2034
|
+
const moveReactModule = (projectRoot, reactFolder, module, rawName, route, framework = 'react')=>{
|
|
2035
|
+
const layout = frontendKindLayouts(framework)[module.kind];
|
|
2036
|
+
const newName = new NestedName(reactModuleName(module.kind, rawName, framework));
|
|
2037
|
+
const { prefix } = frontendLogicNaming[framework];
|
|
2038
|
+
const target = react_module_move_targetPath(reactFolder, module, rawName, framework);
|
|
2039
|
+
const newClassName = newName.ClassName;
|
|
2040
|
+
const renameFile = (name)=>name.replace(new RegExp(`^(${prefix}-)?${escapeRegExp(module.fileBase)}(?=[-.]|$)`), (_, own = '')=>`${own}${newName.fileName}`);
|
|
2041
|
+
const oldFolder = layout.inFolder ? module.path : external_node_path_default().dirname(module.path);
|
|
2042
|
+
const newFolder = layout.inFolder ? target : external_node_path_default().dirname(target);
|
|
2043
|
+
const ownsPath = (candidate)=>layout.inFolder ? candidate === oldFolder || candidate.startsWith(`${oldFolder}${external_node_path_default().sep}`) : external_node_path_default().dirname(candidate) === oldFolder && layout.ownFile(module.fileBase).test(external_node_path_default().basename(candidate));
|
|
2044
|
+
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
2045
|
+
const routeTarget = (candidate)=>{
|
|
2046
|
+
if (!route) return;
|
|
2047
|
+
const file = [
|
|
2048
|
+
...routeFileSet
|
|
2049
|
+
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
2050
|
+
if (!file) return;
|
|
2051
|
+
const moved = external_node_path_default().join(route.to, external_node_path_default().relative(route.from, file));
|
|
2052
|
+
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
2053
|
+
};
|
|
2054
|
+
const movedPath = (candidate)=>{
|
|
2055
|
+
const routed = routeTarget(candidate);
|
|
2056
|
+
if (routed) return routed;
|
|
2057
|
+
if (!ownsPath(candidate)) return;
|
|
2058
|
+
const segments = external_node_path_default().relative(oldFolder, candidate).split(external_node_path_default().sep);
|
|
2059
|
+
const last = segments.length - 1;
|
|
2060
|
+
segments[last] = renameFile(segments[last]);
|
|
2061
|
+
return external_node_path_default().join(newFolder, ...segments);
|
|
2062
|
+
};
|
|
2063
|
+
const moduleFiles = reactModuleFiles(module, framework);
|
|
2064
|
+
const moves = new Map([
|
|
2065
|
+
...moduleFiles,
|
|
2066
|
+
...routeFileSet
|
|
2067
|
+
].map((file)=>[
|
|
2068
|
+
file,
|
|
2069
|
+
movedPath(file) ?? file
|
|
2070
|
+
]));
|
|
2071
|
+
const classPattern = new RegExp(`(?<![\\w$])${layout.classPrefix}${escapeRegExp(module.ClassName)}(?=${layout.classSuffix})`, 'g');
|
|
2072
|
+
const oldTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
2073
|
+
module.ClassName
|
|
2074
|
+
] : module.name.split('/').map((segment)=>new NestedName(segment).ClassName));
|
|
2075
|
+
const titlePattern = oldTitle && new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
2076
|
+
const newTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
2077
|
+
newClassName
|
|
2078
|
+
] : newName.classNameSegments);
|
|
2079
|
+
return stageModuleMove({
|
|
2080
|
+
projectRoot,
|
|
2081
|
+
stopAt: reactFolder,
|
|
2082
|
+
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
2083
|
+
moves,
|
|
2084
|
+
movedPath,
|
|
2085
|
+
rename: (content, { moved })=>{
|
|
2086
|
+
const renamed = content.replace(classPattern, (_, use)=>`${use ?? ''}${newClassName}`);
|
|
2087
|
+
return moved && titlePattern ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
2088
|
+
}
|
|
2089
|
+
});
|
|
2090
|
+
};
|
|
2091
|
+
const routePageFile = {
|
|
2092
|
+
react: 'page.tsx',
|
|
2093
|
+
svelte: '+page.svelte'
|
|
2094
|
+
};
|
|
2095
|
+
const pageRouteFolder = (appFolder, page, framework = 'react')=>{
|
|
2096
|
+
const folder = react_module_move_routeFolder(appFolder, page.name);
|
|
2097
|
+
const routePage = external_node_path_default().join(folder, routePageFile[framework]);
|
|
2098
|
+
return external_node_fs_default().existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(external_node_fs_default().readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
2099
|
+
};
|
|
2100
|
+
const reactModuleFiles = (module, framework)=>{
|
|
2101
|
+
const layout = frontendKindLayouts(framework)[module.kind];
|
|
2102
|
+
if (layout.inFolder) return module_move_walk(module.path);
|
|
2103
|
+
const folder = external_node_path_default().dirname(module.path);
|
|
2104
|
+
const own = layout.ownFile(module.fileBase);
|
|
2105
|
+
return external_node_fs_default().readdirSync(folder, {
|
|
2106
|
+
withFileTypes: true
|
|
2107
|
+
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>external_node_path_default().join(folder, entry.name));
|
|
2108
|
+
};
|
|
2109
|
+
const importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
2110
|
+
const deleteReactModule = (projectRoot, reactFolder, module, route, framework = 'react')=>{
|
|
2111
|
+
const moduleFiles = reactModuleFiles(module, framework);
|
|
2112
|
+
const routeFileList = route ? routeFiles(route.folder) : [];
|
|
2113
|
+
const own = new Set([
|
|
2114
|
+
...moduleFiles,
|
|
2115
|
+
...routeFileList
|
|
2116
|
+
]);
|
|
2117
|
+
const stems = new Set(moduleFiles.map((file)=>file.replace(codeExtension, '')));
|
|
2118
|
+
const isModule = (resolved)=>stems.has(resolved) || moduleFiles.includes(resolved) || frontendKindLayouts(framework)[module.kind].inFolder && (resolved === module.path || resolved.startsWith(`${module.path}${external_node_path_default().sep}`));
|
|
2119
|
+
const { codeFiles, resolve } = projectImports(projectRoot);
|
|
2120
|
+
const relative = (file)=>toPosix(external_node_path_default().relative(projectRoot, file));
|
|
2121
|
+
const usedBy = [];
|
|
2122
|
+
for (const [file, content] of codeFiles)if (!own.has(file)) for (const [, , specifier] of content.matchAll(importSpecifier)){
|
|
2123
|
+
const target = resolve(specifier, file)?.resolved;
|
|
2124
|
+
if (target && isModule(target)) usedBy.push([
|
|
2125
|
+
relative(file),
|
|
2126
|
+
relative(target)
|
|
2127
|
+
]);
|
|
2128
|
+
}
|
|
2129
|
+
if (usedBy.length) return {
|
|
2130
|
+
usedBy
|
|
2131
|
+
};
|
|
2132
|
+
for (const file of moduleFiles)new file_system_File(file).delete(reactFolder);
|
|
2133
|
+
for (const file of routeFileList)new file_system_File(file).delete(route.appFolder);
|
|
2134
|
+
return {
|
|
2135
|
+
deleted: [
|
|
2136
|
+
...moduleFiles,
|
|
2137
|
+
...routeFileList
|
|
2138
|
+
]
|
|
2139
|
+
};
|
|
2140
|
+
};
|
|
2141
|
+
const svelteComponentContent = (propsType)=>`
|
|
2142
|
+
<script lang="ts" module>
|
|
2143
|
+
export type ${propsType} = {}
|
|
2144
|
+
</script>
|
|
2145
|
+
|
|
2146
|
+
<script lang="ts">
|
|
2147
|
+
let props: ${propsType} = $props()
|
|
2148
|
+
</script>
|
|
2149
|
+
`.trim();
|
|
2150
|
+
const svelteStory = (storybookFramework, componentName, componentFile, title)=>`
|
|
2151
|
+
import type { Meta, StoryObj } from '${storybookFramework}'
|
|
2152
|
+
import ${componentName} from './${componentFile}'
|
|
2153
|
+
|
|
2154
|
+
const meta = {
|
|
2155
|
+
title: '${title}',
|
|
2156
|
+
component: ${componentName}
|
|
2157
|
+
} satisfies Meta<typeof ${componentName}>
|
|
2158
|
+
|
|
2159
|
+
export default meta
|
|
2160
|
+
|
|
2161
|
+
type Story = StoryObj<typeof meta>
|
|
2162
|
+
|
|
2163
|
+
export const Default: Story = {
|
|
2164
|
+
args: {}
|
|
2165
|
+
}
|
|
2166
|
+
`.trim();
|
|
2167
|
+
const svelteUIModelContent = (ClassName, propsType)=>`
|
|
2168
|
+
import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from '../types'
|
|
2169
|
+
|
|
2170
|
+
/**
|
|
2171
|
+
* - widgetProps is the $props() proxy as a whole: destructuring it in the
|
|
2172
|
+
* signature (({ a }) =>) or copying it ({ ...props }) loses reactivity
|
|
2173
|
+
* - values depending on props: $derived, exposed through getters only
|
|
2174
|
+
* - local state: $state; methods: plain functions of the returned object
|
|
2175
|
+
* - getters satisfy ${ClassName}WidgetUIProps
|
|
2176
|
+
*/
|
|
2177
|
+
export const create${ClassName}UIModel = (
|
|
2178
|
+
widgetProps: ${propsType},
|
|
2179
|
+
): ${ClassName}WidgetUIProps => {
|
|
2180
|
+
// derived values go here
|
|
2181
|
+
// const value = $derived(widgetProps.value)
|
|
2182
|
+
|
|
2183
|
+
return {
|
|
2184
|
+
// expose values via getters to keep reactivity:
|
|
2185
|
+
// get value() { return value },
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
`.trim();
|
|
2189
|
+
const scaffold_svelte_modules_storybookFramework = ()=>config_file_ConfigFile.Instance.data.frontend?.svelte?.storybookFramework;
|
|
2190
|
+
const svelteKitRouteContent = (ClassName, pageImport)=>`
|
|
2191
|
+
<script lang="ts">
|
|
2192
|
+
import ${ClassName}Page from '${pageImport}'
|
|
2193
|
+
</script>
|
|
2194
|
+
|
|
2195
|
+
<${ClassName}Page />
|
|
2196
|
+
`.trim();
|
|
2197
|
+
const scaffold_svelte_modules_relativeImport = (fromFile, toFile)=>{
|
|
2198
|
+
const relative = external_node_path_default().relative(external_node_path_default().dirname(fromFile), toFile).split(external_node_path_default().sep).join('/');
|
|
2199
|
+
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
2200
|
+
};
|
|
2201
|
+
const scaffoldSvelteKitRoute = (name, pagePath)=>{
|
|
2202
|
+
const root = new project_root_ProjectRoot().path;
|
|
2203
|
+
const route = external_node_path_default().join(root, svelteKitRoutesFolder(root), ...name.folders, name.folderName, routePageFile.svelte);
|
|
2204
|
+
const relativeRoute = external_node_path_default().relative(root, route).split(external_node_path_default().sep).join('/');
|
|
2205
|
+
const routeFile = new file_system_File(route);
|
|
2206
|
+
const content = svelteKitRouteContent(name.ClassName, scaffold_svelte_modules_relativeImport(route, pagePath));
|
|
2207
|
+
if (routeFile.exists) return routeFile.data === content ? void 0 : `${relativeRoute} already exists: render ${name.ClassName}Page there yourself.`;
|
|
2208
|
+
routeFile.data = content;
|
|
2209
|
+
};
|
|
2210
|
+
const scaffoldSveltePage = async (presentationSvelteFolder)=>{
|
|
2211
|
+
const name = await interaction_input({
|
|
2212
|
+
key: 'name',
|
|
2213
|
+
message: 'Provide name (folders split by "/"):',
|
|
2214
|
+
validate: NestedName.validate
|
|
2215
|
+
});
|
|
2216
|
+
const nestedName = new NestedName(name);
|
|
2217
|
+
const { folders, ClassName, fileName } = nestedName;
|
|
2218
|
+
const pageFile = presentationSvelteFolder.subitem([
|
|
2219
|
+
'pages',
|
|
2220
|
+
...folders
|
|
2221
|
+
]).createFile(`${fileName}-page.svelte`, svelteComponentContent(`${ClassName}PageProps`));
|
|
2222
|
+
if (usesSvelteKit()) {
|
|
2223
|
+
const hint = scaffoldSvelteKitRoute(nestedName, pageFile.path);
|
|
2224
|
+
if (hint) report(hint);
|
|
2225
|
+
}
|
|
2226
|
+
};
|
|
2227
|
+
const scaffoldSvelteWidget = async (presentationSvelteFolder)=>{
|
|
2228
|
+
const widgetName = await interaction_input({
|
|
2229
|
+
key: 'name',
|
|
2230
|
+
message: 'Name (folders split by "/"): ',
|
|
2231
|
+
validate: NestedName.validate
|
|
2232
|
+
});
|
|
2233
|
+
const widgetType = await interaction_select({
|
|
2234
|
+
choices: [
|
|
2235
|
+
'monolithic',
|
|
2236
|
+
'with separated ui',
|
|
2237
|
+
'headless'
|
|
2238
|
+
],
|
|
2239
|
+
key: 'widgetType',
|
|
2240
|
+
message: 'Type: '
|
|
2241
|
+
});
|
|
2242
|
+
const { folders, folderName, ClassName, fileName, classNameSegments } = new NestedName(widgetName);
|
|
2243
|
+
const folder = presentationSvelteFolder.subitem([
|
|
2244
|
+
'widgets',
|
|
2245
|
+
...folders,
|
|
2246
|
+
folderName
|
|
2247
|
+
]);
|
|
2248
|
+
const storyTitle = [
|
|
2249
|
+
'Widgets',
|
|
2250
|
+
...classNameSegments
|
|
2251
|
+
].join('/');
|
|
2252
|
+
const widgetFileName = `${fileName}-widget`;
|
|
2253
|
+
const uiFileName = `${fileName}-widget-ui`;
|
|
2254
|
+
const uiModelFileName = `create-${fileName}-ui-model`;
|
|
2255
|
+
if ('monolithic' === widgetType) {
|
|
2256
|
+
folder.createFile('index.ts', `
|
|
2257
|
+
export { default as ${ClassName}Widget } from './${widgetFileName}.svelte'
|
|
2258
|
+
export type { ${ClassName}WidgetProps } from './${widgetFileName}.svelte'
|
|
2259
|
+
`.trim());
|
|
2260
|
+
folder.createFile(`${widgetFileName}.svelte`, svelteComponentContent(`${ClassName}WidgetProps`));
|
|
2261
|
+
return;
|
|
2262
|
+
}
|
|
2263
|
+
folder.createFile('index.ts', `
|
|
2264
|
+
export { default as ${ClassName}Widget } from './${widgetFileName}.svelte'
|
|
2265
|
+
export type { ${ClassName}WidgetProps } from './types'
|
|
2266
|
+
`.trim());
|
|
2267
|
+
if ('with separated ui' === widgetType) {
|
|
2268
|
+
folder.createFile('types.ts', `
|
|
2269
|
+
export type ${ClassName}WidgetProps = { }
|
|
2270
|
+
|
|
2271
|
+
export type ${ClassName}WidgetUIProps = { }
|
|
2272
|
+
`.trim());
|
|
2273
|
+
folder.createFile(`${widgetFileName}.svelte`, `
|
|
2274
|
+
<script lang="ts">
|
|
2275
|
+
import type { ${ClassName}WidgetProps } from './types'
|
|
2276
|
+
import ${ClassName}WidgetUI from './ui/${uiFileName}.svelte'
|
|
2277
|
+
import { create${ClassName}UIModel } from './model/${uiModelFileName}.svelte'
|
|
2278
|
+
|
|
2279
|
+
let props: ${ClassName}WidgetProps = $props()
|
|
2280
|
+
// The $props() proxy stays reactive: the model reads it in $derived and getters
|
|
2281
|
+
// svelte-ignore state_referenced_locally
|
|
2282
|
+
const uiModel = create${ClassName}UIModel(props)
|
|
2283
|
+
</script>
|
|
2284
|
+
|
|
2285
|
+
<${ClassName}WidgetUI {...uiModel} />
|
|
2286
|
+
`.trim());
|
|
2287
|
+
folder.subitem([
|
|
2288
|
+
'ui'
|
|
2289
|
+
]).createFile(`${uiFileName}.svelte`, `
|
|
2290
|
+
<script lang="ts">
|
|
2291
|
+
import type { ${ClassName}WidgetUIProps } from '../types'
|
|
2292
|
+
|
|
2293
|
+
let props: ${ClassName}WidgetUIProps = $props()
|
|
2294
|
+
</script>
|
|
2295
|
+
`.trim());
|
|
2296
|
+
const framework = scaffold_svelte_modules_storybookFramework();
|
|
2297
|
+
if (framework) folder.subitem([
|
|
2298
|
+
'ui'
|
|
2299
|
+
]).createFile(`${uiFileName}.stories.ts`, svelteStory(framework, `${ClassName}WidgetUI`, `${uiFileName}.svelte`, storyTitle));
|
|
2300
|
+
folder.subitem([
|
|
2301
|
+
'model'
|
|
2302
|
+
]).createFile(`${uiModelFileName}.svelte.ts`, svelteUIModelContent(ClassName, `${ClassName}WidgetProps`));
|
|
2303
|
+
return;
|
|
2304
|
+
}
|
|
2305
|
+
folder.createFile('types.ts', `
|
|
2306
|
+
import type { Component } from 'svelte'
|
|
2307
|
+
|
|
2308
|
+
export type ${ClassName}WidgetUIProps = { }
|
|
2309
|
+
|
|
2310
|
+
export type ${ClassName}WidgetProps = {
|
|
2311
|
+
UI: Component<${ClassName}WidgetUIProps>
|
|
2312
|
+
}
|
|
2313
|
+
`.trim());
|
|
2314
|
+
folder.createFile(`${widgetFileName}.svelte`, `
|
|
2315
|
+
<script lang="ts">
|
|
2316
|
+
import type { ${ClassName}WidgetProps } from './types'
|
|
2317
|
+
import { create${ClassName}UIModel } from './model/${uiModelFileName}.svelte'
|
|
2318
|
+
|
|
2319
|
+
let { UI, ...widgetProps }: ${ClassName}WidgetProps = $props()
|
|
2320
|
+
// The rest of $props() stays reactive, a copy made by hand would not
|
|
2321
|
+
// svelte-ignore state_referenced_locally
|
|
2322
|
+
const uiModel = create${ClassName}UIModel(widgetProps)
|
|
2323
|
+
</script>
|
|
2324
|
+
|
|
2325
|
+
<UI {...uiModel} />
|
|
2326
|
+
`.trim());
|
|
2327
|
+
folder.subitem([
|
|
2328
|
+
'model'
|
|
2329
|
+
]).createFile(`${uiModelFileName}.svelte.ts`, svelteUIModelContent(ClassName, `Omit<${ClassName}WidgetProps, 'UI'>`));
|
|
2330
|
+
};
|
|
2331
|
+
const scaffoldSvelteUIKitComponent = async (presentationSvelteFolder)=>{
|
|
2332
|
+
const name = await interaction_input({
|
|
2333
|
+
key: 'name',
|
|
2334
|
+
message: 'Name: '
|
|
2335
|
+
});
|
|
2336
|
+
const { ClassName, fileName } = new UnknownFormatNaming(name);
|
|
2337
|
+
const componentFolder = presentationSvelteFolder.subitem([
|
|
2338
|
+
'ui-kit',
|
|
2339
|
+
fileName
|
|
2340
|
+
]);
|
|
2341
|
+
componentFolder.createFile('index.ts', `
|
|
2342
|
+
export { default as ${ClassName} } from './${fileName}.svelte'
|
|
2343
|
+
export type { ${ClassName}Props } from './${fileName}.svelte'
|
|
2344
|
+
`.trim());
|
|
2345
|
+
componentFolder.createFile(`${fileName}.svelte`, svelteComponentContent(`${ClassName}Props`));
|
|
2346
|
+
const framework = scaffold_svelte_modules_storybookFramework();
|
|
2347
|
+
if (framework) componentFolder.createFile(`${fileName}.stories.ts`, svelteStory(framework, ClassName, `${fileName}.svelte`, `UI-kit/${ClassName}`));
|
|
2348
|
+
};
|
|
2349
|
+
const scaffoldSvelteSharedModel = async (presentationSvelteFolder)=>{
|
|
2350
|
+
const name = await interaction_input({
|
|
2351
|
+
key: 'name',
|
|
2352
|
+
message: 'Name without "create" (e.g. debounce): '
|
|
2353
|
+
});
|
|
2354
|
+
const { ClassName, fileName } = new UnknownFormatNaming(name.trim().replace(/^create-/, ''));
|
|
2355
|
+
presentationSvelteFolder.subitem([
|
|
2356
|
+
'shared',
|
|
2357
|
+
'model'
|
|
2358
|
+
]).createFile(`create-${fileName}.svelte.ts`, `
|
|
2359
|
+
export const create${ClassName} = () => {
|
|
2360
|
+
return {}
|
|
2361
|
+
}
|
|
2362
|
+
`.trim());
|
|
2363
|
+
};
|
|
2364
|
+
const openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
2365
|
+
const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
|
|
2366
|
+
const endpointFileLookup = (rootFolder)=>` // A context is the start of the route, nested ones included
|
|
2367
|
+
// (/sales/orders/...). A controller is the next folder; other
|
|
2368
|
+
// routes belong to the context root in presentation/rest/(root).
|
|
2369
|
+
const contextsFolder = path.join(
|
|
2370
|
+
${rootFolderSegments(rootFolder, 16)}'bounded-contexts'
|
|
2371
|
+
);
|
|
2372
|
+
const endpointFile = Array.from(
|
|
2373
|
+
{ length: routeMetadata.path.length },
|
|
2374
|
+
(_, index) => index + 1
|
|
2375
|
+
)
|
|
2376
|
+
.flatMap((contextLength) => {
|
|
2377
|
+
const restFolder = path.join(
|
|
2378
|
+
contextsFolder,
|
|
2379
|
+
...routeMetadata.path.slice(0, contextLength),
|
|
2380
|
+
'presentation',
|
|
2381
|
+
'rest'
|
|
2382
|
+
);
|
|
2383
|
+
const endpointPath = [
|
|
2384
|
+
...routeMetadata.path
|
|
2385
|
+
.slice(contextLength)
|
|
2386
|
+
.map(pathParameterAsName),
|
|
2387
|
+
\`\${routeMetadata.method.toUpperCase()}.ts\`
|
|
2388
|
+
];
|
|
2389
|
+
return [
|
|
2390
|
+
path.join(restFolder, ...endpointPath),
|
|
2391
|
+
path.join(restFolder, '(root)', ...endpointPath)
|
|
2392
|
+
];
|
|
2393
|
+
})
|
|
2394
|
+
.map((file) => project.getSourceFile(file))
|
|
2395
|
+
.find((file) => !!file);
|
|
2396
|
+
`;
|
|
2397
|
+
const openapiExtractor = (rootFolder)=>`import path from 'node:path';
|
|
2398
|
+
import {
|
|
2399
|
+
type DocNode,
|
|
2400
|
+
DocPlainText,
|
|
2401
|
+
TSDocConfiguration,
|
|
2402
|
+
TSDocParser,
|
|
2403
|
+
TSDocTagDefinition,
|
|
2404
|
+
TSDocTagSyntaxKind
|
|
2405
|
+
} from '@microsoft/tsdoc';
|
|
2406
|
+
import { Node, Project, type SourceFile, SyntaxKind } from 'ts-morph';
|
|
2407
|
+
|
|
2408
|
+
type BlockTag = \`@\${string}\`;
|
|
2409
|
+
|
|
2410
|
+
type OpenApiDataTags = {
|
|
2411
|
+
/** Omit to take the summary from the comment text before the first tag. */
|
|
2412
|
+
summary?: BlockTag;
|
|
2413
|
+
description?: BlockTag;
|
|
2414
|
+
};
|
|
2415
|
+
|
|
2416
|
+
type OpenApiData = Partial<{
|
|
2417
|
+
summary: string;
|
|
2418
|
+
description: string;
|
|
2419
|
+
operationId: string;
|
|
2420
|
+
}>;
|
|
2421
|
+
|
|
2422
|
+
const project = new Project({
|
|
2423
|
+
tsConfigFilePath: 'tsconfig.json'
|
|
2424
|
+
});
|
|
2425
|
+
|
|
2426
|
+
const getText = (node: DocNode): string =>
|
|
2427
|
+
node
|
|
2428
|
+
.getChildNodes()
|
|
2429
|
+
.map((child) => {
|
|
2430
|
+
if (child instanceof DocPlainText) {
|
|
2431
|
+
return child.text;
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
return getText(child);
|
|
2435
|
+
})
|
|
2436
|
+
.join('');
|
|
2437
|
+
|
|
2438
|
+
const getRawCommentText = (comment: string): string =>
|
|
2439
|
+
comment
|
|
2440
|
+
.replace(/^\\/\\*\\*/, '')
|
|
2441
|
+
.replace(/\\*\\/$/, '')
|
|
2442
|
+
.split(/\\r?\\n/)
|
|
2443
|
+
.map((line) => line.replace(/^\\s*\\*\\s?/, ''))
|
|
2444
|
+
.join('\\n');
|
|
2445
|
+
|
|
2446
|
+
// TSDoc treats an unknown tag as summary content, so every block tag of the
|
|
2447
|
+
// comment has to be registered for the summary section to end before it.
|
|
2448
|
+
const parseSummary = (comment: string): string | undefined => {
|
|
2449
|
+
const configuration = new TSDocConfiguration();
|
|
2450
|
+
const tagNames = getRawCommentText(comment).matchAll(/(?:^|\\n)\\s*(@\\w+)/g);
|
|
2451
|
+
|
|
2452
|
+
for (const [, tagName] of tagNames) {
|
|
2453
|
+
if (!configuration.tryGetTagDefinition(tagName)) {
|
|
2454
|
+
configuration.addTagDefinition(
|
|
2455
|
+
new TSDocTagDefinition({
|
|
2456
|
+
tagName,
|
|
2457
|
+
syntaxKind: TSDocTagSyntaxKind.BlockTag
|
|
2458
|
+
})
|
|
2459
|
+
);
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
const { docComment } = new TSDocParser(configuration).parseString(comment);
|
|
2464
|
+
|
|
2465
|
+
return getText(docComment.summarySection).trim() || undefined;
|
|
2466
|
+
};
|
|
2467
|
+
|
|
2468
|
+
// Parsed by hand rather than through TSDoc, which drops the line breaks.
|
|
2469
|
+
const getTagText = (comment: string, tag: BlockTag): string | undefined => {
|
|
2470
|
+
const tagMatch = getRawCommentText(comment).match(
|
|
2471
|
+
new RegExp(
|
|
2472
|
+
\`(?:^|\\\\n)\\\\s*\${tag}(?:[ \\\\t]*\\\\n|[ \\\\t]+)([\\\\s\\\\S]*?)(?=\\\\n\\\\s*@\\\\w+|\\\\s*$)\`
|
|
2473
|
+
)
|
|
2474
|
+
);
|
|
2475
|
+
|
|
2476
|
+
return tagMatch?.[1].trim() || undefined;
|
|
2477
|
+
};
|
|
2478
|
+
|
|
2479
|
+
// Endpoints pass their logic as the generator's first argument
|
|
2480
|
+
// (\`this.endpointGenerator(this.handler.handle, ...)\`), while other injected
|
|
2481
|
+
// queries only serve as helpers, e.g. guest checks.
|
|
2482
|
+
const findHandlerClass = (endpointFile: SourceFile) =>
|
|
2483
|
+
endpointFile
|
|
2484
|
+
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
2485
|
+
.map((call) => call.getArguments()[0])
|
|
2486
|
+
.filter(Node.isPropertyAccessExpression)
|
|
2487
|
+
.find((argument) => argument.getName() === 'handle')
|
|
2488
|
+
?.getExpression()
|
|
2489
|
+
.getType()
|
|
2490
|
+
.getSymbol()
|
|
2491
|
+
?.getDeclarations()
|
|
2492
|
+
.find(Node.isClassDeclaration);
|
|
2493
|
+
|
|
2494
|
+
// Path parameters (\`:id\`) can't be part of file and folder names
|
|
2495
|
+
// everywhere (Windows), so endpoints name them \`_id_\` there.
|
|
2496
|
+
const pathParameterAsName = (segment: string) =>
|
|
2497
|
+
segment.startsWith(':') ? \`_\${segment.slice(1)}_\` : segment;
|
|
2498
|
+
|
|
2499
|
+
export const createOpenApiDataFromEndpointLogicExtractor = ({
|
|
2500
|
+
summary: summaryTag,
|
|
2501
|
+
description: descriptionTag = '@description'
|
|
2502
|
+
}: OpenApiDataTags = {}) => {
|
|
2503
|
+
return (routeMetadata: {
|
|
2504
|
+
method: string;
|
|
2505
|
+
path: readonly string[];
|
|
2506
|
+
}): OpenApiData | undefined => {
|
|
2507
|
+
try {
|
|
2508
|
+
${endpointFileLookup(rootFolder)}
|
|
2509
|
+
if (!endpointFile) {
|
|
2510
|
+
return undefined;
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
const declaration = findHandlerClass(endpointFile);
|
|
2514
|
+
const operationId = declaration?.getName();
|
|
2515
|
+
const comment = declaration?.getJsDocs().at(-1)?.getText();
|
|
2516
|
+
|
|
2517
|
+
if (!comment) {
|
|
2518
|
+
return { operationId };
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
return {
|
|
2522
|
+
summary: summaryTag
|
|
2523
|
+
? getTagText(comment, summaryTag)
|
|
2524
|
+
: parseSummary(comment),
|
|
2525
|
+
description: getTagText(comment, descriptionTag),
|
|
2526
|
+
operationId
|
|
2527
|
+
};
|
|
2528
|
+
} catch (e: unknown) {
|
|
2529
|
+
console.error(e);
|
|
2530
|
+
return undefined;
|
|
2531
|
+
}
|
|
2532
|
+
};
|
|
2533
|
+
};
|
|
2534
|
+
`;
|
|
2535
|
+
const openapiScriptPath = "scripts/generate-openapi.ts";
|
|
2536
|
+
const defaultOpenapiPath = ()=>usesNext() ? 'public/openapi.json' : usesSvelteKit() ? 'static/openapi.json' : 'openapi.json';
|
|
2537
|
+
const extractorPackages = [
|
|
2538
|
+
'ts-morph',
|
|
2539
|
+
'@microsoft/tsdoc'
|
|
2540
|
+
];
|
|
2541
|
+
const swaggerPagePath = (rootFolder, framework = 'react')=>external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'svelte' === framework ? 'presentation/svelte/pages/swagger-page.svelte' : 'presentation/react/pages/swagger-page.tsx');
|
|
2542
|
+
const specImportOf = (pagePath, outputPath)=>{
|
|
2543
|
+
const specImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(pagePath), outputPath);
|
|
2544
|
+
return specImport.startsWith('.') ? specImport : `./${specImport}`;
|
|
2545
|
+
};
|
|
2546
|
+
const swaggerPage = (rootFolder, outputPath, withNext = false)=>{
|
|
2547
|
+
const page = reactPageContent('Swagger', {
|
|
2548
|
+
imports: [
|
|
2549
|
+
"import 'swagger-ui-react/swagger-ui.css'",
|
|
2550
|
+
"import SwaggerUI from 'swagger-ui-react'",
|
|
2551
|
+
`import spec from '${specImportOf(swaggerPagePath(rootFolder), outputPath)}' with { type: 'json' }`
|
|
2552
|
+
],
|
|
1859
2553
|
body: '<SwaggerUI displayOperationId spec={spec} />'
|
|
1860
2554
|
});
|
|
1861
2555
|
return withNext ? `'use client'\n\n${page}` : page;
|
|
1862
2556
|
};
|
|
2557
|
+
const svelteKitStaticFolder = 'static/';
|
|
2558
|
+
const svelteKitStaticUrl = (outputPath)=>outputPath.startsWith(svelteKitStaticFolder) ? `/${outputPath.slice(svelteKitStaticFolder.length)}` : void 0;
|
|
2559
|
+
const svelteSwaggerPage = (rootFolder, outputPath, url)=>`
|
|
2560
|
+
<script lang="ts" module>
|
|
2561
|
+
export type SwaggerPageProps = {}
|
|
2562
|
+
</script>
|
|
2563
|
+
|
|
2564
|
+
<script lang="ts">
|
|
2565
|
+
import 'swagger-ui-dist/swagger-ui.css'
|
|
2566
|
+
import type { SwaggerUIBundle as SwaggerUIBundleType } from 'swagger-ui-dist'
|
|
2567
|
+
import { onMount } from 'svelte'${url ? '' : `
|
|
2568
|
+
import spec from '${specImportOf(swaggerPagePath(rootFolder, 'svelte'), outputPath)}'`}
|
|
2569
|
+
|
|
2570
|
+
let props: SwaggerPageProps = $props()
|
|
2571
|
+
let container: HTMLDivElement
|
|
2572
|
+
|
|
2573
|
+
onMount(async () => {
|
|
2574
|
+
// Self-contained bundle: React is bundled inside, no react deps in the project
|
|
2575
|
+
const { default: SwaggerUIBundle } = (await import(
|
|
2576
|
+
// @ts-expect-error -- swagger-ui-dist ships no types for this entry point
|
|
2577
|
+
'swagger-ui-dist/swagger-ui-bundle.js'
|
|
2578
|
+
)) as { default: SwaggerUIBundleType }
|
|
2579
|
+
|
|
2580
|
+
SwaggerUIBundle({ domNode: container, ${url ? `url: '${url}'` : 'spec'}, displayOperationId: true })
|
|
2581
|
+
})
|
|
2582
|
+
</script>
|
|
2583
|
+
|
|
2584
|
+
<div bind:this={container}></div>
|
|
2585
|
+
`.trim();
|
|
2586
|
+
const swaggerPackages = {
|
|
2587
|
+
react: {
|
|
2588
|
+
dependency: 'swagger-ui-react',
|
|
2589
|
+
types: '@types/swagger-ui-react'
|
|
2590
|
+
},
|
|
2591
|
+
svelte: {
|
|
2592
|
+
dependency: 'swagger-ui-dist',
|
|
2593
|
+
types: '@types/swagger-ui-dist'
|
|
2594
|
+
}
|
|
2595
|
+
};
|
|
1863
2596
|
const openapiScripts = {
|
|
1864
2597
|
openapi: `tsx --env-file-if-exists=.env ${openapiScriptPath}`
|
|
1865
2598
|
};
|
|
@@ -1918,7 +2651,7 @@ const addOpenapi = async ()=>{
|
|
|
1918
2651
|
const outputPath = await interaction_input({
|
|
1919
2652
|
key: 'openapiPath',
|
|
1920
2653
|
message: 'OpenAPI document path:',
|
|
1921
|
-
default: defaultOpenapiPath(
|
|
2654
|
+
default: defaultOpenapiPath(),
|
|
1922
2655
|
validate: (value)=>splitPath(value).length ? true : 'Path is required'
|
|
1923
2656
|
});
|
|
1924
2657
|
const withExtractor = await interaction_confirm({
|
|
@@ -1926,7 +2659,9 @@ const addOpenapi = async ()=>{
|
|
|
1926
2659
|
message: "Fill operationId, summary and description from the endpoint logic TSDoc?",
|
|
1927
2660
|
default: true
|
|
1928
2661
|
});
|
|
1929
|
-
const
|
|
2662
|
+
const { frontend } = config_file_ConfigFile.Instance.data;
|
|
2663
|
+
const framework = frontend?.svelte ? 'svelte' : frontend?.react ? 'react' : void 0;
|
|
2664
|
+
const withSwaggerPage = !!framework && await interaction_confirm({
|
|
1930
2665
|
key: 'swaggerPage',
|
|
1931
2666
|
message: 'Add a Swagger UI page?',
|
|
1932
2667
|
default: true
|
|
@@ -1940,16 +2675,18 @@ const addOpenapi = async ()=>{
|
|
|
1940
2675
|
const generatorFile = new file_system_File(external_node_path_default().join(root, openapiScriptPath));
|
|
1941
2676
|
const content = openapiGenerator(rootFolder, apiTitle(manifest.name), routePrefix, splitPath(outputPath).join('/'), withExtractor);
|
|
1942
2677
|
if (!generatorFile.exists || generatorFile.data !== content) generatorFile.data = content;
|
|
1943
|
-
const
|
|
1944
|
-
let
|
|
2678
|
+
const routeFile = withSwaggerPage && 'react' === framework && usesNext() ? `${nextAppFolder(root)}/swagger/page.tsx` : withSwaggerPage && 'svelte' === framework && usesSvelteKit() ? `${svelteKitRoutesFolder(root)}/swagger/+page.svelte` : void 0;
|
|
2679
|
+
let routeHint;
|
|
2680
|
+
const specUrl = 'svelte' === framework && usesSvelteKit() ? svelteKitStaticUrl(splitPath(outputPath).join('/')) : void 0;
|
|
1945
2681
|
if (withSwaggerPage) {
|
|
1946
|
-
const pagePath = external_node_path_default().join(root, swaggerPagePath(rootFolder));
|
|
2682
|
+
const pagePath = external_node_path_default().join(root, swaggerPagePath(rootFolder, framework));
|
|
1947
2683
|
const pageFile = new file_system_File(pagePath);
|
|
1948
|
-
const page = swaggerPage(rootFolder, splitPath(outputPath).join('/'),
|
|
2684
|
+
const page = 'svelte' === framework ? svelteSwaggerPage(rootFolder, splitPath(outputPath).join('/'), specUrl) : swaggerPage(rootFolder, splitPath(outputPath).join('/'), !!routeFile);
|
|
1949
2685
|
if (!pageFile.exists || pageFile.data !== page) pageFile.data = page;
|
|
1950
|
-
if (
|
|
2686
|
+
if (routeFile) routeHint = ('svelte' === framework ? scaffoldSvelteKitRoute : scaffoldNextRoute)(new NestedName('swagger'), pagePath);
|
|
1951
2687
|
}
|
|
1952
|
-
const
|
|
2688
|
+
const packages = swaggerPackages[framework ?? 'react'];
|
|
2689
|
+
const resolveJsonModule = withSwaggerPage && !specUrl ? compilerOption(external_node_path_default().join(root, 'tsconfig.json'), 'resolveJsonModule') : true;
|
|
1953
2690
|
const hasRestHandlers = new file_system_File(external_node_path_default().join(root, rootFolder, 'presentation', 'rest', 'index.ts')).exists;
|
|
1954
2691
|
const missingExtractorPackages = withExtractor ? extractorPackages.filter((name)=>!dependencies[name]) : [];
|
|
1955
2692
|
return [
|
|
@@ -1962,11 +2699,11 @@ const addOpenapi = async ()=>{
|
|
|
1962
2699
|
...missingExtractorPackages.length ? [
|
|
1963
2700
|
`npm install --save-dev ${missingExtractorPackages.join(' ')}`
|
|
1964
2701
|
] : [],
|
|
1965
|
-
...withSwaggerPage && !dependencies[
|
|
1966
|
-
|
|
2702
|
+
...withSwaggerPage && !dependencies[packages.dependency] ? [
|
|
2703
|
+
`npm install ${packages.dependency}`
|
|
1967
2704
|
] : [],
|
|
1968
|
-
...withSwaggerPage && !dependencies[
|
|
1969
|
-
|
|
2705
|
+
...withSwaggerPage && !dependencies[packages.types] ? [
|
|
2706
|
+
`npm install --save-dev ${packages.types}`
|
|
1970
2707
|
] : [],
|
|
1971
2708
|
...true === resolveJsonModule || null === resolveJsonModule ? [] : [
|
|
1972
2709
|
'set "resolveJsonModule": true in compilerOptions of tsconfig.json — the Swagger UI page imports the OpenAPI document as JSON'
|
|
@@ -1974,11 +2711,11 @@ const addOpenapi = async ()=>{
|
|
|
1974
2711
|
...describeScripts(selected, {
|
|
1975
2712
|
openapi: `generate the OpenAPI document from restHandlers in ${splitPath(outputPath).join('/')}`
|
|
1976
2713
|
}),
|
|
1977
|
-
...withSwaggerPage && !
|
|
1978
|
-
`SwaggerPage from ${swaggerPagePath(rootFolder)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
2714
|
+
...withSwaggerPage && !routeFile ? [
|
|
2715
|
+
`SwaggerPage from ${swaggerPagePath(rootFolder, framework)} shows ${splitPath(outputPath).join('/')} once it is generated — render it on a route of your app`
|
|
1979
2716
|
] : [],
|
|
1980
|
-
...
|
|
1981
|
-
|
|
2717
|
+
...routeFile ? [
|
|
2718
|
+
routeHint ?? `/swagger shows ${splitPath(outputPath).join('/')} once it is generated — the route is ${routeFile}`
|
|
1982
2719
|
] : [],
|
|
1983
2720
|
...hasRestHandlers ? [] : [
|
|
1984
2721
|
`restHandlers appear in ${external_node_path_default().posix.join(rootFolder, 'presentation/rest/index.ts')} with the first REST endpoint generated with @domain-first/wire`
|
|
@@ -1992,20 +2729,28 @@ const addGitignoreEntry = (root, entry)=>{
|
|
|
1992
2729
|
const newline = ignored.includes('\r\n') ? '\r\n' : '\n';
|
|
1993
2730
|
gitignore.update(`${ignored}${ignored && !ignored.endsWith('\n') ? newline : ''}${entry}${newline}`);
|
|
1994
2731
|
};
|
|
1995
|
-
const dataLayerFolder = (rootFolder, target)=>external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'hooks' === target ?
|
|
1996
|
-
const orvalScripts = (rootFolder, targets)=>({
|
|
1997
|
-
'client:orval': targets.map((target)=>`orval --config ${JSON.stringify(`${dataLayerFolder(rootFolder, target)}/orval.config.ts`)}`).join(' && ')
|
|
2732
|
+
const dataLayerFolder = (rootFolder, target, framework = 'react')=>external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), 'hooks' === target ? `presentation/${framework}/data-layer` : 'presentation/data-layer');
|
|
2733
|
+
const orvalScripts = (rootFolder, targets, framework = 'react')=>({
|
|
2734
|
+
'client:orval': targets.map((target)=>`orval --config ${JSON.stringify(`${dataLayerFolder(rootFolder, target, framework)}/orval.config.ts`)}`).join(' && ')
|
|
1998
2735
|
});
|
|
1999
|
-
const
|
|
2000
|
-
|
|
2001
|
-
|
|
2736
|
+
const orvalBaseUrls = {
|
|
2737
|
+
next: 'process.env.NEXT_PUBLIC_API_BASE_URL ?? ""',
|
|
2738
|
+
svelte: 'import.meta.env.VITE_API_BASE_URL ?? ""'
|
|
2739
|
+
};
|
|
2740
|
+
const orvalConfig = (rootFolder, openapiPath, baseUrlSource, target = 'hooks', mutatorPath = './api-client/mutator.ts', framework = 'react')=>{
|
|
2741
|
+
const inputPath = external_node_path_default().posix.relative(dataLayerFolder(rootFolder, target, framework), openapiPath);
|
|
2742
|
+
const baseUrl = baseUrlSource ? `
|
|
2002
2743
|
baseUrl: {
|
|
2003
|
-
runtime: '
|
|
2744
|
+
runtime: '${orvalBaseUrls[baseUrlSource]}'
|
|
2004
2745
|
},` : '';
|
|
2746
|
+
const svelteQuery = 'hooks' === target && 'svelte' === framework;
|
|
2005
2747
|
const client = 'hooks' === target ? `
|
|
2006
|
-
client: 'react-query',
|
|
2748
|
+
client: '${svelteQuery ? 'svelte-query' : 'react-query'}',
|
|
2007
2749
|
httpClient: 'fetch',` : `
|
|
2008
2750
|
client: 'fetch',`;
|
|
2751
|
+
const packageJson = svelteQuery ? `
|
|
2752
|
+
// Svelte Query 6 (runes) even before it is installed; an installed version wins
|
|
2753
|
+
packageJson: './${svelteQueryPackageJsonFile}',` : '';
|
|
2009
2754
|
const query = 'hooks' === target ? `,
|
|
2010
2755
|
query: {
|
|
2011
2756
|
version: 5
|
|
@@ -2018,7 +2763,7 @@ export default defineConfig({
|
|
|
2018
2763
|
output: {
|
|
2019
2764
|
mode: 'tags-split',
|
|
2020
2765
|
target: './orval',
|
|
2021
|
-
schemas: './orval/model',${client}${baseUrl}
|
|
2766
|
+
schemas: './orval/model',${client}${packageJson}${baseUrl}
|
|
2022
2767
|
clean: true,
|
|
2023
2768
|
override: {
|
|
2024
2769
|
mutator: {
|
|
@@ -2034,6 +2779,14 @@ export default defineConfig({
|
|
|
2034
2779
|
});
|
|
2035
2780
|
`;
|
|
2036
2781
|
};
|
|
2782
|
+
const svelteQueryPackageJsonFile = 'orval.package.json';
|
|
2783
|
+
const svelteQueryPackageJson = `${JSON.stringify({
|
|
2784
|
+
private: true,
|
|
2785
|
+
dependencies: {
|
|
2786
|
+
'@tanstack/svelte-query': '^6.0.0'
|
|
2787
|
+
}
|
|
2788
|
+
}, null, 4)}
|
|
2789
|
+
`;
|
|
2037
2790
|
const orvalMutator = `/** Error of the generated requests, with the parsed response body. */
|
|
2038
2791
|
export class ApiError<Body = unknown> extends Error {
|
|
2039
2792
|
constructor(
|
|
@@ -2079,7 +2832,44 @@ export const QueryProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
|
|
2079
2832
|
</QueryClientProvider>
|
|
2080
2833
|
);
|
|
2081
2834
|
};
|
|
2082
|
-
`;
|
|
2835
|
+
`;
|
|
2836
|
+
const svelteQueryProvider = (withSvelteKit)=>`<script lang="ts">
|
|
2837
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
|
|
2838
|
+
import type { Snippet } from 'svelte'${withSvelteKit ? "\n import { browser } from '$app/environment'" : ''}
|
|
2839
|
+
|
|
2840
|
+
let { children }: { children: Snippet } = $props()
|
|
2841
|
+
|
|
2842
|
+
// One client per app instance; a module-level client would be shared between requests on the server
|
|
2843
|
+
const queryClient = new QueryClient(${withSvelteKit ? `{
|
|
2844
|
+
defaultOptions: { queries: { enabled: browser } }
|
|
2845
|
+
}` : ''})
|
|
2846
|
+
</script>
|
|
2847
|
+
|
|
2848
|
+
<QueryClientProvider client={queryClient}>
|
|
2849
|
+
{@render children()}
|
|
2850
|
+
</QueryClientProvider>
|
|
2851
|
+
`;
|
|
2852
|
+
const svelteKitQueryLayout = (providerImport)=>`<script lang="ts">
|
|
2853
|
+
import type { Snippet } from 'svelte'
|
|
2854
|
+
import QueryProvider from '${providerImport}'
|
|
2855
|
+
|
|
2856
|
+
let { children }: { children: Snippet } = $props()
|
|
2857
|
+
</script>
|
|
2858
|
+
|
|
2859
|
+
<QueryProvider>
|
|
2860
|
+
{@render children()}
|
|
2861
|
+
</QueryProvider>
|
|
2862
|
+
`;
|
|
2863
|
+
const connectSvelteKitProvider = (root, providerPath)=>{
|
|
2864
|
+
const layoutPath = external_node_path_default().posix.join(svelteKitRoutesFolder(root), '+layout.svelte');
|
|
2865
|
+
const layout = new file_system_File(external_node_path_default().join(root, layoutPath));
|
|
2866
|
+
if (!layout.exists) {
|
|
2867
|
+
const providerImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(layoutPath), providerPath);
|
|
2868
|
+
layout.data = svelteKitQueryLayout(providerImport.startsWith('.') ? providerImport : `./${providerImport}`);
|
|
2869
|
+
return;
|
|
2870
|
+
}
|
|
2871
|
+
return layout.data.includes('QueryProvider') ? void 0 : `Wrap {@render children()} of ${layoutPath} in QueryProvider from ${providerPath}`;
|
|
2872
|
+
};
|
|
2083
2873
|
const openapiOutputPath = (root)=>{
|
|
2084
2874
|
const generator = new file_system_File(external_node_path_default().join(root, openapiScriptPath));
|
|
2085
2875
|
if (!generator.exists) return;
|
|
@@ -2087,7 +2877,7 @@ const openapiOutputPath = (root)=>{
|
|
|
2087
2877
|
};
|
|
2088
2878
|
const addOrval = async ()=>{
|
|
2089
2879
|
const { project: { rootFolder }, frontend } = config_file_ConfigFile.Instance.data;
|
|
2090
|
-
const
|
|
2880
|
+
const framework = frontend?.svelte ? 'svelte' : frontend?.react ? 'react' : void 0;
|
|
2091
2881
|
const root = new project_root_ProjectRoot().path;
|
|
2092
2882
|
const manifestFile = new file_system_File(external_node_path_default().join(root, 'package.json'));
|
|
2093
2883
|
const manifest = JSON.parse(manifestFile.data);
|
|
@@ -2095,20 +2885,22 @@ const addOrval = async ()=>{
|
|
|
2095
2885
|
...manifest.dependencies,
|
|
2096
2886
|
...manifest.devDependencies
|
|
2097
2887
|
};
|
|
2098
|
-
const
|
|
2888
|
+
const withSvelteKit = usesSvelteKit();
|
|
2889
|
+
const baseUrl = 'svelte' === framework ? 'svelte' : usesNext() ? 'next' : void 0;
|
|
2890
|
+
const hooksFramework = framework ?? 'react';
|
|
2099
2891
|
const generatedOpenapiPath = openapiOutputPath(root);
|
|
2100
2892
|
const openapiPath = await interaction_input({
|
|
2101
2893
|
key: 'openapiPath',
|
|
2102
2894
|
message: 'OpenAPI document path:',
|
|
2103
|
-
default: generatedOpenapiPath ?? defaultOpenapiPath(
|
|
2895
|
+
default: generatedOpenapiPath ?? defaultOpenapiPath(),
|
|
2104
2896
|
validate: (value)=>value.trim() ? true : 'Path is required'
|
|
2105
2897
|
});
|
|
2106
|
-
const targets =
|
|
2898
|
+
const targets = framework ? await interaction_checkbox({
|
|
2107
2899
|
key: 'targets',
|
|
2108
2900
|
message: 'Generate:',
|
|
2109
2901
|
choices: [
|
|
2110
2902
|
{
|
|
2111
|
-
name: 'React Query hooks',
|
|
2903
|
+
name: 'svelte' === framework ? 'Svelte Query (createQuery)' : 'React Query hooks',
|
|
2112
2904
|
value: 'hooks',
|
|
2113
2905
|
checked: true
|
|
2114
2906
|
},
|
|
@@ -2121,16 +2913,23 @@ const addOrval = async ()=>{
|
|
|
2121
2913
|
}) : [
|
|
2122
2914
|
'client'
|
|
2123
2915
|
];
|
|
2124
|
-
const selected = await addPackageScripts(manifestFile, orvalScripts(rootFolder, targets));
|
|
2916
|
+
const selected = await addPackageScripts(manifestFile, orvalScripts(rootFolder, targets, hooksFramework));
|
|
2917
|
+
const layer = (target)=>dataLayerFolder(rootFolder, target, hooksFramework);
|
|
2918
|
+
const providerFile = 'svelte' === hooksFramework ? 'query-provider.svelte' : 'query-provider.tsx';
|
|
2919
|
+
const providerContent = 'svelte' === hooksFramework ? svelteQueryProvider(withSvelteKit) : queryProvider;
|
|
2125
2920
|
const document = external_node_path_default().posix.normalize(openapiPath.trim().replaceAll('\\', '/'));
|
|
2126
2921
|
const withClient = targets.includes('client');
|
|
2127
2922
|
for (const target of targets){
|
|
2128
|
-
const dataLayer =
|
|
2923
|
+
const dataLayer = layer(target);
|
|
2129
2924
|
const sharedMutator = 'hooks' === target && withClient;
|
|
2130
|
-
const mutatorPath = sharedMutator ? `${external_node_path_default().posix.relative(dataLayer,
|
|
2925
|
+
const mutatorPath = sharedMutator ? `${external_node_path_default().posix.relative(dataLayer, layer('client'))}/api-client/mutator.ts` : void 0;
|
|
2131
2926
|
const configFile = new file_system_File(external_node_path_default().join(root, dataLayer, 'orval.config.ts'));
|
|
2132
|
-
const content = orvalConfig(rootFolder, document,
|
|
2927
|
+
const content = orvalConfig(rootFolder, document, baseUrl, target, mutatorPath, hooksFramework);
|
|
2133
2928
|
if (!configFile.exists || configFile.data !== content) configFile.data = content;
|
|
2929
|
+
if ('hooks' === target && 'svelte' === hooksFramework) {
|
|
2930
|
+
const versions = new file_system_File(external_node_path_default().join(root, dataLayer, svelteQueryPackageJsonFile));
|
|
2931
|
+
if (!versions.exists || versions.data !== svelteQueryPackageJson) versions.data = svelteQueryPackageJson;
|
|
2932
|
+
}
|
|
2134
2933
|
for (const [name, fileContent] of [
|
|
2135
2934
|
...sharedMutator ? [] : [
|
|
2136
2935
|
[
|
|
@@ -2140,8 +2939,8 @@ const addOrval = async ()=>{
|
|
|
2140
2939
|
],
|
|
2141
2940
|
...'hooks' === target ? [
|
|
2142
2941
|
[
|
|
2143
|
-
|
|
2144
|
-
|
|
2942
|
+
providerFile,
|
|
2943
|
+
providerContent
|
|
2145
2944
|
]
|
|
2146
2945
|
] : []
|
|
2147
2946
|
]){
|
|
@@ -2150,10 +2949,14 @@ const addOrval = async ()=>{
|
|
|
2150
2949
|
}
|
|
2151
2950
|
addGitignoreEntry(root, `/${dataLayer}/orval/`);
|
|
2152
2951
|
}
|
|
2153
|
-
const
|
|
2952
|
+
const withHooks = targets.includes('hooks');
|
|
2953
|
+
const providerPath = `${layer('hooks')}/${providerFile}`;
|
|
2954
|
+
const layoutNote = withHooks && 'svelte' === hooksFramework && withSvelteKit ? connectSvelteKitProvider(root, providerPath) : void 0;
|
|
2955
|
+
const queryPackage = 'svelte' === hooksFramework ? '@tanstack/svelte-query' : '@tanstack/react-query';
|
|
2956
|
+
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`);
|
|
2154
2957
|
const missing = (names)=>names.filter((name)=>!dependencies[name]);
|
|
2155
|
-
const runtime = missing(
|
|
2156
|
-
|
|
2958
|
+
const runtime = missing(withHooks ? [
|
|
2959
|
+
queryPackage
|
|
2157
2960
|
] : []);
|
|
2158
2961
|
const development = missing([
|
|
2159
2962
|
'orval'
|
|
@@ -2168,8 +2971,11 @@ const addOrval = async ()=>{
|
|
|
2168
2971
|
...describeScripts(selected, {
|
|
2169
2972
|
'client:orval': `generate ${generated.join(' and ')} from ${openapiPath.trim()}`
|
|
2170
2973
|
}),
|
|
2171
|
-
...
|
|
2172
|
-
`Wrap your app in QueryProvider from ${
|
|
2974
|
+
...withHooks && !('svelte' === hooksFramework && withSvelteKit) ? [
|
|
2975
|
+
`Wrap your app in QueryProvider from ${providerPath}`
|
|
2976
|
+
] : [],
|
|
2977
|
+
...layoutNote ? [
|
|
2978
|
+
layoutNote
|
|
2173
2979
|
] : [],
|
|
2174
2980
|
...generatedOpenapiPath ? [] : [
|
|
2175
2981
|
'npx df-integration → OpenAPI generates the OpenAPI document the client is built from'
|
|
@@ -2409,6 +3215,22 @@ const addPrisma = async ()=>{
|
|
|
2409
3215
|
})
|
|
2410
3216
|
];
|
|
2411
3217
|
};
|
|
3218
|
+
const rest_adapters_restAdapters = {
|
|
3219
|
+
next: {
|
|
3220
|
+
package: '@domain-first/handlers-next',
|
|
3221
|
+
adapter: 'nextAdapter',
|
|
3222
|
+
endpoints: 'nextEndpoints',
|
|
3223
|
+
key: 'nextAdapter',
|
|
3224
|
+
routePath: (root)=>external_node_path_default().posix.join(nextAppFolder(root), 'api/[...path]/route.ts')
|
|
3225
|
+
},
|
|
3226
|
+
svelte: {
|
|
3227
|
+
package: '@domain-first/handlers-svelte',
|
|
3228
|
+
adapter: 'svelteAdapter',
|
|
3229
|
+
endpoints: 'svelteEndpoints',
|
|
3230
|
+
key: 'svelteAdapter',
|
|
3231
|
+
routePath: (root)=>external_node_path_default().posix.join(svelteKitRoutesFolder(root), 'api/[...path]/+server.ts')
|
|
3232
|
+
}
|
|
3233
|
+
};
|
|
2412
3234
|
const kindTitles = {
|
|
2413
3235
|
repositories: 'Repositories',
|
|
2414
3236
|
'domain-services': 'Domain services',
|
|
@@ -2603,15 +3425,16 @@ const scaffoldNewPresentationService = async (boundedContextFolder)=>{
|
|
|
2603
3425
|
if (wireFile) await wireNewModuleDependencies(boundedContextFolder, wireFile);
|
|
2604
3426
|
};
|
|
2605
3427
|
const rest_endpoint_generator_name = 'rest-endpoint-generator';
|
|
2606
|
-
const scaffoldRestEndpointGenerator = (sharedFolder, {
|
|
2607
|
-
const
|
|
3428
|
+
const scaffoldRestEndpointGenerator = (sharedFolder, { adapter: framework } = {})=>createPresentationService(sharedFolder, rest_endpoint_generator_name, (className)=>{
|
|
3429
|
+
const known = framework && rest_adapters_restAdapters[framework];
|
|
3430
|
+
const adapter = known ? known.adapter : 'adapter';
|
|
2608
3431
|
return `
|
|
2609
3432
|
import {
|
|
2610
|
-
${
|
|
3433
|
+
${known ? '' : ' type Adapter,\n'} type EndpointGenerator,
|
|
2611
3434
|
createEndpoint,
|
|
2612
3435
|
invalidRequest
|
|
2613
3436
|
} from '@domain-first/handlers-rest'
|
|
2614
|
-
${
|
|
3437
|
+
${known ? `import { ${known.adapter} } from '${known.package}'` : `
|
|
2615
3438
|
/**
|
|
2616
3439
|
* The adapter of your HTTP framework.
|
|
2617
3440
|
*/
|
|
@@ -2636,16 +3459,17 @@ const findRestEndpointGenerator = (sharedFolder)=>{
|
|
|
2636
3459
|
wireFile: external_node_path_default().join(sharedFolder.path, 'wiring', 'presentation-services', `wire-${rest_endpoint_generator_name}-presentation-service.ts`)
|
|
2637
3460
|
};
|
|
2638
3461
|
};
|
|
2639
|
-
const
|
|
2640
|
-
const
|
|
2641
|
-
|
|
3462
|
+
const catchAllRoute = (adapter, restHandlersImport)=>{
|
|
3463
|
+
const { endpoints, package: packageName } = rest_adapters_restAdapters[adapter];
|
|
3464
|
+
return `
|
|
3465
|
+
import { ${endpoints} } from '${packageName}'
|
|
2642
3466
|
${restHandlersImport ? `import { restHandlers } from '${restHandlersImport}'
|
|
2643
3467
|
|
|
2644
|
-
const handler =
|
|
3468
|
+
const handler = ${endpoints}(restHandlers)` : `
|
|
2645
3469
|
/**
|
|
2646
3470
|
* Pass the endpoints' handle here; their paths are relative to this route's folder.
|
|
2647
3471
|
*/
|
|
2648
|
-
const handler =
|
|
3472
|
+
const handler = ${endpoints}([])`}
|
|
2649
3473
|
|
|
2650
3474
|
export const GET = handler
|
|
2651
3475
|
export const POST = handler
|
|
@@ -2653,14 +3477,15 @@ export const PUT = handler
|
|
|
2653
3477
|
export const PATCH = handler
|
|
2654
3478
|
export const DELETE = handler
|
|
2655
3479
|
`.trim();
|
|
2656
|
-
|
|
3480
|
+
};
|
|
3481
|
+
const scaffoldCatchAllRoute = (root, adapter)=>{
|
|
2657
3482
|
const { rootFolder } = config_file_ConfigFile.Instance.data.project;
|
|
2658
3483
|
const { domainFirstPackages } = config_file_ConfigFile.backend;
|
|
2659
|
-
const routePath =
|
|
3484
|
+
const routePath = rest_adapters_restAdapters[adapter].routePath(root);
|
|
2660
3485
|
const routeFile = external_node_path_default().join(root, routePath);
|
|
2661
3486
|
if (new file_system_File(routeFile).exists) return [];
|
|
2662
3487
|
if (!domainFirstPackages.includes('@domain-first/wire')) {
|
|
2663
|
-
new file_system_File(routeFile).data =
|
|
3488
|
+
new file_system_File(routeFile).data = catchAllRoute(adapter, void 0);
|
|
2664
3489
|
return [];
|
|
2665
3490
|
}
|
|
2666
3491
|
const restFolder = new file_system_Folder(root).subitem([
|
|
@@ -2668,16 +3493,21 @@ const rest_endpoint_generator_scaffoldNextRoute = (root)=>{
|
|
|
2668
3493
|
'presentation',
|
|
2669
3494
|
'rest'
|
|
2670
3495
|
]);
|
|
2671
|
-
new file_system_File(routeFile).data =
|
|
3496
|
+
new file_system_File(routeFile).data = catchAllRoute(adapter, relativeImport(routeFile, restFolder.path));
|
|
2672
3497
|
return new file_system_File(external_node_path_default().join(restFolder.path, 'index.ts')).exists ? [] : [
|
|
2673
3498
|
`${routePath} serves restHandlers from ${external_node_path_default().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`
|
|
2674
3499
|
];
|
|
2675
3500
|
};
|
|
2676
|
-
const
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
}
|
|
2680
|
-
|
|
3501
|
+
const frameworkRestAdapter = ()=>usesNext() ? 'next' : usesSvelteKit() ? 'svelte' : void 0;
|
|
3502
|
+
const rest_endpoint_generator_askRestAdapter = async ({ adapter = frameworkRestAdapter() } = {})=>{
|
|
3503
|
+
if (!adapter) return;
|
|
3504
|
+
const { key, package: packageName } = rest_adapters_restAdapters[adapter];
|
|
3505
|
+
return await interaction_confirm({
|
|
3506
|
+
key,
|
|
3507
|
+
message: `Use ${packageName} for REST endpoints`
|
|
3508
|
+
}) ? adapter : void 0;
|
|
3509
|
+
};
|
|
3510
|
+
const rest_endpoint_generator_scaffoldRestEndpointGeneratorFiles = ({ adapter })=>{
|
|
2681
3511
|
const root = new project_root_ProjectRoot().path;
|
|
2682
3512
|
const generatorExisted = restEndpointGeneratorApplied();
|
|
2683
3513
|
const routeNotes = file_system_withoutOverwrites(()=>{
|
|
@@ -2685,40 +3515,64 @@ const rest_endpoint_generator_scaffoldRestEndpointGeneratorFiles = ({ withNextAd
|
|
|
2685
3515
|
config_file_ConfigFile.Instance.data.project.rootFolder,
|
|
2686
3516
|
'shared-kernel'
|
|
2687
3517
|
]), {
|
|
2688
|
-
|
|
3518
|
+
adapter
|
|
2689
3519
|
});
|
|
2690
|
-
return
|
|
3520
|
+
return adapter ? scaffoldCatchAllRoute(root, adapter) : [];
|
|
2691
3521
|
});
|
|
2692
|
-
if (!
|
|
3522
|
+
if (!adapter) return [];
|
|
3523
|
+
const { adapter: adapterName, package: packageName } = rest_adapters_restAdapters[adapter];
|
|
2693
3524
|
return [
|
|
2694
3525
|
...missing_domain_first_packages_missingPackages([
|
|
2695
|
-
|
|
3526
|
+
packageName
|
|
2696
3527
|
]),
|
|
2697
3528
|
...routeNotes,
|
|
2698
3529
|
...generatorExisted ? [
|
|
2699
|
-
|
|
3530
|
+
`the existing endpoint generator was kept — pass ${adapterName} from ${packageName} to its createEndpoint calls`
|
|
2700
3531
|
] : []
|
|
2701
3532
|
];
|
|
2702
3533
|
};
|
|
2703
3534
|
const addRestEndpointGenerator = async ()=>rest_endpoint_generator_scaffoldRestEndpointGeneratorFiles({
|
|
2704
|
-
|
|
3535
|
+
adapter: await rest_endpoint_generator_askRestAdapter()
|
|
2705
3536
|
});
|
|
2706
3537
|
const restEndpointGeneratorApplied = ()=>Boolean(findRestEndpointGenerator(new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
2707
3538
|
config_file_ConfigFile.Instance.data.project.rootFolder,
|
|
2708
3539
|
'shared-kernel'
|
|
2709
3540
|
])));
|
|
2710
|
-
const
|
|
2711
|
-
const
|
|
3541
|
+
const storybookFrameworkPackage = '@storybook/react-vite';
|
|
3542
|
+
const svelteStorybookPackages = {
|
|
3543
|
+
svelte: '@storybook/svelte-vite',
|
|
3544
|
+
sveltekit: '@storybook/sveltekit'
|
|
3545
|
+
};
|
|
3546
|
+
const storybookFamily = ()=>config_file_ConfigFile.Instance.data.frontend?.svelte ? 'svelte' : 'react';
|
|
3547
|
+
const storybookTitle = ()=>config_file_ConfigFile.exists && config_file_ConfigFile.Instance.data.frontend?.svelte ? 'sveltekit' === config_file_ConfigFile.Instance.data.frontend.svelte.framework ? 'Storybook (SvelteKit)' : 'Storybook (Svelte + Vite)' : 'Storybook (React + Vite)';
|
|
3548
|
+
const storybookFolder = ()=>`presentation/${storybookFamily()}/.storybook`;
|
|
3549
|
+
const storybookPreview = (frameworkPackage)=>`import type { Preview } from '${frameworkPackage}';
|
|
3550
|
+
|
|
3551
|
+
const preview: Preview = {
|
|
3552
|
+
parameters: {
|
|
3553
|
+
controls: {
|
|
3554
|
+
matchers: {
|
|
3555
|
+
color: /(background|color)$/i,
|
|
3556
|
+
date: /Date$/i
|
|
3557
|
+
}
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
};
|
|
3561
|
+
|
|
3562
|
+
export default preview;
|
|
3563
|
+
`;
|
|
3564
|
+
const svelteStorybookFiles = (relativeProjectRoot, frameworkPackage)=>{
|
|
3565
|
+
const withPlugin = frameworkPackage === svelteStorybookPackages.svelte;
|
|
3566
|
+
return {
|
|
2712
3567
|
'main.ts': `import { resolve } from 'node:path';
|
|
2713
|
-
import
|
|
2714
|
-
import type { StorybookConfig } from '${storybook_storybookFrameworkPackage}';
|
|
3568
|
+
import type { StorybookConfig } from '${frameworkPackage}';
|
|
2715
3569
|
|
|
2716
3570
|
const projectRoot = resolve(import.meta.dirname, ${JSON.stringify(relativeProjectRoot)});
|
|
2717
3571
|
|
|
2718
3572
|
const config: StorybookConfig = {
|
|
2719
|
-
stories: ['../**/*.mdx', '../**/*.stories.@(ts|
|
|
3573
|
+
stories: ['../**/*.mdx', '../**/*.stories.@(ts|svelte)'],
|
|
2720
3574
|
framework: {
|
|
2721
|
-
name: '${
|
|
3575
|
+
name: '${frameworkPackage}',
|
|
2722
3576
|
options: {}
|
|
2723
3577
|
},
|
|
2724
3578
|
core: {
|
|
@@ -2726,9 +3580,20 @@ const config: StorybookConfig = {
|
|
|
2726
3580
|
},
|
|
2727
3581
|
async viteFinal(viteConfig) {
|
|
2728
3582
|
const { mergeConfig } = await import('vite');
|
|
3583
|
+
${withPlugin ? ` const { svelte } = await import('@sveltejs/vite-plugin-svelte');
|
|
3584
|
+
const hasSvelte = (viteConfig.plugins ?? [])
|
|
3585
|
+
.flat(Infinity)
|
|
3586
|
+
.some(
|
|
3587
|
+
(plugin) =>
|
|
3588
|
+
!!plugin &&
|
|
3589
|
+
typeof plugin === 'object' &&
|
|
3590
|
+
'name' in plugin &&
|
|
3591
|
+
String(plugin.name).startsWith('vite-plugin-svelte')
|
|
3592
|
+
);
|
|
2729
3593
|
|
|
2730
3594
|
return mergeConfig(viteConfig, {
|
|
2731
|
-
plugins: [
|
|
3595
|
+
plugins: hasSvelte ? [] : [svelte()],` : `
|
|
3596
|
+
return mergeConfig(viteConfig, {`}
|
|
2732
3597
|
resolve: {
|
|
2733
3598
|
alias: {
|
|
2734
3599
|
'@': projectRoot
|
|
@@ -2740,62 +3605,79 @@ const config: StorybookConfig = {
|
|
|
2740
3605
|
|
|
2741
3606
|
export default config;
|
|
2742
3607
|
`,
|
|
2743
|
-
'preview.ts':
|
|
3608
|
+
'preview.ts': storybookPreview(frameworkPackage)
|
|
3609
|
+
};
|
|
3610
|
+
};
|
|
3611
|
+
const storybookFiles = (relativeProjectRoot)=>({
|
|
3612
|
+
'main.ts': `import { resolve } from 'node:path';
|
|
3613
|
+
import react from '@vitejs/plugin-react';
|
|
3614
|
+
import type { StorybookConfig } from '${storybookFrameworkPackage}';
|
|
2744
3615
|
|
|
2745
|
-
const
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
3616
|
+
const projectRoot = resolve(import.meta.dirname, ${JSON.stringify(relativeProjectRoot)});
|
|
3617
|
+
|
|
3618
|
+
const config: StorybookConfig = {
|
|
3619
|
+
stories: ['../**/*.mdx', '../**/*.stories.@(ts|tsx)'],
|
|
3620
|
+
framework: {
|
|
3621
|
+
name: '${storybookFrameworkPackage}',
|
|
3622
|
+
options: {}
|
|
3623
|
+
},
|
|
3624
|
+
core: {
|
|
3625
|
+
disableTelemetry: true
|
|
3626
|
+
},
|
|
3627
|
+
async viteFinal(viteConfig) {
|
|
3628
|
+
const { mergeConfig } = await import('vite');
|
|
3629
|
+
|
|
3630
|
+
return mergeConfig(viteConfig, {
|
|
3631
|
+
plugins: [react()],
|
|
3632
|
+
resolve: {
|
|
3633
|
+
alias: {
|
|
3634
|
+
'@': projectRoot
|
|
3635
|
+
}
|
|
2751
3636
|
}
|
|
2752
|
-
}
|
|
3637
|
+
});
|
|
2753
3638
|
}
|
|
2754
3639
|
};
|
|
2755
3640
|
|
|
2756
|
-
export default
|
|
2757
|
-
|
|
3641
|
+
export default config;
|
|
3642
|
+
`,
|
|
3643
|
+
'preview.ts': storybookPreview(storybookFrameworkPackage)
|
|
2758
3644
|
});
|
|
2759
|
-
const storybookScripts = (rootFolder)=>{
|
|
2760
|
-
const folder = external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'),
|
|
3645
|
+
const storybookScripts = (rootFolder, family = 'react')=>{
|
|
3646
|
+
const folder = external_node_path_default().posix.join(rootFolder.replaceAll('\\', '/'), `presentation/${family}`);
|
|
2761
3647
|
const quote = (value)=>JSON.stringify(value);
|
|
2762
3648
|
return {
|
|
2763
3649
|
storybook: `storybook dev -p 6006 -c ${quote(`${folder}/.storybook`)}`,
|
|
2764
3650
|
'build-storybook': `storybook build -c ${quote(`${folder}/.storybook`)} -o ${quote(`${folder}/storybook-static`)}`
|
|
2765
3651
|
};
|
|
2766
3652
|
};
|
|
2767
|
-
const
|
|
3653
|
+
const addSvelteStorybook = async ()=>{
|
|
2768
3654
|
const config = config_file_ConfigFile.Instance.data;
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
requestRequired: true,
|
|
2772
|
-
message: `Configure React scaffolding with ${storybook_storybookFrameworkPackage}?`,
|
|
2773
|
-
default: false
|
|
2774
|
-
})) return [];
|
|
3655
|
+
const svelte = config.frontend?.svelte ?? {};
|
|
3656
|
+
const frameworkPackage = svelteStorybookPackages['sveltekit' === svelte.framework ? 'sveltekit' : 'svelte'];
|
|
2775
3657
|
const root = new project_root_ProjectRoot().path;
|
|
2776
3658
|
const manifestFile = new file_system_File(external_node_path_default().join(root, 'package.json'));
|
|
2777
3659
|
const manifest = JSON.parse(manifestFile.data);
|
|
2778
|
-
const selected = await addPackageScripts(manifestFile, storybookScripts(config.project.rootFolder));
|
|
3660
|
+
const selected = await addPackageScripts(manifestFile, storybookScripts(config.project.rootFolder, 'svelte'));
|
|
2779
3661
|
const folder = new file_system_Folder(root).subitem([
|
|
2780
3662
|
config.project.rootFolder,
|
|
2781
3663
|
'presentation',
|
|
2782
|
-
'
|
|
3664
|
+
'svelte',
|
|
2783
3665
|
'.storybook'
|
|
2784
3666
|
]);
|
|
2785
|
-
for (const [name, content] of Object.entries(
|
|
3667
|
+
for (const [name, content] of Object.entries(svelteStorybookFiles(external_node_path_default().relative(folder.path, root).split(external_node_path_default().sep).join('/'), frameworkPackage))){
|
|
2786
3668
|
const file = new file_system_File(external_node_path_default().join(folder.path, name));
|
|
2787
3669
|
if (!file.exists || file.data !== content) file.data = content;
|
|
2788
3670
|
}
|
|
2789
|
-
if (
|
|
3671
|
+
if (svelte.storybookFramework !== frameworkPackage) config_file_ConfigFile.update({
|
|
2790
3672
|
frontend: {
|
|
2791
3673
|
...config.frontend,
|
|
2792
|
-
|
|
2793
|
-
...
|
|
2794
|
-
storybookFramework:
|
|
3674
|
+
svelte: {
|
|
3675
|
+
...svelte,
|
|
3676
|
+
storybookFramework: frameworkPackage
|
|
2795
3677
|
}
|
|
2796
3678
|
}
|
|
2797
3679
|
});
|
|
2798
|
-
const buildFolder = external_node_path_default().posix.join(config.project.rootFolder.replaceAll('\\', '/'), 'presentation/
|
|
3680
|
+
const buildFolder = external_node_path_default().posix.join(config.project.rootFolder.replaceAll('\\', '/'), 'presentation/svelte/storybook-static');
|
|
2799
3681
|
addGitignoreEntry(root, `/${buildFolder}/`);
|
|
2800
3682
|
const dependencies = {
|
|
2801
3683
|
...manifest.dependencies,
|
|
@@ -2803,20 +3685,24 @@ const storybook_addStorybook = async ()=>{
|
|
|
2803
3685
|
};
|
|
2804
3686
|
const missing = [
|
|
2805
3687
|
'storybook',
|
|
2806
|
-
|
|
3688
|
+
frameworkPackage,
|
|
2807
3689
|
'vite',
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
'react',
|
|
2812
|
-
'react-dom'
|
|
3690
|
+
...frameworkPackage === svelteStorybookPackages.svelte ? [
|
|
3691
|
+
'@sveltejs/vite-plugin-svelte'
|
|
3692
|
+
] : []
|
|
2813
3693
|
].filter((name)=>!dependencies[name]);
|
|
3694
|
+
const missingSvelte = ('sveltekit' === svelte.framework ? [
|
|
3695
|
+
'@sveltejs/kit',
|
|
3696
|
+
'svelte'
|
|
3697
|
+
] : [
|
|
3698
|
+
'svelte'
|
|
3699
|
+
]).filter((name)=>!dependencies[name]);
|
|
2814
3700
|
return [
|
|
2815
3701
|
...missing.length ? [
|
|
2816
3702
|
`npm install --save-dev ${missing.join(' ')}`
|
|
2817
3703
|
] : [],
|
|
2818
|
-
...
|
|
2819
|
-
`npm install ${
|
|
3704
|
+
...missingSvelte.length ? [
|
|
3705
|
+
`npm install ${missingSvelte.join(' ')}`
|
|
2820
3706
|
] : [],
|
|
2821
3707
|
...describeScripts(selected, {
|
|
2822
3708
|
storybook: 'start Storybook on http://localhost:6006',
|
|
@@ -2824,146 +3710,66 @@ const storybook_addStorybook = async ()=>{
|
|
|
2824
3710
|
})
|
|
2825
3711
|
];
|
|
2826
3712
|
};
|
|
2827
|
-
const
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
const
|
|
2838
|
-
const
|
|
2839
|
-
const
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
});
|
|
2850
|
-
};
|
|
2851
|
-
const toPosix = (value)=>value.split(external_node_path_default().sep).join('/');
|
|
2852
|
-
const readAliases = (projectRoot)=>{
|
|
2853
|
-
const tsconfig = external_node_path_default().join(projectRoot, 'tsconfig.json');
|
|
2854
|
-
if (!external_node_fs_default().existsSync(tsconfig)) return [];
|
|
2855
|
-
try {
|
|
2856
|
-
const { compilerOptions = {} } = JSON.parse(stripJsonComments(external_node_fs_default().readFileSync(tsconfig, 'utf8')));
|
|
2857
|
-
const base = external_node_path_default().resolve(projectRoot, compilerOptions.baseUrl ?? '.');
|
|
2858
|
-
return Object.entries(compilerOptions.paths ?? {}).filter(([pattern, targets])=>pattern.endsWith('*') && targets[0]?.endsWith('*')).map(([pattern, [target]])=>({
|
|
2859
|
-
prefix: pattern.slice(0, -1),
|
|
2860
|
-
target: external_node_path_default().resolve(base, target.slice(0, -1))
|
|
2861
|
-
}));
|
|
2862
|
-
} catch {
|
|
2863
|
-
return [];
|
|
3713
|
+
const storybook_addStorybook = async ()=>{
|
|
3714
|
+
const config = config_file_ConfigFile.Instance.data;
|
|
3715
|
+
if (config.frontend?.svelte) return addSvelteStorybook();
|
|
3716
|
+
if ((!config.frontend?.react || config.frontend?.react?.storybookFramework && config.frontend?.react?.storybookFramework !== storybookFrameworkPackage) && !await interaction_confirm({
|
|
3717
|
+
key: 'configureReact',
|
|
3718
|
+
requestRequired: true,
|
|
3719
|
+
message: `Configure React scaffolding with ${storybookFrameworkPackage}?`,
|
|
3720
|
+
default: false
|
|
3721
|
+
})) return [];
|
|
3722
|
+
const root = new project_root_ProjectRoot().path;
|
|
3723
|
+
const manifestFile = new file_system_File(external_node_path_default().join(root, 'package.json'));
|
|
3724
|
+
const manifest = JSON.parse(manifestFile.data);
|
|
3725
|
+
const selected = await addPackageScripts(manifestFile, storybookScripts(config.project.rootFolder));
|
|
3726
|
+
const folder = new file_system_Folder(root).subitem([
|
|
3727
|
+
config.project.rootFolder,
|
|
3728
|
+
'presentation',
|
|
3729
|
+
'react',
|
|
3730
|
+
'.storybook'
|
|
3731
|
+
]);
|
|
3732
|
+
for (const [name, content] of Object.entries(storybookFiles(external_node_path_default().relative(folder.path, root).split(external_node_path_default().sep).join('/')))){
|
|
3733
|
+
const file = new file_system_File(external_node_path_default().join(folder.path, name));
|
|
3734
|
+
if (!file.exists || file.data !== content) file.data = content;
|
|
2864
3735
|
}
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
withoutExtension,
|
|
2872
|
-
external_node_path_default().dirname(withoutExtension)
|
|
2873
|
-
] : [
|
|
2874
|
-
withoutExtension
|
|
2875
|
-
];
|
|
2876
|
-
};
|
|
2877
|
-
const projectImports = (projectRoot)=>{
|
|
2878
|
-
const aliases = readAliases(projectRoot);
|
|
2879
|
-
const resolve = (specifier, fromFile)=>{
|
|
2880
|
-
if (specifier.startsWith('.')) return {
|
|
2881
|
-
resolved: external_node_path_default().resolve(external_node_path_default().dirname(fromFile), specifier),
|
|
2882
|
-
alias: void 0
|
|
2883
|
-
};
|
|
2884
|
-
const alias = aliases.find(({ prefix })=>specifier.startsWith(prefix));
|
|
2885
|
-
return alias ? {
|
|
2886
|
-
resolved: external_node_path_default().resolve(alias.target, specifier.slice(alias.prefix.length)),
|
|
2887
|
-
alias
|
|
2888
|
-
} : void 0;
|
|
2889
|
-
};
|
|
2890
|
-
const specifierFor = (fromFile, toPath, alias)=>{
|
|
2891
|
-
const aliased = alias && toPosix(external_node_path_default().relative(alias.target, toPath));
|
|
2892
|
-
if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
|
|
2893
|
-
const relative = toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toPath));
|
|
2894
|
-
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
2895
|
-
};
|
|
2896
|
-
const codeFiles = new Map(module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
2897
|
-
file,
|
|
2898
|
-
external_node_fs_default().readFileSync(file, 'utf8')
|
|
2899
|
-
]));
|
|
2900
|
-
const importsOf = (file)=>[
|
|
2901
|
-
...(codeFiles.get(file) ?? '').matchAll(specifierPattern)
|
|
2902
|
-
].map(([, , , specifier])=>resolve(specifier, file)?.resolved).filter((resolved)=>!!resolved);
|
|
2903
|
-
return {
|
|
2904
|
-
resolve,
|
|
2905
|
-
specifierFor,
|
|
2906
|
-
codeFiles,
|
|
2907
|
-
importsOf
|
|
2908
|
-
};
|
|
2909
|
-
};
|
|
2910
|
-
const stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
2911
|
-
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
2912
|
-
const { resolve, specifierFor, codeFiles } = projectImports(projectRoot);
|
|
2913
|
-
const barrels = new Set();
|
|
2914
|
-
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
2915
|
-
for(let found = true; found;){
|
|
2916
|
-
found = false;
|
|
2917
|
-
for (const [file, content] of codeFiles){
|
|
2918
|
-
if (moves.has(file) || isBarrel(file)) continue;
|
|
2919
|
-
const reExportsModule = [
|
|
2920
|
-
...content.matchAll(reExportPattern)
|
|
2921
|
-
].some(([, , specifier])=>{
|
|
2922
|
-
const resolution = resolve(specifier, file);
|
|
2923
|
-
return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
|
|
2924
|
-
});
|
|
2925
|
-
if (reExportsModule) {
|
|
2926
|
-
for (const importPath of importPaths(file))barrels.add(importPath);
|
|
2927
|
-
found = true;
|
|
3736
|
+
if (!config.frontend?.react || config.frontend?.react?.storybookFramework !== storybookFrameworkPackage) config_file_ConfigFile.update({
|
|
3737
|
+
frontend: {
|
|
3738
|
+
...config.frontend,
|
|
3739
|
+
react: {
|
|
3740
|
+
...config.frontend?.react,
|
|
3741
|
+
storybookFramework: storybookFrameworkPackage
|
|
2928
3742
|
}
|
|
2929
3743
|
}
|
|
2930
|
-
}
|
|
2931
|
-
const
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
const moved = movedPath(resolution.resolved);
|
|
2937
|
-
if (moved || isBarrel(resolution.resolved)) referencesModule = true;
|
|
2938
|
-
if (!moved && oldFile === newFile) return match;
|
|
2939
|
-
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
2940
|
-
return `${keyword}${quote}${next}${quote}`;
|
|
2941
|
-
});
|
|
2942
|
-
const changed = everyFile(rewritten);
|
|
2943
|
-
if (!referencesModule && !moves.has(oldFile)) return changed;
|
|
2944
|
-
return rename(changed, {
|
|
2945
|
-
moved: moves.has(oldFile)
|
|
2946
|
-
});
|
|
2947
|
-
};
|
|
2948
|
-
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new file_system_File(file).moveTo(newFile, stopFor(file));
|
|
2949
|
-
const updated = [];
|
|
2950
|
-
for (const [file, content] of codeFiles){
|
|
2951
|
-
const newFile = moves.get(file);
|
|
2952
|
-
const next = rewrite(content, file, newFile ?? file);
|
|
2953
|
-
if (newFile && newFile !== file) {
|
|
2954
|
-
new file_system_File(newFile).data = next;
|
|
2955
|
-
new file_system_File(file).delete(stopFor(file));
|
|
2956
|
-
} else if (next !== content) {
|
|
2957
|
-
new file_system_File(file).update(next);
|
|
2958
|
-
if (!newFile) updated.push(file);
|
|
2959
|
-
}
|
|
2960
|
-
}
|
|
2961
|
-
return {
|
|
2962
|
-
moves: [
|
|
2963
|
-
...moves
|
|
2964
|
-
].filter(([from, to])=>from !== to),
|
|
2965
|
-
updated
|
|
3744
|
+
});
|
|
3745
|
+
const buildFolder = external_node_path_default().posix.join(config.project.rootFolder.replaceAll('\\', '/'), 'presentation/react/storybook-static');
|
|
3746
|
+
addGitignoreEntry(root, `/${buildFolder}/`);
|
|
3747
|
+
const dependencies = {
|
|
3748
|
+
...manifest.dependencies,
|
|
3749
|
+
...manifest.devDependencies
|
|
2966
3750
|
};
|
|
3751
|
+
const missing = [
|
|
3752
|
+
'storybook',
|
|
3753
|
+
storybookFrameworkPackage,
|
|
3754
|
+
'vite',
|
|
3755
|
+
'@vitejs/plugin-react'
|
|
3756
|
+
].filter((name)=>!dependencies[name]);
|
|
3757
|
+
const missingReact = [
|
|
3758
|
+
'react',
|
|
3759
|
+
'react-dom'
|
|
3760
|
+
].filter((name)=>!dependencies[name]);
|
|
3761
|
+
return [
|
|
3762
|
+
...missing.length ? [
|
|
3763
|
+
`npm install --save-dev ${missing.join(' ')}`
|
|
3764
|
+
] : [],
|
|
3765
|
+
...missingReact.length ? [
|
|
3766
|
+
`npm install ${missingReact.join(' ')}`
|
|
3767
|
+
] : [],
|
|
3768
|
+
...describeScripts(selected, {
|
|
3769
|
+
storybook: 'start Storybook on http://localhost:6006',
|
|
3770
|
+
'build-storybook': `build static Storybook into ${buildFolder}`
|
|
3771
|
+
})
|
|
3772
|
+
];
|
|
2967
3773
|
};
|
|
2968
3774
|
const serviceLayout = (layer)=>({
|
|
2969
3775
|
title: `${layer[0].toUpperCase()}${layer.slice(1)} services`,
|
|
@@ -3016,7 +3822,7 @@ const aggregateOwnFiles = (name)=>[
|
|
|
3016
3822
|
`${name}-repository.spec.ts`,
|
|
3017
3823
|
'index.ts'
|
|
3018
3824
|
];
|
|
3019
|
-
const
|
|
3825
|
+
const backend_module_move_kindLayouts = {
|
|
3020
3826
|
aggregate: {
|
|
3021
3827
|
title: 'Aggregates',
|
|
3022
3828
|
core: (ClassName)=>`${ClassName}Repository`,
|
|
@@ -3073,7 +3879,7 @@ const projectRootOf = (folder)=>{
|
|
|
3073
3879
|
}
|
|
3074
3880
|
};
|
|
3075
3881
|
const integrationSpecFile = (unit, label)=>{
|
|
3076
|
-
const layout =
|
|
3882
|
+
const layout = backend_module_move_kindLayouts[unit.kind];
|
|
3077
3883
|
const place = {
|
|
3078
3884
|
ownerPath: unit.ownerPath,
|
|
3079
3885
|
name: unit.name
|
|
@@ -3099,9 +3905,9 @@ const backend_module_move_subfolders = (folder)=>external_node_fs_default().exis
|
|
|
3099
3905
|
}).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name).sort() : [];
|
|
3100
3906
|
const namesBySuffix = (folder, suffix)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder).filter((file)=>file.endsWith(suffix) && !file.endsWith('.spec.ts')).map((file)=>file.slice(0, -suffix.length)).sort() : [];
|
|
3101
3907
|
const labelsOf = (ownerPath, kind, name)=>{
|
|
3102
|
-
const { implementations } =
|
|
3908
|
+
const { implementations } = backend_module_move_kindLayouts[kind];
|
|
3103
3909
|
if (!implementations) return [];
|
|
3104
|
-
return backend_module_move_subfolders(external_node_path_default().join(ownerPath, implementations)).filter((label)=>
|
|
3910
|
+
return backend_module_move_subfolders(external_node_path_default().join(ownerPath, implementations)).filter((label)=>backend_module_move_kindLayouts[kind].files({
|
|
3105
3911
|
ownerPath,
|
|
3106
3912
|
name
|
|
3107
3913
|
}, [
|
|
@@ -3139,7 +3945,7 @@ const findBackendUnits = (ownerPath)=>{
|
|
|
3139
3945
|
const kebabName = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
3140
3946
|
const lowerFirst = (value)=>value[0].toLowerCase() + value.slice(1);
|
|
3141
3947
|
const unitMoves = (unit, target)=>{
|
|
3142
|
-
const layout =
|
|
3948
|
+
const layout = backend_module_move_kindLayouts[unit.kind];
|
|
3143
3949
|
const from = layout.files(unit, unit.labels);
|
|
3144
3950
|
const to = layout.files(target, unit.labels);
|
|
3145
3951
|
const moves = new Map();
|
|
@@ -3166,7 +3972,7 @@ const unitMoves = (unit, target)=>{
|
|
|
3166
3972
|
};
|
|
3167
3973
|
const validateBackendMove = (unit, target, sharedKernelPath)=>{
|
|
3168
3974
|
if (!kebabName.test(target.name)) return 'Use kebab-case: lowercase words split by "-", e.g. place-order';
|
|
3169
|
-
if (target.ownerPath === sharedKernelPath && !
|
|
3975
|
+
if (target.ownerPath === sharedKernelPath && !backend_module_move_kindLayouts[unit.kind].sharedKernel) return `${backend_module_move_kindLayouts[unit.kind].title} are not part of the Shared Kernel`;
|
|
3170
3976
|
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';
|
|
3171
3977
|
for (const [from, to] of unitMoves(unit, target))if (to !== from && external_node_fs_default().existsSync(to)) return `${external_node_path_default().relative(target.ownerPath, to)} already exists`;
|
|
3172
3978
|
return true;
|
|
@@ -3195,7 +4001,7 @@ const isolationAllows = (rootFolderPath, from, to)=>{
|
|
|
3195
4001
|
return inside('domain/errors') || from.replace(codeExtension, '') === inMemoryDbFile(rootFolderPath).replace(codeExtension, '') && inside('domain');
|
|
3196
4002
|
};
|
|
3197
4003
|
const moveBackendUnit = (projectRoot, rootFolderPath, unit, target)=>{
|
|
3198
|
-
const layout =
|
|
4004
|
+
const layout = backend_module_move_kindLayouts[unit.kind];
|
|
3199
4005
|
const moves = unitMoves(unit, target);
|
|
3200
4006
|
const withoutExtension = new Map([
|
|
3201
4007
|
...moves
|
|
@@ -3340,7 +4146,7 @@ const projectRelative = (fromFile, toFile)=>{
|
|
|
3340
4146
|
const relative = toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toFile.replace(codeExtension, '')));
|
|
3341
4147
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
3342
4148
|
};
|
|
3343
|
-
const
|
|
4149
|
+
const backend_module_move_importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
3344
4150
|
const backend_module_move_importLine = /^\s*(?:import|export)\b[^'"\n]*\bfrom\s*(['"])([^'"\n]+)\1;?\s*$/;
|
|
3345
4151
|
const deleteBackendUnit = (projectRoot, rootFolderPath, unit)=>{
|
|
3346
4152
|
const files = [
|
|
@@ -3382,7 +4188,7 @@ const deleteBackendUnit = (projectRoot, rootFolderPath, unit)=>{
|
|
|
3382
4188
|
for (const [file, original] of codeFiles){
|
|
3383
4189
|
if (fileSet.has(file)) continue;
|
|
3384
4190
|
const content = cleaned.get(file) ?? original;
|
|
3385
|
-
for (const [, , specifier] of content.matchAll(
|
|
4191
|
+
for (const [, , specifier] of content.matchAll(backend_module_move_importSpecifier)){
|
|
3386
4192
|
const target = resolved(specifier, file);
|
|
3387
4193
|
if (target && isUnit(target)) usedBy.push([
|
|
3388
4194
|
relative(file),
|
|
@@ -3417,18 +4223,18 @@ const contractKinds = [
|
|
|
3417
4223
|
];
|
|
3418
4224
|
const implementations_withWiring = ()=>config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/wire');
|
|
3419
4225
|
const withHandlers = ()=>config_file_ConfigFile.backend.domainFirstPackages.includes('@domain-first/handlers');
|
|
3420
|
-
const contractFile = (unit)=>'aggregate' === unit.kind ? `domain/aggregates/${unit.name}/${unit.name}-repository.ts` :
|
|
4226
|
+
const contractFile = (unit)=>'aggregate' === unit.kind ? `domain/aggregates/${unit.name}/${unit.name}-repository.ts` : backend_module_move_kindLayouts[unit.kind].files(unit, [])[0];
|
|
3421
4227
|
const findContracts = (ownerPath)=>findBackendUnits(ownerPath).filter((unit)=>contractKinds.includes(unit.kind) && external_node_fs_default().existsSync(external_node_path_default().join(ownerPath, contractFile(unit))));
|
|
3422
4228
|
const implementationWireName = (label)=>`wire${new UnknownFormatNaming(label).ClassName}Implementation`;
|
|
3423
|
-
const contractClassName = (unit)=>
|
|
4229
|
+
const contractClassName = (unit)=>backend_module_move_kindLayouts[unit.kind].core(new UnknownFormatNaming(unit.name).ClassName);
|
|
3424
4230
|
const implementationClassName = (unit, label)=>`${new UnknownFormatNaming(label).ClassName}${contractClassName(unit)}`;
|
|
3425
4231
|
const implementationFile = (unit, label)=>{
|
|
3426
|
-
const { implementations } =
|
|
3427
|
-
return
|
|
4232
|
+
const { implementations } = backend_module_move_kindLayouts[unit.kind];
|
|
4233
|
+
return backend_module_move_kindLayouts[unit.kind].files(unit, [
|
|
3428
4234
|
label
|
|
3429
4235
|
]).find((file)=>file.startsWith(`${implementations}/`));
|
|
3430
4236
|
};
|
|
3431
|
-
const contractWireFile = (unit)=>
|
|
4237
|
+
const contractWireFile = (unit)=>backend_module_move_kindLayouts[unit.kind].files(unit, []).find((file)=>file.startsWith('wiring/'));
|
|
3432
4238
|
const handlerImplementation = (ContractName, ClassName, contractImport)=>withHandlers() ? `
|
|
3433
4239
|
import { defineHandler } from '@domain-first/handlers'
|
|
3434
4240
|
import { ${ContractName} } from '${contractImport}'
|
|
@@ -3594,7 +4400,7 @@ const scaffoldIntegrationSpec = (unit, label)=>{
|
|
|
3594
4400
|
if (!specPath) return;
|
|
3595
4401
|
const spec = new file_system_File(specPath);
|
|
3596
4402
|
if (spec.exists) return;
|
|
3597
|
-
const layout =
|
|
4403
|
+
const layout = backend_module_move_kindLayouts[unit.kind];
|
|
3598
4404
|
const naming = new UnknownFormatNaming(unit.name);
|
|
3599
4405
|
const core = layout.core(naming.ClassName);
|
|
3600
4406
|
const files = layout.files({
|
|
@@ -4109,10 +4915,10 @@ const integrationIds = [
|
|
|
4109
4915
|
const integrations = [
|
|
4110
4916
|
{
|
|
4111
4917
|
id: 'storybook',
|
|
4112
|
-
name:
|
|
4918
|
+
name: storybookTitle,
|
|
4113
4919
|
group: 'frontend',
|
|
4114
4920
|
run: storybook_addStorybook,
|
|
4115
|
-
applied: ()=>createdInRoot(
|
|
4921
|
+
applied: ()=>createdInRoot(`${storybookFolder()}/main.ts`)
|
|
4116
4922
|
},
|
|
4117
4923
|
{
|
|
4118
4924
|
id: 'rest-endpoint-generator',
|
|
@@ -4178,9 +4984,10 @@ const integrations = [
|
|
|
4178
4984
|
group: 'frontend',
|
|
4179
4985
|
run: addOrval,
|
|
4180
4986
|
available: ()=>withHandlersRest(),
|
|
4181
|
-
applied: ()=>createdInRoot('presentation/react/data-layer/orval.config.ts') || createdInRoot('presentation/data-layer/orval.config.ts')
|
|
4987
|
+
applied: ()=>createdInRoot('presentation/react/data-layer/orval.config.ts') || createdInRoot('presentation/svelte/data-layer/orval.config.ts') || createdInRoot('presentation/data-layer/orval.config.ts')
|
|
4182
4988
|
}
|
|
4183
4989
|
];
|
|
4990
|
+
const nameOf = ({ name })=>'string' == typeof name ? name : name();
|
|
4184
4991
|
const addIntegration = async ({ save = true } = {})=>{
|
|
4185
4992
|
const available = integrations.filter(({ group, available })=>('backend' !== group || Boolean(config_file_ConfigFile.Instance.data.backend)) && (available?.() ?? true)).map((value)=>({
|
|
4186
4993
|
value,
|
|
@@ -4194,7 +5001,7 @@ const addIntegration = async ({ save = true } = {})=>{
|
|
|
4194
5001
|
return items.length ? [
|
|
4195
5002
|
new prompts_namespaceObject.Separator(title),
|
|
4196
5003
|
...items.map(({ value })=>({
|
|
4197
|
-
name: `${value
|
|
5004
|
+
name: `${nameOf(value)} · ${value.group}`,
|
|
4198
5005
|
value
|
|
4199
5006
|
}))
|
|
4200
5007
|
] : [];
|
|
@@ -4217,7 +5024,7 @@ const addIntegration = async ({ save = true } = {})=>{
|
|
|
4217
5024
|
};
|
|
4218
5025
|
const integrationDescriptions = ()=>integrations.map((integration)=>({
|
|
4219
5026
|
id: integration.id,
|
|
4220
|
-
name: integration
|
|
5027
|
+
name: nameOf(integration),
|
|
4221
5028
|
group: integration.group,
|
|
4222
5029
|
available: ('backend' !== integration.group || Boolean(config_file_ConfigFile.Instance.data.backend)) && (integration.available?.() ?? true)
|
|
4223
5030
|
}));
|
|
@@ -4325,419 +5132,135 @@ const scaffoldRequestSchema = external_zod_default().discriminatedUnion('operati
|
|
|
4325
5132
|
implementation: agent_requests_implementation,
|
|
4326
5133
|
environments: external_zod_default().array(agent_requests_name).min(1).optional().describe('Required when the contract wire is envBranchedWire; omit it otherwise.'),
|
|
4327
5134
|
...agent_requests_wired
|
|
4328
|
-
}),
|
|
4329
|
-
agent_requests_operation('endpoint', {
|
|
4330
|
-
...common,
|
|
4331
|
-
...agent_requests_owner,
|
|
4332
|
-
controller: agent_requests_name.optional().describe('Omit for the context-root controller (root): `/<context>/<path>`.'),
|
|
4333
|
-
method: external_zod_default()["enum"]([
|
|
4334
|
-
'get',
|
|
4335
|
-
'post',
|
|
4336
|
-
'put',
|
|
4337
|
-
'patch',
|
|
4338
|
-
'delete'
|
|
4339
|
-
]),
|
|
4340
|
-
path: external_zod_default().string().regex(/^(?:\/?(?:[a-zA-Z0-9_-]+|:[a-zA-Z][a-zA-Z0-9_]*))*\/?$/),
|
|
4341
|
-
handler: agent_requests_id.optional().describe('Exact handler module ID from --describe. Required when the context has wired queries, commands or use cases; omit it otherwise.')
|
|
4342
|
-
}),
|
|
4343
|
-
agent_requests_operation('wire-dependency', {
|
|
4344
|
-
...common,
|
|
4345
|
-
...agent_requests_owner,
|
|
4346
|
-
module: agent_requests_id.describe('Exact wiring target ID, including implementation class, from --describe.'),
|
|
4347
|
-
dependencies: agent_requests_dependencies
|
|
4348
|
-
}),
|
|
4349
|
-
agent_requests_operation('delete', {
|
|
4350
|
-
...common,
|
|
4351
|
-
...agent_requests_owner,
|
|
4352
|
-
module: agent_requests_id.describe('Exact unit ID from --describe. Refused while other files use it.')
|
|
4353
|
-
}),
|
|
4354
|
-
agent_requests_operation('move', {
|
|
4355
|
-
...common,
|
|
4356
|
-
...agent_requests_owner,
|
|
4357
|
-
module: agent_requests_id.describe('Exact unit ID from --describe.'),
|
|
4358
|
-
targetContext: agent_requests_nestedName.optional(),
|
|
4359
|
-
name: agent_requests_name.optional(),
|
|
4360
|
-
aggregate: agent_requests_name.optional()
|
|
4361
|
-
})
|
|
4362
|
-
]);
|
|
4363
|
-
const
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
]);
|
|
4424
|
-
const agent_requests_relativePath = external_zod_default().string().regex(/^[a-zA-Z0-9_.-]+(?:\/[a-zA-Z0-9_.-]+)*$/).refine((value)=>!value.split('/').some((part)=>'.' === part || '..' === part), 'Use a project-relative path without . or .. segments.');
|
|
4425
|
-
const integrationRequestSchema = agent_requests_operation('add', {
|
|
4426
|
-
...common,
|
|
4427
|
-
integrations: external_zod_default().array(external_zod_default()["enum"](integrationIds)).min(1),
|
|
4428
|
-
nextAdapter: external_zod_default().boolean().optional(),
|
|
4429
|
-
configureReact: external_zod_default().boolean().optional(),
|
|
4430
|
-
replaceTestingLibrary: external_zod_default().boolean().optional(),
|
|
4431
|
-
integrationTestTypes: external_zod_default().array(agent_requests_name).optional().describe('testcontainers with wire: saved primary implementation types whose implementations get integration specs. Omitted: the configured list stays.'),
|
|
4432
|
-
withService: external_zod_default().boolean().optional(),
|
|
4433
|
-
routePrefix: external_zod_default().string().regex(/^\/?[a-zA-Z0-9_/-]*$/).optional(),
|
|
4434
|
-
openapiPath: agent_requests_relativePath.optional(),
|
|
4435
|
-
withExtractor: external_zod_default().boolean().optional(),
|
|
4436
|
-
swaggerPage: external_zod_default().boolean().optional(),
|
|
4437
|
-
targets: external_zod_default().array(external_zod_default()["enum"]([
|
|
4438
|
-
'hooks',
|
|
4439
|
-
'client'
|
|
4440
|
-
])).min(1).optional(),
|
|
4441
|
-
scriptConflicts: external_zod_default().record(agent_requests_id, external_zod_default()["enum"]([
|
|
4442
|
-
'keep',
|
|
4443
|
-
'replace',
|
|
4444
|
-
'rename'
|
|
4445
|
-
])).optional(),
|
|
4446
|
-
scriptNames: external_zod_default().record(agent_requests_id, external_zod_default().string().regex(/^[a-zA-Z0-9:_-]+$/)).optional()
|
|
4447
|
-
});
|
|
4448
|
-
const requestSchemaFor = (command)=>({
|
|
4449
|
-
'df-scaffold': scaffoldRequestSchema,
|
|
4450
|
-
'df-react': reactRequestSchema,
|
|
4451
|
-
'df-integration': integrationRequestSchema
|
|
4452
|
-
})[command];
|
|
4453
|
-
const reactKindLayouts = {
|
|
4454
|
-
page: {
|
|
4455
|
-
folder: 'pages',
|
|
4456
|
-
nested: true,
|
|
4457
|
-
inFolder: false,
|
|
4458
|
-
ownFile: (fileBase)=>new RegExp(`^${escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
4459
|
-
target: (reactFolder, { folders, fileName })=>external_node_path_default().join(reactFolder, 'pages', ...folders, `${fileName}-page.tsx`),
|
|
4460
|
-
classPrefix: '(use)?',
|
|
4461
|
-
classSuffix: 'Page'
|
|
4462
|
-
},
|
|
4463
|
-
widget: {
|
|
4464
|
-
folder: 'widgets',
|
|
4465
|
-
nested: true,
|
|
4466
|
-
inFolder: true,
|
|
4467
|
-
target: (reactFolder, { folders, folderName })=>external_node_path_default().join(reactFolder, 'widgets', ...folders, folderName),
|
|
4468
|
-
classPrefix: '(use)?',
|
|
4469
|
-
classSuffix: 'Widget|UIModel',
|
|
4470
|
-
storyTitle: (segments)=>[
|
|
4471
|
-
'Widgets',
|
|
4472
|
-
...segments
|
|
4473
|
-
].join('/')
|
|
4474
|
-
},
|
|
4475
|
-
'ui-kit': {
|
|
4476
|
-
folder: 'ui-kit',
|
|
4477
|
-
nested: false,
|
|
4478
|
-
inFolder: true,
|
|
4479
|
-
target: (reactFolder, { fileName })=>external_node_path_default().join(reactFolder, 'ui-kit', fileName),
|
|
4480
|
-
classPrefix: '()',
|
|
4481
|
-
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
4482
|
-
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
4483
|
-
},
|
|
4484
|
-
hook: {
|
|
4485
|
-
folder: 'hooks',
|
|
4486
|
-
nested: false,
|
|
4487
|
-
inFolder: false,
|
|
4488
|
-
ownFile: (fileBase)=>new RegExp(`^use-${escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
4489
|
-
target: (reactFolder, { fileName })=>external_node_path_default().join(reactFolder, 'hooks', `use-${fileName}.ts`),
|
|
4490
|
-
classPrefix: '(use)',
|
|
4491
|
-
classSuffix: '(?![\\w$])'
|
|
4492
|
-
}
|
|
4493
|
-
};
|
|
4494
|
-
const reactKindTitles = {
|
|
4495
|
-
page: [
|
|
4496
|
-
'Page',
|
|
4497
|
-
'pages'
|
|
4498
|
-
],
|
|
4499
|
-
widget: [
|
|
4500
|
-
'Widget',
|
|
4501
|
-
'widgets'
|
|
4502
|
-
],
|
|
4503
|
-
'ui-kit': [
|
|
4504
|
-
'UI-kit component',
|
|
4505
|
-
'UI-kit components'
|
|
4506
|
-
],
|
|
4507
|
-
hook: [
|
|
4508
|
-
'Shared hook',
|
|
4509
|
-
'shared hooks'
|
|
4510
|
-
]
|
|
4511
|
-
};
|
|
4512
|
-
const reactModuleName = (kind, rawName)=>'hook' === kind ? rawName.trim().replace(/^use-/, '') : rawName;
|
|
4513
|
-
const react_module_move_nestedName = (folders, fileBase)=>{
|
|
4514
|
-
const prefix = `${folders.join('-')}-`;
|
|
4515
|
-
const last = folders.length && fileBase.startsWith(prefix) ? fileBase.slice(prefix.length) : fileBase;
|
|
4516
|
-
return [
|
|
4517
|
-
...folders,
|
|
4518
|
-
last
|
|
4519
|
-
].join('/');
|
|
4520
|
-
};
|
|
4521
|
-
const declaredClassName = (filePath, suffix, name)=>{
|
|
4522
|
-
const content = external_node_fs_default().readFileSync(filePath, 'utf8');
|
|
4523
|
-
const declared = content.match(new RegExp(`export\\s+(?:const|function)\\s+(\\w+)${suffix}\\b`))?.[1];
|
|
4524
|
-
return declared ?? new NestedName(name).ClassName;
|
|
4525
|
-
};
|
|
4526
|
-
const findUiKit = (reactFolder)=>{
|
|
4527
|
-
const root = external_node_path_default().join(reactFolder, 'ui-kit');
|
|
4528
|
-
if (!external_node_fs_default().existsSync(root)) return [];
|
|
4529
|
-
return external_node_fs_default().readdirSync(root, {
|
|
4530
|
-
withFileTypes: true
|
|
4531
|
-
}).filter((entry)=>entry.isDirectory() && external_node_fs_default().existsSync(external_node_path_default().join(root, entry.name, `${entry.name}.tsx`))).map(({ name })=>({
|
|
4532
|
-
kind: 'ui-kit',
|
|
4533
|
-
name,
|
|
4534
|
-
path: external_node_path_default().join(root, name),
|
|
4535
|
-
fileBase: name,
|
|
4536
|
-
ClassName: declaredClassName(external_node_path_default().join(root, name, `${name}.tsx`), '', name)
|
|
4537
|
-
}));
|
|
4538
|
-
};
|
|
4539
|
-
const findHooks = (reactFolder)=>{
|
|
4540
|
-
const root = external_node_path_default().join(reactFolder, 'hooks');
|
|
4541
|
-
if (!external_node_fs_default().existsSync(root)) return [];
|
|
4542
|
-
return external_node_fs_default().readdirSync(root).filter((file)=>/^use-.+\.tsx?$/.test(file) && !/\.(spec|test)\./.test(file)).map((file)=>{
|
|
4543
|
-
const name = file.replace(/^use-/, '').replace(/\.tsx?$/, '');
|
|
4544
|
-
const content = external_node_fs_default().readFileSync(external_node_path_default().join(root, file), 'utf8');
|
|
4545
|
-
return {
|
|
4546
|
-
kind: 'hook',
|
|
4547
|
-
name,
|
|
4548
|
-
path: external_node_path_default().join(root, file),
|
|
4549
|
-
fileBase: name,
|
|
4550
|
-
ClassName: content.match(/export\s+(?:const|function)\s+use(\w+)\b/)?.[1] ?? new NestedName(name).ClassName
|
|
4551
|
-
};
|
|
4552
|
-
});
|
|
4553
|
-
};
|
|
4554
|
-
const findReactModules = (reactFolder, kind)=>{
|
|
4555
|
-
const modules = 'ui-kit' === kind ? findUiKit(reactFolder) : 'hook' === kind ? findHooks(reactFolder) : 'page' === kind ? module_move_walk(external_node_path_default().join(reactFolder, 'pages')).filter((file)=>file.endsWith('-page.tsx')).map((file)=>{
|
|
4556
|
-
const folders = external_node_path_default().relative(external_node_path_default().join(reactFolder, 'pages'), external_node_path_default().dirname(file)).split(external_node_path_default().sep).filter((segment)=>!!segment);
|
|
4557
|
-
const fileBase = external_node_path_default().basename(file, '-page.tsx');
|
|
4558
|
-
const name = react_module_move_nestedName(folders, fileBase);
|
|
4559
|
-
return {
|
|
4560
|
-
kind,
|
|
4561
|
-
name,
|
|
4562
|
-
path: file,
|
|
4563
|
-
fileBase,
|
|
4564
|
-
ClassName: declaredClassName(file, 'Page', name)
|
|
4565
|
-
};
|
|
4566
|
-
}) : module_move_walk(external_node_path_default().join(reactFolder, 'widgets')).filter((file)=>file.endsWith('-widget.tsx')).map((file)=>{
|
|
4567
|
-
const folder = external_node_path_default().dirname(file);
|
|
4568
|
-
const name = toPosix(external_node_path_default().relative(external_node_path_default().join(reactFolder, 'widgets'), folder));
|
|
4569
|
-
return {
|
|
4570
|
-
kind,
|
|
4571
|
-
name,
|
|
4572
|
-
path: folder,
|
|
4573
|
-
fileBase: external_node_path_default().basename(file, '-widget.tsx'),
|
|
4574
|
-
ClassName: declaredClassName(file, 'Widget', name)
|
|
4575
|
-
};
|
|
4576
|
-
});
|
|
4577
|
-
return modules.sort((a, b)=>a.name.localeCompare(b.name));
|
|
4578
|
-
};
|
|
4579
|
-
const react_module_move_targetPath = (reactFolder, module, rawName)=>reactKindLayouts[module.kind].target(reactFolder, new NestedName(reactModuleName(module.kind, rawName)));
|
|
4580
|
-
const validateMove = (reactFolder, module, rawName)=>{
|
|
4581
|
-
const nameError = NestedName.validate(rawName);
|
|
4582
|
-
if (true !== nameError) return nameError;
|
|
4583
|
-
if (!reactKindLayouts[module.kind].nested && /[\\/]/.test(rawName)) return 'UI-kit components and shared hooks have no folders: enter a name without "/"';
|
|
4584
|
-
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
4585
|
-
if (target !== module.path && external_node_fs_default().existsSync(target)) return `${external_node_path_default().relative(reactFolder, target)} already exists`;
|
|
4586
|
-
if (target.startsWith(`${module.path}${external_node_path_default().sep}`)) return 'A widget cannot be moved into itself';
|
|
4587
|
-
return true;
|
|
4588
|
-
};
|
|
4589
|
-
const react_module_move_routeFolder = (appFolder, rawName)=>{
|
|
4590
|
-
const { folders, folderName } = new NestedName(rawName);
|
|
4591
|
-
return external_node_path_default().join(appFolder, ...folders, folderName);
|
|
4592
|
-
};
|
|
4593
|
-
const routeFiles = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
|
|
4594
|
-
withFileTypes: true
|
|
4595
|
-
}).filter((entry)=>entry.isFile()).map((entry)=>external_node_path_default().join(folder, entry.name)) : [];
|
|
4596
|
-
const moveReactModule = (projectRoot, reactFolder, module, rawName, route)=>{
|
|
4597
|
-
const layout = reactKindLayouts[module.kind];
|
|
4598
|
-
const newName = new NestedName(reactModuleName(module.kind, rawName));
|
|
4599
|
-
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
4600
|
-
const newClassName = newName.ClassName;
|
|
4601
|
-
const renameFile = (name)=>name.replace(new RegExp(`^(use-)?${escapeRegExp(module.fileBase)}(?=[-.]|$)`), (_, use = '')=>`${use}${newName.fileName}`);
|
|
4602
|
-
const oldFolder = layout.inFolder ? module.path : external_node_path_default().dirname(module.path);
|
|
4603
|
-
const newFolder = layout.inFolder ? target : external_node_path_default().dirname(target);
|
|
4604
|
-
const ownsPath = (candidate)=>layout.inFolder ? candidate === oldFolder || candidate.startsWith(`${oldFolder}${external_node_path_default().sep}`) : external_node_path_default().dirname(candidate) === oldFolder && layout.ownFile(module.fileBase).test(external_node_path_default().basename(candidate));
|
|
4605
|
-
const routeFileSet = new Set(route ? routeFiles(route.from) : []);
|
|
4606
|
-
const routeTarget = (candidate)=>{
|
|
4607
|
-
if (!route) return;
|
|
4608
|
-
const file = [
|
|
4609
|
-
...routeFileSet
|
|
4610
|
-
].find((x)=>x === candidate || x.replace(codeExtension, '') === candidate);
|
|
4611
|
-
if (!file) return;
|
|
4612
|
-
const moved = external_node_path_default().join(route.to, external_node_path_default().relative(route.from, file));
|
|
4613
|
-
return file === candidate ? moved : moved.replace(codeExtension, '');
|
|
4614
|
-
};
|
|
4615
|
-
const movedPath = (candidate)=>{
|
|
4616
|
-
const routed = routeTarget(candidate);
|
|
4617
|
-
if (routed) return routed;
|
|
4618
|
-
if (!ownsPath(candidate)) return;
|
|
4619
|
-
const segments = external_node_path_default().relative(oldFolder, candidate).split(external_node_path_default().sep);
|
|
4620
|
-
const last = segments.length - 1;
|
|
4621
|
-
segments[last] = renameFile(segments[last]);
|
|
4622
|
-
return external_node_path_default().join(newFolder, ...segments);
|
|
4623
|
-
};
|
|
4624
|
-
const moduleFiles = reactModuleFiles(module);
|
|
4625
|
-
const moves = new Map([
|
|
4626
|
-
...moduleFiles,
|
|
4627
|
-
...routeFileSet
|
|
4628
|
-
].map((file)=>[
|
|
4629
|
-
file,
|
|
4630
|
-
movedPath(file) ?? file
|
|
4631
|
-
]));
|
|
4632
|
-
const classPattern = new RegExp(`(?<![\\w$])${layout.classPrefix}${escapeRegExp(module.ClassName)}(?=${layout.classSuffix})`, 'g');
|
|
4633
|
-
const oldTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
4634
|
-
module.ClassName
|
|
4635
|
-
] : module.name.split('/').map((segment)=>new NestedName(segment).ClassName));
|
|
4636
|
-
const titlePattern = oldTitle && new RegExp(`(['"\`])${escapeRegExp(oldTitle)}\\1`, 'g');
|
|
4637
|
-
const newTitle = layout.storyTitle?.('ui-kit' === module.kind ? [
|
|
4638
|
-
newClassName
|
|
4639
|
-
] : newName.classNameSegments);
|
|
4640
|
-
return stageModuleMove({
|
|
4641
|
-
projectRoot,
|
|
4642
|
-
stopAt: reactFolder,
|
|
4643
|
-
stopAtFor: (file)=>route && routeFileSet.has(file) ? route.appFolder : void 0,
|
|
4644
|
-
moves,
|
|
4645
|
-
movedPath,
|
|
4646
|
-
rename: (content, { moved })=>{
|
|
4647
|
-
const renamed = content.replace(classPattern, (_, use)=>`${use ?? ''}${newClassName}`);
|
|
4648
|
-
return moved && titlePattern ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
4649
|
-
}
|
|
4650
|
-
});
|
|
4651
|
-
};
|
|
4652
|
-
const pageRouteFolder = (appFolder, page)=>{
|
|
4653
|
-
const folder = react_module_move_routeFolder(appFolder, page.name);
|
|
4654
|
-
const routePage = external_node_path_default().join(folder, 'page.tsx');
|
|
4655
|
-
return external_node_fs_default().existsSync(routePage) && new RegExp(`(?<![\\w$])${page.ClassName}Page(?![\\w$])`).test(external_node_fs_default().readFileSync(routePage, 'utf8')) ? folder : void 0;
|
|
4656
|
-
};
|
|
4657
|
-
const reactModuleFiles = (module)=>{
|
|
4658
|
-
const layout = reactKindLayouts[module.kind];
|
|
4659
|
-
if (layout.inFolder) return module_move_walk(module.path);
|
|
4660
|
-
const folder = external_node_path_default().dirname(module.path);
|
|
4661
|
-
const own = layout.ownFile(module.fileBase);
|
|
4662
|
-
return external_node_fs_default().readdirSync(folder, {
|
|
4663
|
-
withFileTypes: true
|
|
4664
|
-
}).filter((entry)=>entry.isFile() && own.test(entry.name)).map((entry)=>external_node_path_default().join(folder, entry.name));
|
|
4665
|
-
};
|
|
4666
|
-
const react_module_move_importSpecifier = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)(['"])([^'"\n]+)\1/g;
|
|
4667
|
-
const deleteReactModule = (projectRoot, reactFolder, module, route)=>{
|
|
4668
|
-
const moduleFiles = reactModuleFiles(module);
|
|
4669
|
-
const routeFileList = route ? routeFiles(route.folder) : [];
|
|
4670
|
-
const own = new Set([
|
|
4671
|
-
...moduleFiles,
|
|
4672
|
-
...routeFileList
|
|
5135
|
+
}),
|
|
5136
|
+
agent_requests_operation('endpoint', {
|
|
5137
|
+
...common,
|
|
5138
|
+
...agent_requests_owner,
|
|
5139
|
+
controller: agent_requests_name.optional().describe('Omit for the context-root controller (root): `/<context>/<path>`.'),
|
|
5140
|
+
method: external_zod_default()["enum"]([
|
|
5141
|
+
'get',
|
|
5142
|
+
'post',
|
|
5143
|
+
'put',
|
|
5144
|
+
'patch',
|
|
5145
|
+
'delete'
|
|
5146
|
+
]),
|
|
5147
|
+
path: external_zod_default().string().regex(/^(?:\/?(?:[a-zA-Z0-9_-]+|:[a-zA-Z][a-zA-Z0-9_]*))*\/?$/),
|
|
5148
|
+
handler: agent_requests_id.optional().describe('Exact handler module ID from --describe. Required when the context has wired queries, commands or use cases; omit it otherwise.')
|
|
5149
|
+
}),
|
|
5150
|
+
agent_requests_operation('wire-dependency', {
|
|
5151
|
+
...common,
|
|
5152
|
+
...agent_requests_owner,
|
|
5153
|
+
module: agent_requests_id.describe('Exact wiring target ID, including implementation class, from --describe.'),
|
|
5154
|
+
dependencies: agent_requests_dependencies
|
|
5155
|
+
}),
|
|
5156
|
+
agent_requests_operation('delete', {
|
|
5157
|
+
...common,
|
|
5158
|
+
...agent_requests_owner,
|
|
5159
|
+
module: agent_requests_id.describe('Exact unit ID from --describe. Refused while other files use it.')
|
|
5160
|
+
}),
|
|
5161
|
+
agent_requests_operation('move', {
|
|
5162
|
+
...common,
|
|
5163
|
+
...agent_requests_owner,
|
|
5164
|
+
module: agent_requests_id.describe('Exact unit ID from --describe.'),
|
|
5165
|
+
targetContext: agent_requests_nestedName.optional(),
|
|
5166
|
+
name: agent_requests_name.optional(),
|
|
5167
|
+
aggregate: agent_requests_name.optional()
|
|
5168
|
+
})
|
|
5169
|
+
]);
|
|
5170
|
+
const frontendRequestSchema = (router, shared)=>external_zod_default().discriminatedUnion('operation', [
|
|
5171
|
+
agent_requests_operation('page', {
|
|
5172
|
+
...common,
|
|
5173
|
+
name: agent_requests_nestedName
|
|
5174
|
+
}),
|
|
5175
|
+
agent_requests_operation('widget', {
|
|
5176
|
+
...common,
|
|
5177
|
+
name: agent_requests_nestedName,
|
|
5178
|
+
widgetType: external_zod_default()["enum"]([
|
|
5179
|
+
'monolithic',
|
|
5180
|
+
'separated',
|
|
5181
|
+
'headless'
|
|
5182
|
+
]).optional()
|
|
5183
|
+
}),
|
|
5184
|
+
agent_requests_operation('ui-kit-component', {
|
|
5185
|
+
...common,
|
|
5186
|
+
name: agent_requests_name
|
|
5187
|
+
}),
|
|
5188
|
+
agent_requests_operation(shared, {
|
|
5189
|
+
...common,
|
|
5190
|
+
name: agent_requests_name
|
|
5191
|
+
}),
|
|
5192
|
+
agent_requests_operation('move-page', {
|
|
5193
|
+
...common,
|
|
5194
|
+
module: agent_requests_nestedName,
|
|
5195
|
+
name: agent_requests_nestedName,
|
|
5196
|
+
moveRoute: external_zod_default().boolean().optional().describe(`With ${router} and a route at the page path: move it too (default true). Omit it without such a route.`)
|
|
5197
|
+
}),
|
|
5198
|
+
agent_requests_operation('delete-page', {
|
|
5199
|
+
...common,
|
|
5200
|
+
module: agent_requests_nestedName,
|
|
5201
|
+
deleteRoute: external_zod_default().boolean().optional().describe(`With ${router} and the page's own route: delete it too (default true). Omit it without such a route.`)
|
|
5202
|
+
}),
|
|
5203
|
+
agent_requests_operation('delete-widget', {
|
|
5204
|
+
...common,
|
|
5205
|
+
module: agent_requests_nestedName
|
|
5206
|
+
}),
|
|
5207
|
+
agent_requests_operation('move-ui-kit-component', {
|
|
5208
|
+
...common,
|
|
5209
|
+
module: agent_requests_name,
|
|
5210
|
+
name: agent_requests_name
|
|
5211
|
+
}),
|
|
5212
|
+
agent_requests_operation(`move-${shared}`, {
|
|
5213
|
+
...common,
|
|
5214
|
+
module: agent_requests_name,
|
|
5215
|
+
name: agent_requests_name
|
|
5216
|
+
}),
|
|
5217
|
+
agent_requests_operation('delete-ui-kit-component', {
|
|
5218
|
+
...common,
|
|
5219
|
+
module: agent_requests_name
|
|
5220
|
+
}),
|
|
5221
|
+
agent_requests_operation(`delete-${shared}`, {
|
|
5222
|
+
...common,
|
|
5223
|
+
module: agent_requests_name
|
|
5224
|
+
}),
|
|
5225
|
+
agent_requests_operation('move-widget', {
|
|
5226
|
+
...common,
|
|
5227
|
+
module: agent_requests_nestedName,
|
|
5228
|
+
name: agent_requests_nestedName
|
|
5229
|
+
})
|
|
4673
5230
|
]);
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
const
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
].map((method)=>`${method.toUpperCase()}.ts`));
|
|
4708
|
-
const rest_layout_entries = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
|
|
4709
|
-
withFileTypes: true
|
|
4710
|
-
}) : [];
|
|
4711
|
-
const rest_layout_subfolders = (folder)=>rest_layout_entries(folder).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name);
|
|
4712
|
-
const restFolders = (boundedContextFolder)=>({
|
|
4713
|
-
presentation: external_node_path_default().join(boundedContextFolder, 'presentation', 'rest'),
|
|
4714
|
-
wiring: external_node_path_default().join(boundedContextFolder, 'wiring', 'presentation', 'rest')
|
|
4715
|
-
});
|
|
4716
|
-
const restControllers = (boundedContextFolder)=>rest_layout_subfolders(restFolders(boundedContextFolder).presentation).filter((name)=>name !== rootControllerFolder && !isPathParameterName(name));
|
|
4717
|
-
const rootStaticSegments = (boundedContextFolder)=>rest_layout_subfolders(external_node_path_default().join(restFolders(boundedContextFolder).presentation, rootControllerFolder)).filter((name)=>!isPathParameterName(name));
|
|
4718
|
-
const legacyRootEndpoints = (boundedContextFolder)=>{
|
|
4719
|
-
const { presentation, wiring } = restFolders(boundedContextFolder);
|
|
4720
|
-
return {
|
|
4721
|
-
endpointFiles: rest_layout_entries(presentation).filter((entry)=>entry.isFile() && endpointFileNames.has(entry.name)).map((entry)=>external_node_path_default().join(presentation, entry.name)),
|
|
4722
|
-
parameterFolders: rest_layout_subfolders(presentation).filter(isPathParameterName).map((name)=>external_node_path_default().join(presentation, name)),
|
|
4723
|
-
wireFiles: rest_layout_entries(wiring).filter((entry)=>entry.isFile() && 'index.ts' !== entry.name && /\.ts$/.test(entry.name)).map((entry)=>external_node_path_default().join(wiring, entry.name))
|
|
4724
|
-
};
|
|
4725
|
-
};
|
|
4726
|
-
const hasLegacyRootEndpoints = (boundedContextFolder)=>Object.values(legacyRootEndpoints(boundedContextFolder)).some((paths)=>paths.length > 0);
|
|
4727
|
-
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
4728
|
-
if ('ports' === kind) return crossContext ? [
|
|
4729
|
-
{
|
|
4730
|
-
name: 'System: cross-context (calls handlers in another bounded context)',
|
|
4731
|
-
value: crossContextImplementation
|
|
4732
|
-
}
|
|
4733
|
-
] : [];
|
|
4734
|
-
return config_file_ConfigFile.exists && usesInMemoryDb('in-memory') ? [
|
|
4735
|
-
{
|
|
4736
|
-
name: 'System: in-memory (uses the shared in-memory database)',
|
|
4737
|
-
value: 'in-memory'
|
|
4738
|
-
}
|
|
4739
|
-
] : [];
|
|
4740
|
-
};
|
|
5231
|
+
const reactRequestSchema = frontendRequestSchema('Next.js', 'shared-hook');
|
|
5232
|
+
const svelteRequestSchema = frontendRequestSchema('SvelteKit', 'shared-model');
|
|
5233
|
+
const agent_requests_relativePath = external_zod_default().string().regex(/^[a-zA-Z0-9_.-]+(?:\/[a-zA-Z0-9_.-]+)*$/).refine((value)=>!value.split('/').some((part)=>'.' === part || '..' === part), 'Use a project-relative path without . or .. segments.');
|
|
5234
|
+
const integrationRequestSchema = agent_requests_operation('add', {
|
|
5235
|
+
...common,
|
|
5236
|
+
integrations: external_zod_default().array(external_zod_default()["enum"](integrationIds)).min(1),
|
|
5237
|
+
nextAdapter: external_zod_default().boolean().optional(),
|
|
5238
|
+
svelteAdapter: external_zod_default().boolean().optional(),
|
|
5239
|
+
configureReact: external_zod_default().boolean().optional(),
|
|
5240
|
+
replaceTestingLibrary: external_zod_default().boolean().optional(),
|
|
5241
|
+
integrationTestTypes: external_zod_default().array(agent_requests_name).optional().describe('testcontainers with wire: saved primary implementation types whose implementations get integration specs. Omitted: the configured list stays.'),
|
|
5242
|
+
withService: external_zod_default().boolean().optional(),
|
|
5243
|
+
routePrefix: external_zod_default().string().regex(/^\/?[a-zA-Z0-9_/-]*$/).optional(),
|
|
5244
|
+
openapiPath: agent_requests_relativePath.optional(),
|
|
5245
|
+
withExtractor: external_zod_default().boolean().optional(),
|
|
5246
|
+
swaggerPage: external_zod_default().boolean().optional(),
|
|
5247
|
+
targets: external_zod_default().array(external_zod_default()["enum"]([
|
|
5248
|
+
'hooks',
|
|
5249
|
+
'client'
|
|
5250
|
+
])).min(1).optional(),
|
|
5251
|
+
scriptConflicts: external_zod_default().record(agent_requests_id, external_zod_default()["enum"]([
|
|
5252
|
+
'keep',
|
|
5253
|
+
'replace',
|
|
5254
|
+
'rename'
|
|
5255
|
+
])).optional(),
|
|
5256
|
+
scriptNames: external_zod_default().record(agent_requests_id, external_zod_default().string().regex(/^[a-zA-Z0-9:_-]+$/)).optional()
|
|
5257
|
+
});
|
|
5258
|
+
const requestSchemaFor = (command)=>({
|
|
5259
|
+
'df-scaffold': scaffoldRequestSchema,
|
|
5260
|
+
'df-react': reactRequestSchema,
|
|
5261
|
+
'df-svelte': svelteRequestSchema,
|
|
5262
|
+
'df-integration': integrationRequestSchema
|
|
5263
|
+
})[command];
|
|
4741
5264
|
const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
4742
5265
|
const root = new project_root_ProjectRoot().path;
|
|
4743
5266
|
const rootFolderPath = external_node_path_default().join(root, config_file_ConfigFile.Instance.data.project.rootFolder);
|
|
@@ -4747,10 +5270,10 @@ const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
4747
5270
|
key: 'module',
|
|
4748
5271
|
id: unitId,
|
|
4749
5272
|
message: 'Module to delete:',
|
|
4750
|
-
choices: Object.keys(
|
|
5273
|
+
choices: Object.keys(backend_module_move_kindLayouts).flatMap((kind)=>{
|
|
4751
5274
|
const group = units.filter((x)=>x.kind === kind);
|
|
4752
5275
|
return group.length ? [
|
|
4753
|
-
new prompts_namespaceObject.Separator(`── ${
|
|
5276
|
+
new prompts_namespaceObject.Separator(`── ${backend_module_move_kindLayouts[group[0].kind].title}`),
|
|
4754
5277
|
...group.map((value)=>({
|
|
4755
5278
|
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
4756
5279
|
value
|
|
@@ -4789,14 +5312,36 @@ const deleteBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
4789
5312
|
report('Cancelled: nothing was deleted.');
|
|
4790
5313
|
}
|
|
4791
5314
|
};
|
|
4792
|
-
const
|
|
5315
|
+
const pageRouter = (framework)=>{
|
|
5316
|
+
if ('react' === framework) return usesNext() ? {
|
|
5317
|
+
title: 'Next.js',
|
|
5318
|
+
folder: nextAppFolder,
|
|
5319
|
+
pageFile: routePageFile.react
|
|
5320
|
+
} : void 0;
|
|
5321
|
+
return usesSvelteKit() ? {
|
|
5322
|
+
title: 'SvelteKit',
|
|
5323
|
+
folder: svelteKitRoutesFolder,
|
|
5324
|
+
pageFile: routePageFile.svelte
|
|
5325
|
+
} : void 0;
|
|
5326
|
+
};
|
|
5327
|
+
const frameworkTitles = {
|
|
5328
|
+
react: {
|
|
5329
|
+
title: 'React',
|
|
5330
|
+
cli: 'df-react'
|
|
5331
|
+
},
|
|
5332
|
+
svelte: {
|
|
5333
|
+
title: 'Svelte',
|
|
5334
|
+
cli: 'df-svelte'
|
|
5335
|
+
}
|
|
5336
|
+
};
|
|
5337
|
+
const deleteReactModuleUseCase = async (presentationReactFolder, kind, framework = 'react')=>{
|
|
4793
5338
|
const reactFolder = presentationReactFolder.path;
|
|
4794
|
-
const modules = findReactModules(reactFolder, kind);
|
|
4795
|
-
if (!modules.length) return void report(`No ${
|
|
5339
|
+
const modules = findReactModules(reactFolder, kind, framework);
|
|
5340
|
+
if (!modules.length) return void report(`No ${frontendKindTitles(framework)[kind][1]} generated by ${frameworkTitles[framework].cli} were found.`);
|
|
4796
5341
|
const module = await interaction_select({
|
|
4797
5342
|
key: 'module',
|
|
4798
5343
|
id: (value)=>value.name,
|
|
4799
|
-
message: `${
|
|
5344
|
+
message: `${frontendKindTitles(framework)[kind][0]} to delete:`,
|
|
4800
5345
|
choices: modules.map((value)=>({
|
|
4801
5346
|
name: value.name,
|
|
4802
5347
|
value,
|
|
@@ -4805,17 +5350,18 @@ const deleteReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
4805
5350
|
});
|
|
4806
5351
|
const root = new project_root_ProjectRoot().path;
|
|
4807
5352
|
const relative = (file)=>external_node_path_default().relative(root, file).split(external_node_path_default().sep).join('/');
|
|
4808
|
-
const
|
|
4809
|
-
const
|
|
5353
|
+
const router = 'page' === kind ? pageRouter(framework) : void 0;
|
|
5354
|
+
const appFolder = router && external_node_path_default().join(root, router.folder(root));
|
|
5355
|
+
const routeFolder = router && appFolder ? pageRouteFolder(appFolder, module, framework) : void 0;
|
|
4810
5356
|
const withRoute = !!routeFolder && await interaction_confirm({
|
|
4811
5357
|
key: 'deleteRoute',
|
|
4812
|
-
message: `Delete its
|
|
5358
|
+
message: `Delete its ${router?.title} route too: ${relative(routeFolder)}? Its URL stops working.`,
|
|
4813
5359
|
default: true
|
|
4814
5360
|
});
|
|
4815
|
-
const result = deleteReactModule(root, reactFolder, module, withRoute && routeFolder ? {
|
|
5361
|
+
const result = deleteReactModule(root, reactFolder, module, withRoute && routeFolder && appFolder ? {
|
|
4816
5362
|
appFolder,
|
|
4817
5363
|
folder: routeFolder
|
|
4818
|
-
} : void 0);
|
|
5364
|
+
} : void 0, framework);
|
|
4819
5365
|
if (result.usedBy) {
|
|
4820
5366
|
if (isNonInteractive()) throw new RequestError('DELETE_NOT_ALLOWED', `Other files still use the ${kind}.`, {
|
|
4821
5367
|
usedBy: result.usedBy
|
|
@@ -4853,10 +5399,10 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
4853
5399
|
key: 'module',
|
|
4854
5400
|
id: unitId,
|
|
4855
5401
|
message: 'Module:',
|
|
4856
|
-
choices: Object.keys(
|
|
5402
|
+
choices: Object.keys(backend_module_move_kindLayouts).flatMap((kind)=>{
|
|
4857
5403
|
const group = units.filter((x)=>x.kind === kind);
|
|
4858
5404
|
return group.length ? [
|
|
4859
|
-
new prompts_namespaceObject.Separator(`── ${
|
|
5405
|
+
new prompts_namespaceObject.Separator(`── ${backend_module_move_kindLayouts[group[0].kind].title}`),
|
|
4860
5406
|
...group.map((value)=>({
|
|
4861
5407
|
name: value.aggregate ? `${value.name} (${value.aggregate})` : value.name,
|
|
4862
5408
|
value
|
|
@@ -4870,7 +5416,7 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
4870
5416
|
const places = [
|
|
4871
5417
|
unit.ownerPath,
|
|
4872
5418
|
...contexts,
|
|
4873
|
-
...
|
|
5419
|
+
...backend_module_move_kindLayouts[unit.kind].sharedKernel ? [
|
|
4874
5420
|
sharedKernelPath
|
|
4875
5421
|
] : []
|
|
4876
5422
|
].filter((place, index, all)=>all.indexOf(place) === index);
|
|
@@ -4938,17 +5484,18 @@ const moveBackendUnitUseCase = async (ownerFolder)=>{
|
|
|
4938
5484
|
report('Cancelled: nothing was written.');
|
|
4939
5485
|
}
|
|
4940
5486
|
};
|
|
4941
|
-
const promptRouteMove = async (root, page, newName)=>{
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
const
|
|
5487
|
+
const promptRouteMove = async (root, page, newName, framework)=>{
|
|
5488
|
+
const router = pageRouter(framework);
|
|
5489
|
+
if (!router) return;
|
|
5490
|
+
const appFolder = external_node_path_default().join(root, router.folder(root));
|
|
5491
|
+
const from = pageRouteFolder(appFolder, page, framework);
|
|
4945
5492
|
const to = react_module_move_routeFolder(appFolder, newName);
|
|
4946
5493
|
const relative = (file)=>external_node_path_default().relative(root, file).split(external_node_path_default().sep).join('/');
|
|
4947
5494
|
if (!from || from === to) return;
|
|
4948
|
-
if (external_node_fs_default().existsSync(external_node_path_default().join(to,
|
|
5495
|
+
if (external_node_fs_default().existsSync(external_node_path_default().join(to, router.pageFile))) return void report(`${relative(to)}/${router.pageFile} already exists: the route ${relative(from)} stays.`);
|
|
4949
5496
|
const move = await interaction_confirm({
|
|
4950
5497
|
key: 'moveRoute',
|
|
4951
|
-
message: `Move the
|
|
5498
|
+
message: `Move the ${router.title} route too: ${relative(from)} → ${relative(to)}? Its URL changes.`,
|
|
4952
5499
|
default: true
|
|
4953
5500
|
});
|
|
4954
5501
|
return move ? {
|
|
@@ -4957,14 +5504,14 @@ const promptRouteMove = async (root, page, newName)=>{
|
|
|
4957
5504
|
to
|
|
4958
5505
|
} : void 0;
|
|
4959
5506
|
};
|
|
4960
|
-
const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
5507
|
+
const moveReactModuleUseCase = async (presentationReactFolder, kind, framework = 'react')=>{
|
|
4961
5508
|
const reactFolder = presentationReactFolder.path;
|
|
4962
|
-
const modules = findReactModules(reactFolder, kind);
|
|
4963
|
-
if (!modules.length) return void report(`No ${
|
|
5509
|
+
const modules = findReactModules(reactFolder, kind, framework);
|
|
5510
|
+
if (!modules.length) return void report(`No ${frontendKindTitles(framework)[kind][1]} generated by ${frameworkTitles[framework].cli} were found.`);
|
|
4964
5511
|
const module = await interaction_select({
|
|
4965
5512
|
key: 'module',
|
|
4966
5513
|
id: (value)=>value.name,
|
|
4967
|
-
message: `${
|
|
5514
|
+
message: `${frontendKindTitles(framework)[kind][0]}:`,
|
|
4968
5515
|
choices: modules.map((value)=>({
|
|
4969
5516
|
name: value.name,
|
|
4970
5517
|
value,
|
|
@@ -4973,14 +5520,14 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
4973
5520
|
});
|
|
4974
5521
|
const name = await interaction_input({
|
|
4975
5522
|
key: 'name',
|
|
4976
|
-
message:
|
|
5523
|
+
message: frontendKindLayouts(framework)[kind].nested ? 'New name (folders split by "/"):' : 'New name:',
|
|
4977
5524
|
default: module.name,
|
|
4978
|
-
validate: (value)=>validateMove(reactFolder, module, value)
|
|
5525
|
+
validate: (value)=>validateMove(reactFolder, module, value, framework)
|
|
4979
5526
|
});
|
|
4980
5527
|
const root = new project_root_ProjectRoot().path;
|
|
4981
5528
|
const relative = (file)=>external_node_path_default().relative(root, file).split(external_node_path_default().sep).join('/');
|
|
4982
|
-
const route = 'page' === kind ? await promptRouteMove(root, module, name) : void 0;
|
|
4983
|
-
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route);
|
|
5529
|
+
const route = 'page' === kind ? await promptRouteMove(root, module, name, framework) : void 0;
|
|
5530
|
+
const { moves, updated } = moveReactModule(root, reactFolder, module, name, route, framework);
|
|
4984
5531
|
if (!moves.length && !updated.length) return void report('Nothing to change.');
|
|
4985
5532
|
report([
|
|
4986
5533
|
'Files to move:',
|
|
@@ -4999,6 +5546,20 @@ const moveReactModuleUseCase = async (presentationReactFolder, kind)=>{
|
|
|
4999
5546
|
report('Cancelled: nothing was written.');
|
|
5000
5547
|
}
|
|
5001
5548
|
};
|
|
5549
|
+
const systemImplementationChoices = (kind, crossContext = false)=>{
|
|
5550
|
+
if ('ports' === kind) return crossContext ? [
|
|
5551
|
+
{
|
|
5552
|
+
name: 'System: cross-context (calls handlers in another bounded context)',
|
|
5553
|
+
value: crossContextImplementation
|
|
5554
|
+
}
|
|
5555
|
+
] : [];
|
|
5556
|
+
return config_file_ConfigFile.exists && usesInMemoryDb('in-memory') ? [
|
|
5557
|
+
{
|
|
5558
|
+
name: 'System: in-memory (uses the shared in-memory database)',
|
|
5559
|
+
value: 'in-memory'
|
|
5560
|
+
}
|
|
5561
|
+
] : [];
|
|
5562
|
+
};
|
|
5002
5563
|
const enterImplementationTypeOnce = Symbol('enter-implementation-type-once');
|
|
5003
5564
|
const implementationTypeEntryChoices = [
|
|
5004
5565
|
{
|
|
@@ -5591,6 +6152,35 @@ export const ${names.namespace(ClassName)} = errorNamespace('${contextName}').su
|
|
|
5591
6152
|
const namespaceFile = currentErrorFolder.file(`${namespace}.ts`);
|
|
5592
6153
|
namespaceFile.addLineIfMissing(errorClass(names.error(`${namespaceNaming.ClassName}${ClassName}`), exportedNamespace(namespaceFile, names.namespace(namespaceNaming.ClassName)), fileName), '\n\n');
|
|
5593
6154
|
};
|
|
6155
|
+
const rootControllerFolder = '(root)';
|
|
6156
|
+
const pathParameterAsName = (segment)=>segment.startsWith(':') ? `_${segment.slice(1)}_` : segment;
|
|
6157
|
+
const isPathParameterName = (name)=>name.startsWith(':') || /^_.+_$/.test(name);
|
|
6158
|
+
const endpointFileNames = new Set([
|
|
6159
|
+
'get',
|
|
6160
|
+
'post',
|
|
6161
|
+
'put',
|
|
6162
|
+
'patch',
|
|
6163
|
+
'delete'
|
|
6164
|
+
].map((method)=>`${method.toUpperCase()}.ts`));
|
|
6165
|
+
const rest_layout_entries = (folder)=>external_node_fs_default().existsSync(folder) ? external_node_fs_default().readdirSync(folder, {
|
|
6166
|
+
withFileTypes: true
|
|
6167
|
+
}) : [];
|
|
6168
|
+
const rest_layout_subfolders = (folder)=>rest_layout_entries(folder).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name);
|
|
6169
|
+
const restFolders = (boundedContextFolder)=>({
|
|
6170
|
+
presentation: external_node_path_default().join(boundedContextFolder, 'presentation', 'rest'),
|
|
6171
|
+
wiring: external_node_path_default().join(boundedContextFolder, 'wiring', 'presentation', 'rest')
|
|
6172
|
+
});
|
|
6173
|
+
const restControllers = (boundedContextFolder)=>rest_layout_subfolders(restFolders(boundedContextFolder).presentation).filter((name)=>name !== rootControllerFolder && !isPathParameterName(name));
|
|
6174
|
+
const rootStaticSegments = (boundedContextFolder)=>rest_layout_subfolders(external_node_path_default().join(restFolders(boundedContextFolder).presentation, rootControllerFolder)).filter((name)=>!isPathParameterName(name));
|
|
6175
|
+
const legacyRootEndpoints = (boundedContextFolder)=>{
|
|
6176
|
+
const { presentation, wiring } = restFolders(boundedContextFolder);
|
|
6177
|
+
return {
|
|
6178
|
+
endpointFiles: rest_layout_entries(presentation).filter((entry)=>entry.isFile() && endpointFileNames.has(entry.name)).map((entry)=>external_node_path_default().join(presentation, entry.name)),
|
|
6179
|
+
parameterFolders: rest_layout_subfolders(presentation).filter(isPathParameterName).map((name)=>external_node_path_default().join(presentation, name)),
|
|
6180
|
+
wireFiles: rest_layout_entries(wiring).filter((entry)=>entry.isFile() && 'index.ts' !== entry.name && /\.ts$/.test(entry.name)).map((entry)=>external_node_path_default().join(wiring, entry.name))
|
|
6181
|
+
};
|
|
6182
|
+
};
|
|
6183
|
+
const hasLegacyRootEndpoints = (boundedContextFolder)=>Object.values(legacyRootEndpoints(boundedContextFolder)).some((paths)=>paths.length > 0);
|
|
5594
6184
|
const newController = 'New controller';
|
|
5595
6185
|
const rootControllerChoice = 'No controller (context root)';
|
|
5596
6186
|
const sourceFolder = ()=>new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
@@ -6275,6 +6865,94 @@ export const use${ClassName}UIModel = (widgetProps: Omit<${ClassName}WidgetProps
|
|
|
6275
6865
|
break;
|
|
6276
6866
|
}
|
|
6277
6867
|
};
|
|
6868
|
+
const sharedLogicOperation = {
|
|
6869
|
+
react: 'shared-hook',
|
|
6870
|
+
svelte: 'shared-model'
|
|
6871
|
+
};
|
|
6872
|
+
const frontendOperations = (folder, framework)=>{
|
|
6873
|
+
const shared = sharedLogicOperation[framework];
|
|
6874
|
+
const scaffold = 'svelte' === framework ? {
|
|
6875
|
+
page: scaffoldSveltePage,
|
|
6876
|
+
widget: scaffoldSvelteWidget,
|
|
6877
|
+
'ui-kit-component': scaffoldSvelteUIKitComponent,
|
|
6878
|
+
shared: scaffoldSvelteSharedModel
|
|
6879
|
+
} : {
|
|
6880
|
+
page: scaffoldReactPage,
|
|
6881
|
+
widget: scaffoldReactWidget,
|
|
6882
|
+
'ui-kit-component': scaffoldReactUIKitComponent,
|
|
6883
|
+
shared: scaffoldReactSharedHook
|
|
6884
|
+
};
|
|
6885
|
+
const move = (kind)=>()=>moveReactModuleUseCase(folder, kind, framework);
|
|
6886
|
+
const remove = (kind)=>()=>deleteReactModuleUseCase(folder, kind, framework);
|
|
6887
|
+
return {
|
|
6888
|
+
page: ()=>scaffold.page(folder),
|
|
6889
|
+
widget: ()=>scaffold.widget(folder),
|
|
6890
|
+
'ui-kit-component': ()=>scaffold['ui-kit-component'](folder),
|
|
6891
|
+
[shared]: ()=>scaffold.shared(folder),
|
|
6892
|
+
'move-page': move('page'),
|
|
6893
|
+
'move-widget': move('widget'),
|
|
6894
|
+
'move-ui-kit-component': move('ui-kit'),
|
|
6895
|
+
[`move-${shared}`]: move('hook'),
|
|
6896
|
+
'delete-page': remove('page'),
|
|
6897
|
+
'delete-widget': remove('widget'),
|
|
6898
|
+
'delete-ui-kit-component': remove('ui-kit'),
|
|
6899
|
+
[`delete-${shared}`]: remove('hook')
|
|
6900
|
+
};
|
|
6901
|
+
};
|
|
6902
|
+
const frontendMenu = (framework)=>{
|
|
6903
|
+
const shared = sharedLogicOperation[framework];
|
|
6904
|
+
const title = 'svelte' === framework ? 'shared model' : 'shared hook';
|
|
6905
|
+
return [
|
|
6906
|
+
[
|
|
6907
|
+
'New widget',
|
|
6908
|
+
'widget'
|
|
6909
|
+
],
|
|
6910
|
+
[
|
|
6911
|
+
'New page',
|
|
6912
|
+
'page'
|
|
6913
|
+
],
|
|
6914
|
+
[
|
|
6915
|
+
'New UI-kit component',
|
|
6916
|
+
'ui-kit-component'
|
|
6917
|
+
],
|
|
6918
|
+
[
|
|
6919
|
+
`New ${title}`,
|
|
6920
|
+
shared
|
|
6921
|
+
],
|
|
6922
|
+
[
|
|
6923
|
+
'Move or rename widget',
|
|
6924
|
+
'move-widget'
|
|
6925
|
+
],
|
|
6926
|
+
[
|
|
6927
|
+
'Move or rename page',
|
|
6928
|
+
'move-page'
|
|
6929
|
+
],
|
|
6930
|
+
[
|
|
6931
|
+
'Move or rename UI-kit component',
|
|
6932
|
+
'move-ui-kit-component'
|
|
6933
|
+
],
|
|
6934
|
+
[
|
|
6935
|
+
`Move or rename ${title}`,
|
|
6936
|
+
`move-${shared}`
|
|
6937
|
+
],
|
|
6938
|
+
[
|
|
6939
|
+
'Delete widget',
|
|
6940
|
+
'delete-widget'
|
|
6941
|
+
],
|
|
6942
|
+
[
|
|
6943
|
+
'Delete page',
|
|
6944
|
+
'delete-page'
|
|
6945
|
+
],
|
|
6946
|
+
[
|
|
6947
|
+
'Delete UI-kit component',
|
|
6948
|
+
'delete-ui-kit-component'
|
|
6949
|
+
],
|
|
6950
|
+
[
|
|
6951
|
+
`Delete ${title}`,
|
|
6952
|
+
`delete-${shared}`
|
|
6953
|
+
]
|
|
6954
|
+
];
|
|
6955
|
+
};
|
|
6278
6956
|
const requireProject = ()=>{
|
|
6279
6957
|
try {
|
|
6280
6958
|
return new project_root_ProjectRoot().path;
|
|
@@ -6311,12 +6989,24 @@ const ownerFor = (context)=>{
|
|
|
6311
6989
|
});
|
|
6312
6990
|
return owner.folder;
|
|
6313
6991
|
};
|
|
6992
|
+
const frontendFrameworkOf = (command)=>'df-react' === command ? 'react' : 'df-svelte' === command ? 'svelte' : void 0;
|
|
6993
|
+
const frontendModules = (root, rootFolder, framework)=>[
|
|
6994
|
+
'page',
|
|
6995
|
+
'widget',
|
|
6996
|
+
'ui-kit',
|
|
6997
|
+
'hook'
|
|
6998
|
+
].flatMap((kind)=>findReactModules(external_node_path_default().join(root, rootFolder, 'presentation', framework), kind, framework).map((module)=>({
|
|
6999
|
+
kind: 'svelte' === framework && 'hook' === kind ? 'model' : kind,
|
|
7000
|
+
name: module.name,
|
|
7001
|
+
file: external_node_path_default().relative(root, module.path).split(external_node_path_default().sep).join('/')
|
|
7002
|
+
})));
|
|
6314
7003
|
const precondition = (command)=>{
|
|
6315
7004
|
requireProject();
|
|
6316
7005
|
if (!config_file_ConfigFile.exists) throw new RequestError('CONFIG_NOT_FOUND', 'Ask the project owner to run df-init.');
|
|
6317
7006
|
if (config_file_ConfigFile.outdated) throw new RequestError('CONFIG_OUTDATED', 'The config has the format of an earlier major version: ask the project owner to run df-upgrade.');
|
|
6318
7007
|
if ('df-scaffold' === command && !config_file_ConfigFile.Instance.data.backend) throw new RequestError('BACKEND_NOT_CONFIGURED', 'Ask the project owner to run df-init --section backend.');
|
|
6319
|
-
|
|
7008
|
+
const framework = frontendFrameworkOf(command);
|
|
7009
|
+
if (framework && !config_file_ConfigFile.Instance.data.frontend?.[framework]) throw new RequestError('FRONTEND_NOT_CONFIGURED', 'Ask the project owner to run df-init --section frontend.');
|
|
6320
7010
|
};
|
|
6321
7011
|
const describeAgentCommand = (command)=>{
|
|
6322
7012
|
let root;
|
|
@@ -6385,16 +7075,8 @@ const describeAgentCommand = (command)=>{
|
|
|
6385
7075
|
])) : void 0
|
|
6386
7076
|
})),
|
|
6387
7077
|
integrations: integrationDescriptionsSafe(configured),
|
|
6388
|
-
reactModules: config?.frontend?.react ? [
|
|
6389
|
-
|
|
6390
|
-
'widget',
|
|
6391
|
-
'ui-kit',
|
|
6392
|
-
'hook'
|
|
6393
|
-
].flatMap((kind)=>findReactModules(external_node_path_default().join(root, config.project.rootFolder, 'presentation/react'), kind).map((module)=>({
|
|
6394
|
-
kind,
|
|
6395
|
-
name: module.name,
|
|
6396
|
-
file: relative(module.path)
|
|
6397
|
-
}))) : []
|
|
7078
|
+
reactModules: config?.frontend?.react ? frontendModules(root, config.project.rootFolder, 'react') : [],
|
|
7079
|
+
svelteModules: config?.frontend?.svelte ? frontendModules(root, config.project.rootFolder, 'svelte') : []
|
|
6398
7080
|
} : null
|
|
6399
7081
|
};
|
|
6400
7082
|
};
|
|
@@ -6496,29 +7178,16 @@ const executeScaffold = async (request, owner)=>{
|
|
|
6496
7178
|
};
|
|
6497
7179
|
return actions[request.operation]();
|
|
6498
7180
|
};
|
|
6499
|
-
const
|
|
7181
|
+
const executeFrontend = async (request, framework)=>{
|
|
6500
7182
|
const folder = new file_system_Folder(requireProject()).subitem([
|
|
6501
7183
|
config_file_ConfigFile.Instance.data.project.rootFolder,
|
|
6502
|
-
'presentation
|
|
7184
|
+
'presentation',
|
|
7185
|
+
framework
|
|
6503
7186
|
]);
|
|
6504
|
-
const kindOf = (operation)=>operation.endsWith('-page') ? 'page' : operation.endsWith('-widget') ? 'widget' : operation.endsWith('-ui-kit-component') ? 'ui-kit' :
|
|
7187
|
+
const kindOf = (operation)=>operation.endsWith('-page') ? 'page' : operation.endsWith('-widget') ? 'widget' : operation.endsWith('-ui-kit-component') ? 'ui-kit' : /-shared-(hook|model)$/.test(operation) ? 'hook' : void 0;
|
|
6505
7188
|
const kind = /^(move|delete)-/.test(request.operation) ? kindOf(request.operation) : void 0;
|
|
6506
|
-
if (kind && !findReactModules(folder.path, kind).length) throw new RequestError('TARGET_NOT_FOUND', `No
|
|
6507
|
-
|
|
6508
|
-
page: ()=>scaffoldReactPage(folder),
|
|
6509
|
-
widget: ()=>scaffoldReactWidget(folder),
|
|
6510
|
-
'ui-kit-component': ()=>scaffoldReactUIKitComponent(folder),
|
|
6511
|
-
'shared-hook': ()=>scaffoldReactSharedHook(folder),
|
|
6512
|
-
'move-page': ()=>moveReactModuleUseCase(folder, 'page'),
|
|
6513
|
-
'move-widget': ()=>moveReactModuleUseCase(folder, 'widget'),
|
|
6514
|
-
'delete-page': ()=>deleteReactModuleUseCase(folder, 'page'),
|
|
6515
|
-
'delete-widget': ()=>deleteReactModuleUseCase(folder, 'widget'),
|
|
6516
|
-
'move-ui-kit-component': ()=>moveReactModuleUseCase(folder, 'ui-kit'),
|
|
6517
|
-
'move-shared-hook': ()=>moveReactModuleUseCase(folder, 'hook'),
|
|
6518
|
-
'delete-ui-kit-component': ()=>deleteReactModuleUseCase(folder, 'ui-kit'),
|
|
6519
|
-
'delete-shared-hook': ()=>deleteReactModuleUseCase(folder, 'hook')
|
|
6520
|
-
};
|
|
6521
|
-
return actions[request.operation]();
|
|
7189
|
+
if (kind && !findReactModules(folder.path, kind, framework).length) throw new RequestError('TARGET_NOT_FOUND', `No ${frameworkTitles[framework].title} ${frontendKindTitles(framework)[kind][1]} here.`);
|
|
7190
|
+
return frontendOperations(folder, framework)[request.operation]();
|
|
6522
7191
|
};
|
|
6523
7192
|
const executeAgentRequest = async (command, value)=>{
|
|
6524
7193
|
discardPendingChanges();
|
|
@@ -6539,7 +7208,7 @@ const executeAgentRequest = async (command, value)=>{
|
|
|
6539
7208
|
let nextSteps = [];
|
|
6540
7209
|
if ('df-scaffold' === command) if ('bounded-context' === request.operation) await scaffoldNewBoundedContextUseCase();
|
|
6541
7210
|
else await executeScaffold(request, owner);
|
|
6542
|
-
else if (
|
|
7211
|
+
else if (frontendFrameworkOf(command)) await executeFrontend(request, frontendFrameworkOf(command));
|
|
6543
7212
|
else nextSteps = await addIntegration({
|
|
6544
7213
|
save: false
|
|
6545
7214
|
});
|
|
@@ -6624,103 +7293,80 @@ const runCLI = async (command, interactive)=>{
|
|
|
6624
7293
|
process.exitCode = 1;
|
|
6625
7294
|
}
|
|
6626
7295
|
};
|
|
6627
|
-
|
|
6628
|
-
|
|
7296
|
+
const texts = {
|
|
7297
|
+
react: {
|
|
7298
|
+
command: 'df-react',
|
|
7299
|
+
help: `Usage: df-react
|
|
6629
7300
|
|
|
6630
7301
|
Scaffolds React modules of a Domain-First project: pages, widgets, UI-kit
|
|
6631
7302
|
components and shared hooks, and moves or renames pages and widgets.
|
|
6632
|
-
Needs frontend.react in domain-first.project-structure.config.json
|
|
7303
|
+
Needs frontend.react in domain-first.project-structure.config.json.`,
|
|
7304
|
+
notConfigured: 'React is not configured: run df-init --section frontend or add Storybook with df-integration.'
|
|
7305
|
+
},
|
|
7306
|
+
svelte: {
|
|
7307
|
+
command: 'df-svelte',
|
|
7308
|
+
help: `Usage: df-svelte
|
|
7309
|
+
|
|
7310
|
+
Scaffolds Svelte 5 modules of a Domain-First project: pages, widgets, UI-kit
|
|
7311
|
+
components and shared models (create… in .svelte.ts), and moves, renames or deletes
|
|
7312
|
+
them. With SvelteKit, pages get their routes in src/routes.
|
|
7313
|
+
Needs frontend.svelte in domain-first.project-structure.config.json.`,
|
|
7314
|
+
notConfigured: 'Svelte is not configured: run df-init --section frontend.'
|
|
7315
|
+
}
|
|
7316
|
+
};
|
|
7317
|
+
const runFrontendCLI = (framework)=>{
|
|
7318
|
+
const { command, help, notConfigured } = texts[framework];
|
|
7319
|
+
return runCLI(command, async ()=>{
|
|
7320
|
+
const { values } = (0, external_node_util_namespaceObject.parseArgs)({
|
|
7321
|
+
options: {
|
|
7322
|
+
help: {
|
|
7323
|
+
type: 'boolean',
|
|
7324
|
+
short: 'h',
|
|
7325
|
+
default: false
|
|
7326
|
+
}
|
|
7327
|
+
}
|
|
7328
|
+
});
|
|
7329
|
+
if (values.help) {
|
|
7330
|
+
console.log(`${help}
|
|
6633
7331
|
|
|
6634
7332
|
Options:
|
|
6635
7333
|
--request <json|-> execute an operation without prompts; - reads stdin
|
|
6636
7334
|
--describe output request schema and project IDs as JSON
|
|
6637
|
-
-h, --help show this help
|
|
6638
|
-
|
|
6639
|
-
options: {
|
|
6640
|
-
help: {
|
|
6641
|
-
type: 'boolean',
|
|
6642
|
-
short: 'h',
|
|
6643
|
-
default: false
|
|
6644
|
-
}
|
|
7335
|
+
-h, --help show this help`);
|
|
7336
|
+
process.exit(0);
|
|
6645
7337
|
}
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
if (!config_file_ConfigFile.Instance.data.frontend?.react) {
|
|
6660
|
-
console.log('React is not configured: run df-init --section frontend or add Storybook with df-integration.');
|
|
6661
|
-
process.exit(1);
|
|
6662
|
-
}
|
|
6663
|
-
const main = async ()=>{
|
|
6664
|
-
const reactFolder = new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
7338
|
+
if (!config_file_ConfigFile.exists) {
|
|
7339
|
+
console.log('No domain-first.project-structure.config.json found: run df-init first to initialize the project.');
|
|
7340
|
+
process.exit(1);
|
|
7341
|
+
}
|
|
7342
|
+
if (config_file_ConfigFile.outdated) {
|
|
7343
|
+
console.log(outdatedConfigMessage);
|
|
7344
|
+
process.exit(1);
|
|
7345
|
+
}
|
|
7346
|
+
if (!config_file_ConfigFile.Instance.data.frontend?.[framework]) {
|
|
7347
|
+
console.log(notConfigured);
|
|
7348
|
+
process.exit(1);
|
|
7349
|
+
}
|
|
7350
|
+
const folder = new file_system_Folder(new project_root_ProjectRoot().path).subitem([
|
|
6665
7351
|
config_file_ConfigFile.Instance.data.project.rootFolder,
|
|
6666
7352
|
'presentation',
|
|
6667
|
-
|
|
7353
|
+
framework
|
|
6668
7354
|
]);
|
|
6669
|
-
const
|
|
7355
|
+
const operation = await (0, prompts_namespaceObject.select)({
|
|
6670
7356
|
message: 'Module: ',
|
|
6671
|
-
choices: [
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
'New shared hook',
|
|
6676
|
-
'Move or rename widget',
|
|
6677
|
-
'Move or rename page',
|
|
6678
|
-
'Move or rename UI-kit component',
|
|
6679
|
-
'Move or rename shared hook',
|
|
6680
|
-
'Delete widget',
|
|
6681
|
-
'Delete page',
|
|
6682
|
-
'Delete UI-kit component',
|
|
6683
|
-
'Delete shared hook'
|
|
6684
|
-
]
|
|
7357
|
+
choices: frontendMenu(framework).map(([name, value])=>({
|
|
7358
|
+
name,
|
|
7359
|
+
value
|
|
7360
|
+
}))
|
|
6685
7361
|
});
|
|
6686
|
-
|
|
6687
|
-
case 'New widget':
|
|
6688
|
-
return void await scaffoldReactWidget(reactFolder);
|
|
6689
|
-
case 'New page':
|
|
6690
|
-
return void await scaffoldReactPage(reactFolder);
|
|
6691
|
-
case 'New UI-kit component':
|
|
6692
|
-
return void await scaffoldReactUIKitComponent(reactFolder);
|
|
6693
|
-
case 'New shared hook':
|
|
6694
|
-
return void await scaffoldReactSharedHook(reactFolder);
|
|
6695
|
-
case 'Move or rename widget':
|
|
6696
|
-
return void await moveReactModuleUseCase(reactFolder, 'widget');
|
|
6697
|
-
case 'Move or rename page':
|
|
6698
|
-
return void await moveReactModuleUseCase(reactFolder, 'page');
|
|
6699
|
-
case 'Delete widget':
|
|
6700
|
-
return void await deleteReactModuleUseCase(reactFolder, 'widget');
|
|
6701
|
-
case 'Delete page':
|
|
6702
|
-
return void await deleteReactModuleUseCase(reactFolder, 'page');
|
|
6703
|
-
case 'Move or rename UI-kit component':
|
|
6704
|
-
return void await moveReactModuleUseCase(reactFolder, 'ui-kit');
|
|
6705
|
-
case 'Move or rename shared hook':
|
|
6706
|
-
return void await moveReactModuleUseCase(reactFolder, 'hook');
|
|
6707
|
-
case 'Delete UI-kit component':
|
|
6708
|
-
return void await deleteReactModuleUseCase(reactFolder, 'ui-kit');
|
|
6709
|
-
case 'Delete shared hook':
|
|
6710
|
-
return void await deleteReactModuleUseCase(reactFolder, 'hook');
|
|
6711
|
-
default:
|
|
6712
|
-
return;
|
|
6713
|
-
}
|
|
6714
|
-
};
|
|
6715
|
-
const run = async ()=>{
|
|
6716
|
-
await main();
|
|
7362
|
+
await frontendOperations(folder, framework)[operation]();
|
|
6717
7363
|
await savePendingChanges();
|
|
6718
|
-
}
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
7364
|
+
}).catch((error)=>{
|
|
7365
|
+
console.error(error);
|
|
7366
|
+
process.exitCode = 1;
|
|
7367
|
+
});
|
|
7368
|
+
};
|
|
7369
|
+
runFrontendCLI('react');
|
|
6724
7370
|
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
6725
7371
|
Object.defineProperty(exports, '__esModule', {
|
|
6726
7372
|
value: true
|