mirror of
https://github.com/strapi/strapi.git
synced 2025-07-23 00:51:17 +00:00
289 lines
10 KiB
Markdown
289 lines
10 KiB
Markdown
# Command Line Interface (CLI)
|
|
|
|
Strapi comes with a full featured Command Line Interface (CLI) which lets you scaffold and manage your project in seconds.
|
|
|
|
---
|
|
|
|
## strapi new
|
|
|
|
Create a new project.
|
|
|
|
```bash
|
|
strapi new <name>
|
|
|
|
options: [--debug|--quickstart|--dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbname=<dbname> --dbusername=<dbusername> --dbpassword=<dbpassword> --dbssl=<dbssl> --dbauth=<dbauth> --dbforce]
|
|
```
|
|
|
|
- **strapi new <name>**<br/>
|
|
Generates a new project called **<name>** and installs the default plugins through the npm registry.
|
|
|
|
- **strapi new <name> --debug**<br/>
|
|
Will display the full error message if one is fired during the database connection.
|
|
|
|
- **strapi new <name> --quickstart**<br/>
|
|
Use the quickstart system to create your app.
|
|
|
|
- **strapi new <name> --dbclient=<dbclient> --dbhost=<dbhost> --dbport=<dbport> --dbname=<dbname> --dbusername=<dbusername> --dbpassword=<dbpassword> --dbssl=<dbssl> --dbauth=<dbauth> --dbforce**<br/>
|
|
|
|
Generates a new project called **<name>** and skip the interactive database configuration and initialize with these options.
|
|
|
|
- **<dbclient>** can be `mongo`, `postgres`, `mysql`.
|
|
- **<dbssl>** and **<dbauth>** are available only for `mongo` and are optional.
|
|
- **--dbforce** Allows you to overwrite content if the provided database is not empty. Only available for `postgres`, `mysql`, and is optional.
|
|
|
|
## strapi develop|dev
|
|
|
|
Start a Strapi application with autoReload enabled.
|
|
|
|
Strapi modifies/creates files at runtime and needs to restart when new files are created. To achieve this, `strapi develop` adds a file watcher and restarts the application when necessary.
|
|
|
|
::: note
|
|
You should never use this command to run a Strapi application in production.
|
|
:::
|
|
|
|
## strapi start
|
|
|
|
Start a Strapi application with autoReload disabled.
|
|
|
|
This commands is there to run a Strapi application without restarts and file writes (aimed at production usage).
|
|
Certain features are disabled in the `strapi start` mode because they require application restarts.
|
|
|
|
::: note
|
|
You can specify a NODE_ENV to use the configurations in the `./config/environments/[development|staging|production]` folder.
|
|
By default the `development` environment will be used.
|
|
:::
|
|
|
|
## strapi build
|
|
|
|
Builds your admin panel.
|
|
|
|
::: note
|
|
You can specify a NODE_ENV to use the configurations in the `./config/environments/[development|staging|production]` folder.
|
|
By default the `development` environment will be used.
|
|
:::
|
|
|
|
## strapi generate:api
|
|
|
|
Scaffold a complete API with its configurations, controller, model and service.
|
|
|
|
```bash
|
|
strapi generate:api <name> [<attribute:type>]
|
|
|
|
options: [--tpl <name>|--plugin <name>]
|
|
```
|
|
|
|
- **strapi generate:api <name>**<br/>
|
|
Generates an API called **<name>** in the `./api` folder at the root of your project.
|
|
|
|
- **strapi generate:api <name> <attribute:type>**<br/>
|
|
Generates an API called **<name>** in the `./api` folder at the root of your project. The model will already contain an attribute called **<attribute>** with the type property set to **<type>**.
|
|
|
|
Example: `strapi generate:api product name:string description:text price:integer`
|
|
|
|
- **strapi generate:api <name> --plugin <plugin>**<br/>
|
|
Generates an API called **<name>** in the `./plugins/<plugin>` folder.
|
|
|
|
Example: `strapi generate:api product --plugin content-manager`
|
|
|
|
- **strapi generate:api <name> --tpl <template>**<br/>
|
|
Generates an API called **<name>** in the `./api` folder which works with the given **<template>**. By default, the generated APIs are based on Mongoose.
|
|
|
|
Example: `strapi generate:api product --tpl bookshelf`
|
|
|
|
::: note
|
|
The first letter of the filename will be uppercase.
|
|
:::
|
|
|
|
## strapi generate:controller
|
|
|
|
Create a new controller.
|
|
|
|
```bash
|
|
strapi generate:controller <name>
|
|
|
|
options: [--api <name>|--plugin <name>]
|
|
```
|
|
|
|
- **strapi generate:controller <name>**<br/>
|
|
Generates an empty controller called **<name>** in the `./api/<name>/controllers` folder.
|
|
|
|
Example: `strapi generate:controller category` will create the controller at `./api/category/controllers/Category.js`.
|
|
|
|
- **strapi generate:controller <name> --api <api>**<br/>
|
|
Generates an empty controller called **<name>** in the `./api/<api>/controllers` folder.
|
|
|
|
Example: `strapi generate:controller category --api product` will create the controller at `./api/product/controllers/Category.js`.
|
|
|
|
- **strapi generate:controller <name> --plugin <plugin>**<br/>
|
|
Generates an empty controller called **<name>** in the `./plugins/<plugin>/controllers` folder.
|
|
|
|
::: note
|
|
The first letter of the filename will be uppercase.
|
|
:::
|
|
|
|
## strapi generate:model
|
|
|
|
Create a new model.
|
|
|
|
```bash
|
|
strapi generate:model <name> [<attribute:type>]
|
|
|
|
options: [--api <name>|--plugin <name>]
|
|
```
|
|
|
|
- **strapi generate:model <name>**<br/>
|
|
Generates an empty model called **<name>** in the `./api/<name>/models` folder. It will create two files.
|
|
The first one will be **<name>.js** which contains your lifecycle callbacks and another **<name>.settings.json** that will list your attributes and options.
|
|
|
|
Example: `strapi generate:model category` will create these two files `./api/category/models/Category.js` and `./api/category/models/Category.settings.json`.
|
|
|
|
- **strapi generate:model <name> <attribute:type>**<br/>
|
|
Generates an empty model called **<name>** in the `./api/<name>/models` folder. The file **<name>.settings.json** will already contain a list of attribute with their associated **<type>**.
|
|
|
|
Example: `strapi generate:model category name:string description:text` will create these two files `./api/category/models/Category.js` and `./api/category/models/Category.settings.json`. This last file will contain two attributes `name` with the type `string` and `description` with type `text`.
|
|
|
|
- **strapi generate:model <name> --api <api>**<br/>
|
|
Generates an empty model called **<name>** in the `./api/<api>/models` folder.
|
|
|
|
Example: `strapi generate:model category --api product` will create these two files:
|
|
|
|
- `./api/product/models/Category.js`
|
|
- `./api/product/models/Category.settings.json`.
|
|
|
|
* **strapi generate:model <name> --plugin <plugin>**<br/>
|
|
Generates an empty model called **<name>** in the `./plugins/<plugin>/models` folder.
|
|
|
|
::: note
|
|
The first letter of the filename will be uppercase.
|
|
:::
|
|
|
|
## strapi generate:service
|
|
|
|
Create a new service.
|
|
|
|
```bash
|
|
strapi generate:service <name>
|
|
|
|
options: [--api <name>|--plugin <name>]
|
|
```
|
|
|
|
- **strapi generate:service <name>**<br/>
|
|
Generates an empty service called **<name>** in the `./api/<name>/services` folder.
|
|
|
|
Example: `strapi generate:service category` will create the service at `./api/category/services/Category.js`.
|
|
|
|
- **strapi generate:service <name> --api <api>**<br/>
|
|
Generates an empty service called **<name>** in the `./api/<api>/services` folder.
|
|
|
|
Example: `strapi generate:service category --api product` will create the service at `./api/product/services/Category.js`.
|
|
|
|
- **strapi generate:service <name> --plugin <plugin>**<br/>
|
|
Generates an empty service called **<name>** in the `./plugins/<plugin>/services` folder.
|
|
|
|
::: note
|
|
The first letter of the filename will be uppercase.
|
|
:::
|
|
|
|
## strapi generate:policy
|
|
|
|
Create a new policy.
|
|
|
|
```bash
|
|
strapi generate:policy <name>
|
|
|
|
options: [--api <name>|--plugin <name>]
|
|
```
|
|
|
|
- **strapi generate:policy <name>**<br/>
|
|
Generates an empty policy called **<name>** in the `./config/policies` folder.
|
|
|
|
Example: `strapi generate:policy isAuthenticated` will create the policy at `./config/policies/isAuthenticated.js`.
|
|
|
|
- **strapi generate:policy <name> --api <api>**<br/>
|
|
Generates an empty policy called **<name>** in the `./api/<api>/config/policies` folder. This policy will be scoped and only accessible by the **<api>** routes.
|
|
|
|
Example: `strapi generate:policy isAuthenticated --api product` will create the policy at `./api/product/config/policies/isAuthenticated.js`.
|
|
|
|
- **strapi generate:policy <name> --plugin <plugin>**<br/>
|
|
Generates an empty policy called **<name>** in the `./plugins/<plugin>/config/policies` folder. This policy will be scoped and accessible only by the **<plugin>** routes.
|
|
|
|
## strapi generate:plugin
|
|
|
|
Create a new plugin skeleton.
|
|
|
|
```bash
|
|
strapi generate:plugin <name>
|
|
```
|
|
|
|
- **strapi generate:plugin <name>**<br/>
|
|
Generates an empty plugin called **<name>** in the `./plugins` folder.
|
|
|
|
Example: `strapi generate:plugin user` will create the plugin at `./plugins/user`.
|
|
|
|
Please refer to the [local plugins](../plugin-development/quick-start.md) section to know more.
|
|
|
|
---
|
|
|
|
## strapi install
|
|
|
|
Install a plugin in the project.
|
|
|
|
```bash
|
|
strapi install <name>
|
|
```
|
|
|
|
- **strapi install <name>**<br/>
|
|
Installs a plugin called **<name>**.
|
|
|
|
Example: `strapi install graphql` will install the plugin `strapi-plugin-graphql`
|
|
|
|
::: warning
|
|
Some plugins have admin panel integrations, your admin panel might have to be rebuilt. This can take some time.
|
|
:::
|
|
|
|
---
|
|
|
|
## strapi uninstall
|
|
|
|
Uninstall a plugin from the project.
|
|
|
|
```bash
|
|
strapi uninstall <name>
|
|
|
|
options [--delete-files]
|
|
```
|
|
|
|
- **strapi uninstall <name>**<br/>
|
|
Uninstalls a plugin called **<name>**.
|
|
|
|
Example: `strapi uninstall graphql` will remove the plugin `strapi-plugin-graphql`
|
|
|
|
- **strapi uninstall <name> --delete-files**<br/>
|
|
Uninstalls a plugin called **<name>** and removes the files in `./extensions/name/`
|
|
|
|
Example: `strapi uninstall graphql` will remove the plugin `strapi-plugin-graphql` and all the files in `./extensions/graphql`
|
|
|
|
::: warning
|
|
Some plugins have admin panel integrations, your admin panel might have to be rebuilt. This can take some time.
|
|
:::
|
|
|
|
---
|
|
|
|
## strapi version
|
|
|
|
Print the current globally installed Strapi version.
|
|
|
|
```bash
|
|
strapi version
|
|
```
|
|
|
|
---
|
|
|
|
## strapi help
|
|
|
|
List CLI commands.
|
|
|
|
```
|
|
strapi help
|
|
```
|