New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-gen

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-gen - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

todo.md

2

index.js

@@ -130,3 +130,3 @@ #!/usr/bin/env node

} else {
o.modelProps = undefined;
o.modelProps = {};
}

@@ -133,0 +133,0 @@

{
"name": "nestjs-gen",
"version": "1.3.0",
"version": "1.3.1",
"description": "NestJS model package generator",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -14,3 +14,3 @@ ## What This Is:

(Tip: use `--casing pascal` to generate pascal-cased filenames, ie. "ExampleModule.ts")
(**Tip:** use `--casing pascal` to generate pascal-cased filenames, ie. "ExampleModule.ts")

@@ -30,6 +30,9 @@ ## Install:

(If using with local project only, replace `ngen` below with: `./node_modules/.bin/ngen`)
(If using with local project only, replace `ngen` below with: `./node_modules/.bin/ngen`, or alias it)
#### Generate a Module / Controller / Service / Repository / Model (or all):
**Note:** You will need to have a database configured with NestJS in order to use the repositories. See: https://docs.nestjs.com/techniques/database
### Generate a Module / Controller / Service / Repository / Model (or all):
ngen <name> <options>

@@ -40,10 +43,11 @@

(Tip: Use --prefix to place files within a prefix directory, from the current folder)
(**Tip:** Use --prefix to place files within a prefix directory, from the current folder)
(Tip: Use --crud to automatically generate CRUD interfaces within the Controller and Service classes)
(**Tip:** Use --crud to automatically generate CRUD interfaces within the Controller and Service classes)
*(See how to set these up as configuration options in tsconfig.json below)*
## Examples:
#### Generate a Module with all features (module, controller, service, repository, and model):
### Generate a Module with all features (module, controller, service, repository, and model):

@@ -62,3 +66,3 @@ ngen example --all

#### Generate just a Controller, Repository, and Example model (no module)
### Generate just a Controller, Repository, and Example model (no module):

@@ -77,3 +81,3 @@ ngen example --crud

#### Generate each specific thing you want
### Generate each specific thing you want:

@@ -89,9 +93,15 @@ ngen example --module --controller --service --repository --model --crud

#### Specifying model properties (optional)
### Specifying model properties (optional):
ngen example -a --model "prop:type id:number name:string prop:Anything"
If you specify a stringor properties to the --model argumenent, the generated model file will add the given properties, using the format propName:propType. It will also add a @Column() decorator for each properties. propType will be used as the exact class name, but will not be imported (if using a custom class), so you have to add the import yourself, for now. Currently does not support adding other decorators (ie. @PrimaryGeneratedColumn(), joins, etc), or custom @Column({}) definitions, which must be added manually, for now.
If you specify a string of properties to the --model argumenent, the generated model file will add the given properties to the class definition, using the format propName:propType.
**Note**: An 'id: number' property will automaticaly be generated, with an @PrimaryGeneratedColumn() decorator, because TypeOrm requires at least this property to exist. You can change this property name by passing a property with a type of 'primary', and it will add the property with the decorate, and a type of 'number'. For example: ```--model "someIdentifier:primary"```.
It will also add a @Column() decorator for each other property. *propType* will be used as the exact class name, but will not be imported (if using a custom class), so you have to add the import yourself, for now.
*(Currently does not support adding other decorators (ie. joins/relationships), or custom @Column({}) definition properties, which must be added manually, for now.)*
## Things to Note:

@@ -102,8 +112,11 @@ * Generated model class/file names will strip any trailing 's' in the given name, if one exists, unless you set the model class name explicitly with `--model-class <name>`.

Your custom auth guard class name and location can be defined with `--auth-guard-class <class-name>` and `--auth-guard-location <dir>` (or put in tsconfig.json).
* The generated files will all have their imports and injected dependencies referenced correctly relative to each other, but you will still need to add these references to your main AppModule, or wherever you need to use them. In other words: this package doesn't edit existing files.
* The generated files will all have their imports and injected dependencies referenced correctly relative to each other, but you will still need to add these references to your main AppModule, or wherever you need to use them. In other words: **this package doesn't edit existing files.**
* Similarly, modules do not export any classes (ie. Service) by default. You have to add those classes to the generated Module file's exports array manually, for now.
* For now it will only generate TypeScript files (no plain JS), but you can customize the template files if you want to strip the TypeScript stuff (see below).
## 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:
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 (all of these are optional):
// tsconfig.json

@@ -126,3 +139,3 @@ {

## All Options:
Note: If using a configuration file, these command line options will always override the configuration file options.
**Note:** If using a configuration file, these command line options will always override the configuration file options.

@@ -169,15 +182,15 @@ -a Generate all (Module + Controller + Service + Repository + Model optional default: false

## Customizing Templates
## Customizing the Templates
To customize the template files, first copy them to your project with this command:
ngen-copy-templates
(./node_modules/bin/ngen-copy-templates if installed locally)
You can specify `--dir <dir>` to copy the templates to 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:
Then, edit the templates as needed, and specify their custom location in the ngen-config section of the configuration, or with this command:
ngen --template-dir <dir>
(or add "templateDir" option to the configuration file)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc