@azure-net/cli 5.1.0 → 6.0.0-next.2
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 +189 -0
- package/bin/azure-net.js +236 -221
- package/dist/bin/azure-net.d.ts +2 -0
- package/dist/src/checks/architecture.d.ts +20 -0
- package/dist/src/checks/checkDomain.d.ts +1 -0
- package/dist/src/checks/checkFoldersStructure.d.ts +1 -0
- package/dist/src/checks/checkHooks.d.ts +1 -0
- package/dist/src/checks/checkImports.d.ts +1 -0
- package/dist/src/checks/checkInternal.d.ts +1 -0
- package/dist/src/checks/checkLayerBoundaries.d.ts +1 -0
- package/dist/src/checks/checkLayerImports.d.ts +1 -0
- package/dist/src/checks/checkPresenterNames.d.ts +1 -0
- package/dist/src/checks/checkProject.d.ts +1 -0
- package/dist/src/checks/checkProviderGraph.d.ts +1 -0
- package/dist/src/checks/checkProviderNames.d.ts +1 -0
- package/dist/src/generate/layers/generateRepository.d.ts +1 -0
- package/dist/src/generate/layers/generateRepositoryMethod.d.ts +1 -0
- package/dist/src/generate/layers/generateUseCases.d.ts +1 -0
- package/dist/src/generate/module/generateDomain.d.ts +8 -0
- package/dist/src/generate/module/generateModule.d.ts +1 -0
- package/dist/src/generate/module/generateModulePreset.d.ts +1 -0
- package/dist/src/generate/module/generatePresenter.d.ts +29 -0
- package/dist/src/generate/module/generateRepository.d.ts +15 -0
- package/dist/src/generate/module/generateRepositoryMethod.d.ts +2 -0
- package/dist/src/generate/module/generateSchemaFromType.d.ts +9 -0
- package/dist/src/generate/module/generateStore.d.ts +1 -0
- package/dist/src/generate/module/generateTypesJson.d.ts +2 -0
- package/dist/src/generate/module/generateUseCases.d.ts +1 -0
- package/dist/src/generate/module/repositoryModuleShared.d.ts +89 -0
- package/dist/src/generate/routes/generateRoutes.d.ts +14 -0
- package/dist/src/generate/ui/generateComponent.d.ts +1 -0
- package/dist/src/generate/ui/generateDesignComponent.d.ts +1 -0
- package/dist/src/generate/ui/generateWidget.d.ts +1 -0
- package/dist/src/git/commit.d.ts +23 -0
- package/dist/src/git/push.d.ts +11 -0
- package/dist/src/git/runGit.d.ts +2 -0
- package/dist/src/init/initAliases.d.ts +12 -0
- package/dist/src/init/initEdges.d.ts +2 -0
- package/dist/src/init/initStructure.d.ts +1 -0
- package/dist/src/install/configureCommitTools.d.ts +1 -0
- package/dist/src/install/installFresh.d.ts +1 -0
- package/dist/src/migrate/migrate.d.ts +22 -0
- package/dist/src/migrate/presenters.d.ts +7 -0
- package/dist/src/plugins/addLint.d.ts +5 -0
- package/dist/src/scaffolds/createCoreSchema.d.ts +1 -0
- package/dist/src/scaffolds/createDatasource.d.ts +1 -0
- package/dist/src/scaffolds/createProgram.d.ts +1 -0
- package/dist/src/scaffolds/createResponse.d.ts +1 -0
- package/dist/src/scaffolds/createSchemaRule.d.ts +1 -0
- package/dist/src/scaffolds/createTranslationManager.d.ts +1 -0
- package/{src/scaffolds/index.ts → dist/src/scaffolds/index.d.ts} +0 -2
- package/dist/src/scaffolds/registerDatasource.d.ts +2 -0
- package/dist/src/scaffolds/updateDefaultFactoryConfig.d.ts +1 -0
- package/dist/src/utils/architecture.d.ts +31 -0
- package/dist/src/utils/contextUtils.d.ts +6 -0
- package/dist/src/utils/fileUtils.d.ts +5 -0
- package/dist/src/utils/flattenConfig.d.ts +2 -0
- package/dist/src/utils/legacyAliases.d.ts +1 -0
- package/dist/src/utils/loadConfig.d.ts +16 -0
- package/dist/src/utils/packageImports.d.ts +4 -0
- package/dist/src/utils/sharedFoundation.d.ts +20 -0
- package/dist/src/utils/viteConfig.d.ts +9 -0
- package/package.json +48 -36
- package/src/checks/architecture.js +154 -0
- package/src/checks/checkDomain.js +124 -154
- package/src/checks/checkFoldersStructure.js +64 -52
- package/src/checks/checkHooks.js +12 -12
- package/src/checks/checkImports.js +26 -142
- package/src/checks/checkInternal.js +27 -24
- package/src/checks/checkLayerBoundaries.js +22 -197
- package/src/checks/checkLayerImports.js +14 -134
- package/src/checks/checkPresenterNames.js +156 -143
- package/src/checks/checkProject.js +27 -26
- package/src/checks/checkProviderGraph.js +182 -166
- package/src/checks/checkProviderNames.js +123 -112
- package/src/generate/layers/generateRepository.js +1 -109
- package/src/generate/layers/generateRepositoryMethod.js +1 -90
- package/src/generate/layers/generateUseCases.js +1 -44
- package/src/generate/module/generateDomain.js +81 -105
- package/src/generate/module/generateModule.js +34 -68
- package/src/generate/module/generateModulePreset.js +188 -248
- package/src/generate/module/generatePresenter.js +441 -369
- package/src/generate/module/generateRepository.js +102 -121
- package/src/generate/module/generateRepositoryMethod.js +117 -0
- package/src/generate/module/generateSchemaFromType.js +283 -280
- package/src/generate/module/generateStore.js +41 -0
- package/src/generate/module/generateTypesJson.js +196 -195
- package/src/generate/module/generateUseCases.js +47 -55
- package/src/generate/module/repositoryModuleShared.js +480 -459
- package/src/generate/routes/generateRoutes.js +165 -174
- package/src/generate/ui/generateComponent.js +44 -64
- package/src/generate/ui/generateDesignComponent.js +21 -41
- package/src/generate/ui/generateWidget.js +21 -41
- package/src/git/commit.js +67 -0
- package/src/git/push.js +19 -0
- package/src/git/runGit.js +11 -0
- package/src/init/initAliases.js +19 -135
- package/src/init/initEdges.js +79 -54
- package/src/init/initStructure.js +31 -145
- package/src/install/configureCommitTools.js +1 -0
- package/src/install/installFresh.js +39 -68
- package/src/migrate/migrate.js +914 -0
- package/src/migrate/presenters.js +265 -0
- package/src/plugins/addLint.js +52 -219
- package/src/scaffolds/createCoreSchema.js +65 -91
- package/src/scaffolds/createDatasource.js +67 -101
- package/src/scaffolds/createProgram.js +8 -8
- package/src/scaffolds/createResponse.js +29 -29
- package/src/scaffolds/createSchemaRule.js +19 -19
- package/src/scaffolds/createTranslationManager.js +84 -37
- package/src/scaffolds/index.js +0 -2
- package/src/scaffolds/registerDatasource.js +59 -0
- package/src/scaffolds/updateDefaultFactoryConfig.js +31 -0
- package/src/utils/architecture.js +145 -0
- package/src/utils/contextUtils.js +32 -65
- package/src/utils/fileUtils.js +69 -50
- package/src/utils/flattenConfig.js +38 -0
- package/src/utils/legacyAliases.js +75 -0
- package/src/utils/loadConfig.js +76 -40
- package/src/utils/packageImports.js +63 -0
- package/src/utils/sharedFoundation.js +36 -42
- package/src/utils/viteConfig.js +295 -0
- package/.prettierrc +0 -7
- package/bin/azure-net.ts +0 -308
- package/eslint.config.js +0 -34
- package/src/checks/checkDomain.ts +0 -223
- package/src/checks/checkFoldersStructure.ts +0 -85
- package/src/checks/checkHooks.ts +0 -22
- package/src/checks/checkImports.ts +0 -193
- package/src/checks/checkInternal.ts +0 -48
- package/src/checks/checkLayerBoundaries.ts +0 -255
- package/src/checks/checkLayerImports.ts +0 -185
- package/src/checks/checkPresenterNames.ts +0 -203
- package/src/checks/checkProject.ts +0 -45
- package/src/checks/checkProviderGraph.ts +0 -234
- package/src/checks/checkProviderNames.ts +0 -165
- package/src/generate/layers/generateRepository.ts +0 -123
- package/src/generate/layers/generateRepositoryMethod.ts +0 -102
- package/src/generate/layers/generateUseCases.ts +0 -50
- package/src/generate/layers/repositoryShared.js +0 -506
- package/src/generate/layers/repositoryShared.ts +0 -662
- package/src/generate/module/generateDomain.ts +0 -147
- package/src/generate/module/generateModule.ts +0 -84
- package/src/generate/module/generateModulePreset.ts +0 -338
- package/src/generate/module/generatePresenter.ts +0 -498
- package/src/generate/module/generateRepository.ts +0 -158
- package/src/generate/module/generateSchemaFromType.ts +0 -368
- package/src/generate/module/generateTypesJson.ts +0 -259
- package/src/generate/module/generateUseCases.ts +0 -67
- package/src/generate/module/repositoryModuleShared.ts +0 -669
- package/src/generate/routes/generateRoutes.ts +0 -282
- package/src/generate/ui/generateComponent.ts +0 -100
- package/src/generate/ui/generateDesignComponent.ts +0 -71
- package/src/generate/ui/generateWidget.ts +0 -71
- package/src/init/initAliases.ts +0 -172
- package/src/init/initEdges.ts +0 -74
- package/src/init/initStructure.ts +0 -172
- package/src/install/installFresh.ts +0 -93
- package/src/plugins/addLint.ts +0 -274
- package/src/scaffolds/createCoreSchema.ts +0 -130
- package/src/scaffolds/createDatasource.ts +0 -161
- package/src/scaffolds/createDatasourceProvider.js +0 -127
- package/src/scaffolds/createDatasourceProvider.ts +0 -161
- package/src/scaffolds/createPresenterFactory.js +0 -83
- package/src/scaffolds/createPresenterFactory.ts +0 -102
- package/src/scaffolds/createProgram.ts +0 -19
- package/src/scaffolds/createResponse.ts +0 -66
- package/src/scaffolds/createSchemaRule.ts +0 -44
- package/src/scaffolds/createTranslationManager.ts +0 -80
- package/src/utils/contextUtils.ts +0 -88
- package/src/utils/fileUtils.ts +0 -74
- package/src/utils/loadConfig.ts +0 -68
- package/src/utils/sharedFoundation.ts +0 -70
- package/tsconfig.json +0 -19
- /package/{src/checks/index.ts → dist/src/checks/index.d.ts} +0 -0
- /package/{src/plugins/index.ts → dist/src/plugins/index.d.ts} +0 -0
|
@@ -2,216 +2,207 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import prompts from 'prompts';
|
|
4
4
|
import { loadUserConfig } from '../../utils/loadConfig.js';
|
|
5
|
-
import { getSharedContextRootPath, getSharedState } from '../../utils/sharedFoundation.js';
|
|
6
5
|
import { toCamelCase } from '../../utils/contextUtils.js';
|
|
7
|
-
const
|
|
6
|
+
const getRoutesDir = () => path.join(process.cwd(), 'src', 'routes');
|
|
8
7
|
const ROUTE_FILE_PATTERN = /^\+(page|server)(?:\.server)?\.(?:svelte|ts|js)$/;
|
|
9
8
|
const PAGE_FILE_PATTERN = /^\+page(?:\.server)?\.(?:svelte|ts|js)$/;
|
|
10
9
|
const SERVER_FILE_PATTERN = /^\+server\.(?:ts|js)$/;
|
|
11
10
|
const isRouteGroup = (segment) => /^\(.+\)$/.test(segment);
|
|
12
11
|
const getRouteGroupName = (segment) => segment.slice(1, -1).trim();
|
|
13
12
|
const extractParamName = (rawParam) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const withoutRest = rawParam.startsWith('...') ? rawParam.slice(3) : rawParam;
|
|
14
|
+
const matcherIndex = withoutRest.indexOf('=');
|
|
15
|
+
return matcherIndex === -1 ? withoutRest : withoutRest.slice(0, matcherIndex);
|
|
17
16
|
};
|
|
18
17
|
const convertDynamicSegments = (segment) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
const optionalMatch = segment.match(/^\[\[(.+)\]\]$/);
|
|
19
|
+
if (optionalMatch?.[1]) {
|
|
20
|
+
const paramName = extractParamName(optionalMatch[1]);
|
|
21
|
+
return { variants: ['', `{${paramName}}`], params: [paramName] };
|
|
22
|
+
}
|
|
23
|
+
const params = [];
|
|
24
|
+
const converted = segment.replace(/\[(.+?)\]/g, (_match, rawParam) => {
|
|
25
|
+
const paramName = extractParamName(rawParam);
|
|
26
|
+
if (paramName.length)
|
|
27
|
+
params.push(paramName);
|
|
28
|
+
return `{${paramName}}`;
|
|
29
|
+
});
|
|
30
|
+
return { variants: [converted], params };
|
|
31
31
|
};
|
|
32
32
|
const normalizeUrl = (segments) => {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const filtered = segments.filter(Boolean);
|
|
34
|
+
return filtered.length ? `/${filtered.join('/')}` : '/';
|
|
35
35
|
};
|
|
36
36
|
const createRouteVariants = (segments) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
37
|
+
let variants = [[]];
|
|
38
|
+
const dynamicParams = new Set();
|
|
39
|
+
for (const segment of segments) {
|
|
40
|
+
if (isRouteGroup(segment))
|
|
41
|
+
continue;
|
|
42
|
+
const converted = convertDynamicSegments(segment);
|
|
43
|
+
for (const param of converted.params) {
|
|
44
|
+
dynamicParams.add(param);
|
|
45
|
+
}
|
|
46
|
+
const nextVariants = [];
|
|
47
|
+
for (const variant of variants) {
|
|
48
|
+
for (const nextSegment of converted.variants) {
|
|
49
|
+
nextVariants.push(nextSegment ? [...variant, nextSegment] : [...variant]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
variants = nextVariants;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
urls: [...new Set(variants.map(normalizeUrl))],
|
|
56
|
+
dynamicParams: [...dynamicParams]
|
|
57
|
+
};
|
|
57
58
|
};
|
|
58
59
|
const hasRouteFile = (files) => files.some((file) => ROUTE_FILE_PATTERN.test(file));
|
|
59
60
|
const hasPageFile = (files) => files.some((file) => PAGE_FILE_PATTERN.test(file));
|
|
60
61
|
const hasServerFile = (files) => files.some((file) => SERVER_FILE_PATTERN.test(file));
|
|
61
62
|
const readDirSafe = async (dir) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
try {
|
|
64
|
+
return await fs.readdir(dir, { withFileTypes: true });
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
67
69
|
};
|
|
68
70
|
const collectRoutes = async (dir, segments = [], groupStack = [], rootGroup) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
71
|
+
const entries = (await readDirSafe(dir)).sort((a, b) => a.name.localeCompare(b.name));
|
|
72
|
+
const files = entries.filter((entry) => entry.isFile()).map((entry) => entry.name);
|
|
73
|
+
const dirs = entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'));
|
|
74
|
+
const routes = [];
|
|
75
|
+
const routeVariants = createRouteVariants(segments);
|
|
76
|
+
if (hasRouteFile(files)) {
|
|
77
|
+
for (const url of routeVariants.urls) {
|
|
78
|
+
routes.push({
|
|
79
|
+
url,
|
|
80
|
+
routeDir: dir,
|
|
81
|
+
relativeDir: path.relative(getRoutesDir(), dir) || '.',
|
|
82
|
+
segments,
|
|
83
|
+
dynamicParams: routeVariants.dynamicParams,
|
|
84
|
+
rootGroup,
|
|
85
|
+
groupStack,
|
|
86
|
+
depth: segments.length,
|
|
87
|
+
hasChildren: dirs.length > 0,
|
|
88
|
+
hasPage: hasPageFile(files),
|
|
89
|
+
hasServer: hasServerFile(files)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (const child of dirs) {
|
|
94
|
+
const childGroupName = isRouteGroup(child.name) ? getRouteGroupName(child.name) : undefined;
|
|
95
|
+
const nextGroupStack = childGroupName ? [...groupStack, childGroupName] : groupStack;
|
|
96
|
+
const nextRootGroup = rootGroup ?? (segments.length === 0 ? childGroupName : undefined);
|
|
97
|
+
const childRoutes = await collectRoutes(path.join(dir, child.name), [...segments, child.name], nextGroupStack, nextRootGroup);
|
|
98
|
+
routes.push(...childRoutes);
|
|
99
|
+
}
|
|
100
|
+
return routes;
|
|
99
101
|
};
|
|
100
102
|
const sanitizeGroupName = (value) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
const trimmed = value.trim();
|
|
104
|
+
return trimmed.length ? trimmed : 'routes';
|
|
103
105
|
};
|
|
104
106
|
const toRouteVariableName = (groupName) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
const base = toCamelCase(sanitizeGroupName(groupName).replace(/[^\p{L}\p{N}_-]+/gu, '-'));
|
|
108
|
+
return `${base || 'routes'}Routes`;
|
|
107
109
|
};
|
|
108
110
|
const ensureUniqueVariableName = (name, used) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
if (!used.has(name)) {
|
|
112
|
+
used.add(name);
|
|
113
|
+
return name;
|
|
114
|
+
}
|
|
115
|
+
let index = 2;
|
|
116
|
+
let nextName = `${name}${index}`;
|
|
117
|
+
while (used.has(nextName)) {
|
|
118
|
+
index += 1;
|
|
119
|
+
nextName = `${name}${index}`;
|
|
120
|
+
}
|
|
121
|
+
used.add(nextName);
|
|
122
|
+
return nextName;
|
|
121
123
|
};
|
|
122
124
|
const createGroupMap = (routes, mode, resolver) => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return groups;
|
|
125
|
+
const groups = new Map();
|
|
126
|
+
for (const route of routes) {
|
|
127
|
+
const groupName = mode === 'none'
|
|
128
|
+
? 'routes'
|
|
129
|
+
: mode === 'root-groups'
|
|
130
|
+
? (route.rootGroup ?? 'routes')
|
|
131
|
+
: (sanitizeGroupName(String(resolver?.(route) ?? 'routes')) ?? 'routes');
|
|
132
|
+
const list = groups.get(groupName) ?? [];
|
|
133
|
+
list.push(route);
|
|
134
|
+
groups.set(groupName, list);
|
|
135
|
+
}
|
|
136
|
+
return groups;
|
|
136
137
|
};
|
|
137
138
|
const createStringArray = (items, indent = '\t') => {
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
if (!items.length)
|
|
140
|
+
return '[]';
|
|
141
|
+
return `[\n${items.map((item) => `${indent}'${item}'`).join(',\n')}\n]`;
|
|
140
142
|
};
|
|
141
143
|
const createGeneratedFile = (groups) => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
lines.push('export const routeGroups = {');
|
|
161
|
-
lines.push(
|
|
162
|
-
...groupEntries.map((group, index) => `\t'${group.groupName}': ${group.variableName}${index === groupEntries.length - 1 ? '' : ','}`)
|
|
163
|
-
);
|
|
164
|
-
lines.push('} as const;');
|
|
165
|
-
lines.push('');
|
|
166
|
-
lines.push('export type Route = (typeof routes)[number];');
|
|
167
|
-
lines.push('export type RouteGroupName = keyof typeof routeGroups;');
|
|
168
|
-
lines.push('');
|
|
169
|
-
return `${lines.join('\n')}\n`;
|
|
144
|
+
const usedVariables = new Set();
|
|
145
|
+
const groupEntries = [...groups.entries()].map(([groupName, routes]) => ({
|
|
146
|
+
groupName,
|
|
147
|
+
variableName: ensureUniqueVariableName(groupName === 'routes' ? (groups.size === 1 ? 'routes' : 'ungroupedRoutes') : toRouteVariableName(groupName), usedVariables),
|
|
148
|
+
routes: [...new Set(routes.map((route) => route.url))].sort((a, b) => a.localeCompare(b))
|
|
149
|
+
}));
|
|
150
|
+
const lines = ['// This file is generated by `azure-net generate routes`.', '// Do not edit it manually.', ''];
|
|
151
|
+
for (const group of groupEntries) {
|
|
152
|
+
lines.push(`export const ${group.variableName} = ${createStringArray(group.routes)} as const;`);
|
|
153
|
+
lines.push('');
|
|
154
|
+
}
|
|
155
|
+
if (groupEntries.length !== 1 || groupEntries[0]?.variableName !== 'routes') {
|
|
156
|
+
lines.push(`export const routes = [${groupEntries.map((group) => `...${group.variableName}`).join(', ')}] as const;`);
|
|
157
|
+
lines.push('');
|
|
158
|
+
}
|
|
159
|
+
lines.push('export type Route = (typeof routes)[number];');
|
|
160
|
+
lines.push('');
|
|
161
|
+
return `${lines.join('\n')}\n`;
|
|
170
162
|
};
|
|
171
163
|
const selectGroupingMode = async () => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
164
|
+
const { mode } = await prompts({
|
|
165
|
+
type: 'select',
|
|
166
|
+
name: 'mode',
|
|
167
|
+
message: 'How should routes be grouped?',
|
|
168
|
+
choices: [
|
|
169
|
+
{ title: 'By root route groups: (account), (landing), ...', value: 'root-groups' },
|
|
170
|
+
{ title: 'By azure-net.config.ts groupRoutesFunc', value: 'config-function' },
|
|
171
|
+
{ title: 'Do not group, generate one routes array', value: 'none' }
|
|
172
|
+
]
|
|
173
|
+
});
|
|
174
|
+
return mode ? mode : null;
|
|
183
175
|
};
|
|
184
176
|
const getConfigRouteGroupResolver = async () => {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
177
|
+
const config = await loadUserConfig();
|
|
178
|
+
if (typeof config.groupRoutesFunc !== 'function') {
|
|
179
|
+
console.error('❌ `groupRoutesFunc` is missing in azure-net.config.ts/js or is not a function.');
|
|
180
|
+
console.error('Example:');
|
|
181
|
+
console.error('export default {');
|
|
182
|
+
console.error("\tgroupRoutesFunc: (route) => route.rootGroup ?? 'app'");
|
|
183
|
+
console.error('};');
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return config.groupRoutesFunc;
|
|
195
187
|
};
|
|
196
188
|
export default async function generateRoutes() {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
189
|
+
const mode = await selectGroupingMode();
|
|
190
|
+
if (!mode)
|
|
191
|
+
return;
|
|
192
|
+
const resolver = mode === 'config-function' ? await getConfigRouteGroupResolver() : undefined;
|
|
193
|
+
if (mode === 'config-function' && !resolver) {
|
|
194
|
+
process.exitCode = 1;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const routes = await collectRoutes(getRoutesDir());
|
|
198
|
+
if (!routes.length) {
|
|
199
|
+
console.warn('⚠️ No SvelteKit routes found in src/routes');
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const groups = createGroupMap(routes, mode, resolver ?? undefined);
|
|
203
|
+
const outputDir = path.join(process.cwd(), 'src', 'app', 'Platform', 'Bootstrap', 'Routes');
|
|
204
|
+
const outputFile = path.join(outputDir, 'index.ts');
|
|
205
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
206
|
+
await fs.writeFile(outputFile, createGeneratedFile(groups), 'utf-8');
|
|
207
|
+
console.log(`✅ Routes generated: ${outputFile}`);
|
|
216
208
|
}
|
|
217
|
-
//# sourceMappingURL=generateRoutes.js.map
|
|
@@ -2,81 +2,61 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import prompts from 'prompts';
|
|
4
4
|
import { toPascalCase } from '../../utils/contextUtils.js';
|
|
5
|
-
import {
|
|
6
|
-
import { loadUserConfig } from '../../utils/loadConfig.js';
|
|
5
|
+
import { selectWorkspace } from '../../utils/architecture.js';
|
|
7
6
|
import { writeIfNotExists } from '../../utils/fileUtils.js';
|
|
8
7
|
const createComponentContent = (propsName) => `<script lang="ts">
|
|
9
|
-
import type { ${propsName} } from './
|
|
8
|
+
import type { ${propsName} } from './Types';
|
|
10
9
|
const {}: ${propsName} = $props();
|
|
11
10
|
</script>
|
|
12
11
|
<!--Your HTML here-->
|
|
13
12
|
<style lang="scss">
|
|
14
|
-
\t@use './
|
|
13
|
+
\t@use './Style';
|
|
15
14
|
</style>
|
|
16
15
|
`;
|
|
17
16
|
const createTypesContent = (propsName) => `export interface ${propsName} {}
|
|
18
17
|
`;
|
|
19
18
|
const createIndexContent = (name) => `export { default as ${name} } from './Component.svelte';
|
|
20
19
|
`;
|
|
21
|
-
const printContextsError = () => {
|
|
22
|
-
console.error('❌ Cannot generate UI artifact: `contexts` is missing or empty in azure-net.config.ts/js');
|
|
23
|
-
};
|
|
24
|
-
const selectContext = async () => {
|
|
25
|
-
const config = await loadUserConfig();
|
|
26
|
-
const contexts = normalizeContexts(config.contexts);
|
|
27
|
-
if (!contexts.length) return null;
|
|
28
|
-
const { context } = await prompts({
|
|
29
|
-
type: 'select',
|
|
30
|
-
name: 'context',
|
|
31
|
-
message: 'Select context:',
|
|
32
|
-
choices: contexts.map((item) => ({ title: item.name, value: item.name })),
|
|
33
|
-
initial: 0
|
|
34
|
-
});
|
|
35
|
-
return context ? String(context) : null;
|
|
36
|
-
};
|
|
37
20
|
export default async function generateComponent() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
await writeIfNotExists(path.join(targetDir, 'types.ts'), createTypesContent(propsName));
|
|
80
|
-
await writeIfNotExists(path.join(targetDir, 'index.ts'), createIndexContent(name));
|
|
81
|
-
console.log(`✅ Component generated: ${targetDir}`);
|
|
21
|
+
const workspace = await selectWorkspace();
|
|
22
|
+
if (!workspace)
|
|
23
|
+
return;
|
|
24
|
+
const { rawName } = await prompts({
|
|
25
|
+
type: 'text',
|
|
26
|
+
name: 'rawName',
|
|
27
|
+
message: 'Component name:',
|
|
28
|
+
validate: (value) => (String(value).trim().length > 0 ? true : 'Name is required')
|
|
29
|
+
});
|
|
30
|
+
const { componentKind } = await prompts({
|
|
31
|
+
type: 'select',
|
|
32
|
+
name: 'componentKind',
|
|
33
|
+
message: 'Component kind:',
|
|
34
|
+
choices: [
|
|
35
|
+
{ title: 'shared', value: 'shared' },
|
|
36
|
+
{ title: 'layout', value: 'layout' },
|
|
37
|
+
{ title: 'page', value: 'page' }
|
|
38
|
+
],
|
|
39
|
+
initial: 0
|
|
40
|
+
});
|
|
41
|
+
const name = toPascalCase(String(rawName ?? 'Component')) || 'Component';
|
|
42
|
+
const propsName = `IComponent${name}Props`;
|
|
43
|
+
const kind = componentKind ?? 'shared';
|
|
44
|
+
let targetDir = path.join(workspace.path, 'Ui', 'Components', toPascalCase(kind));
|
|
45
|
+
if (kind === 'page') {
|
|
46
|
+
const { pageFolderRaw } = await prompts({
|
|
47
|
+
type: 'text',
|
|
48
|
+
name: 'pageFolderRaw',
|
|
49
|
+
message: 'Page folder name:',
|
|
50
|
+
validate: (value) => (String(value).trim().length > 0 ? true : 'Page folder name is required')
|
|
51
|
+
});
|
|
52
|
+
const pageFolder = toPascalCase(String(pageFolderRaw ?? 'Page')) || 'Page';
|
|
53
|
+
targetDir = path.join(targetDir, pageFolder);
|
|
54
|
+
}
|
|
55
|
+
targetDir = path.join(targetDir, name);
|
|
56
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
57
|
+
await writeIfNotExists(path.join(targetDir, 'Component.svelte'), createComponentContent(propsName));
|
|
58
|
+
await writeIfNotExists(path.join(targetDir, 'Style.scss'), '');
|
|
59
|
+
await writeIfNotExists(path.join(targetDir, 'Types.ts'), createTypesContent(propsName));
|
|
60
|
+
await writeIfNotExists(path.join(targetDir, 'index.ts'), createIndexContent(name));
|
|
61
|
+
console.log(`✅ Component generated: ${targetDir}`);
|
|
82
62
|
}
|
|
@@ -2,58 +2,38 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import prompts from 'prompts';
|
|
4
4
|
import { toPascalCase } from '../../utils/contextUtils.js';
|
|
5
|
-
import {
|
|
6
|
-
import { loadUserConfig } from '../../utils/loadConfig.js';
|
|
5
|
+
import { selectWorkspace } from '../../utils/architecture.js';
|
|
7
6
|
import { writeIfNotExists } from '../../utils/fileUtils.js';
|
|
8
7
|
const createComponentContent = (propsName) => `<script lang="ts">
|
|
9
|
-
import type { ${propsName} } from './
|
|
8
|
+
import type { ${propsName} } from './Types';
|
|
10
9
|
const {}: ${propsName} = $props();
|
|
11
10
|
</script>
|
|
12
11
|
<!--Your HTML here-->
|
|
13
12
|
<style lang="scss">
|
|
14
|
-
\t@use './
|
|
13
|
+
\t@use './Style';
|
|
15
14
|
</style>
|
|
16
15
|
`;
|
|
17
16
|
const createTypesContent = (propsName) => `export interface ${propsName} {}
|
|
18
17
|
`;
|
|
19
18
|
const createIndexContent = (name) => `export { default as ${name} } from './Component.svelte';
|
|
20
19
|
`;
|
|
21
|
-
const printContextsError = () => {
|
|
22
|
-
console.error('❌ Cannot generate UI artifact: `contexts` is missing or empty in azure-net.config.ts/js');
|
|
23
|
-
};
|
|
24
|
-
const selectContext = async () => {
|
|
25
|
-
const config = await loadUserConfig();
|
|
26
|
-
const contexts = normalizeContexts(config.contexts);
|
|
27
|
-
if (!contexts.length) return null;
|
|
28
|
-
const { context } = await prompts({
|
|
29
|
-
type: 'select',
|
|
30
|
-
name: 'context',
|
|
31
|
-
message: 'Select context:',
|
|
32
|
-
choices: contexts.map((item) => ({ title: item.name, value: item.name })),
|
|
33
|
-
initial: 0
|
|
34
|
-
});
|
|
35
|
-
return context ? String(context) : null;
|
|
36
|
-
};
|
|
37
20
|
export default async function generateDesignComponent() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
await writeIfNotExists(path.join(targetDir, 'types.ts'), createTypesContent(propsName));
|
|
57
|
-
await writeIfNotExists(path.join(targetDir, 'index.ts'), createIndexContent(name));
|
|
58
|
-
console.log(`✅ Design component generated: ${targetDir}`);
|
|
21
|
+
const workspace = await selectWorkspace();
|
|
22
|
+
if (!workspace)
|
|
23
|
+
return;
|
|
24
|
+
const { rawName } = await prompts({
|
|
25
|
+
type: 'text',
|
|
26
|
+
name: 'rawName',
|
|
27
|
+
message: 'Design component name:',
|
|
28
|
+
validate: (value) => (String(value).trim().length > 0 ? true : 'Name is required')
|
|
29
|
+
});
|
|
30
|
+
const name = toPascalCase(String(rawName ?? 'DesignComponent')) || 'DesignComponent';
|
|
31
|
+
const propsName = `IDesignComponent${name}Props`;
|
|
32
|
+
const targetDir = path.join(workspace.path, 'Ui', 'Design', name);
|
|
33
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
34
|
+
await writeIfNotExists(path.join(targetDir, 'Component.svelte'), createComponentContent(propsName));
|
|
35
|
+
await writeIfNotExists(path.join(targetDir, 'Style.scss'), '');
|
|
36
|
+
await writeIfNotExists(path.join(targetDir, 'Types.ts'), createTypesContent(propsName));
|
|
37
|
+
await writeIfNotExists(path.join(targetDir, 'index.ts'), createIndexContent(name));
|
|
38
|
+
console.log(`✅ Design component generated: ${targetDir}`);
|
|
59
39
|
}
|