@alevnyacow/nzmt 0.2.0 → 0.2.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/cli.js +59 -2
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -6,6 +6,30 @@ var args = process.argv.slice(2);
|
|
|
6
6
|
|
|
7
7
|
var [command, entityName, ...options] = args;
|
|
8
8
|
|
|
9
|
+
function insertAfterLineInFile(filePath, targetLine, newLine) {
|
|
10
|
+
let content = fs.readFileSync(filePath, 'utf8');
|
|
11
|
+
|
|
12
|
+
const lines = content.split('\n');
|
|
13
|
+
const index = lines.findIndex(line => line.includes(targetLine));
|
|
14
|
+
|
|
15
|
+
if (index !== -1) {
|
|
16
|
+
lines.splice(index + 1, 0, newLine);
|
|
17
|
+
fs.writeFileSync(filePath, lines.join('\n'), 'utf8');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function insertBeforeLineInFile(filePath, targetLine, newLine) {
|
|
22
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
23
|
+
const lines = content.split('\n');
|
|
24
|
+
|
|
25
|
+
const index = lines.findIndex(line => line.includes(targetLine));
|
|
26
|
+
|
|
27
|
+
if (index !== -1) {
|
|
28
|
+
lines.splice(index, 0, newLine);
|
|
29
|
+
fs.writeFileSync(filePath, lines.join('\n'), 'utf8');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
9
33
|
function camelizeVariants(str) {
|
|
10
34
|
if (!str.includes('-')) {
|
|
11
35
|
return [str, str.substring(0, 1).toUpperCase() + str.substring(1)]
|
|
@@ -87,7 +111,6 @@ function createDefaultConfig() {
|
|
|
87
111
|
}
|
|
88
112
|
}, null, '\t'))
|
|
89
113
|
}
|
|
90
|
-
|
|
91
114
|
}
|
|
92
115
|
|
|
93
116
|
function initDI() {
|
|
@@ -100,6 +123,7 @@ function initDI() {
|
|
|
100
123
|
// Entries
|
|
101
124
|
fs.writeFileSync(path.resolve(folder, `entries.di.ts`), [
|
|
102
125
|
"import type { BindInWhenOnFluentSyntax } from 'inversify'",
|
|
126
|
+
"",
|
|
103
127
|
"type DIEntries = Record<",
|
|
104
128
|
"\tstring,",
|
|
105
129
|
"\t| (new (...args: any[]) => any)",
|
|
@@ -385,6 +409,23 @@ function generateStores(lowerCase, upperCase) {
|
|
|
385
409
|
`export * from './${entityName}.store.prisma.ts'`,
|
|
386
410
|
`export * from './${entityName}.store.ram.ts'`
|
|
387
411
|
].join('\n'))
|
|
412
|
+
|
|
413
|
+
// update DI
|
|
414
|
+
|
|
415
|
+
const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di, 'entries.di.ts')
|
|
416
|
+
|
|
417
|
+
insertBeforeLineInFile(
|
|
418
|
+
diEntriesPath,
|
|
419
|
+
'type DIEntries =',
|
|
420
|
+
`import { ${upperCase}PrismaStore, ${upperCase}RAMStore } from '${config?.paths?.stores.replace('./src', '@')}/${entityName}'\n`
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
insertAfterLineInFile(
|
|
424
|
+
diEntriesPath,
|
|
425
|
+
'// Stores',
|
|
426
|
+
`\t${upperCase}Store: { test: [${upperCase}RAMStore, (x) => x.inSingletonScope()], prod: ${upperCase}PrismaStore, dev: ${upperCase}PrismaStore },`,
|
|
427
|
+
)
|
|
428
|
+
|
|
388
429
|
}
|
|
389
430
|
|
|
390
431
|
if (command === 'store') {
|
|
@@ -500,7 +541,7 @@ function generateService(lowerCase, upperCase, withCrud) {
|
|
|
500
541
|
"\tschemas: {}",
|
|
501
542
|
"} satisfies Module.Metadata",
|
|
502
543
|
"",
|
|
503
|
-
`export type ${upperCase}ServiceDTOs = Module.DTOs<typeof ${lowerCase}ServiceMetadata
|
|
544
|
+
`export type ${upperCase}ServiceDTOs = Module.DTOs<typeof ${lowerCase}ServiceMetadata>`
|
|
504
545
|
].filter(x => typeof x === 'string').join('\n'))
|
|
505
546
|
}
|
|
506
547
|
|
|
@@ -564,6 +605,22 @@ function generateService(lowerCase, upperCase, withCrud) {
|
|
|
564
605
|
`export * from './${entityName}.service.metadata'`,
|
|
565
606
|
`export * from './${entityName}.service'`
|
|
566
607
|
].join('\n'))
|
|
608
|
+
|
|
609
|
+
// Update DI
|
|
610
|
+
|
|
611
|
+
const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di, 'entries.di.ts')
|
|
612
|
+
|
|
613
|
+
insertBeforeLineInFile(
|
|
614
|
+
diEntriesPath,
|
|
615
|
+
'type DIEntries =',
|
|
616
|
+
`import { ${upperCase}Service } from '${config?.paths?.services.replace('./src', '@')}/${entityName}}'\n`
|
|
617
|
+
)
|
|
618
|
+
|
|
619
|
+
insertAfterLineInFile(
|
|
620
|
+
diEntriesPath,
|
|
621
|
+
'// Services',
|
|
622
|
+
`\t${upperCase}Service,`,
|
|
623
|
+
)
|
|
567
624
|
}
|
|
568
625
|
|
|
569
626
|
if (command === 'service') {
|