@azure-net/cli 5.1.1 → 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 +4 -7
- 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 -275
- 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
package/src/init/initEdges.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import fsSync from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
const EDGES_IMPORT = `import { edgesPlugin } from '@azure-net/kit/edges/plugin';`;
|
|
6
|
-
|
|
7
|
-
function resolveViteConfigPath(): string | null {
|
|
8
|
-
const cwd = process.cwd();
|
|
9
|
-
const candidates = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs', 'vite.config.cjs'].map((filename) => path.join(cwd, filename));
|
|
10
|
-
|
|
11
|
-
for (const filepath of candidates) {
|
|
12
|
-
if (fsSync.existsSync(filepath)) {
|
|
13
|
-
return filepath;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function injectEdgesImport(content: string): string {
|
|
21
|
-
if (content.includes(EDGES_IMPORT)) return content;
|
|
22
|
-
|
|
23
|
-
const svelteImportRegex = /import\s+\{\s*sveltekit\s*\}\s+from\s+['"]@sveltejs\/kit\/vite['"]\s*;?/m;
|
|
24
|
-
if (svelteImportRegex.test(content)) {
|
|
25
|
-
return content.replace(svelteImportRegex, (line) => `${line}\n${EDGES_IMPORT}`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return `${EDGES_IMPORT}\n${content}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function injectEdgesPlugin(content: string): string {
|
|
32
|
-
if (/edgesPlugin\s*\(\s*\)/.test(content)) return content;
|
|
33
|
-
|
|
34
|
-
const pluginsRegex = /plugins\s*:\s*\[([\s\S]*?)\]/m;
|
|
35
|
-
const pluginsMatch = content.match(pluginsRegex);
|
|
36
|
-
if (!pluginsMatch) {
|
|
37
|
-
throw new Error('plugins array was not found in vite.config');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const pluginsBody = pluginsMatch[1] ?? '';
|
|
41
|
-
let nextPluginsBody = pluginsBody;
|
|
42
|
-
|
|
43
|
-
if (/sveltekit\s*\(\s*\)/.test(pluginsBody)) {
|
|
44
|
-
nextPluginsBody = pluginsBody.replace(/sveltekit\s*\(\s*\)\s*,?/, (matched) => {
|
|
45
|
-
const hasComma = matched.trim().endsWith(',');
|
|
46
|
-
return hasComma ? `${matched} edgesPlugin(),` : `${matched}, edgesPlugin()`;
|
|
47
|
-
});
|
|
48
|
-
} else {
|
|
49
|
-
const trimmed = pluginsBody.trim();
|
|
50
|
-
if (!trimmed.length) {
|
|
51
|
-
nextPluginsBody = 'edgesPlugin()';
|
|
52
|
-
} else {
|
|
53
|
-
const withComma = /\s*,\s*$/.test(pluginsBody) ? pluginsBody : `${pluginsBody},`;
|
|
54
|
-
nextPluginsBody = `${withComma} edgesPlugin()`;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return content.replace(pluginsRegex, `plugins: [${nextPluginsBody}]`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export default async function initEdges(): Promise<void> {
|
|
62
|
-
const viteConfigPath = resolveViteConfigPath();
|
|
63
|
-
if (!viteConfigPath) {
|
|
64
|
-
console.error('❌ vite.config.(ts|js|mjs|cjs) was not found');
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let content = await fs.readFile(viteConfigPath, 'utf-8');
|
|
69
|
-
content = injectEdgesImport(content);
|
|
70
|
-
content = injectEdgesPlugin(content);
|
|
71
|
-
await fs.writeFile(viteConfigPath, content, 'utf-8');
|
|
72
|
-
|
|
73
|
-
console.log(`✅ Edges plugin initialized in ${path.basename(viteConfigPath)}`);
|
|
74
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { loadUserConfig } from '../utils/loadConfig.js';
|
|
4
|
-
import initAliases, { normalizeContexts } from './initAliases.js';
|
|
5
|
-
import { getSharedEssentialsPath } from '../utils/sharedFoundation.js';
|
|
6
|
-
|
|
7
|
-
type ContextConfig = { name: string; alias: string };
|
|
8
|
-
|
|
9
|
-
const ROOT = path.join(process.cwd(), 'src');
|
|
10
|
-
const APP_ROOT = path.join(ROOT, 'app');
|
|
11
|
-
|
|
12
|
-
const CONTEXT_DIRS = [
|
|
13
|
-
'ui',
|
|
14
|
-
'layers',
|
|
15
|
-
'layers/domain',
|
|
16
|
-
'layers/application',
|
|
17
|
-
'layers/application/providers',
|
|
18
|
-
'layers/application/use-cases',
|
|
19
|
-
'layers/infrastructure',
|
|
20
|
-
'layers/infrastructure/providers',
|
|
21
|
-
'layers/infrastructure/http',
|
|
22
|
-
'layers/infrastructure/http/repositories',
|
|
23
|
-
'layers/presentation'
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
const SHARED_ESSENTIALS_DIRS = [
|
|
27
|
-
'',
|
|
28
|
-
'foundation',
|
|
29
|
-
'foundation/constructs',
|
|
30
|
-
'foundation/constructs/datasource',
|
|
31
|
-
'foundation/constructs/presenter',
|
|
32
|
-
'foundation/constructs/provider',
|
|
33
|
-
'foundation/constructs/response',
|
|
34
|
-
'foundation/constructs/schema',
|
|
35
|
-
'foundation/constructs/schema/custom-rules',
|
|
36
|
-
'localization',
|
|
37
|
-
'pipelines'
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
const ensureDir = async (dirPath: string): Promise<void> => {
|
|
41
|
-
try {
|
|
42
|
-
await fs.mkdir(dirPath, { recursive: true });
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.warn(`⚠️ Failed to create directory: ${dirPath}`, error);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const ensureFile = async (filePath: string, content: string): Promise<void> => {
|
|
49
|
-
try {
|
|
50
|
-
await fs.access(filePath);
|
|
51
|
-
return;
|
|
52
|
-
} catch {
|
|
53
|
-
// File is missing
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
58
|
-
await fs.writeFile(filePath, content, 'utf-8');
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.warn(`⚠️ Failed to create file: ${filePath}`, error);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const toPascalCase = (value: string): string =>
|
|
65
|
-
value
|
|
66
|
-
.split(/[-_\s]+/)
|
|
67
|
-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
68
|
-
.join('');
|
|
69
|
-
|
|
70
|
-
const createInfrastructureProvider = (contextName: string) => `import { createBoundaryProvider } from '@azure-net/kit';
|
|
71
|
-
|
|
72
|
-
export const ${contextName}InfrastructureProvider = createBoundaryProvider('${contextName}InfrastructureProvider', {
|
|
73
|
-
\tregister: () => ({})
|
|
74
|
-
});
|
|
75
|
-
`;
|
|
76
|
-
|
|
77
|
-
const createApplicationProvider = (contextName: string) => `import { createBoundaryProvider } from '@azure-net/kit';
|
|
78
|
-
import { ${contextName}InfrastructureProvider } from '../../infrastructure/providers';
|
|
79
|
-
|
|
80
|
-
export const ${contextName}ApplicationProvider = createBoundaryProvider('${contextName}ApplicationProvider', {
|
|
81
|
-
\tdependsOn: { ${contextName}InfrastructureProvider },
|
|
82
|
-
\tregister: () => ({})
|
|
83
|
-
});
|
|
84
|
-
`;
|
|
85
|
-
|
|
86
|
-
const printContextsError = () => {
|
|
87
|
-
console.error('❌ Cannot generate folders structure: `contexts` is missing or empty in azure-net.config.ts/js');
|
|
88
|
-
console.error('Add contexts first, for example:');
|
|
89
|
-
console.error('export default {');
|
|
90
|
-
console.error("\tcontexts: ['web', 'admin']");
|
|
91
|
-
console.error('\t// or');
|
|
92
|
-
console.error("\t// contexts: [{ name: 'web', alias: '$web' }, { name: 'admin', alias: '$admin' }]");
|
|
93
|
-
console.error('};');
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const printSharedAliasError = () => {
|
|
97
|
-
console.error('❌ Cannot generate folders structure: `sharedAlias` is missing in azure-net.config.ts/js');
|
|
98
|
-
console.error('Add shared context and alias first, for example:');
|
|
99
|
-
console.error('export default {');
|
|
100
|
-
console.error("\tsharedAlias: '$shared-kernel',");
|
|
101
|
-
console.error("\tcontexts: [{ name: 'shared-kernel', alias: '$shared-kernel' }, 'public']");
|
|
102
|
-
console.error('};');
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const ensureSharedEssentialsStructure = async (contexts: ContextConfig[], sharedAlias: string): Promise<boolean> => {
|
|
106
|
-
const normalizedSharedAlias = sharedAlias.startsWith('$') ? sharedAlias : `$${sharedAlias}`;
|
|
107
|
-
const sharedContext = contexts.find((context) => context.alias === normalizedSharedAlias);
|
|
108
|
-
|
|
109
|
-
if (!sharedContext) {
|
|
110
|
-
console.error(`❌ sharedAlias "${normalizedSharedAlias}" does not point to any configured context.`);
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const essentialsRoot = getSharedEssentialsPath(sharedContext.name);
|
|
115
|
-
for (const dir of SHARED_ESSENTIALS_DIRS) {
|
|
116
|
-
await ensureDir(path.join(essentialsRoot, dir));
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return true;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const ensureContextStructure = async (context: ContextConfig): Promise<void> => {
|
|
123
|
-
const contextRoot = path.join(APP_ROOT, context.name);
|
|
124
|
-
for (const dir of CONTEXT_DIRS) {
|
|
125
|
-
await ensureDir(path.join(contextRoot, dir));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const contextName = toPascalCase(context.name);
|
|
129
|
-
const infraProviderPath = path.join(contextRoot, 'layers', 'infrastructure', 'providers', 'InfrastructureProvider.ts');
|
|
130
|
-
const infraProviderIndex = path.join(contextRoot, 'layers', 'infrastructure', 'providers', 'index.ts');
|
|
131
|
-
const appProviderPath = path.join(contextRoot, 'layers', 'application', 'providers', 'ApplicationProvider.ts');
|
|
132
|
-
const appProviderIndex = path.join(contextRoot, 'layers', 'application', 'providers', 'index.ts');
|
|
133
|
-
const repositoriesIndex = path.join(contextRoot, 'layers', 'infrastructure', 'http', 'repositories', 'index.ts');
|
|
134
|
-
const useCasesIndex = path.join(contextRoot, 'layers', 'application', 'use-cases', 'index.ts');
|
|
135
|
-
|
|
136
|
-
await ensureFile(infraProviderPath, createInfrastructureProvider(contextName));
|
|
137
|
-
await ensureFile(infraProviderIndex, `export * from './InfrastructureProvider';\n`);
|
|
138
|
-
await ensureFile(appProviderPath, createApplicationProvider(contextName));
|
|
139
|
-
await ensureFile(appProviderIndex, `export * from './ApplicationProvider';\n`);
|
|
140
|
-
await ensureFile(repositoriesIndex, '');
|
|
141
|
-
await ensureFile(useCasesIndex, '');
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
export default async function initStructure(): Promise<void> {
|
|
145
|
-
const config = await loadUserConfig();
|
|
146
|
-
const contexts = normalizeContexts(config.contexts) as ContextConfig[];
|
|
147
|
-
|
|
148
|
-
if (!contexts.length) {
|
|
149
|
-
printContextsError();
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const sharedAlias = String(config.sharedAlias ?? '').trim();
|
|
154
|
-
if (!sharedAlias.length) {
|
|
155
|
-
printSharedAliasError();
|
|
156
|
-
process.exitCode = 1;
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
for (const context of contexts) {
|
|
161
|
-
await ensureContextStructure(context);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const sharedCreated = await ensureSharedEssentialsStructure(contexts, sharedAlias);
|
|
165
|
-
if (!sharedCreated) {
|
|
166
|
-
process.exitCode = 1;
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
await initAliases();
|
|
171
|
-
console.log('✅ Folders structure initialized');
|
|
172
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import prompts from 'prompts';
|
|
2
|
-
import { addLint } from '../plugins/index.js';
|
|
3
|
-
import initEdges from '../init/initEdges.js';
|
|
4
|
-
import initStructure from '../init/initStructure.js';
|
|
5
|
-
import { normalizeContexts } from '../init/initAliases.js';
|
|
6
|
-
import { loadUserConfig } from '../utils/loadConfig.js';
|
|
7
|
-
import {
|
|
8
|
-
createCoreSchema,
|
|
9
|
-
createDatasource,
|
|
10
|
-
createDatasourceProvider,
|
|
11
|
-
createPresenterFactory,
|
|
12
|
-
createProgram,
|
|
13
|
-
createResponse,
|
|
14
|
-
createTranslationManager
|
|
15
|
-
} from '../scaffolds/index.js';
|
|
16
|
-
|
|
17
|
-
const printContextsError = (): void => {
|
|
18
|
-
console.error('❌ Cannot run "install fresh": `contexts` is missing or empty in azure-net.config.ts/js');
|
|
19
|
-
console.error('Add contexts first, for example:');
|
|
20
|
-
console.error('export default {');
|
|
21
|
-
console.error("\tcontexts: ['web', 'admin']");
|
|
22
|
-
console.error('\t// or');
|
|
23
|
-
console.error("\t// contexts: [{ name: 'web', alias: '$web' }, { name: 'admin', alias: '$admin' }]");
|
|
24
|
-
console.error('};');
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const askConfirm = async (message: string): Promise<boolean> => {
|
|
28
|
-
const result = await prompts({
|
|
29
|
-
type: 'confirm',
|
|
30
|
-
name: 'confirmed',
|
|
31
|
-
message,
|
|
32
|
-
initial: true
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
return Boolean(result.confirmed);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const runOptionalStep = async (question: string, action: () => Promise<void>): Promise<void> => {
|
|
39
|
-
const shouldRun = await askConfirm(question);
|
|
40
|
-
if (!shouldRun) return;
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
await action();
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.warn(`⚠️ Step failed: ${question}`);
|
|
46
|
-
console.warn(error);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export default async function installFresh(): Promise<void> {
|
|
51
|
-
const config = await loadUserConfig();
|
|
52
|
-
const contexts = normalizeContexts(config.contexts);
|
|
53
|
-
|
|
54
|
-
if (!contexts.length) {
|
|
55
|
-
printContextsError();
|
|
56
|
-
process.exitCode = 1;
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
await initStructure();
|
|
61
|
-
await initEdges();
|
|
62
|
-
await createProgram();
|
|
63
|
-
|
|
64
|
-
await runOptionalStep('Add commit tools (lint/commit conventions)?', async () => {
|
|
65
|
-
await addLint();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
await runOptionalStep('Create schema factory?', async () => {
|
|
69
|
-
await createCoreSchema();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
await runOptionalStep('Create presenter factory?', async () => {
|
|
73
|
-
await createPresenterFactory();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
await runOptionalStep('Create API response?', async () => {
|
|
77
|
-
await createResponse();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
await runOptionalStep('Create datasource?', async () => {
|
|
81
|
-
await createDatasource();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
await runOptionalStep('Create datasource provider?', async () => {
|
|
85
|
-
await createDatasourceProvider();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
await runOptionalStep('Create translation manager (i18n)?', async () => {
|
|
89
|
-
await createTranslationManager();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
console.log('✅ install fresh completed');
|
|
93
|
-
}
|
package/src/plugins/addLint.ts
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { execSync } from 'node:child_process';
|
|
4
|
-
|
|
5
|
-
type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';
|
|
6
|
-
|
|
7
|
-
interface AddLintOptions {
|
|
8
|
-
manager?: PackageManager;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface ConfigState {
|
|
12
|
-
configPath: string | null;
|
|
13
|
-
content: string | null;
|
|
14
|
-
hasPackageManagerKey: boolean;
|
|
15
|
-
validPackageManager: PackageManager | null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const dependencies = ['@commitlint/cli', 'semantic-release', '@semantic-release/git', 'git-cz', 'husky', 'commitizen', 'env-cmd'];
|
|
19
|
-
|
|
20
|
-
const commitlintConfig = `export default {
|
|
21
|
-
rules: {
|
|
22
|
-
'body-leading-blank': [2, 'always'],
|
|
23
|
-
'footer-leading-blank': [2, 'always'],
|
|
24
|
-
'header-max-length': [2, 'always', 72],
|
|
25
|
-
'subject-empty': [2, 'never'],
|
|
26
|
-
'subject-full-stop': [2, 'never', '.'],
|
|
27
|
-
'type-case': [2, 'always', 'lower-case'],
|
|
28
|
-
'type-empty': [2, 'never'],
|
|
29
|
-
'type-enum': [2, 'always', ['feat', 'fix', 'refactor', 'perf', 'chore', 'docs', 'style', 'test', 'ci']]
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
`;
|
|
33
|
-
|
|
34
|
-
const releaseConfig = `export default {
|
|
35
|
-
branches: ['main', 'dev'],
|
|
36
|
-
dryRun: false,
|
|
37
|
-
ci: false,
|
|
38
|
-
plugins: [
|
|
39
|
-
[
|
|
40
|
-
'@semantic-release/commit-analyzer',
|
|
41
|
-
{
|
|
42
|
-
releaseRules: [
|
|
43
|
-
{ type: 'release', release: 'major' },
|
|
44
|
-
{ type: 'feature', release: 'minor' },
|
|
45
|
-
{ type: 'perf', release: false },
|
|
46
|
-
{ type: 'refactor', release: false },
|
|
47
|
-
{ type: 'fix', release: 'patch' },
|
|
48
|
-
{ type: 'chore', release: false },
|
|
49
|
-
{ type: 'ci', release: false },
|
|
50
|
-
{ type: 'docs', scope: 'README', release: false },
|
|
51
|
-
{ type: 'test', release: false },
|
|
52
|
-
{ type: 'style', release: false }
|
|
53
|
-
]
|
|
54
|
-
}
|
|
55
|
-
],
|
|
56
|
-
'@semantic-release/release-notes-generator'
|
|
57
|
-
]
|
|
58
|
-
};
|
|
59
|
-
`;
|
|
60
|
-
|
|
61
|
-
const prettierConfig = `{
|
|
62
|
-
"useTabs": true,
|
|
63
|
-
"singleQuote": true,
|
|
64
|
-
"trailingComma": "none",
|
|
65
|
-
"tabWidth": 2,
|
|
66
|
-
"semi": true,
|
|
67
|
-
"printWidth": 150,
|
|
68
|
-
"plugins": ["prettier-plugin-svelte"],
|
|
69
|
-
"overrides": [
|
|
70
|
-
{
|
|
71
|
-
"files": "*.svelte",
|
|
72
|
-
"options": {
|
|
73
|
-
"parser": "svelte"
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
]
|
|
77
|
-
}
|
|
78
|
-
`;
|
|
79
|
-
|
|
80
|
-
const resolveInstallCommand = (manager: PackageManager): string => {
|
|
81
|
-
const deps = dependencies.join(' ');
|
|
82
|
-
switch (manager) {
|
|
83
|
-
case 'pnpm':
|
|
84
|
-
return `pnpm add -D ${deps}`;
|
|
85
|
-
case 'npm':
|
|
86
|
-
return `npm install -D ${deps}`;
|
|
87
|
-
case 'yarn':
|
|
88
|
-
return `yarn add -D ${deps}`;
|
|
89
|
-
case 'bun':
|
|
90
|
-
return `bun add -d ${deps}`;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const resolveRunScriptCommand = (manager: PackageManager, script: string): string => {
|
|
95
|
-
switch (manager) {
|
|
96
|
-
case 'pnpm':
|
|
97
|
-
return `pnpm ${script}`;
|
|
98
|
-
case 'npm':
|
|
99
|
-
return `npm run ${script}`;
|
|
100
|
-
case 'yarn':
|
|
101
|
-
return `yarn ${script}`;
|
|
102
|
-
case 'bun':
|
|
103
|
-
return `bun run ${script}`;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const resolveHuskyCommand = (manager: PackageManager): string => {
|
|
108
|
-
switch (manager) {
|
|
109
|
-
case 'pnpm':
|
|
110
|
-
return 'pnpm exec husky';
|
|
111
|
-
case 'npm':
|
|
112
|
-
return 'npx husky';
|
|
113
|
-
case 'yarn':
|
|
114
|
-
return 'yarn husky';
|
|
115
|
-
case 'bun':
|
|
116
|
-
return 'bunx husky';
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const detectPackageManager = (cwd: string): PackageManager | undefined => {
|
|
121
|
-
if (fs.existsSync(path.join(cwd, 'bun.lock')) || fs.existsSync(path.join(cwd, 'bun.lockb'))) return 'bun';
|
|
122
|
-
if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm';
|
|
123
|
-
if (fs.existsSync(path.join(cwd, 'yarn.lock'))) return 'yarn';
|
|
124
|
-
if (fs.existsSync(path.join(cwd, 'package-lock.json'))) return 'npm';
|
|
125
|
-
return undefined;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const parseConfigState = (cwd: string): ConfigState => {
|
|
129
|
-
const tsPath = path.join(cwd, 'azure-net.config.ts');
|
|
130
|
-
const jsPath = path.join(cwd, 'azure-net.config.js');
|
|
131
|
-
const configPath = fs.existsSync(tsPath) ? tsPath : fs.existsSync(jsPath) ? jsPath : null;
|
|
132
|
-
|
|
133
|
-
if (!configPath) {
|
|
134
|
-
return {
|
|
135
|
-
configPath: null,
|
|
136
|
-
content: null,
|
|
137
|
-
hasPackageManagerKey: false,
|
|
138
|
-
validPackageManager: null
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const content = fs.readFileSync(configPath, 'utf-8');
|
|
143
|
-
const hasPackageManagerKey = /packageManager\s*:/.test(content);
|
|
144
|
-
const managerMatch = content.match(/packageManager\s*:\s*['"`](bun|pnpm|npm|yarn)['"`]/);
|
|
145
|
-
const validPackageManager = managerMatch?.[1] as PackageManager | undefined;
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
configPath,
|
|
149
|
-
content,
|
|
150
|
-
hasPackageManagerKey,
|
|
151
|
-
validPackageManager: validPackageManager ?? null
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const upsertPackageManagerInConfig = (content: string, manager: PackageManager): string => {
|
|
156
|
-
const packageManagerEntry = `packageManager: '${manager}'`;
|
|
157
|
-
const hasExportDefaultObject = /export\s+default\s*\{[\s\S]*\}\s*;?/.test(content);
|
|
158
|
-
|
|
159
|
-
if (!hasExportDefaultObject) {
|
|
160
|
-
return `export default {\n\t${packageManagerEntry}\n};\n`;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (/packageManager\s*:/.test(content)) {
|
|
164
|
-
return content.replace(/packageManager\s*:\s*['"`][^'"`]+['"`]/, packageManagerEntry);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return content.replace(/export\s+default\s*\{([\s\S]*?)\}\s*;?/, (_full, body: string) => {
|
|
168
|
-
const trimmedRight = body.replace(/\s*$/, '');
|
|
169
|
-
if (!trimmedRight.length) {
|
|
170
|
-
return `export default {\n\t${packageManagerEntry}\n};`;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const withComma = trimmedRight.endsWith(',') ? trimmedRight : `${trimmedRight},`;
|
|
174
|
-
return `export default {${withComma}\n\t${packageManagerEntry}\n};`;
|
|
175
|
-
});
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const localOnlyPrepareScript = `node -e "const local = !process.env.CI && process.env.NODE_ENV !== 'production' && !process.env.DOCKER && !process.env.CONTAINER; process.exit(local ? 1 : 0)" || (husky && svelte-kit sync)`;
|
|
179
|
-
|
|
180
|
-
const selectPackageManager = async (cwd: string, preset?: PackageManager): Promise<PackageManager> => {
|
|
181
|
-
if (preset) return preset;
|
|
182
|
-
const { default: prompts } = await import('prompts');
|
|
183
|
-
|
|
184
|
-
const detected = detectPackageManager(cwd);
|
|
185
|
-
const response = await prompts({
|
|
186
|
-
type: 'select',
|
|
187
|
-
name: 'manager',
|
|
188
|
-
message: 'Choose your package manager:',
|
|
189
|
-
choices: [
|
|
190
|
-
{ title: 'bun', value: 'bun' },
|
|
191
|
-
{ title: 'pnpm', value: 'pnpm' },
|
|
192
|
-
{ title: 'npm', value: 'npm' },
|
|
193
|
-
{ title: 'yarn', value: 'yarn' }
|
|
194
|
-
],
|
|
195
|
-
initial: detected ? ['bun', 'pnpm', 'npm', 'yarn'].indexOf(detected) : 0
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
if (!response.manager) {
|
|
199
|
-
throw new Error('Package manager is required');
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return response.manager as PackageManager;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
export default async function addLint(options: AddLintOptions = {}): Promise<void> {
|
|
206
|
-
const cwd = process.cwd();
|
|
207
|
-
const pkgPath = path.join(cwd, 'package.json');
|
|
208
|
-
|
|
209
|
-
if (!fs.existsSync(pkgPath)) {
|
|
210
|
-
console.error('❌ package.json not found in this directory');
|
|
211
|
-
process.exit(1);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const configState = parseConfigState(cwd);
|
|
215
|
-
const manager = configState.validPackageManager ?? (await selectPackageManager(cwd, options.manager));
|
|
216
|
-
|
|
217
|
-
if (!configState.configPath) {
|
|
218
|
-
const newConfigPath = path.join(cwd, 'azure-net.config.ts');
|
|
219
|
-
fs.writeFileSync(newConfigPath, `export default {\n\tpackageManager: '${manager}'\n};\n`);
|
|
220
|
-
} else if (!configState.validPackageManager || !configState.hasPackageManagerKey) {
|
|
221
|
-
const nextConfig = upsertPackageManagerInConfig(configState.content ?? '', manager);
|
|
222
|
-
fs.writeFileSync(configState.configPath, nextConfig);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const installCommand = resolveInstallCommand(manager);
|
|
226
|
-
const runFormatCommand = resolveRunScriptCommand(manager, 'format');
|
|
227
|
-
const preCommitScript = `${resolveRunScriptCommand(manager, 'lint')} && ${resolveRunScriptCommand(manager, 'check')}`;
|
|
228
|
-
const commitScript = `${resolveRunScriptCommand(manager, 'format')} && git add . && git-cz && git push`;
|
|
229
|
-
const releaseScript = `${resolveRunScriptCommand(manager, 'commit')} && ${resolveRunScriptCommand(manager, 'semantic-release')}`;
|
|
230
|
-
|
|
231
|
-
console.log(`📦 Installing packages with ${manager}...`);
|
|
232
|
-
execSync(installCommand, { stdio: 'inherit' });
|
|
233
|
-
|
|
234
|
-
console.log('📁 Updating package.json...');
|
|
235
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')) as {
|
|
236
|
-
scripts?: Record<string, string>;
|
|
237
|
-
config?: Record<string, unknown>;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
pkg.scripts = {
|
|
241
|
-
...(pkg.scripts ?? {}),
|
|
242
|
-
precommit: preCommitScript,
|
|
243
|
-
prepare: localOnlyPrepareScript,
|
|
244
|
-
'semantic-release': 'env-cmd semantic-release',
|
|
245
|
-
commit: commitScript,
|
|
246
|
-
release: releaseScript
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
pkg.config = pkg.config ?? {};
|
|
250
|
-
pkg.config.commitizen = {
|
|
251
|
-
path: 'git-cz'
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 4));
|
|
255
|
-
|
|
256
|
-
fs.writeFileSync(path.join(cwd, 'commitlint.config.ts'), commitlintConfig);
|
|
257
|
-
fs.writeFileSync(path.join(cwd, 'release.config.ts'), releaseConfig);
|
|
258
|
-
fs.writeFileSync(path.join(cwd, '.prettierrc'), prettierConfig);
|
|
259
|
-
|
|
260
|
-
console.log('🔧 Initializing Husky...');
|
|
261
|
-
try {
|
|
262
|
-
execSync(resolveHuskyCommand(manager), { stdio: 'inherit' });
|
|
263
|
-
} catch {
|
|
264
|
-
console.warn('⚠️ Husky initialization skipped (command failed in current environment).');
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
try {
|
|
268
|
-
execSync(runFormatCommand, { stdio: 'inherit' });
|
|
269
|
-
} catch {
|
|
270
|
-
console.warn('⚠️ Format script execution skipped (script may be missing).');
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
console.log(`✅ Linting and release setup completed! Added prepare script: ${localOnlyPrepareScript}`);
|
|
274
|
-
}
|