@azure-net/cli 1.1.4 → 1.1.7
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 +1 -1
- package/src/commands/generateCrud.js +10 -6
- package/src/templates/data/repo/ClassRepo.ejs +3 -3
- package/src/templates/domain/abstracts/Class.ejs +5 -2
- package/src/templates/domain/abstracts/ClassCreateRequest.ejs +4 -1
- package/src/templates/domain/abstracts/ClassUpdateRequest.ejs +4 -1
- package/src/templates/domain/services/ClassService.ejs +1 -1
- package/src/templates/generateCrudRepo.ejs +1 -1
package/package.json
CHANGED
|
@@ -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
|
-
// ✅
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { <%= datasource %> } from '$data/datasources';
|
|
2
2
|
import {
|
|
3
3
|
I<%= className %>Collection,
|
|
4
4
|
I<%= className %>Resource,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
|
|
9
9
|
export class <%= className %>Repo {
|
|
10
10
|
private endpoint = '<%= endpoint %>';
|
|
11
|
-
constructor(private source
|
|
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));
|
|
@@ -29,4 +29,4 @@ export class <%= className %>Repo {
|
|
|
29
29
|
public async remove(id: number) {
|
|
30
30
|
return await this.source.createRequest<void>(({ http }) => http.delete(`${this.endpoint}/${id}`));
|
|
31
31
|
}
|
|
32
|
-
}
|
|
32
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export interface I<%= className %>Resource {
|
|
1
|
+
export interface I<%= className %>Resource {
|
|
2
|
+
// TODO: define fields
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
}
|
|
2
5
|
|
|
3
|
-
export type I<%= className %>Collection = I<%= className %>Resource[];
|
|
6
|
+
export type I<%= className %>Collection = I<%= className %>Resource[];
|