@azure-net/cli 5.0.0-3 → 5.0.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/bin/azure-net.js +5 -46
- package/bin/azure-net.ts +5 -5
- package/package.json +1 -1
- package/src/checks/checkDomain.js +8 -38
- package/src/checks/checkFoldersStructure.js +0 -14
- package/src/checks/checkHooks.js +0 -5
- package/src/checks/checkImports.js +0 -1
- package/src/checks/checkInternal.js +0 -1
- package/src/checks/checkLayerBoundaries.js +50 -54
- package/src/checks/checkLayerBoundaries.ts +55 -58
- package/src/checks/checkPresenterNames.js +1 -37
- package/src/checks/checkPresenterNames.ts +1 -6
- package/src/checks/checkProject.js +0 -6
- package/src/checks/checkProviderGraph.js +1 -38
- package/src/checks/checkProviderNames.js +0 -28
- package/src/checks/index.js +0 -1
- package/src/generate/layers/generateRepository.js +4 -19
- package/src/generate/layers/generateRepositoryMethod.js +0 -12
- package/src/generate/layers/generateUseCases.js +0 -6
- package/src/generate/layers/repositoryShared.js +41 -104
- package/src/generate/layers/repositoryShared.ts +17 -12
- package/src/generate/module/generateDomain.js +0 -25
- package/src/generate/module/generateModule.js +0 -10
- package/src/generate/module/generateModulePreset.js +10 -51
- package/src/generate/module/generateModulePreset.ts +9 -8
- package/src/generate/module/generatePresenter.js +29 -76
- package/src/generate/module/generatePresenter.ts +15 -10
- package/src/generate/module/generateRepository.js +0 -17
- package/src/generate/module/generateSchemaFromType.js +9 -58
- package/src/generate/module/generateSchemaFromType.ts +1 -2
- package/src/generate/module/generateTypesJson.js +4 -45
- package/src/generate/module/generateUseCases.js +0 -9
- package/src/generate/module/repositoryModuleShared.js +21 -98
- package/src/generate/module/repositoryModuleShared.ts +14 -10
- package/src/generate/ui/generateComponent.js +0 -16
- package/src/generate/ui/generateDesignComponent.js +0 -12
- package/src/generate/ui/generateWidget.js +0 -12
- package/src/init/initAliases.js +42 -64
- package/src/init/initAliases.ts +47 -42
- package/src/init/initEdges.js +0 -15
- package/src/init/initStructure.js +48 -21
- package/src/init/initStructure.ts +51 -3
- package/src/install/installFresh.js +0 -16
- package/src/plugins/addLint.js +11 -46
- package/src/scaffolds/createCoreSchema.js +6 -40
- package/src/scaffolds/createCoreSchema.ts +6 -18
- package/src/scaffolds/createDatasource.js +26 -61
- package/src/scaffolds/createDatasource.ts +26 -40
- package/src/scaffolds/createDatasourceProvider.js +19 -56
- package/src/scaffolds/createDatasourceProvider.ts +20 -34
- package/src/scaffolds/createPresenterFactory.js +5 -34
- package/src/scaffolds/createPresenterFactory.ts +5 -17
- package/src/scaffolds/createProgram.js +1 -5
- package/src/scaffolds/createResponse.js +3 -11
- package/src/scaffolds/createResponse.ts +3 -1
- package/src/scaffolds/createSchemaRule.js +3 -8
- package/src/scaffolds/createSchemaRule.ts +3 -1
- package/src/scaffolds/createTranslationManager.js +3 -14
- package/src/scaffolds/createTranslationManager.ts +3 -1
- package/src/utils/contextUtils.js +5 -20
- package/src/utils/contextUtils.ts +2 -3
- package/src/utils/fileUtils.js +3 -38
- package/src/utils/fileUtils.ts +0 -26
- package/src/utils/loadConfig.js +1 -14
- package/src/utils/loadConfig.ts +1 -3
- package/src/utils/sharedFoundation.js +48 -0
- package/src/utils/sharedFoundation.ts +70 -0
|
@@ -5,7 +5,6 @@ import { toPascalCase } from '../../utils/contextUtils.js';
|
|
|
5
5
|
import { normalizeContexts } from '../../init/initAliases.js';
|
|
6
6
|
import { loadUserConfig } from '../../utils/loadConfig.js';
|
|
7
7
|
import { writeIfNotExists } from '../../utils/fileUtils.js';
|
|
8
|
-
|
|
9
8
|
const createComponentContent = (propsName) => `<script lang="ts">
|
|
10
9
|
import type { ${propsName} } from './types';
|
|
11
10
|
const {}: ${propsName} = $props();
|
|
@@ -15,22 +14,17 @@ const {}: ${propsName} = $props();
|
|
|
15
14
|
\t@use './style';
|
|
16
15
|
</style>
|
|
17
16
|
`;
|
|
18
|
-
|
|
19
17
|
const createTypesContent = (propsName) => `export interface ${propsName} {}
|
|
20
18
|
`;
|
|
21
|
-
|
|
22
19
|
const createIndexContent = (name) => `export { default as ${name} } from './Component.svelte';
|
|
23
20
|
`;
|
|
24
|
-
|
|
25
21
|
const printContextsError = () => {
|
|
26
22
|
console.error('❌ Cannot generate UI artifact: `contexts` is missing or empty in azure-net.config.ts/js');
|
|
27
23
|
};
|
|
28
|
-
|
|
29
24
|
const selectContext = async () => {
|
|
30
25
|
const config = await loadUserConfig();
|
|
31
26
|
const contexts = normalizeContexts(config.contexts);
|
|
32
27
|
if (!contexts.length) return null;
|
|
33
|
-
|
|
34
28
|
const { context } = await prompts({
|
|
35
29
|
type: 'select',
|
|
36
30
|
name: 'context',
|
|
@@ -38,10 +32,8 @@ const selectContext = async () => {
|
|
|
38
32
|
choices: contexts.map((item) => ({ title: item.name, value: item.name })),
|
|
39
33
|
initial: 0
|
|
40
34
|
});
|
|
41
|
-
|
|
42
35
|
return context ? String(context) : null;
|
|
43
36
|
};
|
|
44
|
-
|
|
45
37
|
export default async function generateDesignComponent() {
|
|
46
38
|
const context = await selectContext();
|
|
47
39
|
if (!context) {
|
|
@@ -49,23 +41,19 @@ export default async function generateDesignComponent() {
|
|
|
49
41
|
process.exitCode = 1;
|
|
50
42
|
return;
|
|
51
43
|
}
|
|
52
|
-
|
|
53
44
|
const { rawName } = await prompts({
|
|
54
45
|
type: 'text',
|
|
55
46
|
name: 'rawName',
|
|
56
47
|
message: 'Design component name:',
|
|
57
48
|
validate: (value) => (String(value).trim().length > 0 ? true : 'Name is required')
|
|
58
49
|
});
|
|
59
|
-
|
|
60
50
|
const name = toPascalCase(String(rawName ?? 'DesignComponent')) || 'DesignComponent';
|
|
61
51
|
const propsName = `IDesignComponent${name}Props`;
|
|
62
52
|
const targetDir = path.join(process.cwd(), 'src', 'app', context, 'ui', 'design', name);
|
|
63
|
-
|
|
64
53
|
await fs.mkdir(targetDir, { recursive: true });
|
|
65
54
|
await writeIfNotExists(path.join(targetDir, 'Component.svelte'), createComponentContent(propsName));
|
|
66
55
|
await writeIfNotExists(path.join(targetDir, 'style.scss'), '');
|
|
67
56
|
await writeIfNotExists(path.join(targetDir, 'types.ts'), createTypesContent(propsName));
|
|
68
57
|
await writeIfNotExists(path.join(targetDir, 'index.ts'), createIndexContent(name));
|
|
69
|
-
|
|
70
58
|
console.log(`✅ Design component generated: ${targetDir}`);
|
|
71
59
|
}
|
|
@@ -5,7 +5,6 @@ import { toPascalCase } from '../../utils/contextUtils.js';
|
|
|
5
5
|
import { normalizeContexts } from '../../init/initAliases.js';
|
|
6
6
|
import { loadUserConfig } from '../../utils/loadConfig.js';
|
|
7
7
|
import { writeIfNotExists } from '../../utils/fileUtils.js';
|
|
8
|
-
|
|
9
8
|
const createComponentContent = (propsName) => `<script lang="ts">
|
|
10
9
|
import type { ${propsName} } from './types';
|
|
11
10
|
const {}: ${propsName} = $props();
|
|
@@ -15,22 +14,17 @@ const {}: ${propsName} = $props();
|
|
|
15
14
|
\t@use './style';
|
|
16
15
|
</style>
|
|
17
16
|
`;
|
|
18
|
-
|
|
19
17
|
const createTypesContent = (propsName) => `export interface ${propsName} {}
|
|
20
18
|
`;
|
|
21
|
-
|
|
22
19
|
const createIndexContent = (name) => `export { default as ${name} } from './Component.svelte';
|
|
23
20
|
`;
|
|
24
|
-
|
|
25
21
|
const printContextsError = () => {
|
|
26
22
|
console.error('❌ Cannot generate UI artifact: `contexts` is missing or empty in azure-net.config.ts/js');
|
|
27
23
|
};
|
|
28
|
-
|
|
29
24
|
const selectContext = async () => {
|
|
30
25
|
const config = await loadUserConfig();
|
|
31
26
|
const contexts = normalizeContexts(config.contexts);
|
|
32
27
|
if (!contexts.length) return null;
|
|
33
|
-
|
|
34
28
|
const { context } = await prompts({
|
|
35
29
|
type: 'select',
|
|
36
30
|
name: 'context',
|
|
@@ -38,10 +32,8 @@ const selectContext = async () => {
|
|
|
38
32
|
choices: contexts.map((item) => ({ title: item.name, value: item.name })),
|
|
39
33
|
initial: 0
|
|
40
34
|
});
|
|
41
|
-
|
|
42
35
|
return context ? String(context) : null;
|
|
43
36
|
};
|
|
44
|
-
|
|
45
37
|
export default async function generateWidget() {
|
|
46
38
|
const context = await selectContext();
|
|
47
39
|
if (!context) {
|
|
@@ -49,23 +41,19 @@ export default async function generateWidget() {
|
|
|
49
41
|
process.exitCode = 1;
|
|
50
42
|
return;
|
|
51
43
|
}
|
|
52
|
-
|
|
53
44
|
const { rawName } = await prompts({
|
|
54
45
|
type: 'text',
|
|
55
46
|
name: 'rawName',
|
|
56
47
|
message: 'Widget name:',
|
|
57
48
|
validate: (value) => (String(value).trim().length > 0 ? true : 'Name is required')
|
|
58
49
|
});
|
|
59
|
-
|
|
60
50
|
const name = toPascalCase(String(rawName ?? 'Widget')) || 'Widget';
|
|
61
51
|
const propsName = `IWidget${name}Props`;
|
|
62
52
|
const targetDir = path.join(process.cwd(), 'src', 'app', context, 'ui', 'widgets', name);
|
|
63
|
-
|
|
64
53
|
await fs.mkdir(targetDir, { recursive: true });
|
|
65
54
|
await writeIfNotExists(path.join(targetDir, 'Component.svelte'), createComponentContent(propsName));
|
|
66
55
|
await writeIfNotExists(path.join(targetDir, 'style.scss'), '');
|
|
67
56
|
await writeIfNotExists(path.join(targetDir, 'types.ts'), createTypesContent(propsName));
|
|
68
57
|
await writeIfNotExists(path.join(targetDir, 'index.ts'), createIndexContent(name));
|
|
69
|
-
|
|
70
58
|
console.log(`✅ Widget generated: ${targetDir}`);
|
|
71
59
|
}
|
package/src/init/initAliases.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { loadUserConfig
|
|
4
|
-
|
|
3
|
+
import { loadUserConfig } from '../utils/loadConfig.js';
|
|
5
4
|
const svelteConfigPath = path.resolve('svelte.config.js');
|
|
6
|
-
|
|
7
5
|
function normalizeAliasValue(value, fallbackName) {
|
|
8
6
|
const raw = String(value ?? '').trim();
|
|
9
7
|
if (!raw.length) return `$${fallbackName}`;
|
|
10
8
|
return raw.startsWith('$') ? raw : `$${raw}`;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
export function normalizeContexts(rawContexts) {
|
|
14
11
|
if (!Array.isArray(rawContexts)) return [];
|
|
15
|
-
|
|
16
12
|
return rawContexts
|
|
17
13
|
.map((item) => {
|
|
18
14
|
if (typeof item === 'string') {
|
|
@@ -20,81 +16,90 @@ export function normalizeContexts(rawContexts) {
|
|
|
20
16
|
if (!name.length) return null;
|
|
21
17
|
return { name, alias: `$${name}` };
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
if (!item || typeof item !== 'object') return null;
|
|
25
|
-
|
|
26
20
|
const name = String(item.name ?? '').trim();
|
|
27
21
|
if (!name.length) return null;
|
|
28
|
-
|
|
29
22
|
return {
|
|
30
23
|
name,
|
|
31
24
|
alias: normalizeAliasValue(item.alias, name)
|
|
32
25
|
};
|
|
33
26
|
})
|
|
34
|
-
.filter(
|
|
27
|
+
.filter((item) => item !== null);
|
|
35
28
|
}
|
|
36
|
-
|
|
37
29
|
export function generateAliases(config) {
|
|
38
|
-
const coreAlias = normalizeAliasValue(config.coreAlias, 'core');
|
|
39
30
|
const contexts = normalizeContexts(config.contexts);
|
|
40
|
-
|
|
41
31
|
const entries = [];
|
|
42
32
|
for (const context of contexts) {
|
|
43
33
|
entries.push([context.alias, `./src/app/${context.name}`]);
|
|
44
34
|
}
|
|
45
|
-
|
|
46
|
-
entries.push([coreAlias, './src/core']);
|
|
47
|
-
|
|
48
35
|
return {
|
|
49
|
-
coreAlias,
|
|
50
36
|
contexts,
|
|
51
37
|
aliases: Object.fromEntries(entries)
|
|
52
38
|
};
|
|
53
39
|
}
|
|
54
|
-
|
|
55
40
|
function parseAliasEntries(aliasBody) {
|
|
56
41
|
const entryRegex = /(['"`])([^'"`]+)\1\s*:\s*(['"`])([^'"`]+)\3\s*,?/g;
|
|
57
42
|
const ordered = [];
|
|
58
43
|
const map = new Map();
|
|
59
44
|
let match;
|
|
60
|
-
|
|
61
45
|
while ((match = entryRegex.exec(aliasBody)) !== null) {
|
|
62
46
|
const key = match[2];
|
|
63
47
|
const value = match[4];
|
|
48
|
+
if (!key || !value) continue;
|
|
64
49
|
if (!map.has(key)) {
|
|
65
50
|
ordered.push(key);
|
|
66
51
|
}
|
|
67
52
|
map.set(key, value);
|
|
68
53
|
}
|
|
69
|
-
|
|
70
54
|
return { ordered, map };
|
|
71
55
|
}
|
|
72
|
-
|
|
73
56
|
function buildAliasEntriesString(orderedKeys, map, baseIndent) {
|
|
74
57
|
if (!orderedKeys.length) return '';
|
|
75
|
-
|
|
76
|
-
return orderedKeys.map((key) => `${baseIndent}'${key}': '${map.get(key)}'`).join(',\n');
|
|
58
|
+
return orderedKeys.map((key) => `${baseIndent}'${key}': '${map.get(key) ?? ''}'`).join(',\n');
|
|
77
59
|
}
|
|
78
|
-
|
|
60
|
+
function removeAliasEntry(content, alias) {
|
|
61
|
+
const escapedAlias = alias.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
62
|
+
const aliasRegex = new RegExp(`\\n?\\s*['"\`]${escapedAlias}['"\`]\\s*:\\s*['"\`][^'"\`]+['"\`]\\s*,?`, 'g');
|
|
63
|
+
return content.replace(aliasRegex, '');
|
|
64
|
+
}
|
|
65
|
+
const removeCoreAliasFromAzureNetConfig = async () => {
|
|
66
|
+
const tsPath = path.resolve('azure-net.config.ts');
|
|
67
|
+
const jsPath = path.resolve('azure-net.config.js');
|
|
68
|
+
let filepath = null;
|
|
69
|
+
try {
|
|
70
|
+
await fs.access(tsPath);
|
|
71
|
+
filepath = tsPath;
|
|
72
|
+
} catch {
|
|
73
|
+
try {
|
|
74
|
+
await fs.access(jsPath);
|
|
75
|
+
filepath = jsPath;
|
|
76
|
+
} catch {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const content = await fs.readFile(filepath, 'utf-8');
|
|
81
|
+
if (!/coreAlias\s*:/.test(content)) return;
|
|
82
|
+
const nextContent = content.replace(/\n?\s*coreAlias\s*:\s*['"`][^'"`]+['"`]\s*,?/m, '').replace(/,\s*\n\s*\}/m, '\n}');
|
|
83
|
+
await fs.writeFile(filepath, nextContent, 'utf-8');
|
|
84
|
+
};
|
|
79
85
|
export function mergeAliasesInSvelteConfig(content, aliases) {
|
|
80
86
|
const aliasRegex = /alias\s*:\s*\{([\s\S]*?)\}/m;
|
|
81
87
|
const aliasMatch = content.match(aliasRegex);
|
|
82
|
-
|
|
83
88
|
if (aliasMatch) {
|
|
84
89
|
const aliasBody = aliasMatch[1] ?? '';
|
|
85
90
|
const { ordered, map } = parseAliasEntries(aliasBody);
|
|
91
|
+
map.delete('$core');
|
|
86
92
|
for (const [key, value] of Object.entries(aliases)) {
|
|
87
93
|
if (!map.has(key)) ordered.push(key);
|
|
88
94
|
map.set(key, value);
|
|
89
95
|
}
|
|
90
|
-
|
|
96
|
+
const nextOrdered = ordered.filter((key) => key !== '$core');
|
|
91
97
|
const baseIndentMatch = aliasBody.match(/\n(\s*)['"`]/);
|
|
92
98
|
const baseIndent = baseIndentMatch?.[1] ?? '\t\t\t';
|
|
93
|
-
const merged = buildAliasEntriesString(
|
|
99
|
+
const merged = buildAliasEntriesString(nextOrdered, map, baseIndent);
|
|
94
100
|
const nextAliasBlock = `alias: {\n${merged}\n\t\t}`;
|
|
95
101
|
return content.replace(aliasRegex, nextAliasBlock);
|
|
96
102
|
}
|
|
97
|
-
|
|
98
103
|
const kitRegex = /kit\s*:\s*\{/m;
|
|
99
104
|
if (kitRegex.test(content)) {
|
|
100
105
|
const aliasLines = Object.entries(aliases)
|
|
@@ -103,48 +108,22 @@ export function mergeAliasesInSvelteConfig(content, aliases) {
|
|
|
103
108
|
const aliasBlock = `alias: {\n${aliasLines}\n\t\t},`;
|
|
104
109
|
return content.replace(kitRegex, `kit: {\n\t\t${aliasBlock}`);
|
|
105
110
|
}
|
|
106
|
-
|
|
107
111
|
return `${content}\n\n// azure-net aliases\nconst alias = {\n${Object.entries(aliases)
|
|
108
112
|
.map(([key, value]) => `\t'${key}': '${value}'`)
|
|
109
113
|
.join(',\n')}\n};\n`;
|
|
110
114
|
}
|
|
111
|
-
|
|
112
|
-
function upsertCoreAlias(content, coreAlias) {
|
|
113
|
-
const exportDefaultRegex = /export\s+default\s*\{([\s\S]*)\}\s*;?/m;
|
|
114
|
-
if (!exportDefaultRegex.test(content)) {
|
|
115
|
-
return `export default {\n\tcoreAlias: '${coreAlias}'\n};\n`;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (/coreAlias\s*:/.test(content)) {
|
|
119
|
-
return content.replace(/coreAlias\s*:\s*['"`][^'"`]+['"`]/, `coreAlias: '${coreAlias}'`);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return content.replace(exportDefaultRegex, (_full, body) => {
|
|
123
|
-
const trimmed = body.replace(/\s*$/, '');
|
|
124
|
-
if (!trimmed.length) {
|
|
125
|
-
return `export default {\n\tcoreAlias: '${coreAlias}'\n};`;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const withComma = trimmed.endsWith(',') ? trimmed : `${trimmed},`;
|
|
129
|
-
return `export default {${withComma}\n\tcoreAlias: '${coreAlias}'\n};`;
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export async function ensureCoreAliasInConfig(coreAlias) {
|
|
134
|
-
const { exists, filepath } = resolveConfigFile();
|
|
135
|
-
const aliasToSave = normalizeAliasValue(coreAlias, 'core');
|
|
136
|
-
const currentContent = exists ? await fs.readFile(filepath, 'utf-8') : '';
|
|
137
|
-
const nextContent = upsertCoreAlias(currentContent, aliasToSave);
|
|
138
|
-
await fs.writeFile(filepath, nextContent, 'utf-8');
|
|
139
|
-
return aliasToSave;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
115
|
export default async function initAliases() {
|
|
143
116
|
const config = await loadUserConfig();
|
|
117
|
+
const sharedAlias = String(config.sharedAlias ?? '').trim();
|
|
118
|
+
if (!sharedAlias.length) {
|
|
119
|
+
console.error('❌ Cannot update aliases: `sharedAlias` is missing in azure-net.config.ts/js.');
|
|
120
|
+
console.error("Add it first, for example: sharedAlias: '$shared-kernel'");
|
|
121
|
+
process.exitCode = 1;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
144
124
|
const generated = generateAliases(config);
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
125
|
+
const aliases = generated.aliases;
|
|
126
|
+
await removeCoreAliasFromAzureNetConfig();
|
|
148
127
|
let content;
|
|
149
128
|
try {
|
|
150
129
|
content = await fs.readFile(svelteConfigPath, 'utf-8');
|
|
@@ -152,8 +131,7 @@ export default async function initAliases() {
|
|
|
152
131
|
console.warn('⚠️ svelte.config.js not found, aliases were not updated');
|
|
153
132
|
return;
|
|
154
133
|
}
|
|
155
|
-
|
|
156
|
-
const nextContent = mergeAliasesInSvelteConfig(content, aliases);
|
|
134
|
+
const nextContent = removeAliasEntry(mergeAliasesInSvelteConfig(content, aliases), '$core');
|
|
157
135
|
await fs.writeFile(svelteConfigPath, nextContent, 'utf-8');
|
|
158
136
|
console.log('✅ Aliases updated in svelte.config.js');
|
|
159
137
|
}
|
package/src/init/initAliases.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { loadUserConfig
|
|
3
|
+
import { loadUserConfig } from '../utils/loadConfig.js';
|
|
4
4
|
|
|
5
5
|
const svelteConfigPath = path.resolve('svelte.config.js');
|
|
6
6
|
|
|
@@ -37,12 +37,10 @@ export function normalizeContexts(rawContexts: unknown): ContextConfig[] {
|
|
|
37
37
|
.filter((item): item is ContextConfig => item !== null);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export function generateAliases(config: {
|
|
41
|
-
coreAlias: string;
|
|
40
|
+
export function generateAliases(config: { contexts?: unknown }): {
|
|
42
41
|
contexts: ContextConfig[];
|
|
43
42
|
aliases: Record<string, string>;
|
|
44
43
|
} {
|
|
45
|
-
const coreAlias = normalizeAliasValue(config.coreAlias, 'core');
|
|
46
44
|
const contexts = normalizeContexts(config.contexts);
|
|
47
45
|
|
|
48
46
|
const entries: Array<[string, string]> = [];
|
|
@@ -50,10 +48,7 @@ export function generateAliases(config: { coreAlias?: string; contexts?: unknown
|
|
|
50
48
|
entries.push([context.alias, `./src/app/${context.name}`]);
|
|
51
49
|
}
|
|
52
50
|
|
|
53
|
-
entries.push([coreAlias, './src/core']);
|
|
54
|
-
|
|
55
51
|
return {
|
|
56
|
-
coreAlias,
|
|
57
52
|
contexts,
|
|
58
53
|
aliases: Object.fromEntries(entries)
|
|
59
54
|
};
|
|
@@ -84,6 +79,36 @@ function buildAliasEntriesString(orderedKeys: string[], map: Map<string, string>
|
|
|
84
79
|
return orderedKeys.map((key) => `${baseIndent}'${key}': '${map.get(key) ?? ''}'`).join(',\n');
|
|
85
80
|
}
|
|
86
81
|
|
|
82
|
+
function removeAliasEntry(content: string, alias: string): string {
|
|
83
|
+
const escapedAlias = alias.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
84
|
+
const aliasRegex = new RegExp(`\\n?\\s*['"\`]${escapedAlias}['"\`]\\s*:\\s*['"\`][^'"\`]+['"\`]\\s*,?`, 'g');
|
|
85
|
+
return content.replace(aliasRegex, '');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const removeCoreAliasFromAzureNetConfig = async (): Promise<void> => {
|
|
89
|
+
const tsPath = path.resolve('azure-net.config.ts');
|
|
90
|
+
const jsPath = path.resolve('azure-net.config.js');
|
|
91
|
+
let filepath: string | null = null;
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
await fs.access(tsPath);
|
|
95
|
+
filepath = tsPath;
|
|
96
|
+
} catch {
|
|
97
|
+
try {
|
|
98
|
+
await fs.access(jsPath);
|
|
99
|
+
filepath = jsPath;
|
|
100
|
+
} catch {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const content = await fs.readFile(filepath, 'utf-8');
|
|
106
|
+
if (!/coreAlias\s*:/.test(content)) return;
|
|
107
|
+
|
|
108
|
+
const nextContent = content.replace(/\n?\s*coreAlias\s*:\s*['"`][^'"`]+['"`]\s*,?/m, '').replace(/,\s*\n\s*\}/m, '\n}');
|
|
109
|
+
await fs.writeFile(filepath, nextContent, 'utf-8');
|
|
110
|
+
};
|
|
111
|
+
|
|
87
112
|
export function mergeAliasesInSvelteConfig(content: string, aliases: Record<string, string>): string {
|
|
88
113
|
const aliasRegex = /alias\s*:\s*\{([\s\S]*?)\}/m;
|
|
89
114
|
const aliasMatch = content.match(aliasRegex);
|
|
@@ -91,14 +116,16 @@ export function mergeAliasesInSvelteConfig(content: string, aliases: Record<stri
|
|
|
91
116
|
if (aliasMatch) {
|
|
92
117
|
const aliasBody = aliasMatch[1] ?? '';
|
|
93
118
|
const { ordered, map } = parseAliasEntries(aliasBody);
|
|
119
|
+
map.delete('$core');
|
|
94
120
|
for (const [key, value] of Object.entries(aliases)) {
|
|
95
121
|
if (!map.has(key)) ordered.push(key);
|
|
96
122
|
map.set(key, value);
|
|
97
123
|
}
|
|
124
|
+
const nextOrdered = ordered.filter((key) => key !== '$core');
|
|
98
125
|
|
|
99
126
|
const baseIndentMatch = aliasBody.match(/\n(\s*)['"`]/);
|
|
100
127
|
const baseIndent = baseIndentMatch?.[1] ?? '\t\t\t';
|
|
101
|
-
const merged = buildAliasEntriesString(
|
|
128
|
+
const merged = buildAliasEntriesString(nextOrdered, map, baseIndent);
|
|
102
129
|
const nextAliasBlock = `alias: {\n${merged}\n\t\t}`;
|
|
103
130
|
return content.replace(aliasRegex, nextAliasBlock);
|
|
104
131
|
}
|
|
@@ -117,41 +144,19 @@ export function mergeAliasesInSvelteConfig(content: string, aliases: Record<stri
|
|
|
117
144
|
.join(',\n')}\n};\n`;
|
|
118
145
|
}
|
|
119
146
|
|
|
120
|
-
function upsertCoreAlias(content: string, coreAlias: string): string {
|
|
121
|
-
const exportDefaultRegex = /export\s+default\s*\{([\s\S]*)\}\s*;?/m;
|
|
122
|
-
if (!exportDefaultRegex.test(content)) {
|
|
123
|
-
return `export default {\n\tcoreAlias: '${coreAlias}'\n};\n`;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (/coreAlias\s*:/.test(content)) {
|
|
127
|
-
return content.replace(/coreAlias\s*:\s*['"`][^'"`]+['"`]/, `coreAlias: '${coreAlias}'`);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return content.replace(exportDefaultRegex, (_full, body: string) => {
|
|
131
|
-
const trimmed = body.replace(/\s*$/, '');
|
|
132
|
-
if (!trimmed.length) {
|
|
133
|
-
return `export default {\n\tcoreAlias: '${coreAlias}'\n};`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const withComma = trimmed.endsWith(',') ? trimmed : `${trimmed},`;
|
|
137
|
-
return `export default {${withComma}\n\tcoreAlias: '${coreAlias}'\n};`;
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export async function ensureCoreAliasInConfig(coreAlias: string): Promise<string> {
|
|
142
|
-
const { exists, filepath } = resolveConfigFile();
|
|
143
|
-
const aliasToSave = normalizeAliasValue(coreAlias, 'core');
|
|
144
|
-
const currentContent = exists ? await fs.readFile(filepath, 'utf-8') : '';
|
|
145
|
-
const nextContent = upsertCoreAlias(currentContent, aliasToSave);
|
|
146
|
-
await fs.writeFile(filepath, nextContent, 'utf-8');
|
|
147
|
-
return aliasToSave;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
147
|
export default async function initAliases(): Promise<void> {
|
|
151
148
|
const config = await loadUserConfig();
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
149
|
+
const sharedAlias = String(config.sharedAlias ?? '').trim();
|
|
150
|
+
if (!sharedAlias.length) {
|
|
151
|
+
console.error('❌ Cannot update aliases: `sharedAlias` is missing in azure-net.config.ts/js.');
|
|
152
|
+
console.error("Add it first, for example: sharedAlias: '$shared-kernel'");
|
|
153
|
+
process.exitCode = 1;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const generated = generateAliases(config as { contexts?: unknown });
|
|
158
|
+
const aliases = generated.aliases;
|
|
159
|
+
await removeCoreAliasFromAzureNetConfig();
|
|
155
160
|
|
|
156
161
|
let content: string;
|
|
157
162
|
try {
|
|
@@ -161,7 +166,7 @@ export default async function initAliases(): Promise<void> {
|
|
|
161
166
|
return;
|
|
162
167
|
}
|
|
163
168
|
|
|
164
|
-
const nextContent = mergeAliasesInSvelteConfig(content, aliases);
|
|
169
|
+
const nextContent = removeAliasEntry(mergeAliasesInSvelteConfig(content, aliases), '$core');
|
|
165
170
|
await fs.writeFile(svelteConfigPath, nextContent, 'utf-8');
|
|
166
171
|
console.log('✅ Aliases updated in svelte.config.js');
|
|
167
172
|
}
|
package/src/init/initEdges.js
CHANGED
|
@@ -1,45 +1,34 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import fsSync from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
|
|
5
4
|
const EDGES_IMPORT = `import { edgesPlugin } from '@azure-net/kit/edges/plugin';`;
|
|
6
|
-
|
|
7
5
|
function resolveViteConfigPath() {
|
|
8
6
|
const cwd = process.cwd();
|
|
9
7
|
const candidates = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs', 'vite.config.cjs'].map((filename) => path.join(cwd, filename));
|
|
10
|
-
|
|
11
8
|
for (const filepath of candidates) {
|
|
12
9
|
if (fsSync.existsSync(filepath)) {
|
|
13
10
|
return filepath;
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
return null;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
function injectEdgesImport(content) {
|
|
21
16
|
if (content.includes(EDGES_IMPORT)) return content;
|
|
22
|
-
|
|
23
17
|
const svelteImportRegex = /import\s+\{\s*sveltekit\s*\}\s+from\s+['"]@sveltejs\/kit\/vite['"]\s*;?/m;
|
|
24
18
|
if (svelteImportRegex.test(content)) {
|
|
25
19
|
return content.replace(svelteImportRegex, (line) => `${line}\n${EDGES_IMPORT}`);
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
return `${EDGES_IMPORT}\n${content}`;
|
|
29
22
|
}
|
|
30
|
-
|
|
31
23
|
function injectEdgesPlugin(content) {
|
|
32
24
|
if (/edgesPlugin\s*\(\s*\)/.test(content)) return content;
|
|
33
|
-
|
|
34
25
|
const pluginsRegex = /plugins\s*:\s*\[([\s\S]*?)\]/m;
|
|
35
26
|
const pluginsMatch = content.match(pluginsRegex);
|
|
36
27
|
if (!pluginsMatch) {
|
|
37
28
|
throw new Error('plugins array was not found in vite.config');
|
|
38
29
|
}
|
|
39
|
-
|
|
40
30
|
const pluginsBody = pluginsMatch[1] ?? '';
|
|
41
31
|
let nextPluginsBody = pluginsBody;
|
|
42
|
-
|
|
43
32
|
if (/sveltekit\s*\(\s*\)/.test(pluginsBody)) {
|
|
44
33
|
nextPluginsBody = pluginsBody.replace(/sveltekit\s*\(\s*\)\s*,?/, (matched) => {
|
|
45
34
|
const hasComma = matched.trim().endsWith(',');
|
|
@@ -54,21 +43,17 @@ function injectEdgesPlugin(content) {
|
|
|
54
43
|
nextPluginsBody = `${withComma} edgesPlugin()`;
|
|
55
44
|
}
|
|
56
45
|
}
|
|
57
|
-
|
|
58
46
|
return content.replace(pluginsRegex, `plugins: [${nextPluginsBody}]`);
|
|
59
47
|
}
|
|
60
|
-
|
|
61
48
|
export default async function initEdges() {
|
|
62
49
|
const viteConfigPath = resolveViteConfigPath();
|
|
63
50
|
if (!viteConfigPath) {
|
|
64
51
|
console.error('❌ vite.config.(ts|js|mjs|cjs) was not found');
|
|
65
52
|
return;
|
|
66
53
|
}
|
|
67
|
-
|
|
68
54
|
let content = await fs.readFile(viteConfigPath, 'utf-8');
|
|
69
55
|
content = injectEdgesImport(content);
|
|
70
56
|
content = injectEdgesPlugin(content);
|
|
71
57
|
await fs.writeFile(viteConfigPath, content, 'utf-8');
|
|
72
|
-
|
|
73
58
|
console.log(`✅ Edges plugin initialized in ${path.basename(viteConfigPath)}`);
|
|
74
59
|
}
|