@azure-net/cli 4.0.0-0 → 4.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/azure-net.js +65 -34
- package/bin/azure-net.ts +65 -34
- package/eslint.config.js +15 -0
- package/package.json +1 -1
- package/src/checks/checkDomain.js +201 -0
- package/src/checks/checkDomain.ts +213 -0
- package/src/checks/checkFoldersStructure.js +70 -0
- package/src/checks/checkFoldersStructure.ts +85 -0
- package/src/checks/checkInternal.js +35 -0
- package/src/checks/checkInternal.ts +40 -0
- package/src/checks/checkLayerBoundaries.js +178 -0
- package/src/checks/checkLayerBoundaries.ts +189 -0
- package/src/checks/checkPresenterNames.js +202 -0
- package/src/checks/checkPresenterNames.ts +208 -0
- package/src/checks/checkProject.js +42 -0
- package/src/checks/checkProject.ts +45 -0
- package/src/checks/checkProviderNames.js +158 -0
- package/src/checks/checkProviderNames.ts +165 -0
- package/src/checks/index.js +7 -0
- package/src/checks/index.ts +7 -0
- package/src/generate/layers/generateRepository.ts +123 -0
- package/src/generate/layers/generateRepositoryMethod.ts +102 -0
- package/src/generate/layers/generateUseCases.ts +50 -0
- package/src/generate/layers/repositoryShared.ts +657 -0
- package/src/generate/module/generateModulePreset.js +307 -0
- package/src/generate/module/generateModulePreset.ts +337 -0
- package/src/generate/module/generateSchemaFromType.js +46 -8
- package/src/generate/module/generateSchemaFromType.ts +52 -8
- package/src/generate/module/repositoryModuleShared.ts +661 -0
- package/src/utils/contextUtils.ts +89 -0
- package/src/utils/fileUtils.ts +100 -0
- package/src/utils/loadConfig.ts +69 -0
- package/src/commands/generate/generateCrudBase.js +0 -188
- package/src/commands/generate/generateCrudPresenter.js +0 -225
- package/src/commands/generate/generateModule.js +0 -31
- package/src/commands/generate/generateModuleBase.js +0 -130
- package/src/commands/generate/generateModulePresenter.js +0 -103
- package/src/commands/generate/generatePresenter.js +0 -80
- package/src/commands/generate/generateRepository.js +0 -70
- package/src/commands/generate/generateSchema.js +0 -100
- package/src/commands/generate/generateService.js +0 -66
- package/src/commands/generate/index.js +0 -9
|
@@ -0,0 +1,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
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
const IMPORT_PATTERN = 'import\\s*\\{([^}]+)\\}\\s*from\\s*[\'"]([^\'"]+)[\'"]';
|
|
7
|
+
const CALL_PATTERN = '\\b([A-Za-z_$][A-Za-z0-9_$]*)\\s*\\(\\s*([\'"`])([^\'"`]*)\\2';
|
|
8
|
+
|
|
9
|
+
const toPosixPath = (value) => value.split(path.sep).join('/');
|
|
10
|
+
|
|
11
|
+
const parseImportAliases = (rawImports, importName) => {
|
|
12
|
+
const aliases = [];
|
|
13
|
+
for (const segment of rawImports.split(',')) {
|
|
14
|
+
const item = segment.trim();
|
|
15
|
+
if (!item.length) continue;
|
|
16
|
+
|
|
17
|
+
const aliasMatch = item.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
|
|
18
|
+
if (aliasMatch?.[1] === importName && aliasMatch[2]) {
|
|
19
|
+
aliases.push(aliasMatch[2]);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (item === importName) {
|
|
24
|
+
aliases.push(importName);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return aliases;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const listSourceFiles = async (rootDir) => {
|
|
31
|
+
const files = [];
|
|
32
|
+
const stack = [rootDir];
|
|
33
|
+
|
|
34
|
+
while (stack.length) {
|
|
35
|
+
const current = stack.pop();
|
|
36
|
+
if (!current) continue;
|
|
37
|
+
|
|
38
|
+
let entries = [];
|
|
39
|
+
try {
|
|
40
|
+
entries = await fs.readdir(current, { withFileTypes: true });
|
|
41
|
+
} catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
if (entry.isDirectory()) {
|
|
47
|
+
if (!IGNORED_DIRS.has(entry.name)) {
|
|
48
|
+
stack.push(path.join(current, entry.name));
|
|
49
|
+
}
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!entry.isFile()) continue;
|
|
54
|
+
const filepath = path.join(current, entry.name);
|
|
55
|
+
if (!TARGET_EXTENSIONS.has(path.extname(filepath))) continue;
|
|
56
|
+
files.push(filepath);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return files;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getLineByIndex = (content, index) => {
|
|
64
|
+
let line = 1;
|
|
65
|
+
for (let i = 0; i < index; i += 1) {
|
|
66
|
+
if (content[i] === '\n') line += 1;
|
|
67
|
+
}
|
|
68
|
+
return line;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const extractBoundaryFactoryAliases = (content) => {
|
|
72
|
+
const importRegex = new RegExp(IMPORT_PATTERN, 'g');
|
|
73
|
+
const aliases = new Set(['createBoundaryProvider']);
|
|
74
|
+
let match;
|
|
75
|
+
|
|
76
|
+
while ((match = importRegex.exec(content)) !== null) {
|
|
77
|
+
const rawImports = match[1];
|
|
78
|
+
if (!rawImports) continue;
|
|
79
|
+
for (const alias of parseImportAliases(rawImports, 'createBoundaryProvider')) {
|
|
80
|
+
aliases.add(alias);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return aliases;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const collectProviderOccurrences = (content, filepath) => {
|
|
88
|
+
const aliases = extractBoundaryFactoryAliases(content);
|
|
89
|
+
const callRegex = new RegExp(CALL_PATTERN, 'g');
|
|
90
|
+
const occurrences = [];
|
|
91
|
+
let match;
|
|
92
|
+
|
|
93
|
+
while ((match = callRegex.exec(content)) !== null) {
|
|
94
|
+
const callee = match[1];
|
|
95
|
+
const quote = match[2];
|
|
96
|
+
const providerId = match[3];
|
|
97
|
+
|
|
98
|
+
if (!callee || !providerId) continue;
|
|
99
|
+
if (!aliases.has(callee)) continue;
|
|
100
|
+
if (quote === '`' && providerId.includes('${')) continue;
|
|
101
|
+
|
|
102
|
+
occurrences.push({
|
|
103
|
+
id: providerId,
|
|
104
|
+
file: filepath,
|
|
105
|
+
line: getLineByIndex(content, match.index),
|
|
106
|
+
callee
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return occurrences;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export default async function checkProviderNames() {
|
|
114
|
+
const srcPath = path.join(process.cwd(), 'src');
|
|
115
|
+
try {
|
|
116
|
+
await fs.access(srcPath);
|
|
117
|
+
} catch {
|
|
118
|
+
console.error('❌ src folder not found in current workspace.');
|
|
119
|
+
process.exitCode = 1;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const files = await listSourceFiles(srcPath);
|
|
124
|
+
const occurrences = [];
|
|
125
|
+
|
|
126
|
+
for (const filepath of files) {
|
|
127
|
+
const content = await fs.readFile(filepath, 'utf-8');
|
|
128
|
+
occurrences.push(...collectProviderOccurrences(content, filepath));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!occurrences.length) {
|
|
132
|
+
console.log('✅ No providers declarations found.');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const grouped = new Map();
|
|
137
|
+
for (const occurrence of occurrences) {
|
|
138
|
+
const list = grouped.get(occurrence.id) ?? [];
|
|
139
|
+
list.push(occurrence);
|
|
140
|
+
grouped.set(occurrence.id, list);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const duplicated = Array.from(grouped.entries()).filter(([, list]) => list.length > 1);
|
|
144
|
+
if (!duplicated.length) {
|
|
145
|
+
console.log(`✅ Provider names are unique (${occurrences.length} found).`);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
console.error('❌ Duplicate provider names found:');
|
|
150
|
+
for (const [providerId, list] of duplicated) {
|
|
151
|
+
console.error(`\n- "${providerId}"`);
|
|
152
|
+
for (const item of list) {
|
|
153
|
+
console.error(` • ${toPosixPath(path.relative(process.cwd(), item.file))}:${item.line} (${item.callee})`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
process.exitCode = 1;
|
|
158
|
+
}
|