@webundsoehne/nx-nest
v6.0.0
Published
Nest Plugin for Nx
Readme
@webundsoehne/nx-nest
Description
This package includes nx generators to set up nest.js projects.
Preset
To create a nx + nestjs workspace together in one command: npx create-nx-workspace --skip ci --preset @webundsoehne/nx-nest [name]. (See Workspace for details on the options)
Based on the selected database and microservice-provider, this will generate an empty workspace with apps and libs folders, eslint setup, gitlab-ci preset, package.json scripts and pre-commit setup.
If a database was selected the database util-library will be generated providing the database-orm options and a central place for entities, migrations and seeds.
If the microservice-provider was included, the microservice-provider library will be created. This will be the central spot for keeping Message-Queues, their patterns and message-interfaces.
Generators
Use the generators by calling nx g @webundsoehne/nx-nest:<NAME> [OPTIONS]. Any required option will be prompted for if not given as parameter yet. To update an application pass --update with the same name of an existing application and reselect the required and new options. (This will not remove existing configurations if deselected on update)
Database-ORM and Microservice-Provider Libraries can be created on workspace initialization, if selected on application generation or manually by hand. Information to those two util-libraries are stored in the nx.json in the custom integration section.
Run nx list @webundsoehne/nx-nest to view available generators (or check the following sections below). Run nx g @webundsoehne/nx-nest:<NAME> --help to get details about the selected generator (also below in the respective section).
typeorm only: Once a database system is selected it is automatically used on any following application generations, if typeorm is selected as ORM.
Workspace
The generator used in the preset. If you have an empty nx workspace already, use this to add the nestjs skeleton presets.
Names: workspace, ws
Options:
| Option | Type | Description |
| -------------------- | ------- | ---------------------------------------------------------------------------- |
| name | string | workspace folder name |
| scope | string | library import prefix i.e. @scope/lib |
| database | boolean | if a database-orm should be set up |
| microserviceProvider | boolean | if to include the microservice-provider util-library |
| skipPackageJson | boolean | optional skip any action related to the package.json (scripts, dependencies) |
| force | boolean | option force overwriting existing files |
Application
The main nestjs application itself.
Names: application, app
Options:
| Option | Type | Description | | -------------------- | -------- | ----------------------------------------------------------------------------------------- | | name | string | application folder name | | components | string[] | what components the app includes (any of: server, bg-task, command, microservice) | | jest | boolean | if to setup jest for unit and e2e tests | | database | boolean | if a database-orm should be set up | | microserviceProvider | boolean | if to include the microservice-provider in the app (if the app is an Microservice-Client) | | skipPackageJson | boolean | optional skip any action related to the package.json (scripts, dependencies) | | update | boolean | option set to true if you want to update the applications options |
Microservice Provider
All about microservices and their message patterns and interfaces. In here, the Message-Queues are defined, what pattern they hold and which interfaces those patterns require on request and response.
Names: microserviceProvider, microservice-provider, msp
Options:
| Option | Type | Description |
| --------------- | ------- | ---------------------------------------------------------------------------- |
| name | string | library folder name (default: microservice-provider) |
| importPath | string | optional import-path overwrite (full path) (default: @{scope}/{name}) |
| skipPackageJson | boolean | optional skip any action related to the package.json (scripts, dependencies) |
Database ORM
The place for database setup, entities, migrations and seeds. Besides the orm-config and general database options, in this library the entities, migrations and seeds should be placed.
Names: database, db
Options:
| Option | Type | Description |
| --------------- | ------- | ---------------------------------------------------------------------------- |
| orm | string | which database orm to use |
| database | string | for typeorm select mysql or postgres db-system |
| name | string | library folder name (default: database) |
| importPath | string | optional import-path overwrite (full path) (default: @{scope}/{name}) |
| skipPackageJson | boolean | optional skip any action related to the package.json (scripts, dependencies) |
Library
An empty library folder with optional jest setup.
Names: library, lib
Options:
| Option | Type | Description |
| --------------- | ------- | ---------------------------------------------------------------------------- |
| name | string | library folder name |
| jest | boolean | if to setup jest for unit tests |
| importPath | string | optional import-path overwrite (full path) (default: @{scope}/{name}) |
| skipPackageJson | boolean | optional skip any action related to the package.json (scripts, dependencies) |
| update | boolean | optional set to true if you want to update the library options |
Resource
A specific component resource: folder with module + controller/task/command + service.
Names: resource, res
Options:
| Option | Type | Description | | --------- | ------ | -------------------------------------------------------------------------------------- | | component | string | the resource-type to generate (one of: server, bg-task, command, microservice, seeder) | | name | string | Resource name | | project | string | in which project to generate the new resource |
The resource generator allows generating via commandline args, but also has a custom enquirer prompt flow. After setting the name and selecting the component, only applications including this component will be suggested for selection.
Additionally, a resources can be generated by the shorthand command nx g @webundsoehne/nx-nest:res <component> <name> <project> i.e. nx g @webundsoehne/nx-nest:res server user app-api
component == seeder ignores any project option and will always generate the seed and factory file into the seeder lib folder.
Database Target
Generates the package.json scripts and project.json targets to manage db migrations.
Names: database-target, dbt
Options:
| Option | Type | Description | | ------- | ------ | -------------------------------------------------------- | | project | string | in/for which project to generate the scripts and targets |
Seeder
Generates a seeder library for e.g. seeding database entries.
Names: seeder, seed
