@azure-net/cli 2.3.63 → 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.
Files changed (117) hide show
  1. package/.prettierrc +7 -0
  2. package/bin/azure-net.js +278 -157
  3. package/bin/azure-net.ts +284 -0
  4. package/eslint.config.js +34 -0
  5. package/package.json +12 -5
  6. package/src/checks/checkDomain.js +201 -0
  7. package/src/checks/checkDomain.ts +213 -0
  8. package/src/checks/checkFoldersStructure.js +70 -0
  9. package/src/checks/checkFoldersStructure.ts +85 -0
  10. package/src/checks/checkInternal.js +35 -0
  11. package/src/checks/checkInternal.ts +40 -0
  12. package/src/checks/checkLayerBoundaries.js +178 -0
  13. package/src/checks/checkLayerBoundaries.ts +189 -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/checkProviderNames.js +158 -0
  19. package/src/checks/checkProviderNames.ts +165 -0
  20. package/src/checks/index.js +7 -0
  21. package/src/checks/index.ts +7 -0
  22. package/src/generate/layers/generateRepository.js +124 -0
  23. package/src/generate/layers/generateRepository.ts +123 -0
  24. package/src/generate/layers/generateRepositoryMethod.js +102 -0
  25. package/src/generate/layers/generateRepositoryMethod.ts +102 -0
  26. package/src/generate/layers/generateUseCases.js +50 -0
  27. package/src/generate/layers/generateUseCases.ts +50 -0
  28. package/src/generate/layers/repositoryShared.js +569 -0
  29. package/src/generate/layers/repositoryShared.ts +657 -0
  30. package/src/generate/module/generateDomain.js +146 -0
  31. package/src/generate/module/generateDomain.ts +147 -0
  32. package/src/generate/module/generateModule.js +84 -0
  33. package/src/generate/module/generateModule.ts +84 -0
  34. package/src/generate/module/generateModulePreset.js +307 -0
  35. package/src/generate/module/generateModulePreset.ts +337 -0
  36. package/src/generate/module/generatePresenter.js +419 -0
  37. package/src/generate/module/generatePresenter.ts +442 -0
  38. package/src/generate/module/generateRepository.js +144 -0
  39. package/src/generate/module/generateRepository.ts +158 -0
  40. package/src/generate/module/generateSchemaFromType.js +358 -0
  41. package/src/generate/module/generateSchemaFromType.ts +369 -0
  42. package/src/generate/module/generateTypesJson.js +252 -0
  43. package/src/generate/module/generateTypesJson.ts +259 -0
  44. package/src/generate/module/generateUseCases.js +67 -0
  45. package/src/generate/module/generateUseCases.ts +67 -0
  46. package/src/generate/module/repositoryModuleShared.js +598 -0
  47. package/src/generate/module/repositoryModuleShared.ts +661 -0
  48. package/src/generate/ui/generateComponent.js +98 -0
  49. package/src/generate/ui/generateComponent.ts +100 -0
  50. package/src/generate/ui/generateDesignComponent.js +71 -0
  51. package/src/generate/ui/generateDesignComponent.ts +71 -0
  52. package/src/generate/ui/generateWidget.js +71 -0
  53. package/src/generate/ui/generateWidget.ts +71 -0
  54. package/src/init/initAliases.js +159 -0
  55. package/src/init/initAliases.ts +167 -0
  56. package/src/init/initEdges.js +74 -0
  57. package/src/init/initEdges.ts +74 -0
  58. package/src/init/initStructure.js +122 -0
  59. package/src/init/initStructure.ts +124 -0
  60. package/src/install/installFresh.js +101 -0
  61. package/src/install/installFresh.ts +101 -0
  62. package/src/plugins/addLint.js +257 -0
  63. package/src/plugins/addLint.ts +274 -0
  64. package/src/plugins/index.js +1 -0
  65. package/src/plugins/index.ts +1 -0
  66. package/src/scaffolds/createCoreMiddleware.js +27 -0
  67. package/src/scaffolds/createCoreMiddleware.ts +27 -0
  68. package/src/scaffolds/createCoreSchema.js +141 -0
  69. package/src/scaffolds/createCoreSchema.ts +142 -0
  70. package/src/scaffolds/createDatasource.js +173 -0
  71. package/src/scaffolds/createDatasource.ts +175 -0
  72. package/src/scaffolds/createDatasourceProvider.js +164 -0
  73. package/src/scaffolds/createDatasourceProvider.ts +175 -0
  74. package/src/scaffolds/createMiddleware.js +105 -0
  75. package/src/scaffolds/createMiddleware.ts +105 -0
  76. package/src/scaffolds/createPresenterFactory.js +112 -0
  77. package/src/scaffolds/createPresenterFactory.ts +114 -0
  78. package/src/scaffolds/createResponse.js +64 -0
  79. package/src/scaffolds/createResponse.ts +64 -0
  80. package/src/scaffolds/createSchemaRule.js +40 -0
  81. package/src/scaffolds/createSchemaRule.ts +42 -0
  82. package/src/scaffolds/createTranslationManager.js +78 -0
  83. package/src/scaffolds/createTranslationManager.ts +78 -0
  84. package/src/scaffolds/index.js +9 -0
  85. package/src/scaffolds/index.ts +9 -0
  86. package/src/utils/contextUtils.js +56 -49
  87. package/src/utils/contextUtils.ts +89 -0
  88. package/src/utils/fileUtils.js +72 -84
  89. package/src/utils/fileUtils.ts +100 -0
  90. package/src/utils/loadConfig.js +57 -13
  91. package/src/utils/loadConfig.ts +69 -0
  92. package/tsconfig.json +19 -0
  93. package/src/commands/generate/generateComponent.js +0 -53
  94. package/src/commands/generate/generateCrudBase.js +0 -207
  95. package/src/commands/generate/generateCrudPresenter.js +0 -232
  96. package/src/commands/generate/generateDatasource.js +0 -84
  97. package/src/commands/generate/generateDesignComponent.js +0 -53
  98. package/src/commands/generate/generateModule.js +0 -31
  99. package/src/commands/generate/generateModuleBase.js +0 -152
  100. package/src/commands/generate/generateModulePresenter.js +0 -110
  101. package/src/commands/generate/generatePresenter.js +0 -86
  102. package/src/commands/generate/generateRepository.js +0 -76
  103. package/src/commands/generate/generateResponse.js +0 -41
  104. package/src/commands/generate/generateSchema.js +0 -96
  105. package/src/commands/generate/generateService.js +0 -71
  106. package/src/commands/generate/generateWidget.js +0 -53
  107. package/src/commands/generate/index.js +0 -14
  108. package/src/commands/init/index.js +0 -9
  109. package/src/commands/init/initAliases.js +0 -52
  110. package/src/commands/init/initEdges.js +0 -42
  111. package/src/commands/init/initLint.js +0 -138
  112. package/src/commands/init/initMiddleware.js +0 -21
  113. package/src/commands/init/initPresenter.js +0 -25
  114. package/src/commands/init/initSchema.js +0 -22
  115. package/src/commands/init/initStructure.js +0 -140
  116. package/src/commands/init/initTranslations.js +0 -59
  117. package/src/commands/init/migrateStructure.js +0 -144
@@ -0,0 +1,213 @@
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
+
6
+ type DomainIssue = {
7
+ file: string;
8
+ line: number;
9
+ message: string;
10
+ };
11
+
12
+ type Declaration = {
13
+ kind: 'interface' | 'type';
14
+ name: string;
15
+ line: number;
16
+ };
17
+
18
+ const DOMAIN_FILE_EXTENSIONS = new Set(['.ts']);
19
+ const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
20
+
21
+ const INTERFACE_DECLARATION_PATTERN = /(?:^|\n)\s*(?:export\s+)?interface\s+([A-Za-z_$][A-Za-z0-9_$]*)\b/g;
22
+ const TYPE_DECLARATION_PATTERN = /(?:^|\n)\s*(?:export\s+)?type\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=/g;
23
+
24
+ const EXPORT_STAR_PATTERN = /export\s+\*\s+from\s*['"][^'"]+['"]\s*;?/g;
25
+ const EXPORT_FROM_PATTERN = /export\s+(?:type\s+)?\{[\s\S]*?\}\s+from\s*['"][^'"]+['"]\s*;?/g;
26
+ const EXPORT_LOCAL_PATTERN = /export\s+(?:type\s+)?\{[\s\S]*?\}\s*;?/g;
27
+
28
+ const toPosixPath = (value: string): string => value.split(path.sep).join('/');
29
+
30
+ const stripComments = (content: string): string => content.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|[^\\])\/\/.*$/gm, '$1');
31
+
32
+ const stripExportStatements = (content: string): string =>
33
+ content.replace(EXPORT_STAR_PATTERN, '').replace(EXPORT_FROM_PATTERN, '').replace(EXPORT_LOCAL_PATTERN, '');
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 getRelativeFilePath = (filePath: string): string => toPosixPath(path.relative(process.cwd(), filePath));
44
+
45
+ const isEnumsPath = (filePath: string): boolean => {
46
+ const normalized = toPosixPath(filePath);
47
+ return normalized.includes('/enums/');
48
+ };
49
+
50
+ const isIndexFile = (filePath: string): boolean => path.basename(filePath) === 'index.ts';
51
+
52
+ const isExportOnlyIndex = (content: string): boolean => {
53
+ const withoutComments = stripComments(content);
54
+ const withoutExports = stripExportStatements(withoutComments);
55
+ return withoutExports.trim().length === 0;
56
+ };
57
+
58
+ const validateName = (declaration: Declaration): string | null => {
59
+ if (declaration.kind === 'interface') {
60
+ return /^I[A-Z]/.test(declaration.name) ? null : `Interface "${declaration.name}" must start with "I" and have uppercase second letter`;
61
+ }
62
+
63
+ return /^[IT][A-Z]/.test(declaration.name)
64
+ ? null
65
+ : `Type "${declaration.name}" must start with "I" or "T" and have uppercase second letter`;
66
+ };
67
+
68
+ const extractDeclarations = (content: string): Declaration[] => {
69
+ const cleaned = stripComments(content);
70
+ const declarations: Declaration[] = [];
71
+
72
+ const interfaceRegex = new RegExp(INTERFACE_DECLARATION_PATTERN.source, 'g');
73
+ let interfaceMatch: RegExpExecArray | null;
74
+ while ((interfaceMatch = interfaceRegex.exec(cleaned)) !== null) {
75
+ const name = interfaceMatch[1];
76
+ if (!name) continue;
77
+ declarations.push({
78
+ kind: 'interface',
79
+ name,
80
+ line: findLineByIndex(cleaned, interfaceMatch.index)
81
+ });
82
+ }
83
+
84
+ const typeRegex = new RegExp(TYPE_DECLARATION_PATTERN.source, 'g');
85
+ let typeMatch: RegExpExecArray | null;
86
+ while ((typeMatch = typeRegex.exec(cleaned)) !== null) {
87
+ const name = typeMatch[1];
88
+ if (!name) continue;
89
+ declarations.push({
90
+ kind: 'type',
91
+ name,
92
+ line: findLineByIndex(cleaned, typeMatch.index)
93
+ });
94
+ }
95
+
96
+ return declarations.sort((a, b) => a.line - b.line);
97
+ };
98
+
99
+ const listDomainFiles = async (domainRoot: string): Promise<string[]> => {
100
+ const files: string[] = [];
101
+ const stack: string[] = [domainRoot];
102
+
103
+ while (stack.length) {
104
+ const current = stack.pop();
105
+ if (!current) continue;
106
+
107
+ let entries: import('node:fs').Dirent[] = [];
108
+ try {
109
+ entries = await fs.readdir(current, { withFileTypes: true });
110
+ } catch {
111
+ continue;
112
+ }
113
+
114
+ for (const entry of entries) {
115
+ if (entry.isDirectory()) {
116
+ if (!IGNORED_DIRS.has(entry.name)) {
117
+ stack.push(path.join(current, entry.name));
118
+ }
119
+ continue;
120
+ }
121
+
122
+ if (!entry.isFile()) continue;
123
+ const filePath = path.join(current, entry.name);
124
+ if (!DOMAIN_FILE_EXTENSIONS.has(path.extname(filePath))) continue;
125
+ files.push(filePath);
126
+ }
127
+ }
128
+
129
+ return files;
130
+ };
131
+
132
+ const collectIssuesForFile = (filePath: string, content: string): DomainIssue[] => {
133
+ const issues: DomainIssue[] = [];
134
+
135
+ if (isIndexFile(filePath) && !isExportOnlyIndex(content)) {
136
+ issues.push({
137
+ file: filePath,
138
+ line: 1,
139
+ message: 'index.ts must contain only exports. Move declarations to separate files'
140
+ });
141
+ }
142
+
143
+ if (isEnumsPath(filePath)) {
144
+ return issues;
145
+ }
146
+
147
+ const declarations = extractDeclarations(content);
148
+ if (declarations.length > 5) {
149
+ issues.push({
150
+ file: filePath,
151
+ line: declarations[5]?.line ?? 1,
152
+ message: `Too many declarations in one file (${declarations.length}). Maximum is 5`
153
+ });
154
+ }
155
+
156
+ for (const declaration of declarations) {
157
+ const validationError = validateName(declaration);
158
+ if (!validationError) continue;
159
+ issues.push({
160
+ file: filePath,
161
+ line: declaration.line,
162
+ message: validationError
163
+ });
164
+ }
165
+
166
+ return issues;
167
+ };
168
+
169
+ export default async function checkDomain(): Promise<void> {
170
+ const config = await loadUserConfig();
171
+ const contexts = normalizeContexts(config.contexts);
172
+
173
+ if (!contexts.length) {
174
+ console.error('❌ No contexts found in azure-net.config.ts/js. Fill `contexts` first.');
175
+ process.exitCode = 1;
176
+ return;
177
+ }
178
+
179
+ const issues: DomainIssue[] = [];
180
+
181
+ for (const context of contexts) {
182
+ const domainRoot = path.join(process.cwd(), 'src', 'app', context.name, 'layers', 'domain');
183
+
184
+ try {
185
+ await fs.access(domainRoot);
186
+ } catch {
187
+ issues.push({
188
+ file: domainRoot,
189
+ line: 1,
190
+ message: `Domain folder not found for context "${context.name}"`
191
+ });
192
+ continue;
193
+ }
194
+
195
+ const files = await listDomainFiles(domainRoot);
196
+ for (const filePath of files) {
197
+ const content = await fs.readFile(filePath, 'utf-8');
198
+ issues.push(...collectIssuesForFile(filePath, content));
199
+ }
200
+ }
201
+
202
+ if (!issues.length) {
203
+ console.log('✅ Domain check passed: naming, per-file limits and index exports are valid.');
204
+ return;
205
+ }
206
+
207
+ console.error('❌ Domain check failed:');
208
+ for (const issue of issues) {
209
+ console.error(`• ${getRelativeFilePath(issue.file)}:${issue.line} — ${issue.message}`);
210
+ }
211
+
212
+ process.exitCode = 1;
213
+ }
@@ -0,0 +1,70 @@
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
+
6
+ const ALLOWED_LAYERS_FOLDERS = new Set(['domain', 'presentation', 'infrastructure', 'application']);
7
+ const ALLOWED_UI_FOLDERS = new Set(['components', 'widgets', 'design', 'style']);
8
+ const ALLOWED_COMPONENTS_FOLDERS = new Set(['page', 'layout', 'shared']);
9
+
10
+ const toPosixPath = (value) => value.split(path.sep).join('/');
11
+
12
+ const getRelativePath = (filePath) => toPosixPath(path.relative(process.cwd(), filePath));
13
+
14
+ const getDirectories = async (dirPath) => {
15
+ try {
16
+ const entries = await fs.readdir(dirPath, { withFileTypes: true });
17
+ return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
18
+ } catch {
19
+ return null;
20
+ }
21
+ };
22
+
23
+ const checkOnlyAllowedFolders = async (basePath, allowed, scopeLabel, issues) => {
24
+ const directories = await getDirectories(basePath);
25
+ if (!directories) return;
26
+
27
+ for (const dir of directories) {
28
+ if (allowed.has(dir)) continue;
29
+ issues.push({
30
+ file: basePath,
31
+ message: `${scopeLabel} can contain only: ${Array.from(allowed).join(', ')}. Found: ${dir}`
32
+ });
33
+ }
34
+ };
35
+
36
+ export default async function checkFoldersStructure() {
37
+ const config = await loadUserConfig();
38
+ const contexts = normalizeContexts(config.contexts);
39
+
40
+ if (!contexts.length) {
41
+ console.error('❌ No contexts found in azure-net.config.ts/js. Fill `contexts` first.');
42
+ process.exitCode = 1;
43
+ return;
44
+ }
45
+
46
+ const issues = [];
47
+
48
+ for (const context of contexts) {
49
+ const contextRoot = path.join(process.cwd(), 'src', 'app', context.name);
50
+ const layersPath = path.join(contextRoot, 'layers');
51
+ const uiPath = path.join(contextRoot, 'ui');
52
+ const componentsPath = path.join(uiPath, 'components');
53
+
54
+ await checkOnlyAllowedFolders(layersPath, ALLOWED_LAYERS_FOLDERS, `layers (${context.name})`, issues);
55
+ await checkOnlyAllowedFolders(uiPath, ALLOWED_UI_FOLDERS, `ui (${context.name})`, issues);
56
+ await checkOnlyAllowedFolders(componentsPath, ALLOWED_COMPONENTS_FOLDERS, `ui/components (${context.name})`, issues);
57
+ }
58
+
59
+ if (!issues.length) {
60
+ console.log('✅ Folders structure check passed.');
61
+ return;
62
+ }
63
+
64
+ console.error('❌ Folders structure check failed:');
65
+ for (const issue of issues) {
66
+ console.error(`• ${getRelativePath(issue.file)} — ${issue.message}`);
67
+ }
68
+
69
+ process.exitCode = 1;
70
+ }
@@ -0,0 +1,85 @@
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
+
6
+ type StructureIssue = {
7
+ file: string;
8
+ message: string;
9
+ };
10
+
11
+ type ContextConfig = {
12
+ name: string;
13
+ alias: string;
14
+ };
15
+
16
+ const ALLOWED_LAYERS_FOLDERS = new Set(['domain', 'presentation', 'infrastructure', 'application']);
17
+ const ALLOWED_UI_FOLDERS = new Set(['components', 'widgets', 'design', 'style']);
18
+ const ALLOWED_COMPONENTS_FOLDERS = new Set(['page', 'layout', 'shared']);
19
+
20
+ const toPosixPath = (value: string): string => value.split(path.sep).join('/');
21
+
22
+ const getRelativePath = (filePath: string): string => toPosixPath(path.relative(process.cwd(), filePath));
23
+
24
+ const getDirectories = async (dirPath: string): Promise<string[] | null> => {
25
+ try {
26
+ const entries = await fs.readdir(dirPath, { withFileTypes: true });
27
+ return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
28
+ } catch {
29
+ return null;
30
+ }
31
+ };
32
+
33
+ const checkOnlyAllowedFolders = async (
34
+ basePath: string,
35
+ allowed: Set<string>,
36
+ scopeLabel: string,
37
+ issues: StructureIssue[]
38
+ ): Promise<void> => {
39
+ const directories = await getDirectories(basePath);
40
+ if (!directories) return;
41
+
42
+ for (const dir of directories) {
43
+ if (allowed.has(dir)) continue;
44
+ issues.push({
45
+ file: basePath,
46
+ message: `${scopeLabel} can contain only: ${Array.from(allowed).join(', ')}. Found: ${dir}`
47
+ });
48
+ }
49
+ };
50
+
51
+ export default async function checkFoldersStructure(): Promise<void> {
52
+ const config = await loadUserConfig();
53
+ const contexts = normalizeContexts(config.contexts) as ContextConfig[];
54
+
55
+ if (!contexts.length) {
56
+ console.error('❌ No contexts found in azure-net.config.ts/js. Fill `contexts` first.');
57
+ process.exitCode = 1;
58
+ return;
59
+ }
60
+
61
+ const issues: StructureIssue[] = [];
62
+
63
+ for (const context of contexts) {
64
+ const contextRoot = path.join(process.cwd(), 'src', 'app', context.name);
65
+ const layersPath = path.join(contextRoot, 'layers');
66
+ const uiPath = path.join(contextRoot, 'ui');
67
+ const componentsPath = path.join(uiPath, 'components');
68
+
69
+ await checkOnlyAllowedFolders(layersPath, ALLOWED_LAYERS_FOLDERS, `layers (${context.name})`, issues);
70
+ await checkOnlyAllowedFolders(uiPath, ALLOWED_UI_FOLDERS, `ui (${context.name})`, issues);
71
+ await checkOnlyAllowedFolders(componentsPath, ALLOWED_COMPONENTS_FOLDERS, `ui/components (${context.name})`, issues);
72
+ }
73
+
74
+ if (!issues.length) {
75
+ console.log('✅ Folders structure check passed.');
76
+ return;
77
+ }
78
+
79
+ console.error('❌ Folders structure check failed:');
80
+ for (const issue of issues) {
81
+ console.error(`• ${getRelativePath(issue.file)} — ${issue.message}`);
82
+ }
83
+
84
+ process.exitCode = 1;
85
+ }
@@ -0,0 +1,35 @@
1
+ import checkPresenterNames from './checkPresenterNames.js';
2
+ import checkProviderNames from './checkProviderNames.js';
3
+ import checkDomain from './checkDomain.js';
4
+ import checkLayerBoundaries from './checkLayerBoundaries.js';
5
+ import checkFoldersStructure from './checkFoldersStructure.js';
6
+
7
+ const tasks = [
8
+ { name: 'presenter-names', run: checkPresenterNames },
9
+ { name: 'provider-names', run: checkProviderNames },
10
+ { name: 'domain', run: checkDomain },
11
+ { name: 'layer-boundaries', run: checkLayerBoundaries },
12
+ { name: 'folders-structure', run: checkFoldersStructure }
13
+ ];
14
+
15
+ const runTask = async (task) => {
16
+ console.log(`\n▶ Running check ${task.name}...`);
17
+ process.exitCode = 0;
18
+ await task.run();
19
+
20
+ if ((process.exitCode ?? 0) !== 0) {
21
+ throw new Error(`Check "${task.name}" failed`);
22
+ }
23
+ };
24
+
25
+ export default async function checkInternal() {
26
+ try {
27
+ for (const task of tasks) {
28
+ await runTask(task);
29
+ }
30
+ console.log('\n✅ Internal checks passed.');
31
+ } catch (error) {
32
+ console.error(`\n❌ Internal checks failed: ${error instanceof Error ? error.message : String(error)}`);
33
+ process.exitCode = 1;
34
+ }
35
+ }
@@ -0,0 +1,40 @@
1
+ import checkPresenterNames from './checkPresenterNames.js';
2
+ import checkProviderNames from './checkProviderNames.js';
3
+ import checkDomain from './checkDomain.js';
4
+ import checkLayerBoundaries from './checkLayerBoundaries.js';
5
+ import checkFoldersStructure from './checkFoldersStructure.js';
6
+
7
+ type CheckTask = {
8
+ name: string;
9
+ run: () => Promise<void>;
10
+ };
11
+
12
+ const tasks: CheckTask[] = [
13
+ { name: 'presenter-names', run: checkPresenterNames },
14
+ { name: 'provider-names', run: checkProviderNames },
15
+ { name: 'domain', run: checkDomain },
16
+ { name: 'layer-boundaries', run: checkLayerBoundaries },
17
+ { name: 'folders-structure', run: checkFoldersStructure }
18
+ ];
19
+
20
+ const runTask = async (task: CheckTask): Promise<void> => {
21
+ console.log(`\n▶ Running check ${task.name}...`);
22
+ process.exitCode = 0;
23
+ await task.run();
24
+
25
+ if ((process.exitCode ?? 0) !== 0) {
26
+ throw new Error(`Check "${task.name}" failed`);
27
+ }
28
+ };
29
+
30
+ export default async function checkInternal(): Promise<void> {
31
+ try {
32
+ for (const task of tasks) {
33
+ await runTask(task);
34
+ }
35
+ console.log('\n✅ Internal checks passed.');
36
+ } catch (error) {
37
+ console.error(`\n❌ Internal checks failed: ${error instanceof Error ? error.message : String(error)}`);
38
+ process.exitCode = 1;
39
+ }
40
+ }
@@ -0,0 +1,178 @@
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
+
6
+ const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
7
+ const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
8
+
9
+ const IMPORT_FROM_PATTERN = /\bimport\s+(?:type\s+)?[\s\S]*?\sfrom\s*['"]([^'"]+)['"]/g;
10
+ const EXPORT_FROM_PATTERN = /\bexport\s+(?:type\s+)?\{[\s\S]*?\}\sfrom\s*['"]([^'"]+)['"]/g;
11
+ const DYNAMIC_IMPORT_PATTERN = /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
12
+
13
+ const toPosixPath = (value) => value.split(path.sep).join('/');
14
+
15
+ const normalizeAlias = (value, fallback = '') => {
16
+ const raw = String(value ?? '').trim();
17
+ if (!raw.length) return fallback;
18
+ return raw.startsWith('$') ? raw : `$${raw}`;
19
+ };
20
+
21
+ const findLineByIndex = (content, index) => {
22
+ let line = 1;
23
+ for (let i = 0; i < index; i += 1) {
24
+ if (content[i] === '\n') line += 1;
25
+ }
26
+ return line;
27
+ };
28
+
29
+ const getRelativePath = (filePath) => toPosixPath(path.relative(process.cwd(), filePath));
30
+
31
+ const listFiles = async (rootDir) => {
32
+ const files = [];
33
+ const stack = [rootDir];
34
+
35
+ while (stack.length) {
36
+ const current = stack.pop();
37
+ if (!current) continue;
38
+
39
+ let entries = [];
40
+ try {
41
+ entries = await fs.readdir(current, { withFileTypes: true });
42
+ } catch {
43
+ continue;
44
+ }
45
+
46
+ for (const entry of entries) {
47
+ if (entry.isDirectory()) {
48
+ if (!IGNORED_DIRS.has(entry.name)) {
49
+ stack.push(path.join(current, entry.name));
50
+ }
51
+ continue;
52
+ }
53
+
54
+ if (!entry.isFile()) continue;
55
+ const filePath = path.join(current, entry.name);
56
+ if (!TARGET_EXTENSIONS.has(path.extname(filePath))) continue;
57
+ files.push(filePath);
58
+ }
59
+ }
60
+
61
+ return files;
62
+ };
63
+
64
+ const extractImports = (content) => {
65
+ const matches = [];
66
+ const patterns = [IMPORT_FROM_PATTERN, EXPORT_FROM_PATTERN, DYNAMIC_IMPORT_PATTERN];
67
+
68
+ for (const pattern of patterns) {
69
+ const regex = new RegExp(pattern.source, 'g');
70
+ let match;
71
+ while ((match = regex.exec(content)) !== null) {
72
+ const value = match[1];
73
+ if (!value) continue;
74
+ matches.push({ value, line: findLineByIndex(content, match.index) });
75
+ }
76
+ }
77
+
78
+ return matches;
79
+ };
80
+
81
+ const resolveAliasFromImport = (importPath, aliases) => {
82
+ const sorted = [...aliases].sort((a, b) => b.length - a.length);
83
+ for (const alias of sorted) {
84
+ if (importPath === alias || importPath.startsWith(`${alias}/`)) {
85
+ return alias;
86
+ }
87
+ }
88
+ return null;
89
+ };
90
+
91
+ const isSharedLikeContext = (contextName, alias) => {
92
+ const normalizedName = contextName.toLowerCase();
93
+ const normalizedAlias = alias.toLowerCase();
94
+ return normalizedName.includes('shared') || normalizedAlias.includes('shared');
95
+ };
96
+
97
+ export default async function checkLayerBoundaries() {
98
+ const config = await loadUserConfig();
99
+ const contexts = normalizeContexts(config.contexts);
100
+
101
+ if (!contexts.length) {
102
+ console.error('❌ No contexts found in azure-net.config.ts/js. Fill `contexts` first.');
103
+ process.exitCode = 1;
104
+ return;
105
+ }
106
+
107
+ const coreAlias = normalizeAlias(config.coreAlias, '$core');
108
+ const sharedAliasRaw = normalizeAlias(config.sharedAlias, '');
109
+ const sharedAlias = sharedAliasRaw.length ? sharedAliasRaw : null;
110
+
111
+ const aliasToContext = new Map();
112
+ for (const context of contexts) {
113
+ aliasToContext.set(context.alias, context);
114
+ }
115
+
116
+ const knownAliases = [coreAlias, ...contexts.map((context) => context.alias)];
117
+ if (sharedAlias && !knownAliases.includes(sharedAlias)) {
118
+ knownAliases.push(sharedAlias);
119
+ }
120
+
121
+ const issues = [];
122
+
123
+ for (const context of contexts) {
124
+ const layersRoot = path.join(process.cwd(), 'src', 'app', context.name, 'layers');
125
+
126
+ try {
127
+ await fs.access(layersRoot);
128
+ } catch {
129
+ continue;
130
+ }
131
+
132
+ const files = await listFiles(layersRoot);
133
+ const allowedAliases = new Set([context.alias, coreAlias]);
134
+ if (sharedAlias) {
135
+ allowedAliases.add(sharedAlias);
136
+ }
137
+
138
+ for (const filePath of files) {
139
+ const content = await fs.readFile(filePath, 'utf-8');
140
+ const imports = extractImports(content);
141
+
142
+ for (const entry of imports) {
143
+ const targetAlias = resolveAliasFromImport(entry.value, knownAliases);
144
+ if (!targetAlias) continue;
145
+ if (targetAlias === coreAlias) continue;
146
+ if (allowedAliases.has(targetAlias)) continue;
147
+
148
+ const targetContext = aliasToContext.get(targetAlias);
149
+ const baseMessage = targetContext
150
+ ? `Layer boundary violation: context "${context.name}" cannot import from context "${targetContext.name}" (${targetAlias})`
151
+ : `Layer boundary violation: context "${context.name}" cannot import from "${targetAlias}"`;
152
+
153
+ const withSharedHint =
154
+ !sharedAlias && targetContext && isSharedLikeContext(targetContext.name, targetAlias)
155
+ ? `${baseMessage}. sharedAlias is not configured in azure-net.config.ts/js; if this context is shared, set sharedAlias explicitly`
156
+ : baseMessage;
157
+
158
+ issues.push({
159
+ file: filePath,
160
+ line: entry.line,
161
+ message: withSharedHint
162
+ });
163
+ }
164
+ }
165
+ }
166
+
167
+ if (!issues.length) {
168
+ console.log('✅ Layer boundaries check passed.');
169
+ return;
170
+ }
171
+
172
+ console.error('❌ Layer boundaries check failed:');
173
+ for (const issue of issues) {
174
+ console.error(`• ${getRelativePath(issue.file)}:${issue.line} — ${issue.message}`);
175
+ }
176
+
177
+ process.exitCode = 1;
178
+ }