Skip to content

Commit b59574b

Browse files
committed
Add smaller adjustments to plugin dev. (creation & structure)
1 parent 5abb837 commit b59574b

File tree

3 files changed

+68
-68
lines changed

3 files changed

+68
-68
lines changed

docusaurus/docs/dev-docs/plugins/development/create-a-plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,5 @@ export default (config, webpack) => {
185185
```
186186

187187
:::caution
188-
Because the server looks at the `server/src/index.js` file to import your plugin code, you must use the `watch` command otherwise the code will not be transpiled and the server will not be able to find your plugin.
188+
Because the server looks at the `server/src/index.ts|js` file to import your plugin code, you must use the `watch` command otherwise the code will not be transpiled and the server will not be able to find your plugin.
189189
:::

docusaurus/docs/dev-docs/plugins/development/plugin-structure.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ import InteractivePluginStructure from '@site/src/components/PluginStructure.js'
1616

1717
# Plugin structure
1818

19-
When [creating a plugin with Plugin SDK](/dev-docs/plugins/development/create-a-plugin), Strapi generates the following boilerplate structure for you in the `./src/plugins/my-plugin` folder:
19+
When [creating a plugin with Plugin SDK](/dev-docs/plugins/development/create-a-plugin), Strapi generates the following boilerplate structure for you in the `/src/plugins/my-plugin` folder:
2020

2121
<InteractivePluginStructure />
2222

2323
A Strapi plugin is divided into 2 parts, each living in a different folder and offering a different API:
2424

2525
| Plugin part | Description | Folder | API |
2626
|-------------|-------------|--------------|-----|
27-
| Admin panel | Includes what will be visible in the [admin panel](/user-docs/intro) (components, navigation, settings, etc.) | `/admin` |[Admin Panel API](/dev-docs/plugins/admin-panel-api)|
28-
| Backend server | Includes what relates to the [backend server](/dev-docs/backend-customization) (content-types, controllers, middlewares, etc.) |`/server` |[Server API](/dev-docs/plugins/server-api)|
27+
| Admin panel | Includes what will be visible in the [admin panel](/user-docs/intro) (components, navigation, settings, etc.) | `admin/` |[Admin Panel API](/dev-docs/plugins/admin-panel-api)|
28+
| Backend server | Includes what relates to the [backend server](/dev-docs/backend-customization) (content-types, controllers, middlewares, etc.) |`server/` |[Server API](/dev-docs/plugins/server-api)|
2929

3030
<br />
3131

3232
:::note Notes about the usefulness of the different parts for your specific use case
3333
- **Server-only plugin**: You can create a plugin that will just use the server part to enhance the API of your application. For instance, this plugin could have its own visible or invisible content-types, controller actions, and routes that are useful for a specific use case. In such a scenario, you don't need your plugin to have an interface in the admin panel.
3434

35-
- **Admin panel plugin vs. application-specific customization**: You can create a plugin to inject some components into the admin panel. However, you can also achieve this by creating a `./src/admin/index.js` file and invoking the `bootstrap` lifecycle function to inject your components. In this case, deciding whether to create a plugin depends on whether you plan to reuse and distribute the code or if it's only useful for a unique Strapi application.
35+
- **Admin panel plugin vs. application-specific customization**: You can create a plugin to inject some components into the admin panel. However, you can also achieve this by creating a `/src/admin/index.js` file and invoking the `bootstrap` lifecycle function to inject your components. In this case, deciding whether to create a plugin depends on whether you plan to reuse and distribute the code or if it's only useful for a unique Strapi application.
3636
:::
3737

3838
<br/>

docusaurus/src/components/PluginStructure.js

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,69 @@ export default function InteractivePluginStructure() {
66
return (
77
<div className="project-structure">
88
<Tabs>
9+
<TabItem title="TypeScript-based projects" value="TypeScript-based plugins">
10+
11+
The following diagram is interactive: you can click on any file or folder name highlighted in purple to go to the corresponding documentation section.<br /><br />
12+
13+
<pre className="prism-code">
14+
<code>
15+
. <span className="token comment"># root of the plugin folder (e.g., /src/plugins/my-plugin)</span><br/>
16+
├── <a href="/dev-docs/plugins/admin-panel-api">admin</a> <span className="token comment"># Admin panel part of your plugin.</span><br/>
17+
│ ├── src<br />
18+
│ │ ├── components <span className="token comment"># Contains your front-end components</span><br/>
19+
│ │ │ ├── Initializer.tsx <span className="token comment"># Plugin initializer</span><br/>
20+
│ │ │ └── PluginIcon.tsx <span className="token comment"># Contains the icon of your plugin in the main navigation</span><br/>
21+
│ │ ├── pages <span className="token comment"># Contains the pages of your plugin</span><br/>
22+
│ │ │ ├── App.tsx <span className="token comment"># Skeleton around the actual pages</span><br/>
23+
│ │ │ └── HomePage.tsx <span className="token comment"># Homepage of your plugin</span><br/>
24+
│ │ ├── translations <span className="token comment"># Translations files to make your plugin i18n-friendly</span><br/>
25+
│ │ │ ├── en.json<br/>
26+
│ │ ├── utils<br/>
27+
│ │ │ └── getTranslations.ts <span className="token comment"># getTranslations function to return the corresponding plugin translations</span><br/>
28+
│ │ ├── index.ts <span className="token comment"># Main setup of your plugin, used to register elements in the admin panel</span><br/>
29+
│ │ └── pluginId.ts <span className="token comment"># pluginId variable computed from package.tsxon name</span><br/>
30+
│ ├── custom.d.ts <span className="token comment"># Generated types</span><br/>
31+
│ ├── tsconfig.build.json <span className="token comment"></span><br />
32+
│ └── tsconfig.json <span className="token comment"># TypeScript compiler options for the admin panel part</span><br />
33+
├── dist <span className="token comment"># Build of the plugin (front end and back end)</span><br/>
34+
├── node_modules<br />
35+
├── <a href="/dev-docs/plugins/server-api">server</a> <span className="token comment"># Back-end part of your plugin</span><br/>
36+
│ ├── src<br />
37+
│ │ ├── <a href="/dev-docs/plugins/server-api#configuration">config</a><br/>
38+
│ │ │ └── index.ts <span className="token comment"># Contains the default server configuration</span><br/>
39+
│ │ ├── <a href="/dev-docs/plugins/server-api#content-types">content-types</a> <span className="token comment"># Content-types specific to your plugin</span><br/>
40+
│ │ │ └── index.ts <span className="token comment"># Loads all the plugin's content-types</span><br />
41+
│ │ ├── <a href="/dev-docs/plugins/server-api#controllers">controllers</a> <span className="token comment"># Controllers specific to your plugin</span><br />
42+
│ │ │ ├── index.ts <span className="token comment"># Loads all the plugin's controllers</span><br/>
43+
│ │ │ └── controller.ts <span className="token comment"># Custom controller example. You can rename it or delete it.</span><br/>
44+
│ │ ├── <a href="/dev-docs/plugins/server-api#middlewares">middlewares</a> <span className="token comment"># Middlewares specific to your plugin</span><br/>
45+
│ │ │ └── index.ts <span className="token comment"># Loads all the plugin's middlewares</span><br />
46+
│ │ ├── <a href="/dev-docs/plugins/server-api#policies">policies</a> <span className="token comment"># Policies specific to your plugin</span><br />
47+
│ │ │ └── index.ts <span className="token comment"># Loads all the plugin's policies</span><br />
48+
│ │ ├── <a href="/dev-docs/plugins/server-api#routes">routes</a> <span className="token comment"># Routes specific to your plugin</span><br/>
49+
│ │ │ └── index.ts <span className="token comment"># Contains an example route for the my-controller custom controller example</span><br/>
50+
│ │ ├── <a href="/dev-docs/plugins/server-api#services">services</a> <span className="token comment"># Services specific to your plugin</span> <br/>
51+
│ │ │ ├── index.ts <span className="token comment"># Loads all the plugin's services</span><br/>
52+
│ │ │ └── service.ts <span className="token comment"># Custom service example. You can rename it or delete it.</span><br/>
53+
│ │ ├── <a href="/dev-docs/plugins/server-api#bootstrap">bootstrap.ts</a> <span className="token comment"># Function that is called right after the plugin has registered</span><br/>
54+
│ │ ├── <a href="/dev-docs/plugins/server-api#register">destroy.ts</a> <span className="token comment"># Function that is called to clean up the plugin after Strapi instance is destroyed</span><br/>
55+
│ │ ├── <a href="/dev-docs/plugins/server-api">index.ts</a> <span className="token comment"># Entrypoint for the server (back end)</span> <br />
56+
│ │ └── <a href="/dev-docs/plugins/server-api#register">register.ts</a> <span className="token comment"># Function that is called to load the plugin, before bootstrap.</span><br/>
57+
│ ├── tsconfig.build.json <span className="token comment"></span><br />
58+
│ └── tsconfig.json <span className="token comment"># TypeScript compiler options for the server part</span><br />
59+
├── .editorconfig<br />
60+
├── .eslintignore<br />
61+
├── .gitignore<br />
62+
├── .prettierignore<br />
63+
├── .prettierrc<br />
64+
├── package-lock.json<br />
65+
├── package.json<br />
66+
└── README.md<br />
67+
</code>
68+
</pre>
69+
70+
</TabItem>
71+
972
<TabItem value="js" label="JavaScript-based plugins">
1073

1174
The following diagram is interactive: you can click on any file or folder name highlighted in purple to go to the corresponding documentation section.<br /><br />
@@ -64,69 +127,6 @@ export default function InteractivePluginStructure() {
64127
</pre>
65128

66129
</TabItem>
67-
68-
<TabItem title="TypeScript-based projects" value="TypeScript-based plugins">
69-
70-
The following diagram is interactive: you can click on any file or folder name highlighted in purple to go to the corresponding documentation section.<br /><br />
71-
72-
<pre className="prism-code">
73-
<code>
74-
. <span className="token comment"># root of the plugin folder (e.g., /src/plugins/my-plugin)</span><br/>
75-
├── <a href="/dev-docs/plugins/admin-panel-api">admin</a> <span className="token comment"># Admin panel part of your plugin.</span><br/>
76-
│ ├── src<br />
77-
│ │ ├── components <span className="token comment"># Contains your front-end components</span><br/>
78-
│ │ │ ├── Initializer.tsx <span className="token comment"># Plugin initializer</span><br/>
79-
│ │ │ └── PluginIcon.tsx <span className="token comment"># Contains the icon of your plugin in the main navigation</span><br/>
80-
│ │ ├── pages <span className="token comment"># Contains the pages of your plugin</span><br/>
81-
│ │ │ ├── App.tsx <span className="token comment"># Skeleton around the actual pages</span><br/>
82-
│ │ │ └── HomePage.tsx <span className="token comment"># Homepage of your plugin</span><br/>
83-
│ │ ├── translations <span className="token comment"># Translations files to make your plugin i18n-friendly</span><br/>
84-
│ │ │ ├── en.json<br/>
85-
│ │ ├── utils<br/>
86-
│ │ │ └── getTranslations.ts <span className="token comment"># getTranslations function to return the corresponding plugin translations</span><br/>
87-
│ │ ├── index.ts <span className="token comment"># Main setup of your plugin, used to register elements in the admin panel</span><br/>
88-
│ │ └── pluginId.ts <span className="token comment"># pluginId variable computed from package.tsxon name</span><br/>
89-
│ ├── custom.d.ts <span className="token comment"># Generated types</span><br/>
90-
│ ├── tsconfig.build.json <span className="token comment"></span><br />
91-
│ └── tsconfig.json <span className="token comment"># TypeScript compiler options for the admin panel part</span><br />
92-
├── dist <span className="token comment"># Build of the plugin (front end and back end)</span><br/>
93-
├── node_modules<br />
94-
├── <a href="/dev-docs/plugins/server-api">server</a> <span className="token comment"># Back-end part of your plugin</span><br/>
95-
│ ├── src<br />
96-
│ │ ├── <a href="/dev-docs/plugins/server-api#configuration">config</a><br/>
97-
│ │ │ └── index.ts <span className="token comment"># Contains the default server configuration</span><br/>
98-
│ │ ├── <a href="/dev-docs/plugins/server-api#content-types">content-types</a> <span className="token comment"># Content-types specific to your plugin</span><br/>
99-
│ │ │ └── index.ts <span className="token comment"># Loads all the plugin's content-types</span><br />
100-
│ │ ├── <a href="/dev-docs/plugins/server-api#controllers">controllers</a> <span className="token comment"># Controllers specific to your plugin</span><br />
101-
│ │ │ ├── index.ts <span className="token comment"># Loads all the plugin's controllers</span><br/>
102-
│ │ │ └── controller.ts <span className="token comment"># Custom controller example. You can rename it or delete it.</span><br/>
103-
│ │ ├── <a href="/dev-docs/plugins/server-api#middlewares">middlewares</a> <span className="token comment"># Middlewares specific to your plugin</span><br/>
104-
│ │ │ └── index.ts <span className="token comment"># Loads all the plugin's middlewares</span><br />
105-
│ │ ├── <a href="/dev-docs/plugins/server-api#policies">policies</a> <span className="token comment"># Policies specific to your plugin</span><br />
106-
│ │ │ └── index.ts <span className="token comment"># Loads all the plugin's policies</span><br />
107-
│ │ ├── <a href="/dev-docs/plugins/server-api#routes">routes</a> <span className="token comment"># Routes specific to your plugin</span><br/>
108-
│ │ │ └── index.ts <span className="token comment"># Contains an example route for the my-controller custom controller example</span><br/>
109-
│ │ ├── <a href="/dev-docs/plugins/server-api#services">services</a> <span className="token comment"># Services specific to your plugin</span> <br/>
110-
│ │ │ ├── index.ts <span className="token comment"># Loads all the plugin's services</span><br/>
111-
│ │ │ └── service.ts <span className="token comment"># Custom service example. You can rename it or delete it.</span><br/>
112-
│ │ ├── <a href="/dev-docs/plugins/server-api#bootstrap">bootstrap.ts</a> <span className="token comment"># Function that is called right after the plugin has registered</span><br/>
113-
│ │ ├── <a href="/dev-docs/plugins/server-api#register">destroy.ts</a> <span className="token comment"># Function that is called to clean up the plugin after Strapi instance is destroyed</span><br/>
114-
│ │ ├── <a href="/dev-docs/plugins/server-api">index.ts</a> <span className="token comment"># Entrypoint for the server (back end)</span> <br />
115-
│ │ └── <a href="/dev-docs/plugins/server-api#register">register.ts</a> <span className="token comment"># Function that is called to load the plugin, before bootstrap.</span><br/>
116-
│ ├── tsconfig.build.json <span className="token comment"></span><br />
117-
│ └── tsconfig.json <span className="token comment"># TypeScript compiler options for the server part</span><br />
118-
├── .editorconfig<br />
119-
├── .eslintignore<br />
120-
├── .gitignore<br />
121-
├── .prettierignore<br />
122-
├── .prettierrc<br />
123-
├── package-lock.json<br />
124-
├── package.json<br />
125-
└── README.md<br />
126-
</code>
127-
</pre>
128-
129-
</TabItem>
130130
</Tabs>
131131
</div>
132132
);

0 commit comments

Comments
 (0)