@domain-first/project-structure 8.11.0 → 8.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/287.js +36 -967
- package/dist/364.js +3 -3
- package/dist/38.js +4 -3
- package/dist/561.js +76 -67
- package/dist/783.js +1115 -0
- package/dist/{201.js → 878.js} +453 -1
- package/dist/agent-cli.d.ts +5 -5
- package/dist/agent-requests.d.ts +9 -9
- package/dist/frontend-modules.d.ts +6 -1
- package/dist/graph.cjs +113 -4
- package/dist/graph.js +1 -1
- package/dist/index.cjs +105 -81
- package/dist/index.js +1 -1
- package/dist/init.cjs +47 -6
- package/dist/init.js +1 -1
- package/dist/integration.cjs +105 -81
- package/dist/integration.js +1 -1
- package/dist/integrations/openapi.d.ts +13 -3
- package/dist/lint.cjs +119 -9
- package/dist/lint.js +1 -1
- package/dist/react-module-move.d.ts +18 -2
- package/dist/react.cjs +161 -133
- package/dist/svelte.cjs +161 -133
- package/dist/upgrade-svelte.d.ts +22 -0
- package/dist/upgrade-svelte.spec.d.ts +1 -0
- package/dist/upgrade.cjs +381 -41
- package/dist/upgrade.js +219 -13
- package/dist/use-cases/scaffold-svelte-modules.d.ts +3 -2
- package/package.json +1 -1
- package/skills/df-ps-scaffold/SKILL.md +2 -2
- package/skills/df-ps-scaffold/references/agent-operations.md +2 -2
- package/skills/df-ps-svelte/SKILL.md +16 -11
- package/skills/df-ps-svelte/references/generators.md +6 -5
- package/dist/115.js +0 -616
package/dist/upgrade.cjs
CHANGED
|
@@ -491,7 +491,7 @@ const inMemoryDbWithIdStep = {
|
|
|
491
491
|
file.update(/\bhasId\b/.test(fixed.replace(legacyHasId, '')) ? fixed : fixed.replace(legacyHasId, ''));
|
|
492
492
|
}
|
|
493
493
|
};
|
|
494
|
-
const
|
|
494
|
+
const openapi_extractor_openapiExtractorPath = "scripts/extract-open-api-data-from-endpoint.ts";
|
|
495
495
|
const rootFolderSegments = (rootFolder, indent = 20)=>rootFolder.split(/[\\/]/).map((segment)=>segment.trim()).filter((segment)=>!!segment && '.' !== segment).map((segment)=>`'${segment}',\n${' '.repeat(indent)}`).join('');
|
|
496
496
|
const legacyEndpointFileLookup = (rootFolder)=>` // The controller, if any, is the first folder of the path:
|
|
497
497
|
// context-root endpoints live right in presentation/rest.
|
|
@@ -580,7 +580,8 @@ const ignoredFolders = new Set([
|
|
|
580
580
|
'coverage',
|
|
581
581
|
'storybook-static'
|
|
582
582
|
]);
|
|
583
|
-
const
|
|
583
|
+
const module_move_codeExtension = /\.(?:tsx?|mts|cts|jsx?|mjs|cjs|mdx|svelte)$/;
|
|
584
|
+
const module_move_escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
584
585
|
const module_move_walk = (folder)=>{
|
|
585
586
|
if (!external_node_fs_default().existsSync(folder)) return [];
|
|
586
587
|
return external_node_fs_default().readdirSync(folder, {
|
|
@@ -593,7 +594,7 @@ const module_move_walk = (folder)=>{
|
|
|
593
594
|
] : [];
|
|
594
595
|
});
|
|
595
596
|
};
|
|
596
|
-
const
|
|
597
|
+
const module_move_toPosix = (value)=>value.split(external_node_path_default().sep).join('/');
|
|
597
598
|
const readAliases = (projectRoot)=>{
|
|
598
599
|
const tsconfig = external_node_path_default().join(projectRoot, 'tsconfig.json');
|
|
599
600
|
if (!external_node_fs_default().existsSync(tsconfig)) return [];
|
|
@@ -611,7 +612,7 @@ const readAliases = (projectRoot)=>{
|
|
|
611
612
|
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
|
|
612
613
|
const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
|
|
613
614
|
const importPaths = (file)=>{
|
|
614
|
-
const withoutExtension = file.replace(
|
|
615
|
+
const withoutExtension = file.replace(module_move_codeExtension, '');
|
|
615
616
|
return 'index' === external_node_path_default().basename(withoutExtension) ? [
|
|
616
617
|
withoutExtension,
|
|
617
618
|
external_node_path_default().dirname(withoutExtension)
|
|
@@ -619,7 +620,7 @@ const importPaths = (file)=>{
|
|
|
619
620
|
withoutExtension
|
|
620
621
|
];
|
|
621
622
|
};
|
|
622
|
-
const
|
|
623
|
+
const module_move_projectImports = (projectRoot)=>{
|
|
623
624
|
const aliases = readAliases(projectRoot);
|
|
624
625
|
const resolve = (specifier, fromFile)=>{
|
|
625
626
|
if (specifier.startsWith('.')) return {
|
|
@@ -633,12 +634,12 @@ const projectImports = (projectRoot)=>{
|
|
|
633
634
|
} : void 0;
|
|
634
635
|
};
|
|
635
636
|
const specifierFor = (fromFile, toPath, alias)=>{
|
|
636
|
-
const aliased = alias &&
|
|
637
|
+
const aliased = alias && module_move_toPosix(external_node_path_default().relative(alias.target, toPath));
|
|
637
638
|
if (aliased && !aliased.startsWith('..')) return `${alias.prefix}${aliased}`;
|
|
638
|
-
const relative =
|
|
639
|
+
const relative = module_move_toPosix(external_node_path_default().relative(external_node_path_default().dirname(fromFile), toPath));
|
|
639
640
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
640
641
|
};
|
|
641
|
-
const codeFiles = new Map(module_move_walk(projectRoot).filter((file)=>
|
|
642
|
+
const codeFiles = new Map(module_move_walk(projectRoot).filter((file)=>module_move_codeExtension.test(file)).map((file)=>[
|
|
642
643
|
file,
|
|
643
644
|
external_node_fs_default().readFileSync(file, 'utf8')
|
|
644
645
|
]));
|
|
@@ -652,11 +653,11 @@ const projectImports = (projectRoot)=>{
|
|
|
652
653
|
importsOf
|
|
653
654
|
};
|
|
654
655
|
};
|
|
655
|
-
const
|
|
656
|
+
const module_move_stageModuleMove = ({ projectRoot, stopAt, moves, movedPath, rename, everyFile = (content)=>content, stopAtFor })=>{
|
|
656
657
|
const stopFor = (file)=>stopAtFor?.(file) ?? stopAt;
|
|
657
|
-
const { resolve, specifierFor, codeFiles } =
|
|
658
|
+
const { resolve, specifierFor, codeFiles } = module_move_projectImports(projectRoot);
|
|
658
659
|
const barrels = new Set();
|
|
659
|
-
const isBarrel = (resolved)=>barrels.has(resolved.replace(
|
|
660
|
+
const isBarrel = (resolved)=>barrels.has(resolved.replace(module_move_codeExtension, ''));
|
|
660
661
|
for(let found = true; found;){
|
|
661
662
|
found = false;
|
|
662
663
|
for (const [file, content] of codeFiles){
|
|
@@ -747,7 +748,7 @@ const contextFolders = (context)=>{
|
|
|
747
748
|
return bounded_contexts_boundedContextNames(contexts).map((name)=>boundedContextPath(contexts, name));
|
|
748
749
|
};
|
|
749
750
|
const legacyContexts = (context)=>contextFolders(context).filter(hasLegacyRootEndpoints);
|
|
750
|
-
const upgrade_rest_root_relative = (file)=>
|
|
751
|
+
const upgrade_rest_root_relative = (file)=>module_move_toPosix(external_node_path_default().relative(new project_root_ProjectRoot().path, file));
|
|
751
752
|
const intoRoot = (folder, file)=>external_node_path_default().join(folder, "(root)", external_node_path_default().relative(folder, file));
|
|
752
753
|
const rootMoves = (contextFolder)=>{
|
|
753
754
|
const { presentation, wiring } = restFolders(contextFolder);
|
|
@@ -823,10 +824,10 @@ const restRootControllerStep = {
|
|
|
823
824
|
const withoutExtension = new Map([
|
|
824
825
|
...moves
|
|
825
826
|
].map(([from, to])=>[
|
|
826
|
-
from.replace(
|
|
827
|
-
to.replace(
|
|
827
|
+
from.replace(module_move_codeExtension, ''),
|
|
828
|
+
to.replace(module_move_codeExtension, '')
|
|
828
829
|
]));
|
|
829
|
-
|
|
830
|
+
module_move_stageModuleMove({
|
|
830
831
|
projectRoot,
|
|
831
832
|
stopAt: projectRoot,
|
|
832
833
|
stopAtFor: (file)=>contexts.flatMap((folder)=>Object.values(restFolders(folder))).find((folder)=>file.startsWith(`${folder}${external_node_path_default().sep}`)),
|
|
@@ -856,22 +857,22 @@ const restRootControllerStep = {
|
|
|
856
857
|
}
|
|
857
858
|
}
|
|
858
859
|
};
|
|
859
|
-
const
|
|
860
|
+
const upgrade_rest_root_extractorFile = ()=>new file_system_File(external_node_path_default().join(new project_root_ProjectRoot().path, openapi_extractor_openapiExtractorPath));
|
|
860
861
|
const openapiExtractorRootStep = {
|
|
861
862
|
id: 'openapi-extractor-root',
|
|
862
863
|
kind: 'optional',
|
|
863
864
|
title: "Let the OpenAPI extractor find endpoints in presentation/rest/(root)/",
|
|
864
865
|
detect: (context)=>{
|
|
865
866
|
const rootFolder = rootFolderOf(context);
|
|
866
|
-
const file =
|
|
867
|
+
const file = upgrade_rest_root_extractorFile();
|
|
867
868
|
return !!rootFolder && file.exists && file.data.includes(legacyEndpointFileLookup(rootFolder));
|
|
868
869
|
},
|
|
869
870
|
plan: ()=>[
|
|
870
|
-
`${
|
|
871
|
+
`${openapi_extractor_openapiExtractorPath}: the endpoint file is looked up in the controller folder, then in (root)/`
|
|
871
872
|
],
|
|
872
873
|
apply: (context)=>{
|
|
873
874
|
const rootFolder = rootFolderOf(context);
|
|
874
|
-
const file =
|
|
875
|
+
const file = upgrade_rest_root_extractorFile();
|
|
875
876
|
file.update(file.data.replace(legacyEndpointFileLookup(rootFolder), endpointFileLookup(rootFolder)));
|
|
876
877
|
}
|
|
877
878
|
};
|
|
@@ -881,15 +882,15 @@ const openapiExtractorNestedStep = {
|
|
|
881
882
|
title: 'Let the OpenAPI extractor find endpoints of nested bounded contexts',
|
|
882
883
|
detect: (context)=>{
|
|
883
884
|
const rootFolder = rootFolderOf(context);
|
|
884
|
-
const file =
|
|
885
|
+
const file = upgrade_rest_root_extractorFile();
|
|
885
886
|
return !!rootFolder && file.exists && file.data.includes(rootEndpointFileLookup(rootFolder)) && contextFolders(context).some((folder)=>external_node_path_default().relative(external_node_path_default().join(new project_root_ProjectRoot().path, rootFolder, 'bounded-contexts'), folder).includes(external_node_path_default().sep));
|
|
886
887
|
},
|
|
887
888
|
plan: ()=>[
|
|
888
|
-
`${
|
|
889
|
+
`${openapi_extractor_openapiExtractorPath}: the context of an endpoint is looked up by the start of its route, nested contexts included`
|
|
889
890
|
],
|
|
890
891
|
apply: (context)=>{
|
|
891
892
|
const rootFolder = rootFolderOf(context);
|
|
892
|
-
const file =
|
|
893
|
+
const file = upgrade_rest_root_extractorFile();
|
|
893
894
|
file.update(file.data.replace(rootEndpointFileLookup(rootFolder), endpointFileLookup(rootFolder)));
|
|
894
895
|
}
|
|
895
896
|
};
|
|
@@ -899,16 +900,350 @@ const openapiExtractorManualStep = {
|
|
|
899
900
|
title: 'Update the OpenAPI extractor by hand',
|
|
900
901
|
detect: (context)=>{
|
|
901
902
|
const rootFolder = rootFolderOf(context);
|
|
902
|
-
const file =
|
|
903
|
+
const file = upgrade_rest_root_extractorFile();
|
|
903
904
|
if (!rootFolder || !file.exists) return false;
|
|
904
905
|
const data = file.data;
|
|
905
906
|
return !data.includes(endpointFileLookup(rootFolder)) && !data.includes(rootEndpointFileLookup(rootFolder)) && !data.includes(legacyEndpointFileLookup(rootFolder)) && contextFolders(context).some((folder)=>hasLegacyRootEndpoints(folder) || external_node_fs_default().existsSync(external_node_path_default().join(restFolders(folder).presentation, "(root)")));
|
|
906
907
|
},
|
|
907
908
|
plan: ()=>[
|
|
908
|
-
`${
|
|
909
|
+
`${openapi_extractor_openapiExtractorPath} doesn't look up endpoints in presentation/rest/(root)/: compare it with the one npx df-integration scaffolds for openapi`
|
|
909
910
|
]
|
|
910
911
|
};
|
|
912
|
+
const external_node_async_hooks_namespaceObject = require("node:async_hooks");
|
|
913
|
+
new external_node_async_hooks_namespaceObject.AsyncLocalStorage();
|
|
914
|
+
const frontendExtensions = {
|
|
915
|
+
react: {
|
|
916
|
+
component: '.tsx',
|
|
917
|
+
hook: '.ts'
|
|
918
|
+
},
|
|
919
|
+
svelte: {
|
|
920
|
+
component: '.svelte',
|
|
921
|
+
hook: '.svelte.ts'
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
const frontendLogicNaming = {
|
|
925
|
+
react: {
|
|
926
|
+
prefix: 'use',
|
|
927
|
+
shared: [
|
|
928
|
+
'hooks'
|
|
929
|
+
]
|
|
930
|
+
},
|
|
931
|
+
svelte: {
|
|
932
|
+
prefix: 'create',
|
|
933
|
+
shared: [
|
|
934
|
+
'shared',
|
|
935
|
+
'model'
|
|
936
|
+
]
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
const kindLayouts = (framework)=>{
|
|
940
|
+
const { component, hook } = frontendExtensions[framework];
|
|
941
|
+
const { prefix, shared } = frontendLogicNaming[framework];
|
|
942
|
+
return {
|
|
943
|
+
page: {
|
|
944
|
+
folder: 'pages',
|
|
945
|
+
nested: true,
|
|
946
|
+
inFolder: false,
|
|
947
|
+
ownFile: (fileBase)=>new RegExp(`^${module_move_escapeRegExp(fileBase)}-page(?:\\.|$)`),
|
|
948
|
+
target: (reactFolder, { folders, fileName })=>external_node_path_default().join(reactFolder, 'pages', ...folders, `${fileName}-page${component}`),
|
|
949
|
+
classPrefix: `(${prefix})?`,
|
|
950
|
+
classSuffix: 'Page'
|
|
951
|
+
},
|
|
952
|
+
widget: {
|
|
953
|
+
folder: 'widgets',
|
|
954
|
+
nested: true,
|
|
955
|
+
inFolder: true,
|
|
956
|
+
target: (reactFolder, { folders, folderName })=>external_node_path_default().join(reactFolder, 'widgets', ...folders, folderName),
|
|
957
|
+
classPrefix: `(${prefix})?`,
|
|
958
|
+
classSuffix: 'Widget|UIModel',
|
|
959
|
+
storyTitle: (segments)=>[
|
|
960
|
+
'Widgets',
|
|
961
|
+
...segments
|
|
962
|
+
].join('/')
|
|
963
|
+
},
|
|
964
|
+
'ui-kit': {
|
|
965
|
+
folder: 'ui-kit',
|
|
966
|
+
nested: false,
|
|
967
|
+
inFolder: true,
|
|
968
|
+
target: (reactFolder, { fileName })=>external_node_path_default().join(reactFolder, 'ui-kit', fileName),
|
|
969
|
+
classPrefix: '()',
|
|
970
|
+
classSuffix: 'Props(?![\\w$])|(?![\\w$])',
|
|
971
|
+
storyTitle: (segments)=>`UI-kit/${segments.join('')}`
|
|
972
|
+
},
|
|
973
|
+
hook: {
|
|
974
|
+
folder: shared.join('/'),
|
|
975
|
+
nested: false,
|
|
976
|
+
inFolder: false,
|
|
977
|
+
ownFile: (fileBase)=>new RegExp(`^${prefix}-${module_move_escapeRegExp(fileBase)}(?:\\.|$)`),
|
|
978
|
+
target: (reactFolder, { fileName })=>external_node_path_default().join(reactFolder, ...shared, `${prefix}-${fileName}${hook}`),
|
|
979
|
+
classPrefix: `(${prefix})`,
|
|
980
|
+
classSuffix: '(?![\\w$])'
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
};
|
|
984
|
+
kindLayouts('react');
|
|
985
|
+
kindLayouts('svelte');
|
|
986
|
+
const reactKindTitles = {
|
|
987
|
+
page: [
|
|
988
|
+
'Page',
|
|
989
|
+
'pages'
|
|
990
|
+
],
|
|
991
|
+
widget: [
|
|
992
|
+
'Widget',
|
|
993
|
+
'widgets'
|
|
994
|
+
],
|
|
995
|
+
'ui-kit': [
|
|
996
|
+
'UI-kit component',
|
|
997
|
+
'UI-kit components'
|
|
998
|
+
],
|
|
999
|
+
hook: [
|
|
1000
|
+
'Shared hook',
|
|
1001
|
+
'shared hooks'
|
|
1002
|
+
]
|
|
1003
|
+
};
|
|
1004
|
+
({
|
|
1005
|
+
...reactKindTitles,
|
|
1006
|
+
hook: [
|
|
1007
|
+
'Shared model',
|
|
1008
|
+
'shared models'
|
|
1009
|
+
]
|
|
1010
|
+
});
|
|
1011
|
+
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');
|
|
1012
|
+
const specImportOf = (pagePath, outputPath)=>{
|
|
1013
|
+
const specImport = external_node_path_default().posix.relative(external_node_path_default().posix.dirname(pagePath), outputPath);
|
|
1014
|
+
return specImport.startsWith('.') ? specImport : `./${specImport}`;
|
|
1015
|
+
};
|
|
1016
|
+
const svelteKitStaticFolder = 'static/';
|
|
1017
|
+
const svelteKitStaticUrl = (outputPath)=>outputPath.startsWith(svelteKitStaticFolder) ? `/${outputPath.slice(svelteKitStaticFolder.length)}` : void 0;
|
|
1018
|
+
const svelteSwaggerPage = (rootFolder, outputPath, url)=>`
|
|
1019
|
+
<script lang="ts" module>
|
|
1020
|
+
export type SwaggerPageProps = {}
|
|
1021
|
+
</script>
|
|
1022
|
+
|
|
1023
|
+
<script lang="ts">
|
|
1024
|
+
import 'swagger-ui-dist/swagger-ui.css'
|
|
1025
|
+
import type { SwaggerUIBundle as SwaggerUIBundleType } from 'swagger-ui-dist'
|
|
1026
|
+
import { onMount } from 'svelte'${url ? '' : `
|
|
1027
|
+
import spec from '${specImportOf(swaggerPagePath(rootFolder, 'svelte'), outputPath)}'`}
|
|
1028
|
+
|
|
1029
|
+
let props: SwaggerPageProps = $props()
|
|
1030
|
+
let container: HTMLDivElement
|
|
1031
|
+
|
|
1032
|
+
onMount(async () => {
|
|
1033
|
+
// Self-contained bundle: React is bundled inside, no react deps in the project
|
|
1034
|
+
const { default: SwaggerUIBundle } = (await import(
|
|
1035
|
+
// @ts-expect-error -- swagger-ui-dist ships no types for this entry point
|
|
1036
|
+
'swagger-ui-dist/swagger-ui-bundle.js'
|
|
1037
|
+
)) as { default: SwaggerUIBundleType }
|
|
1038
|
+
|
|
1039
|
+
SwaggerUIBundle({ domNode: container, ${url ? `url: '${url}'` : 'spec'}, displayOperationId: true })
|
|
1040
|
+
})
|
|
1041
|
+
</script>
|
|
1042
|
+
|
|
1043
|
+
<div bind:this={container}></div>
|
|
1044
|
+
`.trim();
|
|
911
1045
|
const record = (value)=>'object' != typeof value || null === value || Array.isArray(value) ? {} : value;
|
|
1046
|
+
const svelteOf = ({ config })=>'svelte' in record(config.frontend) ? record(record(config.frontend).svelte) : void 0;
|
|
1047
|
+
const upgrade_svelte_rootFolderOf = ({ config })=>{
|
|
1048
|
+
const rootFolder = record(config.project).rootFolder;
|
|
1049
|
+
return 'string' == typeof rootFolder ? rootFolder : void 0;
|
|
1050
|
+
};
|
|
1051
|
+
const upgrade_svelte_relative = (file)=>module_move_toPosix(external_node_path_default().relative(new project_root_ProjectRoot().path, file));
|
|
1052
|
+
const svelteFolder = (context)=>{
|
|
1053
|
+
const rootFolder = upgrade_svelte_rootFolderOf(context);
|
|
1054
|
+
return svelteOf(context) && rootFolder ? external_node_path_default().join(new project_root_ProjectRoot().path, rootFolder, 'presentation', 'svelte') : void 0;
|
|
1055
|
+
};
|
|
1056
|
+
const legacySwaggerPage = (context)=>{
|
|
1057
|
+
const rootFolder = upgrade_svelte_rootFolderOf(context);
|
|
1058
|
+
if (!svelteOf(context) || !rootFolder) return;
|
|
1059
|
+
const file = new file_system_File(external_node_path_default().join(new project_root_ProjectRoot().path, swaggerPagePath(rootFolder, 'svelte')));
|
|
1060
|
+
return file.exists && /swagger-ui\/dist\/swagger-ui\.css|import\(\s*['"]swagger-ui['"]\s*\)/.test(file.data) ? file : void 0;
|
|
1061
|
+
};
|
|
1062
|
+
const importedSpecPath = (page)=>{
|
|
1063
|
+
const specifier = page.data.match(/import\s+spec\s+from\s+['"]([^'"]+)['"]/)?.[1];
|
|
1064
|
+
return specifier?.startsWith('.') ? upgrade_svelte_relative(external_node_path_default().resolve(external_node_path_default().dirname(page.path), specifier)) : void 0;
|
|
1065
|
+
};
|
|
1066
|
+
const svelteSwaggerPageStep = {
|
|
1067
|
+
id: 'svelte-swagger-ui-dist',
|
|
1068
|
+
kind: 'optional',
|
|
1069
|
+
title: 'Render the Svelte Swagger UI page with swagger-ui-dist',
|
|
1070
|
+
detect: (context)=>{
|
|
1071
|
+
const page = legacySwaggerPage(context);
|
|
1072
|
+
return !!page && !!importedSpecPath(page);
|
|
1073
|
+
},
|
|
1074
|
+
plan: (context)=>{
|
|
1075
|
+
const page = legacySwaggerPage(context);
|
|
1076
|
+
return [
|
|
1077
|
+
`${upgrade_svelte_relative(page.path)}: regenerated on swagger-ui-dist/swagger-ui-bundle.js, which bundles its own React`
|
|
1078
|
+
];
|
|
1079
|
+
},
|
|
1080
|
+
apply: (context)=>{
|
|
1081
|
+
const page = legacySwaggerPage(context);
|
|
1082
|
+
const outputPath = importedSpecPath(page);
|
|
1083
|
+
const sveltekit = svelteOf(context)?.framework === 'sveltekit';
|
|
1084
|
+
page.update(svelteSwaggerPage(upgrade_svelte_rootFolderOf(context), outputPath, sveltekit ? svelteKitStaticUrl(outputPath) : void 0));
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
const svelteSwaggerPackagesStep = {
|
|
1088
|
+
id: 'svelte-swagger-ui-dist-packages',
|
|
1089
|
+
kind: 'manual',
|
|
1090
|
+
title: 'Replace swagger-ui with swagger-ui-dist',
|
|
1091
|
+
detect: (context)=>!!svelteOf(context) && hasDependency('swagger-ui'),
|
|
1092
|
+
plan: ()=>[
|
|
1093
|
+
`npm uninstall swagger-ui${hasDependency('@types/swagger-ui') ? ' @types/swagger-ui' : ''}`,
|
|
1094
|
+
...hasDependency('swagger-ui-dist') ? [] : [
|
|
1095
|
+
'npm install swagger-ui-dist'
|
|
1096
|
+
],
|
|
1097
|
+
...hasDependency('@types/swagger-ui-dist') ? [] : [
|
|
1098
|
+
'npm install --save-dev @types/swagger-ui-dist'
|
|
1099
|
+
]
|
|
1100
|
+
]
|
|
1101
|
+
};
|
|
1102
|
+
const legacyFunctionNames = (file)=>[
|
|
1103
|
+
...external_node_fs_default().readFileSync(file, 'utf8').matchAll(/export\s+(?:const|function)\s+use(\w+)\b/g)
|
|
1104
|
+
].map(([, name])=>[
|
|
1105
|
+
`use${name}`,
|
|
1106
|
+
`create${name}`
|
|
1107
|
+
]);
|
|
1108
|
+
const legacyModels = (context)=>{
|
|
1109
|
+
const folder = svelteFolder(context);
|
|
1110
|
+
if (!folder) return [];
|
|
1111
|
+
const sharedFolder = external_node_path_default().join(folder, 'hooks');
|
|
1112
|
+
if (!external_node_fs_default().existsSync(sharedFolder)) return [];
|
|
1113
|
+
return external_node_fs_default().readdirSync(sharedFolder).map((name)=>external_node_path_default().join(sharedFolder, name)).filter((file)=>/^use-.+\.svelte\.[jt]s$/.test(external_node_path_default().basename(file)) && !/\.(spec|test)\./.test(file)).map((file)=>({
|
|
1114
|
+
from: file,
|
|
1115
|
+
to: external_node_path_default().join(folder, 'shared', 'model', external_node_path_default().basename(file).replace(/^use-/, 'create-'))
|
|
1116
|
+
})).filter(({ to })=>!external_node_fs_default().existsSync(to)).map((move)=>({
|
|
1117
|
+
...move,
|
|
1118
|
+
names: legacyFunctionNames(move.from)
|
|
1119
|
+
}));
|
|
1120
|
+
};
|
|
1121
|
+
const svelteModelsStep = {
|
|
1122
|
+
id: 'svelte-models',
|
|
1123
|
+
kind: 'optional',
|
|
1124
|
+
title: 'Rename Svelte shared hooks to shared models: shared/model/create-*.svelte.ts',
|
|
1125
|
+
detect: (context)=>legacyModels(context).length > 0,
|
|
1126
|
+
plan: (context)=>legacyModels(context).flatMap(({ from, to, names })=>[
|
|
1127
|
+
`${upgrade_svelte_relative(from)} → ${upgrade_svelte_relative(to)}`,
|
|
1128
|
+
...names.map(([from, to])=>` ${from} → ${to}`)
|
|
1129
|
+
]),
|
|
1130
|
+
apply: (context)=>{
|
|
1131
|
+
const models = legacyModels(context);
|
|
1132
|
+
const moves = new Map(models.map(({ from, to })=>[
|
|
1133
|
+
from,
|
|
1134
|
+
to
|
|
1135
|
+
]));
|
|
1136
|
+
const withoutExtension = new Map(models.map(({ from, to })=>[
|
|
1137
|
+
from.replace(module_move_codeExtension, ''),
|
|
1138
|
+
to.replace(module_move_codeExtension, '')
|
|
1139
|
+
]));
|
|
1140
|
+
const names = models.flatMap((model)=>model.names);
|
|
1141
|
+
const namePattern = names.length && new RegExp(`(?<![\\w$])(${names.map(([from])=>module_move_escapeRegExp(from)).join('|')})(?![\\w$])`, 'g');
|
|
1142
|
+
const renames = new Map(names);
|
|
1143
|
+
module_move_stageModuleMove({
|
|
1144
|
+
projectRoot: new project_root_ProjectRoot().path,
|
|
1145
|
+
stopAt: svelteFolder(context),
|
|
1146
|
+
moves,
|
|
1147
|
+
movedPath: (candidate)=>moves.get(candidate) ?? withoutExtension.get(candidate),
|
|
1148
|
+
rename: (content)=>namePattern ? content.replace(namePattern, (name)=>renames.get(name) ?? name) : content
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
const withoutLineComments = (text)=>text.split('\n').filter((line)=>!/^\s*\/\//.test(line)).join('\n');
|
|
1153
|
+
const closesAtEnd = (text)=>{
|
|
1154
|
+
let depth = 0;
|
|
1155
|
+
let quote;
|
|
1156
|
+
for(let index = 0; index < text.length; index++){
|
|
1157
|
+
const char = text[index];
|
|
1158
|
+
if (quote) {
|
|
1159
|
+
if ('\\' === char) index++;
|
|
1160
|
+
else if (char === quote) quote = void 0;
|
|
1161
|
+
continue;
|
|
1162
|
+
}
|
|
1163
|
+
if ("'" === char || '"' === char || '`' === char) quote = char;
|
|
1164
|
+
else if ('{' === char) depth++;
|
|
1165
|
+
else if ('}' === char && 0 === --depth) return index === text.length - 1;
|
|
1166
|
+
}
|
|
1167
|
+
return false;
|
|
1168
|
+
};
|
|
1169
|
+
const mappedObject = (content)=>{
|
|
1170
|
+
const lines = content.replace(/\/\*[\s\S]*?\*\//g, '').split('\n');
|
|
1171
|
+
const exportAt = lines.findIndex((line)=>/^export\s/.test(line));
|
|
1172
|
+
if (exportAt < 0) return;
|
|
1173
|
+
const onlyTypeImports = lines.slice(0, exportAt).filter((line)=>line.trim() && !/^\s*\/\//.test(line)).every((line)=>/^import\s+type\s*\{[^}]*\}\s*from\s*['"]\.\.\/types['"];?\s*$/.test(line));
|
|
1174
|
+
const declaration = lines.slice(exportAt).join('\n').trim().match(/^export\s+const\s+(?:use|create)(\w+)UIModel\s*=\s*\(\s*([\w$]+)\s*(?::[^)]*)?\)\s*(?::[^=]+?)?=>\s*([\s\S]*?);?$/);
|
|
1175
|
+
if (!onlyTypeImports || !declaration) return;
|
|
1176
|
+
const [, ClassName, param, rawBody] = declaration;
|
|
1177
|
+
const body = rawBody.trim();
|
|
1178
|
+
const object = body.startsWith('(') && body.endsWith(')') ? body.slice(1, -1).trim() : body.startsWith('{') && body.endsWith('}') ? withoutLineComments(body.slice(1, -1)).trim().match(/^return\s*(\{[\s\S]*\})\s*;?$/)?.[1] : void 0;
|
|
1179
|
+
if (!object || !closesAtEnd(object)) return;
|
|
1180
|
+
if (/\b(?:get|set)\s+[\w$]+\s*\(|\$(?:state|derived|effect)\b/.test(object)) return;
|
|
1181
|
+
const ownProps = new RegExp(`(?<![\\w$.])${module_move_escapeRegExp(param)}\\.`, 'g');
|
|
1182
|
+
if (new RegExp(`(?<![\\w$])${module_move_escapeRegExp(param)}(?![\\w$])`).test(object.replace(ownProps, ''))) return;
|
|
1183
|
+
return {
|
|
1184
|
+
ClassName,
|
|
1185
|
+
object: '{}' === withoutLineComments(object).replace(/\s/g, '') ? '{}' : object,
|
|
1186
|
+
ownProps
|
|
1187
|
+
};
|
|
1188
|
+
};
|
|
1189
|
+
const inlineModel = (widget, model)=>{
|
|
1190
|
+
const mapped = mappedObject(external_node_fs_default().readFileSync(model, 'utf8'));
|
|
1191
|
+
if (!mapped) return;
|
|
1192
|
+
const { ClassName, object, ownProps } = mapped;
|
|
1193
|
+
const content = external_node_fs_default().readFileSync(widget, 'utf8');
|
|
1194
|
+
const importLine = new RegExp(`^[ \\t]*import\\s*\\{\\s*(?:use|create)${ClassName}UIModel\\s*\\}\\s*from\\s*['"]\\./(?:hooks|model)/[^'"]+['"];?[ \\t]*\\n`, 'm');
|
|
1195
|
+
const call = new RegExp(`^(?:[ \\t]*// The (?:\\$props\\(\\) proxy|rest of \\$props\\(\\)).*\\n)?(?:[ \\t]*// svelte-ignore state_referenced_locally\\n)?([ \\t]*)const\\s+uiModel\\s*=\\s*(?:use|create)${ClassName}UIModel\\(\\s*([\\w$]+)\\s*\\);?[ \\t]*\\n`, 'm');
|
|
1196
|
+
const typesImport = new RegExp(`import\\s+type\\s*\\{\\s*${ClassName}WidgetProps\\s*\\}\\s*from\\s*(['"])\\./types\\1`);
|
|
1197
|
+
const callMatch = content.match(call);
|
|
1198
|
+
if (!importLine.test(content) || !callMatch || !typesImport.test(content) || !content.includes('{...uiModel}')) return;
|
|
1199
|
+
const [, indent, argument] = callMatch;
|
|
1200
|
+
const objectLines = object.replace(ownProps, `${argument}.`).split('\n');
|
|
1201
|
+
const closingIndent = objectLines.at(-1).match(/^\s*/)[0].length;
|
|
1202
|
+
const shift = indent.length - closingIndent;
|
|
1203
|
+
const reindented = objectLines.map((line, index)=>0 === index ? line : shift >= 0 ? `${' '.repeat(shift)}${line}` : line.replace(new RegExp(`^ {0,${-shift}}`), '')).join('\n');
|
|
1204
|
+
const inlined = content.replace(importLine, '').replace(call, `${indent}const toUIProps = (): ${ClassName}WidgetUIProps => (${reindented})\n`).replace(typesImport, (_, quote)=>`import type { ${ClassName}WidgetProps, ${ClassName}WidgetUIProps } from ${quote}./types${quote}`).replaceAll('{...uiModel}', '{...toUIProps()}');
|
|
1205
|
+
return /(?<![\w$])uiModel(?![\w$])/.test(inlined) ? void 0 : inlined;
|
|
1206
|
+
};
|
|
1207
|
+
const widgetModels = (context)=>{
|
|
1208
|
+
const folder = svelteFolder(context);
|
|
1209
|
+
if (!folder) return [];
|
|
1210
|
+
return module_move_walk(external_node_path_default().join(folder, 'widgets')).filter((file)=>[
|
|
1211
|
+
'hooks',
|
|
1212
|
+
'model'
|
|
1213
|
+
].includes(external_node_path_default().basename(external_node_path_default().dirname(file))) && /^(?:use|create)-.+-ui-model\.svelte\.[jt]s$/.test(external_node_path_default().basename(file))).map((model)=>{
|
|
1214
|
+
const widgetFolder = external_node_path_default().dirname(external_node_path_default().dirname(model));
|
|
1215
|
+
const widgetName = external_node_fs_default().readdirSync(widgetFolder).find((name)=>name.endsWith('-widget.svelte'));
|
|
1216
|
+
const widget = widgetName && external_node_path_default().join(widgetFolder, widgetName);
|
|
1217
|
+
const specifier = external_node_path_default().basename(model).replace(module_move_codeExtension, '');
|
|
1218
|
+
const usedElsewhere = module_move_walk(widgetFolder).some((file)=>file !== widget && file !== model && module_move_codeExtension.test(file) && external_node_fs_default().readFileSync(file, 'utf8').includes(specifier));
|
|
1219
|
+
return {
|
|
1220
|
+
model,
|
|
1221
|
+
widget,
|
|
1222
|
+
inlined: widget && !usedElsewhere ? inlineModel(widget, model) : void 0
|
|
1223
|
+
};
|
|
1224
|
+
});
|
|
1225
|
+
};
|
|
1226
|
+
const svelteToUIPropsStep = {
|
|
1227
|
+
id: 'svelte-to-ui-props',
|
|
1228
|
+
kind: 'optional',
|
|
1229
|
+
title: 'Map Svelte widget props with toUIProps in the widget',
|
|
1230
|
+
detect: (context)=>widgetModels(context).some(({ inlined })=>void 0 !== inlined),
|
|
1231
|
+
plan: (context)=>widgetModels(context).filter(({ inlined })=>void 0 !== inlined).map(({ model, widget })=>`${upgrade_svelte_relative(model)} → toUIProps in ${upgrade_svelte_relative(widget)}; the model file is deleted`),
|
|
1232
|
+
apply: (context)=>{
|
|
1233
|
+
for (const { model, widget, inlined } of widgetModels(context))if (void 0 !== inlined) {
|
|
1234
|
+
new file_system_File(widget).update(inlined);
|
|
1235
|
+
new file_system_File(model).delete(external_node_path_default().dirname(widget));
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
};
|
|
1239
|
+
const svelteToUIPropsManualStep = {
|
|
1240
|
+
id: 'svelte-to-ui-props-manual',
|
|
1241
|
+
kind: 'manual',
|
|
1242
|
+
title: 'Move Svelte widget UI models into toUIProps by hand',
|
|
1243
|
+
detect: (context)=>widgetModels(context).some(({ inlined })=>void 0 === inlined),
|
|
1244
|
+
plan: (context)=>widgetModels(context).filter(({ inlined })=>void 0 === inlined).map(({ model, widget })=>widget ? `${upgrade_svelte_relative(model)}: move its state and methods into the <script> of ${upgrade_svelte_relative(widget)}, map props in toUIProps and render {...toUIProps()}, then delete the model` : `${upgrade_svelte_relative(model)}: no widget file next to it; map props with toUIProps in the widget`)
|
|
1245
|
+
};
|
|
1246
|
+
const upgrade_steps_record = (value)=>'object' != typeof value || null === value || Array.isArray(value) ? {} : value;
|
|
912
1247
|
const flatConfigSchema = external_zod_default().object({
|
|
913
1248
|
rootFolder: external_zod_default().string().min(1),
|
|
914
1249
|
domainFirstPackages: external_zod_default().array(external_zod_default()["enum"](config_file_domainFirstPackages)),
|
|
@@ -962,17 +1297,17 @@ const sectionsStep = {
|
|
|
962
1297
|
};
|
|
963
1298
|
}
|
|
964
1299
|
};
|
|
965
|
-
const reactOf = (config)=>
|
|
1300
|
+
const reactOf = (config)=>upgrade_steps_record(upgrade_steps_record(config.frontend).react);
|
|
966
1301
|
const frameworkStep = {
|
|
967
1302
|
id: 'react-framework',
|
|
968
1303
|
kind: 'required',
|
|
969
1304
|
title: 'Record the frontend framework explicitly',
|
|
970
|
-
detect: ({ config })=>'react' in
|
|
1305
|
+
detect: ({ config })=>'react' in upgrade_steps_record(config.frontend) && !reactOf(config).framework,
|
|
971
1306
|
plan: ()=>[
|
|
972
1307
|
hasDependency('next') ? 'frontend.react.framework: "next" (next is in package.json)' : 'frontend.react.framework: "react" (next is not in package.json)'
|
|
973
1308
|
],
|
|
974
1309
|
apply: ({ config })=>{
|
|
975
|
-
const frontend =
|
|
1310
|
+
const frontend = upgrade_steps_record(config.frontend);
|
|
976
1311
|
config.frontend = {
|
|
977
1312
|
...frontend,
|
|
978
1313
|
react: {
|
|
@@ -991,9 +1326,9 @@ const persistenceStep = {
|
|
|
991
1326
|
id: 'persistence-default',
|
|
992
1327
|
kind: 'required',
|
|
993
1328
|
title: 'Move the default persistence implementation to saved implementation types',
|
|
994
|
-
detect: ({ config })=>'defaultPersistenceLayerImplementation' in
|
|
1329
|
+
detect: ({ config })=>'defaultPersistenceLayerImplementation' in upgrade_steps_record(config.backend),
|
|
995
1330
|
plan: ({ config })=>{
|
|
996
|
-
const label =
|
|
1331
|
+
const label = upgrade_steps_record(config.backend).defaultPersistenceLayerImplementation;
|
|
997
1332
|
if (void 0 === label) return [];
|
|
998
1333
|
return implementationLabelSchema.safeParse(label).success ? [
|
|
999
1334
|
`defaultPersistenceLayerImplementation "${label}" → first primary type of backend.implementations.${persistenceKinds.join(', ')}`
|
|
@@ -1002,11 +1337,11 @@ const persistenceStep = {
|
|
|
1002
1337
|
];
|
|
1003
1338
|
},
|
|
1004
1339
|
apply: ({ config })=>{
|
|
1005
|
-
const { defaultPersistenceLayerImplementation: label, ...backend } =
|
|
1006
|
-
const implementations =
|
|
1340
|
+
const { defaultPersistenceLayerImplementation: label, ...backend } = upgrade_steps_record(config.backend);
|
|
1341
|
+
const implementations = upgrade_steps_record(backend.implementations);
|
|
1007
1342
|
if (implementationLabelSchema.safeParse(label).success) {
|
|
1008
1343
|
for (const kind of persistenceKinds){
|
|
1009
|
-
const group =
|
|
1344
|
+
const group = upgrade_steps_record(implementations[kind]);
|
|
1010
1345
|
const primary = Array.isArray(group.primary) ? group.primary : [];
|
|
1011
1346
|
implementations[kind] = {
|
|
1012
1347
|
primary: [
|
|
@@ -1029,12 +1364,17 @@ const upgradeSteps = [
|
|
|
1029
1364
|
openapiExtractorRootStep,
|
|
1030
1365
|
openapiExtractorNestedStep,
|
|
1031
1366
|
openapiExtractorManualStep,
|
|
1032
|
-
inMemoryDbWithIdStep
|
|
1367
|
+
inMemoryDbWithIdStep,
|
|
1368
|
+
svelteSwaggerPageStep,
|
|
1369
|
+
svelteSwaggerPackagesStep,
|
|
1370
|
+
svelteModelsStep,
|
|
1371
|
+
svelteToUIPropsStep,
|
|
1372
|
+
svelteToUIPropsManualStep
|
|
1033
1373
|
];
|
|
1034
1374
|
const skillsNote = 'Update the agent skills to this version: npx df-skills';
|
|
1035
1375
|
const planUpgrade = async (config, acceptOptional = ()=>true, steps = upgradeSteps)=>{
|
|
1036
1376
|
const context = {
|
|
1037
|
-
config: structuredClone(
|
|
1377
|
+
config: structuredClone(upgrade_steps_record(config))
|
|
1038
1378
|
};
|
|
1039
1379
|
const original = JSON.stringify(context.config);
|
|
1040
1380
|
const planned = [];
|
|
@@ -1069,7 +1409,7 @@ Options:
|
|
|
1069
1409
|
--dry-run show the plan without writing anything
|
|
1070
1410
|
--yes apply without asking, optional steps included
|
|
1071
1411
|
-h, --help show this help`;
|
|
1072
|
-
const { values } = (0, external_node_util_namespaceObject.parseArgs)({
|
|
1412
|
+
const { values: upgrade_values } = (0, external_node_util_namespaceObject.parseArgs)({
|
|
1073
1413
|
options: {
|
|
1074
1414
|
help: {
|
|
1075
1415
|
type: 'boolean',
|
|
@@ -1087,7 +1427,7 @@ const { values } = (0, external_node_util_namespaceObject.parseArgs)({
|
|
|
1087
1427
|
}
|
|
1088
1428
|
}
|
|
1089
1429
|
});
|
|
1090
|
-
if (
|
|
1430
|
+
if (upgrade_values.help) {
|
|
1091
1431
|
console.log(help);
|
|
1092
1432
|
process.exit(0);
|
|
1093
1433
|
}
|
|
@@ -1095,7 +1435,7 @@ const printStep = ({ step, changes })=>{
|
|
|
1095
1435
|
console.log(`\n${step.title}${'optional' === step.kind ? ' (optional)' : ''}`);
|
|
1096
1436
|
for (const change of changes)console.log(` ${change}`);
|
|
1097
1437
|
};
|
|
1098
|
-
const
|
|
1438
|
+
const upgrade_run = async ()=>{
|
|
1099
1439
|
const root = new project_root_ProjectRoot().path;
|
|
1100
1440
|
const configPath = external_node_path_default().join(root, configFileName);
|
|
1101
1441
|
if (!config_file_ConfigFile.exists) {
|
|
@@ -1109,9 +1449,9 @@ const run = async ()=>{
|
|
|
1109
1449
|
console.log(`${configFileName} is not valid JSON: fix it first.`);
|
|
1110
1450
|
process.exit(1);
|
|
1111
1451
|
}
|
|
1112
|
-
const dryRun =
|
|
1452
|
+
const dryRun = upgrade_values['dry-run'];
|
|
1113
1453
|
const { planned, changed, config } = await planUpgrade(raw, (entry)=>{
|
|
1114
|
-
if (dryRun ||
|
|
1454
|
+
if (dryRun || upgrade_values.yes) return true;
|
|
1115
1455
|
printStep(entry);
|
|
1116
1456
|
return (0, prompts_namespaceObject.confirm)({
|
|
1117
1457
|
message: 'Apply this optional step?',
|
|
@@ -1126,7 +1466,7 @@ const run = async ()=>{
|
|
|
1126
1466
|
skillsNote
|
|
1127
1467
|
];
|
|
1128
1468
|
if (dryRun) return void console.log('\nDry run: nothing was written.');
|
|
1129
|
-
if (!
|
|
1469
|
+
if (!upgrade_values.yes && !await (0, prompts_namespaceObject.confirm)({
|
|
1130
1470
|
message: 'Apply?',
|
|
1131
1471
|
default: true
|
|
1132
1472
|
})) {
|
|
@@ -1140,7 +1480,7 @@ const run = async ()=>{
|
|
|
1140
1480
|
console.log('\nDo it yourself:');
|
|
1141
1481
|
for (const note of manual)console.log(` ${note}`);
|
|
1142
1482
|
};
|
|
1143
|
-
|
|
1483
|
+
upgrade_run().catch((error)=>{
|
|
1144
1484
|
console.error(error instanceof Error ? error.message : error);
|
|
1145
1485
|
process.exitCode = 1;
|
|
1146
1486
|
});
|