Skip to content

Commit

Permalink
feat: add plugin cli docs page (#1965)
Browse files Browse the repository at this point in the history
* feat: add plugin cli docs page

* chore: edit create-a-plugin page

* Fix unwanted line indentation changes

* Split content into a guide and a reference

* Add guide to plugins development intro.

* Add Plugin CLI docs to TOC

* Fix capitalization

* Fix SEO for reference page

---------

Co-authored-by: Pierre Wizla <[email protected]>
  • Loading branch information
joshuaellis and pwizla authored Feb 20, 2024
1 parent 7f245a7 commit 00dc22d
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 27 deletions.
1 change: 1 addition & 0 deletions docusaurus/docs/dev-docs/plugins/developing-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Plugins can also be used to add [custom fields](/dev-docs/custom-fields) to Stra

<CustomDocCard small emoji="💁" title="How to store and access data from a Strapi plugin" description="" link="/dev-docs/plugins/guides/store-and-access-data" />
<CustomDocCard small emoji="💁" title="How to pass data from the backend server to the admin panel with a plugin" description="" link="/dev-docs/plugins/guides/pass-data-from-server-to-admin" />
<CustomDocCard small emoji="💁" title="How to use the experimental Plugin CLI to create and publish a Strapi plugin" description="" link="/dev-docs/plugins/guides/use-the-plugin-cli" />

<br />

Expand Down
53 changes: 26 additions & 27 deletions docusaurus/docs/dev-docs/plugins/development/create-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ To start developing a Strapi plugin, you need to:

:::prerequisites
You created a Strapi project.

<details>
<summary>Use the CLI to create a project:</summary>

Expand All @@ -40,6 +41,7 @@ npx create-strapi-app@latest my-project --quickstart
</Tabs>

More details can be found in the [CLI installation guide](/dev-docs/installation/cli).

</details>
:::

Expand All @@ -51,21 +53,21 @@ The fastest way to create a Strapi plugin is to use the CLI generator. To do so:
2. Run the following command in a terminal window to start the interactive CLI:

<Tabs groupId="yarn-npm">
<TabItem value="yarn" label="Yarn">
<TabItem value="yarn" label="Yarn">

```sh
yarn strapi generate plugin
yarn strapi generate plugin
```

</TabItem>
</TabItem>

<TabItem value="npm" label="NPM">
<TabItem value="npm" label="NPM">

```sh
npm run strapi generate plugin
```

</TabItem>
</TabItem>
</Tabs>

4. Choose either `JavaScript` or `TypeScript` for the plugin language.
Expand All @@ -80,22 +82,23 @@ To enable a plugin:
2. Enable the plugin by adding the following code to the plugins configuration file:

<Tabs>
<TabItem value="js" label="JavaScript">
<TabItem value="js" label="JavaScript">

```js title="./config/plugins.js"
module.exports = {
// ...
"my-plugin": { // name of your plugin, kebab-cased
enabled: true,
resolve: "./src/plugins/my-plugin", // path to the plugin folder
},
// ...
};
```
```js title="./config/plugins.js"
module.exports = {
// ...
"my-plugin": {
// name of your plugin, kebab-cased
enabled: true,
resolve: "./src/plugins/my-plugin", // path to the plugin folder
},
// ...
};
```

</TabItem>
</TabItem>

<TabItem value="ts" label="TypeScript">
<TabItem value="ts" label="TypeScript">

```js title=./config/plugins.ts
export default {
Expand All @@ -108,7 +111,7 @@ To enable a plugin:
};
```

</TabItem>
</TabItem>
</Tabs>

:::tip
Expand Down Expand Up @@ -146,18 +149,18 @@ Once the plugin code has been generated and the plugin is enabled, the next step
</Tabs>

3. Navigate back to the Strapi project root with `cd ../../..` and run the following command to build the admin panel and start the server(s):

<Tabs groupId="yarn-npm">
<TabItem value="yarn" label="Yarn">

```sh
yarn develop
```

</TabItem>

<TabItem value="npm" label="NPM">

```sh
npm run develop
```
Expand Down Expand Up @@ -225,7 +228,7 @@ Once the plugin code has been generated and the plugin is enabled, the next step
</TabItem>

<TabItem value="npm" label="NPM">

```sh
npm run develop
```
Expand All @@ -242,10 +245,6 @@ You should now be ready to start developing your plugin.
You can either jump to the [plugin structure](/dev-docs/plugins/development/plugin-structure) documentation or read the [servers and hot reloading](#servers-and-hot-reloading) section to learn more about different ways to start the server.
:::

:::info Did you know?
The admin panel needs to be rebuilt after its code has been modified. Rebuilding the admin panel is done by running the `build` command. The `strapi generate plugin` generates code that injects some plugin components (menu link, plugin homepage) into the admin panel. That's why we run the `build` command after the plugin code has been generated and before starting the server.
:::

### Servers and hot reloading

Strapi itself is **headless** <HeadlessCms />. The admin panel is completely separate from the server.
Expand Down
87 changes: 87 additions & 0 deletions docusaurus/docs/dev-docs/plugins/development/plugin-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: Plugin CLI
description: Reference documentation for Strapi's Plugin CLI commands
displayed_sidebar: devDocsSidebar
---

# Plugin CLI reference

:::caution
The Plugin CLI is currently experimental.
:::

The Plugin CLI is set of commands orientated around developing plugins to use them as local plugins or to publish them on NPM and/or submit them to the Marketplace.

The present documentation lists the available Plugin CLI commands. The [associated guide](/dev-docs/plugins/guides/use-the-plugin-cli) illustrates how to use these commands to create a plugin from scratch, link it to an existing project, and publish it.

## strapi plugin:init

Create a new plugin at a given path.

```bash
strapi plugin:init <path>
```

| Arguments | Type | Description | Default |
| --------- | :----: | --------------------| ------------------------- |
| `path` | string | Path to the plugin | `./src/plugins/my-plugin` |

| Option | Type | Description | Default |
| ------------- | :--: | ---------------------------------------- |---------|
| `-d, --debug` | - | Enable debugging mode with verbose logs | false |
| `--silent` | - | Do not log anything | false |

## strapi plugin:build

Bundle the strapi plugin for publishing.

```bash
strapi plugin:build
```

| Option | Type | Description | Default |
| -------------- | :----: | ----------------------------------------------------------------------------------------------------------------- | --------|
| `--force` | string | Automatically answer "yes" to all prompts, including potentially destructive requests, and run non-interactively. | - |
| `-d, --debug` | - | Enable debugging mode with verbose logs | false |
| `--silent` | - | Do not log anything | false |
| `--minify` | - | Minify the output | true |
| `--sourcemaps` | - | Produce sourcemaps | false |

## strapi plugin:link-watch

Recompiles the plugin automatically on changes and runs `yalc push --publish`.

```bash
strapi plugin:link-watch
```

| Option | Type | Description | Default |
| ------------- | :--: | -------------------------------------------------------- | --------|
| `-d, --debug` | - | Enable debugging mode with verbose logs | false |
| `--silent` | - | Do not log anything | false |

## strapi plugin:watch

Watch and compile the Strapi plugin for local development.

```bash
strapi plugin:watch
```

| Option | Type | Description | Default |
| ------------- | :--: | -------------------------------------------------------- |---------|
| `-d, --debug` | - | Enable debugging mode with verbose logs | false |
| `--silent` | - | Do not log anything | false |

## strapi plugin:verify

Verify the output of the plugin before publishing it.

```bash
strapi plugin:verify
```

| Option | Type | Description | Default |
| ------------- | :--: | -------------------------------------------------------- | --------|
| `-d, --debug` | - | Enable debugging mode with verbose logs | false |
| `--silent` | - | Do not log anything | false |
Loading

0 comments on commit 00dc22d

Please sign in to comment.