@guachos/nestjs-typeorm-schematics

0.1.1 • Public • Published

NestJS CLI Schematics for Custom resources Generation

(typeorm persistence layer)

Overview

This package contains a set of NestJS CLI schematics for generating custom resources for a nestjs project using typeorm persistent layer

  • crud: fully functional and swagger integrated CRUD module.

TRHANKS!: This solution is inspired in this article, and this, and this repos

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 @guachos/nestjs-typeorm-schematics

or

yarn add -D @guachos/nestjs-typeorm-schematics

Dependencies

yarn add typeorm @nestjs/{common,typeorm,swagger} @guachos/{api-core,nestjs-typeorm-data-access,nestjs-typeorm-recipes}

The generated code uses some of the public libraries of the @guachos development ecosystem:

  • @guachos/api-core
  • @guachos/nestjs-api-response
  • @guachos/nestjs-common
  • @guachos/nestjs-typeorm-data-access
  • @guachos/nestjs-typeorm-meta-mapper
  • @guachos/nestjs-typeorm-recipes

NOTE: some of these libraries are currently maintained in private repos, so this solution is not fully open source...for now

Resources Generation

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

  1. Adding a generated CRUD module to an existing NestJS project. In this case, the module is created in its own folder, and is wired into 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 CRUD module with Swagger integration and this schematic 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 always generate spec files.

Use the crud schematic

npx nest g -c @guachos/nestjs-typeorm-schematics crud <module-name> <destination-path>
  • crud is the name of the schematic used to generate a new CRUD module (which will be added to your existing project).
  • <module-name> is the name of the new module you're building.
  • <destination-path> is the path where the new module will be generated

TIP: You can simply type nest g -c @guachos/nestjs-typeorm-schematics crud and follow the prompt instructions

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.

Example: Create todo crud module
> npx nest g -c @guachos/nestjs-typeorm-schematics crud               
? Which project would you like to generate to? src [ Default ]
? What name would you like to use for the module? todo
? What path would you like to use for create the module? 
CREATE src/todo/todo.controller.ts (684 bytes)
CREATE src/todo/todo.module.ts (551 bytes)
CREATE src/todo/todo.service.ts (479 bytes)
CREATE src/todo/app/dto/todo.create.dto.ts (550 bytes)
CREATE src/todo/app/dto/todo.update.dto.ts (260 bytes)
CREATE src/todo/app/dto/todo.view.ts (532 bytes)
CREATE src/todo/domain/todo.domain.entity.ts (1893 bytes)
CREATE src/todo/infra/todo.mapper.ts (1079 bytes)
CREATE src/todo/infra/todo.persistence.entity.ts (213 bytes)
CREATE src/todo/infra/todo.repository.ts (451 bytes)
CREATE src/todo/test/todo.controller.spec.ts (548 bytes)
CREATE src/todo/test/todo.service.spec.ts (438 bytes)
UPDATE src/app.module.ts (417 bytes)

More Help

You can also refer to these articles:

Schematics — An Introduction

How to build completely dynamic NestJS modules - 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.

Use Angular Schematics to Simplify Your Life

Extend Angular Schematics to customize your development process

How to create your own Angular Schematics

Generating microservices with nestjs and schematics

Change Log

See Changelog for more information.

Author

David Estevez destevezbreso@gmail.com

License

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

Project status

This utility generates code that relies on some of the newest features of the @guachos development ecosystem. Several of these features are in an early stage of development.

We will continue to improve and add new features

Readme

Keywords

none

Package Sidebar

Install

npm i @guachos/nestjs-typeorm-schematics

Weekly Downloads

20

Version

0.1.1

License

MIT

Unpacked Size

61.9 kB

Total Files

68

Last publish

Collaborators

  • alexbd9106
  • destbreso
  • alejulian9119
  • guajiritos