@azure-net/cli 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/azure-net.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { Command } from 'commander';
4
+ import generateRequest from '../src/commands/generateRequest.js';
4
5
  import generateDatasource from '../src/commands/generateDatasource.js';
5
6
  import generateRepo from '../src/commands/generateRepo.js';
6
7
  import generateService from '../src/commands/generateService.js';
@@ -26,6 +27,11 @@ program
26
27
  .description('Generate repo')
27
28
  .action(generateRepo);
28
29
 
30
+ program
31
+ .command('make:request')
32
+ .description('Generate request')
33
+ .action(generateRequest);
34
+
29
35
  program
30
36
  .command('make:service')
31
37
  .description('Generate service')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/cli",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "azure-net": "bin/azure-net.js"
@@ -15,6 +15,12 @@ async function writeIfNotExists(filepath, content) {
15
15
  }
16
16
  }
17
17
 
18
+ async function updateIndexTs(dir) {
19
+ const files = (await fs.readdir(dir)).filter(f => f.endsWith('.ts') && f !== 'index.ts');
20
+ const content = files.map(f => `export * from './${f.replace('.ts', '')}';`).join('\n') + '\n';
21
+ await fs.writeFile(path.join(dir, 'index.ts'), content, 'utf-8');
22
+ }
23
+
18
24
  export default async function generateDatasource() {
19
25
  const { name } = await prompts({
20
26
  type: 'text',
@@ -28,11 +34,11 @@ export default async function generateDatasource() {
28
34
  const content = `import { BaseHttpDatasource, HttpService } from '@azure-net/kit';
29
35
 
30
36
  export class ${capital}Datasource extends BaseHttpDatasource {
31
- // TODO: fill generated class
32
37
  constructor() {
33
- super({ http: new HttpService({ baseUrl: '' }) });
38
+ super({ http: new HttpService({ baseUrl: '' }) }); // TODO: fill generated class
34
39
  }
35
40
  }`;
36
41
 
37
42
  await writeIfNotExists(filePath, content);
43
+ await updateIndexTs(CORE_DATASOURCES_PATH);
38
44
  }
@@ -1,4 +1,3 @@
1
- // === generateRepo.js ===
2
1
  import prompts from 'prompts';
3
2
  import fs from 'fs/promises';
4
3
  import path from 'path';
@@ -16,6 +15,12 @@ async function getAvailableDatasources() {
16
15
  }
17
16
  }
18
17
 
18
+ async function updateIndexTs(dir) {
19
+ const files = (await fs.readdir(dir)).filter(f => f.endsWith('.ts') && f !== 'index.ts');
20
+ const content = files.map(f => `export * from './${f.replace('.ts', '')}';`).join('\n') + '\n';
21
+ await fs.writeFile(path.join(dir, 'index.ts'), content, 'utf-8');
22
+ }
23
+
19
24
  export default async function generateRepo() {
20
25
  const config = await loadUserConfig();
21
26
  const datasources = await getAvailableDatasources();
@@ -59,5 +64,6 @@ export class ${capital}Repo {
59
64
 
60
65
  await fs.mkdir(repoDir, { recursive: true });
61
66
  await fs.writeFile(filePath, content);
67
+ await updateIndexTs(repoDir);
62
68
  console.log(`✅ Repo created at ${filePath}`);
63
- }
69
+ }
@@ -0,0 +1,95 @@
1
+ import prompts from 'prompts';
2
+ import fs from 'fs/promises';
3
+ import path from 'path';
4
+ import ejs from 'ejs';
5
+ import { loadUserConfig } from '../utils/loadConfig.js';
6
+
7
+ const __dirname = path.dirname(new URL(import.meta.url).pathname);
8
+ const CONTEXTS_PATH = path.join(process.cwd(), 'src/app/contexts');
9
+
10
+ async function writeIfNotExists(filepath, content) {
11
+ try {
12
+ await fs.access(filepath);
13
+ console.log(`⚠️ Skip existing: ${filepath}`);
14
+ } catch {
15
+ await fs.mkdir(path.dirname(filepath), { recursive: true });
16
+ await fs.writeFile(filepath, content, 'utf-8');
17
+ console.log(`✅ Created: ${filepath}`);
18
+ }
19
+ }
20
+
21
+ async function updateIndexTs(dir) {
22
+ const files = (await fs.readdir(dir)).filter(f => f.endsWith('.ts') && f !== 'index.ts');
23
+ const content = files.map(f => `export * from './${f.replace('.ts', '')}';`).join('\n') + '\n';
24
+ await fs.writeFile(path.join(dir, 'index.ts'), content, 'utf-8');
25
+ }
26
+
27
+ async function getAvailableSubfolders(baseDomainPath) {
28
+ try {
29
+ const entries = await fs.readdir(baseDomainPath, { withFileTypes: true });
30
+ return entries.filter(e => e.isDirectory()).map(e => e.name);
31
+ } catch {
32
+ return [];
33
+ }
34
+ }
35
+
36
+ export default async function generateRequest() {
37
+ const config = await loadUserConfig();
38
+
39
+ const { module } = await prompts({
40
+ type: 'select',
41
+ name: 'module',
42
+ message: 'Select target module:',
43
+ choices: [...config.modules, 'shared-context'].map(m => ({ title: m, value: m }))
44
+ });
45
+
46
+ const { className } = await prompts({
47
+ type: 'text',
48
+ name: 'className',
49
+ message: 'Request class name (PascalCase, without `Request` suffix):'
50
+ });
51
+
52
+ const pascalCaseName = className.trim();
53
+ const aliasModule = module === 'shared-context' ? '$shared-context' : `$${module}`;
54
+
55
+ const domainPath = path.join(CONTEXTS_PATH, module, 'Domain');
56
+ const availableSub = await getAvailableSubfolders(domainPath);
57
+
58
+ const { submodule } = await prompts({
59
+ type: 'autocomplete',
60
+ name: 'submodule',
61
+ message: 'Select or enter submodule:',
62
+ choices: [...availableSub.map(s => ({ title: s, value: s })), { title: '[Create new submodule]', value: '__custom' }]
63
+ });
64
+
65
+ let actualSub = submodule;
66
+ if (submodule === '__custom') {
67
+ const { newSub } = await prompts({
68
+ type: 'text',
69
+ name: 'newSub',
70
+ message: 'Enter new submodule name:'
71
+ });
72
+ actualSub = newSub.trim();
73
+ }
74
+
75
+ const basePath = path.join(domainPath, actualSub);
76
+ const abstractsDir = path.join(basePath, 'Abstracts');
77
+ const requestDir = path.join(basePath, 'Request');
78
+
79
+ const templateData = { pascalCaseName };
80
+
81
+ const abstractTpl = `export interface I${pascalCaseName}Request {
82
+ // TODO: define fields
83
+ [key: string]: unknown;
84
+ }`;
85
+ await writeIfNotExists(path.join(abstractsDir, `I${pascalCaseName}Request.ts`), abstractTpl);
86
+ await updateIndexTs(abstractsDir);
87
+
88
+ const requestTplPath = path.join(__dirname, '../templates/domain/request/ClassRequest.ejs');
89
+ const tpl = await fs.readFile(requestTplPath, 'utf-8');
90
+ const result = ejs.render(tpl, templateData);
91
+ await writeIfNotExists(path.join(requestDir, `${pascalCaseName}Request.ts`), result);
92
+ await updateIndexTs(requestDir);
93
+
94
+ console.log(`✅ Request generated in ${path.join(module, actualSub)}`);
95
+ }
@@ -15,6 +15,12 @@ async function getAvailableRepos(module) {
15
15
  }
16
16
  }
17
17
 
18
+ async function updateIndexTs(dir) {
19
+ const files = (await fs.readdir(dir)).filter(f => f.endsWith('.ts') && f !== 'index.ts');
20
+ const content = files.map(f => `export * from './${f.replace('.ts', '')}';`).join('\n') + '\n';
21
+ await fs.writeFile(path.join(dir, 'index.ts'), content, 'utf-8');
22
+ }
23
+
18
24
  export default async function generateService() {
19
25
  const config = await loadUserConfig();
20
26
 
@@ -66,5 +72,6 @@ export class ${capital}Service {
66
72
 
67
73
  await fs.mkdir(serviceDir, { recursive: true });
68
74
  await fs.writeFile(filePath, content);
75
+ await updateIndexTs(serviceDir);
69
76
  console.log(`✅ Service created at ${filePath}`);
70
77
  }
@@ -0,0 +1,8 @@
1
+ import { BaseRequest } from '@azure-net/kit';
2
+ import type { I<%= pascalCaseName %>Request } from '../Abstracts';
3
+
4
+ export class <%= pascalCaseName %>Request extends BaseRequest<I<%= pascalCaseName %>Request> {
5
+ override rules() {
6
+ return {};
7
+ }
8
+ }