@writechoice/mint-cli 0.0.7 → 0.0.9
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 +138 -287
- package/bin/cli.js +58 -8
- package/package.json +5 -4
- 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,241 @@
|
|
|
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
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
5
|
+
## Quick Start
|
|
14
6
|
|
|
15
|
-
###
|
|
7
|
+
### Installation
|
|
16
8
|
|
|
17
9
|
```bash
|
|
18
10
|
npm install -g @writechoice/mint-cli
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Local Development
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
# Clone the repository
|
|
25
|
-
git clone <repository-url>
|
|
26
|
-
cd writechoice-mint-cli
|
|
27
|
-
|
|
28
|
-
# Install dependencies
|
|
29
|
-
npm install
|
|
30
|
-
|
|
31
|
-
# Install Playwright browsers
|
|
32
11
|
npx playwright install chromium
|
|
33
|
-
|
|
34
|
-
# Make CLI executable
|
|
35
|
-
chmod +x bin/cli.js
|
|
36
|
-
|
|
37
|
-
# Link for local development
|
|
38
|
-
npm link
|
|
39
12
|
```
|
|
40
13
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### Check Version
|
|
44
|
-
|
|
45
|
-
Check the installed version:
|
|
14
|
+
### Usage
|
|
46
15
|
|
|
47
16
|
```bash
|
|
17
|
+
# Check version
|
|
48
18
|
writechoice --version
|
|
49
|
-
# or
|
|
50
|
-
writechoice -v
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Update to Latest Version
|
|
54
|
-
|
|
55
|
-
Update to the latest version from npm:
|
|
56
19
|
|
|
57
|
-
|
|
20
|
+
# Update to latest
|
|
58
21
|
writechoice update
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
The CLI also automatically checks for updates and displays a notification when a new version is available.
|
|
62
|
-
|
|
63
|
-
### Validate Links
|
|
64
22
|
|
|
65
|
-
Validate
|
|
23
|
+
# Validate MDX parsing
|
|
24
|
+
writechoice check parse
|
|
66
25
|
|
|
67
|
-
|
|
26
|
+
# Validate links
|
|
68
27
|
writechoice check links https://docs.example.com
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
You can also omit the `https://` prefix:
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
writechoice check links docs.example.com
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
**Using a Validation Base URL**
|
|
78
28
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
# Use localhost:3000 for validation (default)
|
|
83
|
-
writechoice check links docs.example.com
|
|
84
|
-
|
|
85
|
-
# Use a custom validation URL
|
|
29
|
+
# Validate with local development server
|
|
86
30
|
writechoice check links docs.example.com http://localhost:3000
|
|
87
31
|
|
|
88
|
-
#
|
|
89
|
-
writechoice
|
|
32
|
+
# Fix broken anchor links
|
|
33
|
+
writechoice fix links
|
|
90
34
|
```
|
|
91
35
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
**How the two-step validation works:**
|
|
95
|
-
|
|
96
|
-
For anchor links, the tool performs a smart validation:
|
|
97
|
-
|
|
98
|
-
1. Navigates to your production docs (base URL) to find the actual heading the anchor points to
|
|
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
|
|
36
|
+
## Commands
|
|
101
37
|
|
|
102
|
-
|
|
38
|
+
### `check parse`
|
|
103
39
|
|
|
104
|
-
|
|
105
|
-
- Handles pages with duplicate headings correctly by matching position
|
|
106
|
-
- Validates against your local development environment before deploying
|
|
107
|
-
|
|
108
|
-
### Common Options
|
|
40
|
+
Validates MDX files for parsing errors.
|
|
109
41
|
|
|
110
42
|
```bash
|
|
111
|
-
|
|
112
|
-
writechoice check
|
|
43
|
+
writechoice check parse # All files
|
|
44
|
+
writechoice check parse -f file.mdx # Single file
|
|
45
|
+
writechoice check parse -d docs # Specific directory
|
|
46
|
+
```
|
|
113
47
|
|
|
114
|
-
|
|
115
|
-
writechoice check links docs.example.com -d path/to/docs
|
|
48
|
+
**Output:** Both `mdx_errors_report.json` and `mdx_errors_report.md`
|
|
116
49
|
|
|
117
|
-
|
|
118
|
-
writechoice check links docs.example.com --dry-run
|
|
50
|
+
### `check links`
|
|
119
51
|
|
|
120
|
-
|
|
121
|
-
writechoice check links docs.example.com --quiet
|
|
52
|
+
Validates internal links and anchors using browser automation.
|
|
122
53
|
|
|
123
|
-
|
|
124
|
-
writechoice check links
|
|
54
|
+
```bash
|
|
55
|
+
writechoice check links <baseUrl> [validationBaseUrl]
|
|
56
|
+
```
|
|
125
57
|
|
|
126
|
-
|
|
127
|
-
|
|
58
|
+
**Common options:**
|
|
59
|
+
- `-f, --file <path>` - Validate single file
|
|
60
|
+
- `-d, --dir <path>` - Validate specific directory
|
|
61
|
+
- `-o, --output <path>` - Base name for reports (default: `links_report`)
|
|
62
|
+
- `-c, --concurrency <number>` - Concurrent browser tabs (default: 25)
|
|
63
|
+
- `--quiet` - Suppress output
|
|
64
|
+
- `--dry-run` - Extract links without validating
|
|
128
65
|
|
|
129
|
-
|
|
130
|
-
writechoice check links docs.example.com --no-headless
|
|
66
|
+
**Output:** Both `links_report.json` and `links_report.md`
|
|
131
67
|
|
|
132
|
-
|
|
133
|
-
writechoice check links docs.example.com --fix
|
|
68
|
+
### `fix links`
|
|
134
69
|
|
|
135
|
-
|
|
136
|
-
writechoice check links docs.example.com --fix-from-report
|
|
70
|
+
Automatically fixes broken anchor links based on validation reports.
|
|
137
71
|
|
|
138
|
-
|
|
139
|
-
writechoice
|
|
72
|
+
```bash
|
|
73
|
+
writechoice fix links # Use default report
|
|
74
|
+
writechoice fix links -r custom_report.json # Use custom report
|
|
140
75
|
```
|
|
141
76
|
|
|
142
|
-
|
|
77
|
+
**Common options:**
|
|
78
|
+
- `-r, --report <path>` - Path to JSON report (default: `links_report.json`)
|
|
79
|
+
- `--quiet` - Suppress output
|
|
143
80
|
|
|
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` |
|
|
81
|
+
**Note:** Requires JSON report from `check links` command.
|
|
158
82
|
|
|
159
|
-
|
|
83
|
+
### `update`
|
|
160
84
|
|
|
161
|
-
|
|
85
|
+
Update CLI to latest version.
|
|
162
86
|
|
|
163
|
-
|
|
87
|
+
```bash
|
|
88
|
+
writechoice update
|
|
89
|
+
```
|
|
164
90
|
|
|
165
|
-
|
|
91
|
+
## Features
|
|
166
92
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
93
|
+
- **MDX Parsing Validation** - Catch syntax errors before deployment
|
|
94
|
+
- **Link Validation** - Test links against live websites with Playwright
|
|
95
|
+
- **Two-Step Anchor Validation** - Compare production vs development anchors
|
|
96
|
+
- **Auto-Fix** - Separate fix command to automatically correct broken anchor links
|
|
97
|
+
- **Dual Report Formats** - Generates both JSON (for automation) and Markdown (for humans)
|
|
98
|
+
- **Configuration File** - Optional config.json for default settings
|
|
99
|
+
- **CI/CD Ready** - Exit codes for pipeline integration
|
|
171
100
|
|
|
172
|
-
|
|
101
|
+
## How Two-Step Validation Works
|
|
173
102
|
|
|
174
|
-
|
|
175
|
-
- HTML images: `<img src="./image.png" />`
|
|
103
|
+
For anchor links, the tool:
|
|
176
104
|
|
|
177
|
-
|
|
105
|
+
1. **Finds the target** (Production): Navigates to production docs to identify which heading the anchor points to
|
|
106
|
+
2. **Gets the anchor** (Validation): Navigates to your dev server (localhost:3000), clicks the heading, and extracts the generated anchor
|
|
107
|
+
3. **Compares**: Checks if anchors match
|
|
178
108
|
|
|
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
|
|
109
|
+
This ensures your local development environment matches production behavior.
|
|
190
110
|
|
|
191
|
-
|
|
111
|
+
## Configuration File
|
|
192
112
|
|
|
193
|
-
|
|
113
|
+
Create an optional `config.json` in your project root to set default values:
|
|
194
114
|
|
|
195
115
|
```json
|
|
196
116
|
{
|
|
197
|
-
"
|
|
198
|
-
"
|
|
199
|
-
|
|
200
|
-
"scanned_directories": ["."],
|
|
201
|
-
"excluded_directories": ["snippets"],
|
|
117
|
+
"source": "https://docs.example.com",
|
|
118
|
+
"target": "http://localhost:3000",
|
|
119
|
+
"links": {
|
|
202
120
|
"concurrency": 25,
|
|
203
|
-
"
|
|
121
|
+
"quiet": false
|
|
204
122
|
},
|
|
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
|
-
]
|
|
123
|
+
"parse": {
|
|
124
|
+
"quiet": false
|
|
226
125
|
}
|
|
227
126
|
}
|
|
228
127
|
```
|
|
229
128
|
|
|
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:
|
|
129
|
+
With config.json, you can run commands without arguments:
|
|
254
130
|
|
|
255
131
|
```bash
|
|
256
|
-
#
|
|
257
|
-
writechoice check links
|
|
132
|
+
# Uses source and target from config.json
|
|
133
|
+
writechoice check links
|
|
258
134
|
|
|
259
|
-
#
|
|
260
|
-
writechoice check links
|
|
135
|
+
# CLI args override config.json values
|
|
136
|
+
writechoice check links https://staging.example.com
|
|
261
137
|
```
|
|
262
138
|
|
|
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
|
-
```
|
|
139
|
+
See [config.example.json](config.example.json) for all available options.
|
|
273
140
|
|
|
274
|
-
|
|
141
|
+
## Examples
|
|
275
142
|
|
|
276
143
|
```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:
|
|
144
|
+
# Validate all MDX files for parsing errors
|
|
145
|
+
writechoice check parse
|
|
289
146
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
You can modify this in the source code at [src/commands/validate/links.js](src/commands/validate/links.js).
|
|
147
|
+
# Validate all links (uses localhost:3000 by default)
|
|
148
|
+
writechoice check links https://docs.example.com
|
|
293
149
|
|
|
294
|
-
|
|
150
|
+
# Validate with staging environment
|
|
151
|
+
writechoice check links docs.example.com https://staging.example.com
|
|
295
152
|
|
|
296
|
-
|
|
153
|
+
# Validate specific directory only
|
|
154
|
+
writechoice check links docs.example.com -d api
|
|
297
155
|
|
|
298
|
-
|
|
299
|
-
|
|
156
|
+
# Run quietly (only generate reports)
|
|
157
|
+
writechoice check links docs.example.com --quiet
|
|
300
158
|
|
|
301
|
-
|
|
159
|
+
# Fix broken anchor links
|
|
160
|
+
writechoice fix links
|
|
302
161
|
|
|
303
|
-
|
|
162
|
+
# Fix from custom report
|
|
163
|
+
writechoice fix links -r custom_report.json
|
|
304
164
|
|
|
305
|
-
|
|
165
|
+
# Full workflow: validate -> fix -> re-validate
|
|
166
|
+
writechoice check links docs.example.com
|
|
167
|
+
writechoice fix links
|
|
306
168
|
writechoice check links docs.example.com
|
|
307
169
|
```
|
|
308
170
|
|
|
309
|
-
|
|
171
|
+
## Documentation
|
|
310
172
|
|
|
311
|
-
|
|
312
|
-
writechoice check links docs.example.com --quiet
|
|
313
|
-
```
|
|
173
|
+
Detailed documentation is available in the [docs/](docs/) folder:
|
|
314
174
|
|
|
315
|
-
|
|
175
|
+
- **Commands**
|
|
176
|
+
- [check links](docs/commands/check-links.md) - Link validation
|
|
177
|
+
- [check parse](docs/commands/check-parse.md) - MDX parsing validation
|
|
178
|
+
- [fix links](docs/commands/fix-links.md) - Auto-fix broken links
|
|
179
|
+
- [update](docs/commands/update.md) - Update command
|
|
180
|
+
- **Guides**
|
|
181
|
+
- [Configuration File](docs/config-file.md) - Using config.json
|
|
182
|
+
- [Configuration](docs/configuration.md) - Advanced configuration
|
|
183
|
+
- [Publishing](docs/publishing.md) - How to publish new versions
|
|
316
184
|
|
|
317
|
-
|
|
318
|
-
writechoice check links docs.example.com --fix
|
|
319
|
-
```
|
|
185
|
+
## Development
|
|
320
186
|
|
|
321
|
-
###
|
|
187
|
+
### Local Setup
|
|
322
188
|
|
|
323
189
|
```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
|
|
190
|
+
git clone <repository-url>
|
|
191
|
+
cd writechoice-mint-cli
|
|
192
|
+
npm install
|
|
193
|
+
npx playwright install chromium
|
|
194
|
+
chmod +x bin/cli.js
|
|
195
|
+
npm link
|
|
332
196
|
```
|
|
333
197
|
|
|
334
|
-
###
|
|
198
|
+
### Project Structure
|
|
335
199
|
|
|
336
|
-
```
|
|
337
|
-
writechoice
|
|
200
|
+
```
|
|
201
|
+
writechoice-mint-cli/
|
|
202
|
+
├── bin/
|
|
203
|
+
│ └── cli.js # CLI entry point
|
|
204
|
+
├── src/
|
|
205
|
+
│ ├── commands/
|
|
206
|
+
│ │ ├── validate/
|
|
207
|
+
│ │ │ ├── links.js # Link validation
|
|
208
|
+
│ │ │ └── mdx.js # MDX parsing validation
|
|
209
|
+
│ │ └── fix/
|
|
210
|
+
│ │ └── links.js # Link fixing
|
|
211
|
+
│ └── utils/
|
|
212
|
+
│ ├── helpers.js # Utility functions
|
|
213
|
+
│ └── reports.js # Report generation
|
|
214
|
+
├── docs/ # Detailed documentation
|
|
215
|
+
├── package.json
|
|
216
|
+
└── README.md
|
|
338
217
|
```
|
|
339
218
|
|
|
340
219
|
## Troubleshooting
|
|
341
220
|
|
|
342
221
|
### Playwright Not Installed
|
|
343
222
|
|
|
344
|
-
If you get an error about Playwright not being installed:
|
|
345
|
-
|
|
346
223
|
```bash
|
|
347
224
|
npx playwright install chromium
|
|
348
225
|
```
|
|
349
226
|
|
|
350
227
|
### Memory Issues
|
|
351
228
|
|
|
352
|
-
If you encounter memory issues with high concurrency:
|
|
353
|
-
|
|
354
229
|
```bash
|
|
355
230
|
writechoice check links docs.example.com -c 10
|
|
356
231
|
```
|
|
357
232
|
|
|
358
|
-
###
|
|
359
|
-
|
|
360
|
-
If the browser fails to launch in headless mode:
|
|
361
|
-
|
|
362
|
-
```bash
|
|
363
|
-
writechoice check links docs.example.com --no-headless
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
## Development
|
|
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
|
|
233
|
+
### Permission Errors
|
|
385
234
|
|
|
386
235
|
```bash
|
|
387
|
-
npm
|
|
236
|
+
sudo npm install -g @writechoice/mint-cli
|
|
388
237
|
```
|
|
389
238
|
|
|
390
|
-
|
|
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
|
|
239
|
+
Or use a node version manager like [nvm](https://github.com/nvm-sh/nvm).
|
|
395
240
|
|
|
396
241
|
## License
|
|
397
242
|
|
|
@@ -400,3 +245,9 @@ MIT
|
|
|
400
245
|
## Contributing
|
|
401
246
|
|
|
402
247
|
Contributions are welcome! Please open an issue or submit a pull request.
|
|
248
|
+
|
|
249
|
+
## Links
|
|
250
|
+
|
|
251
|
+
- [npm package](https://www.npmjs.com/package/@writechoice/mint-cli)
|
|
252
|
+
- [GitHub repository](https://github.com/writechoice/mint-cli)
|
|
253
|
+
- [Issue tracker](https://github.com/writechoice/mint-cli/issues)
|
package/bin/cli.js
CHANGED
|
@@ -24,25 +24,75 @@ 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
|
-
options.validationBaseUrl = validationBaseUrl || "http://localhost:3000";
|
|
45
|
-
await validateLinks(baseUrl, options);
|
|
95
|
+
await fixLinks(options);
|
|
46
96
|
});
|
|
47
97
|
|
|
48
98
|
// 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.9",
|
|
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
|
+
}
|