@azure-net/cli 2.0.1 → 2.0.3

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": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "azure-net": "bin/azure-net.js"
@@ -13,7 +13,9 @@ const entityTemplate = `export interface I{{name}} {
13
13
  \tupdated_at: string;
14
14
  }`;
15
15
 
16
- const portsIndexTemplate = `export interface I{{name}}Collection {
16
+ const portsIndexTemplate = `import type { I{{name}} } from '../../Entities/{{name}}';
17
+
18
+ export interface I{{name}}Collection {
17
19
  \tdata: I{{name}}[];
18
20
  \ttotal: number;
19
21
  }
@@ -33,13 +35,13 @@ export interface I{{name}}UpdateRequest {
33
35
  }`;
34
36
 
35
37
  const repositoryTemplate = `import { {{datasource}} } from '{{datasourceImport}}';
36
- import type { I{{name}} } from '${{context}}/Domain/Entities/{{name}}';
38
+ import type { I{{name}} } from '\${{context}}/Domain/Entities/{{name}}';
37
39
  import type {
38
40
  \tI{{name}}Collection,
39
41
  \tI{{name}}CollectionQuery,
40
42
  \tI{{name}}CreateRequest,
41
43
  \tI{{name}}UpdateRequest
42
- } from '${{context}}/Domain/Ports/{{name}}';
44
+ } from '\${{context}}/Domain/Ports/{{name}}';
43
45
 
44
46
  export class {{name}}Repository {
45
47
  \tprivate endpoint = '{{endpoint}}';
@@ -93,7 +95,7 @@ export class {{name}}Service extends ClassMirror<{{name}}Repository> {
93
95
  }`;
94
96
 
95
97
  const createSchemaTemplate = `import { {{schemaFactory}} } from '{{schemaImport}}';
96
- import type { I{{name}}CreateRequest } from '${{context}}/Domain/Ports/{{name}}';
98
+ import type { I{{name}}CreateRequest } from '\${{context}}/Domain/Ports/{{name}}';
97
99
 
98
100
  export const Create{{name}}Schema = {{schemaFactory}}<I{{name}}CreateRequest>()
99
101
  \t.rules((rules) => ({
@@ -102,7 +104,7 @@ export const Create{{name}}Schema = {{schemaFactory}}<I{{name}}CreateRequest>()
102
104
  \t.create();`;
103
105
 
104
106
  const updateSchemaTemplate = `import { {{schemaFactory}} } from '{{schemaImport}}';
105
- import type { I{{name}}UpdateRequest } from '${{context}}/Domain/Ports/{{name}}';
107
+ import type { I{{name}}UpdateRequest } from '\${{context}}/Domain/Ports/{{name}}';
106
108
 
107
109
  export const Update{{name}}Schema = {{schemaFactory}}<I{{name}}UpdateRequest>()
108
110
  \t.rules((rules) => ({
@@ -111,13 +113,13 @@ export const Update{{name}}Schema = {{schemaFactory}}<I{{name}}UpdateRequest>()
111
113
  \t.create();`;
112
114
 
113
115
  const presenterTemplate = `import { {{presenterFactory}} } from '{{presenterImport}}';
114
- import { ApplicationProvider } from '${{context}}/Application';
116
+ import { ApplicationProvider } from '\${{context}}/Application';
115
117
  import { Create{{name}}Schema, Update{{name}}Schema } from './Schema';
116
118
  import type {
117
119
  \tI{{name}}CollectionQuery,
118
120
  \tI{{name}}CreateRequest,
119
121
  \tI{{name}}UpdateRequest
120
- } from '${{context}}/Domain/Ports/{{name}}';
122
+ } from '\${{context}}/Domain/Ports/{{name}}';
121
123
 
122
124
  export const {{name}}Presenter = {{presenterFactory}}('{{name}}Presenter', ({ createAsyncResource, createAsyncAction }) => {
123
125
  \tconst { {{name}}Service } = ApplicationProvider();
@@ -236,7 +238,7 @@ export default async function generateCrud() {
236
238
  const repoPath = path.join(contextPath, 'Infrastructure', 'Http', 'Repositories');
237
239
  const datasourceImport = datasource.from === 'core'
238
240
  ? '$core/Datasource'
239
- : `$${context}/Infrastructure/Http/Datasource`;
241
+ : `\$${context}/Infrastructure/Http/Datasource`;
240
242
 
241
243
  await writeIfNotExists(
242
244
  path.join(repoPath, `${pascalName}Repository.ts`),
@@ -265,28 +267,54 @@ export default async function generateCrud() {
265
267
  const schemaPath = path.join(deliveryModulePath, 'Schema');
266
268
 
267
269
  // Create schemas
268
- const schemaFactory = schemaType === 'package' ? 'createSchemaFactory' : schemaType;
270
+ const schemaFactory = schemaType === 'package' ? 'Schema' : schemaType;
269
271
  const schemaImport = schemaType === 'package'
270
272
  ? '@azure-net/kit'
271
273
  : '$core/Schema';
272
274
 
273
- await writeIfNotExists(
274
- path.join(schemaPath, `Create${pascalName}Schema.ts`),
275
- createSchemaTemplate
276
- .replace(/{{name}}/g, pascalName)
277
- .replace(/{{context}}/g, context)
278
- .replace(/{{schemaFactory}}/g, schemaFactory)
279
- .replace(/{{schemaImport}}/g, schemaImport)
280
- );
281
-
282
- await writeIfNotExists(
283
- path.join(schemaPath, `Update${pascalName}Schema.ts`),
284
- updateSchemaTemplate
285
- .replace(/{{name}}/g, pascalName)
286
- .replace(/{{context}}/g, context)
287
- .replace(/{{schemaFactory}}/g, schemaFactory)
288
- .replace(/{{schemaImport}}/g, schemaImport)
289
- );
275
+ if (schemaType === 'package') {
276
+ // Add the import for createSchemaFactory and rules
277
+ const schemaImportFull = `import { createSchemaFactory } from '@azure-net/kit';
278
+ import { createRules, validationMessagesI18n } from '@azure-net/kit/schema';
279
+
280
+ const Schema = createSchemaFactory(createRules(validationMessagesI18n));`;
281
+
282
+ await writeIfNotExists(
283
+ path.join(schemaPath, `Create${pascalName}Schema.ts`),
284
+ schemaImportFull + '\n' + createSchemaTemplate
285
+ .replace('import { {{schemaFactory}} } from \'{{schemaImport}}\';\n', '')
286
+ .replace(/{{name}}/g, pascalName)
287
+ .replace(/{{context}}/g, context)
288
+ .replace(/{{schemaFactory}}/g, 'Schema')
289
+ );
290
+
291
+ await writeIfNotExists(
292
+ path.join(schemaPath, `Update${pascalName}Schema.ts`),
293
+ schemaImportFull + '\n' + updateSchemaTemplate
294
+ .replace('import { {{schemaFactory}} } from \'{{schemaImport}}\';\n', '')
295
+ .replace(/{{name}}/g, pascalName)
296
+ .replace(/{{context}}/g, context)
297
+ .replace(/{{schemaFactory}}/g, 'Schema')
298
+ );
299
+ } else {
300
+ await writeIfNotExists(
301
+ path.join(schemaPath, `Create${pascalName}Schema.ts`),
302
+ createSchemaTemplate
303
+ .replace(/{{name}}/g, pascalName)
304
+ .replace(/{{context}}/g, context)
305
+ .replace(/{{schemaFactory}}/g, schemaFactory)
306
+ .replace(/{{schemaImport}}/g, schemaImport)
307
+ );
308
+
309
+ await writeIfNotExists(
310
+ path.join(schemaPath, `Update${pascalName}Schema.ts`),
311
+ updateSchemaTemplate
312
+ .replace(/{{name}}/g, pascalName)
313
+ .replace(/{{context}}/g, context)
314
+ .replace(/{{schemaFactory}}/g, schemaFactory)
315
+ .replace(/{{schemaImport}}/g, schemaImport)
316
+ );
317
+ }
290
318
  await updateIndexTs(schemaPath);
291
319
 
292
320
  // 6. Create Presenter
@@ -3,7 +3,7 @@ import path from 'path';
3
3
  import { selectContext, getContextPath, toPascalCase, getAvailableFiles } from '../../utils/contextUtils.js';
4
4
  import { writeIfNotExists, updateIndexTs } from '../../utils/fileUtils.js';
5
5
 
6
- const presenterWithCoreTemplate = `import { {{corePresenter}} } from '$core/Presenter';
6
+ const presenterWithCoreTemplate = `import { {{corePresenter}} } from '\$core/Presenter';
7
7
  {{serviceImport}}
8
8
 
9
9
  export const {{name}}Presenter = {{corePresenter}}('{{name}}Presenter', ({ createAsyncResource, createAsyncAction }) => {
@@ -85,7 +85,7 @@ export default async function generatePresenter() {
85
85
  const filePath = path.join(modulePath, `${pascalName}Presenter.ts`);
86
86
 
87
87
  const serviceImport = service
88
- ? `import { ApplicationProvider } from '$${context}/Application';`
88
+ ? `import { ApplicationProvider } from '\$${context}/Application';`
89
89
  : '';
90
90
 
91
91
  const serviceInit = service
@@ -1,10 +1,11 @@
1
1
  import prompts from 'prompts';
2
2
  import path from 'path';
3
+ import fs from 'fs/promises';
3
4
  import { selectContext, getContextPath, toPascalCase, getAvailableFiles } from '../../utils/contextUtils.js';
4
5
  import { writeIfNotExists, updateIndexTs } from '../../utils/fileUtils.js';
5
6
 
6
- const schemaWithCoreTemplate = `import { {{coreSchema}} } from '$core/Schema';
7
- import type { I{{name}}Request } from '${{context}}/Domain/Ports/{{entity}}';
7
+ const schemaWithCoreTemplate = `import { {{coreSchema}} } from '\$core/Schema';
8
+ import type { I{{name}}Request } from '\${{context}}/Domain/Ports/{{entity}}';
8
9
 
9
10
  export const {{name}}Schema = {{coreSchema}}<I{{name}}Request>()
10
11
  \t.rules((rules) => ({
@@ -14,7 +15,7 @@ export const {{name}}Schema = {{coreSchema}}<I{{name}}Request>()
14
15
 
15
16
  const schemaWithPackageTemplate = `import { createSchemaFactory } from '@azure-net/kit';
16
17
  import { createRules, validationMessagesI18n } from '@azure-net/kit/schema';
17
- import type { I{{name}}Request } from '${{context}}/Domain/Ports/{{entity}}';
18
+ import type { I{{name}}Request } from '\${{context}}/Domain/Ports/{{entity}}';
18
19
 
19
20
  const Schema = createSchemaFactory(createRules(validationMessagesI18n));
20
21
 
@@ -6,7 +6,7 @@ import { writeIfNotExists, updateIndexTs } from '../../utils/fileUtils.js';
6
6
  import { ensureProvider, addToProvider } from '../../utils/providerUtils.js';
7
7
 
8
8
  const serviceTemplate = `import { ClassMirror } from '@azure-net/kit';
9
- import { {{repository}} } from '../../Infrastructure/Repositories/index.js';
9
+ import { {{repository}} } from '../../Infrastructure/Http/Repositories';
10
10
 
11
11
  export class {{name}}Service extends ClassMirror<{{repository}}> {
12
12
  \tconstructor(private {{repositoryVar}}: {{repository}}) {
@@ -42,12 +42,12 @@ export default async function generateService() {
42
42
  // Get available repositories
43
43
  const contextPath = getContextPath(context);
44
44
  const repositories = await getAvailableFiles(
45
- path.join(contextPath, 'Infrastructure', 'Repositories')
45
+ path.join(contextPath, 'Infrastructure', 'Http', 'Repositories')
46
46
  );
47
47
 
48
48
  const choices = [
49
49
  { title: 'Without repository', value: null },
50
- ...repositories.map(r => ({ title: `${r}Repository`, value: `${r}Repository` }))
50
+ ...repositories.map(r => ({ title: `${r}`, value: r }))
51
51
  ];
52
52
 
53
53
  const { repository } = await prompts({
@@ -74,19 +74,20 @@ export default async function generateService() {
74
74
 
75
75
  // Ensure ApplicationProvider exists and add service
76
76
  const appProvider = await ensureProvider(context, 'Application', { infrastructure: true });
77
- await addToProvider(
78
- appProvider.path,
79
- `${pascalName}Service`,
80
- '../Services/index.js'
81
- );
82
77
 
83
- // Add repository dependency if selected
84
78
  if (repository) {
85
- let providerContent = await fs.readFile(appProvider.path, 'utf-8');
86
- const serviceFactory = `${pascalName}Service: () => new ${pascalName}Service()`;
87
- const serviceWithRepo = `${pascalName}Service: () => new ${pascalName}Service(InfrastructureProvider.${repository})`;
88
- providerContent = providerContent.replace(serviceFactory, serviceWithRepo);
89
- await fs.writeFile(appProvider.path, providerContent, 'utf-8');
79
+ await addToProvider(
80
+ appProvider.path,
81
+ `${pascalName}Service`,
82
+ '../Services',
83
+ `InfrastructureProvider.${repository}`
84
+ );
85
+ } else {
86
+ await addToProvider(
87
+ appProvider.path,
88
+ `${pascalName}Service`,
89
+ '../Services'
90
+ );
90
91
  }
91
92
 
92
93
  console.log(`✅ Service created at ${filePath}`);
@@ -1,7 +1,7 @@
1
1
  import { writeIfNotExists } from '../../utils/fileUtils.js';
2
2
  import path from 'path';
3
3
 
4
- const schemaPath = path.join(process.cwd(), 'src/app/core/Schemas/Schema.ts');
4
+ const schemaPath = path.join(process.cwd(), 'src/app/core/Schema/Schema.ts');
5
5
 
6
6
  const schemaTemplate = `import { createSchemaFactory } from '@azure-net/kit';
7
7
  import { createRules, validationMessagesI18n } from '@azure-net/kit/schema';
@@ -11,7 +11,7 @@ export const Schema = createSchemaFactory(createRules(validationMessagesI18n));`
11
11
  export default async function initSchema() {
12
12
  await writeIfNotExists(schemaPath, schemaTemplate);
13
13
  await writeIfNotExists(
14
- path.join(process.cwd(), 'src/app/core/Schemas/index.ts'),
14
+ path.join(process.cwd(), 'src/app/core/Schema/index.ts'),
15
15
  `export * from './Schema';`
16
16
  );
17
17
 
@@ -43,7 +43,7 @@ function generateProviderContent(context, layer, dependencies) {
43
43
  }
44
44
 
45
45
  if (dependencies.infrastructure && layer === 'Application') {
46
- imports.push(`import { InfrastructureProvider } from '$${context}/Infrastructure';`);
46
+ imports.push(`import { InfrastructureProvider } from '\$${context}/Infrastructure';`);
47
47
  deps.push('InfrastructureProvider');
48
48
  }
49
49