@alevnyacow/nzmt 0.1.10 → 0.1.11
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 +12 -16
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -317,22 +317,18 @@ if (command === 'entity') {
|
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
function generateService(lowerCase, upperCase, withCrud) {
|
|
320
|
-
|
|
321
|
-
const serviceName = withCrud ? entityName + 's' : entityName
|
|
322
|
-
const folder = config?.paths?.services ? path.resolve(process.cwd(), config?.paths?.services, serviceName) : path.resolve(process.cwd(), serviceName);
|
|
320
|
+
const folder = config?.paths?.services ? path.resolve(process.cwd(), config?.paths?.services, entityName) : path.resolve(process.cwd(), entityName);
|
|
323
321
|
|
|
324
322
|
fs.mkdirSync(folder, { recursive: true })
|
|
325
323
|
|
|
326
324
|
// Metadata
|
|
327
|
-
const [lowerCaseService, upperCaseService] = camelizeVariants(serviceName)
|
|
328
|
-
|
|
329
325
|
if (withCrud) {
|
|
330
|
-
fs.writeFileSync(path.resolve(folder, `${
|
|
326
|
+
fs.writeFileSync(path.resolve(folder, `${entityName}.service.metadata.ts`), [
|
|
331
327
|
"import { type Module, Entities } from '@alevnyacow/nzmt'",
|
|
332
328
|
"import z from 'zod'",
|
|
333
329
|
`import { ${lowerCase}StoreMetadata } from '${config?.paths?.stores?.replace('./src', '@')}/${entityName}'`,
|
|
334
330
|
"",
|
|
335
|
-
`export const ${
|
|
331
|
+
`export const ${lowerCase}ServiceMetadata = {`,
|
|
336
332
|
`\tname: '${upperCase}sService',`,
|
|
337
333
|
"\tschemas: {",
|
|
338
334
|
"\t\tgetSpecific: {",
|
|
@@ -376,10 +372,10 @@ function generateService(lowerCase, upperCase, withCrud) {
|
|
|
376
372
|
"\t}",
|
|
377
373
|
"} satisfies Module.Metadata",
|
|
378
374
|
"",
|
|
379
|
-
`export type ${
|
|
375
|
+
`export type ${upperCase}ServiceDTOs = Module.DTOs<typeof ${lowerCase}ServiceMetadata>`
|
|
380
376
|
].filter(x => typeof x === 'string').join('\n'))
|
|
381
377
|
} else {
|
|
382
|
-
fs.writeFileSync(path.resolve(folder, `${
|
|
378
|
+
fs.writeFileSync(path.resolve(folder, `${entityName}.service.metadata.ts`), [
|
|
383
379
|
"import type { Module } from '@alevnyacow/nzmt'",
|
|
384
380
|
"",
|
|
385
381
|
`export const ${lowerCase}ServiceMetadata = {`,
|
|
@@ -394,20 +390,20 @@ function generateService(lowerCase, upperCase, withCrud) {
|
|
|
394
390
|
// Service body
|
|
395
391
|
|
|
396
392
|
if (withCrud) {
|
|
397
|
-
fs.writeFileSync(path.resolve(folder, `${
|
|
393
|
+
fs.writeFileSync(path.resolve(folder, `${entityName}.service.ts`), [
|
|
398
394
|
config?.dependencyInjection?.inversifyjs ? "import { injectable, inject } from 'inversify'" : undefined,
|
|
399
395
|
config?.dependencyInjection?.inversifyjs?.storeTokensImport ?? undefined,
|
|
400
396
|
`import type { ${upperCase}Store } from '${config?.paths?.stores?.replace('./src', '@')}/${entityName}'`,
|
|
401
|
-
`import { ${
|
|
397
|
+
`import { ${lowerCase}ServiceMetadata } from './${entityName}.service.metadata'`,
|
|
402
398
|
"import { Module } from '@alevnyacow/nzmt'",
|
|
403
399
|
config?.dependencyInjection?.inversifyjs ? "@injectable()" : undefined,
|
|
404
|
-
`export class ${
|
|
400
|
+
`export class ${upperCase}Service {`,
|
|
405
401
|
`\tconstructor(`,
|
|
406
402
|
config?.dependencyInjection?.inversifyjs?.storeTokensImport ? `\t\t@inject(${getImportName(config?.dependencyInjection?.inversifyjs?.storeTokensImport)}.${lowerCase}s)` : undefined,
|
|
407
403
|
`\t\tprivate readonly ${lowerCase}s: ${upperCase}Store`,
|
|
408
404
|
'\t) { }',
|
|
409
405
|
'\t',
|
|
410
|
-
`\tprivate method = Module.methods(${
|
|
406
|
+
`\tprivate method = Module.methods(${lowerCase}ServiceMetadata)`,
|
|
411
407
|
'\t',
|
|
412
408
|
`\tcreate = this.method('create', this.${lowerCase}s.create);`,
|
|
413
409
|
'\t',
|
|
@@ -433,7 +429,7 @@ function generateService(lowerCase, upperCase, withCrud) {
|
|
|
433
429
|
"}"
|
|
434
430
|
].filter(x => typeof x === 'string').join('\n'))
|
|
435
431
|
} else {
|
|
436
|
-
fs.writeFileSync(path.resolve(folder, `${
|
|
432
|
+
fs.writeFileSync(path.resolve(folder, `${entityName}.service.ts`), [
|
|
437
433
|
config?.dependencyInjection?.inversifyjs ? "import { injectable } from 'inversify'" : undefined,
|
|
438
434
|
`import { ${lowerCase}ServiceMetadata } from './${entityName}.service.metadata'`,
|
|
439
435
|
"import { Module } from '@alevnyacow/nzmt'",
|
|
@@ -448,8 +444,8 @@ function generateService(lowerCase, upperCase, withCrud) {
|
|
|
448
444
|
// Barrel
|
|
449
445
|
|
|
450
446
|
fs.writeFileSync(path.resolve(folder, 'index.ts'), [
|
|
451
|
-
`export * from './${
|
|
452
|
-
`export * from './${
|
|
447
|
+
`export * from './${entityName}.service.metadata'`,
|
|
448
|
+
`export * from './${entityName}.service'`
|
|
453
449
|
].join('\n'))
|
|
454
450
|
}
|
|
455
451
|
|