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

nest-genie

v1.0.4

Published

A CLI tool to generate NestJS modules, services, controllers, and more

Downloads

299

Readme

Nest Genie 🧞

Nest Genie is a CLI tool for generating modules, services, controllers, and more in NestJS projects that follow a clean architecture structure.

Installation

To install Nest Genie, you can use npm and then install the dependencies:

# Use npm
$ npm install -g nest-genie

# Use yarn
$ yarn add -g nest-genie

# Use pnpm
$ pnpm install -g nest-genie

Use

Nest Genie provides several generators to help you create different parts of your NestJS application. The available generators are:

  • doc: Easily generate error codes for later use in different places in the application.
  • single: Generates individual controllers, CRUDs, providers, schemas and use cases.

The main command includes this same documentation and can be consulted at any time:

$ genie


  _   _           _      ____            _      _ 
 | \ | | ___  ___| |_   / ___| ___ _ __ (_) ___| |
 |  \| |/ _ \/ __| __| | |  _ / _ \ '_ \| |/ _ \ |
 | |\  |  __/\__ \ |_  | |_| |  __/ | | | |  __/_|
 |_| \_|\___||___/\__|  \____|\___|_| |_|_|\___(_)

  

  Usage: genie <generator> <action>

  Available generators and actions:
  - doc: doc errors
  - single: single controller, single crud, single provider, single schema, single use-case

  Examples:
  - genie doc errors
  - genie single controller

  For more information, visit our documentation at https://docs

Commands

To use Nest Genie, run the genie command followed by the generator and the action you want to perform. Here are some examples:

$ genie doc errors
$ genie single controller
$ genie single crud
$ genie single provider
$ genie single schema
$ genie single use-case

Examples

1. Generate a controller:

To generate a driver, use the following command:

$ genie single controller
  √ Controller module name (singular)? · car

  Loaded templates: ....
        inject: src/app.module.ts
        inject: src/app.module.ts
        inject: src/infraestructure/controllers/index.ts
        added: src/infraestructure/controllers/cars.controller.ts
        added: src/infraestructure/controllers/docs/cars/cars.docs.decorator.ts
        inject: src/infraestructure/controllers/docs/index.ts
        added: src/infraestructure/controllers/docs/cars/cars.responses.ts       
        added: src/infraestructure/controllers/tests/cars/cars.controller.spec.ts

2. Generate a Use Case

$ genie single use-case
  √ Use case module name (singular)? · car

  Loaded templates: ....
        inject: src/application/application.module.ts
        inject: src/application/application.module.ts
        inject: src/application/application.module.ts
        added: src/application/cars/cars.use-cases.ts
        added: src/application/cars/tests/cars.use-cases.mocks.ts
        added: src/application/cars/tests/cars.use-cases.spec.ts

Note that it asks for the name of the module it will take to build the required structure.

3. Generate a CRUD

To generate a CRUD, use the following command:

$ genie single crud
  √ Entity name (singular)? · car
  √ Pick a database · MongoDB

  Loaded templates: ....
        inject: src/application/application.module.ts
        inject: src/application/application.module.ts
        inject: src/application/application.module.ts
        added: src/application/cars/tests/cars.use-cases.mocks.ts
        added: src/application/cars/tests/cars.use-cases.spec.ts 
        added: src/application/cars/cars.use-cases.ts
        added: src/domain/cars/cars.adapter.ts
        added: src/domain/cars/index.ts
        .......

You can select between MongoDB and PostgreSQL according to your particular case.

4. Generate a new schema

We can easily generate a new database schema within the framework layer according to the selected database:

$ genie single schema
  √ Schema's name · car
  √ Pick a database · PostgreSQL

  Loaded templates: ....
        added: src/domain/cars/cars.adapter.ts
        added: src/domain/cars/index.ts
        added: src/domain/cars/cars.entity.ts
        added: src/domain/cars/cars.types.ts
        inject: src/framework/providers/data.provider.ts
        inject: src/framework/providers/data.provider.ts
        inject: src/framework/postgresql/models/index.ts
        added: src/framework/postgresql/models/cars.model.ts
        inject: src/framework/postgresql/postgresql.service.ts
        inject: src/framework/postgresql/postgresql.module.ts
        inject: src/framework/postgresql/postgresql.service.ts
        inject: src/framework/postgresql/postgresql.service.ts
        inject: src/framework/postgresql/postgresql.service.ts
        .......

5. Generate a new provider based on an abstraction

This generator allows you to create an abstraction that represents something tangible, for example, a mailer provider. This can be implemented by a framework:

$ genie single provider
  √ Abstraction's name · email
  √ Library's name · nodemailer
  √ Abstraction's name · email
  √ Library's name · nodemailer

  Loaded templates: ....
        added: src/framework/providers/email.provider.ts
        added: src/framework/nodemailer/nodemailer.module.ts
        added: src/framework/nodemailer/nodemailer.repository.ts
        added: src/framework/nodemailer/tests/nodemailer.repository.spec.ts
        inject: src/framework/providers/providers.module.ts
        inject: src/framework/providers/providers.module.ts
        inject: src/framework/providers/providers.module.ts

6. Generate error definition easily

You can generate a complete error definition from the CLI without needing to visit the configuration files directly.

  $ genie doc errors
  √ Error name (simple and short)? · car not registered
  √ HTTP Status code: · 405
  √ Message: · This message is an example
  √ Description (for swagger docs): · Description for swagger documentation

  Loaded templates: ....
        inject: libs/common/src/exceptions/codes.ts
        inject: libs/common/src/exceptions/codesDefinition.ts

The modified files look like this:

// libs/common/src/exceptions/codes.ts
export enum ErrorCodes {
  // Add custom codes | Don't remove this line
  CAR_NOT_REGISTERED = 'CAR_NOT_REGISTERED',
  ...
}

// libs/common/src/exceptions/codesDefinition.ts
export const ErrorCodesDefinition: ErrorFromEnumObject<typeof ErrorCodes> = {
  // Add custom codes definition | Don't remove this line
  CAR_NOT_REGISTERED: {
    message: 'This message is an example',
    statusCode: 405,
    description: 'Description for swagger documentation',
  },
}

Contributors

  • Manuel Cutie M.
  • Gabriel Barrera O.

License

This project is licensed under the BSD-3-Clause license.

This documentation provides an overview of the tool, installation instructions, usage examples, and other relevant information.