Overview
The CLI (command-line interface) tool helps you to create ExpressoTS projects and scaffold ExpressoTS resources.
We use the npm
in this tutorial for simplicity. However, you can use your preferred package manager (yarn
or pnpm
) by replacing npm
with the appropriate command.
Installation
First install the CLI globally using the command below:
npm install -g @expressots/cli
Commands available
The CLI provides the following commands:
Name | Alias | Description |
---|---|---|
new project | new | Generate a new project |
info | i | Provides project information |
resources | r | Displays CLI commands and resources |
scripts | scripts | Run scripts list or a specific script |
help | help | Show command help |
service | g s | Generate a service [controller, usecase, dto, module] |
controller | g c | Generate a controller |
usecase | g u | Generate a usecase |
dto | g d | Generate a DTO |
entity | g e | Generate an entity |
provider | g p | Generate internal provider |
provider | add | Add external provider to the project |
provider | remove | remove external provider |
provider | create | Create external provider |
module | g mo | Generate a module |
middleware | g mi | Generate a middleware |
Usage examples
You can use the CLI either with:
expressots
ex
as an alias.
Command example:
expressots <command> [options]
// Or
ex <command> [options]
Help command
Verify the available commands and options:
expressots help
Info command
Providers information about your Operational System, Project and CLI version:
expressots info
Resources list
List all available resources to scaffold:
expressots resources (Alias: r)
Create a project
There are two options to create a new project, interactively or silently (passing the options as arguments). Here is the complete command syntax:
expressots new <project-name> -p <package-manager> -t <template> -d <directory>
Interactively
expressots new <project-name>
Silently
expressots new <project-name> -p <package-manager> -t <template> -d <directory>
- package-manager:
npm
,yarn
orpnpm
- template:
opinionated
ornon-opinionated
- directory:
./my-project
The flag -d
is optional and is used to specify the directory where the project will be created. If not specified, the project will be created in the current directory.
Add a provider
Add an external provider to the project:
expressots add <provider-name>
Although you can add npm registry packages, the primary use case for this command is to add providers that were built specifically for ExpressoTS.
Create a provider
Create a new ExpressoTS provider. For more information about providers, check the Providers section.
expressots create <provider-name>
Scaffold resources
The CLI provides commands to scaffold resources like controller
, usecase
, dto
, entity
, module
and middleware
.
expressots generate <resource> <name> [options]
Resources are created in the src
directory by default. They also can be scaffolded in 2 different ways: passing the path
or using the shorthand operation
.
The resource scaffolding operations produce different results based on the project template used. The opinionated
template provides a more structured project, while the non-opinionated
template provides a more flexible project structure.
- Non Opinionated
- Opinionated
Passing the path
expressots g c services/user
src
└── services
└── user.controller.ts
Shorthand operation
expressots g c services-user
src
└── services
└── user
└── services-user.controller.ts
In the opinionated
template, the scaffolded resources are created following a predefined structure.
Passing the path
expressots g c services/user
The command above will create a controller named user
inside the useCases/services
directory.
src
└── useCases
└── services
└── user.controller.ts
useCases
directory.Shorthand operation
expressots g c services-user
The command above will create a controller named services-user
inside the useCases/services/user
directory.
src
└── useCases
└── services
└── user
└── services-user.controller.ts
Using the shorthand operation in the opinionated template offers significant benefits. It creates a well-structured project that's easier to navigate and understand. When you scaffold with the shorthand, the CLI automatically places resources in the correct directories, adds controllers to their modules, and integrates the module into the container.
Support us ❤️
ExpressoTS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please read our support guide.