@alevnyacow/nzmt 0.3.3 → 0.5.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/bin/cli.js +96 -2
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -127,10 +127,12 @@ function initDI() {
|
|
|
127
127
|
"",
|
|
128
128
|
"type DIEntries = Record<",
|
|
129
129
|
"\tstring,",
|
|
130
|
+
"\t| { constantValue: object }",
|
|
130
131
|
"\t| (new (...args: any[]) => any)",
|
|
131
132
|
"\t| Record<'test' | 'dev' | 'prod',",
|
|
132
133
|
"\t\t| [new (...args: any[]) => any, (x: BindInWhenOnFluentSyntax<unknown>) => any]",
|
|
133
134
|
"\t\t| (new (...args: any[]) => any)",
|
|
135
|
+
"\t\t| { constantValue: object }",
|
|
134
136
|
"\t>",
|
|
135
137
|
">",
|
|
136
138
|
"",
|
|
@@ -154,6 +156,10 @@ function initDI() {
|
|
|
154
156
|
"",
|
|
155
157
|
"for (const rule in diEntries) {",
|
|
156
158
|
"\tconst ruleContentRaw = diEntries[rule as keyof typeof diEntries]",
|
|
159
|
+
"\tif ('constantValue' in ruleContentRaw) {",
|
|
160
|
+
"\t\tcontainer.bind(rule).toConstantValue(ruleContentRaw.constantValue)",
|
|
161
|
+
"\t\tcontinue",
|
|
162
|
+
"\t}",
|
|
157
163
|
"\tconst ruleContent =",
|
|
158
164
|
"\t\ttypeof ruleContentRaw === 'object'",
|
|
159
165
|
"\t\t\t? ruleContentRaw.dev",
|
|
@@ -163,6 +169,10 @@ function initDI() {
|
|
|
163
169
|
"\t\tbuilder(container.bind(rule).to(Entry))",
|
|
164
170
|
"\t\tcontinue",
|
|
165
171
|
"\t}",
|
|
172
|
+
"\tif ('constantValue' in ruleContent) {",
|
|
173
|
+
"\t\tcontainer.bind(rule).toConstantValue(ruleContent.constantValue)",
|
|
174
|
+
"\t\tcontinue",
|
|
175
|
+
"\t}",
|
|
166
176
|
"\tcontainer.bind(rule).to(ruleContent)",
|
|
167
177
|
"}",
|
|
168
178
|
"",
|
|
@@ -177,6 +187,10 @@ function initDI() {
|
|
|
177
187
|
"",
|
|
178
188
|
"for (const rule in diEntries) {",
|
|
179
189
|
"\tconst ruleContentRaw = diEntries[rule as keyof typeof diEntries]",
|
|
190
|
+
"\tif ('constantValue' in ruleContentRaw) {",
|
|
191
|
+
"\t\tcontainer.bind(rule).toConstantValue(ruleContentRaw.constantValue)",
|
|
192
|
+
"\t\tcontinue",
|
|
193
|
+
"\t}",
|
|
180
194
|
"\tconst ruleContent =",
|
|
181
195
|
"\t\ttypeof ruleContentRaw === 'object'",
|
|
182
196
|
"\t\t\t? ruleContentRaw.test",
|
|
@@ -186,6 +200,10 @@ function initDI() {
|
|
|
186
200
|
"\t\tbuilder(container.bind(rule).to(Entry))",
|
|
187
201
|
"\t\tcontinue",
|
|
188
202
|
"\t}",
|
|
203
|
+
"\tif ('constantValue' in ruleContent) {",
|
|
204
|
+
"\t\tcontainer.bind(rule).toConstantValue(ruleContent.constantValue)",
|
|
205
|
+
"\t\tcontinue",
|
|
206
|
+
"\t}",
|
|
189
207
|
"\tcontainer.bind(rule).to(ruleContent)",
|
|
190
208
|
"}",
|
|
191
209
|
"",
|
|
@@ -200,6 +218,10 @@ function initDI() {
|
|
|
200
218
|
"",
|
|
201
219
|
"for (const rule in diEntries) {",
|
|
202
220
|
"\tconst ruleContentRaw = diEntries[rule as keyof typeof diEntries]",
|
|
221
|
+
"\tif ('constantValue' in ruleContentRaw) {",
|
|
222
|
+
"\t\tcontainer.bind(rule).toConstantValue(ruleContentRaw.constantValue)",
|
|
223
|
+
"\t\tcontinue",
|
|
224
|
+
"\t}",
|
|
203
225
|
"\tconst ruleContent =",
|
|
204
226
|
"\t\ttypeof ruleContentRaw === 'object'",
|
|
205
227
|
"\t\t\t? ruleContentRaw.prod",
|
|
@@ -209,6 +231,10 @@ function initDI() {
|
|
|
209
231
|
"\t\tbuilder(container.bind(rule).to(Entry))",
|
|
210
232
|
"\t\tcontinue",
|
|
211
233
|
"\t}",
|
|
234
|
+
"\tif ('constantValue' in ruleContent) {",
|
|
235
|
+
"\t\tcontainer.bind(rule).toConstantValue(ruleContent.constantValue)",
|
|
236
|
+
"\t\tcontinue",
|
|
237
|
+
"\t}",
|
|
212
238
|
"\tcontainer.bind(rule).to(ruleContent)",
|
|
213
239
|
"}",
|
|
214
240
|
"",
|
|
@@ -439,7 +465,7 @@ if (command.toLowerCase() === 'store' || command === 's') {
|
|
|
439
465
|
|
|
440
466
|
function generateEntity(upperCase) {
|
|
441
467
|
const folder = config?.paths?.entities ? path.resolve(process.cwd(), config?.paths?.entities, entityName) : path.resolve(process.cwd(), entityName);
|
|
442
|
-
const fields = options.filter(x => x.startsWith('f:')).flatMap(x => x.split(':')[1]).join(',').split(',').map(x => x.split('-'))
|
|
468
|
+
const fields = options.filter(x => x.startsWith('f:')).flatMap(x => x.split(':')[1]).join(',').split(',').map(x => x.split('-')).filter(x => x.length === 2)
|
|
443
469
|
|
|
444
470
|
fs.mkdirSync(folder, { recursive: true })
|
|
445
471
|
|
|
@@ -484,7 +510,7 @@ if (command.toLowerCase() === 'entity' || command === 'e') {
|
|
|
484
510
|
|
|
485
511
|
function generateValueObject(upperCase) {
|
|
486
512
|
const folder = config?.paths?.valueObjects ? path.resolve(process.cwd(), config?.paths?.valueObjects, entityName) : path.resolve(process.cwd(), entityName);
|
|
487
|
-
const fields = options.filter(x => x.startsWith('f:')).flatMap(x => x.split(':')[1]).join(',').split(',').map(x => x.split('-'))
|
|
513
|
+
const fields = options.filter(x => x.startsWith('f:')).flatMap(x => x.split(':')[1]).join(',').split(',').map(x => x.split('-')).filter(x => x.length === 2)
|
|
488
514
|
|
|
489
515
|
fs.mkdirSync(folder, { recursive: true })
|
|
490
516
|
|
|
@@ -525,6 +551,74 @@ if (command.toLowerCase() === 'value-object' || command === 'vo') {
|
|
|
525
551
|
process.exit(0)
|
|
526
552
|
}
|
|
527
553
|
|
|
554
|
+
function generateProvider(lowerCase, upperCase) {
|
|
555
|
+
const folder = config?.paths?.providers ? path.resolve(process.cwd(), config?.paths?.providers, entityName) : path.resolve(process.cwd(), entityName);
|
|
556
|
+
const providerType = options.find(x => x.startsWith('pt:'))?.split(':')?.at(1) ?? 'API'
|
|
557
|
+
|
|
558
|
+
fs.mkdirSync(folder, { recursive: true })
|
|
559
|
+
|
|
560
|
+
// Base
|
|
561
|
+
fs.writeFileSync(path.resolve(folder, `${entityName}.provider.ts`), [
|
|
562
|
+
`import { Module } from '@alevnyacow/nzmt'`,
|
|
563
|
+
'',
|
|
564
|
+
`export const ${lowerCase}ProviderMetadata = {`,
|
|
565
|
+
`\tname: '${upperCase}Provider'`,
|
|
566
|
+
`\tschemas: {}`,
|
|
567
|
+
`} satisfies Module.Metadata`,
|
|
568
|
+
``,
|
|
569
|
+
`type Methods = Module.Methods<typeof ${lowerCase}ProviderMetadata>;`,
|
|
570
|
+
``,
|
|
571
|
+
`export abstract class ${upperCase}Provider {`,
|
|
572
|
+
`\t`,
|
|
573
|
+
`}`
|
|
574
|
+
].join('\n'))
|
|
575
|
+
|
|
576
|
+
// Mock
|
|
577
|
+
fs.writeFileSync(path.resolve(folder, `${entityName}.provider.mock.ts`), [
|
|
578
|
+
`import { ${upperCase}Provider } from './${entityName}.provider'`,
|
|
579
|
+
'',
|
|
580
|
+
`export class ${upperCase}MockProvider extends ${upperCase}Provider {`,
|
|
581
|
+
`\t`,
|
|
582
|
+
`}`
|
|
583
|
+
].join('\n'))
|
|
584
|
+
|
|
585
|
+
// Provider
|
|
586
|
+
fs.writeFileSync(path.resolve(folder, `${entityName}.provider.${providerType.toLowerCase()}.ts`), [
|
|
587
|
+
`import { ${upperCase}Provider } from './${entityName}.provider'`,
|
|
588
|
+
'',
|
|
589
|
+
`export class ${upperCase}${providerType}Provider extends ${upperCase}Provider {`,
|
|
590
|
+
`\t`,
|
|
591
|
+
`}`
|
|
592
|
+
].join('\n'))
|
|
593
|
+
|
|
594
|
+
// Barrel
|
|
595
|
+
fs.writeFileSync(path.resolve(folder, `index.ts`), [
|
|
596
|
+
`export * from './${entityName}.provider'`,
|
|
597
|
+
`export * from './${entityName}.provider.${providerType.toLowerCase()}'`
|
|
598
|
+
].join('\n'))
|
|
599
|
+
|
|
600
|
+
// Update DI
|
|
601
|
+
const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di, 'entries.di.ts')
|
|
602
|
+
|
|
603
|
+
insertBeforeLineInFile(
|
|
604
|
+
diEntriesPath,
|
|
605
|
+
'type DIEntries =',
|
|
606
|
+
`import { ${upperCase}MockProvider, ${upperCase}${providerType}Provider } from '${config?.paths?.providers.replace('./src', '@')}/${entityName}}'\n`
|
|
607
|
+
)
|
|
608
|
+
|
|
609
|
+
insertAfterLineInFile(
|
|
610
|
+
diEntriesPath,
|
|
611
|
+
'// Providers',
|
|
612
|
+
`\t${upperCase}Provider: { test: ${upperCase}MockProvider, prod: ${upperCase}${providerType}Provider, dev: ${upperCase}${providerType}Provider },`,
|
|
613
|
+
)
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (command.toLowerCase() === 'provider' || command === 'p') {
|
|
617
|
+
var [lowerCase, upperCase] = camelizeVariants(entityName)
|
|
618
|
+
generateProvider(lowerCase, upperCase)
|
|
619
|
+
process.exit(0)
|
|
620
|
+
}
|
|
621
|
+
|
|
528
622
|
|
|
529
623
|
function generateService(lowerCase, upperCase, withCrud) {
|
|
530
624
|
const folder = config?.paths?.services ? path.resolve(process.cwd(), config?.paths?.services, entityName) : path.resolve(process.cwd(), entityName);
|