@alevnyacow/nzmt 0.2.0 → 0.2.1
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 +42 -1
- 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)]
|
|
@@ -100,6 +124,7 @@ function initDI() {
|
|
|
100
124
|
// Entries
|
|
101
125
|
fs.writeFileSync(path.resolve(folder, `entries.di.ts`), [
|
|
102
126
|
"import type { BindInWhenOnFluentSyntax } from 'inversify'",
|
|
127
|
+
"",
|
|
103
128
|
"type DIEntries = Record<",
|
|
104
129
|
"\tstring,",
|
|
105
130
|
"\t| (new (...args: any[]) => any)",
|
|
@@ -500,7 +525,7 @@ function generateService(lowerCase, upperCase, withCrud) {
|
|
|
500
525
|
"\tschemas: {}",
|
|
501
526
|
"} satisfies Module.Metadata",
|
|
502
527
|
"",
|
|
503
|
-
`export type ${upperCase}ServiceDTOs = Module.DTOs<typeof ${lowerCase}ServiceMetadata
|
|
528
|
+
`export type ${upperCase}ServiceDTOs = Module.DTOs<typeof ${lowerCase}ServiceMetadata>`
|
|
504
529
|
].filter(x => typeof x === 'string').join('\n'))
|
|
505
530
|
}
|
|
506
531
|
|
|
@@ -564,6 +589,22 @@ function generateService(lowerCase, upperCase, withCrud) {
|
|
|
564
589
|
`export * from './${entityName}.service.metadata'`,
|
|
565
590
|
`export * from './${entityName}.service'`
|
|
566
591
|
].join('\n'))
|
|
592
|
+
|
|
593
|
+
// Update DI
|
|
594
|
+
|
|
595
|
+
const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di, 'entries.di.ts')
|
|
596
|
+
|
|
597
|
+
insertBeforeLineInFile(
|
|
598
|
+
diEntriesPath,
|
|
599
|
+
'type DIEntries =',
|
|
600
|
+
`import { ${upperCase}Service } from '${config?.paths?.services.replace('./src', '@')}/${entityName}}'\n`
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
insertAfterLineInFile(
|
|
604
|
+
diEntriesPath,
|
|
605
|
+
'// Services',
|
|
606
|
+
`\t${upperCase}Service,`,
|
|
607
|
+
)
|
|
567
608
|
}
|
|
568
609
|
|
|
569
610
|
if (command === 'service') {
|