@azure-net/cli 4.0.0-0 → 4.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/azure-net.js +65 -34
- package/bin/azure-net.ts +65 -34
- package/eslint.config.js +15 -0
- package/package.json +1 -1
- package/src/checks/checkDomain.js +201 -0
- package/src/checks/checkDomain.ts +213 -0
- package/src/checks/checkFoldersStructure.js +70 -0
- package/src/checks/checkFoldersStructure.ts +85 -0
- package/src/checks/checkInternal.js +35 -0
- package/src/checks/checkInternal.ts +40 -0
- package/src/checks/checkLayerBoundaries.js +178 -0
- package/src/checks/checkLayerBoundaries.ts +189 -0
- package/src/checks/checkPresenterNames.js +202 -0
- package/src/checks/checkPresenterNames.ts +208 -0
- package/src/checks/checkProject.js +42 -0
- package/src/checks/checkProject.ts +45 -0
- package/src/checks/checkProviderNames.js +158 -0
- package/src/checks/checkProviderNames.ts +165 -0
- package/src/checks/index.js +7 -0
- package/src/checks/index.ts +7 -0
- package/src/generate/layers/generateRepository.ts +123 -0
- package/src/generate/layers/generateRepositoryMethod.ts +102 -0
- package/src/generate/layers/generateUseCases.ts +50 -0
- package/src/generate/layers/repositoryShared.ts +657 -0
- package/src/generate/module/generateModulePreset.js +307 -0
- package/src/generate/module/generateModulePreset.ts +337 -0
- package/src/generate/module/generateSchemaFromType.js +46 -8
- package/src/generate/module/generateSchemaFromType.ts +52 -8
- package/src/generate/module/repositoryModuleShared.ts +661 -0
- package/src/utils/contextUtils.ts +89 -0
- package/src/utils/fileUtils.ts +100 -0
- package/src/utils/loadConfig.ts +69 -0
- package/src/commands/generate/generateCrudBase.js +0 -188
- package/src/commands/generate/generateCrudPresenter.js +0 -225
- package/src/commands/generate/generateModule.js +0 -31
- package/src/commands/generate/generateModuleBase.js +0 -130
- package/src/commands/generate/generateModulePresenter.js +0 -103
- package/src/commands/generate/generatePresenter.js +0 -80
- package/src/commands/generate/generateRepository.js +0 -70
- package/src/commands/generate/generateSchema.js +0 -100
- package/src/commands/generate/generateService.js +0 -66
- package/src/commands/generate/index.js +0 -9
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
type ProviderOccurrence = {
|
|
5
|
+
id: string;
|
|
6
|
+
file: string;
|
|
7
|
+
line: number;
|
|
8
|
+
callee: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
|
|
12
|
+
const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
|
|
13
|
+
const IMPORT_PATTERN = 'import\\s*\\{([^}]+)\\}\\s*from\\s*[\'"]([^\'"]+)[\'"]';
|
|
14
|
+
const CALL_PATTERN = '\\b([A-Za-z_$][A-Za-z0-9_$]*)\\s*\\(\\s*([\'"`])([^\'"`]*)\\2';
|
|
15
|
+
|
|
16
|
+
const toPosixPath = (value: string): string => value.split(path.sep).join('/');
|
|
17
|
+
|
|
18
|
+
const parseImportAliases = (rawImports: string, importName: string): string[] => {
|
|
19
|
+
const aliases: string[] = [];
|
|
20
|
+
for (const segment of rawImports.split(',')) {
|
|
21
|
+
const item = segment.trim();
|
|
22
|
+
if (!item.length) continue;
|
|
23
|
+
|
|
24
|
+
const aliasMatch = item.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
|
|
25
|
+
if (aliasMatch?.[1] === importName && aliasMatch[2]) {
|
|
26
|
+
aliases.push(aliasMatch[2]);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (item === importName) {
|
|
31
|
+
aliases.push(importName);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return aliases;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const listSourceFiles = async (rootDir: string): Promise<string[]> => {
|
|
38
|
+
const files: string[] = [];
|
|
39
|
+
const stack: string[] = [rootDir];
|
|
40
|
+
|
|
41
|
+
while (stack.length) {
|
|
42
|
+
const current = stack.pop();
|
|
43
|
+
if (!current) continue;
|
|
44
|
+
|
|
45
|
+
let entries: import('node:fs').Dirent[] = [];
|
|
46
|
+
try {
|
|
47
|
+
entries = await fs.readdir(current, { withFileTypes: true });
|
|
48
|
+
} catch {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const entry of entries) {
|
|
53
|
+
if (entry.isDirectory()) {
|
|
54
|
+
if (!IGNORED_DIRS.has(entry.name)) {
|
|
55
|
+
stack.push(path.join(current, entry.name));
|
|
56
|
+
}
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!entry.isFile()) continue;
|
|
61
|
+
const filepath = path.join(current, entry.name);
|
|
62
|
+
if (!TARGET_EXTENSIONS.has(path.extname(filepath))) continue;
|
|
63
|
+
files.push(filepath);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return files;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const getLineByIndex = (content: string, index: number): number => {
|
|
71
|
+
let line = 1;
|
|
72
|
+
for (let i = 0; i < index; i += 1) {
|
|
73
|
+
if (content[i] === '\n') line += 1;
|
|
74
|
+
}
|
|
75
|
+
return line;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const extractBoundaryFactoryAliases = (content: string): Set<string> => {
|
|
79
|
+
const importRegex = new RegExp(IMPORT_PATTERN, 'g');
|
|
80
|
+
const aliases = new Set<string>(['createBoundaryProvider']);
|
|
81
|
+
let match: RegExpExecArray | null;
|
|
82
|
+
|
|
83
|
+
while ((match = importRegex.exec(content)) !== null) {
|
|
84
|
+
const rawImports = match[1];
|
|
85
|
+
if (!rawImports) continue;
|
|
86
|
+
for (const alias of parseImportAliases(rawImports, 'createBoundaryProvider')) {
|
|
87
|
+
aliases.add(alias);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return aliases;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const collectProviderOccurrences = (content: string, filepath: string): ProviderOccurrence[] => {
|
|
95
|
+
const aliases = extractBoundaryFactoryAliases(content);
|
|
96
|
+
const callRegex = new RegExp(CALL_PATTERN, 'g');
|
|
97
|
+
const occurrences: ProviderOccurrence[] = [];
|
|
98
|
+
let match: RegExpExecArray | null;
|
|
99
|
+
|
|
100
|
+
while ((match = callRegex.exec(content)) !== null) {
|
|
101
|
+
const callee = match[1];
|
|
102
|
+
const quote = match[2];
|
|
103
|
+
const providerId = match[3];
|
|
104
|
+
|
|
105
|
+
if (!callee || !providerId) continue;
|
|
106
|
+
if (!aliases.has(callee)) continue;
|
|
107
|
+
if (quote === '`' && providerId.includes('${')) continue;
|
|
108
|
+
|
|
109
|
+
occurrences.push({
|
|
110
|
+
id: providerId,
|
|
111
|
+
file: filepath,
|
|
112
|
+
line: getLineByIndex(content, match.index),
|
|
113
|
+
callee
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return occurrences;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default async function checkProviderNames(): Promise<void> {
|
|
121
|
+
const srcPath = path.join(process.cwd(), 'src');
|
|
122
|
+
try {
|
|
123
|
+
await fs.access(srcPath);
|
|
124
|
+
} catch {
|
|
125
|
+
console.error('❌ src folder not found in current workspace.');
|
|
126
|
+
process.exitCode = 1;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const files = await listSourceFiles(srcPath);
|
|
131
|
+
const occurrences: ProviderOccurrence[] = [];
|
|
132
|
+
|
|
133
|
+
for (const filepath of files) {
|
|
134
|
+
const content = await fs.readFile(filepath, 'utf-8');
|
|
135
|
+
occurrences.push(...collectProviderOccurrences(content, filepath));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!occurrences.length) {
|
|
139
|
+
console.log('✅ No providers declarations found.');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const grouped = new Map<string, ProviderOccurrence[]>();
|
|
144
|
+
for (const occurrence of occurrences) {
|
|
145
|
+
const list = grouped.get(occurrence.id) ?? [];
|
|
146
|
+
list.push(occurrence);
|
|
147
|
+
grouped.set(occurrence.id, list);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const duplicated = Array.from(grouped.entries()).filter(([, list]) => list.length > 1);
|
|
151
|
+
if (!duplicated.length) {
|
|
152
|
+
console.log(`✅ Provider names are unique (${occurrences.length} found).`);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
console.error('❌ Duplicate provider names found:');
|
|
157
|
+
for (const [providerId, list] of duplicated) {
|
|
158
|
+
console.error(`\n- "${providerId}"`);
|
|
159
|
+
for (const item of list) {
|
|
160
|
+
console.error(` • ${toPosixPath(path.relative(process.cwd(), item.file))}:${item.line} (${item.callee})`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
process.exitCode = 1;
|
|
165
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as checkPresenterNames } from './checkPresenterNames.js';
|
|
2
|
+
export { default as checkProviderNames } from './checkProviderNames.js';
|
|
3
|
+
export { default as checkDomain } from './checkDomain.js';
|
|
4
|
+
export { default as checkLayerBoundaries } from './checkLayerBoundaries.js';
|
|
5
|
+
export { default as checkFoldersStructure } from './checkFoldersStructure.js';
|
|
6
|
+
export { default as checkInternal } from './checkInternal.js';
|
|
7
|
+
export { default as checkProject } from './checkProject.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as checkPresenterNames } from './checkPresenterNames.js';
|
|
2
|
+
export { default as checkProviderNames } from './checkProviderNames.js';
|
|
3
|
+
export { default as checkDomain } from './checkDomain.js';
|
|
4
|
+
export { default as checkLayerBoundaries } from './checkLayerBoundaries.js';
|
|
5
|
+
export { default as checkFoldersStructure } from './checkFoldersStructure.js';
|
|
6
|
+
export { default as checkInternal } from './checkInternal.js';
|
|
7
|
+
export { default as checkProject } from './checkProject.js';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import prompts from 'prompts';
|
|
4
|
+
import {
|
|
5
|
+
buildRepositoryContent,
|
|
6
|
+
ensureDomainType,
|
|
7
|
+
ensureRepositoryInterfaceFile,
|
|
8
|
+
ensureRepositoryName,
|
|
9
|
+
ensureUseCasesFile,
|
|
10
|
+
getConfigState,
|
|
11
|
+
getRepositoryMeta,
|
|
12
|
+
resolveContextAlias,
|
|
13
|
+
resolveRepositoriesPath,
|
|
14
|
+
selectContext,
|
|
15
|
+
selectDatasource,
|
|
16
|
+
promptMethodDefinition
|
|
17
|
+
} from './repositoryShared.js';
|
|
18
|
+
import { updateIndexTs, writeIfNotExists } from '../../utils/fileUtils.js';
|
|
19
|
+
|
|
20
|
+
export default async function generateRepository(): Promise<void> {
|
|
21
|
+
const { rawName } = await prompts({
|
|
22
|
+
type: 'text',
|
|
23
|
+
name: 'rawName',
|
|
24
|
+
message: 'Repository name:',
|
|
25
|
+
validate: (value) => (String(value ?? '').trim().length > 0 ? true : 'Repository name is required')
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const className = ensureRepositoryName(rawName);
|
|
29
|
+
const meta = getRepositoryMeta(className);
|
|
30
|
+
const contextName = await selectContext('Select context for repository:');
|
|
31
|
+
if (!contextName) {
|
|
32
|
+
process.exitCode = 1;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const datasource = await selectDatasource(contextName);
|
|
37
|
+
if (!datasource) {
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { methodsCountRaw } = await prompts({
|
|
43
|
+
type: 'number',
|
|
44
|
+
name: 'methodsCountRaw',
|
|
45
|
+
message: 'How many methods to create?',
|
|
46
|
+
initial: 1,
|
|
47
|
+
min: 0
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const methodsCount = Number(methodsCountRaw ?? 0);
|
|
51
|
+
if (!Number.isFinite(methodsCount) || methodsCount < 0) {
|
|
52
|
+
console.error('❌ Invalid methods count.');
|
|
53
|
+
process.exitCode = 1;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const methods: Array<Awaited<ReturnType<typeof promptMethodDefinition>>> = [];
|
|
58
|
+
for (let index = 0; index < methodsCount; index += 1) {
|
|
59
|
+
console.log(`\n🧩 Method ${index + 1} of ${methodsCount}`);
|
|
60
|
+
const method = await promptMethodDefinition();
|
|
61
|
+
methods.push(method);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const { contexts } = await getConfigState();
|
|
65
|
+
const contextAlias = resolveContextAlias(contexts, contextName);
|
|
66
|
+
const repositoriesPath = resolveRepositoriesPath(contextName);
|
|
67
|
+
await fs.mkdir(repositoriesPath, { recursive: true });
|
|
68
|
+
const repositoryPath = path.join(repositoriesPath, `${meta.className}.ts`);
|
|
69
|
+
|
|
70
|
+
for (const method of methods) {
|
|
71
|
+
if (!method) continue;
|
|
72
|
+
const ensuredResponseType = await ensureDomainType({
|
|
73
|
+
contextName,
|
|
74
|
+
domainName: meta.domainName,
|
|
75
|
+
typeName: method.responseType,
|
|
76
|
+
layer: method.responseLayer
|
|
77
|
+
});
|
|
78
|
+
method.responseType = ensuredResponseType.interfaceName;
|
|
79
|
+
method.responseLayer = ensuredResponseType.layer;
|
|
80
|
+
|
|
81
|
+
if (method.requestType) {
|
|
82
|
+
const ensuredRequestType = await ensureDomainType({
|
|
83
|
+
contextName,
|
|
84
|
+
domainName: meta.domainName,
|
|
85
|
+
typeName: method.requestType,
|
|
86
|
+
layer: method.requestLayer ?? 'ports'
|
|
87
|
+
});
|
|
88
|
+
method.requestType = ensuredRequestType.interfaceName;
|
|
89
|
+
method.requestLayer = ensuredRequestType.layer;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const filteredMethods = methods.filter(Boolean);
|
|
94
|
+
await ensureRepositoryInterfaceFile({ contextName, meta, methods: filteredMethods });
|
|
95
|
+
const repositoryContent = buildRepositoryContent({
|
|
96
|
+
meta,
|
|
97
|
+
contextAlias,
|
|
98
|
+
datasourceImportPath: datasource.importPath,
|
|
99
|
+
datasourceName: datasource.name,
|
|
100
|
+
methods: filteredMethods
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const created = await writeIfNotExists(repositoryPath, repositoryContent);
|
|
104
|
+
await updateIndexTs(repositoriesPath);
|
|
105
|
+
if (!created) {
|
|
106
|
+
console.warn(`⚠️ Repository "${meta.className}" already exists. File was not overwritten.`);
|
|
107
|
+
process.exitCode = 1;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const { shouldCreateUseCases } = await prompts({
|
|
112
|
+
type: 'confirm',
|
|
113
|
+
name: 'shouldCreateUseCases',
|
|
114
|
+
message: 'Create UseCases for this repository?',
|
|
115
|
+
initial: true
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (shouldCreateUseCases) {
|
|
119
|
+
await ensureUseCasesFile({ contextName, contextAlias, meta });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(`✅ Repository generated: ${repositoryPath}`);
|
|
123
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import prompts from 'prompts';
|
|
4
|
+
import {
|
|
5
|
+
appendRepositoryMethod,
|
|
6
|
+
ensureDomainType,
|
|
7
|
+
ensureRepositoryInterfaceFile,
|
|
8
|
+
getAvailableTsNames,
|
|
9
|
+
getConfigState,
|
|
10
|
+
getRepositoryMeta,
|
|
11
|
+
parseRepositoryMethods,
|
|
12
|
+
resolveContextAlias,
|
|
13
|
+
resolveRepositoriesPath,
|
|
14
|
+
selectContext,
|
|
15
|
+
promptMethodDefinition
|
|
16
|
+
} from './repositoryShared.js';
|
|
17
|
+
|
|
18
|
+
export default async function generateRepositoryMethod(): Promise<void> {
|
|
19
|
+
const contextName = await selectContext('Select context for repository method:');
|
|
20
|
+
if (!contextName) {
|
|
21
|
+
process.exitCode = 1;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const repositoriesPath = resolveRepositoriesPath(contextName);
|
|
26
|
+
const repositories = await getAvailableTsNames(repositoriesPath);
|
|
27
|
+
if (!repositories.length) {
|
|
28
|
+
console.error(`❌ No repositories found in ${repositoriesPath}`);
|
|
29
|
+
process.exitCode = 1;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { repositoryName } = await prompts({
|
|
34
|
+
type: 'select',
|
|
35
|
+
name: 'repositoryName',
|
|
36
|
+
message: 'Select repository:',
|
|
37
|
+
choices: repositories.map((name: string) => ({ title: name, value: name })),
|
|
38
|
+
initial: 0
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (!repositoryName) {
|
|
42
|
+
process.exitCode = 1;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const meta = getRepositoryMeta(String(repositoryName));
|
|
47
|
+
const repositoryPath = path.join(repositoriesPath, `${meta.className}.ts`);
|
|
48
|
+
const method = await promptMethodDefinition();
|
|
49
|
+
|
|
50
|
+
const ensuredResponseType = await ensureDomainType({
|
|
51
|
+
contextName,
|
|
52
|
+
domainName: meta.domainName,
|
|
53
|
+
typeName: method.responseType,
|
|
54
|
+
layer: method.responseLayer
|
|
55
|
+
});
|
|
56
|
+
method.responseType = ensuredResponseType.interfaceName;
|
|
57
|
+
method.responseLayer = ensuredResponseType.layer;
|
|
58
|
+
|
|
59
|
+
if (method.requestType) {
|
|
60
|
+
const ensuredRequestType = await ensureDomainType({
|
|
61
|
+
contextName,
|
|
62
|
+
domainName: meta.domainName,
|
|
63
|
+
typeName: method.requestType,
|
|
64
|
+
layer: method.requestLayer ?? 'ports'
|
|
65
|
+
});
|
|
66
|
+
method.requestType = ensuredRequestType.interfaceName;
|
|
67
|
+
method.requestLayer = ensuredRequestType.layer;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let repositoryContent = '';
|
|
71
|
+
try {
|
|
72
|
+
repositoryContent = await fs.readFile(repositoryPath, 'utf-8');
|
|
73
|
+
} catch {
|
|
74
|
+
console.error(`❌ Repository file not found: ${repositoryPath}`);
|
|
75
|
+
process.exitCode = 1;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const existingMethods = parseRepositoryMethods(repositoryContent);
|
|
80
|
+
if (existingMethods.some((item) => item.name === method.name)) {
|
|
81
|
+
console.warn(`⚠️ Method "${method.name}" already exists in ${meta.className}.`);
|
|
82
|
+
process.exitCode = 1;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const { contexts } = await getConfigState();
|
|
87
|
+
const contextAlias = resolveContextAlias(contexts, contextName);
|
|
88
|
+
await appendRepositoryMethod({
|
|
89
|
+
repositoryPath,
|
|
90
|
+
method,
|
|
91
|
+
contextAlias,
|
|
92
|
+
domainName: meta.domainName
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
await ensureRepositoryInterfaceFile({
|
|
96
|
+
contextName,
|
|
97
|
+
meta,
|
|
98
|
+
methods: [...existingMethods, method]
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
console.log(`✅ Method "${method.name}" added to ${meta.className}`);
|
|
102
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import prompts from 'prompts';
|
|
2
|
+
import {
|
|
3
|
+
ensureUseCasesFile,
|
|
4
|
+
getAvailableTsNames,
|
|
5
|
+
getConfigState,
|
|
6
|
+
getRepositoryMeta,
|
|
7
|
+
resolveContextAlias,
|
|
8
|
+
resolveRepositoriesPath,
|
|
9
|
+
selectContext
|
|
10
|
+
} from './repositoryShared.js';
|
|
11
|
+
|
|
12
|
+
export default async function generateUseCases(): Promise<void> {
|
|
13
|
+
const contextName = await selectContext('Select context for UseCases:');
|
|
14
|
+
if (!contextName) {
|
|
15
|
+
process.exitCode = 1;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const repositoriesPath = resolveRepositoriesPath(contextName);
|
|
20
|
+
const repositories = await getAvailableTsNames(repositoriesPath);
|
|
21
|
+
if (!repositories.length) {
|
|
22
|
+
console.error(`❌ No repositories found in ${repositoriesPath}`);
|
|
23
|
+
process.exitCode = 1;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const { repositoryName } = await prompts({
|
|
28
|
+
type: 'select',
|
|
29
|
+
name: 'repositoryName',
|
|
30
|
+
message: 'Select repository:',
|
|
31
|
+
choices: repositories.map((name: string) => ({ title: name, value: name })),
|
|
32
|
+
initial: 0
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (!repositoryName) {
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { contexts } = await getConfigState();
|
|
41
|
+
const contextAlias = resolveContextAlias(contexts, contextName);
|
|
42
|
+
const meta = getRepositoryMeta(String(repositoryName));
|
|
43
|
+
const created = await ensureUseCasesFile({ contextName, contextAlias, meta });
|
|
44
|
+
if (!created) {
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(`✅ UseCases generated: ${meta.useCasesClassName}`);
|
|
50
|
+
}
|