|
1
|
# docs-generator |
|
2
|
|
|
3
|
A CLI tool that generates different types of docblocks from source code: |
|
4
|
|
|
5
|
- Adds TSDocs to any TypeScript file. |
|
6
|
- Generates files with OpenApi Spec comments in `generated/oas-output`. |
|
7
|
- Generates JSON documentation files for models built with Medusa's DML in `generated/dml-output`. |
|
8
|
|
|
9
|
## Prerequisites |
|
10
|
|
|
11
|
1. Run the `yarn` command to install dependencies. |
|
12
|
2. Run the `yarn build` command to build source files. |
|
13
|
|
|
14
|
--- |
|
15
|
|
|
16
|
## Usage |
|
17
|
|
|
18
|
### Generate for a specific file |
|
19
|
|
|
20
|
Run the following command to run the tool for a specific file: |
|
21
|
|
|
22
|
```bash |
|
23
|
yarn dev run /absolute/path/to/file.ts |
|
24
|
``` |
|
25
|
|
|
26
|
### Generate for git-changed files |
|
27
|
|
|
28
|
Run the following command to run the tool for applicable git file changes: |
|
29
|
|
|
30
|
```bash |
|
31
|
yarn dev run:changes |
|
32
|
``` |
|
33
|
|
|
34
|
### Generate for a specific commit |
|
35
|
|
|
36
|
Run the following command to run the tool for a commit SHA hash: |
|
37
|
|
|
38
|
```bash |
|
39
|
yarn dev run:commit <commit-sha> |
|
40
|
``` |
|
41
|
|
|
42
|
Where `<commit-sha>` is the SHA of the commit. For example, `e28fa7fbdf45c5b1fa19848db731132a0bf1757d`. |
|
43
|
|
|
44
|
### Generate for a release |
|
45
|
|
|
46
|
Run the following command to run the tool on commits since the latest release. |
|
47
|
|
|
48
|
```bash |
|
49
|
yarn dev run:release |
|
50
|
``` |
|
51
|
|
|
52
|
### Clean OAS |
|
53
|
|
|
54
|
Run the following command to clean up the OAS output files and remove any routes that no longer exist: |
|
55
|
|
|
56
|
```bash |
|
57
|
yarn dev clean:oas |
|
58
|
``` |
|
59
|
|
|
60
|
This command will also remove tags and schemas not used. |
|
61
|
|
|
62
|
### Clean DML JSON files |
|
63
|
|
|
64
|
Run the following command to clean up the DML JSON output files and remove any data models that no longer exist: |
|
65
|
|
|
66
|
```bash |
|
67
|
yarn dev clean:dml |
|
68
|
``` |
|
69
|
|
|
70
|
--- |
|
71
|
|
|
72
|
## How it Works |
|
73
|
|
|
74
|
### Generating OAS |
|
75
|
|
|
76
|
If a node is an API route, it generates OAS comments rather than TSDoc comments. The OAS comments are generated and placed in new/existing files under the `www/utils/generated/oas-output/operations` directory. |
|
77
|
|
|
78
|
## Models Built with DML |
|
79
|
|
|
80
|
If a node is a `CallExpression` and it's created using `model.define`, then a JSON documentation file with key-value pairs is generated to add description to its properties. |
|
81
|
|
|
82
|
Only files under `packages/modules/**/src/models` are considered here. |
|
83
|
|
|
84
|
### Generating TSDoc Docblocks |
|
85
|
|
|
86
|
If a node isn't an API Route and it complies with the specified conditions, TSDoc docblocks are generated for it. |
|
87
|
|
|
88
|
Files under the `packages/medusa/src/api` or `packages/modules/**/src/models` directories are considered incompatible, so any files under these directories won't have TSDoc docblocks generated for them. |
|
89
|
|
|
90
|
--- |
|
91
|
|
|
92
|
## Common Options |
|
93
|
|
|
94
|
This section includes options that you can pass to any of the mentioned commands. |
|
95
|
|
|
96
|
### --generate-examples |
|
97
|
|
|
98
|
If this option is passed, the tool will try to generate OAS examples. Currently, it will only try to generate JS Client examples. |
|
99
|
|
|
100
|
cURL examples are always generated regardless of this option. |
|
101
|
|
|
102
|
### --type |
|
103
|
|
|
104
|
You can use this option to specify the type of docs to generate. Possible values are: |
|
105
|
|
|
106
|
- `all`: (default) Generate all doc types. |
|
107
|
- `docs`: Generate only TSDoc docblocks. |
|
108
|
- `oas`: Generate only OAS files. |
|
109
|
- `dml`: Generate only JSON files for models built with DML. |