@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
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import prompts from 'prompts';
|
|
4
|
-
import { normalizeContexts } from '../../init/initAliases.js';
|
|
5
|
-
import { loadUserConfig } from '../../utils/loadConfig.js';
|
|
6
|
-
import { toKebabCase, toPascalCase } from '../../utils/contextUtils.js';
|
|
7
|
-
import { updateIndexTs, writeIfNotExists } from '../../utils/fileUtils.js';
|
|
8
|
-
|
|
9
|
-
const parseInterfaceNames = (rawValue: unknown): string[] =>
|
|
10
|
-
String(rawValue ?? '')
|
|
11
|
-
.split(',')
|
|
12
|
-
.map((item) => item.trim())
|
|
13
|
-
.filter(Boolean)
|
|
14
|
-
.map((item) => toPascalCase(item))
|
|
15
|
-
.filter(Boolean);
|
|
16
|
-
|
|
17
|
-
const toFileNameFromInterface = (interfaceName: string): string => interfaceName.replace(/^I/, '') || 'Type';
|
|
18
|
-
|
|
19
|
-
const validateInterfaceNames = (rawValue: unknown): true | string => {
|
|
20
|
-
const names = parseInterfaceNames(rawValue);
|
|
21
|
-
if (!names.length) return 'Provide at least one interface name';
|
|
22
|
-
|
|
23
|
-
for (const name of names) {
|
|
24
|
-
if (!name.startsWith('I')) {
|
|
25
|
-
return `Interface "${name}" must start with "I"`;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return true;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const createInterfaceContent = (name: string): string => `export interface ${name} {
|
|
33
|
-
\t[key: string]: unknown;
|
|
34
|
-
}
|
|
35
|
-
`;
|
|
36
|
-
|
|
37
|
-
const writeRootIndex = async (domainPath: string): Promise<void> => {
|
|
38
|
-
const content = `export * from './model';
|
|
39
|
-
export * from './ports';
|
|
40
|
-
`;
|
|
41
|
-
|
|
42
|
-
await fs.writeFile(path.join(domainPath, 'index.ts'), content, 'utf-8');
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const selectContext = async (): Promise<string | null> => {
|
|
46
|
-
const config = await loadUserConfig();
|
|
47
|
-
const contexts = normalizeContexts(config.contexts);
|
|
48
|
-
if (!contexts.length) {
|
|
49
|
-
console.error('❌ Cannot generate domain: `contexts` is missing or empty in azure-net.config.ts/js');
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const { context } = await prompts({
|
|
54
|
-
type: 'select',
|
|
55
|
-
name: 'context',
|
|
56
|
-
message: 'Select context:',
|
|
57
|
-
choices: contexts.map((item) => ({ title: item.name, value: item.name })),
|
|
58
|
-
initial: 0
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return context ? String(context) : null;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const createInterfacesInLayer = async (layerPath: string, names: string[]): Promise<void> => {
|
|
65
|
-
for (const interfaceName of names) {
|
|
66
|
-
const fileName = toFileNameFromInterface(interfaceName);
|
|
67
|
-
const filePath = path.join(layerPath, `${fileName}.ts`);
|
|
68
|
-
await writeIfNotExists(filePath, createInterfaceContent(interfaceName));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
await updateIndexTs(layerPath);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export default async function generateDomain(
|
|
75
|
-
options: { contextName?: string; entityName?: string } = {}
|
|
76
|
-
): Promise<{ contextName: string; domainName: string; domainPath: string } | null> {
|
|
77
|
-
const { entityRaw } = await prompts({
|
|
78
|
-
type: 'text',
|
|
79
|
-
name: 'entityRaw',
|
|
80
|
-
message: 'Entity name:',
|
|
81
|
-
initial: options.entityName ?? '',
|
|
82
|
-
validate: (value: string) => (String(value ?? '').trim().length > 0 ? true : 'Entity name is required')
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
let context: string | null = options.contextName ? String(options.contextName) : null;
|
|
86
|
-
if (!context) {
|
|
87
|
-
context = await selectContext();
|
|
88
|
-
}
|
|
89
|
-
if (!context) {
|
|
90
|
-
process.exitCode = 1;
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const entityName = toKebabCase(String(entityRaw ?? '').trim()) || 'entity';
|
|
95
|
-
const domainPath = path.join(process.cwd(), 'src', 'app', context, 'layers', 'domain', entityName);
|
|
96
|
-
const modelPath = path.join(domainPath, 'model');
|
|
97
|
-
const portsPath = path.join(domainPath, 'ports');
|
|
98
|
-
|
|
99
|
-
await fs.mkdir(modelPath, { recursive: true });
|
|
100
|
-
await fs.mkdir(portsPath, { recursive: true });
|
|
101
|
-
|
|
102
|
-
const { shouldCreateModels } = await prompts({
|
|
103
|
-
type: 'confirm',
|
|
104
|
-
name: 'shouldCreateModels',
|
|
105
|
-
message: 'Create model interfaces?',
|
|
106
|
-
initial: true
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
if (shouldCreateModels) {
|
|
110
|
-
const { modelNamesRaw } = await prompts({
|
|
111
|
-
type: 'text',
|
|
112
|
-
name: 'modelNamesRaw',
|
|
113
|
-
message: 'Model interface names (comma separated, start with I):',
|
|
114
|
-
validate: validateInterfaceNames
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const modelNames = parseInterfaceNames(modelNamesRaw);
|
|
118
|
-
await createInterfacesInLayer(modelPath, modelNames);
|
|
119
|
-
} else {
|
|
120
|
-
await updateIndexTs(modelPath);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const { shouldCreatePorts } = await prompts({
|
|
124
|
-
type: 'confirm',
|
|
125
|
-
name: 'shouldCreatePorts',
|
|
126
|
-
message: 'Create port interfaces?',
|
|
127
|
-
initial: true
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
if (shouldCreatePorts) {
|
|
131
|
-
const { portNamesRaw } = await prompts({
|
|
132
|
-
type: 'text',
|
|
133
|
-
name: 'portNamesRaw',
|
|
134
|
-
message: 'Port interface names (comma separated, start with I):',
|
|
135
|
-
validate: validateInterfaceNames
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const portNames = parseInterfaceNames(portNamesRaw);
|
|
139
|
-
await createInterfacesInLayer(portsPath, portNames);
|
|
140
|
-
} else {
|
|
141
|
-
await updateIndexTs(portsPath);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
await writeRootIndex(domainPath);
|
|
145
|
-
console.log(`✅ Domain generated: ${domainPath}`);
|
|
146
|
-
return { contextName: context, domainName: entityName, domainPath };
|
|
147
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import prompts from 'prompts';
|
|
4
|
-
import generateDomain from './generateDomain.js';
|
|
5
|
-
import generateRepository from './generateRepository.js';
|
|
6
|
-
import generatePresenter from './generatePresenter.js';
|
|
7
|
-
|
|
8
|
-
const findProviderFile = async (contextName: string, layerName: string, preferredFileName: string): Promise<string> => {
|
|
9
|
-
const providersPath = path.join(process.cwd(), 'src', 'app', contextName, 'layers', layerName, 'providers');
|
|
10
|
-
const preferredPath = path.join(providersPath, preferredFileName);
|
|
11
|
-
try {
|
|
12
|
-
await fs.access(preferredPath);
|
|
13
|
-
return preferredPath;
|
|
14
|
-
} catch {
|
|
15
|
-
try {
|
|
16
|
-
const files = await fs.readdir(providersPath);
|
|
17
|
-
const firstTs = files.find((item) => item.endsWith('.ts') && item !== 'index.ts');
|
|
18
|
-
return firstTs ? path.join(providersPath, firstTs) : preferredPath;
|
|
19
|
-
} catch {
|
|
20
|
-
return preferredPath;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const parseProviderConstName = async (providerPath: string, fallbackName: string): Promise<string> => {
|
|
26
|
-
try {
|
|
27
|
-
const content = await fs.readFile(providerPath, 'utf-8');
|
|
28
|
-
const match = content.match(/export\s+const\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*createBoundaryProvider/);
|
|
29
|
-
return match?.[1] ?? fallbackName;
|
|
30
|
-
} catch {
|
|
31
|
-
return fallbackName;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default async function generateModule(): Promise<void> {
|
|
36
|
-
const domainResult = await generateDomain();
|
|
37
|
-
if (!domainResult) {
|
|
38
|
-
process.exitCode = 1;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const repositoryResult = await generateRepository({
|
|
43
|
-
contextName: domainResult.contextName,
|
|
44
|
-
domainName: domainResult.domainName,
|
|
45
|
-
forceCreateUseCases: true
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
if (!repositoryResult) {
|
|
49
|
-
process.exitCode = 1;
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const infrastructureProviderPath = await findProviderFile(repositoryResult.contextName, 'infrastructure', 'InfrastructureProvider.ts');
|
|
54
|
-
const applicationProviderPath = await findProviderFile(repositoryResult.contextName, 'application', 'ApplicationProvider.ts');
|
|
55
|
-
const infrastructureProviderName = await parseProviderConstName(infrastructureProviderPath, 'InfrastructureProvider');
|
|
56
|
-
|
|
57
|
-
console.log('\n⚠️ Manual provider registration is required before presenter generation.');
|
|
58
|
-
console.log(`Infrastructure provider file: ${infrastructureProviderPath}`);
|
|
59
|
-
console.log(`Application provider file: ${applicationProviderPath}`);
|
|
60
|
-
console.log('\nSuggested register snippets:');
|
|
61
|
-
console.log(
|
|
62
|
-
`- Infrastructure register: ${repositoryResult.repositoryName}: () => new ${repositoryResult.repositoryName}(/* datasource */),`
|
|
63
|
-
);
|
|
64
|
-
console.log(
|
|
65
|
-
`- Application register: ${repositoryResult.useCasesName}: () => new ${repositoryResult.useCasesName}(${infrastructureProviderName}().${repositoryResult.repositoryName}),`
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const { isReadyForPresenter } = await prompts({
|
|
69
|
-
type: 'confirm',
|
|
70
|
-
name: 'isReadyForPresenter',
|
|
71
|
-
message: 'Did you register repository/use-cases in providers and want to continue?',
|
|
72
|
-
initial: false
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
if (!isReadyForPresenter) {
|
|
76
|
-
console.log('ℹ️ Module flow paused. Complete provider wiring and rerun `azure-net generate presenter`.');
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
await generatePresenter({
|
|
81
|
-
contextName: repositoryResult.contextName,
|
|
82
|
-
useCasesName: repositoryResult.useCasesName
|
|
83
|
-
});
|
|
84
|
-
}
|
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import prompts from 'prompts';
|
|
4
|
-
import { toKebabCase, toPascalCase } from '../../utils/contextUtils.js';
|
|
5
|
-
import { updateIndexTs, writeIfNotExists } from '../../utils/fileUtils.js';
|
|
6
|
-
import generatePresenter from './generatePresenter.js';
|
|
7
|
-
import {
|
|
8
|
-
buildRepositoryContent,
|
|
9
|
-
createUseCasesForRepository,
|
|
10
|
-
getAvailableTsNames,
|
|
11
|
-
getConfigState,
|
|
12
|
-
getRepositoryMeta,
|
|
13
|
-
resolveContextAlias,
|
|
14
|
-
resolveDatasourcesPath,
|
|
15
|
-
resolveDomainRootPath,
|
|
16
|
-
resolveRepositoriesPath,
|
|
17
|
-
resolveSharedDatasourcesPath,
|
|
18
|
-
selectContext,
|
|
19
|
-
writeRepositoryInterface
|
|
20
|
-
} from './repositoryModuleShared.js';
|
|
21
|
-
import { getFoundationConstructImportPath } from '../../utils/sharedFoundation.js';
|
|
22
|
-
|
|
23
|
-
type DatasourceDescriptor = { name: string; importPath: string };
|
|
24
|
-
|
|
25
|
-
type PresetMethod = {
|
|
26
|
-
name: string;
|
|
27
|
-
httpMethod: 'get' | 'post' | 'put' | 'delete';
|
|
28
|
-
route: string;
|
|
29
|
-
response: { kind: 'domain' | 'primitive'; type: string; layer: 'model' | 'ports' | null };
|
|
30
|
-
queryType: { name: string; layer: 'ports' | 'model' } | null;
|
|
31
|
-
bodyType: { name: string; layer: 'ports' | 'model' } | null;
|
|
32
|
-
pathParamType: 'string' | 'number' | null;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const toInterfaceFileName = (interfaceName: string): string => `${String(interfaceName ?? '').replace(/^I/, '') || 'Type'}.ts`;
|
|
36
|
-
|
|
37
|
-
const createInterfaceContent = (interfaceName: string): string => `export interface ${interfaceName} {
|
|
38
|
-
\t[key: string]: unknown;
|
|
39
|
-
}
|
|
40
|
-
`;
|
|
41
|
-
|
|
42
|
-
const writeDomainIndexes = async (domainPath: string, modelPath: string, portsPath: string): Promise<void> => {
|
|
43
|
-
await updateIndexTs(modelPath);
|
|
44
|
-
await updateIndexTs(portsPath);
|
|
45
|
-
await fs.writeFile(path.join(domainPath, 'index.ts'), `export * from './model';\nexport * from './ports';\n`, 'utf-8');
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const ensureDomainScaffold = async ({
|
|
49
|
-
contextName,
|
|
50
|
-
entityNamePascal,
|
|
51
|
-
domainName
|
|
52
|
-
}: {
|
|
53
|
-
contextName: string;
|
|
54
|
-
entityNamePascal: string;
|
|
55
|
-
domainName: string;
|
|
56
|
-
}): Promise<{ domainPath: string; modelPath: string; portsPath: string }> => {
|
|
57
|
-
const domainPath = resolveDomainRootPath(contextName, domainName);
|
|
58
|
-
const modelPath = path.join(domainPath, 'model');
|
|
59
|
-
const portsPath = path.join(domainPath, 'ports');
|
|
60
|
-
|
|
61
|
-
await fs.mkdir(modelPath, { recursive: true });
|
|
62
|
-
await fs.mkdir(portsPath, { recursive: true });
|
|
63
|
-
|
|
64
|
-
const modelInterfaces = [`I${entityNamePascal}`];
|
|
65
|
-
const portInterfaces = [
|
|
66
|
-
`I${entityNamePascal}CreateRequest`,
|
|
67
|
-
`I${entityNamePascal}UpdateRequest`,
|
|
68
|
-
`I${entityNamePascal}CollectionResponse`,
|
|
69
|
-
`I${entityNamePascal}CollectionQuery`
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
for (const interfaceName of modelInterfaces) {
|
|
73
|
-
const filePath = path.join(modelPath, toInterfaceFileName(interfaceName));
|
|
74
|
-
await writeIfNotExists(filePath, createInterfaceContent(interfaceName));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
for (const interfaceName of portInterfaces) {
|
|
78
|
-
const filePath = path.join(portsPath, toInterfaceFileName(interfaceName));
|
|
79
|
-
await writeIfNotExists(filePath, createInterfaceContent(interfaceName));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
await writeDomainIndexes(domainPath, modelPath, portsPath);
|
|
83
|
-
return { domainPath, modelPath, portsPath };
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const resolveDatasourceForPreset = async (contextName: string): Promise<DatasourceDescriptor | null> => {
|
|
87
|
-
const { contexts, sharedAlias } = await getConfigState();
|
|
88
|
-
const contextAlias = resolveContextAlias(contexts, contextName);
|
|
89
|
-
|
|
90
|
-
const sharedDatasources = await getAvailableTsNames(await resolveSharedDatasourcesPath());
|
|
91
|
-
const contextDatasources = await getAvailableTsNames(resolveDatasourcesPath(contextName));
|
|
92
|
-
|
|
93
|
-
if (sharedDatasources.includes('ApiDatasource')) {
|
|
94
|
-
return { name: 'ApiDatasource', importPath: getFoundationConstructImportPath(sharedAlias, 'datasource') };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (contextDatasources.includes('ApiDatasource')) {
|
|
98
|
-
return { name: 'ApiDatasource', importPath: `${contextAlias}/layers/infrastructure/http/datasources` };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (sharedDatasources.length) {
|
|
102
|
-
return { name: sharedDatasources[0] as string, importPath: getFoundationConstructImportPath(sharedAlias, 'datasource') };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (contextDatasources.length) {
|
|
106
|
-
return { name: contextDatasources[0] as string, importPath: `${contextAlias}/layers/infrastructure/http/datasources` };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return null;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const buildPresetMethods = ({
|
|
113
|
-
entityNamePascal,
|
|
114
|
-
route,
|
|
115
|
-
pathParamType
|
|
116
|
-
}: {
|
|
117
|
-
entityNamePascal: string;
|
|
118
|
-
route: string;
|
|
119
|
-
pathParamType: 'string' | 'number';
|
|
120
|
-
}): PresetMethod[] => [
|
|
121
|
-
{
|
|
122
|
-
name: 'collection',
|
|
123
|
-
httpMethod: 'get',
|
|
124
|
-
route,
|
|
125
|
-
response: { kind: 'domain', type: `I${entityNamePascal}CollectionResponse`, layer: 'ports' },
|
|
126
|
-
queryType: { name: `I${entityNamePascal}CollectionQuery`, layer: 'ports' },
|
|
127
|
-
bodyType: null,
|
|
128
|
-
pathParamType: null
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
name: 'resource',
|
|
132
|
-
httpMethod: 'get',
|
|
133
|
-
route,
|
|
134
|
-
response: { kind: 'domain', type: `I${entityNamePascal}`, layer: 'model' },
|
|
135
|
-
queryType: null,
|
|
136
|
-
bodyType: null,
|
|
137
|
-
pathParamType
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
name: 'create',
|
|
141
|
-
httpMethod: 'post',
|
|
142
|
-
route,
|
|
143
|
-
response: { kind: 'domain', type: `I${entityNamePascal}`, layer: 'model' },
|
|
144
|
-
queryType: null,
|
|
145
|
-
bodyType: { name: `I${entityNamePascal}CreateRequest`, layer: 'ports' },
|
|
146
|
-
pathParamType: null
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
name: 'update',
|
|
150
|
-
httpMethod: 'put',
|
|
151
|
-
route,
|
|
152
|
-
response: { kind: 'domain', type: `I${entityNamePascal}`, layer: 'model' },
|
|
153
|
-
queryType: null,
|
|
154
|
-
bodyType: { name: `I${entityNamePascal}UpdateRequest`, layer: 'ports' },
|
|
155
|
-
pathParamType
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
name: 'destroy',
|
|
159
|
-
httpMethod: 'delete',
|
|
160
|
-
route,
|
|
161
|
-
response: { kind: 'primitive', type: 'never', layer: null },
|
|
162
|
-
queryType: null,
|
|
163
|
-
bodyType: null,
|
|
164
|
-
pathParamType
|
|
165
|
-
}
|
|
166
|
-
];
|
|
167
|
-
|
|
168
|
-
const findProviderFile = async (
|
|
169
|
-
contextName: string,
|
|
170
|
-
layerName: 'application' | 'infrastructure',
|
|
171
|
-
preferredFileName: string
|
|
172
|
-
): Promise<string> => {
|
|
173
|
-
const providersPath = path.join(process.cwd(), 'src', 'app', contextName, 'layers', layerName, 'providers');
|
|
174
|
-
const preferredPath = path.join(providersPath, preferredFileName);
|
|
175
|
-
try {
|
|
176
|
-
await fs.access(preferredPath);
|
|
177
|
-
return preferredPath;
|
|
178
|
-
} catch {
|
|
179
|
-
try {
|
|
180
|
-
const files = await fs.readdir(providersPath);
|
|
181
|
-
const firstTs = files.find((item) => item.endsWith('.ts') && item !== 'index.ts');
|
|
182
|
-
return firstTs ? path.join(providersPath, firstTs) : preferredPath;
|
|
183
|
-
} catch {
|
|
184
|
-
return preferredPath;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
const parseProviderConstName = async (providerPath: string, fallbackName: string): Promise<string> => {
|
|
190
|
-
try {
|
|
191
|
-
const content = await fs.readFile(providerPath, 'utf-8');
|
|
192
|
-
const match = content.match(/export\s+const\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*createBoundaryProvider/);
|
|
193
|
-
return match?.[1] ?? fallbackName;
|
|
194
|
-
} catch {
|
|
195
|
-
return fallbackName;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export default async function generateModulePreset(): Promise<void> {
|
|
200
|
-
const contextName = await selectContext('Select context for preset module:');
|
|
201
|
-
if (!contextName) {
|
|
202
|
-
process.exitCode = 1;
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const { entityNameRaw } = await prompts({
|
|
207
|
-
type: 'text',
|
|
208
|
-
name: 'entityNameRaw',
|
|
209
|
-
message: 'Module name:',
|
|
210
|
-
validate: (value: string) => (String(value ?? '').trim().length > 0 ? true : 'Module name is required')
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
const { routeRaw } = await prompts({
|
|
214
|
-
type: 'text',
|
|
215
|
-
name: 'routeRaw',
|
|
216
|
-
message: 'Base request path (e.g. /users):',
|
|
217
|
-
initial: '/resource',
|
|
218
|
-
validate: (value: string) => {
|
|
219
|
-
const route = String(value ?? '').trim();
|
|
220
|
-
if (!route.length) return 'Path is required';
|
|
221
|
-
return route.startsWith('/') ? true : 'Path must start with "/"';
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
const { pathParamType } = await prompts({
|
|
226
|
-
type: 'select',
|
|
227
|
-
name: 'pathParamType',
|
|
228
|
-
message: 'Path param type:',
|
|
229
|
-
choices: [
|
|
230
|
-
{ title: 'string', value: 'string' },
|
|
231
|
-
{ title: 'number', value: 'number' }
|
|
232
|
-
],
|
|
233
|
-
initial: 0
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
const entityNamePascal = toPascalCase(String(entityNameRaw ?? '').trim());
|
|
237
|
-
if (!entityNamePascal) {
|
|
238
|
-
console.error('❌ Invalid module name.');
|
|
239
|
-
process.exitCode = 1;
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const route = String(routeRaw ?? '').trim();
|
|
244
|
-
if (!route) {
|
|
245
|
-
console.error('❌ Invalid route.');
|
|
246
|
-
process.exitCode = 1;
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const resolvedPathParamType: 'string' | 'number' = pathParamType === 'number' ? 'number' : 'string';
|
|
251
|
-
const domainName = toKebabCase(entityNamePascal);
|
|
252
|
-
|
|
253
|
-
await ensureDomainScaffold({ contextName, entityNamePascal, domainName });
|
|
254
|
-
|
|
255
|
-
const datasource = await resolveDatasourceForPreset(contextName);
|
|
256
|
-
if (!datasource) {
|
|
257
|
-
console.error('❌ No datasource found in shared foundation or selected context. Create datasource first.');
|
|
258
|
-
process.exitCode = 1;
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const methods = buildPresetMethods({
|
|
263
|
-
entityNamePascal,
|
|
264
|
-
route,
|
|
265
|
-
pathParamType: resolvedPathParamType
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
const repositoryClassName = `${entityNamePascal}Repository`;
|
|
269
|
-
const meta = getRepositoryMeta(repositoryClassName);
|
|
270
|
-
const { contexts } = await getConfigState();
|
|
271
|
-
const contextAlias = resolveContextAlias(contexts, contextName);
|
|
272
|
-
|
|
273
|
-
await writeRepositoryInterface({
|
|
274
|
-
contextName,
|
|
275
|
-
domainName,
|
|
276
|
-
meta,
|
|
277
|
-
methods
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
const repositoryContent = buildRepositoryContent({
|
|
281
|
-
meta,
|
|
282
|
-
contextAlias,
|
|
283
|
-
domainName,
|
|
284
|
-
datasource,
|
|
285
|
-
methods
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
const repositoriesPath = resolveRepositoriesPath(contextName);
|
|
289
|
-
await fs.mkdir(repositoriesPath, { recursive: true });
|
|
290
|
-
const repositoryPath = path.join(repositoriesPath, `${meta.className}.ts`);
|
|
291
|
-
const createdRepository = await writeIfNotExists(repositoryPath, repositoryContent);
|
|
292
|
-
await updateIndexTs(repositoriesPath);
|
|
293
|
-
|
|
294
|
-
if (!createdRepository) {
|
|
295
|
-
console.error(`❌ Repository "${meta.className}" already exists. Preset flow stopped.`);
|
|
296
|
-
process.exitCode = 1;
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
await createUseCasesForRepository({
|
|
301
|
-
contextName,
|
|
302
|
-
contextAlias,
|
|
303
|
-
domainName,
|
|
304
|
-
repositoryName: meta.className
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
const infrastructureProviderPath = await findProviderFile(contextName, 'infrastructure', 'InfrastructureProvider.ts');
|
|
308
|
-
const applicationProviderPath = await findProviderFile(contextName, 'application', 'ApplicationProvider.ts');
|
|
309
|
-
const infrastructureProviderName = await parseProviderConstName(infrastructureProviderPath, 'InfrastructureProvider');
|
|
310
|
-
|
|
311
|
-
console.log('\n⚠️ Manual provider registration is required before presenter generation.');
|
|
312
|
-
console.log(`Infrastructure provider file: ${infrastructureProviderPath}`);
|
|
313
|
-
console.log(`Application provider file: ${applicationProviderPath}`);
|
|
314
|
-
console.log('\nSuggested register snippets:');
|
|
315
|
-
console.log(`- Infrastructure register: ${meta.className}: () => new ${meta.className}(/* datasource */),`);
|
|
316
|
-
console.log(
|
|
317
|
-
`- Application register: ${meta.useCasesClassName}: () => new ${meta.useCasesClassName}(${infrastructureProviderName}().${meta.className}),`
|
|
318
|
-
);
|
|
319
|
-
|
|
320
|
-
const { readyAnswer } = await prompts({
|
|
321
|
-
type: 'text',
|
|
322
|
-
name: 'readyAnswer',
|
|
323
|
-
message: 'Type "y" when provider wiring is done:'
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
const normalizedReadyAnswer = String(readyAnswer ?? '')
|
|
327
|
-
.trim()
|
|
328
|
-
.toLowerCase();
|
|
329
|
-
if (normalizedReadyAnswer !== 'y') {
|
|
330
|
-
console.log('ℹ️ Preset module flow paused. Complete provider wiring and run `azure-net generate presenter`.');
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
await generatePresenter({
|
|
335
|
-
contextName,
|
|
336
|
-
useCasesName: meta.useCasesClassName
|
|
337
|
-
});
|
|
338
|
-
}
|