From 0eaa4da037c7b4187493603a4c3648e319c5cf58 Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Wed, 29 Oct 2025 13:13:59 +0100 Subject: [PATCH 1/3] docs: add documentation about the strapi-plugin generate command --- .../cms/plugins-development/plugin-sdk.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docusaurus/docs/cms/plugins-development/plugin-sdk.md b/docusaurus/docs/cms/plugins-development/plugin-sdk.md index 9b8ea97e1c..b8c24ed996 100644 --- a/docusaurus/docs/cms/plugins-development/plugin-sdk.md +++ b/docusaurus/docs/cms/plugins-development/plugin-sdk.md @@ -76,6 +76,31 @@ strapi-plugin watch | `-d, --debug` | - | Enable debugging mode with verbose logs | false | | `--silent` | - | Do not log anything | false | +## strapi-plugin generate + +Generate APIs, [controllers](/cms/backend-customization/controllers), [content-types](/cms/backend-customization/models), [policies](/cms/backend-customization/policies), [middlewares](/cms/backend-customization/middlewares) and [services](/cms/backend-customization/services) for your plugin. + +```bash +strapi-plugin generate +``` + +| Option | Type | Description | Default | +| ------------- | :--: | --------------------------------------- | ------- | +| `-d, --debug` | - | Enable debugging mode with verbose logs | false | +| `--silent` | - | Do not log anything | false | + +The command displays an interactive menu with the following options: + +- **api** - Generate a new API with controller and service +- **controller** - Generate a new controller +- **content-type** - Generate a new content type with schema +- **policy** - Generate a new policy +- **middleware** - Generate a new middleware +- **service** - Generate a new service + +The generator detects TypeScript or JavaScript automatically and creates files with the correct extension (`.ts` or `.js`). +Generated files include commented examples. Singular and plural names must be different and use kebab-case format. + ## strapi-plugin verify Verify the output of the plugin before publishing it. From 1bd6894c674fdb5b8cf7468dc09a4aba72efd965 Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Wed, 29 Oct 2025 14:44:25 +0100 Subject: [PATCH 2/3] fix: update original generate command references --- .../docs/cms/plugins-development/admin-panel-api.md | 2 +- .../plugins-development/guides/store-and-access-data.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docusaurus/docs/cms/plugins-development/admin-panel-api.md b/docusaurus/docs/cms/plugins-development/admin-panel-api.md index 779f082484..8fa91b5958 100644 --- a/docusaurus/docs/cms/plugins-development/admin-panel-api.md +++ b/docusaurus/docs/cms/plugins-development/admin-panel-api.md @@ -41,7 +41,7 @@ The Admin Panel API includes: - and several [specific APIs](#available-actions) for your plugin to interact with the admin panel. :::note -The whole code for the admin panel part of your plugin could live in the `/strapi-admin.js|ts` or `/admin/src/index.js|ts` file. However, it's recommended to split the code into different folders, just like the [structure](/cms/plugins-development/plugin-structure) created by the `strapi generate plugin` CLI generator command. +The whole code for the admin panel part of your plugin could live in the `/strapi-admin.js|ts` or `/admin/src/index.js|ts` file. However, it's recommended to split the code into different folders, just like the [structure](/cms/plugins-development/plugin-structure) created by the `npx @strapi/sdk-plugin init` CLI generator command. ::: ## Entry file diff --git a/docusaurus/docs/cms/plugins-development/guides/store-and-access-data.md b/docusaurus/docs/cms/plugins-development/guides/store-and-access-data.md index 48593324be..73e62d4c7a 100644 --- a/docusaurus/docs/cms/plugins-development/guides/store-and-access-data.md +++ b/docusaurus/docs/cms/plugins-development/guides/store-and-access-data.md @@ -21,13 +21,13 @@ To store data with a Strapi [plugin](/cms/plugins-development/developing-plugins ## Create a content-type for your plugin -To create a content-type with the CLI generator, run the following command in a terminal within the `server/src/` directory of your plugin: +To create a content-type with the CLI generator, run the following command in a terminal within the root of your Strapi project: ```bash -yarn strapi generate content-type +yarn strapi generate ``` @@ -35,7 +35,7 @@ yarn strapi generate content-type ```bash -npm run strapi generate content-type +npm run strapi generate ``` @@ -100,7 +100,7 @@ The following highlighted lines in an example `schema.json` file show how to mak ### Ensure plugin content-types are imported -The CLI generator might not have imported all the related content-type files for your plugin, so you might have to make the following adjustments after the `strapi generate content-type` CLI command has finished running: +The CLI generator might not have imported all the related content-type files for your plugin, so you might have to make the following adjustments after the `strapi generate` CLI command has finished running: 1. In the `/server/index.js` file, import the content-types: From fe38ce3783fc9bb4739eb537c2d62741c9d5d6d1 Mon Sep 17 00:00:00 2001 From: Boaz Poolman Date: Wed, 29 Oct 2025 15:21:50 +0100 Subject: [PATCH 3/3] docs: add more documentation about the generators on the server API page --- .../guides/store-and-access-data.md | 6 ++-- .../cms/plugins-development/server-api.md | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/docusaurus/docs/cms/plugins-development/guides/store-and-access-data.md b/docusaurus/docs/cms/plugins-development/guides/store-and-access-data.md index 73e62d4c7a..a391e6cf53 100644 --- a/docusaurus/docs/cms/plugins-development/guides/store-and-access-data.md +++ b/docusaurus/docs/cms/plugins-development/guides/store-and-access-data.md @@ -27,7 +27,7 @@ To create a content-type with the CLI generator, run the following command in a ```bash -yarn strapi generate +yarn strapi generate content-type ``` @@ -35,7 +35,7 @@ yarn strapi generate ```bash -npm run strapi generate +npm run strapi generate content-type ``` @@ -100,7 +100,7 @@ The following highlighted lines in an example `schema.json` file show how to mak ### Ensure plugin content-types are imported -The CLI generator might not have imported all the related content-type files for your plugin, so you might have to make the following adjustments after the `strapi generate` CLI command has finished running: +The CLI generator might not have imported all the related content-type files for your plugin, so you might have to make the following adjustments after the `strapi generate content-type` CLI command has finished running: 1. In the `/server/index.js` file, import the content-types: diff --git a/docusaurus/docs/cms/plugins-development/server-api.md b/docusaurus/docs/cms/plugins-development/server-api.md index df6a24bcb6..5d913f59b7 100644 --- a/docusaurus/docs/cms/plugins-development/server-api.md +++ b/docusaurus/docs/cms/plugins-development/server-api.md @@ -250,6 +250,13 @@ An object with the [content-types](/cms/backend-customization/models) the plugin Content-Types keys in the `contentTypes` object should re-use the `singularName` defined in the [`info`](/cms/backend-customization/models#model-information) key of the schema. ::: +:::tip +You can scaffold a content-type by using the [generate command](/cms/plugins-development/plugin-sdk#strapi-plugin-generate) inside the root of your plugin: +```bash +strapi-plugin generate content-type +``` +::: + **Example:** @@ -527,6 +534,13 @@ An object with the [controllers](/cms/backend-customization/controllers) the plu **Type**: `Object` +:::tip +You can scaffold a controller by using the [generate command](/cms/plugins-development/plugin-sdk#strapi-plugin-generate) inside the root of your plugin: +```bash +strapi-plugin generate controller +``` +::: + **Example:** @@ -629,6 +643,13 @@ Services should be functions taking `strapi` as a parameter. **Type**: `Object` +:::tip +You can scaffold a service by using the [generate command](/cms/plugins-development/plugin-sdk#strapi-plugin-generate) inside the root of your plugin: +```bash +strapi-plugin generate service +``` +::: + **Example:** @@ -725,6 +746,13 @@ An object with the [policies](/cms/backend-customization/policies) the plugin pr **Type**: `Object` +:::tip +You can scaffold a policy by using the [generate command](/cms/plugins-development/plugin-sdk#strapi-plugin-generate) inside the root of your plugin: +```bash +strapi-plugin generate policy +``` +::: + **Example:** @@ -817,6 +845,13 @@ An object with the [middlewares](/cms/configurations/middlewares) the plugin pro **Type**: `Object` +:::tip +You can scaffold a middleware by using the [generate command](/cms/plugins-development/plugin-sdk#strapi-plugin-generate) inside the root of your plugin: +```bash +strapi-plugin generate middleware +``` +::: + **Example:**