@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.
- package/.prettierrc +7 -0
- package/bin/azure-net.js +278 -157
- package/bin/azure-net.ts +284 -0
- package/eslint.config.js +34 -0
- package/package.json +12 -5
- 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.js +124 -0
- package/src/generate/layers/generateRepository.ts +123 -0
- package/src/generate/layers/generateRepositoryMethod.js +102 -0
- package/src/generate/layers/generateRepositoryMethod.ts +102 -0
- package/src/generate/layers/generateUseCases.js +50 -0
- package/src/generate/layers/generateUseCases.ts +50 -0
- package/src/generate/layers/repositoryShared.js +569 -0
- package/src/generate/layers/repositoryShared.ts +657 -0
- package/src/generate/module/generateDomain.js +146 -0
- package/src/generate/module/generateDomain.ts +147 -0
- package/src/generate/module/generateModule.js +84 -0
- package/src/generate/module/generateModule.ts +84 -0
- package/src/generate/module/generateModulePreset.js +307 -0
- package/src/generate/module/generateModulePreset.ts +337 -0
- package/src/generate/module/generatePresenter.js +419 -0
- package/src/generate/module/generatePresenter.ts +442 -0
- package/src/generate/module/generateRepository.js +144 -0
- package/src/generate/module/generateRepository.ts +158 -0
- package/src/generate/module/generateSchemaFromType.js +358 -0
- package/src/generate/module/generateSchemaFromType.ts +369 -0
- package/src/generate/module/generateTypesJson.js +252 -0
- package/src/generate/module/generateTypesJson.ts +259 -0
- package/src/generate/module/generateUseCases.js +67 -0
- package/src/generate/module/generateUseCases.ts +67 -0
- package/src/generate/module/repositoryModuleShared.js +598 -0
- package/src/generate/module/repositoryModuleShared.ts +661 -0
- package/src/generate/ui/generateComponent.js +98 -0
- package/src/generate/ui/generateComponent.ts +100 -0
- package/src/generate/ui/generateDesignComponent.js +71 -0
- package/src/generate/ui/generateDesignComponent.ts +71 -0
- package/src/generate/ui/generateWidget.js +71 -0
- package/src/generate/ui/generateWidget.ts +71 -0
- package/src/init/initAliases.js +159 -0
- package/src/init/initAliases.ts +167 -0
- package/src/init/initEdges.js +74 -0
- package/src/init/initEdges.ts +74 -0
- package/src/init/initStructure.js +122 -0
- package/src/init/initStructure.ts +124 -0
- package/src/install/installFresh.js +101 -0
- package/src/install/installFresh.ts +101 -0
- package/src/plugins/addLint.js +257 -0
- package/src/plugins/addLint.ts +274 -0
- package/src/plugins/index.js +1 -0
- package/src/plugins/index.ts +1 -0
- package/src/scaffolds/createCoreMiddleware.js +27 -0
- package/src/scaffolds/createCoreMiddleware.ts +27 -0
- package/src/scaffolds/createCoreSchema.js +141 -0
- package/src/scaffolds/createCoreSchema.ts +142 -0
- package/src/scaffolds/createDatasource.js +173 -0
- package/src/scaffolds/createDatasource.ts +175 -0
- package/src/scaffolds/createDatasourceProvider.js +164 -0
- package/src/scaffolds/createDatasourceProvider.ts +175 -0
- package/src/scaffolds/createMiddleware.js +105 -0
- package/src/scaffolds/createMiddleware.ts +105 -0
- package/src/scaffolds/createPresenterFactory.js +112 -0
- package/src/scaffolds/createPresenterFactory.ts +114 -0
- package/src/scaffolds/createResponse.js +64 -0
- package/src/scaffolds/createResponse.ts +64 -0
- package/src/scaffolds/createSchemaRule.js +40 -0
- package/src/scaffolds/createSchemaRule.ts +42 -0
- package/src/scaffolds/createTranslationManager.js +78 -0
- package/src/scaffolds/createTranslationManager.ts +78 -0
- package/src/scaffolds/index.js +9 -0
- package/src/scaffolds/index.ts +9 -0
- package/src/utils/contextUtils.js +56 -49
- package/src/utils/contextUtils.ts +89 -0
- package/src/utils/fileUtils.js +72 -84
- package/src/utils/fileUtils.ts +100 -0
- package/src/utils/loadConfig.js +57 -13
- package/src/utils/loadConfig.ts +69 -0
- package/tsconfig.json +19 -0
- package/src/commands/generate/generateComponent.js +0 -53
- package/src/commands/generate/generateCrudBase.js +0 -207
- package/src/commands/generate/generateCrudPresenter.js +0 -232
- package/src/commands/generate/generateDatasource.js +0 -84
- package/src/commands/generate/generateDesignComponent.js +0 -53
- package/src/commands/generate/generateModule.js +0 -31
- package/src/commands/generate/generateModuleBase.js +0 -152
- package/src/commands/generate/generateModulePresenter.js +0 -110
- package/src/commands/generate/generatePresenter.js +0 -86
- package/src/commands/generate/generateRepository.js +0 -76
- package/src/commands/generate/generateResponse.js +0 -41
- package/src/commands/generate/generateSchema.js +0 -96
- package/src/commands/generate/generateService.js +0 -71
- package/src/commands/generate/generateWidget.js +0 -53
- package/src/commands/generate/index.js +0 -14
- package/src/commands/init/index.js +0 -9
- package/src/commands/init/initAliases.js +0 -52
- package/src/commands/init/initEdges.js +0 -42
- package/src/commands/init/initLint.js +0 -138
- package/src/commands/init/initMiddleware.js +0 -21
- package/src/commands/init/initPresenter.js +0 -25
- package/src/commands/init/initSchema.js +0 -22
- package/src/commands/init/initStructure.js +0 -140
- package/src/commands/init/initTranslations.js +0 -59
- package/src/commands/init/migrateStructure.js +0 -144
|
@@ -0,0 +1,189 @@
|
|
|
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 BoundaryIssue = {
|
|
7
|
+
file: string;
|
|
8
|
+
line: number;
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type ContextConfig = {
|
|
13
|
+
name: string;
|
|
14
|
+
alias: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
|
|
18
|
+
const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
|
|
19
|
+
|
|
20
|
+
const IMPORT_FROM_PATTERN = /\bimport\s+(?:type\s+)?[\s\S]*?\sfrom\s*['"]([^'"]+)['"]/g;
|
|
21
|
+
const EXPORT_FROM_PATTERN = /\bexport\s+(?:type\s+)?\{[\s\S]*?\}\sfrom\s*['"]([^'"]+)['"]/g;
|
|
22
|
+
const DYNAMIC_IMPORT_PATTERN = /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
23
|
+
|
|
24
|
+
const toPosixPath = (value: string): string => value.split(path.sep).join('/');
|
|
25
|
+
|
|
26
|
+
const normalizeAlias = (value: unknown, fallback = ''): string => {
|
|
27
|
+
const raw = String(value ?? '').trim();
|
|
28
|
+
if (!raw.length) return fallback;
|
|
29
|
+
return raw.startsWith('$') ? raw : `$${raw}`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const findLineByIndex = (content: string, index: number): number => {
|
|
33
|
+
let line = 1;
|
|
34
|
+
for (let i = 0; i < index; i += 1) {
|
|
35
|
+
if (content[i] === '\n') line += 1;
|
|
36
|
+
}
|
|
37
|
+
return line;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const getRelativePath = (filePath: string): string => toPosixPath(path.relative(process.cwd(), filePath));
|
|
41
|
+
|
|
42
|
+
const listFiles = async (rootDir: string): Promise<string[]> => {
|
|
43
|
+
const files: string[] = [];
|
|
44
|
+
const stack: string[] = [rootDir];
|
|
45
|
+
|
|
46
|
+
while (stack.length) {
|
|
47
|
+
const current = stack.pop();
|
|
48
|
+
if (!current) continue;
|
|
49
|
+
|
|
50
|
+
let entries: import('node:fs').Dirent[] = [];
|
|
51
|
+
try {
|
|
52
|
+
entries = await fs.readdir(current, { withFileTypes: true });
|
|
53
|
+
} catch {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const entry of entries) {
|
|
58
|
+
if (entry.isDirectory()) {
|
|
59
|
+
if (!IGNORED_DIRS.has(entry.name)) {
|
|
60
|
+
stack.push(path.join(current, entry.name));
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!entry.isFile()) continue;
|
|
66
|
+
const filePath = path.join(current, entry.name);
|
|
67
|
+
if (!TARGET_EXTENSIONS.has(path.extname(filePath))) continue;
|
|
68
|
+
files.push(filePath);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return files;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const extractImports = (content: string): Array<{ value: string; line: number }> => {
|
|
76
|
+
const matches: Array<{ value: string; line: number }> = [];
|
|
77
|
+
const patterns = [IMPORT_FROM_PATTERN, EXPORT_FROM_PATTERN, DYNAMIC_IMPORT_PATTERN];
|
|
78
|
+
|
|
79
|
+
for (const pattern of patterns) {
|
|
80
|
+
const regex = new RegExp(pattern.source, 'g');
|
|
81
|
+
let match: RegExpExecArray | null;
|
|
82
|
+
while ((match = regex.exec(content)) !== null) {
|
|
83
|
+
const value = match[1];
|
|
84
|
+
if (!value) continue;
|
|
85
|
+
matches.push({ value, line: findLineByIndex(content, match.index) });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return matches;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const resolveAliasFromImport = (importPath: string, aliases: string[]): string | null => {
|
|
93
|
+
const sorted = [...aliases].sort((a, b) => b.length - a.length);
|
|
94
|
+
for (const alias of sorted) {
|
|
95
|
+
if (importPath === alias || importPath.startsWith(`${alias}/`)) {
|
|
96
|
+
return alias;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const isSharedLikeContext = (contextName: string, alias: string): boolean => {
|
|
103
|
+
const normalizedName = contextName.toLowerCase();
|
|
104
|
+
const normalizedAlias = alias.toLowerCase();
|
|
105
|
+
return normalizedName.includes('shared') || normalizedAlias.includes('shared');
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export default async function checkLayerBoundaries(): Promise<void> {
|
|
109
|
+
const config = await loadUserConfig();
|
|
110
|
+
const contexts = normalizeContexts(config.contexts) as ContextConfig[];
|
|
111
|
+
|
|
112
|
+
if (!contexts.length) {
|
|
113
|
+
console.error('❌ No contexts found in azure-net.config.ts/js. Fill `contexts` first.');
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const coreAlias = normalizeAlias(config.coreAlias, '$core');
|
|
119
|
+
const sharedAliasRaw = normalizeAlias(config.sharedAlias, '');
|
|
120
|
+
const sharedAlias = sharedAliasRaw.length ? sharedAliasRaw : null;
|
|
121
|
+
|
|
122
|
+
const aliasToContext = new Map<string, ContextConfig>();
|
|
123
|
+
for (const context of contexts) {
|
|
124
|
+
aliasToContext.set(context.alias, context);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const knownAliases = [coreAlias, ...contexts.map((context) => context.alias)];
|
|
128
|
+
if (sharedAlias && !knownAliases.includes(sharedAlias)) {
|
|
129
|
+
knownAliases.push(sharedAlias);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const issues: BoundaryIssue[] = [];
|
|
133
|
+
|
|
134
|
+
for (const context of contexts) {
|
|
135
|
+
const layersRoot = path.join(process.cwd(), 'src', 'app', context.name, 'layers');
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
await fs.access(layersRoot);
|
|
139
|
+
} catch {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const files = await listFiles(layersRoot);
|
|
144
|
+
const allowedAliases = new Set<string>([context.alias, coreAlias]);
|
|
145
|
+
if (sharedAlias) {
|
|
146
|
+
allowedAliases.add(sharedAlias);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
for (const filePath of files) {
|
|
150
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
151
|
+
const imports = extractImports(content);
|
|
152
|
+
|
|
153
|
+
for (const entry of imports) {
|
|
154
|
+
const targetAlias = resolveAliasFromImport(entry.value, knownAliases);
|
|
155
|
+
if (!targetAlias) continue;
|
|
156
|
+
if (targetAlias === coreAlias) continue;
|
|
157
|
+
if (allowedAliases.has(targetAlias)) continue;
|
|
158
|
+
|
|
159
|
+
const targetContext = aliasToContext.get(targetAlias);
|
|
160
|
+
const baseMessage = targetContext
|
|
161
|
+
? `Layer boundary violation: context "${context.name}" cannot import from context "${targetContext.name}" (${targetAlias})`
|
|
162
|
+
: `Layer boundary violation: context "${context.name}" cannot import from "${targetAlias}"`;
|
|
163
|
+
|
|
164
|
+
const withSharedHint =
|
|
165
|
+
!sharedAlias && targetContext && isSharedLikeContext(targetContext.name, targetAlias)
|
|
166
|
+
? `${baseMessage}. sharedAlias is not configured in azure-net.config.ts/js; if this context is shared, set sharedAlias explicitly`
|
|
167
|
+
: baseMessage;
|
|
168
|
+
|
|
169
|
+
issues.push({
|
|
170
|
+
file: filePath,
|
|
171
|
+
line: entry.line,
|
|
172
|
+
message: withSharedHint
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!issues.length) {
|
|
179
|
+
console.log('✅ Layer boundaries check passed.');
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
console.error('❌ Layer boundaries check failed:');
|
|
184
|
+
for (const issue of issues) {
|
|
185
|
+
console.error(`• ${getRelativePath(issue.file)}:${issue.line} — ${issue.message}`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
process.exitCode = 1;
|
|
189
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
|
|
5
|
+
const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
|
|
6
|
+
|
|
7
|
+
const CREATE_FACTORY_PATTERN = '(?:export\\s+)?(?:const|let|var)\\s+([A-Za-z_$][A-Za-z0-9_$]*)\\s*=\\s*createPresenterFactory\\s*\\(';
|
|
8
|
+
const IMPORT_FROM_PRESENTER_PATTERN = 'import\\s*\\{([^}]+)\\}\\s*from\\s*[\'"]([^\'"]+)[\'"]';
|
|
9
|
+
const PRESENTER_CALL_PATTERN = '\\b([A-Za-z_$][A-Za-z0-9_$]*)\\s*\\(\\s*([\'"`])([^\'"`]*)\\2';
|
|
10
|
+
|
|
11
|
+
const toPosixPath = (value) => value.split(path.sep).join('/');
|
|
12
|
+
|
|
13
|
+
const isPresenterImportPath = (importPath) => {
|
|
14
|
+
const normalized = importPath.replace(/\\/g, '/');
|
|
15
|
+
return /(^|\/)presenter(\/|$)/.test(normalized);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const parseImportLocals = (rawImports) => {
|
|
19
|
+
const locals = [];
|
|
20
|
+
for (const segment of rawImports.split(',')) {
|
|
21
|
+
const item = segment.trim();
|
|
22
|
+
if (!item.length) continue;
|
|
23
|
+
const aliasMatch = item.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
|
|
24
|
+
if (aliasMatch?.[2]) {
|
|
25
|
+
locals.push(aliasMatch[2]);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const directMatch = item.match(/^([A-Za-z_$][A-Za-z0-9_$]*)$/);
|
|
30
|
+
if (directMatch?.[1]) {
|
|
31
|
+
locals.push(directMatch[1]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return locals;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const listSourceFiles = async (rootDir) => {
|
|
38
|
+
const result = [];
|
|
39
|
+
const stack = [rootDir];
|
|
40
|
+
|
|
41
|
+
while (stack.length) {
|
|
42
|
+
const current = stack.pop();
|
|
43
|
+
if (!current) continue;
|
|
44
|
+
|
|
45
|
+
let entries = [];
|
|
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 fullPath = path.join(current, entry.name);
|
|
62
|
+
const extension = path.extname(fullPath);
|
|
63
|
+
if (!TARGET_EXTENSIONS.has(extension)) continue;
|
|
64
|
+
result.push(fullPath);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getLineByIndex = (content, index) => {
|
|
72
|
+
let line = 1;
|
|
73
|
+
for (let i = 0; i < index; i += 1) {
|
|
74
|
+
if (content[i] === '\n') line += 1;
|
|
75
|
+
}
|
|
76
|
+
return line;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const extractFactoryNamesFromContent = (content) => {
|
|
80
|
+
const createFactoryRegex = new RegExp(CREATE_FACTORY_PATTERN, 'g');
|
|
81
|
+
const names = [];
|
|
82
|
+
let match;
|
|
83
|
+
while ((match = createFactoryRegex.exec(content)) !== null) {
|
|
84
|
+
const name = match[1];
|
|
85
|
+
if (name) names.push(name);
|
|
86
|
+
}
|
|
87
|
+
return names;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const extractImportedPresenterFactories = (content) => {
|
|
91
|
+
const importFromPresenterRegex = new RegExp(IMPORT_FROM_PRESENTER_PATTERN, 'g');
|
|
92
|
+
const names = [];
|
|
93
|
+
let match;
|
|
94
|
+
while ((match = importFromPresenterRegex.exec(content)) !== null) {
|
|
95
|
+
const rawImports = match[1];
|
|
96
|
+
const importPath = match[2];
|
|
97
|
+
if (!rawImports || !importPath) continue;
|
|
98
|
+
if (!isPresenterImportPath(importPath)) continue;
|
|
99
|
+
names.push(...parseImportLocals(rawImports));
|
|
100
|
+
}
|
|
101
|
+
return names;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const collectPresenterOccurrences = (content, filePath, knownFactories) => {
|
|
105
|
+
const presenterCallRegex = new RegExp(PRESENTER_CALL_PATTERN, 'g');
|
|
106
|
+
const occurrences = [];
|
|
107
|
+
const availableCallees = new Set(['createPresenter']);
|
|
108
|
+
|
|
109
|
+
for (const name of extractFactoryNamesFromContent(content)) {
|
|
110
|
+
availableCallees.add(name);
|
|
111
|
+
}
|
|
112
|
+
for (const name of extractImportedPresenterFactories(content)) {
|
|
113
|
+
availableCallees.add(name);
|
|
114
|
+
}
|
|
115
|
+
for (const name of knownFactories) {
|
|
116
|
+
availableCallees.add(name);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let match;
|
|
120
|
+
while ((match = presenterCallRegex.exec(content)) !== null) {
|
|
121
|
+
const callee = match[1];
|
|
122
|
+
const quote = match[2];
|
|
123
|
+
const presenterId = match[3];
|
|
124
|
+
if (!callee || !presenterId) continue;
|
|
125
|
+
if (!availableCallees.has(callee)) continue;
|
|
126
|
+
if (quote === '`' && presenterId.includes('${')) continue;
|
|
127
|
+
|
|
128
|
+
occurrences.push({
|
|
129
|
+
id: presenterId,
|
|
130
|
+
file: filePath,
|
|
131
|
+
line: getLineByIndex(content, match.index),
|
|
132
|
+
callee
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return occurrences;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export default async function checkPresenterNames() {
|
|
140
|
+
const srcPath = path.join(process.cwd(), 'src');
|
|
141
|
+
try {
|
|
142
|
+
await fs.access(srcPath);
|
|
143
|
+
} catch {
|
|
144
|
+
console.error('❌ src folder not found in current workspace.');
|
|
145
|
+
process.exitCode = 1;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const files = await listSourceFiles(srcPath);
|
|
150
|
+
const fileContents = new Map();
|
|
151
|
+
|
|
152
|
+
for (const filePath of files) {
|
|
153
|
+
// eslint-disable-next-line no-await-in-loop
|
|
154
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
155
|
+
fileContents.set(filePath, content);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const globalFactoryNames = new Set();
|
|
159
|
+
for (const [filePath, content] of fileContents.entries()) {
|
|
160
|
+
for (const name of extractFactoryNamesFromContent(content)) {
|
|
161
|
+
globalFactoryNames.add(name);
|
|
162
|
+
}
|
|
163
|
+
if (filePath.endsWith(path.join('core', 'presenter', 'index.ts')) || filePath.endsWith(path.join('core', 'presenter', 'index.js'))) {
|
|
164
|
+
for (const name of extractImportedPresenterFactories(content)) {
|
|
165
|
+
globalFactoryNames.add(name);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const occurrences = [];
|
|
171
|
+
for (const [filePath, content] of fileContents.entries()) {
|
|
172
|
+
occurrences.push(...collectPresenterOccurrences(content, filePath, globalFactoryNames));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!occurrences.length) {
|
|
176
|
+
console.log('✅ No presenter declarations found.');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const grouped = new Map();
|
|
181
|
+
for (const occurrence of occurrences) {
|
|
182
|
+
const list = grouped.get(occurrence.id) ?? [];
|
|
183
|
+
list.push(occurrence);
|
|
184
|
+
grouped.set(occurrence.id, list);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const duplicated = Array.from(grouped.entries()).filter(([, list]) => list.length > 1);
|
|
188
|
+
if (!duplicated.length) {
|
|
189
|
+
console.log(`✅ Presenter names are unique (${occurrences.length} found).`);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
console.error('❌ Duplicate presenter names found:');
|
|
194
|
+
for (const [presenterId, list] of duplicated) {
|
|
195
|
+
console.error(`\n- "${presenterId}"`);
|
|
196
|
+
for (const item of list) {
|
|
197
|
+
console.error(` • ${toPosixPath(path.relative(process.cwd(), item.file))}:${item.line} (${item.callee})`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
process.exitCode = 1;
|
|
202
|
+
}
|
|
@@ -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, 'typecheck');
|
|
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, 'typecheck');
|
|
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
|
+
}
|