@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
|
@@ -186,9 +186,9 @@ const findInterfaceBodyByScan = async (rootDir, interfaceName) => {
|
|
|
186
186
|
return null;
|
|
187
187
|
};
|
|
188
188
|
|
|
189
|
-
const
|
|
189
|
+
const extractRuleKeys = (body) => {
|
|
190
190
|
const keys = [];
|
|
191
|
-
const keyRegex = /^\s*([A-Za-z_$][A-Za-z0-9_$]*)
|
|
191
|
+
const keyRegex = /^\s*([A-Za-z_$][A-Za-z0-9_$]*)\s*:/gm;
|
|
192
192
|
let match;
|
|
193
193
|
while ((match = keyRegex.exec(body)) !== null) {
|
|
194
194
|
keys.push(match[1]);
|
|
@@ -196,14 +196,52 @@ const extractKeys = (body) => {
|
|
|
196
196
|
return Array.from(new Set(keys));
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
const
|
|
199
|
+
const extractInterfaceFields = (body) => {
|
|
200
|
+
const fields = [];
|
|
201
|
+
const fieldRegex = /^\s*(?:readonly\s+)?([A-Za-z_$][A-Za-z0-9_$]*)(\?)?\s*:\s*([^;]+);/gm;
|
|
202
|
+
let match;
|
|
203
|
+
while ((match = fieldRegex.exec(body)) !== null) {
|
|
204
|
+
const name = match[1];
|
|
205
|
+
const optionalMark = match[2];
|
|
206
|
+
const type = String(match[3] ?? '').trim();
|
|
207
|
+
if (!name || !type) continue;
|
|
208
|
+
fields.push({
|
|
209
|
+
name,
|
|
210
|
+
optional: optionalMark === '?',
|
|
211
|
+
type
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const unique = new Map();
|
|
216
|
+
for (const field of fields) {
|
|
217
|
+
if (!unique.has(field.name)) unique.set(field.name, field);
|
|
218
|
+
}
|
|
219
|
+
return Array.from(unique.values());
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const buildRulesArray = (field) => {
|
|
223
|
+
const ruleCalls = [];
|
|
224
|
+
if (!field.optional) {
|
|
225
|
+
ruleCalls.push('rules.required()');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (field.type === 'string') {
|
|
229
|
+
ruleCalls.push('rules.string()');
|
|
230
|
+
} else if (field.type === 'number') {
|
|
231
|
+
ruleCalls.push('rules.number()');
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return `[${ruleCalls.join(', ')}]`;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const updateRulesObject = (schemaContent, fields) => {
|
|
200
238
|
const rulesRegex = /\.rules\(\(rules\)\s*=>\s*\(\{([\s\S]*?)\}\)\)/m;
|
|
201
239
|
const match = schemaContent.match(rulesRegex);
|
|
202
240
|
if (!match) return null;
|
|
203
241
|
|
|
204
242
|
const currentBody = match[1] ?? '';
|
|
205
|
-
const existingKeys = new Set(
|
|
206
|
-
const newLines =
|
|
243
|
+
const existingKeys = new Set(extractRuleKeys(currentBody));
|
|
244
|
+
const newLines = fields.filter((field) => !existingKeys.has(field.name)).map((field) => `\t\t${field.name}: ${buildRulesArray(field)},`);
|
|
207
245
|
|
|
208
246
|
if (!newLines.length) return schemaContent;
|
|
209
247
|
|
|
@@ -297,13 +335,13 @@ export default async function generateSchemaFromType() {
|
|
|
297
335
|
return;
|
|
298
336
|
}
|
|
299
337
|
|
|
300
|
-
const
|
|
301
|
-
if (!
|
|
338
|
+
const interfaceFields = extractInterfaceFields(interfaceBody);
|
|
339
|
+
if (!interfaceFields.length) {
|
|
302
340
|
console.log('ℹ️ Interface has no explicit keys to transfer into rules.');
|
|
303
341
|
return;
|
|
304
342
|
}
|
|
305
343
|
|
|
306
|
-
const updatedSchemaContent = updateRulesObject(schemaContent,
|
|
344
|
+
const updatedSchemaContent = updateRulesObject(schemaContent, interfaceFields);
|
|
307
345
|
if (!updatedSchemaContent) {
|
|
308
346
|
console.error('❌ Could not locate `.rules((rules) => ({}))` block in schema file.');
|
|
309
347
|
process.exitCode = 1;
|
|
@@ -190,9 +190,15 @@ const findInterfaceBodyByScan = async (rootDir: string, interfaceName: string):
|
|
|
190
190
|
return null;
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
type InterfaceField = {
|
|
194
|
+
name: string;
|
|
195
|
+
optional: boolean;
|
|
196
|
+
type: string;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const extractRuleKeys = (body: string): string[] => {
|
|
194
200
|
const keys: string[] = [];
|
|
195
|
-
const keyRegex = /^\s*([A-Za-z_$][A-Za-z0-9_$]*)
|
|
201
|
+
const keyRegex = /^\s*([A-Za-z_$][A-Za-z0-9_$]*)\s*:/gm;
|
|
196
202
|
let match: RegExpExecArray | null;
|
|
197
203
|
while ((match = keyRegex.exec(body)) !== null) {
|
|
198
204
|
const key = match[1];
|
|
@@ -201,14 +207,52 @@ const extractKeys = (body: string): string[] => {
|
|
|
201
207
|
return Array.from(new Set(keys));
|
|
202
208
|
};
|
|
203
209
|
|
|
204
|
-
const
|
|
210
|
+
const extractInterfaceFields = (body: string): InterfaceField[] => {
|
|
211
|
+
const fields: InterfaceField[] = [];
|
|
212
|
+
const fieldRegex = /^\s*(?:readonly\s+)?([A-Za-z_$][A-Za-z0-9_$]*)(\?)?\s*:\s*([^;]+);/gm;
|
|
213
|
+
let match: RegExpExecArray | null;
|
|
214
|
+
while ((match = fieldRegex.exec(body)) !== null) {
|
|
215
|
+
const name = match[1];
|
|
216
|
+
const optionalMark = match[2];
|
|
217
|
+
const type = String(match[3] ?? '').trim();
|
|
218
|
+
if (!name || !type) continue;
|
|
219
|
+
fields.push({
|
|
220
|
+
name,
|
|
221
|
+
optional: optionalMark === '?',
|
|
222
|
+
type
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const unique = new Map<string, InterfaceField>();
|
|
227
|
+
for (const field of fields) {
|
|
228
|
+
if (!unique.has(field.name)) unique.set(field.name, field);
|
|
229
|
+
}
|
|
230
|
+
return Array.from(unique.values());
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const buildRulesArray = (field: InterfaceField): string => {
|
|
234
|
+
const ruleCalls: string[] = [];
|
|
235
|
+
if (!field.optional) {
|
|
236
|
+
ruleCalls.push('rules.required()');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (field.type === 'string') {
|
|
240
|
+
ruleCalls.push('rules.string()');
|
|
241
|
+
} else if (field.type === 'number') {
|
|
242
|
+
ruleCalls.push('rules.number()');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return `[${ruleCalls.join(', ')}]`;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const updateRulesObject = (schemaContent: string, fields: InterfaceField[]): string | null => {
|
|
205
249
|
const rulesRegex = /\.rules\(\(rules\)\s*=>\s*\(\{([\s\S]*?)\}\)\)/m;
|
|
206
250
|
const match = schemaContent.match(rulesRegex);
|
|
207
251
|
if (!match) return null;
|
|
208
252
|
|
|
209
253
|
const currentBody = match[1] ?? '';
|
|
210
|
-
const existingKeys = new Set(
|
|
211
|
-
const newLines =
|
|
254
|
+
const existingKeys = new Set(extractRuleKeys(currentBody));
|
|
255
|
+
const newLines = fields.filter((field) => !existingKeys.has(field.name)).map((field) => `\t\t${field.name}: ${buildRulesArray(field)},`);
|
|
212
256
|
|
|
213
257
|
if (!newLines.length) return schemaContent;
|
|
214
258
|
|
|
@@ -302,13 +346,13 @@ export default async function generateSchemaFromType(): Promise<void> {
|
|
|
302
346
|
return;
|
|
303
347
|
}
|
|
304
348
|
|
|
305
|
-
const
|
|
306
|
-
if (!
|
|
349
|
+
const interfaceFields = extractInterfaceFields(interfaceBody);
|
|
350
|
+
if (!interfaceFields.length) {
|
|
307
351
|
console.log('ℹ️ Interface has no explicit keys to transfer into rules.');
|
|
308
352
|
return;
|
|
309
353
|
}
|
|
310
354
|
|
|
311
|
-
const updatedSchemaContent = updateRulesObject(schemaContent,
|
|
355
|
+
const updatedSchemaContent = updateRulesObject(schemaContent, interfaceFields);
|
|
312
356
|
if (!updatedSchemaContent) {
|
|
313
357
|
console.error('❌ Could not locate `.rules((rules) => ({}))` block in schema file.');
|
|
314
358
|
process.exitCode = 1;
|