@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { updateDefaultFactoryConfig } from './updateDefaultFactoryConfig.js';
|
|
1
2
|
import fs from 'node:fs/promises';
|
|
2
3
|
import fsSync from 'node:fs';
|
|
3
4
|
import path from 'node:path';
|
|
@@ -6,102 +7,75 @@ import { writeIfNotExists, updateIndexTs } from '../utils/fileUtils.js';
|
|
|
6
7
|
import { toPascalCase } from '../utils/contextUtils.js';
|
|
7
8
|
import { getFoundationConstructPath, getSharedState } from '../utils/sharedFoundation.js';
|
|
8
9
|
const resolvePresetImportName = (preset) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
switch (preset) {
|
|
11
|
+
case 'ru':
|
|
12
|
+
return 'validationMessagesRu';
|
|
13
|
+
case 'en':
|
|
14
|
+
return 'validationMessagesEn';
|
|
15
|
+
case 'i18n':
|
|
16
|
+
return 'validationMessagesI18n';
|
|
17
|
+
}
|
|
17
18
|
};
|
|
18
|
-
const createSchemaFactoryTemplate = (
|
|
19
|
-
factoryName,
|
|
20
|
-
messagesImportName
|
|
21
|
-
) => `import { createSchemaFactory, createRules, ${messagesImportName} } from '@azure-net/kit/delivery';
|
|
19
|
+
const createSchemaFactoryTemplate = (factoryName, messagesImportName) => `import { createSchemaFactory, createRules, ${messagesImportName} } from '@azure-net/kit/delivery';
|
|
22
20
|
|
|
23
21
|
export const ${factoryName} = createSchemaFactory(createRules(${messagesImportName}));
|
|
24
22
|
`;
|
|
25
23
|
const resolveConfigFile = (cwd) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
const buildDefaultSchemaFactoryConfigEntry = (factoryName) => {
|
|
37
|
-
return `defaultSchemaFactory: '${factoryName}'`;
|
|
38
|
-
};
|
|
39
|
-
const upsertDefaultSchemaFactoryConfig = (content, factoryName) => {
|
|
40
|
-
const hasExportDefaultObject = /export\s+default\s*\{[\s\S]*\}\s*;?/.test(content);
|
|
41
|
-
const defaultFactoryEntry = buildDefaultSchemaFactoryConfigEntry(factoryName);
|
|
42
|
-
if (!hasExportDefaultObject) {
|
|
43
|
-
return `export default {\n\t${defaultFactoryEntry}\n};\n`;
|
|
44
|
-
}
|
|
45
|
-
let nextContent = content;
|
|
46
|
-
if (/defaultSchemaFactory\s*:/.test(nextContent)) {
|
|
47
|
-
nextContent = nextContent.replace(/defaultSchemaFactory\s*:\s*(\{[\s\S]*?\n\s*\}|['"`][^'"`]+['"`])/m, defaultFactoryEntry);
|
|
48
|
-
} else if (/defaultSchema\s*:/.test(nextContent)) {
|
|
49
|
-
nextContent = nextContent.replace(/defaultSchema\s*:\s*(\{[\s\S]*?\n\s*\}|['"`][^'"`]+['"`])/m, defaultFactoryEntry);
|
|
50
|
-
} else {
|
|
51
|
-
nextContent = nextContent.replace(/export\s+default\s*\{([\s\S]*)\}\s*;?/, (_full, body) => {
|
|
52
|
-
const trimmedRight = body.replace(/\s*$/, '');
|
|
53
|
-
if (!trimmedRight.length) {
|
|
54
|
-
return `export default {\n\t${defaultFactoryEntry}\n};`;
|
|
55
|
-
}
|
|
56
|
-
const withComma = trimmedRight.endsWith(',') ? trimmedRight : `${trimmedRight},`;
|
|
57
|
-
return `export default {${withComma}\n\t${defaultFactoryEntry}\n};`;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return nextContent;
|
|
24
|
+
const tsPath = path.join(cwd, 'azure-net.config.ts');
|
|
25
|
+
const jsPath = path.join(cwd, 'azure-net.config.js');
|
|
26
|
+
if (fsSync.existsSync(tsPath)) {
|
|
27
|
+
return { filepath: tsPath, type: 'ts', exists: true, content: fsSync.readFileSync(tsPath, 'utf-8') };
|
|
28
|
+
}
|
|
29
|
+
if (fsSync.existsSync(jsPath)) {
|
|
30
|
+
return { filepath: jsPath, type: 'js', exists: true, content: fsSync.readFileSync(jsPath, 'utf-8') };
|
|
31
|
+
}
|
|
32
|
+
return { filepath: tsPath, type: 'ts', exists: false, content: '' };
|
|
61
33
|
};
|
|
62
34
|
export default async function createCoreSchema() {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
35
|
+
const { schemaFactoryNameRaw } = await prompts({
|
|
36
|
+
type: 'text',
|
|
37
|
+
name: 'schemaFactoryNameRaw',
|
|
38
|
+
message: 'Schema factory name:',
|
|
39
|
+
initial: 'Schema'
|
|
40
|
+
});
|
|
41
|
+
const schemaFactoryName = toPascalCase(String(schemaFactoryNameRaw ?? 'Schema')) || 'Schema';
|
|
42
|
+
const { preset } = await prompts({
|
|
43
|
+
type: 'select',
|
|
44
|
+
name: 'preset',
|
|
45
|
+
message: 'Choose validation messages:',
|
|
46
|
+
choices: [
|
|
47
|
+
{ title: 'Russian', value: 'ru' },
|
|
48
|
+
{ title: 'English', value: 'en' },
|
|
49
|
+
{ title: 'i18n', value: 'i18n' }
|
|
50
|
+
],
|
|
51
|
+
initial: 2
|
|
52
|
+
});
|
|
53
|
+
const selectedPreset = (preset ?? 'i18n');
|
|
54
|
+
const messagesImportName = resolvePresetImportName(selectedPreset);
|
|
55
|
+
const { sharedContext } = await getSharedState();
|
|
56
|
+
const coreSchemaPath = getFoundationConstructPath(sharedContext.name, 'schema');
|
|
57
|
+
const customRulesPath = path.join(coreSchemaPath, 'CustomRules');
|
|
58
|
+
const filePath = path.join(coreSchemaPath, `${schemaFactoryName}.ts`);
|
|
59
|
+
await fs.mkdir(coreSchemaPath, { recursive: true });
|
|
60
|
+
await fs.mkdir(customRulesPath, { recursive: true });
|
|
61
|
+
const created = await writeIfNotExists(filePath, createSchemaFactoryTemplate(schemaFactoryName, messagesImportName));
|
|
62
|
+
if (!created) {
|
|
63
|
+
console.log(`⚠️ Schema factory "${schemaFactoryName}" already exists. File was not overwritten.`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
await updateIndexTs(coreSchemaPath);
|
|
67
|
+
console.log(`✅ Shared schema factory created: ${filePath}`);
|
|
68
|
+
}
|
|
69
|
+
const { useAsDefault } = await prompts({
|
|
70
|
+
type: 'confirm',
|
|
71
|
+
name: 'useAsDefault',
|
|
72
|
+
message: 'Use this schema factory as default for the project?',
|
|
73
|
+
initial: true
|
|
74
|
+
});
|
|
75
|
+
if (!useAsDefault)
|
|
76
|
+
return;
|
|
77
|
+
const config = resolveConfigFile(process.cwd());
|
|
78
|
+
const nextContent = updateDefaultFactoryConfig(config.content, 'defaultSchemaFactory', schemaFactoryName);
|
|
79
|
+
await fs.writeFile(config.filepath, nextContent, 'utf-8');
|
|
80
|
+
console.log(`✅ Default schema factory saved to ${path.basename(config.filepath)}`);
|
|
107
81
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import prompts from 'prompts';
|
|
4
|
+
import { registerDatasource } from './registerDatasource.js';
|
|
4
5
|
import { writeIfNotExists, updateIndexTs } from '../utils/fileUtils.js';
|
|
5
6
|
import { toPascalCase } from '../utils/contextUtils.js';
|
|
6
|
-
import { loadUserConfig } from '../utils/loadConfig.js';
|
|
7
|
-
import { normalizeContexts } from '../init/initAliases.js';
|
|
8
7
|
import { getFoundationConstructImportPath, getFoundationConstructPath, getSharedState } from '../utils/sharedFoundation.js';
|
|
9
|
-
const createDatasourceTemplateWithoutResponse = (
|
|
10
|
-
className
|
|
11
|
-
) => `import { BaseHttpDatasource, type CreateRequestCallbackType } from '@azure-net/kit/infra';
|
|
8
|
+
const createDatasourceTemplateWithoutResponse = (className) => `import { BaseHttpDatasource, type CreateRequestCallbackType } from '@azure-net/kit/infra';
|
|
12
9
|
|
|
13
10
|
export class ${className} extends BaseHttpDatasource {
|
|
14
11
|
\tasync createRequest<T>(callback: CreateRequestCallbackType<T>) {
|
|
@@ -16,11 +13,7 @@ export class ${className} extends BaseHttpDatasource {
|
|
|
16
13
|
\t}
|
|
17
14
|
}
|
|
18
15
|
`;
|
|
19
|
-
const createDatasourceTemplateWithResponseAndInterface = (
|
|
20
|
-
className,
|
|
21
|
-
responseName,
|
|
22
|
-
responseImportPath
|
|
23
|
-
) => `import { BaseHttpDatasource, type CreateRequestCallbackType } from '@azure-net/kit/infra';
|
|
16
|
+
const createDatasourceTemplateWithResponseAndInterface = (className, responseName, responseImportPath) => `import { BaseHttpDatasource, type CreateRequestCallbackType } from '@azure-net/kit/infra';
|
|
24
17
|
import { ${responseName}, type I${responseName} } from '${responseImportPath}';
|
|
25
18
|
|
|
26
19
|
export class ${className} extends BaseHttpDatasource {
|
|
@@ -29,11 +22,7 @@ export class ${className} extends BaseHttpDatasource {
|
|
|
29
22
|
\t}
|
|
30
23
|
}
|
|
31
24
|
`;
|
|
32
|
-
const createDatasourceTemplateWithResponse = (
|
|
33
|
-
className,
|
|
34
|
-
responseName,
|
|
35
|
-
responseImportPath
|
|
36
|
-
) => `import { BaseHttpDatasource, type CreateRequestCallbackType } from '@azure-net/kit/infra';
|
|
25
|
+
const createDatasourceTemplateWithResponse = (className, responseName, responseImportPath) => `import { BaseHttpDatasource, type CreateRequestCallbackType } from '@azure-net/kit/infra';
|
|
37
26
|
import { ${responseName} } from '${responseImportPath}';
|
|
38
27
|
|
|
39
28
|
export class ${className} extends BaseHttpDatasource {
|
|
@@ -43,96 +32,73 @@ export class ${className} extends BaseHttpDatasource {
|
|
|
43
32
|
}
|
|
44
33
|
`;
|
|
45
34
|
const ensureDatasourceClassName = (rawName) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
const getContextChoices = async () => {
|
|
50
|
-
const config = await loadUserConfig();
|
|
51
|
-
const contexts = normalizeContexts(config.contexts);
|
|
52
|
-
const choices = [{ title: 'shared foundation', value: '__shared__' }];
|
|
53
|
-
for (const context of contexts) {
|
|
54
|
-
choices.push({ title: context.name, value: context.name });
|
|
55
|
-
}
|
|
56
|
-
return choices;
|
|
35
|
+
const normalized = toPascalCase(rawName || 'ApiHttpDatasource');
|
|
36
|
+
return normalized.endsWith('Datasource') ? normalized : `${normalized}Datasource`;
|
|
57
37
|
};
|
|
58
38
|
const getSharedResponses = async () => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
39
|
+
const { sharedContext } = await getSharedState();
|
|
40
|
+
const responsesPath = getFoundationConstructPath(sharedContext.name, 'response');
|
|
41
|
+
try {
|
|
42
|
+
const files = await fs.readdir(responsesPath);
|
|
43
|
+
return files.filter((file) => file.endsWith('.ts') && file !== 'index.ts').map((file) => file.replace(/\.ts$/, ''));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
67
48
|
};
|
|
68
49
|
const hasResponseInterface = async (responseName) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
const resolveTargetPath = (target) => {
|
|
80
|
-
if (target === '__shared__') {
|
|
81
|
-
throw new Error('Shared target path must be resolved async.');
|
|
82
|
-
}
|
|
83
|
-
return path.join(process.cwd(), 'src', 'app', target, 'layers', 'infrastructure', 'http', 'datasources');
|
|
50
|
+
const { sharedContext } = await getSharedState();
|
|
51
|
+
const responsePath = path.join(getFoundationConstructPath(sharedContext.name, 'response'), `${responseName}.ts`);
|
|
52
|
+
try {
|
|
53
|
+
const content = await fs.readFile(responsePath, 'utf-8');
|
|
54
|
+
const interfaceRegex = new RegExp(`export\\s+interface\\s+I${responseName}\\b`);
|
|
55
|
+
return interfaceRegex.test(content);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
84
60
|
};
|
|
85
61
|
export default async function createDatasource() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
: resolveTargetPath(selectedTarget);
|
|
129
|
-
await fs.mkdir(targetPath, { recursive: true });
|
|
130
|
-
const filePath = path.join(targetPath, `${className}.ts`);
|
|
131
|
-
const created = await writeIfNotExists(filePath, content);
|
|
132
|
-
await updateIndexTs(targetPath);
|
|
133
|
-
if (!created) {
|
|
134
|
-
console.log(`⚠️ Datasource "${className}" already exists. File was not overwritten.`);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
console.log(`✅ Datasource created: ${filePath}`);
|
|
62
|
+
const { datasourceNameRaw } = await prompts({
|
|
63
|
+
type: 'text',
|
|
64
|
+
name: 'datasourceNameRaw',
|
|
65
|
+
message: 'Datasource name:',
|
|
66
|
+
initial: 'ApiHttpDatasource'
|
|
67
|
+
});
|
|
68
|
+
const className = ensureDatasourceClassName(String(datasourceNameRaw ?? 'ApiHttpDatasource'));
|
|
69
|
+
const sharedResponses = await getSharedResponses();
|
|
70
|
+
let selectedResponse = null;
|
|
71
|
+
if (sharedResponses.length > 0) {
|
|
72
|
+
const { responseName } = await prompts({
|
|
73
|
+
type: 'select',
|
|
74
|
+
name: 'responseName',
|
|
75
|
+
message: 'Select response for datasource:',
|
|
76
|
+
choices: [{ title: 'No response', value: null }, ...sharedResponses.map((response) => ({ title: response, value: response }))],
|
|
77
|
+
initial: 0
|
|
78
|
+
});
|
|
79
|
+
selectedResponse = responseName ? String(responseName) : null;
|
|
80
|
+
}
|
|
81
|
+
let content;
|
|
82
|
+
if (!selectedResponse) {
|
|
83
|
+
content = createDatasourceTemplateWithoutResponse(className);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const { sharedAlias } = await getSharedState();
|
|
87
|
+
const responseImportPath = getFoundationConstructImportPath(sharedAlias, 'response');
|
|
88
|
+
const withInterface = await hasResponseInterface(selectedResponse);
|
|
89
|
+
content = withInterface
|
|
90
|
+
? createDatasourceTemplateWithResponseAndInterface(className, selectedResponse, responseImportPath)
|
|
91
|
+
: createDatasourceTemplateWithResponse(className, selectedResponse, responseImportPath);
|
|
92
|
+
}
|
|
93
|
+
const targetPath = getFoundationConstructPath((await getSharedState()).sharedContext.name, 'datasource');
|
|
94
|
+
await fs.mkdir(targetPath, { recursive: true });
|
|
95
|
+
const filePath = path.join(targetPath, `${className}.ts`);
|
|
96
|
+
const created = await writeIfNotExists(filePath, content);
|
|
97
|
+
await updateIndexTs(targetPath);
|
|
98
|
+
if (!created) {
|
|
99
|
+
console.log(`⚠️ Datasource "${className}" already exists. File was not overwritten.`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
await registerDatasource(className);
|
|
103
|
+
console.log(`✅ Datasource created: ${filePath}`);
|
|
138
104
|
}
|
|
@@ -2,14 +2,14 @@ import path from 'node:path';
|
|
|
2
2
|
import { writeIfNotExists } from '../utils/fileUtils.js';
|
|
3
3
|
const createProgramTemplate = () => `import { createApp } from '@azure-net/kit';
|
|
4
4
|
|
|
5
|
-
export const { register
|
|
5
|
+
export const { register } = createApp((app) => app);
|
|
6
6
|
`;
|
|
7
7
|
export default async function createProgram() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const programPath = path.join(process.cwd(), 'src', 'program.ts');
|
|
9
|
+
const created = await writeIfNotExists(programPath, createProgramTemplate());
|
|
10
|
+
if (!created) {
|
|
11
|
+
console.log('⚠️ Program already exists. Nothing was overwritten.');
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
console.log(`✅ Program created: ${programPath}`);
|
|
15
15
|
}
|
|
@@ -5,8 +5,8 @@ import { writeIfNotExists, updateIndexTs } from '../utils/fileUtils.js';
|
|
|
5
5
|
import { toPascalCase } from '../utils/contextUtils.js';
|
|
6
6
|
import { getFoundationConstructPath, getSharedState } from '../utils/sharedFoundation.js';
|
|
7
7
|
const createResponseWithWrapperTemplate = (name) => {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const interfaceName = `I${name}`;
|
|
9
|
+
return `import { ResponseBuilder } from '@azure-net/kit/infra';
|
|
10
10
|
|
|
11
11
|
export interface ${interfaceName}<T> {
|
|
12
12
|
\tdata: T;
|
|
@@ -24,33 +24,33 @@ const createResponseSimpleTemplate = (name) => `import { ResponseBuilder } from
|
|
|
24
24
|
export class ${name}<TData = unknown, TMeta = unknown> extends ResponseBuilder<TData, TMeta> {}
|
|
25
25
|
`;
|
|
26
26
|
const ensureResponseName = (rawName) => {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const normalized = toPascalCase(rawName || 'ApiResponse') || 'ApiResponse';
|
|
28
|
+
return normalized.endsWith('Response') ? normalized : `${normalized}Response`;
|
|
29
29
|
};
|
|
30
30
|
export default async function createResponse() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
31
|
+
const { responseNameRaw } = await prompts({
|
|
32
|
+
type: 'text',
|
|
33
|
+
name: 'responseNameRaw',
|
|
34
|
+
message: 'Response class name:',
|
|
35
|
+
initial: 'ApiResponse'
|
|
36
|
+
});
|
|
37
|
+
const responseName = ensureResponseName(String(responseNameRaw ?? 'ApiResponse'));
|
|
38
|
+
const { useCommonResponseWrapper } = await prompts({
|
|
39
|
+
type: 'confirm',
|
|
40
|
+
name: 'useCommonResponseWrapper',
|
|
41
|
+
message: 'Use common backend response wrapper interface?',
|
|
42
|
+
initial: true
|
|
43
|
+
});
|
|
44
|
+
const { sharedContext } = await getSharedState();
|
|
45
|
+
const responseRoot = getFoundationConstructPath(sharedContext.name, 'response');
|
|
46
|
+
const filePath = path.join(responseRoot, `${responseName}.ts`);
|
|
47
|
+
await fs.mkdir(responseRoot, { recursive: true });
|
|
48
|
+
const template = useCommonResponseWrapper ? createResponseWithWrapperTemplate(responseName) : createResponseSimpleTemplate(responseName);
|
|
49
|
+
const created = await writeIfNotExists(filePath, template);
|
|
50
|
+
await updateIndexTs(responseRoot);
|
|
51
|
+
if (!created) {
|
|
52
|
+
console.log(`⚠️ Response "${responseName}" already exists. File was not overwritten.`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
console.log(`✅ Response created: ${filePath}`);
|
|
56
56
|
}
|
|
@@ -13,23 +13,23 @@ export const ${ruleName} = <T = unknown, D = unknown>(): ValidationRuleResult<T,
|
|
|
13
13
|
};
|
|
14
14
|
`;
|
|
15
15
|
export default async function createSchemaRule() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
16
|
+
const { ruleNameRaw } = await prompts({
|
|
17
|
+
type: 'text',
|
|
18
|
+
name: 'ruleNameRaw',
|
|
19
|
+
message: 'Schema rule name:',
|
|
20
|
+
initial: 'File'
|
|
21
|
+
});
|
|
22
|
+
const pascalName = toPascalCase(String(ruleNameRaw ?? 'File')) || 'File';
|
|
23
|
+
const camelName = toCamelCase(pascalName) || 'file';
|
|
24
|
+
const { sharedContext } = await getSharedState();
|
|
25
|
+
const rulesPath = path.join(getFoundationConstructPath(sharedContext.name, 'schema'), 'CustomRules');
|
|
26
|
+
const filePath = path.join(rulesPath, `${pascalName}.ts`);
|
|
27
|
+
await fs.mkdir(rulesPath, { recursive: true });
|
|
28
|
+
const created = await writeIfNotExists(filePath, createSchemaRuleTemplate(camelName));
|
|
29
|
+
await updateIndexTs(rulesPath);
|
|
30
|
+
if (!created) {
|
|
31
|
+
console.log(`⚠️ Schema rule "${pascalName}" already exists. File was not overwritten.`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
console.log(`✅ Schema rule created: ${filePath}`);
|
|
35
35
|
}
|