@azure-net/cli 4.0.0-0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/bin/azure-net.js +73 -34
  2. package/bin/azure-net.ts +81 -34
  3. package/eslint.config.js +15 -0
  4. package/package.json +1 -1
  5. package/src/checks/checkDomain.js +201 -0
  6. package/src/checks/checkDomain.ts +223 -0
  7. package/src/checks/checkFoldersStructure.js +70 -0
  8. package/src/checks/checkFoldersStructure.ts +85 -0
  9. package/src/checks/checkImports.ts +166 -0
  10. package/src/checks/checkInternal.js +37 -0
  11. package/src/checks/checkInternal.ts +44 -0
  12. package/src/checks/checkLayerBoundaries.js +178 -0
  13. package/src/checks/checkLayerBoundaries.ts +216 -0
  14. package/src/checks/checkPresenterNames.js +202 -0
  15. package/src/checks/checkPresenterNames.ts +208 -0
  16. package/src/checks/checkProject.js +42 -0
  17. package/src/checks/checkProject.ts +45 -0
  18. package/src/checks/checkProviderGraph.js +221 -0
  19. package/src/checks/checkProviderGraph.ts +234 -0
  20. package/src/checks/checkProviderNames.js +158 -0
  21. package/src/checks/checkProviderNames.ts +165 -0
  22. package/src/checks/index.js +8 -0
  23. package/src/checks/index.ts +9 -0
  24. package/src/generate/layers/generateRepository.ts +123 -0
  25. package/src/generate/layers/generateRepositoryMethod.ts +102 -0
  26. package/src/generate/layers/generateUseCases.ts +50 -0
  27. package/src/generate/layers/repositoryShared.ts +657 -0
  28. package/src/generate/module/generateModulePreset.js +307 -0
  29. package/src/generate/module/generateModulePreset.ts +337 -0
  30. package/src/generate/module/generateSchemaFromType.js +46 -8
  31. package/src/generate/module/generateSchemaFromType.ts +52 -8
  32. package/src/generate/module/repositoryModuleShared.ts +665 -0
  33. package/src/utils/contextUtils.ts +89 -0
  34. package/src/utils/fileUtils.ts +100 -0
  35. package/src/utils/loadConfig.ts +69 -0
  36. package/src/commands/generate/generateCrudBase.js +0 -188
  37. package/src/commands/generate/generateCrudPresenter.js +0 -225
  38. package/src/commands/generate/generateModule.js +0 -31
  39. package/src/commands/generate/generateModuleBase.js +0 -130
  40. package/src/commands/generate/generateModulePresenter.js +0 -103
  41. package/src/commands/generate/generatePresenter.js +0 -80
  42. package/src/commands/generate/generateRepository.js +0 -70
  43. package/src/commands/generate/generateSchema.js +0 -100
  44. package/src/commands/generate/generateService.js +0 -66
  45. package/src/commands/generate/index.js +0 -9
@@ -0,0 +1,208 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+
4
+ type PresenterOccurrence = {
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
+
14
+ const CREATE_FACTORY_PATTERN = '(?:export\\s+)?(?:const|let|var)\\s+([A-Za-z_$][A-Za-z0-9_$]*)\\s*=\\s*createPresenterFactory\\s*\\(';
15
+ const IMPORT_FROM_PRESENTER_PATTERN = 'import\\s*\\{([^}]+)\\}\\s*from\\s*[\'"]([^\'"]+)[\'"]';
16
+ const PRESENTER_CALL_PATTERN = '\\b([A-Za-z_$][A-Za-z0-9_$]*)\\s*\\(\\s*([\'"`])([^\'"`]*)\\2';
17
+
18
+ const toPosixPath = (value: string): string => value.split(path.sep).join('/');
19
+
20
+ const isPresenterImportPath = (importPath: string): boolean => {
21
+ const normalized = importPath.replace(/\\/g, '/');
22
+ return /(^|\/)presenter(\/|$)/.test(normalized);
23
+ };
24
+
25
+ const parseImportLocals = (rawImports: string): string[] => {
26
+ const locals: string[] = [];
27
+ for (const segment of rawImports.split(',')) {
28
+ const item = segment.trim();
29
+ if (!item.length) continue;
30
+ const aliasMatch = item.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
31
+ if (aliasMatch?.[2]) {
32
+ locals.push(aliasMatch[2]);
33
+ continue;
34
+ }
35
+
36
+ const directMatch = item.match(/^([A-Za-z_$][A-Za-z0-9_$]*)$/);
37
+ if (directMatch?.[1]) {
38
+ locals.push(directMatch[1]);
39
+ }
40
+ }
41
+ return locals;
42
+ };
43
+
44
+ const listSourceFiles = async (rootDir: string): Promise<string[]> => {
45
+ const result: string[] = [];
46
+ const stack: string[] = [rootDir];
47
+
48
+ while (stack.length) {
49
+ const current = stack.pop();
50
+ if (!current) continue;
51
+
52
+ let entries: import('node:fs').Dirent[] = [];
53
+ try {
54
+ entries = await fs.readdir(current, { withFileTypes: true });
55
+ } catch {
56
+ continue;
57
+ }
58
+
59
+ for (const entry of entries) {
60
+ if (entry.isDirectory()) {
61
+ if (!IGNORED_DIRS.has(entry.name)) {
62
+ stack.push(path.join(current, entry.name));
63
+ }
64
+ continue;
65
+ }
66
+
67
+ if (!entry.isFile()) continue;
68
+ const fullPath = path.join(current, entry.name);
69
+ const extension = path.extname(fullPath);
70
+ if (!TARGET_EXTENSIONS.has(extension)) continue;
71
+ result.push(fullPath);
72
+ }
73
+ }
74
+
75
+ return result;
76
+ };
77
+
78
+ const getLineByIndex = (content: string, index: number): number => {
79
+ let line = 1;
80
+ for (let i = 0; i < index; i += 1) {
81
+ if (content[i] === '\n') line += 1;
82
+ }
83
+ return line;
84
+ };
85
+
86
+ const extractFactoryNamesFromContent = (content: string): string[] => {
87
+ const createFactoryRegex = new RegExp(CREATE_FACTORY_PATTERN, 'g');
88
+ const names: string[] = [];
89
+ let match: RegExpExecArray | null;
90
+ while ((match = createFactoryRegex.exec(content)) !== null) {
91
+ const name = match[1];
92
+ if (name) names.push(name);
93
+ }
94
+ return names;
95
+ };
96
+
97
+ const extractImportedPresenterFactories = (content: string): string[] => {
98
+ const importFromPresenterRegex = new RegExp(IMPORT_FROM_PRESENTER_PATTERN, 'g');
99
+ const names: string[] = [];
100
+ let match: RegExpExecArray | null;
101
+ while ((match = importFromPresenterRegex.exec(content)) !== null) {
102
+ const rawImports = match[1];
103
+ const importPath = match[2];
104
+ if (!rawImports || !importPath) continue;
105
+ if (!isPresenterImportPath(importPath)) continue;
106
+ names.push(...parseImportLocals(rawImports));
107
+ }
108
+ return names;
109
+ };
110
+
111
+ const collectPresenterOccurrences = (content: string, filePath: string, knownFactories: Set<string>): PresenterOccurrence[] => {
112
+ const presenterCallRegex = new RegExp(PRESENTER_CALL_PATTERN, 'g');
113
+ const occurrences: PresenterOccurrence[] = [];
114
+ const availableCallees = new Set<string>(['createPresenter']);
115
+
116
+ for (const name of extractFactoryNamesFromContent(content)) {
117
+ availableCallees.add(name);
118
+ }
119
+ for (const name of extractImportedPresenterFactories(content)) {
120
+ availableCallees.add(name);
121
+ }
122
+ for (const name of knownFactories) {
123
+ availableCallees.add(name);
124
+ }
125
+
126
+ let match: RegExpExecArray | null;
127
+ while ((match = presenterCallRegex.exec(content)) !== null) {
128
+ const callee = match[1];
129
+ const quote = match[2];
130
+ const presenterId = match[3];
131
+ if (!callee || !presenterId) continue;
132
+ if (!availableCallees.has(callee)) continue;
133
+ if (quote === '`' && presenterId.includes('${')) continue;
134
+
135
+ occurrences.push({
136
+ id: presenterId,
137
+ file: filePath,
138
+ line: getLineByIndex(content, match.index),
139
+ callee
140
+ });
141
+ }
142
+
143
+ return occurrences;
144
+ };
145
+
146
+ export default async function checkPresenterNames(): Promise<void> {
147
+ const srcPath = path.join(process.cwd(), 'src');
148
+ try {
149
+ await fs.access(srcPath);
150
+ } catch {
151
+ console.error('❌ src folder not found in current workspace.');
152
+ process.exitCode = 1;
153
+ return;
154
+ }
155
+
156
+ const files = await listSourceFiles(srcPath);
157
+ const fileContents = new Map<string, string>();
158
+
159
+ for (const filePath of files) {
160
+ const content = await fs.readFile(filePath, 'utf-8');
161
+ fileContents.set(filePath, content);
162
+ }
163
+
164
+ const globalFactoryNames = new Set<string>();
165
+ for (const [filePath, content] of fileContents.entries()) {
166
+ for (const name of extractFactoryNamesFromContent(content)) {
167
+ globalFactoryNames.add(name);
168
+ }
169
+ if (filePath.endsWith(path.join('core', 'presenter', 'index.ts')) || filePath.endsWith(path.join('core', 'presenter', 'index.js'))) {
170
+ for (const name of extractImportedPresenterFactories(content)) {
171
+ globalFactoryNames.add(name);
172
+ }
173
+ }
174
+ }
175
+
176
+ const occurrences: PresenterOccurrence[] = [];
177
+ for (const [filePath, content] of fileContents.entries()) {
178
+ occurrences.push(...collectPresenterOccurrences(content, filePath, globalFactoryNames));
179
+ }
180
+
181
+ if (!occurrences.length) {
182
+ console.log('✅ No presenter declarations found.');
183
+ return;
184
+ }
185
+
186
+ const grouped = new Map<string, PresenterOccurrence[]>();
187
+ for (const occurrence of occurrences) {
188
+ const list = grouped.get(occurrence.id) ?? [];
189
+ list.push(occurrence);
190
+ grouped.set(occurrence.id, list);
191
+ }
192
+
193
+ const duplicated = Array.from(grouped.entries()).filter(([, list]) => list.length > 1);
194
+ if (!duplicated.length) {
195
+ console.log(`✅ Presenter names are unique (${occurrences.length} found).`);
196
+ return;
197
+ }
198
+
199
+ console.error('❌ Duplicate presenter names found:');
200
+ for (const [presenterId, list] of duplicated) {
201
+ console.error(`\n- "${presenterId}"`);
202
+ for (const item of list) {
203
+ console.error(` • ${toPosixPath(path.relative(process.cwd(), item.file))}:${item.line} (${item.callee})`);
204
+ }
205
+ }
206
+
207
+ process.exitCode = 1;
208
+ }
@@ -0,0 +1,42 @@
1
+ import { execSync } from 'node:child_process';
2
+ import { loadUserConfig } from '../utils/loadConfig.js';
3
+ import checkInternal from './checkInternal.js';
4
+
5
+ const isPackageManager = (value) => typeof value === 'string' && ['pnpm', 'npm', 'yarn', 'bun'].includes(value);
6
+
7
+ const runScript = (manager, script) => {
8
+ const command = `${manager} run ${script}`;
9
+ console.log(`\n▶ Running: ${command}`);
10
+ execSync(command, { stdio: 'inherit' });
11
+ };
12
+
13
+ const runInternalChecks = async () => {
14
+ console.log('\n▶ Running: azure-net check internal');
15
+ process.exitCode = 0;
16
+ await checkInternal();
17
+ if ((process.exitCode ?? 0) !== 0) {
18
+ throw new Error('azure-net check internal failed');
19
+ }
20
+ };
21
+
22
+ export default async function checkProject() {
23
+ const config = await loadUserConfig();
24
+ const manager = config.packageManager;
25
+
26
+ if (!isPackageManager(manager)) {
27
+ console.error('❌ packageManager is missing or invalid in azure-net.config.ts/js. Use one of: bun, pnpm, npm, yarn');
28
+ process.exitCode = 1;
29
+ return;
30
+ }
31
+
32
+ try {
33
+ runScript(manager, 'format');
34
+ await runInternalChecks();
35
+ runScript(manager, 'lint');
36
+ runScript(manager, 'check');
37
+ console.log('\n✅ Project checks passed.');
38
+ } catch (error) {
39
+ console.error(`\n❌ Project checks failed: ${error instanceof Error ? error.message : String(error)}`);
40
+ process.exitCode = 1;
41
+ }
42
+ }
@@ -0,0 +1,45 @@
1
+ import { execSync } from 'node:child_process';
2
+ import { loadUserConfig } from '../utils/loadConfig.js';
3
+ import checkInternal from './checkInternal.js';
4
+
5
+ type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';
6
+
7
+ const isPackageManager = (value: unknown): value is PackageManager =>
8
+ typeof value === 'string' && ['pnpm', 'npm', 'yarn', 'bun'].includes(value);
9
+
10
+ const runScript = (manager: PackageManager, script: string): void => {
11
+ const command = `${manager} run ${script}`;
12
+ console.log(`\n▶ Running: ${command}`);
13
+ execSync(command, { stdio: 'inherit' });
14
+ };
15
+
16
+ const runInternalChecks = async (): Promise<void> => {
17
+ console.log('\n▶ Running: azure-net check internal');
18
+ process.exitCode = 0;
19
+ await checkInternal();
20
+ if ((process.exitCode ?? 0) !== 0) {
21
+ throw new Error('azure-net check internal failed');
22
+ }
23
+ };
24
+
25
+ export default async function checkProject(): Promise<void> {
26
+ const config = await loadUserConfig();
27
+ const manager = config.packageManager;
28
+
29
+ if (!isPackageManager(manager)) {
30
+ console.error('❌ packageManager is missing or invalid in azure-net.config.ts/js. Use one of: bun, pnpm, npm, yarn');
31
+ process.exitCode = 1;
32
+ return;
33
+ }
34
+
35
+ try {
36
+ runScript(manager, 'format');
37
+ await runInternalChecks();
38
+ runScript(manager, 'lint');
39
+ runScript(manager, 'check');
40
+ console.log('\n✅ Project checks passed.');
41
+ } catch (error) {
42
+ console.error(`\n❌ Project checks failed: ${error instanceof Error ? error.message : String(error)}`);
43
+ process.exitCode = 1;
44
+ }
45
+ }
@@ -0,0 +1,221 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+
4
+ const TARGET_EXTENSIONS = new Set(['.ts', '.js']);
5
+ const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
6
+
7
+ const toPosixPath = (value) => value.split(path.sep).join('/');
8
+
9
+ const getLineByIndex = (content, index) => {
10
+ let line = 1;
11
+ for (let i = 0; i < index; i += 1) {
12
+ if (content[i] === '\n') line += 1;
13
+ }
14
+ return line;
15
+ };
16
+
17
+ const listSourceFiles = async (rootDir) => {
18
+ const files = [];
19
+ const stack = [rootDir];
20
+
21
+ while (stack.length) {
22
+ const current = stack.pop();
23
+ if (!current) continue;
24
+
25
+ let entries = [];
26
+ try {
27
+ entries = await fs.readdir(current, { withFileTypes: true });
28
+ } catch {
29
+ continue;
30
+ }
31
+
32
+ for (const entry of entries) {
33
+ if (entry.isDirectory()) {
34
+ if (!IGNORED_DIRS.has(entry.name)) stack.push(path.join(current, entry.name));
35
+ continue;
36
+ }
37
+
38
+ if (!entry.isFile()) continue;
39
+ const filePath = path.join(current, entry.name);
40
+ if (!TARGET_EXTENSIONS.has(path.extname(filePath))) continue;
41
+ files.push(filePath);
42
+ }
43
+ }
44
+
45
+ return files;
46
+ };
47
+
48
+ const findMatchingBracket = (content, startIndex, openChar, closeChar) => {
49
+ let depth = 0;
50
+ for (let i = startIndex; i < content.length; i += 1) {
51
+ const ch = content[i];
52
+ if (ch === openChar) depth += 1;
53
+ if (ch === closeChar) {
54
+ depth -= 1;
55
+ if (depth === 0) return i;
56
+ }
57
+ }
58
+ return -1;
59
+ };
60
+
61
+ const extractDependsOn = (configBlock) => {
62
+ const dependsOnMatch = configBlock.match(/dependsOn\s*:\s*\{([\s\S]*?)\}/m);
63
+ if (!dependsOnMatch?.[1]) return [];
64
+
65
+ const block = dependsOnMatch[1];
66
+ const deps = new Set();
67
+ const keyRegex = /([A-Za-z_$][A-Za-z0-9_$]*)\s*:/g;
68
+ let match;
69
+ while ((match = keyRegex.exec(block)) !== null) {
70
+ const key = match[1];
71
+ if (key) deps.add(key);
72
+ }
73
+ return [...deps];
74
+ };
75
+
76
+ const parseProviderGraphFromFile = (content, filePath) => {
77
+ const nodes = [];
78
+ const token = 'createBoundaryProvider(';
79
+ let fromIndex = 0;
80
+
81
+ while (fromIndex < content.length) {
82
+ const start = content.indexOf(token, fromIndex);
83
+ if (start === -1) break;
84
+
85
+ const openParenIndex = start + token.length - 1;
86
+ const closeParenIndex = findMatchingBracket(content, openParenIndex, '(', ')');
87
+ if (closeParenIndex === -1) break;
88
+
89
+ const fullCall = content.slice(openParenIndex + 1, closeParenIndex);
90
+ const idMatch = fullCall.match(/^\s*(['"`])([^'"`]+)\1\s*,/m);
91
+ const providerName = idMatch?.[2];
92
+ if (providerName) {
93
+ const objectStartInCall = fullCall.indexOf('{');
94
+ if (objectStartInCall !== -1) {
95
+ const absoluteObjectStart = openParenIndex + 1 + objectStartInCall;
96
+ const absoluteObjectEnd = findMatchingBracket(content, absoluteObjectStart, '{', '}');
97
+ const configBlock =
98
+ absoluteObjectEnd !== -1 ? content.slice(absoluteObjectStart, absoluteObjectEnd + 1) : fullCall.slice(objectStartInCall);
99
+
100
+ nodes.push({
101
+ name: providerName,
102
+ file: filePath,
103
+ line: getLineByIndex(content, start),
104
+ dependsOn: extractDependsOn(configBlock)
105
+ });
106
+ } else {
107
+ nodes.push({
108
+ name: providerName,
109
+ file: filePath,
110
+ line: getLineByIndex(content, start),
111
+ dependsOn: []
112
+ });
113
+ }
114
+ }
115
+
116
+ fromIndex = closeParenIndex + 1;
117
+ }
118
+
119
+ return nodes;
120
+ };
121
+
122
+ const findCycles = (graph) => {
123
+ const cycles = [];
124
+ const visited = new Set();
125
+ const inStack = new Set();
126
+ const stack = [];
127
+
128
+ const dfs = (node) => {
129
+ visited.add(node);
130
+ inStack.add(node);
131
+ stack.push(node);
132
+
133
+ const neighbors = graph.get(node) ?? [];
134
+ for (const next of neighbors) {
135
+ if (!graph.has(next)) continue;
136
+ if (!visited.has(next)) {
137
+ dfs(next);
138
+ continue;
139
+ }
140
+ if (inStack.has(next)) {
141
+ const idx = stack.indexOf(next);
142
+ if (idx !== -1) cycles.push([...stack.slice(idx), next]);
143
+ }
144
+ }
145
+
146
+ stack.pop();
147
+ inStack.delete(node);
148
+ };
149
+
150
+ for (const node of graph.keys()) {
151
+ if (!visited.has(node)) dfs(node);
152
+ }
153
+
154
+ return cycles;
155
+ };
156
+
157
+ export default async function checkProviderGraph() {
158
+ const srcPath = path.join(process.cwd(), 'src');
159
+ try {
160
+ await fs.access(srcPath);
161
+ } catch {
162
+ console.error('❌ src folder not found in current workspace.');
163
+ process.exitCode = 1;
164
+ return;
165
+ }
166
+
167
+ const files = await listSourceFiles(srcPath);
168
+ const providers = [];
169
+
170
+ for (const filePath of files) {
171
+ const content = await fs.readFile(filePath, 'utf-8');
172
+ providers.push(...parseProviderGraphFromFile(content, filePath));
173
+ }
174
+
175
+ if (!providers.length) {
176
+ console.log('✅ No createBoundaryProvider declarations found.');
177
+ return;
178
+ }
179
+
180
+ const graph = new Map();
181
+ const issues = [];
182
+ const byName = new Map();
183
+
184
+ for (const provider of providers) {
185
+ if (byName.has(provider.name)) {
186
+ const existing = byName.get(provider.name);
187
+ issues.push({
188
+ file: provider.file,
189
+ line: provider.line,
190
+ message: `Provider graph ambiguity: duplicate provider id "${provider.name}" (first declared at ${toPosixPath(
191
+ path.relative(process.cwd(), existing.file)
192
+ )}:${existing.line})`
193
+ });
194
+ continue;
195
+ }
196
+ byName.set(provider.name, provider);
197
+ graph.set(provider.name, provider.dependsOn);
198
+ }
199
+
200
+ const cycles = findCycles(graph);
201
+ for (const cycle of cycles) {
202
+ const firstNode = byName.get(cycle[0] ?? '');
203
+ issues.push({
204
+ file: firstNode?.file ?? srcPath,
205
+ line: firstNode?.line ?? 1,
206
+ message: `Circular provider dependency detected: ${cycle.join(' -> ')}`
207
+ });
208
+ }
209
+
210
+ if (!issues.length) {
211
+ console.log(`✅ Provider graph check passed (${providers.length} providers).`);
212
+ return;
213
+ }
214
+
215
+ console.error('❌ Provider graph check failed:');
216
+ for (const issue of issues) {
217
+ console.error(`• ${toPosixPath(path.relative(process.cwd(), issue.file))}:${issue.line} — ${issue.message}`);
218
+ }
219
+
220
+ process.exitCode = 1;
221
+ }