@writechoice/mint-cli 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PUBLISH.md +54 -332
- package/README.md +148 -282
- package/bin/cli.js +69 -8
- package/package.json +5 -4
- package/src/commands/config.js +70 -0
- package/src/commands/fix/links.js +212 -0
- package/src/commands/validate/links.js +13 -299
- package/src/commands/validate/mdx.js +213 -0
- package/src/utils/config.js +115 -0
- package/src/utils/reports.js +182 -0
package/README.md
CHANGED
|
@@ -2,396 +2,256 @@
|
|
|
2
2
|
|
|
3
3
|
CLI tool for Mintlify documentation validation and utilities.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- **Link Validation**: Validates internal links and anchors in MDX documentation files
|
|
8
|
-
- **Browser Automation**: Uses Playwright to test links against live websites
|
|
9
|
-
- **Auto-Fix**: Automatically fixes incorrect anchor links
|
|
10
|
-
- **Detailed Reporting**: Generates JSON reports with validation results
|
|
11
|
-
- **Concurrent Processing**: Validates multiple links simultaneously for better performance
|
|
5
|
+
## Quick Start
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
### Global Installation
|
|
7
|
+
### Installation
|
|
16
8
|
|
|
17
9
|
```bash
|
|
18
10
|
npm install -g @writechoice/mint-cli
|
|
11
|
+
npx playwright install chromium
|
|
19
12
|
```
|
|
20
13
|
|
|
21
|
-
###
|
|
14
|
+
### Usage
|
|
22
15
|
|
|
23
16
|
```bash
|
|
24
|
-
#
|
|
25
|
-
|
|
26
|
-
cd writechoice-mint-cli
|
|
27
|
-
|
|
28
|
-
# Install dependencies
|
|
29
|
-
npm install
|
|
30
|
-
|
|
31
|
-
# Install Playwright browsers
|
|
32
|
-
npx playwright install chromium
|
|
17
|
+
# Check version
|
|
18
|
+
writechoice --version
|
|
33
19
|
|
|
34
|
-
#
|
|
35
|
-
|
|
20
|
+
# Update to latest
|
|
21
|
+
writechoice update
|
|
36
22
|
|
|
37
|
-
#
|
|
38
|
-
|
|
39
|
-
```
|
|
23
|
+
# Validate MDX parsing
|
|
24
|
+
writechoice check parse
|
|
40
25
|
|
|
41
|
-
|
|
26
|
+
# Validate links
|
|
27
|
+
writechoice check links https://docs.example.com
|
|
42
28
|
|
|
43
|
-
|
|
29
|
+
# Validate with local development server
|
|
30
|
+
writechoice check links docs.example.com http://localhost:3000
|
|
44
31
|
|
|
45
|
-
|
|
32
|
+
# Fix broken anchor links
|
|
33
|
+
writechoice fix links
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
writechoice
|
|
49
|
-
# or
|
|
50
|
-
writechoice -v
|
|
35
|
+
# Generate config.json template
|
|
36
|
+
writechoice config
|
|
51
37
|
```
|
|
52
38
|
|
|
53
|
-
|
|
39
|
+
## Commands
|
|
40
|
+
|
|
41
|
+
### `config`
|
|
54
42
|
|
|
55
|
-
|
|
43
|
+
Generates a config.json template file with all available options.
|
|
56
44
|
|
|
57
45
|
```bash
|
|
58
|
-
writechoice
|
|
46
|
+
writechoice config # Create config.json
|
|
47
|
+
writechoice config --force # Overwrite existing config.json
|
|
59
48
|
```
|
|
60
49
|
|
|
61
|
-
|
|
50
|
+
**Output:** Creates `config.json` in the current directory with placeholder values.
|
|
62
51
|
|
|
63
|
-
###
|
|
52
|
+
### `check parse`
|
|
64
53
|
|
|
65
|
-
|
|
54
|
+
Validates MDX files for parsing errors.
|
|
66
55
|
|
|
67
56
|
```bash
|
|
68
|
-
writechoice check
|
|
57
|
+
writechoice check parse # All files
|
|
58
|
+
writechoice check parse -f file.mdx # Single file
|
|
59
|
+
writechoice check parse -d docs # Specific directory
|
|
69
60
|
```
|
|
70
61
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
writechoice check links docs.example.com
|
|
75
|
-
```
|
|
62
|
+
**Output:** Both `mdx_errors_report.json` and `mdx_errors_report.md`
|
|
76
63
|
|
|
77
|
-
|
|
64
|
+
### `check links`
|
|
78
65
|
|
|
79
|
-
|
|
66
|
+
Validates internal links and anchors using browser automation.
|
|
80
67
|
|
|
81
68
|
```bash
|
|
82
|
-
|
|
83
|
-
writechoice check links docs.example.com
|
|
84
|
-
|
|
85
|
-
# Use a custom validation URL
|
|
86
|
-
writechoice check links docs.example.com http://localhost:3000
|
|
87
|
-
|
|
88
|
-
# Use a staging environment
|
|
89
|
-
writechoice check links docs.example.com https://staging.example.com
|
|
69
|
+
writechoice check links <baseUrl> [validationBaseUrl]
|
|
90
70
|
```
|
|
91
71
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
72
|
+
**Common options:**
|
|
73
|
+
- `-f, --file <path>` - Validate single file
|
|
74
|
+
- `-d, --dir <path>` - Validate specific directory
|
|
75
|
+
- `-o, --output <path>` - Base name for reports (default: `links_report`)
|
|
76
|
+
- `-c, --concurrency <number>` - Concurrent browser tabs (default: 25)
|
|
77
|
+
- `--quiet` - Suppress output
|
|
78
|
+
- `--dry-run` - Extract links without validating
|
|
95
79
|
|
|
96
|
-
|
|
80
|
+
**Output:** Both `links_report.json` and `links_report.md`
|
|
97
81
|
|
|
98
|
-
|
|
99
|
-
2. Then navigates to your local dev server (validation URL) and clicks the same heading to see what anchor it generates
|
|
100
|
-
3. Compares the two anchors to detect mismatches
|
|
82
|
+
### `fix links`
|
|
101
83
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
- Link text in MDX files may differ from actual heading text
|
|
105
|
-
- Handles pages with duplicate headings correctly by matching position
|
|
106
|
-
- Validates against your local development environment before deploying
|
|
107
|
-
|
|
108
|
-
### Common Options
|
|
84
|
+
Automatically fixes broken anchor links based on validation reports.
|
|
109
85
|
|
|
110
86
|
```bash
|
|
111
|
-
|
|
112
|
-
writechoice
|
|
113
|
-
|
|
114
|
-
# Validate links in a specific directory
|
|
115
|
-
writechoice check links docs.example.com -d path/to/docs
|
|
116
|
-
|
|
117
|
-
# Dry run (extract links without validating)
|
|
118
|
-
writechoice check links docs.example.com --dry-run
|
|
119
|
-
|
|
120
|
-
# Quiet mode (suppress terminal output, only generate report)
|
|
121
|
-
writechoice check links docs.example.com --quiet
|
|
122
|
-
|
|
123
|
-
# Custom output path for report
|
|
124
|
-
writechoice check links docs.example.com -o validation-report.json
|
|
125
|
-
|
|
126
|
-
# Set concurrency level
|
|
127
|
-
writechoice check links docs.example.com -c 50
|
|
128
|
-
|
|
129
|
-
# Show browser window (for debugging)
|
|
130
|
-
writechoice check links docs.example.com --no-headless
|
|
131
|
-
|
|
132
|
-
# Auto-fix incorrect anchor links
|
|
133
|
-
writechoice check links docs.example.com --fix
|
|
134
|
-
|
|
135
|
-
# Fix links from the default report file (links_report.json)
|
|
136
|
-
writechoice check links docs.example.com --fix-from-report
|
|
137
|
-
|
|
138
|
-
# Fix links from a custom report file
|
|
139
|
-
writechoice check links docs.example.com --fix-from-report custom_report.json
|
|
87
|
+
writechoice fix links # Use default report
|
|
88
|
+
writechoice fix links -r custom_report.json # Use custom report
|
|
140
89
|
```
|
|
141
90
|
|
|
142
|
-
|
|
91
|
+
**Common options:**
|
|
92
|
+
- `-r, --report <path>` - Path to JSON report (default: `links_report.json`)
|
|
93
|
+
- `--quiet` - Suppress output
|
|
143
94
|
|
|
144
|
-
|
|
145
|
-
| -------------------------- | ----- | ------------------------------------------------------------------------- | ----------------------- |
|
|
146
|
-
| `<baseUrl>` | - | Base URL for the documentation site (required, with or without https://) | - |
|
|
147
|
-
| `[validationBaseUrl]` | - | Base URL for online validation (optional, clicks headings to get anchors) | `http://localhost:3000` |
|
|
148
|
-
| `--file <path>` | `-f` | Validate links in a single MDX file | - |
|
|
149
|
-
| `--dir <path>` | `-d` | Validate links in a specific directory | - |
|
|
150
|
-
| `--output <path>` | `-o` | Output path for JSON report | `links_report.json` |
|
|
151
|
-
| `--dry-run` | - | Extract and show links without validating | `false` |
|
|
152
|
-
| `--quiet` | - | Suppress terminal output (only generate report) | `false` |
|
|
153
|
-
| `--concurrency <number>` | `-c` | Number of concurrent browser tabs | `25` |
|
|
154
|
-
| `--headless` | - | Run browser in headless mode | `true` |
|
|
155
|
-
| `--no-headless` | - | Show browser window (for debugging) | - |
|
|
156
|
-
| `--fix` | - | Automatically fix anchor links in MDX files | `false` |
|
|
157
|
-
| `--fix-from-report [path]` | - | Fix anchor links from report file (optional path) | `links_report.json` |
|
|
95
|
+
**Note:** Requires JSON report from `check links` command.
|
|
158
96
|
|
|
159
|
-
|
|
97
|
+
### `update`
|
|
160
98
|
|
|
161
|
-
|
|
99
|
+
Update CLI to latest version.
|
|
162
100
|
|
|
163
|
-
|
|
101
|
+
```bash
|
|
102
|
+
writechoice update
|
|
103
|
+
```
|
|
164
104
|
|
|
165
|
-
|
|
105
|
+
## Features
|
|
166
106
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
107
|
+
- **MDX Parsing Validation** - Catch syntax errors before deployment
|
|
108
|
+
- **Link Validation** - Test links against live websites with Playwright
|
|
109
|
+
- **Two-Step Anchor Validation** - Compare production vs development anchors
|
|
110
|
+
- **Auto-Fix** - Separate fix command to automatically correct broken anchor links
|
|
111
|
+
- **Dual Report Formats** - Generates both JSON (for automation) and Markdown (for humans)
|
|
112
|
+
- **Configuration File** - Optional config.json for default settings
|
|
113
|
+
- **CI/CD Ready** - Exit codes for pipeline integration
|
|
171
114
|
|
|
172
|
-
|
|
115
|
+
## How Two-Step Validation Works
|
|
173
116
|
|
|
174
|
-
|
|
175
|
-
- HTML images: `<img src="./image.png" />`
|
|
117
|
+
For anchor links, the tool:
|
|
176
118
|
|
|
177
|
-
|
|
119
|
+
1. **Finds the target** (Production): Navigates to production docs to identify which heading the anchor points to
|
|
120
|
+
2. **Gets the anchor** (Validation): Navigates to your dev server (localhost:3000), clicks the heading, and extracts the generated anchor
|
|
121
|
+
3. **Compares**: Checks if anchors match
|
|
178
122
|
|
|
179
|
-
|
|
180
|
-
- For normal links: Verifies the file exists in the repository
|
|
181
|
-
- For anchor links: Checks if the heading exists in the MDX file with matching kebab-case format
|
|
182
|
-
2. **Online Validation**: If local check fails, performs a two-step validation process
|
|
183
|
-
- For normal links: Navigates to the validation base URL and verifies the page loads successfully
|
|
184
|
-
- For anchor links (two-step process):
|
|
185
|
-
1. **Step 1 - Find the target heading**: Navigates to the base URL (production docs) with the anchor to identify which heading the anchor points to and its position (handles duplicate headings)
|
|
186
|
-
2. **Step 2 - Get generated anchor**: Navigates to the validation base URL (e.g., localhost:3000), finds the same heading (by text and position), clicks it to trigger anchor generation, and extracts the generated anchor from the URL
|
|
187
|
-
3. Compares the generated anchor with the expected anchor from the MDX file
|
|
188
|
-
3. **Validation Base URL**: By default uses `http://localhost:3000` for online validation, or you can specify a custom URL (e.g., staging environment). This allows testing against a local development server or staging environment while validating links meant for production.
|
|
189
|
-
4. **Auto-Fix**: When issues are found, can automatically update MDX files with the correct anchors
|
|
123
|
+
This ensures your local development environment matches production behavior.
|
|
190
124
|
|
|
191
|
-
|
|
125
|
+
## Configuration File
|
|
192
126
|
|
|
193
|
-
|
|
127
|
+
Create an optional `config.json` in your project root to set default values:
|
|
194
128
|
|
|
195
129
|
```json
|
|
196
130
|
{
|
|
197
|
-
"
|
|
198
|
-
"
|
|
199
|
-
|
|
200
|
-
"scanned_directories": ["."],
|
|
201
|
-
"excluded_directories": ["snippets"],
|
|
131
|
+
"source": "https://docs.example.com",
|
|
132
|
+
"target": "http://localhost:3000",
|
|
133
|
+
"links": {
|
|
202
134
|
"concurrency": 25,
|
|
203
|
-
"
|
|
135
|
+
"quiet": false
|
|
204
136
|
},
|
|
205
|
-
"
|
|
206
|
-
"
|
|
207
|
-
"success": 240,
|
|
208
|
-
"failure": 8,
|
|
209
|
-
"error": 2
|
|
210
|
-
},
|
|
211
|
-
"results_by_file": {
|
|
212
|
-
"docs/getting-started.mdx": [
|
|
213
|
-
{
|
|
214
|
-
"source": {
|
|
215
|
-
"filePath": "docs/getting-started.mdx",
|
|
216
|
-
"lineNumber": 42,
|
|
217
|
-
"linkText": "Installation Guide",
|
|
218
|
-
"rawHref": "./installation#setup",
|
|
219
|
-
"linkType": "markdown"
|
|
220
|
-
},
|
|
221
|
-
"targetUrl": "https://docs.example.com/docs/installation#setup",
|
|
222
|
-
"status": "failure",
|
|
223
|
-
"errorMessage": "Expected anchor \"#setup\" but page heading \"Setup Process\" should use \"#setup-process\""
|
|
224
|
-
}
|
|
225
|
-
]
|
|
137
|
+
"parse": {
|
|
138
|
+
"quiet": false
|
|
226
139
|
}
|
|
227
140
|
}
|
|
228
141
|
```
|
|
229
142
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
The `--fix` option automatically corrects anchor links that don't match the heading text:
|
|
233
|
-
|
|
234
|
-
**Before:**
|
|
235
|
-
|
|
236
|
-
```markdown
|
|
237
|
-
[Installation Guide](./installation#setup)
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
**After:**
|
|
241
|
-
|
|
242
|
-
```markdown
|
|
243
|
-
[Installation Guide](./installation#setup-process)
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### Fix Workflow
|
|
247
|
-
|
|
248
|
-
1. **Run validation**: `writechoice check links docs.example.com`
|
|
249
|
-
2. **Review report**: Check the generated `links_report.json` for issues
|
|
250
|
-
3. **Apply fixes**: `writechoice check links docs.example.com --fix-from-report`
|
|
251
|
-
4. **Re-validate**: Run validation again to verify fixes
|
|
252
|
-
|
|
253
|
-
Or use a custom report file:
|
|
143
|
+
With config.json, you can run commands without arguments:
|
|
254
144
|
|
|
255
145
|
```bash
|
|
256
|
-
#
|
|
257
|
-
writechoice check links
|
|
146
|
+
# Uses source and target from config.json
|
|
147
|
+
writechoice check links
|
|
258
148
|
|
|
259
|
-
#
|
|
260
|
-
writechoice check links
|
|
149
|
+
# CLI args override config.json values
|
|
150
|
+
writechoice check links https://staging.example.com
|
|
261
151
|
```
|
|
262
152
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
The CLI automatically checks for new versions and displays a notification when an update is available:
|
|
266
|
-
|
|
267
|
-
```
|
|
268
|
-
┌─────────────────────────────────────────────────┐
|
|
269
|
-
│ Update available: 0.0.2 → 0.0.3 │
|
|
270
|
-
│ Run: writechoice update │
|
|
271
|
-
└─────────────────────────────────────────────────┘
|
|
272
|
-
```
|
|
153
|
+
See [config.example.json](config.example.json) for all available options.
|
|
273
154
|
|
|
274
|
-
|
|
155
|
+
## Examples
|
|
275
156
|
|
|
276
157
|
```bash
|
|
277
|
-
#
|
|
278
|
-
writechoice
|
|
279
|
-
|
|
280
|
-
# Or using npm directly
|
|
281
|
-
npm install -g @writechoice/mint-cli@latest
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
## Configuration
|
|
285
|
-
|
|
286
|
-
### Excluded Directories
|
|
287
|
-
|
|
288
|
-
By default, the following directories are excluded from scanning:
|
|
289
|
-
|
|
290
|
-
- `snippets/`
|
|
158
|
+
# Validate all MDX files for parsing errors
|
|
159
|
+
writechoice check parse
|
|
291
160
|
|
|
292
|
-
|
|
161
|
+
# Validate all links (uses localhost:3000 by default)
|
|
162
|
+
writechoice check links https://docs.example.com
|
|
293
163
|
|
|
294
|
-
|
|
164
|
+
# Validate with staging environment
|
|
165
|
+
writechoice check links docs.example.com https://staging.example.com
|
|
295
166
|
|
|
296
|
-
|
|
167
|
+
# Validate specific directory only
|
|
168
|
+
writechoice check links docs.example.com -d api
|
|
297
169
|
|
|
298
|
-
|
|
299
|
-
|
|
170
|
+
# Run quietly (only generate reports)
|
|
171
|
+
writechoice check links docs.example.com --quiet
|
|
300
172
|
|
|
301
|
-
|
|
173
|
+
# Fix broken anchor links
|
|
174
|
+
writechoice fix links
|
|
302
175
|
|
|
303
|
-
|
|
176
|
+
# Fix from custom report
|
|
177
|
+
writechoice fix links -r custom_report.json
|
|
304
178
|
|
|
305
|
-
|
|
179
|
+
# Full workflow: validate -> fix -> re-validate
|
|
180
|
+
writechoice check links docs.example.com
|
|
181
|
+
writechoice fix links
|
|
306
182
|
writechoice check links docs.example.com
|
|
307
183
|
```
|
|
308
184
|
|
|
309
|
-
|
|
185
|
+
## Documentation
|
|
310
186
|
|
|
311
|
-
|
|
312
|
-
writechoice check links docs.example.com --quiet
|
|
313
|
-
```
|
|
187
|
+
Detailed documentation is available in the [docs/](docs/) folder:
|
|
314
188
|
|
|
315
|
-
|
|
189
|
+
- **Commands**
|
|
190
|
+
- [config](docs/commands/config.md) - Generate config.json template
|
|
191
|
+
- [check links](docs/commands/check-links.md) - Link validation
|
|
192
|
+
- [check parse](docs/commands/check-parse.md) - MDX parsing validation
|
|
193
|
+
- [fix links](docs/commands/fix-links.md) - Auto-fix broken links
|
|
194
|
+
- [update](docs/commands/update.md) - Update command
|
|
195
|
+
- **Guides**
|
|
196
|
+
- [Configuration File](docs/config-file.md) - Using config.json
|
|
197
|
+
- [Configuration](docs/configuration.md) - Advanced configuration
|
|
198
|
+
- [Publishing](docs/publishing.md) - How to publish new versions
|
|
316
199
|
|
|
317
|
-
|
|
318
|
-
writechoice check links docs.example.com --fix
|
|
319
|
-
```
|
|
200
|
+
## Development
|
|
320
201
|
|
|
321
|
-
###
|
|
202
|
+
### Local Setup
|
|
322
203
|
|
|
323
204
|
```bash
|
|
324
|
-
|
|
325
|
-
writechoice
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
# Or fix from default report (links_report.json)
|
|
331
|
-
writechoice check links docs.example.com --fix-from-report
|
|
205
|
+
git clone <repository-url>
|
|
206
|
+
cd writechoice-mint-cli
|
|
207
|
+
npm install
|
|
208
|
+
npx playwright install chromium
|
|
209
|
+
chmod +x bin/cli.js
|
|
210
|
+
npm link
|
|
332
211
|
```
|
|
333
212
|
|
|
334
|
-
###
|
|
213
|
+
### Project Structure
|
|
335
214
|
|
|
336
|
-
```
|
|
337
|
-
writechoice
|
|
215
|
+
```
|
|
216
|
+
writechoice-mint-cli/
|
|
217
|
+
├── bin/
|
|
218
|
+
│ └── cli.js # CLI entry point
|
|
219
|
+
├── src/
|
|
220
|
+
│ ├── commands/
|
|
221
|
+
│ │ ├── validate/
|
|
222
|
+
│ │ │ ├── links.js # Link validation
|
|
223
|
+
│ │ │ └── mdx.js # MDX parsing validation
|
|
224
|
+
│ │ └── fix/
|
|
225
|
+
│ │ └── links.js # Link fixing
|
|
226
|
+
│ └── utils/
|
|
227
|
+
│ ├── helpers.js # Utility functions
|
|
228
|
+
│ └── reports.js # Report generation
|
|
229
|
+
├── docs/ # Detailed documentation
|
|
230
|
+
├── package.json
|
|
231
|
+
└── README.md
|
|
338
232
|
```
|
|
339
233
|
|
|
340
234
|
## Troubleshooting
|
|
341
235
|
|
|
342
236
|
### Playwright Not Installed
|
|
343
237
|
|
|
344
|
-
If you get an error about Playwright not being installed:
|
|
345
|
-
|
|
346
238
|
```bash
|
|
347
239
|
npx playwright install chromium
|
|
348
240
|
```
|
|
349
241
|
|
|
350
242
|
### Memory Issues
|
|
351
243
|
|
|
352
|
-
If you encounter memory issues with high concurrency:
|
|
353
|
-
|
|
354
244
|
```bash
|
|
355
245
|
writechoice check links docs.example.com -c 10
|
|
356
246
|
```
|
|
357
247
|
|
|
358
|
-
###
|
|
359
|
-
|
|
360
|
-
If the browser fails to launch in headless mode:
|
|
248
|
+
### Permission Errors
|
|
361
249
|
|
|
362
250
|
```bash
|
|
363
|
-
|
|
251
|
+
sudo npm install -g @writechoice/mint-cli
|
|
364
252
|
```
|
|
365
253
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
### Project Structure
|
|
369
|
-
|
|
370
|
-
```
|
|
371
|
-
writechoice-mint-cli/
|
|
372
|
-
├── bin/
|
|
373
|
-
│ └── cli.js # CLI entry point
|
|
374
|
-
├── src/
|
|
375
|
-
│ ├── commands/
|
|
376
|
-
│ │ └── validate/
|
|
377
|
-
│ │ └── links.js # Link validation logic
|
|
378
|
-
│ └── utils/
|
|
379
|
-
│ └── helpers.js # Helper functions
|
|
380
|
-
├── package.json
|
|
381
|
-
└── README.md
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
### Running Tests
|
|
385
|
-
|
|
386
|
-
```bash
|
|
387
|
-
npm test
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
### Adding New Commands
|
|
391
|
-
|
|
392
|
-
1. Create a new command file in `src/commands/`
|
|
393
|
-
2. Add the command to `bin/cli.js`
|
|
394
|
-
3. Update this README with usage instructions
|
|
254
|
+
Or use a node version manager like [nvm](https://github.com/nvm-sh/nvm).
|
|
395
255
|
|
|
396
256
|
## License
|
|
397
257
|
|
|
@@ -400,3 +260,9 @@ MIT
|
|
|
400
260
|
## Contributing
|
|
401
261
|
|
|
402
262
|
Contributions are welcome! Please open an issue or submit a pull request.
|
|
263
|
+
|
|
264
|
+
## Links
|
|
265
|
+
|
|
266
|
+
- [npm package](https://www.npmjs.com/package/@writechoice/mint-cli)
|
|
267
|
+
- [GitHub repository](https://github.com/writechoice/mint-cli)
|
|
268
|
+
- [Issue tracker](https://github.com/writechoice/mint-cli/issues)
|
package/bin/cli.js
CHANGED
|
@@ -24,25 +24,86 @@ const check = program.command("check").description("Validation commands for docu
|
|
|
24
24
|
|
|
25
25
|
// Validate links subcommand
|
|
26
26
|
check
|
|
27
|
-
.command("links
|
|
27
|
+
.command("links [baseUrl] [validationBaseUrl]")
|
|
28
28
|
.description("Validate internal links and anchors in MDX documentation files")
|
|
29
29
|
.option("-f, --file <path>", "Validate links in a single MDX file")
|
|
30
30
|
.option("-d, --dir <path>", "Validate links in a specific directory")
|
|
31
|
-
.option("-o, --output <path>", "Output path for
|
|
31
|
+
.option("-o, --output <path>", "Output path for report (without extension)", "links_report")
|
|
32
32
|
.option("--dry-run", "Extract and show links without validating")
|
|
33
33
|
.option("--quiet", "Suppress terminal output (only generate report)")
|
|
34
34
|
.option("-c, --concurrency <number>", "Number of concurrent browser tabs", "25")
|
|
35
35
|
.option("--headless", "Run browser in headless mode (default)", true)
|
|
36
36
|
.option("--no-headless", "Show browser window (for debugging)")
|
|
37
|
-
.option("--fix", "Automatically fix anchor links in MDX files")
|
|
38
|
-
.option("--fix-from-report [path]", "Fix anchor links from report file (default: links_report.json)")
|
|
39
37
|
.action(async (baseUrl, validationBaseUrl, options) => {
|
|
38
|
+
const { loadConfig, mergeLinksConfig, validateRequiredConfig } = await import("../src/utils/config.js");
|
|
40
39
|
const { validateLinks } = await import("../src/commands/validate/links.js");
|
|
41
|
-
|
|
40
|
+
|
|
41
|
+
// Load config.json if it exists
|
|
42
|
+
const config = loadConfig();
|
|
43
|
+
|
|
44
|
+
// Merge CLI args with config file (CLI takes precedence)
|
|
45
|
+
const merged = mergeLinksConfig(baseUrl, validationBaseUrl, options, config);
|
|
46
|
+
|
|
47
|
+
// Validate that baseUrl is provided (either via CLI or config)
|
|
48
|
+
try {
|
|
49
|
+
validateRequiredConfig(merged.baseUrl, "writechoice check links");
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(error.message);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Set defaults
|
|
56
|
+
merged.options.verbose = !merged.options.quiet;
|
|
57
|
+
merged.options.validationBaseUrl = merged.validationBaseUrl || "http://localhost:3000";
|
|
58
|
+
|
|
59
|
+
await validateLinks(merged.baseUrl, merged.options);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Validate MDX parsing subcommand
|
|
63
|
+
check
|
|
64
|
+
.command("parse")
|
|
65
|
+
.description("Validate MDX files for parsing errors")
|
|
66
|
+
.option("-f, --file <path>", "Validate a single MDX file")
|
|
67
|
+
.option("-d, --dir <path>", "Validate MDX files in a specific directory")
|
|
68
|
+
.option("--quiet", "Suppress terminal output (only generate report)")
|
|
69
|
+
.action(async (options) => {
|
|
70
|
+
const { loadConfig, mergeParseConfig } = await import("../src/utils/config.js");
|
|
71
|
+
const { validateMdxFiles } = await import("../src/commands/validate/mdx.js");
|
|
72
|
+
|
|
73
|
+
// Load config.json if it exists
|
|
74
|
+
const config = loadConfig();
|
|
75
|
+
|
|
76
|
+
// Merge CLI args with config file (CLI takes precedence)
|
|
77
|
+
const mergedOptions = mergeParseConfig(options, config);
|
|
78
|
+
|
|
79
|
+
mergedOptions.verbose = !mergedOptions.quiet;
|
|
80
|
+
await validateMdxFiles(mergedOptions);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Fix command
|
|
84
|
+
const fix = program.command("fix").description("Fix issues found in validation reports");
|
|
85
|
+
|
|
86
|
+
// Fix links subcommand
|
|
87
|
+
fix
|
|
88
|
+
.command("links")
|
|
89
|
+
.description("Fix broken anchor links from validation report")
|
|
90
|
+
.option("-r, --report <path>", "Path to validation report", "links_report.json")
|
|
91
|
+
.option("--quiet", "Suppress terminal output")
|
|
92
|
+
.action(async (options) => {
|
|
93
|
+
const { fixLinks } = await import("../src/commands/fix/links.js");
|
|
42
94
|
options.verbose = !options.quiet;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
95
|
+
await fixLinks(options);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Config command
|
|
99
|
+
program
|
|
100
|
+
.command("config")
|
|
101
|
+
.description("Generate a config.json template file")
|
|
102
|
+
.option("--force", "Overwrite existing config.json file")
|
|
103
|
+
.option("--quiet", "Suppress terminal output")
|
|
104
|
+
.action(async (options) => {
|
|
105
|
+
const { generateConfig } = await import("../src/commands/config.js");
|
|
106
|
+
await generateConfig(options);
|
|
46
107
|
});
|
|
47
108
|
|
|
48
109
|
// Update command
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@writechoice/mint-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "CLI tool for Mintlify documentation validation and utilities",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -41,11 +41,12 @@
|
|
|
41
41
|
"PUBLISH.md"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
+
"@mdx-js/mdx": "^3.1.1",
|
|
45
|
+
"chalk": "^5.3.0",
|
|
44
46
|
"commander": "^12.0.0",
|
|
45
|
-
"playwright": "^1.40.0"
|
|
46
|
-
"chalk": "^5.3.0"
|
|
47
|
+
"playwright": "^1.40.0"
|
|
47
48
|
},
|
|
48
49
|
"engines": {
|
|
49
50
|
"node": ">=18.0.0"
|
|
50
51
|
}
|
|
51
|
-
}
|
|
52
|
+
}
|