@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.
Files changed (176) hide show
  1. package/README.md +189 -0
  2. package/bin/azure-net.js +236 -221
  3. package/dist/bin/azure-net.d.ts +2 -0
  4. package/dist/src/checks/architecture.d.ts +20 -0
  5. package/dist/src/checks/checkDomain.d.ts +1 -0
  6. package/dist/src/checks/checkFoldersStructure.d.ts +1 -0
  7. package/dist/src/checks/checkHooks.d.ts +1 -0
  8. package/dist/src/checks/checkImports.d.ts +1 -0
  9. package/dist/src/checks/checkInternal.d.ts +1 -0
  10. package/dist/src/checks/checkLayerBoundaries.d.ts +1 -0
  11. package/dist/src/checks/checkLayerImports.d.ts +1 -0
  12. package/dist/src/checks/checkPresenterNames.d.ts +1 -0
  13. package/dist/src/checks/checkProject.d.ts +1 -0
  14. package/dist/src/checks/checkProviderGraph.d.ts +1 -0
  15. package/dist/src/checks/checkProviderNames.d.ts +1 -0
  16. package/dist/src/generate/layers/generateRepository.d.ts +1 -0
  17. package/dist/src/generate/layers/generateRepositoryMethod.d.ts +1 -0
  18. package/dist/src/generate/layers/generateUseCases.d.ts +1 -0
  19. package/dist/src/generate/module/generateDomain.d.ts +8 -0
  20. package/dist/src/generate/module/generateModule.d.ts +1 -0
  21. package/dist/src/generate/module/generateModulePreset.d.ts +1 -0
  22. package/dist/src/generate/module/generatePresenter.d.ts +29 -0
  23. package/dist/src/generate/module/generateRepository.d.ts +15 -0
  24. package/dist/src/generate/module/generateRepositoryMethod.d.ts +2 -0
  25. package/dist/src/generate/module/generateSchemaFromType.d.ts +9 -0
  26. package/dist/src/generate/module/generateStore.d.ts +1 -0
  27. package/dist/src/generate/module/generateTypesJson.d.ts +2 -0
  28. package/dist/src/generate/module/generateUseCases.d.ts +1 -0
  29. package/dist/src/generate/module/repositoryModuleShared.d.ts +89 -0
  30. package/dist/src/generate/routes/generateRoutes.d.ts +14 -0
  31. package/dist/src/generate/ui/generateComponent.d.ts +1 -0
  32. package/dist/src/generate/ui/generateDesignComponent.d.ts +1 -0
  33. package/dist/src/generate/ui/generateWidget.d.ts +1 -0
  34. package/dist/src/git/commit.d.ts +23 -0
  35. package/dist/src/git/push.d.ts +11 -0
  36. package/dist/src/git/runGit.d.ts +2 -0
  37. package/dist/src/init/initAliases.d.ts +12 -0
  38. package/dist/src/init/initEdges.d.ts +2 -0
  39. package/dist/src/init/initStructure.d.ts +1 -0
  40. package/dist/src/install/configureCommitTools.d.ts +1 -0
  41. package/dist/src/install/installFresh.d.ts +1 -0
  42. package/dist/src/migrate/migrate.d.ts +22 -0
  43. package/dist/src/migrate/presenters.d.ts +7 -0
  44. package/dist/src/plugins/addLint.d.ts +5 -0
  45. package/dist/src/scaffolds/createCoreSchema.d.ts +1 -0
  46. package/dist/src/scaffolds/createDatasource.d.ts +1 -0
  47. package/dist/src/scaffolds/createProgram.d.ts +1 -0
  48. package/dist/src/scaffolds/createResponse.d.ts +1 -0
  49. package/dist/src/scaffolds/createSchemaRule.d.ts +1 -0
  50. package/dist/src/scaffolds/createTranslationManager.d.ts +1 -0
  51. package/{src/scaffolds/index.ts → dist/src/scaffolds/index.d.ts} +0 -2
  52. package/dist/src/scaffolds/registerDatasource.d.ts +2 -0
  53. package/dist/src/scaffolds/updateDefaultFactoryConfig.d.ts +1 -0
  54. package/dist/src/utils/architecture.d.ts +31 -0
  55. package/dist/src/utils/contextUtils.d.ts +6 -0
  56. package/dist/src/utils/fileUtils.d.ts +5 -0
  57. package/dist/src/utils/flattenConfig.d.ts +2 -0
  58. package/dist/src/utils/legacyAliases.d.ts +1 -0
  59. package/dist/src/utils/loadConfig.d.ts +16 -0
  60. package/dist/src/utils/packageImports.d.ts +4 -0
  61. package/dist/src/utils/sharedFoundation.d.ts +20 -0
  62. package/dist/src/utils/viteConfig.d.ts +9 -0
  63. package/package.json +48 -36
  64. package/src/checks/architecture.js +154 -0
  65. package/src/checks/checkDomain.js +124 -154
  66. package/src/checks/checkFoldersStructure.js +64 -52
  67. package/src/checks/checkHooks.js +12 -12
  68. package/src/checks/checkImports.js +26 -142
  69. package/src/checks/checkInternal.js +27 -24
  70. package/src/checks/checkLayerBoundaries.js +22 -197
  71. package/src/checks/checkLayerImports.js +14 -134
  72. package/src/checks/checkPresenterNames.js +156 -143
  73. package/src/checks/checkProject.js +27 -26
  74. package/src/checks/checkProviderGraph.js +182 -166
  75. package/src/checks/checkProviderNames.js +123 -112
  76. package/src/generate/layers/generateRepository.js +1 -109
  77. package/src/generate/layers/generateRepositoryMethod.js +1 -90
  78. package/src/generate/layers/generateUseCases.js +1 -44
  79. package/src/generate/module/generateDomain.js +81 -105
  80. package/src/generate/module/generateModule.js +34 -68
  81. package/src/generate/module/generateModulePreset.js +188 -248
  82. package/src/generate/module/generatePresenter.js +441 -369
  83. package/src/generate/module/generateRepository.js +102 -121
  84. package/src/generate/module/generateRepositoryMethod.js +117 -0
  85. package/src/generate/module/generateSchemaFromType.js +283 -280
  86. package/src/generate/module/generateStore.js +41 -0
  87. package/src/generate/module/generateTypesJson.js +196 -195
  88. package/src/generate/module/generateUseCases.js +47 -55
  89. package/src/generate/module/repositoryModuleShared.js +480 -459
  90. package/src/generate/routes/generateRoutes.js +165 -174
  91. package/src/generate/ui/generateComponent.js +44 -64
  92. package/src/generate/ui/generateDesignComponent.js +21 -41
  93. package/src/generate/ui/generateWidget.js +21 -41
  94. package/src/git/commit.js +67 -0
  95. package/src/git/push.js +19 -0
  96. package/src/git/runGit.js +11 -0
  97. package/src/init/initAliases.js +19 -135
  98. package/src/init/initEdges.js +79 -54
  99. package/src/init/initStructure.js +31 -145
  100. package/src/install/configureCommitTools.js +1 -0
  101. package/src/install/installFresh.js +39 -68
  102. package/src/migrate/migrate.js +914 -0
  103. package/src/migrate/presenters.js +265 -0
  104. package/src/plugins/addLint.js +52 -219
  105. package/src/scaffolds/createCoreSchema.js +65 -91
  106. package/src/scaffolds/createDatasource.js +67 -101
  107. package/src/scaffolds/createProgram.js +8 -8
  108. package/src/scaffolds/createResponse.js +29 -29
  109. package/src/scaffolds/createSchemaRule.js +19 -19
  110. package/src/scaffolds/createTranslationManager.js +84 -37
  111. package/src/scaffolds/index.js +0 -2
  112. package/src/scaffolds/registerDatasource.js +59 -0
  113. package/src/scaffolds/updateDefaultFactoryConfig.js +31 -0
  114. package/src/utils/architecture.js +145 -0
  115. package/src/utils/contextUtils.js +32 -65
  116. package/src/utils/fileUtils.js +69 -50
  117. package/src/utils/flattenConfig.js +38 -0
  118. package/src/utils/legacyAliases.js +75 -0
  119. package/src/utils/loadConfig.js +76 -40
  120. package/src/utils/packageImports.js +63 -0
  121. package/src/utils/sharedFoundation.js +36 -42
  122. package/src/utils/viteConfig.js +295 -0
  123. package/.prettierrc +0 -7
  124. package/bin/azure-net.ts +0 -308
  125. package/eslint.config.js +0 -34
  126. package/src/checks/checkDomain.ts +0 -223
  127. package/src/checks/checkFoldersStructure.ts +0 -85
  128. package/src/checks/checkHooks.ts +0 -22
  129. package/src/checks/checkImports.ts +0 -193
  130. package/src/checks/checkInternal.ts +0 -48
  131. package/src/checks/checkLayerBoundaries.ts +0 -255
  132. package/src/checks/checkLayerImports.ts +0 -185
  133. package/src/checks/checkPresenterNames.ts +0 -203
  134. package/src/checks/checkProject.ts +0 -45
  135. package/src/checks/checkProviderGraph.ts +0 -234
  136. package/src/checks/checkProviderNames.ts +0 -165
  137. package/src/generate/layers/generateRepository.ts +0 -123
  138. package/src/generate/layers/generateRepositoryMethod.ts +0 -102
  139. package/src/generate/layers/generateUseCases.ts +0 -50
  140. package/src/generate/layers/repositoryShared.js +0 -506
  141. package/src/generate/layers/repositoryShared.ts +0 -662
  142. package/src/generate/module/generateDomain.ts +0 -147
  143. package/src/generate/module/generateModule.ts +0 -84
  144. package/src/generate/module/generateModulePreset.ts +0 -338
  145. package/src/generate/module/generatePresenter.ts +0 -498
  146. package/src/generate/module/generateRepository.ts +0 -158
  147. package/src/generate/module/generateSchemaFromType.ts +0 -368
  148. package/src/generate/module/generateTypesJson.ts +0 -259
  149. package/src/generate/module/generateUseCases.ts +0 -67
  150. package/src/generate/module/repositoryModuleShared.ts +0 -669
  151. package/src/generate/routes/generateRoutes.ts +0 -282
  152. package/src/generate/ui/generateComponent.ts +0 -100
  153. package/src/generate/ui/generateDesignComponent.ts +0 -71
  154. package/src/generate/ui/generateWidget.ts +0 -71
  155. package/src/init/initAliases.ts +0 -172
  156. package/src/init/initEdges.ts +0 -74
  157. package/src/init/initStructure.ts +0 -172
  158. package/src/install/installFresh.ts +0 -93
  159. package/src/plugins/addLint.ts +0 -274
  160. package/src/scaffolds/createCoreSchema.ts +0 -130
  161. package/src/scaffolds/createDatasource.ts +0 -161
  162. package/src/scaffolds/createDatasourceProvider.js +0 -127
  163. package/src/scaffolds/createDatasourceProvider.ts +0 -161
  164. package/src/scaffolds/createPresenterFactory.js +0 -83
  165. package/src/scaffolds/createPresenterFactory.ts +0 -102
  166. package/src/scaffolds/createProgram.ts +0 -19
  167. package/src/scaffolds/createResponse.ts +0 -66
  168. package/src/scaffolds/createSchemaRule.ts +0 -44
  169. package/src/scaffolds/createTranslationManager.ts +0 -80
  170. package/src/utils/contextUtils.ts +0 -88
  171. package/src/utils/fileUtils.ts +0 -74
  172. package/src/utils/loadConfig.ts +0 -68
  173. package/src/utils/sharedFoundation.ts +0 -70
  174. package/tsconfig.json +0 -19
  175. /package/{src/checks/index.ts → dist/src/checks/index.d.ts} +0 -0
  176. /package/{src/plugins/index.ts → dist/src/plugins/index.d.ts} +0 -0
@@ -1,255 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { loadUserConfig } from '../utils/loadConfig.js';
4
- import { normalizeContexts } from '../init/initAliases.js';
5
- import { SHARED_ESSENTIALS_DIR_NAME } from '../utils/sharedFoundation.js';
6
-
7
- type BoundaryIssue = {
8
- file: string;
9
- line: number;
10
- message: string;
11
- };
12
-
13
- type ContextConfig = {
14
- name: string;
15
- alias: string;
16
- };
17
-
18
- const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
19
- const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
20
-
21
- const IMPORT_FROM_PATTERN = /\bimport\s+(?:type\s+)?[\s\S]*?\sfrom\s*['"]([^'"]+)['"]/g;
22
- const EXPORT_FROM_PATTERN = /\bexport\s+(?:type\s+)?\{[\s\S]*?\}\sfrom\s*['"]([^'"]+)['"]/g;
23
- const DYNAMIC_IMPORT_PATTERN = /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
24
-
25
- const toPosixPath = (value: string): string => value.split(path.sep).join('/');
26
-
27
- const normalizeAlias = (value: unknown, fallback = ''): string => {
28
- const raw = String(value ?? '').trim();
29
- if (!raw.length) return fallback;
30
- return raw.startsWith('$') ? raw : `$${raw}`;
31
- };
32
-
33
- const findLineByIndex = (content: string, index: number): number => {
34
- let line = 1;
35
- for (let i = 0; i < index; i += 1) {
36
- if (content[i] === '\n') line += 1;
37
- }
38
- return line;
39
- };
40
-
41
- const getRelativePath = (filePath: string): string => toPosixPath(path.relative(process.cwd(), filePath));
42
-
43
- const listFiles = async (rootDir: string): Promise<string[]> => {
44
- const files: string[] = [];
45
- const stack: string[] = [rootDir];
46
-
47
- while (stack.length) {
48
- const current = stack.pop();
49
- if (!current) continue;
50
-
51
- let entries: import('node:fs').Dirent[] = [];
52
- try {
53
- entries = await fs.readdir(current, { withFileTypes: true });
54
- } catch {
55
- continue;
56
- }
57
-
58
- for (const entry of entries) {
59
- if (entry.isDirectory()) {
60
- if (!IGNORED_DIRS.has(entry.name)) {
61
- stack.push(path.join(current, entry.name));
62
- }
63
- continue;
64
- }
65
-
66
- if (!entry.isFile()) continue;
67
- const filePath = path.join(current, entry.name);
68
- if (!TARGET_EXTENSIONS.has(path.extname(filePath))) continue;
69
- files.push(filePath);
70
- }
71
- }
72
-
73
- return files;
74
- };
75
-
76
- const extractImports = (content: string): Array<{ value: string; line: number }> => {
77
- const matches: Array<{ value: string; line: number }> = [];
78
- const patterns = [IMPORT_FROM_PATTERN, EXPORT_FROM_PATTERN, DYNAMIC_IMPORT_PATTERN];
79
-
80
- for (const pattern of patterns) {
81
- const regex = new RegExp(pattern.source, 'g');
82
- let match: RegExpExecArray | null;
83
- while ((match = regex.exec(content)) !== null) {
84
- const value = match[1];
85
- if (!value) continue;
86
- matches.push({ value, line: findLineByIndex(content, match.index) });
87
- }
88
- }
89
-
90
- return matches;
91
- };
92
-
93
- const resolveAliasFromImport = (importPath: string, aliases: string[]): string | null => {
94
- const sorted = [...aliases].sort((a, b) => b.length - a.length);
95
- for (const alias of sorted) {
96
- if (importPath === alias || importPath.startsWith(`${alias}/`)) {
97
- return alias;
98
- }
99
- }
100
- return null;
101
- };
102
-
103
- const resolveContextFromRelativeImport = (filePath: string, importPath: string, contexts: ContextConfig[]): ContextConfig | null => {
104
- if (!importPath.startsWith('.')) return null;
105
-
106
- const absoluteImportPath = path.resolve(path.dirname(filePath), importPath);
107
- const appRoot = path.join(process.cwd(), 'src', 'app');
108
-
109
- for (const context of contexts) {
110
- const contextRoot = path.join(appRoot, context.name);
111
- if (absoluteImportPath === contextRoot || absoluteImportPath.startsWith(`${contextRoot}${path.sep}`)) {
112
- return context;
113
- }
114
- }
115
-
116
- return null;
117
- };
118
-
119
- const isInside = (targetPath: string, rootPath: string): boolean =>
120
- targetPath === rootPath || targetPath.startsWith(`${rootPath}${path.sep}`);
121
-
122
- const resolveAbsoluteRelativeImport = (filePath: string, importPath: string): string | null => {
123
- if (!importPath.startsWith('.')) return null;
124
- return path.resolve(path.dirname(filePath), importPath);
125
- };
126
-
127
- export default async function checkLayerBoundaries(): Promise<void> {
128
- const config = await loadUserConfig();
129
- const contexts = normalizeContexts(config.contexts) as ContextConfig[];
130
-
131
- if (!contexts.length) {
132
- console.error('❌ No contexts found in azure-net.config.ts/js. Fill `contexts` first.');
133
- process.exitCode = 1;
134
- return;
135
- }
136
-
137
- const sharedAliasRaw = normalizeAlias(config.sharedAlias, '');
138
- const sharedAlias = sharedAliasRaw.length ? sharedAliasRaw : null;
139
- if (!sharedAlias) {
140
- console.error('❌ sharedAlias is missing in azure-net.config.ts/js. Set it explicitly to the shared context alias.');
141
- process.exitCode = 1;
142
- return;
143
- }
144
-
145
- const aliasToContext = new Map<string, ContextConfig>();
146
- for (const context of contexts) {
147
- aliasToContext.set(context.alias, context);
148
- }
149
-
150
- const knownAliases = [...contexts.map((context) => context.alias)];
151
- const sharedContext = aliasToContext.get(sharedAlias);
152
- if (!sharedContext) {
153
- console.error(`❌ sharedAlias "${sharedAlias}" does not point to any configured context.`);
154
- process.exitCode = 1;
155
- return;
156
- }
157
-
158
- const issues: BoundaryIssue[] = [];
159
-
160
- for (const context of contexts) {
161
- const contextRoot = path.join(process.cwd(), 'src', 'app', context.name);
162
- const isSharedContext = context.alias === sharedAlias;
163
- const sharedEssentialsRoot = isSharedContext ? path.join(contextRoot, SHARED_ESSENTIALS_DIR_NAME) : null;
164
-
165
- try {
166
- await fs.access(contextRoot);
167
- } catch {
168
- continue;
169
- }
170
-
171
- const files = await listFiles(contextRoot);
172
- const allowedAliases = new Set<string>([context.alias]);
173
- if (context.alias !== sharedAlias) {
174
- allowedAliases.add(sharedAlias);
175
- }
176
-
177
- for (const filePath of files) {
178
- const content = await fs.readFile(filePath, 'utf-8');
179
- const imports = extractImports(content);
180
- const isSharedEssentialsFile = Boolean(sharedEssentialsRoot && isInside(filePath, sharedEssentialsRoot));
181
-
182
- for (const entry of imports) {
183
- const targetAlias = resolveAliasFromImport(entry.value, knownAliases);
184
- if (!targetAlias) continue;
185
-
186
- if (isSharedEssentialsFile && targetAlias === sharedAlias) {
187
- const importRest = entry.value.slice(sharedAlias.length).replace(/^\/+/, '');
188
- if (importRest.length && !importRest.startsWith(`${SHARED_ESSENTIALS_DIR_NAME}/`)) {
189
- issues.push({
190
- file: filePath,
191
- line: entry.line,
192
- message: `Layer boundary violation: shared essentials cannot import from shared "${importRest}". Essentials may depend only on shared essentials code.`
193
- });
194
- continue;
195
- }
196
- }
197
-
198
- if (allowedAliases.has(targetAlias)) continue;
199
-
200
- const targetContext = aliasToContext.get(targetAlias);
201
- const baseMessage = targetContext
202
- ? `Layer boundary violation: context "${context.name}" cannot import from context "${targetContext.name}" (${targetAlias})`
203
- : `Layer boundary violation: context "${context.name}" cannot import from "${targetAlias}"`;
204
-
205
- issues.push({
206
- file: filePath,
207
- line: entry.line,
208
- message: baseMessage
209
- });
210
- }
211
-
212
- for (const entry of imports) {
213
- const absoluteRelativeImport = resolveAbsoluteRelativeImport(filePath, entry.value);
214
- if (
215
- isSharedEssentialsFile &&
216
- absoluteRelativeImport &&
217
- sharedEssentialsRoot &&
218
- isInside(absoluteRelativeImport, contextRoot) &&
219
- !isInside(absoluteRelativeImport, sharedEssentialsRoot)
220
- ) {
221
- issues.push({
222
- file: filePath,
223
- line: entry.line,
224
- message: 'Layer boundary violation: shared essentials cannot import from shared layers/ui via relative path.'
225
- });
226
- continue;
227
- }
228
-
229
- const relativeTargetContext = resolveContextFromRelativeImport(filePath, entry.value, contexts);
230
- if (!relativeTargetContext || relativeTargetContext.name === context.name) continue;
231
- if (context.alias !== sharedAlias && relativeTargetContext.alias === sharedAlias) continue;
232
-
233
- const baseMessage = `Layer boundary violation: context "${context.name}" cannot import from context "${relativeTargetContext.name}" via relative path`;
234
-
235
- issues.push({
236
- file: filePath,
237
- line: entry.line,
238
- message: baseMessage
239
- });
240
- }
241
- }
242
- }
243
-
244
- if (!issues.length) {
245
- console.log('✅ Layer boundaries check passed.');
246
- return;
247
- }
248
-
249
- console.error('❌ Layer boundaries check failed:');
250
- for (const issue of issues) {
251
- console.error(`• ${getRelativePath(issue.file)}:${issue.line} — ${issue.message}`);
252
- }
253
-
254
- process.exitCode = 1;
255
- }
@@ -1,185 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { normalizeContexts } from '../init/initAliases.js';
4
- import { loadUserConfig } from '../utils/loadConfig.js';
5
-
6
- type LayerName = 'domain' | 'application' | 'infrastructure' | 'presentation';
7
-
8
- type ContextConfig = {
9
- name: string;
10
- alias: string;
11
- };
12
-
13
- type LayerImportIssue = {
14
- file: string;
15
- line: number;
16
- message: string;
17
- };
18
-
19
- const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
20
- const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
21
- const LAYERS: LayerName[] = ['domain', 'application', 'infrastructure', 'presentation'];
22
- const FORBIDDEN_LAYER_IMPORTS: Record<LayerName, LayerName[]> = {
23
- infrastructure: ['application', 'presentation'],
24
- application: ['presentation'],
25
- domain: ['application', 'infrastructure', 'presentation'],
26
- presentation: []
27
- };
28
-
29
- const IMPORT_FROM_PATTERN = /\bimport\s+(?:type\s+)?[\s\S]*?\sfrom\s*['"]([^'"]+)['"]/g;
30
- const EXPORT_FROM_PATTERN = /\bexport\s+(?:type\s+)?\{[\s\S]*?\}\sfrom\s*['"]([^'"]+)['"]/g;
31
- const DYNAMIC_IMPORT_PATTERN = /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
32
-
33
- const toPosixPath = (value: string): string => value.split(path.sep).join('/');
34
-
35
- const findLineByIndex = (content: string, index: number): number => {
36
- let line = 1;
37
- for (let i = 0; i < index; i += 1) {
38
- if (content[i] === '\n') line += 1;
39
- }
40
- return line;
41
- };
42
-
43
- const getRelativePath = (filePath: string): string => toPosixPath(path.relative(process.cwd(), filePath));
44
-
45
- const listFiles = async (rootDir: string): Promise<string[]> => {
46
- const files: string[] = [];
47
- const stack: string[] = [rootDir];
48
-
49
- while (stack.length) {
50
- const current = stack.pop();
51
- if (!current) continue;
52
-
53
- let entries: import('node:fs').Dirent[] = [];
54
- try {
55
- entries = await fs.readdir(current, { withFileTypes: true });
56
- } catch {
57
- continue;
58
- }
59
-
60
- for (const entry of entries) {
61
- if (entry.isDirectory()) {
62
- if (!IGNORED_DIRS.has(entry.name)) {
63
- stack.push(path.join(current, entry.name));
64
- }
65
- continue;
66
- }
67
-
68
- if (!entry.isFile()) continue;
69
- const filePath = path.join(current, entry.name);
70
- if (!TARGET_EXTENSIONS.has(path.extname(filePath))) continue;
71
- files.push(filePath);
72
- }
73
- }
74
-
75
- return files;
76
- };
77
-
78
- const extractImports = (content: string): Array<{ value: string; line: number }> => {
79
- const matches: Array<{ value: string; line: number }> = [];
80
- const patterns = [IMPORT_FROM_PATTERN, EXPORT_FROM_PATTERN, DYNAMIC_IMPORT_PATTERN];
81
-
82
- for (const pattern of patterns) {
83
- const regex = new RegExp(pattern.source, 'g');
84
- let match: RegExpExecArray | null;
85
- while ((match = regex.exec(content)) !== null) {
86
- const value = match[1];
87
- if (!value) continue;
88
- matches.push({ value, line: findLineByIndex(content, match.index) });
89
- }
90
- }
91
-
92
- return matches;
93
- };
94
-
95
- const getLayerFromPath = (filePath: string, contextRoot: string): LayerName | null => {
96
- for (const layer of LAYERS) {
97
- const layerRoot = path.join(contextRoot, 'layers', layer);
98
- if (filePath === layerRoot || filePath.startsWith(`${layerRoot}${path.sep}`)) {
99
- return layer;
100
- }
101
- }
102
-
103
- return null;
104
- };
105
-
106
- const getLayerFromAliasImport = (importPath: string, context: ContextConfig): LayerName | null => {
107
- if (importPath !== context.alias && !importPath.startsWith(`${context.alias}/`)) return null;
108
-
109
- const withoutAlias = importPath.slice(context.alias.length).replace(/^\/+/, '');
110
- for (const layer of LAYERS) {
111
- if (withoutAlias === `layers/${layer}` || withoutAlias.startsWith(`layers/${layer}/`)) return layer;
112
- if (withoutAlias === layer || withoutAlias.startsWith(`${layer}/`)) return layer;
113
- }
114
-
115
- return null;
116
- };
117
-
118
- const getLayerFromRelativeImport = (filePath: string, importPath: string, contextRoot: string): LayerName | null => {
119
- if (!importPath.startsWith('.')) return null;
120
-
121
- const absoluteImportPath = path.resolve(path.dirname(filePath), importPath);
122
- return getLayerFromPath(absoluteImportPath, contextRoot);
123
- };
124
-
125
- const createMessage = (sourceLayer: LayerName, targetLayer: LayerName, context: ContextConfig): string =>
126
- `Layer import violation: "${context.name}" ${sourceLayer} layer cannot import from ${targetLayer} layer`;
127
-
128
- export default async function checkLayerImports(): Promise<void> {
129
- const config = await loadUserConfig();
130
- const contexts = normalizeContexts(config.contexts) as ContextConfig[];
131
-
132
- if (!contexts.length) {
133
- console.error('❌ No contexts found in azure-net.config.ts/js. Fill `contexts` first.');
134
- process.exitCode = 1;
135
- return;
136
- }
137
-
138
- const issues: LayerImportIssue[] = [];
139
-
140
- for (const context of contexts) {
141
- const contextRoot = path.join(process.cwd(), 'src', 'app', context.name);
142
-
143
- try {
144
- await fs.access(contextRoot);
145
- } catch {
146
- continue;
147
- }
148
-
149
- const files = await listFiles(path.join(contextRoot, 'layers'));
150
-
151
- for (const filePath of files) {
152
- const sourceLayer = getLayerFromPath(filePath, contextRoot);
153
- if (!sourceLayer) continue;
154
-
155
- const forbiddenLayers = FORBIDDEN_LAYER_IMPORTS[sourceLayer];
156
- if (!forbiddenLayers.length) continue;
157
-
158
- const content = await fs.readFile(filePath, 'utf-8');
159
- const imports = extractImports(content);
160
-
161
- for (const entry of imports) {
162
- const targetLayer = getLayerFromAliasImport(entry.value, context) ?? getLayerFromRelativeImport(filePath, entry.value, contextRoot);
163
- if (!targetLayer || !forbiddenLayers.includes(targetLayer)) continue;
164
-
165
- issues.push({
166
- file: filePath,
167
- line: entry.line,
168
- message: createMessage(sourceLayer, targetLayer, context)
169
- });
170
- }
171
- }
172
- }
173
-
174
- if (!issues.length) {
175
- console.log('✅ Layer imports check passed.');
176
- return;
177
- }
178
-
179
- console.error('❌ Layer imports check failed:');
180
- for (const issue of issues) {
181
- console.error(`• ${getRelativePath(issue.file)}:${issue.line} — ${issue.message}`);
182
- }
183
-
184
- process.exitCode = 1;
185
- }
@@ -1,203 +0,0 @@
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 content of fileContents.values()) {
166
- for (const name of extractFactoryNamesFromContent(content)) {
167
- globalFactoryNames.add(name);
168
- }
169
- }
170
-
171
- const occurrences: PresenterOccurrence[] = [];
172
- for (const [filePath, content] of fileContents.entries()) {
173
- occurrences.push(...collectPresenterOccurrences(content, filePath, globalFactoryNames));
174
- }
175
-
176
- if (!occurrences.length) {
177
- console.log('✅ No presenter declarations found.');
178
- return;
179
- }
180
-
181
- const grouped = new Map<string, PresenterOccurrence[]>();
182
- for (const occurrence of occurrences) {
183
- const list = grouped.get(occurrence.id) ?? [];
184
- list.push(occurrence);
185
- grouped.set(occurrence.id, list);
186
- }
187
-
188
- const duplicated = Array.from(grouped.entries()).filter(([, list]) => list.length > 1);
189
- if (!duplicated.length) {
190
- console.log(`✅ Presenter names are unique (${occurrences.length} found).`);
191
- return;
192
- }
193
-
194
- console.error('❌ Duplicate presenter names found:');
195
- for (const [presenterId, list] of duplicated) {
196
- console.error(`\n- "${presenterId}"`);
197
- for (const item of list) {
198
- console.error(` • ${toPosixPath(path.relative(process.cwd(), item.file))}:${item.line} (${item.callee})`);
199
- }
200
- }
201
-
202
- process.exitCode = 1;
203
- }
@@ -1,45 +0,0 @@
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
- }