Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 45 additions & 142 deletions docs/developer-docs/latest/developer-resources/cli/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ options: [--no-optimization]
- **strapi build --no-optimization**<br/>
Builds the administration panel without minimizing the assets. The build duration is faster.

## strapi watch-admin

Starts the admin server. Strapi should already be running with `strapi develop`.

```sh
strapi watch-admin
options: [--browser <name>]
```

## strapi configuration:dump

**Alias**: `config:dump`
Expand Down Expand Up @@ -183,181 +192,75 @@ strapi admin:reset-user-password --email=chef@strapi.io --password=Gourmet1234
| -p, --password | string | New password for the user |
| -h, --help | | display help for command |

## strapi generate:api
## strapi generate

Scaffold a complete API with its configurations, controller, model and service.
Run a fully interactive CLI to generate APIs, [controllers](/developer-docs/latest/development/backend-customization/controllers.md), [content-types](/developer-docs/latest/development/backend-customization/models.md), [plugins](/developer-docs/latest/development/plugins-development.md#creating-a-plugin), [policies](/developer-docs/latest/development/backend-customization/policies.md), [middlewares](/developer-docs/latest/development/backend-customization/middlewares.md) and [services](/developer-docs/latest/development/backend-customization/services.md).

```bash
strapi generate:api <name> [<attribute:type>]

options: [--plugin <name>]
```sh
strapi generate
```

- **strapi generate:api &#60;name&#62;**<br/>
Generates an API called **&#60;name&#62;** in the `./api` folder at the root of your project.

- **strapi generate:api &#60;name&#62; --draft-and-publish=true**<br/>
Generates an API called **&#60;name&#62;** in the `./api` folder at the root of your project and enabled the draft/publish feature.

- **strapi generate:api &#60;name&#62; &#60;attribute:type&#62;**<br/>
Generates an API called **&#60;name&#62;** in the `./api` folder at the root of your project. The model will already contain an attribute called **&#60;attribute&#62;** with the type property set to **&#60;type&#62;**.

Example: `strapi generate:api product name:string description:text price:integer`

- **strapi generate:api &#60;name&#62; --plugin &#60;plugin&#62;**<br/>
Generates an API called **&#60;name&#62;** in the `./plugins/<plugin>` folder.

Example: `strapi generate:api product --plugin content-manager`

::: tip TIPS
* The filename will be kebab-cased.
* When you create a new API using the CLI, a model is automatically created.
:::

## strapi generate:controller
## strapi generate:template

Create a new controller.
Create a template from the current strapi project

```bash
strapi generate:controller <name>

options: [--api <name>|--plugin <name>]
strapi generate:template <path>
```

- **strapi generate:controller &#60;name&#62;**<br/>
Generates an empty controller called **&#60;name&#62;** in the `./api/<name>/controllers` folder.

Example: `strapi generate:controller category` will create the controller at `./api/category/controllers/Category.js`.

- **strapi generate:controller &#60;name&#62; --api &#60;api&#62;**<br/>
Generates an empty controller called **&#60;name&#62;** 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 &#60;name&#62; --plugin &#60;plugin&#62;**<br/>
Generates an empty controller called **&#60;name&#62;** in the `./plugins/<plugin>/controllers` folder.

::: tip
The first letter of the filename will be uppercase.
:::
- **strapi generate:template &#60;path&#62;**<br/>
Generates a Strapi template at `<path>`

## strapi generate:model
Example: `strapi generate:template ../strapi-template-name` will copy the required files and folders to a `template` directory inside `../strapi-template-name`

Create a new model.
## strapi routes:list

```bash
strapi generate:model <name> [<attribute:type>]
Display a list of all the available [routes](/developer-docs/latest/development/backend-customization/routes.md).

options: [--api <name>|--plugin <name>|--draft-and-publish <boolean>]
```sh
strapi routes:list
```

- **strapi generate:model &#60;name&#62;**<br/>
Generates an empty model called **&#60;name&#62;** in the `./api/<name>/models` folder. It will create two files.
The first one will be **&#60;name&#62;.js** which contains your lifecycle callbacks and another **&#60;name&#62;.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 &#60;name&#62; &#60;attribute:type&#62;**<br/>
Generates an empty model called **&#60;name&#62;** in the `./api/<name>/models` folder. The file **&#60;name&#62;.settings.json** will already contain a list of attribute with their associated **&#60;type&#62;**.

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 &#60;name&#62; --api &#60;api&#62;**<br/>
Generates an empty model called **&#60;name&#62;** 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 policies:list

* **strapi generate:model &#60;name&#62; --plugin &#60;plugin&#62;**<br/>
Generates an empty model called **&#60;name&#62;** in the `./plugins/<plugin>/models` folder.
Display a list of all the registered [policies](/developer-docs/latest/development/backend-customization/policies.md).

* **strapi generate:model &#60;name&#62; --draft-and-publish=true**<br/>
Generates an empty model called **&#60;name&#62;** in the `./plugins/<plugin>/models` folder with the draft/publish feature enabled

::: tip
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>]
```sh
strapi policies:list
```

- **strapi generate:service &#60;name&#62;**<br/>
Generates an empty service called **&#60;name&#62;** in the `./api/<name>/services` folder.

Example: `strapi generate:service category` will create the service at `./api/category/services/Category.js`.

- **strapi generate:service &#60;name&#62; --api &#60;api&#62;**<br/>
Generates an empty service called **&#60;name&#62;** in the `./api/<api>/services` folder.
## strapi middlewares:list

Example: `strapi generate:service category --api product` will create the service at `./api/product/services/Category.js`.
Display a list of all the registered [middlewares](/developer-docs/latest/development/backend-customization/middlewares.md).

- **strapi generate:service &#60;name&#62; --plugin &#60;plugin&#62;**<br/>
Generates an empty service called **&#60;name&#62;** in the `./plugins/<plugin>/services` folder.

::: tip
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>]
```sh
strapi middlewares:list
```

- **strapi generate:policy &#60;name&#62;**<br/>
Generates an empty policy called **&#60;name&#62;** in the `./config/policies` folder.

Example: `strapi generate:policy isAuthenticated` will create the policy at `./config/policies/isAuthenticated.js`.
## strapi content-types:list

- **strapi generate:policy &#60;name&#62; --api &#60;api&#62;**<br/>
Generates an empty policy called **&#60;name&#62;** in the `./api/<api>/config/policies` folder. This policy will be scoped and only accessible by the **&#60;api&#62;** routes.
Display a list of all the existing [content-types](/developer-docs/latest/development/backend-customization/models.md).

Example: `strapi generate:policy isAuthenticated --api product` will create the policy at `./api/product/config/policies/isAuthenticated.js`.

- **strapi generate:policy &#60;name&#62; --plugin &#60;plugin&#62;**<br/>
Generates an empty policy called **&#60;name&#62;** in the `./plugins/<plugin>/config/policies` folder. This policy will be scoped and accessible only by the **&#60;plugin&#62;** routes.

## strapi generate:plugin

Create a new plugin skeleton.

```bash
strapi generate:plugin <name>
```sh
strapi content-types:list
```

- **strapi generate:plugin &#60;name&#62;**<br/>
Generates an empty plugin called **&#60;name&#62;** in the `./plugins` folder.

Example: `strapi generate:plugin user` will create the plugin at `./plugins/user`.

Please refer to the [plugins development](/developer-docs/latest/development/plugins-development.md) section to know more.

## strapi generate:template
<!-- ? should we document this? only returns strapi::content-types.beforeSync and afterSync on a new project, and I don't want people to get confused as we officially "remove" hooks ? -->
## strapi hooks:list

Create a template from the current strapi project
Display a list of all the available hooks.

```bash
strapi generate:template <path>
```sh
strapi hooks:list
```

- **strapi generate:template &#60;path&#62;**<br/>
Generates a Strapi template at `<path>`
## strapi services:list

Example: `strapi generate:template ../strapi-template-name` will copy the required files and folders to a `template` directory inside `../strapi-template-name`
Display a list of all the registered [services](/developer-docs/latest/development/backend-customization/services.md).

```sh
strapi services:list
```

## strapi install

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Content-types and components models are created and stored differently.
Content-types in Strapi can be created:

- with the [Content-Types Builder in the admin panel](/user-docs/latest/content-types-builder/introduction-to-content-types-builder.md),
- or with [Strapi's CLI `generate:model`](/developer-docs/latest/developer-resources/cli/CLI.md#strapi-generate-model) command.
- or with [Strapi's interactive CLI `strapi generate`](/developer-docs/latest/developer-resources/cli/CLI.md#strapi-generate) command.

Creating a content-type with either method generates 2 files:

Expand Down
5 changes: 3 additions & 2 deletions docs/developer-docs/latest/development/plugins-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ To create a plugin, use Strapi CLI tools:

1. (_Optional_) If you don't already have an existing project, create a new development project with `strapi new myDevelopmentProject`.
2. Start the project with `cd myDevelopmentProject && strapi develop`.
3. In a new terminal window, [create a new plugin](/developer-docs/latest/developer-resources/cli/CLI.md#strapi-generate-plugin) with `cd /path/to/myDevelopmentProject && strapi generate:plugin my-plugin`
4. Enable the plugin by adding it to the [plugins configurations](/developer-docs/latest/setup-deployment-guides/configurations/optional/plugins.md) file:
3. In a new terminal window, run `cd /path/to/myDevelopmentProject && strapi generate` to launch the interactive `strapi generate` CLI.
4. Choose "plugin" from the list, press Enter, and give the plugin a name.
5. Enable the plugin by adding it to the [plugins configurations](/developer-docs/latest/setup-deployment-guides/configurations/optional/plugins.md) file:
```js
// path: /path/to/myDevelopmentProject/config/plugins.js

Expand Down
2 changes: 1 addition & 1 deletion docs/developer-docs/latest/plugins/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ To simplify and automate the build of the GraphQL schema, we introduced the Shad

**Example:**

If you've generated an API called `Restaurant` using the CLI `strapi generate:api restaurant` or the administration panel, your model looks like this:
If you've generated an API called `Restaurant` using [the interactive `strapi generate` CLI](/developer-docs/latest/developer-resources/cli/CLI.md#strapi-generate) or the administration panel, your model looks like this:

```json
// path: ./src/api/[api-name]/content-types/restaurant/schema.json
Expand Down