@alevnyacow/nzmt 0.0.33 → 0.0.34
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 +56 -10
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -6,6 +6,11 @@ var args = process.argv.slice(2);
|
|
|
6
6
|
|
|
7
7
|
var [command, entityName, options = ''] = args;
|
|
8
8
|
|
|
9
|
+
function getImportName(str) {
|
|
10
|
+
const match = str.match(/import\s*{\s*([^}]+)\s*}/);
|
|
11
|
+
return match ? match[1].trim() : null;
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
function camelizeVariants(str) {
|
|
10
15
|
if (!str.includes('-')) {
|
|
11
16
|
return [str, str.substring(0, 1).toUpperCase() + str.substring(1)]
|
|
@@ -383,16 +388,57 @@ function generateService(lowerCase, upperCase, withCrud) {
|
|
|
383
388
|
|
|
384
389
|
// Service body
|
|
385
390
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
391
|
+
if (withCrud) {
|
|
392
|
+
fs.writeFileSync(path.resolve(folder, `${serviceName}.service.ts`), [
|
|
393
|
+
config?.dependencyInjection?.inversifyjs ? "import { injectable, inject } from 'inversify'" : undefined,
|
|
394
|
+
config?.dependencyInjection?.storeTokensPrefix ?? undefined,
|
|
395
|
+
`import type { ${upperCase}Store } from '${config?.paths?.stores?.replace('./src', '@')}/${entityName}'`,
|
|
396
|
+
`import { ${lowerCase}ServiceMetadata } from './${entityName}.service.metadata'`,
|
|
397
|
+
"import { Module } from '@alevnyacow/nzmt'",
|
|
398
|
+
config?.dependencyInjection === 'inversifyjs' ? "@injectable()" : undefined,
|
|
399
|
+
`export class ${upperCase}Service {`,
|
|
400
|
+
`\tconstructor(`,
|
|
401
|
+
config?.dependencyInjection?.storeTokensPrefix ? `\t\t@inject(${getImportName(config?.dependencyInjection?.storeTokensPrefix)}.${lowerCase}s)` : undefined,
|
|
402
|
+
`\t\tprivate readonly ${lowerCase}s: ${upperCase}Store))`,
|
|
403
|
+
'\t) { }',
|
|
404
|
+
'\t',
|
|
405
|
+
`\tprivate method = Module.methods(${lowerCase}ServiceMetadata)`,
|
|
406
|
+
'\t',
|
|
407
|
+
`\tcreate = this.method('create', this.${lowerCase}s.create);`,
|
|
408
|
+
'\t',
|
|
409
|
+
`\tgetSpecific = this.method('getSpecific', async (x) => {`,
|
|
410
|
+
`\t\tconst item = await this.${lowerCase}s.details(x);`,
|
|
411
|
+
`\t\treturn { item };`,
|
|
412
|
+
`\t})`,
|
|
413
|
+
`\t`,
|
|
414
|
+
`\tgetList = this.method('getList', async (x) => {`,
|
|
415
|
+
`\t\tconst items = await this.${lowerCase}s.list(x);`,
|
|
416
|
+
`\t\treturn { items };`,
|
|
417
|
+
`\t})`,
|
|
418
|
+
`\t`,
|
|
419
|
+
`\tupdateOne = this.method('updateOne', async (x) => {`,
|
|
420
|
+
`\t\tawait this.${lowerCase}s.updateOne(x);`,
|
|
421
|
+
`\t\treturn {};`,
|
|
422
|
+
`\t})`,
|
|
423
|
+
`\t`,
|
|
424
|
+
`\tdeleteOne = this.method('deleteOne', async (x) => {`,
|
|
425
|
+
`\t\tawait this.${lowerCase}s.deleteOne(x);`,
|
|
426
|
+
`\t\treturn {};`,
|
|
427
|
+
`\t})`,
|
|
428
|
+
"}"
|
|
429
|
+
].filter(x => typeof x === 'string').join('\n'))
|
|
430
|
+
} else {
|
|
431
|
+
fs.writeFileSync(path.resolve(folder, `${serviceName}.service.ts`), [
|
|
432
|
+
config?.dependencyInjection?.inversifyjs ? "import { injectable } from 'inversify'" : undefined,
|
|
433
|
+
`import { ${lowerCase}ServiceMetadata } from './${entityName}.service.metadata'`,
|
|
434
|
+
"import { Module } from '@alevnyacow/nzmt'",
|
|
435
|
+
"",
|
|
436
|
+
config?.dependencyInjection === 'inversifyjs' ? "@injectable()" : undefined,
|
|
437
|
+
`export class ${upperCase}Service {`,
|
|
438
|
+
`\tprivate methods = Module.methods(${lowerCase}ServiceMetadata)`,
|
|
439
|
+
"}"
|
|
440
|
+
].filter(x => typeof x === 'string').join('\n'))
|
|
441
|
+
}
|
|
396
442
|
|
|
397
443
|
// Barrel
|
|
398
444
|
|