@alevnyacow/nzmt 0.8.7 → 0.9.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 +55 -49
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -91,21 +91,26 @@ function createDefaultConfig() {
|
|
|
91
91
|
throw 'No package.json was found'
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
const folders = fs.readdirSync(projectRoot, { withFileTypes: true }).filter(x => x.isDirectory).map(x => x.name)
|
|
95
|
+
const withSrcFolder = folders.includes('src')
|
|
96
|
+
const coreFolder = withSrcFolder ? './src' : '.'
|
|
97
|
+
|
|
94
98
|
const prismaClientPathOption = [entityName, ...options].find(x => x.startsWith('prismaClientPath:'))
|
|
95
99
|
|
|
96
100
|
let prismaClientPath = prismaClientPathOption ? prismaClientPathOption.split(':')[1] : undefined
|
|
97
101
|
|
|
98
102
|
fs.writeFileSync(path.resolve(projectRoot, 'nzmt.config.json'), JSON.stringify(prismaClientPath ? {
|
|
103
|
+
coreFolder,
|
|
99
104
|
paths: {
|
|
100
|
-
di: '
|
|
101
|
-
stores: '
|
|
102
|
-
services: '
|
|
103
|
-
providers: '
|
|
104
|
-
controllers: '
|
|
105
|
-
infrastructure: '
|
|
106
|
-
entities: '
|
|
107
|
-
valueObjects: '
|
|
108
|
-
queries: '
|
|
105
|
+
di: '/server/di',
|
|
106
|
+
stores: '/server/stores',
|
|
107
|
+
services: '/server/services',
|
|
108
|
+
providers: '/server/providers',
|
|
109
|
+
controllers: '/server/controllers',
|
|
110
|
+
infrastructure: '/server/infrastructure',
|
|
111
|
+
entities: '/shared/entities',
|
|
112
|
+
valueObjects: '/shared/value-objects',
|
|
113
|
+
queries: '/client/shared/queries',
|
|
109
114
|
},
|
|
110
115
|
store: {
|
|
111
116
|
prisma: {
|
|
@@ -113,16 +118,17 @@ function createDefaultConfig() {
|
|
|
113
118
|
},
|
|
114
119
|
}
|
|
115
120
|
} : {
|
|
121
|
+
coreFolder,
|
|
116
122
|
paths: {
|
|
117
|
-
di: '
|
|
118
|
-
stores: '
|
|
119
|
-
services: '
|
|
120
|
-
providers: '
|
|
121
|
-
controllers: '
|
|
122
|
-
infrastructure: '
|
|
123
|
-
entities: '
|
|
124
|
-
valueObjects: '
|
|
125
|
-
queries: '
|
|
123
|
+
di: '/server/di',
|
|
124
|
+
stores: '/server/stores',
|
|
125
|
+
services: '/server/services',
|
|
126
|
+
providers: '/server/providers',
|
|
127
|
+
controllers: '/server/controllers',
|
|
128
|
+
infrastructure: '/server/infrastructure',
|
|
129
|
+
entities: '/shared/entities',
|
|
130
|
+
valueObjects: '/shared/value-objects',
|
|
131
|
+
queries: '/client/shared/queries',
|
|
126
132
|
}
|
|
127
133
|
}, null, '\t'))
|
|
128
134
|
}
|
|
@@ -132,7 +138,7 @@ function initDI() {
|
|
|
132
138
|
const config = loadConfig()
|
|
133
139
|
const diPath = config?.paths?.di
|
|
134
140
|
|
|
135
|
-
const folder = path.resolve(process.cwd(), diPath)
|
|
141
|
+
const folder = path.resolve(process.cwd(), `${config.coreFolder}${diPath}`)
|
|
136
142
|
fs.mkdirSync(folder, { recursive: true })
|
|
137
143
|
|
|
138
144
|
// Entries
|
|
@@ -289,12 +295,12 @@ function initPrisma() {
|
|
|
289
295
|
if (!prismaClientPath) {
|
|
290
296
|
return
|
|
291
297
|
}
|
|
292
|
-
const prismaFolder = path.resolve(process.cwd(), config?.paths?.infrastructure
|
|
298
|
+
const prismaFolder = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.infrastructure}`, 'prisma')
|
|
293
299
|
fs.mkdirSync(prismaFolder, { recursive: true })
|
|
294
300
|
|
|
295
301
|
fs.writeFileSync(path.resolve(prismaFolder, 'client.ts'), [
|
|
296
302
|
`import { PrismaPg } from '@prisma/adapter-pg'`,
|
|
297
|
-
`import { PrismaClient } from '
|
|
303
|
+
`import { PrismaClient } from '@${prismaClientPath}'`,
|
|
298
304
|
``,
|
|
299
305
|
`const adapter = new PrismaPg({`,
|
|
300
306
|
`\tconnectionString: process.env.DATABASE_URL`,
|
|
@@ -309,12 +315,12 @@ function initPrisma() {
|
|
|
309
315
|
|
|
310
316
|
// Update DI
|
|
311
317
|
|
|
312
|
-
const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di
|
|
318
|
+
const diEntriesPath = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.di}`, 'entries.di.ts')
|
|
313
319
|
|
|
314
320
|
insertBeforeLineInFile(
|
|
315
321
|
diEntriesPath,
|
|
316
322
|
'type DIEntries =',
|
|
317
|
-
`import { prismaClient } from '
|
|
323
|
+
`import { prismaClient } from '@${config?.paths?.infrastructure}/prisma'`
|
|
318
324
|
)
|
|
319
325
|
|
|
320
326
|
insertAfterLineInFile(
|
|
@@ -326,7 +332,7 @@ function initPrisma() {
|
|
|
326
332
|
|
|
327
333
|
function initLogger() {
|
|
328
334
|
const config = loadConfig()
|
|
329
|
-
const loggerFolder = path.resolve(process.cwd(), config?.paths?.infrastructure
|
|
335
|
+
const loggerFolder = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.infrastructure}`, 'logger')
|
|
330
336
|
fs.mkdirSync(loggerFolder, { recursive: true })
|
|
331
337
|
|
|
332
338
|
fs.writeFileSync(path.resolve(loggerFolder, 'logger.ts'), [
|
|
@@ -353,12 +359,12 @@ function initLogger() {
|
|
|
353
359
|
|
|
354
360
|
// Update DI
|
|
355
361
|
|
|
356
|
-
const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di
|
|
362
|
+
const diEntriesPath = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.di}`, 'entries.di.ts')
|
|
357
363
|
|
|
358
364
|
insertBeforeLineInFile(
|
|
359
365
|
diEntriesPath,
|
|
360
366
|
'type DIEntries =',
|
|
361
|
-
`import { ConsoleLogger } from '
|
|
367
|
+
`import { ConsoleLogger } from '@${config?.paths?.infrastructure}/logger'`
|
|
362
368
|
)
|
|
363
369
|
|
|
364
370
|
insertAfterLineInFile(
|
|
@@ -378,7 +384,7 @@ if (command.toLowerCase() === 'init' || command === 'i') {
|
|
|
378
384
|
}
|
|
379
385
|
|
|
380
386
|
function generateStores(lowerCase, upperCase, withEntityPreset) {
|
|
381
|
-
const folder = config?.paths?.stores ? path.resolve(process.cwd(), config?.paths?.stores
|
|
387
|
+
const folder = config?.paths?.stores ? path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.stores}`, entityName) : path.resolve(process.cwd(), entityName);
|
|
382
388
|
|
|
383
389
|
fs.mkdirSync(folder, { recursive: true })
|
|
384
390
|
|
|
@@ -388,7 +394,7 @@ function generateStores(lowerCase, upperCase, withEntityPreset) {
|
|
|
388
394
|
|
|
389
395
|
fs.writeFileSync(path.resolve(folder, `${entityName}.store.ts`), [
|
|
390
396
|
"import type { Store } from '@alevnyacow/nzmt'",
|
|
391
|
-
withEntity ? `import { ${upperCase} } from '
|
|
397
|
+
withEntity ? `import { ${upperCase} } from '@${config?.paths?.entities}/${entityName}'` : undefined,
|
|
392
398
|
"",
|
|
393
399
|
`export const ${lowerCase}StoreMetadata = {`,
|
|
394
400
|
"\tmodels: {",
|
|
@@ -432,7 +438,7 @@ function generateStores(lowerCase, upperCase, withEntityPreset) {
|
|
|
432
438
|
if (prismaPath) {
|
|
433
439
|
fs.writeFileSync(path.resolve(folder, `${entityName}.store.prisma.ts`), [
|
|
434
440
|
`import type { Prisma, PrismaClient } from '${prismaPath}'`,
|
|
435
|
-
`import { DITokens } from '
|
|
441
|
+
`import { DITokens } from '@${config?.paths?.di}'`,
|
|
436
442
|
"import { injectable, inject } from 'inversify'",
|
|
437
443
|
"import { Store } from '@alevnyacow/nzmt'",
|
|
438
444
|
`import { type ${upperCase}Store, ${lowerCase}StoreMetadata } from './${entityName}.store'`,
|
|
@@ -551,12 +557,12 @@ function generateStores(lowerCase, upperCase, withEntityPreset) {
|
|
|
551
557
|
|
|
552
558
|
// update DI
|
|
553
559
|
|
|
554
|
-
const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di
|
|
560
|
+
const diEntriesPath = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.di}`, 'entries.di.ts')
|
|
555
561
|
|
|
556
562
|
insertBeforeLineInFile(
|
|
557
563
|
diEntriesPath,
|
|
558
564
|
'type DIEntries =',
|
|
559
|
-
prismaPath ? `import { ${upperCase}PrismaStore, ${upperCase}RAMStore } from '
|
|
565
|
+
prismaPath ? `import { ${upperCase}PrismaStore, ${upperCase}RAMStore } from '@${config?.paths?.stores}/${entityName}'` : `import { ${upperCase}RAMStore } from '@${config?.paths?.stores}/${entityName}'`
|
|
560
566
|
)
|
|
561
567
|
|
|
562
568
|
insertAfterLineInFile(
|
|
@@ -574,7 +580,7 @@ if (command.toLowerCase() === 'store' || command === 's') {
|
|
|
574
580
|
}
|
|
575
581
|
|
|
576
582
|
function generateEntity(upperCase) {
|
|
577
|
-
const folder = config?.paths?.entities ? path.resolve(process.cwd(), config?.paths?.entities
|
|
583
|
+
const folder = config?.paths?.entities ? path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.entities}`, entityName) : path.resolve(process.cwd(), entityName);
|
|
578
584
|
const fields = options.filter(x => x.startsWith('f:')).flatMap(x => x.split(':')[1]).join(',').split(',').map(x => x.split('-')).filter(x => x.length === 2)
|
|
579
585
|
|
|
580
586
|
fs.mkdirSync(folder, { recursive: true })
|
|
@@ -619,7 +625,7 @@ if (command.toLowerCase() === 'entity' || command === 'e') {
|
|
|
619
625
|
}
|
|
620
626
|
|
|
621
627
|
function generateValueObject(upperCase) {
|
|
622
|
-
const folder = config?.paths?.valueObjects ? path.resolve(process.cwd(), config?.paths?.valueObjects
|
|
628
|
+
const folder = config?.paths?.valueObjects ? path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.valueObjects}`, entityName) : path.resolve(process.cwd(), entityName);
|
|
623
629
|
const fields = options.filter(x => x.startsWith('f:')).flatMap(x => x.split(':')[1]).join(',').split(',').map(x => x.split('-')).filter(x => x.length === 2)
|
|
624
630
|
|
|
625
631
|
fs.mkdirSync(folder, { recursive: true })
|
|
@@ -662,7 +668,7 @@ if (command.toLowerCase() === 'value-object' || command === 'vo') {
|
|
|
662
668
|
}
|
|
663
669
|
|
|
664
670
|
function generateProvider(lowerCase, upperCase) {
|
|
665
|
-
const folder = config?.paths?.providers ? path.resolve(process.cwd(), config?.paths?.providers
|
|
671
|
+
const folder = config?.paths?.providers ? path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.providers}`, entityName) : path.resolve(process.cwd(), entityName);
|
|
666
672
|
const providerType = options.find(x => x.startsWith('pt:'))?.split(':')?.at(1) ?? 'API'
|
|
667
673
|
|
|
668
674
|
fs.mkdirSync(folder, { recursive: true })
|
|
@@ -708,12 +714,12 @@ function generateProvider(lowerCase, upperCase) {
|
|
|
708
714
|
].join('\n'))
|
|
709
715
|
|
|
710
716
|
// Update DI
|
|
711
|
-
const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di
|
|
717
|
+
const diEntriesPath = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.di}`, 'entries.di.ts')
|
|
712
718
|
|
|
713
719
|
insertBeforeLineInFile(
|
|
714
720
|
diEntriesPath,
|
|
715
721
|
'type DIEntries =',
|
|
716
|
-
`import { ${upperCase}MockProvider, ${upperCase}${providerType}Provider } from '
|
|
722
|
+
`import { ${upperCase}MockProvider, ${upperCase}${providerType}Provider } from '@${config?.paths?.providers}/${entityName}}'`
|
|
717
723
|
)
|
|
718
724
|
|
|
719
725
|
insertAfterLineInFile(
|
|
@@ -736,7 +742,7 @@ function toKebabFromPascal(str) {
|
|
|
736
742
|
}
|
|
737
743
|
|
|
738
744
|
function generateService(lowerCase, upperCase) {
|
|
739
|
-
const folder = config?.paths?.services ? path.resolve(process.cwd(), config?.paths?.services
|
|
745
|
+
const folder = config?.paths?.services ? path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.services}`, entityName) : path.resolve(process.cwd(), entityName);
|
|
740
746
|
|
|
741
747
|
const injections = options.filter(x => x.startsWith('i:')).flatMap(x => x.split(':')[1]).join(',').split(',').filter(x => !!x.length)
|
|
742
748
|
|
|
@@ -746,10 +752,10 @@ function generateService(lowerCase, upperCase) {
|
|
|
746
752
|
}
|
|
747
753
|
|
|
748
754
|
if (i.endsWith('Store')) {
|
|
749
|
-
return `import { ${i} } from '
|
|
755
|
+
return `import { ${i} } from '@${config?.paths?.stores}/${toKebabFromPascal(i).slice(0, -'-store'.length)}'`
|
|
750
756
|
}
|
|
751
757
|
|
|
752
|
-
return `import { ${i} } from '
|
|
758
|
+
return `import { ${i} } from '@${config?.paths?.infrastructure}/${toKebabFromPascal(i)}'`
|
|
753
759
|
})
|
|
754
760
|
|
|
755
761
|
fs.mkdirSync(folder, { recursive: true })
|
|
@@ -772,7 +778,7 @@ function generateService(lowerCase, upperCase) {
|
|
|
772
778
|
|
|
773
779
|
fs.writeFileSync(path.resolve(folder, `${entityName}.service.ts`), [
|
|
774
780
|
"import { injectable, inject } from 'inversify'",
|
|
775
|
-
injections.length ? `import { DITokens } from '
|
|
781
|
+
injections.length ? `import { DITokens } from '@${config?.paths?.di}'` : undefined,
|
|
776
782
|
`import { ${lowerCase}ServiceMetadata } from './${entityName}.service.metadata'`,
|
|
777
783
|
"import { Module } from '@alevnyacow/nzmt'",
|
|
778
784
|
...importInjections,
|
|
@@ -798,12 +804,12 @@ function generateService(lowerCase, upperCase) {
|
|
|
798
804
|
|
|
799
805
|
// Update DI
|
|
800
806
|
|
|
801
|
-
const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di
|
|
807
|
+
const diEntriesPath = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.di}`, 'entries.di.ts')
|
|
802
808
|
|
|
803
809
|
insertBeforeLineInFile(
|
|
804
810
|
diEntriesPath,
|
|
805
811
|
'type DIEntries =',
|
|
806
|
-
`import { ${upperCase}Service } from '
|
|
812
|
+
`import { ${upperCase}Service } from '@${config?.paths?.services}/${entityName}'`
|
|
807
813
|
)
|
|
808
814
|
|
|
809
815
|
insertAfterLineInFile(
|
|
@@ -820,7 +826,7 @@ if (command.toLowerCase() === 'service' || command === 'S') {
|
|
|
820
826
|
}
|
|
821
827
|
|
|
822
828
|
function generateController(upperCase, lowerCase) {
|
|
823
|
-
const folder = config?.paths?.controllers ? path.resolve(process.cwd(), config?.paths?.controllers
|
|
829
|
+
const folder = config?.paths?.controllers ? path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.controllers}`, entityName) : path.resolve(process.cwd(), entityName);
|
|
824
830
|
|
|
825
831
|
const injections = options.filter(x => x.startsWith('i:')).flatMap(x => x.split(':')[1]).join(',').split(',').filter(x => !!x.length)
|
|
826
832
|
|
|
@@ -830,14 +836,14 @@ function generateController(upperCase, lowerCase) {
|
|
|
830
836
|
}
|
|
831
837
|
|
|
832
838
|
if (i.endsWith('Store')) {
|
|
833
|
-
return `import { ${i} } from '
|
|
839
|
+
return `import { ${i} } from '@${config?.paths?.stores}/${toKebabFromPascal(i).slice(0, -'-store'.length)}'`
|
|
834
840
|
}
|
|
835
841
|
|
|
836
842
|
if (i.endsWith('Service')) {
|
|
837
|
-
return `import { ${i} } from '
|
|
843
|
+
return `import { ${i} } from '@${config?.paths?.services}/${toKebabFromPascal(i).slice(0, -'-service'.length)}'`
|
|
838
844
|
}
|
|
839
845
|
|
|
840
|
-
return `import { ${i} } from '
|
|
846
|
+
return `import { ${i} } from '@${config?.paths?.infrastructure}/${toKebabFromPascal(i)}'`
|
|
841
847
|
})
|
|
842
848
|
|
|
843
849
|
fs.mkdirSync(folder, { recursive: true })
|
|
@@ -860,7 +866,7 @@ function generateController(upperCase, lowerCase) {
|
|
|
860
866
|
fs.writeFileSync(path.resolve(folder, `${entityName}.controller.ts`), [
|
|
861
867
|
`import { Controller } from '@alevnyacow/nzmt'`,
|
|
862
868
|
`import { injectable, inject } from 'inversify'`,
|
|
863
|
-
`import { DITokens } from '
|
|
869
|
+
`import { DITokens } from '@${config?.paths?.di}'`,
|
|
864
870
|
`import { ${lowerCase}ControllerMetadata } from './${entityName}.controller.metadata'`,
|
|
865
871
|
...importInjections,
|
|
866
872
|
``,
|
|
@@ -884,12 +890,12 @@ function generateController(upperCase, lowerCase) {
|
|
|
884
890
|
|
|
885
891
|
// Update DI
|
|
886
892
|
|
|
887
|
-
const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di
|
|
893
|
+
const diEntriesPath = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.di}`, 'entries.di.ts')
|
|
888
894
|
|
|
889
895
|
insertBeforeLineInFile(
|
|
890
896
|
diEntriesPath,
|
|
891
897
|
'type DIEntries =',
|
|
892
|
-
`import { ${upperCase}Controller } from '
|
|
898
|
+
`import { ${upperCase}Controller } from '@${config?.paths?.controllers}/${entityName}'`
|
|
893
899
|
)
|
|
894
900
|
|
|
895
901
|
insertAfterLineInFile(
|