@alevnyacow/nzmt 0.24.0 → 0.25.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.
Files changed (2) hide show
  1. package/bin/cli.js +51 -3
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -403,6 +403,48 @@ function initPrisma() {
403
403
  )
404
404
  }
405
405
 
406
+ function generateInfrastructure(upperCase, lowerCase) {
407
+ const config = loadConfig()
408
+ const folder = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.infrastructure}`, entityName)
409
+ fs.mkdirSync(folder, { recursive: true })
410
+
411
+ fs.writeFileSync(path.resolve(folder, `${entityName}.ts`), [
412
+ `export class ${upperCase} {`,
413
+ `\t`,
414
+ `}`
415
+ ])
416
+
417
+ fs.writeFileSync(path.resolve(folder, `${entityName}.mock.ts`), [
418
+ `import { ${upperCase} } from './${entityName}'`,
419
+ '',
420
+ `export class Mock${upperCase} implements ${upperCase} {`,
421
+ `\t`,
422
+ `}`
423
+ ])
424
+
425
+ fs.writeFileSync(path.resolve(folder, `index.ts`), [
426
+ `export * from './${entityName}'`,
427
+ `export * from './${entityName}.mock'`
428
+ ])
429
+
430
+ // Update DI
431
+
432
+ const diEntriesPath = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.di}`, 'entries.di.ts')
433
+
434
+ insertBeforeLineInFile(
435
+ diEntriesPath,
436
+ 'type DIEntries =',
437
+ `import { ${upperCase} } from '@${config?.paths?.infrastructure}/${entityName}'`
438
+ )
439
+
440
+ insertAfterLineInFile(
441
+ diEntriesPath,
442
+ '// Infrastructure',
443
+ `\t${upperCase}: { test: Mock${upperCase}, dev: ${upperCase}, prod: ${upperCase} },`,
444
+ )
445
+ }
446
+
447
+
406
448
  function initGuards() {
407
449
  const config = loadConfig()
408
450
  const endpointGuardsFolder = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.infrastructure}`, 'guards')
@@ -435,7 +477,6 @@ function initGuards() {
435
477
  '// Infrastructure',
436
478
  `\tGuards,`,
437
479
  )
438
-
439
480
  }
440
481
 
441
482
  function initLogger() {
@@ -482,7 +523,7 @@ function initLogger() {
482
523
  )
483
524
  }
484
525
 
485
- if (command.toLowerCase() === 'init' || command === 'i') {
526
+ if (command.toLowerCase() === 'init') {
486
527
  createDefaultConfig()
487
528
  initDI()
488
529
  initClientUtils()
@@ -1283,10 +1324,10 @@ function generateQueries(lowerCase, upperCase, entity) {
1283
1324
 
1284
1325
  const indexPath = path.resolve(projectRoot, `${config.coreFolder}${config.paths.queries}`, `${requiredEntity}`)
1285
1326
  fs.writeFileSync(path.resolve(indexPath, 'index.ts'), `export * as ${upperCase}Queries from './endpoints'`)
1286
-
1287
1327
  }
1288
1328
 
1289
1329
 
1330
+
1290
1331
  if (command === 'api-routes') {
1291
1332
  var [lowerCase, upperCase] = camelizeVariants(entityName)
1292
1333
 
@@ -1316,6 +1357,13 @@ if (command.toLowerCase() === 'controller' || command === 'c') {
1316
1357
  process.exit(0)
1317
1358
  }
1318
1359
 
1360
+ if (command.toLowerCase() === 'infrastructure' || command === 'i') {
1361
+ var [lowerCase, upperCase] = camelizeVariants(entityName)
1362
+ generateInfrastructure(upperCase, lowerCase)
1363
+ process.exit(0)
1364
+
1365
+ }
1366
+
1319
1367
  if (command.toLowerCase() === 'stored-entity' || command === 'se') {
1320
1368
  var [lowerCase, upperCase] = camelizeVariants(entityName)
1321
1369
  generateEntity(upperCase)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "keywords": ["next", "full-stack", "server", "backend", "cli", "scaffolding", "zod", "rest", "contract programming", "contract-first", "react-query", "ddd", "domain-driven"],
6
6
  "repository": {