Skip to content
LeChatErrant edited this page Dec 18, 2021 · 16 revisions

CLI

The template comes with a Command-Line Interface that helps you to initialize, develop and maintain your projects.

It essentially saves your time by writing boilerplate code for you

Installation

The CLI is listed in the dev-dependencies of the template, so all you need to do is

  1. npm install
  2. npm run cli

If you want to, you can install the cli globally with npm install -g templated-project-cli to be able to launch it with from anywhere

Create new resource

Each time you want to add a new resource to your API, you need to write some boilerplate code (router, middlewares, controllers, tests, and more...)

CLI - Generate

The CLI saves your time by writing this code for you

  1. npm run cli
  2. Choose generate new API resource
  3. Enter the name of the resource to be created (singular form)
  4. The CLI will infer the plural form. In case it is not correct, you can still write it by hand
  5. Relax and take a coffee

You now have a basic CRUD example

The only thing left is to add some data in the database model and to add custom logic in controllers. Enjoy !

However, all the generated code is instantly functional without needing any modification

Details of what is generated

  • Default model in schema.prisma
  • Relations with other existing models in schema.prisma
  • New directory in src/routes
  • Default example routes with CRUD and protections (auth, validation...)
  • Default CRUD controllers
  • DTOs, ROs, assemblers
  • Integration tests skeleton
  • Resource linked in src/routes/index.ts
  • ORM re-generated
Clone this wiki locally