1 import { Prerequisites } from "docs-ui"
2
3 export const metadata = {
4 title: `Docs Contribution Guidelines`,
5 }
6
7 # {metadata.title}
8
9 Thank you for your interest in contributing to the documentation! You will be helping the open source community and other developers interested in learning more about Medusa and using it.
10
11 <Note title="Tip">
12
13 Making a quick fix to a page's content? You can scroll down to the bottom of the page and click on the "Edit this page" link to make quick edits directly in GitHub. If you're making bigger changes, such as adding a new page or making changes to the codebase, check out the rest of this guide.
14
15 </Note>
16
17 <Note title="Tip">
18
19 This guide is specific to contributing to the documentation. If you’re interested in contributing to Medusa’s codebase, check out the [contributing guidelines in the Medusa GitHub repository](https://github.com/medusajs/medusa/blob/develop/CONTRIBUTING.md).
20
21 </Note>
22
23 ## What Can You Contribute?
24
25 You can contribute to the Medusa documentation in the following ways:
26
27 - Fixes to existing content. This includes small fixes like typos, or adding missing information.
28 - Additions to the documentation. If you think a documentation page can be useful to other developers, you can contribute by adding it.
29 - Make sure to open an issue first in the [medusa repository](https://github.com/medusajs/medusa) to confirm that you can add that documentation page.
30 - Fixes to UI components and tooling. If you find a bug while browsing the documentation, you can contribute by fixing it.
31
32 ---
33
34 ## Documentation Workspace
35
36 Medusa's documentation projects are all part of the documentation `yarn` workspace, which you can find in the [medusa repository](https://github.com/medusajs/medusa) under the `www` directory.
37
38 The workspace has the following two directories:
39
40 - `apps`: this directory holds the different documentation websites and projects. All projects are built with [Next.js 15](https://nextjs.org/).
41 - `book`: includes the codebase and content for the [main Medusa documentation](../../../page.mdx).
42 - `resources`: includes the codebase and content for the resources documentation, which powers different sections of the docs such as the [Integrations](!resources!/integrations) or [How-to & Tutorials](!resources!/how-to-tutorials) sections.
43 - `api-reference`: includes the codebase and content for the [API reference](!api!/store).
44 - `ui`: includes the codebase and content for the [Medusa UI documentation](!ui!).
45 - `user-guide`: includes the codebase and content for the [user guide documentation](!user-guide!).
46 - `cloud`: includes the codebase and content for the [Medusa Cloud documentation](!cloud!).
47 - `packages`: this directory holds the shared packages and components necessary for the development of the projects in the `apps` directory.
48 - `docs-ui` includes the shared React components between the different apps.
49 - `remark-rehype-plugins` includes Remark and Rehype plugins used by the documentation projects.
50
51 ### Setup the Documentation Workspace
52
53 <Prerequisites
54 items={[
55 {
56 text: "Node.js v20.19.0+ or v22.12.0+",
57 link: "https://nodejs.org/en/download"
58 },
59 {
60 text: "Yarn v3+",
61 link: "https://v3.yarnpkg.com/getting-started/install"
62 }
63 ]}
64 />
65
66 In the `www` directory, run the following command to install the dependencies:
67
68 ```bash
69 yarn install
70 ```
71
72 Then, run the following command to build packages under the `www/packages` directory:
73
74 ```bash
75 yarn build
76 ```
77
78 After that, you can change into the directory of any documentation project under the `www/apps` directory and run the `dev` command to start the development server.
79
80 ---
81
82 ## Documentation Content
83
84 All documentation projects are built with Next.js. The content is written in MDX files.
85
86 ### Medusa Main Docs Content
87
88 The content of the Medusa main docs are under the `www/apps/book/app` directory.
89
90 ### Medusa Resources Content
91
92 The content of all pages under the `/resources` path are under the `www/apps/resources/app` directory.
93
94 <Note>
95
96 Documentation pages under the `www/apps/resources/references` directory are generated automatically from the source code under the `packages/medusa` directory. So, you can't directly make changes to them. Instead, you'll have to make changes to the comments in the original source code.
97
98 </Note>
99
100 ### API Reference
101
102 The API reference's content is split into two types:
103
104 1. Static content, which are the content related to getting started, expanding fields, and more. These are located in the `www/apps/api-reference/markdown` directory. They are MDX files.
105 2. OpenAPI specs that are shown to developers when checking the reference of an API Route. These are generated from OpenApi Spec comments, which are under the `www/utils/generated/oas-output` directory.
106
107 ### Medusa UI Documentation
108
109 The content of the Medusa UI documentation are located under the `www/apps/ui/app` directory. They are MDX files.
110
111 The UI documentation also shows code examples, which are under the `www/apps/ui/specs/examples` directory.
112
113 The UI component props are generated from the source code and placed into the `www/apps/ui/specs/components` directory. To contribute to these props and their comments, check the comments in the source code under the `packages/design-system/ui` directory.
114
115 ### Medusa User Guide
116
117 The content of all pages under the `/user-guide` path are under the `www/apps/user-guide/app` directory.
118
119 ### Medusa Cloud Docs
120
121 The content of all pages under the `/cloud` path are under the `www/apps/cloud/app` directory.
122
123 ---
124
125 ## Run Documentation Projects Locally
126
127 To run a documentation project locally, such as `book` or `resources`, change into the directory of that project.
128
129 Then, copy the `.env.example` file to a new `.env.local` file. This should sufficiently set up the environment variables needed to run the project.
130
131 Finally, run the `dev` command to start the development server. For example, in the `book` project:
132
133 ```bash npm2yarn
134 npm run dev
135 ```
136
137 You can then access the documentation site by going to the following URLs in your browser:
138
139 - `book`: `http://localhost:3000`
140 - `resources`: `http://localhost:3000/resources`
141 - `api-reference`: `http://localhost:3000/api` (Store API routes at `/api/store` and Admin API routes at `/api/admin`)
142 - `ui`: `http://localhost:3000/ui`
143 - `user-guide`: `http://localhost:3000/user-guide`
144 - `cloud`: `http://localhost:3000/cloud`
145
146 <Note>
147
148 When you access the documentation site, you might see errors or warning messages related to missing environment variables of services like Algolia. You can ignore these errors and warnings when working locally.
149
150 </Note>
151
152 ### Prep Command
153
154 Each documentation project has a `prep` command that runs scripts to prepare data useful for development or production.
155
156 The common task that `prep` does is generate the sidebar files, which is useful for both development and production. If you make changes to sidebar items, make sure to run the `prep` command before starting the development server.
157
158 ```bash npm2yarn
159 npm run prep
160 ```
161
162 In the `resources` project, you may need to run `prep:turbo --force` for tag changes:
163
164 ```bash npm2yarn title="www/apps/resources"
165 npm run prep:turbo -- --force
166 ```
167
168 ---
169
170 ## Style Guide
171
172 When you contribute to the documentation content, make sure to follow the [documentation style guide](https://www.notion.so/Style-Guide-Docs-fad86dd1c5f84b48b145e959f36628e0).
173
174 ---
175
176 ## How to Contribute
177
178 If you’re fixing small errors in an existing documentation page, you can scroll down to the end of the page and click on the “Edit this page” link. You’ll be redirected to the GitHub edit form of that page and you can make edits directly and submit a pull request (PR).
179
180 If you’re adding a new page or contributing to the codebase, fork the repository, create a new branch, and make all changes necessary in your repository. Then, once you’re done, create a PR in the Medusa repository.
181
182 ### Base Branch
183
184 When you make an edit to an existing documentation page or fork the repository to make changes to the documentation, create a new branch.
185
186 Documentation contributions always use `develop` as the base branch. Make sure to also open your PR against the `develop` branch.
187
188 ### Branch Name
189
190 Make sure that the branch name starts with `docs/`. For example, `docs/fix-services`. Vercel deployed previews are only triggered for branches starting with `docs/`.
191
192 ### Pull Request Conventions
193
194 When you create a pull request, prefix the title with `docs:` or `docs(PROJECT_NAME):`, where `PROJECT_NAME` is the name of the documentation project this pull request pertains to. For example, `docs(ui): fix titles`.
195
196 In the body of the PR, explain clearly what the PR does. If the PR solves an issue, use [closing keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) with the issue number. For example, `Closes #1333`.
197
198 #### Prep Command Before PR
199
200 If you made changes to the content of any documentation project, you must run the [prep](#prep-command) command in the `book` project before creating a pull request. It will generate the `llms-full.txt` file with the updated content. You should also run it in the project you made changes to, as that will generate other necessary files for the project, such as edit dates.
201
202 ```bash npm2yarn title="www/apps/book"
203 npm run prep
204 ```
205
206 <Note>
207
208 Some files are ignored by the script. So, if you don't see that the `llms-full.txt` file is updated after running the `prep` command, you can safely ignore it.
209
210 </Note>
211
212 ---
213
214 ## Images
215
216 If you are adding images to a documentation page, you can host the image on [Imgur](https://imgur.com) for free to include it in the PR. Our team will later upload it to our image hosting CDN.
217
218 ---
219
220 ## NPM and Yarn Code Blocks
221
222 If you’re adding code blocks that use NPM and Yarn, you must add the `npm2yarn` meta field.
223
224 For example:
225
226 ~~~md
227 ```bash npm2yarn
228 npm run start
229 ```
230 ~~~
231
232 The code snippet must be written using NPM.
233
234 ### Global Option
235
236 When a command uses the global option `-g`, add it at the end of the NPM command to ensure that it’s transformed to a Yarn command properly. For example:
237
238 ```bash npm2yarn
239 npm install @medusajs/cli -g
240 ```
241
242 ---
243
244 ## Linting with Vale
245
246 Medusa uses [Vale](https://vale.sh/) to lint documentation pages and perform checks on incoming PRs into the repository.
247
248 ### Result of Vale PR Checks
249
250 You can check the result of running the "lint" action on your PR by clicking the Details link next to it. You can find there all errors that you need to fix.
251
252 ### Run Vale Locally
253
254 If you want to check your work locally, you can do that by:
255
256 1. [Installing Vale](https://vale.sh/docs/vale-cli/installation/) on your machine.
257 2. Changing to the `www/vale` directory:
258
259 ```bash
260 cd www/vale
261 ```
262
263 3\. Running the `run-vale` script:
264
265 ```bash
266 # to lint content for the main documentation
267 ./run-vale.sh book/app/learn error resources
268 # to lint content for the resources documentation
269 ./run-vale.sh resources/app error
270 # to lint content for the API reference
271 ./run-vale.sh api-reference/markdown error
272 # to lint content for the Medusa UI documentation
273 ./run-vale.sh ui/app error
274 # to lint content for the user guide
275 ./run-vale.sh user-guide/app error
276 ```
277
278 {/* TODO need to enable MDX v1 comments first. */}
279
280 {/* ### Linter Exceptions
281
282 If it's needed to break some style guide rules in a document, you can wrap the parts that the linter shouldn't scan with the following comments in the `md` or `mdx` files:
283
284 ```md
285 <!-- vale off -->
286
287 content that shouldn't be scanned for errors here...
288
289 <!-- vale on -->
290 ```
291
292 You can also disable specific rules. For example:
293
294 ```md
295 <!-- vale docs.Numbers = NO -->
296
297 Medusa supports Node versions 14 and 16.
298
299 <!-- vale docs.Numbers = YES -->
300 ```
301
302 If you use this in your PR, you must justify its usage. */}
303
304 ---
305
306 ## Linting with ESLint
307
308 Medusa uses ESlint to lint code blocks both in the content and the code base of the documentation apps.
309
310 ### Linting Content with ESLint
311
312 Each PR runs through a check that lints the code in the content files using ESLint. The action's name is `content-eslint`.
313
314 If you want to check content ESLint errors locally and fix them, you can do that by:
315
316 1\. Install the dependencies in the `www` directory:
317
318 ```bash
319 yarn install
320 ```
321
322 2\. Run the turbo command in the `www` directory or the specific documentation's directory (for example, `www/apps/book`):
323
324 ```bash
325 turbo run lint:content
326 ```
327
328 This will fix any fixable errors, and show errors that require your action.
329
330 ### Linting Code with ESLint
331
332 Each PR runs through a check that lints the code in the content files using ESLint. The action's name is `code-docs-eslint`.
333
334 If you want to check code ESLint errors locally and fix them, you can do that by:
335
336 1\. Install the dependencies in the `www` directory:
337
338 ```bash
339 yarn install
340 ```
341
342 2\. Run the turbo command in the `www` directory or the specific documentation's directory (for example, `www/apps/book`):
343
344 ```bash
345 yarn lint
346 ```
347
348 This will fix any fixable errors, and show errors that require your action.
349
350 {/* TODO need to enable MDX v1 comments first. */}
351
352 {/* ### ESLint Exceptions
353
354 If some code blocks have errors that can't or shouldn't be fixed, you can add the following command before the code block:
355
356 ~~~md
357 <!-- eslint-skip -->
358
359 ```js
360 console.log("This block isn't linted")
361 ```
362
363 ```js
364 console.log("This block is linted")
365 ```
366 ~~~
367
368 You can also disable specific rules. For example:
369
370 ~~~md
371 <!-- eslint-disable semi -->
372
373 ```js
374 console.log("This block can use semicolons");
375 ```
376
377 ```js
378 console.log("This block can't use semi colons")
379 ```
380 ~~~ */}