docs: improvements to create plugin guide (#4285)

* docs: improvements to create plugin guide

* fix link
This commit is contained in:
Shahed Nasser
2023-06-12 10:57:40 +03:00
committed by GitHub
parent 1b748d435c
commit 8228503fa2
15 changed files with 126 additions and 27 deletions

View File

@@ -186,4 +186,4 @@ With entities, you can create relationships, index keys, and more. As Medusa use
## See Also
- [Extend Entity](./extend-entity.md)
- [Create a Plugin](../plugins/create.md)
- [Create a Plugin](../plugins/create.mdx)

View File

@@ -17,7 +17,7 @@ npx typeorm migration:create src/migrations/UserChanged
This will create the migration file in the path you specify. You can use this without the need to install Typeorm's CLI tool. You can then go ahead and make changes to it as necessary.
The migration file must be inside the `src/migrations` directory. When you run the build command, it will be transpiled into the directory `dist/migrations`. The `migrations run` command can only pick up migrations under the `dist/migrations` directory on a Medusa backend. This applies to migrations created in a Medusa backend, and not in a Medusa plugin. For plugins, check out the [Plugin's Structure section](../../plugins/create.md).
The migration file must be inside the `src/migrations` directory. When you run the build command, it will be transpiled into the directory `dist/migrations`. The `migrations run` command can only pick up migrations under the `dist/migrations` directory on a Medusa backend. This applies to migrations created in a Medusa backend, and not in a Medusa plugin. For plugins, check out the [Plugin's Structure section](../../plugins/create.mdx).
<details>
<summary>Generating Migrations for Entities</summary>
@@ -99,4 +99,4 @@ If you check your database now you should see that the change defined by the mig
## See Also
- [Create a Plugin](../../plugins/create.md)
- [Create a Plugin](../../plugins/create.mdx)

View File

@@ -96,4 +96,4 @@ When using attributes defined in the subscriber, such as the `productService` in
## See Also
- [Create a Plugin](../plugins/create.md)
- [Create a Plugin](../plugins/create.mdx)

View File

@@ -390,7 +390,7 @@ npm run build
:::note
This section explains how to test out your implementation if the file service was created in the Medusa backend codebase. You can refer to the [plugin documentation](../plugins/create.md#test-your-plugin) on how to test a plugin.
This section explains how to test out your implementation if the file service was created in the Medusa backend codebase. You can refer to the [plugin documentation](../plugins/create.mdx#test-your-plugin) on how to test a plugin.
:::
@@ -430,5 +430,5 @@ export default () => {
## See Also
- [How to create a plugin](../plugins/create.md)
- [How to create a plugin](../plugins/create.mdx)
- [How to publish a plugin](../plugins/publish.md)

View File

@@ -190,5 +190,5 @@ medusa-dev --packages @medusajs/medusa-cli medusa-file-minio
## See Also
- [Create a Plugin](../plugins/create.md)
- [Create a Plugin](../plugins/create.mdx)
- [Contribution Guidelines](https://github.com/medusajs/medusa/blob/master/CONTRIBUTING.md)

View File

@@ -73,7 +73,7 @@ npm run build
:::note
This section explains how to test out the loader if its created in the Medusa backend codebase. If youre creating your loader in a plugin, you can learn how to test it in the [plugins documentation](../plugins/create.md#test-your-plugin). Alternatively, if youre creating your loader in a module, you can learn how to test it in the [modules documentation](../modules/create.mdx#step-4-test-your-module).
This section explains how to test out the loader if its created in the Medusa backend codebase. If youre creating your loader in a plugin, you can learn how to test it in the [plugins documentation](../plugins/create.mdx#test-your-plugin). Alternatively, if youre creating your loader in a module, you can learn how to test it in the [modules documentation](../modules/create.mdx#step-4-test-your-module).
:::

View File

@@ -343,4 +343,4 @@ This request returns the same notification object as the List Notifications endp
## See Also
- [Create a Plugin](../plugins/create.md)
- [Create a Plugin](../plugins/create.mdx)

View File

@@ -3,6 +3,9 @@ description: 'Learn how to create a plugin in Medusa. This guide explains how to
addHowToData: true
---
import DocCardList from '@theme/DocCardList';
import Icons from '@theme/Icon';
# How to Create a Plugin
In this document, youll learn how to create a plugin and some tips for develoment. If youre interested to learn more about what plugins are and where to find available official and community plugins, check out the [overview document](./overview.mdx).
@@ -90,6 +93,16 @@ Once youre done making these changes, re-run the install command to update yo
npm install
```
Then, make sure to remove the plugins and modules you removed from `medusa-config.js`:
```js title=medusa-config.js
// previously had plugins
const plugins = []
// previously had modules
const modules = {}
```
### Recommended: Change Scripts
It's recommended to remove the `seed` and `start` scripts from your `package.json` as they aren't necessary for plugin development.
@@ -135,11 +148,97 @@ It was previously required to output your files into the root of the plugin's di
This guide doesn't cover how to create different files and components. If youre interested in learning how to do that, you can check out these guides:
- How to [create endpoints](../endpoints/create.md)
- How to [create a service](../services/create-service.mdx)
- How to [create a subscriber](../events/create-subscriber.md)
- How to [create an entity](../entities/create.md)
- How to [create a migration](../entities/migrations/create.md)
<DocCardList colSize={6} items={[
{
type: 'link',
href: '/development/entities/create',
label: 'Create an Entity',
customProps: {
icon: Icons['academic-cap-solid'],
description: 'Learn how to create an entity.'
}
},
{
type: 'link',
href: '/development/services/create-service',
label: 'Create a Service',
customProps: {
icon: Icons['academic-cap-solid'],
description: 'Learn how to create a service.'
}
},
{
type: 'link',
href: '/development/endpoints/create',
label: 'Create an Endpoint',
customProps: {
icon: Icons['academic-cap-solid'],
description: 'Learn how to create an endpoint.'
}
},
{
type: 'link',
href: '/development/events/create-subscriber',
label: 'Create a Subscriber',
customProps: {
icon: Icons['academic-cap-solid'],
description: 'Learn how to create a subscriber.'
}
},
]} />
If you're developing something specific, such as a payment processor plugin, you can follow one of the following guides to learn how to create different services within your plugin.
<DocCardList colSize={6} items={[
{
type: 'link',
href: '/modules/carts-and-checkout/backend/add-payment-provider',
label: 'Create a Payment Processor',
customProps: {
icon: Icons['academic-cap-solid'],
description: 'Learn how to create a payment processor.'
}
},
{
type: 'link',
href: '/modules/carts-and-checkout/backend/add-fulfillment-provider',
label: 'Create a Fulfillment Provider',
customProps: {
icon: Icons['academic-cap-solid'],
description: 'Learn how to create a fulfillment provider.'
}
},
]} />
<DocCardList colSize={4} items={[
{
type: 'link',
href: '/development/search/create',
label: 'Create a Search Service',
customProps: {
icon: Icons['academic-cap-solid'],
description: 'Learn how to create a search service.'
}
},
{
type: 'link',
href: '/development/file-service/create-file-service',
label: 'Create a File Service',
customProps: {
icon: Icons['academic-cap-solid'],
description: 'Learn how to create a file service.'
}
},
{
type: 'link',
href: '/development/file-service/create-file-service',
label: 'Create a Notification Service',
customProps: {
icon: Icons['academic-cap-solid'],
description: 'Learn how to create a notification service.'
}
},
]} />
---
@@ -149,7 +248,7 @@ Plugins often allow developers that will later use them to enter their own confi
To pass a plugin its configurations on a Medusa backend, you have to add it to the `plugins` array in `medusa-config.js`:
```jsx title=medusa-config.js
```js title=medusa-config.js
const plugins = [
// ...
{
@@ -163,7 +262,7 @@ const plugins = [
Then, you can have access to your plugin configuration in the constructor of services in your plugin:
```jsx title=src/service/test.ts
```js title=src/service/test.ts
// In a service in your plugin
class MyService extends TransactionBaseService {
constructor(container, options) {
@@ -177,7 +276,7 @@ class MyService extends TransactionBaseService {
You can also have access to the configurations in endpoints in your plugin:
```jsx title=src/api/index.ts
```js title=src/api/index.ts
// in an endpoint in your plugin
export default (rootDirectory, options) => {
// options contain the plugin configurations

View File

@@ -7,7 +7,7 @@ import Icons from '@theme/Icon';
# Plugins
In this document, youll get an overview of plugins in Medusa, where to find them, and how to install them. If you want to learn how to create a plugin, check out [this guide](create.md) instead.
In this document, youll get an overview of plugins in Medusa, where to find them, and how to install them. If you want to learn how to create a plugin, check out [this guide](create.mdx) instead.
## Overview

View File

@@ -9,7 +9,7 @@ In this document, you'll learn how to publish a Medusa plugin to NPM and what ar
## Prerequisites
If you haven't created a plugin yet, please check [this guide to learn how to create a plugin](./create.md).
If you haven't created a plugin yet, please check [this guide to learn how to create a plugin](./create.mdx).
---
@@ -46,7 +46,7 @@ Make sure you add the `publish` command to your `scripts` field and make the fol
"prepare": "cross-env NODE_ENV=production npm run build"
```
The `build` command ensures that the plugin's built files are placed as explained in the [plugin structure](./create.md#plugin-structure) section of the Create Plugin documentation.
The `build` command ensures that the plugin's built files are placed as explained in the [plugin structure](./create.mdx#plugin-structure) section of the Create Plugin documentation.
The `prepare` command facilitates your publishing process. You would typically run this script before publishing your plugin.
@@ -58,7 +58,7 @@ npm install --save-dev cross-env
### Plugin Structure
Make sure your plugin's structure is as described in the [Create Plugin](./create.md#plugin-structure) documentation. If you've made the changes mentioned in [the above section to the scripts](#scripts-in-packagejson) in `package.json`, you should have the correct structure when you run the `prepare` command.
Make sure your plugin's structure is as described in the [Create Plugin](./create.mdx#plugin-structure) documentation. If you've made the changes mentioned in [the above section to the scripts](#scripts-in-packagejson) in `package.json`, you should have the correct structure when you run the `prepare` command.
### NPM Ignore File

View File

@@ -177,4 +177,4 @@ To test the previous example out instantly, you can change the scheduled job exp
## See Also
- [Create a Plugin](../plugins/create.md)
- [Create a Plugin](../plugins/create.mdx)

View File

@@ -396,7 +396,7 @@ npm run build
:::note
This section explains how to test out your implementation if the search service was created in the Medusa backend codebase. You can refer to [the plugin documentation](../plugins/create.md#test-your-plugin) on how to test a plugin.
This section explains how to test out your implementation if the search service was created in the Medusa backend codebase. You can refer to [the plugin documentation](../plugins/create.mdx#test-your-plugin) on how to test a plugin.
:::
@@ -412,5 +412,5 @@ You can then send a request to the [Search Products endpoint](/api/store#tag/Pro
## See Also
- [How to create a plugin](../plugins/create.md)
- [How to create a plugin](../plugins/create.mdx)
- [How to publish a plugin](../plugins/publish.md)

View File

@@ -161,4 +161,4 @@ class MySubscriber {
## See Also
- [Create a Plugin](../plugins/create.md)
- [Create a Plugin](../plugins/create.mdx)

View File

@@ -31,7 +31,7 @@ The service must then be transpiled using the `build` command, which moves them
:::tip
If you're creating a service in a plugin, learn more about the required structure [here](../plugins/create.md#plugin-structure).
If you're creating a service in a plugin, learn more about the required structure [here](../plugins/create.mdx#plugin-structure).
:::

View File

@@ -199,4 +199,4 @@ If you try to update products on Medusa either using the [REST APIs](/api/admin/
## See Also
- [Deploy the Medusa backend](../../deployments/server/index.mdx)
- [Create your own plugin](../../development/plugins/create.md)
- [Create your own plugin](../../development/plugins/create.mdx)