2.1.1 • Published 3 years ago

@comerick/nestjs-template-schematics v2.1.1

Weekly downloads
19
License
MIT
Repository
github
Last release
3 years ago

Overview

This package contains a set of NestJS CLI schematics for generating modules that can be dynamically configured. The concepts behind the generated code is covered in detail in this article.

See below for a description of the use cases.

Installation

Install the package as dev dependencies below. Due to the implementation of the NestJS CLI, the package can be global or dev.

npm install -D @comerick/nestjs-template-schematics"

Dynamic Package Generation

Currently, there are only one case supported, each with a corresponding schematic:

  1. Adding a generated dynamic module to an existing NestJS project. In this case, the module is created in its own folder, and is wired in to the existing project using appropriate module metadata, includes, etc. This schematic works much like Nest's built-in module schematic, but creates a fully implemented dynamic module and this schematics is based on generated entities.

Nest CLI

These schematics are built on top of the Nest CLI infrastructure, so their usage is exactly as documented on that page.

Note: since these schematics are built on top of the Nest CLI, all of the optional arguments (such as specifying an optional path in which to generate the code) and options (such as --dry-run, --flat) are available. Currently, however, the schematics do not generate spec files.

Use-case #1: Generating a standalone package

The following step will create a new folder using <pkg-name>, which will contain the standalone package files and folders for your new dynamic module package.

Verify generated package

If you answered yes to the prompt Generate a testing client?, a small testing module was automatically generated called <pkg-name>ClientModule. You can test that the template was properly generated by running:

npm run start:dev

Then browse to http://localhost:3000. Your browser should display Hello from <pkg-name>Module!.

Optionally publish package

The package.json and tsconfig.json files are generated according to the process described in this article. This means that publishing the package to npm is as simple as: 1. updating the package.json with your author information, etc. 2. running npm publish

See the npm packaging article for more information.

Use the dnymod schematic

nest g -c @comerick/nestjs-template-schematics dynmod <module-name>
  • dynmod is the name of the schematic used to generate a new dynamic module (which will be added to your existing project).
  • <module-name> is the name of the new module you're building.

The schematic adds the new module in a folder named <module-name>. Just like using the built-in module schematic (e.g., nest g module myNewModule), this will add the generated module to the imports list of your root module with the appropriate metadata and includes. At this point, you can customize the generated module as needed.

Customizing

The files in the project have comments that should help guide you.

More help

You can also refer to these articles:

How to build completely dynamic NestJS mdoules - for details on the concepts behind the dynamic module pattern.

Built a NestJS module for Knex.js in 5 minutes - an end-to-end tutorial on using these schematics.

Change Log

See Changelog for more information.

Author

Erik Gróf

License

Licensed under the MIT License - see the LICENSE file for details.

2.1.1

3 years ago

2.0.13

3 years ago

2.0.12

3 years ago

2.1.0

3 years ago

2.0.9

3 years ago

2.0.10

3 years ago

2.0.8

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago