@azure-net/cli 1.1.5 → 1.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/cli",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "azure-net": "bin/azure-net.js"
@@ -19,15 +19,18 @@ async function writeIfNotExists(filepath, content) {
19
19
 
20
20
  export default async function generateCrud() {
21
21
  const config = await loadUserConfig();
22
+
22
23
  const answers = await prompts([
23
24
  { type: 'text', name: 'className', message: 'Class name (PascalCase):' },
24
- { type: 'text', name: 'endpoint', message: 'API endpoint:' }
25
+ { type: 'text', name: 'endpoint', message: 'API endpoint:' },
26
+ { type: 'text', name: 'datasource', message: 'Datasource name:', initial: 'BaseDatasource' }
25
27
  ]);
26
28
 
27
29
  const rawName = answers.className.trim();
28
30
  const capital = rawName[0].toUpperCase() + rawName.slice(1);
29
31
  const lower = rawName[0].toLowerCase() + rawName.slice(1);
30
32
  const endpoint = answers.endpoint.trim();
33
+ const datasource = answers.datasource.trim();
31
34
 
32
35
  // === Domain lowercase folder ===
33
36
  const domainPath = path.join(process.cwd(), config.output.domain, lower);
@@ -73,13 +76,13 @@ export default async function generateCrud() {
73
76
  });
74
77
  await writeIfNotExists(path.join(serviceDir, `${capital}Service.ts`), serviceResult);
75
78
 
76
- // ✅ Новый файл index.ts в services
79
+ // ✅ Services index.ts
77
80
  await writeIfNotExists(
78
81
  path.join(serviceDir, 'index.ts'),
79
82
  `export * from './${capital}Service';\n`
80
83
  );
81
84
 
82
- // 4) Domain Index
85
+ // === 4) Domain Index ===
83
86
  await writeIfNotExists(
84
87
  path.join(domainPath, 'index.ts'),
85
88
  [
@@ -89,16 +92,17 @@ export default async function generateCrud() {
89
92
  ].join('\n')
90
93
  );
91
94
 
92
- // === Generate Repo ===
95
+ // === 5) Generate Repo ===
93
96
  const repoTpl = await fs.readFile(path.join(__dirname, '../templates/data/repo/ClassRepo.ejs'), 'utf-8');
94
97
  const repoResult = ejs.render(repoTpl, {
95
98
  className: capital,
96
99
  endpoint,
97
- domainName: lower
100
+ domainName: lower,
101
+ datasource // <-- 👈 Передаём!
98
102
  });
99
103
  await writeIfNotExists(path.join(repoPath, `${capital}Repo.ts`), repoResult);
100
104
 
101
- // === Repo Index ===
105
+ // === 6) Repo Index ===
102
106
  const files = await fs.readdir(repoPath);
103
107
  const exports = files
104
108
  .filter(f => f.endsWith('Repo.ts') && f !== 'index.ts')
@@ -1,5 +1,5 @@
1
- import { BaseDatasource } from '@azure-net/kit';
2
- import {
1
+ import { <%= datasource %> } from '$data/datasources';
2
+ import type {
3
3
  I<%= className %>Collection,
4
4
  I<%= className %>Resource,
5
5
  I<%= className %>CreateRequest,
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  export class <%= className %>Repo {
10
10
  private endpoint = '<%= endpoint %>';
11
- constructor(private source: BaseDatasource) {}
11
+ constructor(private source = new <%= datasource %>()) {}
12
12
 
13
13
  public async collection() {
14
14
  return await this.source.createRequest<I<%= className %>Collection>(({ http }) => http.get(this.endpoint));
@@ -1,5 +1,5 @@
1
1
  import { BaseRequest } from '@azure-net/kit';
2
- import { I<%= className %>CreateRequest } from '../abstracts';
2
+ import type { I<%= className %>CreateRequest } from '../abstracts';
3
3
 
4
4
  export class <%= className %>CreateRequest extends BaseRequest<I<%= className %>CreateRequest> {
5
5
  override rules() {
@@ -1,5 +1,5 @@
1
1
  import { BaseRequest } from '@azure-net/kit';
2
- import { I<%= className %>UpdateRequest } from '../abstracts';
2
+ import type { I<%= className %>UpdateRequest } from '../abstracts';
3
3
 
4
4
  export class <%= className %>UpdateRequest extends BaseRequest<I<%= className %>UpdateRequest> {
5
5
  override rules() {
@@ -1,6 +1,6 @@
1
1
  import { BaseService } from '@azure-net/kit';
2
2
  import { <%= className %>Repo } from '$data/repo';
3
- import { <%= className %>CreateRequest, <%= className %>UpdateRequest } from '$domain/<%= domainName %>/request';
3
+ import type { <%= className %>CreateRequest, <%= className %>UpdateRequest } from '$domain/<%= domainName %>/request';
4
4
 
5
5
  export class <%= className %>Service extends BaseService {
6
6
  constructor(private <%= domainName %>Repo = new <%= className %>Repo()) {
@@ -23,4 +23,4 @@ export class <%= className %>Repo {
23
23
  public async delete(id: number) {
24
24
  return await this.source.createRequest<unknown>(({ http }) => http.delete(`${this.endpoint}/${id}`));
25
25
  }
26
- }
26
+ }