npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nestjsplus/dyn-schematics

v1.0.12

Published

NestJS Dynamic Module Schematics for @nestjs/cli

Downloads

5,476

Readme

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 globally as shown below. Due to the implementation of the NestJS CLI, the package must be global.

npm install -g @nestjsplus/dyn-schematics

Dynamic Package Generation

Currently, there are two use cases supported, each with a corresponding schematic:

  1. Generating a complete, new standalone NestJS package containing a dynamic module. Such a package can easily be installed locally with npm, or packaged and distributed via the npm registry, or a private registry. In other words, use this to build a re-usable library.
  2. 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.

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.

Note: I'm working on schematics to add new components to an existing dynamic module, such as additional options providers. This should be coming soon.

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.

Use the dynpkg schematic

nest g -c @nestjsplus/dyn-schematics dynpkg <pkg-name>
  • dynpkg is the name of the schematic used to generate a new standalone package containing a dynamic module.
  • <pkg-name> is the name of the new package you're building.

The schematic will prompt you asking whether to create a test client. If you answer yes, it will add a small module, which you can later easily remove, to test out the newly generated schematic. I recommend you choose yes when first testing out the schematic.

Move to the sub-folder just created:

cd <pkg-name>
  • where pkg-name is the name you supplied in the original nest g command above.

Install the dependencies for the generated package:

npm install

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-case #2: Adding a dynamic module to an existing project

Make sure you're in the project root folder, just as you would be if running something like nest g controller myController.

Use the dnymod schematic

nest g -c @nestjsplus/dyn-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.

Contributing

Contributions welcome! See Contributing.

Author

John Biundo (Y Prospect on Discord)

License

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