nestjs-gen
Advanced tools
Comparing version 1.2.0 to 1.2.1
62
index.js
@@ -22,2 +22,28 @@ #!/usr/bin/env node | ||
function _findConfig() { | ||
let ngenConfig; | ||
// look in tsconfig.app.json | ||
let configFile = path.resolve("./tsconfig.app.json"); | ||
if (fs.existsSync(configFile)) { | ||
let config = require(configFile); | ||
if (config['ngen-config']) { | ||
ngenConfig = config['ngen-config'] | ||
} | ||
} | ||
// look in tsconfig.json | ||
if (!ngenConfig) { | ||
configFile = path.resolve("./tsconfig.json"); | ||
if (fs.existsSync(configFile)) { | ||
let config = require(configFile); | ||
if (config['ngen-config']) { | ||
ngenConfig = config['ngen-config'] | ||
} | ||
} | ||
} | ||
return ngenConfig; | ||
} | ||
prog | ||
@@ -28,5 +54,2 @@ .version('1.0.0') | ||
.option('-p <prefix>', 'Specify root/prefix dir to generate in') | ||
.option('--prefix <prefix>', 'Specify root/prefix dir to generate in') | ||
.option('-a', 'Generate all (Module + Controller + Service + Repository + Model') | ||
@@ -56,2 +79,6 @@ .option('--all', 'Generate all (Module + Controller + Service + Repository + Model') | ||
// add prefix/subdir to generate in | ||
.option('-p <prefix>', 'Specify root/prefix dir to generate in') | ||
.option('--prefix <prefix>', 'Specify root/prefix dir to generate in') | ||
// add authentication guards? | ||
@@ -63,3 +90,3 @@ .option('--auth', 'CRUD actions will add authentication guards, requiring a logged in user') | ||
.option('--template-dir <dir>', 'The location of the template files to use') | ||
.option('--no-subdir', 'Don\'t put generated files in <name> subdirectory (if not using a module)') | ||
.option('--no-subdir', 'Don\'t put generated files in <name> subdirectory (only if not using a module)') | ||
@@ -70,2 +97,27 @@ .option('--casing <pascal>', 'default = "example.controller.ts", pascal = "ExampleController.ts"') | ||
// first see if there is a configuration file available, and start with that | ||
let config = _findConfig(); | ||
if (config) { | ||
if (config["prefix"] && !o.prefix) | ||
o.prefix = config["prefix"] ; | ||
if (config["model-dir"] && !o.modelDir) | ||
o.modelDir = config["model-dir"] ; | ||
if (config["template-dir"] && !o.templateDir) | ||
o.templateDir = config["template-dir"] ; | ||
if (config["no-subdir"] && !o.noSubdir) | ||
o.noSubdir = config["no-subdir"] ; | ||
if (config["casing"] && !o.casing) | ||
o.casing = config["casing"] ; | ||
if (config["auth-guard-class"] && !o.authGuardClass) | ||
o.authGuardClass = config["auth-guard-class"] ; | ||
if (config["auth-guard-dir"] && !o.authGuardDir) | ||
o.authGuardDir = config["auth-guard-dir"] ; | ||
} | ||
// normalize and validate | ||
@@ -89,3 +141,3 @@ if (o.p) { o.prefix = o.p }; | ||
o.authGuardName = o.authGuardClass ? o.authGuardClass : 'PrincipalGuard'; | ||
o.authGuardDir = o.authGuardDir ? o.authGuardDir : 'modules/auth/lib/'; | ||
o.authGuardDir = o.authGuardDir ? (o.authGuardDir+'/') : 'modules/auth/lib/'; | ||
} | ||
@@ -92,0 +144,0 @@ |
{ | ||
"name": "nestjs-gen", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "NestJS model package generator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -12,3 +12,3 @@ ## What This Is: | ||
(You can generate pascal-cased filenames with `--casing pascal`, ie. "ExampleModule.ts") | ||
(Tip: use `--casing pascal` to generate pascal-cased filenames, ie. "ExampleModule.ts") | ||
@@ -86,37 +86,55 @@ ## Install: | ||
## All Options: | ||
## Using a Configuration File | ||
You can specify generator configuration values by adding an `"ngen-config"` property inside your project's `tsconfig.app.json` or `tsconfig.json` file. For example: | ||
// tsconfig.json | ||
{ | ||
"ngen-config": { | ||
"prefix": "src", | ||
"modelDir": "models", | ||
"templateDir": "templates", | ||
"noSubdir": true, | ||
"casing": "pascal", | ||
"authGuardClass": "PrincipalGuard" | ||
"authGuardDir": "modules/auth/lib/" | ||
} | ||
} | ||
-p <prefix> Specify root/prefix dir to generate in optional | ||
--prefix <prefix> Specify root/prefix dir to generate in optional | ||
-a Generate all (Module + Controller + Service + Repository + Model optional default: false | ||
--all Generate all (Module + Controller + Service + Repository + Model optional default: false | ||
## All Options: | ||
Note: If using a configuration file, these command line options will always override the configuration file options. | ||
-m Generate a Module optional default: false | ||
--module Generate a Module optional default: false | ||
-r Generate a Repository for the model optional default: false | ||
--repo Generate a Repository for the model optional default: false | ||
--repository Generate a Repository for the model optional default: false | ||
-a Generate all (Module + Controller + Service + Repository + Model optional default: false | ||
--all Generate all (Module + Controller + Service + Repository + Model optional default: false | ||
-d Generate the model files optional default: false | ||
--model Generate the model file optional default: false | ||
--model-name <name> Specify a custom class name for the model optional | ||
--model-dir <dir> Specify a subdirectory to put the model in (ie. 'models') optional | ||
-m Generate a Module optional default: false | ||
--module Generate a Module optional default: false | ||
-c Generate a Controller for the model optional default: false | ||
--controller Generate a Controller for the model optional default: false | ||
-r Generate a Repository for the model optional default: false | ||
--repo Generate a Repository for the model optional default: false | ||
--repository Generate a Repository for the model optional default: false | ||
-s Generate a Service for the model optional default: false | ||
--service Generate a Service for the model optional default: false | ||
-d Generate the model files optional default: false | ||
--model Generate the model file optional default: false | ||
--model-name <name> Specify a custom class name for the model optional | ||
--model-dir <dir> Specify a subdirectory to put the model in (ie. 'models') optional | ||
--crud Generates CRUD actions within the Controller and Service optional default: false | ||
-c Generate a Controller for the model optional default: false | ||
--controller Generate a Controller for the model optional default: false | ||
--auth CRUD actions will add authentication guards, requiring a logged in user optional default: false | ||
--auth-guard-class <name> Name of a custom @(Guard<name>) class to use optional | ||
--auth-guard-dir <dir> The location of the custom @Guard class file optional | ||
-s Generate a Service for the model optional default: false | ||
--service Generate a Service for the model optional default: false | ||
--template-dir <dir> Specify a custom location of template files to use optional | ||
--no-subdir Don't put generated files in <name> subdirectory (if not using a module) optional default: false | ||
--crud Generates CRUD actions within the Controller and Service optional default: false | ||
--casing <pascal> Use pascal-casing for filenames, ie. "ExampleController.ts" optional default: false | ||
-p <prefix> Specify root/prefix dir to generate in optional | ||
--prefix <prefix> Specify root/prefix dir to generate in optional | ||
--auth CRUD actions will add authentication guards, requiring a logged in user optional default: false | ||
--auth-guard-class <name> Name of a custom @(Guard<name>) class to use optional | ||
--auth-guard-dir <dir> The location of the custom @Guard class file optional | ||
--template-dir <dir> The location of the template files to use optional | ||
--no-subdir Don't put generated files in <name> subdirectory (only if not using a module) optional default: false | ||
@@ -129,6 +147,6 @@ | ||
You can specify `--dir <dir>` to put the templates in a specific directory, otherwise they'll be put in a 'templates' directory. | ||
You can specify `--dir <dir>` to copy the templates to a specific directory, otherwise they'll be put in a 'templates' directory. | ||
(Specify `-f` to force-override existing files.) | ||
Then, edit the templates as needed, and specify their custom location in the ngen command with: `ngen --template-dir <dir>`. | ||
Then, edit the templates as needed, and specify their custom location in the ngen command with: `ngen --template-dir <dir>` (or add "templateDir" option to the config) |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
25728
217
150
10
5