@azure-net/cli 2.0.0 → 2.0.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 +7 -1
- package/package.json +1 -1
- package/src/commands/generate/generateCrud.js +146 -91
- package/src/commands/generate/generateDatasource.js +10 -5
- package/src/commands/generate/generatePresenter.js +14 -14
- package/src/commands/generate/generateRepository.js +25 -20
- package/src/commands/generate/generateSchema.js +35 -9
- package/src/commands/generate/generateService.js +15 -14
- package/src/commands/init/index.js +2 -1
- package/src/commands/init/initLint.js +138 -0
- package/src/commands/init/initMiddleware.js +9 -24
- package/src/commands/init/initSchema.js +2 -2
- package/src/commands/init/initStructure.js +40 -29
- package/src/commands/init/initTranslations.js +14 -9
- package/src/utils/fileUtils.js +20 -1
- package/src/utils/providerUtils.js +49 -20
|
@@ -4,7 +4,10 @@ import { toPascalCase, toCamelCase } from './contextUtils.js';
|
|
|
4
4
|
import { writeIfNotExists, updateIndexTs } from './fileUtils.js';
|
|
5
5
|
|
|
6
6
|
export async function ensureProvider(context, layer, dependencies = {}) {
|
|
7
|
-
const
|
|
7
|
+
const contextName = toPascalCase(context);
|
|
8
|
+
const providerName = `${layer}Provider`;
|
|
9
|
+
const boundaryName = `${contextName}${layer}BoundaryProvider`;
|
|
10
|
+
|
|
8
11
|
const contextPath = path.join(process.cwd(), 'src/app/contexts', context);
|
|
9
12
|
const providerPath = path.join(contextPath, layer, 'Providers', `${layer}Provider.ts`);
|
|
10
13
|
|
|
@@ -16,29 +19,38 @@ export async function ensureProvider(context, layer, dependencies = {}) {
|
|
|
16
19
|
const content = generateProviderContent(context, layer, dependencies);
|
|
17
20
|
await writeIfNotExists(providerPath, content);
|
|
18
21
|
await updateIndexTs(path.dirname(providerPath));
|
|
19
|
-
|
|
22
|
+
|
|
23
|
+
// Update layer index to export provider
|
|
24
|
+
const layerIndexPath = path.join(contextPath, layer, 'index.ts');
|
|
25
|
+
await writeIfNotExists(layerIndexPath, `export { ${providerName} } from './Providers';`);
|
|
26
|
+
|
|
20
27
|
return { exists: false, name: providerName, path: providerPath };
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
function generateProviderContent(context, layer, dependencies) {
|
|
25
|
-
const
|
|
32
|
+
const contextName = toPascalCase(context);
|
|
33
|
+
const boundaryName = `${contextName}${layer}BoundaryProvider`;
|
|
26
34
|
const varName = `${layer}Provider`;
|
|
27
35
|
|
|
28
36
|
let imports = [`import { createBoundaryProvider } from '@azure-net/kit';`];
|
|
29
37
|
let deps = [];
|
|
30
|
-
let
|
|
38
|
+
let depParams = '';
|
|
31
39
|
|
|
32
|
-
if (dependencies.
|
|
33
|
-
imports.push(`import {
|
|
34
|
-
|
|
40
|
+
if (dependencies.hasDatasource && layer === 'Infrastructure') {
|
|
41
|
+
imports.push(`import { DatasourceProvider } from './DatasourceProvider';`);
|
|
42
|
+
deps.push('DatasourceProvider');
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
if (dependencies.infrastructure && layer === 'Application') {
|
|
38
|
-
imports.push(`import { InfrastructureProvider } from '
|
|
46
|
+
imports.push(`import { InfrastructureProvider } from '\$${context}/Infrastructure';`);
|
|
39
47
|
deps.push('InfrastructureProvider');
|
|
40
48
|
}
|
|
41
49
|
|
|
50
|
+
if (deps.length > 0) {
|
|
51
|
+
depParams = `{ ${deps.join(', ')} }`;
|
|
52
|
+
}
|
|
53
|
+
|
|
42
54
|
const dependsOnStr = deps.length > 0
|
|
43
55
|
? `,\n\t{ dependsOn: { ${deps.join(', ')} } }`
|
|
44
56
|
: '';
|
|
@@ -46,32 +58,49 @@ function generateProviderContent(context, layer, dependencies) {
|
|
|
46
58
|
return `${imports.join('\n')}
|
|
47
59
|
|
|
48
60
|
export const ${varName} = createBoundaryProvider(
|
|
49
|
-
\t'${
|
|
50
|
-
\t(${
|
|
51
|
-
|
|
61
|
+
\t'${boundaryName}',
|
|
62
|
+
\t(${depParams ? depParams : ''}) => ({
|
|
63
|
+
\t\t// Services will be added here
|
|
52
64
|
\t})${dependsOnStr}
|
|
53
65
|
);`;
|
|
54
66
|
}
|
|
55
67
|
|
|
56
|
-
export async function addToProvider(providerPath, serviceName, importPath) {
|
|
68
|
+
export async function addToProvider(providerPath, serviceName, importPath, dependency = null) {
|
|
57
69
|
let content = await fs.readFile(providerPath, 'utf-8');
|
|
58
70
|
|
|
59
71
|
// Add import if not exists
|
|
60
72
|
const importStatement = `import { ${serviceName} } from '${importPath}';`;
|
|
61
|
-
if (!content.includes(
|
|
73
|
+
if (!content.includes(serviceName)) {
|
|
62
74
|
const lastImportIndex = content.lastIndexOf('import ');
|
|
63
75
|
const endOfImportLine = content.indexOf('\n', lastImportIndex);
|
|
64
76
|
content = content.slice(0, endOfImportLine + 1) + importStatement + '\n' + content.slice(endOfImportLine + 1);
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
// Add factory method
|
|
68
|
-
const factoryLine =
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
// Add factory method with dependency
|
|
80
|
+
const factoryLine = dependency
|
|
81
|
+
? `\t\t${serviceName}: () => new ${serviceName}(${dependency})`
|
|
82
|
+
: `\t\t${serviceName}: () => new ${serviceName}()`;
|
|
83
|
+
|
|
84
|
+
if (!content.includes(`${serviceName}:`)) {
|
|
85
|
+
// Find the position to insert
|
|
86
|
+
const returnIndex = content.indexOf('=> ({');
|
|
87
|
+
const endOfReturn = content.indexOf('\t})', returnIndex);
|
|
88
|
+
|
|
89
|
+
// Check if there are existing services
|
|
90
|
+
const servicesSection = content.substring(returnIndex, endOfReturn);
|
|
91
|
+
const hasServices = servicesSection.includes(':');
|
|
71
92
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
93
|
+
if (hasServices) {
|
|
94
|
+
// Add comma before new service
|
|
95
|
+
const beforeEnd = content.lastIndexOf('\n', endOfReturn);
|
|
96
|
+
content = content.slice(0, beforeEnd) + ',\n' + factoryLine + content.slice(beforeEnd);
|
|
97
|
+
} else {
|
|
98
|
+
// First service, replace comment
|
|
99
|
+
content = content.replace(
|
|
100
|
+
'// Services will be added here',
|
|
101
|
+
factoryLine
|
|
102
|
+
);
|
|
103
|
+
}
|
|
75
104
|
}
|
|
76
105
|
|
|
77
106
|
await fs.writeFile(providerPath, content, 'utf-8');
|