@azure-net/cli 2.1.7 ā 2.2.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/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import prompts from 'prompts';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
selectContext,
|
|
5
|
+
getContextPath,
|
|
6
|
+
toPascalCase,
|
|
7
|
+
toCamelCase,
|
|
8
|
+
getAvailableFiles,
|
|
9
|
+
toKebabCase
|
|
10
|
+
} from '../../utils/contextUtils.js';
|
|
4
11
|
import { writeIfNotExists, updateIndexTs, updateCoreIndex } from '../../utils/fileUtils.js';
|
|
5
12
|
|
|
6
13
|
// Templates for CRUD base generation
|
|
@@ -11,7 +18,7 @@ const entityTemplate = `export interface I{{name}} {
|
|
|
11
18
|
\tupdated_at: string;
|
|
12
19
|
}`;
|
|
13
20
|
|
|
14
|
-
const portsIndexTemplate = `import type { I{{name}} } from '\${{context}}/domain/{{
|
|
21
|
+
const portsIndexTemplate = `import type { I{{name}} } from '\${{context}}/domain/{{entityLower}}/model';
|
|
15
22
|
|
|
16
23
|
export interface I{{name}}Collection {
|
|
17
24
|
\tdata: I{{name}}[];
|
|
@@ -41,7 +48,7 @@ import type {
|
|
|
41
48
|
\tI{{name}}CollectionQuery,
|
|
42
49
|
\tI{{name}}CreateRequest,
|
|
43
50
|
\tI{{name}}UpdateRequest
|
|
44
|
-
} from '\${{context}}/domain/{{
|
|
51
|
+
} from '\${{context}}/domain/{{entityLower}}';
|
|
45
52
|
|
|
46
53
|
export class {{name}}Repository {
|
|
47
54
|
\tprivate endpoint = '{{endpoint}}';
|
|
@@ -132,11 +139,12 @@ export default async function generateCrudBase() {
|
|
|
132
139
|
|
|
133
140
|
const pascalName = toPascalCase(name);
|
|
134
141
|
const camelName = toCamelCase(name);
|
|
142
|
+
const entityLower = toKebabCase(pascalName);
|
|
135
143
|
|
|
136
144
|
console.log('\nš Generating CRUD base (repository & service)...\n');
|
|
137
145
|
|
|
138
146
|
// 1. Create Domain structure
|
|
139
|
-
const domainPath = path.join(contextPath, 'domain',
|
|
147
|
+
const domainPath = path.join(contextPath, 'domain', entityLower);
|
|
140
148
|
const modelPath = path.join(domainPath, 'model');
|
|
141
149
|
const portsPath = path.join(domainPath, 'ports');
|
|
142
150
|
|
|
@@ -152,6 +160,7 @@ export default async function generateCrudBase() {
|
|
|
152
160
|
portsIndexTemplate
|
|
153
161
|
.replace(/{{name}}/g, pascalName)
|
|
154
162
|
.replace(/{{context}}/g, context)
|
|
163
|
+
.replace(/{{entityLower}}/g, entityLower)
|
|
155
164
|
);
|
|
156
165
|
|
|
157
166
|
// Create Domain module index
|
|
@@ -175,6 +184,7 @@ export default async function generateCrudBase() {
|
|
|
175
184
|
.replace(/{{datasource}}/g, datasource.name)
|
|
176
185
|
.replace(/{{datasourceImport}}/g, datasourceImport)
|
|
177
186
|
.replace(/{{datasourceVar}}/g, toCamelCase(datasource.name))
|
|
187
|
+
.replace(/{{entityLower}}/g, entityLower)
|
|
178
188
|
);
|
|
179
189
|
await updateIndexTs(repoPath);
|
|
180
190
|
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import prompts from 'prompts';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
selectContext,
|
|
5
|
+
getContextPath,
|
|
6
|
+
toPascalCase,
|
|
7
|
+
getAvailableFiles,
|
|
8
|
+
getApplicationProviderServices,
|
|
9
|
+
toKebabCase
|
|
10
|
+
} from '../../utils/contextUtils.js';
|
|
4
11
|
import { updateIndexTs, writeIfNotExists, updateCoreIndex } from '../../utils/fileUtils.js';
|
|
5
12
|
|
|
6
13
|
const createSchemaTemplate = `import { {{schemaFactory}} } from '{{schemaImport}}';
|
|
7
|
-
import type { I{{name}}CreateRequest } from '\${{context}}/domain/{{
|
|
14
|
+
import type { I{{name}}CreateRequest } from '\${{context}}/domain/{{entityLower}}';
|
|
8
15
|
|
|
9
16
|
export const Create{{name}}Schema = {{schemaFactory}}<I{{name}}CreateRequest>()
|
|
10
17
|
\t.rules((rules) => ({
|
|
@@ -13,7 +20,7 @@ export const Create{{name}}Schema = {{schemaFactory}}<I{{name}}CreateRequest>()
|
|
|
13
20
|
\t.create();`;
|
|
14
21
|
|
|
15
22
|
const updateSchemaTemplate = `import { {{schemaFactory}} } from '{{schemaImport}}';
|
|
16
|
-
import type { I{{name}}UpdateRequest } from '\${{context}}/domain/{{
|
|
23
|
+
import type { I{{name}}UpdateRequest } from '\${{context}}/domain/{{entityLower}}';
|
|
17
24
|
|
|
18
25
|
export const Update{{name}}Schema = {{schemaFactory}}<I{{name}}UpdateRequest>()
|
|
19
26
|
\t.rules((rules) => ({
|
|
@@ -28,7 +35,7 @@ import type {
|
|
|
28
35
|
\tI{{name}}CollectionQuery,
|
|
29
36
|
\tI{{name}}CreateRequest,
|
|
30
37
|
\tI{{name}}UpdateRequest
|
|
31
|
-
} from '\${{context}}/domain/{{
|
|
38
|
+
} from '\${{context}}/domain/{{entityLower}}';
|
|
32
39
|
|
|
33
40
|
export const {{name}}Presenter = {{presenterFactory}}('{{name}}Presenter', ({ createAsyncResource, createAsyncAction }) => {
|
|
34
41
|
\tconst { {{serviceName}} } = ApplicationProvider();
|
|
@@ -58,7 +65,7 @@ import type {
|
|
|
58
65
|
\tI{{name}}CollectionQuery,
|
|
59
66
|
\tI{{name}}CreateRequest,
|
|
60
67
|
\tI{{name}}UpdateRequest
|
|
61
|
-
} from '\${{context}}/domain/{{
|
|
68
|
+
} from '\${{context}}/domain/{{entityLower}}';
|
|
62
69
|
|
|
63
70
|
export const {{name}}Presenter = createPresenter('{{name}}Presenter', () => {
|
|
64
71
|
\tconst { {{serviceName}} } = ApplicationProvider();
|
|
@@ -102,6 +109,7 @@ export default async function generateCrudPresenter() {
|
|
|
102
109
|
// Extract entity name from service name
|
|
103
110
|
const entityName = service.replace('Service', '');
|
|
104
111
|
const pascalName = toPascalCase(entityName);
|
|
112
|
+
const entityLower = toKebabCase(pascalName);
|
|
105
113
|
|
|
106
114
|
// Get schema factory
|
|
107
115
|
const coreSchemas = await getAvailableFiles(
|
|
@@ -134,7 +142,7 @@ export default async function generateCrudPresenter() {
|
|
|
134
142
|
});
|
|
135
143
|
|
|
136
144
|
const contextPath = getContextPath(context);
|
|
137
|
-
const deliveryModulePath = path.join(contextPath, 'delivery',
|
|
145
|
+
const deliveryModulePath = path.join(contextPath, 'delivery', entityLower);
|
|
138
146
|
const schemaPath = path.join(deliveryModulePath, 'schema');
|
|
139
147
|
|
|
140
148
|
console.log('\nš Generating CRUD presenter...\n');
|
|
@@ -157,7 +165,7 @@ const Schema = createSchemaFactory(createRules(validationMessagesI18n));`;
|
|
|
157
165
|
.replace('import { {{schemaFactory}} } from \'{{schemaImport}}\';\n', '')
|
|
158
166
|
.replace(/{{name}}/g, pascalName)
|
|
159
167
|
.replace(/{{context}}/g, context)
|
|
160
|
-
.replace(/{{
|
|
168
|
+
.replace(/{{entityLower}}/g, entityLower)
|
|
161
169
|
.replace(/{{schemaFactory}}/g, 'Schema')
|
|
162
170
|
);
|
|
163
171
|
|
|
@@ -167,7 +175,7 @@ const Schema = createSchemaFactory(createRules(validationMessagesI18n));`;
|
|
|
167
175
|
.replace('import { {{schemaFactory}} } from \'{{schemaImport}}\';\n', '')
|
|
168
176
|
.replace(/{{name}}/g, pascalName)
|
|
169
177
|
.replace(/{{context}}/g, context)
|
|
170
|
-
.replace(/{{
|
|
178
|
+
.replace(/{{entityLower}}/g, entityLower)
|
|
171
179
|
.replace(/{{schemaFactory}}/g, 'Schema')
|
|
172
180
|
);
|
|
173
181
|
} else {
|
|
@@ -176,7 +184,7 @@ const Schema = createSchemaFactory(createRules(validationMessagesI18n));`;
|
|
|
176
184
|
createSchemaTemplate
|
|
177
185
|
.replace(/{{name}}/g, pascalName)
|
|
178
186
|
.replace(/{{context}}/g, context)
|
|
179
|
-
.replace(/{{
|
|
187
|
+
.replace(/{{entityLower}}/g, entityLower)
|
|
180
188
|
.replace(/{{schemaFactory}}/g, schemaFactory)
|
|
181
189
|
.replace(/{{schemaImport}}/g, schemaImport)
|
|
182
190
|
);
|
|
@@ -186,7 +194,7 @@ const Schema = createSchemaFactory(createRules(validationMessagesI18n));`;
|
|
|
186
194
|
updateSchemaTemplate
|
|
187
195
|
.replace(/{{name}}/g, pascalName)
|
|
188
196
|
.replace(/{{context}}/g, context)
|
|
189
|
-
.replace(/{{
|
|
197
|
+
.replace(/{{entityLower}}/g, entityLower)
|
|
190
198
|
.replace(/{{schemaFactory}}/g, schemaFactory)
|
|
191
199
|
.replace(/{{schemaImport}}/g, schemaImport)
|
|
192
200
|
);
|
|
@@ -207,6 +215,7 @@ const Schema = createSchemaFactory(createRules(validationMessagesI18n));`;
|
|
|
207
215
|
.replace(/{{context}}/g, context)
|
|
208
216
|
.replace(/{{serviceName}}/g, service)
|
|
209
217
|
.replace(/{{presenterFactory}}/g, presenterFactory)
|
|
218
|
+
.replace(/{{entityLower}}/g, entityLower)
|
|
210
219
|
);
|
|
211
220
|
|
|
212
221
|
// Create module index
|
|
@@ -58,8 +58,9 @@ export default async function generatePresenter() {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
const pascalName = toPascalCase(name);
|
|
61
|
+
const moduleLower = pascalName.toLowerCase();
|
|
61
62
|
const contextPath = getContextPath(context);
|
|
62
|
-
const modulePath = path.join(contextPath, 'delivery',
|
|
63
|
+
const modulePath = path.join(contextPath, 'delivery', moduleLower);
|
|
63
64
|
const filePath = path.join(modulePath, `${pascalName}Presenter.ts`);
|
|
64
65
|
|
|
65
66
|
const content = presenterType === 'package'
|
|
@@ -5,7 +5,7 @@ import { selectContext, getContextPath, toPascalCase, getAvailableFiles } from '
|
|
|
5
5
|
import { writeIfNotExists, updateIndexTs } from '../../utils/fileUtils.js';
|
|
6
6
|
|
|
7
7
|
const schemaWithCoreTemplate = `import { {{coreSchema}} } from '\$core/schemas';
|
|
8
|
-
import type { I{{name}}Request } from '\${{context}}/domain/{{
|
|
8
|
+
import type { I{{name}}Request } from '\${{context}}/domain/{{entityLower}}';
|
|
9
9
|
|
|
10
10
|
export const {{name}}Schema = {{coreSchema}}<I{{name}}Request>()
|
|
11
11
|
\t.rules((rules) => ({
|
|
@@ -15,7 +15,7 @@ export const {{name}}Schema = {{coreSchema}}<I{{name}}Request>()
|
|
|
15
15
|
|
|
16
16
|
const schemaWithPackageTemplate = `import { createSchemaFactory } from '@azure-net/kit';
|
|
17
17
|
import { createRules, validationMessagesI18n } from '@azure-net/kit/schema';
|
|
18
|
-
import type { I{{name}}Request } from '\${{context}}/domain/{{
|
|
18
|
+
import type { I{{name}}Request } from '\${{context}}/domain/{{entityLower}}';
|
|
19
19
|
|
|
20
20
|
const Schema = createSchemaFactory(createRules(validationMessagesI18n));
|
|
21
21
|
|
|
@@ -64,26 +64,28 @@ export default async function generateSchema() {
|
|
|
64
64
|
|
|
65
65
|
const pascalName = toPascalCase(name);
|
|
66
66
|
const moduleName = toPascalCase(module);
|
|
67
|
+
const moduleLower = moduleName.toLowerCase();
|
|
68
|
+
const entityLower = moduleName.toLowerCase();
|
|
67
69
|
const contextPath = getContextPath(context);
|
|
68
|
-
const schemaPath = path.join(contextPath, 'delivery',
|
|
70
|
+
const schemaPath = path.join(contextPath, 'delivery', moduleLower, 'schema');
|
|
69
71
|
const filePath = path.join(schemaPath, `${pascalName}Schema.ts`);
|
|
70
72
|
|
|
71
73
|
const content = schemaType === 'package'
|
|
72
74
|
? schemaWithPackageTemplate
|
|
73
75
|
.replace(/{{name}}/g, pascalName)
|
|
74
76
|
.replace(/{{context}}/g, context)
|
|
75
|
-
.replace(/{{
|
|
77
|
+
.replace(/{{entityLower}}/g, entityLower)
|
|
76
78
|
: schemaWithCoreTemplate
|
|
77
79
|
.replace(/{{name}}/g, pascalName)
|
|
78
80
|
.replace(/{{context}}/g, context)
|
|
79
|
-
.replace(/{{
|
|
81
|
+
.replace(/{{entityLower}}/g, entityLower)
|
|
80
82
|
.replace(/{{coreSchema}}/g, schemaType);
|
|
81
83
|
|
|
82
84
|
await writeIfNotExists(filePath, content);
|
|
83
85
|
await updateIndexTs(schemaPath);
|
|
84
86
|
|
|
85
87
|
// Update module index
|
|
86
|
-
const moduleIndexPath = path.join(contextPath, 'delivery',
|
|
88
|
+
const moduleIndexPath = path.join(contextPath, 'delivery', moduleLower, 'index.ts');
|
|
87
89
|
if (await fs.access(moduleIndexPath).then(() => true).catch(() => false)) {
|
|
88
90
|
let indexContent = await fs.readFile(moduleIndexPath, 'utf-8');
|
|
89
91
|
if (!indexContent.includes(`export * from './schema'`)) {
|
|
@@ -72,3 +72,10 @@ export function toCamelCase(str) {
|
|
|
72
72
|
const pascal = toPascalCase(str);
|
|
73
73
|
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
74
74
|
}
|
|
75
|
+
|
|
76
|
+
export function toKebabCase(str) {
|
|
77
|
+
return str
|
|
78
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
79
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
|
|
80
|
+
.toLowerCase();
|
|
81
|
+
}
|