@writechoice/mint-cli 0.0.1

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/README.md ADDED
@@ -0,0 +1,324 @@
1
+ # WriteChoice Mint CLI
2
+
3
+ CLI tool for Mintlify documentation validation and utilities.
4
+
5
+ ## Features
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
14
+
15
+ ### Global Installation
16
+
17
+ ```bash
18
+ 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
+ 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
+ ```
40
+
41
+ ## Usage
42
+
43
+ ### Validate Links
44
+
45
+ Validate all internal links and anchors in your MDX documentation:
46
+
47
+ ```bash
48
+ writechoice check links https://docs.example.com
49
+ ```
50
+
51
+ You can also omit the `https://` prefix:
52
+
53
+ ```bash
54
+ writechoice check links docs.example.com
55
+ ```
56
+
57
+ ### Common Options
58
+
59
+ ```bash
60
+ # Validate links in a specific file
61
+ writechoice check links docs.example.com -f path/to/file.mdx
62
+
63
+ # Validate links in a specific directory
64
+ writechoice check links docs.example.com -d path/to/docs
65
+
66
+ # Use short aliases for common flags
67
+ writechoice check links docs.example.com -v -o my_report.json
68
+
69
+ # Dry run (extract links without validating)
70
+ writechoice check links docs.example.com --dry-run
71
+
72
+ # Verbose output
73
+ writechoice check links docs.example.com -v
74
+
75
+ # Quiet mode (only generate report)
76
+ writechoice check links docs.example.com --quiet
77
+
78
+ # Custom output path for report
79
+ writechoice check links docs.example.com -o validation-report.json
80
+
81
+ # Set concurrency level
82
+ writechoice check links docs.example.com -c 50
83
+
84
+ # Show browser window (for debugging)
85
+ writechoice check links docs.example.com --no-headless
86
+
87
+ # Auto-fix incorrect anchor links
88
+ writechoice check links docs.example.com --fix
89
+
90
+ # Fix links from the default report file (links_report.json)
91
+ writechoice check links docs.example.com --fix-from-report
92
+
93
+ # Fix links from a custom report file
94
+ writechoice check links docs.example.com --fix-from-report custom_report.json
95
+ ```
96
+
97
+ ### Complete Options
98
+
99
+ | Option | Alias | Description | Default |
100
+ | -------------------------- | ----- | ------------------------------------------------------------------------ | ------------------- |
101
+ | `<baseUrl>` | - | Base URL for the documentation site (required, with or without https://) | - |
102
+ | `--file <path>` | `-f` | Validate links in a single MDX file | - |
103
+ | `--dir <path>` | `-d` | Validate links in a specific directory | - |
104
+ | `--output <path>` | `-o` | Output path for JSON report | `links_report.json` |
105
+ | `--dry-run` | - | Extract and show links without validating | `false` |
106
+ | `--verbose` | `-v` | Print detailed progress information | `false` |
107
+ | `--quiet` | - | Suppress stdout output (only generate report) | `false` |
108
+ | `--concurrency <number>` | `-c` | Number of concurrent browser tabs | `25` |
109
+ | `--headless` | - | Run browser in headless mode | `true` |
110
+ | `--no-headless` | - | Show browser window (for debugging) | - |
111
+ | `--fix` | - | Automatically fix anchor links in MDX files | `false` |
112
+ | `--fix-from-report [path]` | - | Fix anchor links from report file (optional path) | `links_report.json` |
113
+
114
+ ## How It Works
115
+
116
+ ### Link Extraction
117
+
118
+ The tool extracts internal links from MDX files in the following formats:
119
+
120
+ 1. **Markdown links**: `[Link Text](./path/to/page#anchor)`
121
+ 2. **HTML anchors**: `<a href="/path/to/page#anchor">Link Text</a>`
122
+ 3. **JSX Card components**: `<Card href="/path/to/page" title="Card Title" />`
123
+ 4. **JSX Button components**: `<Button href="/path/to/page#anchor">Button Text</Button>`
124
+
125
+ ### Validation Process
126
+
127
+ 1. **Local Validation**: First checks if the target MDX file exists locally
128
+ 2. **Online Validation**: If local check fails, uses Playwright to navigate to the live URL
129
+ 3. **Anchor Validation**: For anchor links, verifies the heading exists and matches the anchor format
130
+ 4. **Kebab-case Checking**: Ensures anchors follow the correct kebab-case format
131
+
132
+ ### Report Format
133
+
134
+ The tool generates a JSON report with the following structure:
135
+
136
+ ```json
137
+ {
138
+ "timestamp": "2024-01-15T10:30:00.000Z",
139
+ "configuration": {
140
+ "base_url": "https://docs.example.com",
141
+ "scanned_directories": ["."],
142
+ "excluded_directories": ["snippets"],
143
+ "concurrency": 25,
144
+ "execution_time_seconds": 45.23
145
+ },
146
+ "summary": {
147
+ "total_links": 250,
148
+ "success": 240,
149
+ "failure": 8,
150
+ "error": 2
151
+ },
152
+ "summary_by_file": {
153
+ "docs/getting-started.mdx": {
154
+ "total": 10,
155
+ "success": 9,
156
+ "failure": 1,
157
+ "error": 0
158
+ }
159
+ },
160
+ "results_by_file": {
161
+ "docs/getting-started.mdx": [
162
+ {
163
+ "source": {
164
+ "filePath": "docs/getting-started.mdx",
165
+ "lineNumber": 42,
166
+ "linkText": "Installation Guide",
167
+ "rawHref": "./installation#setup",
168
+ "linkType": "markdown"
169
+ },
170
+ "targetUrl": "https://docs.example.com/docs/installation#setup",
171
+ "status": "failure",
172
+ "errorMessage": "Expected anchor \"#setup\" but page heading \"Setup Process\" should use \"#setup-process\""
173
+ }
174
+ ]
175
+ }
176
+ }
177
+ ```
178
+
179
+ ## Auto-Fix Feature
180
+
181
+ The `--fix` option automatically corrects anchor links that don't match the heading text:
182
+
183
+ **Before:**
184
+
185
+ ```markdown
186
+ [Installation Guide](./installation#setup)
187
+ ```
188
+
189
+ **After:**
190
+
191
+ ```markdown
192
+ [Installation Guide](./installation#setup-process)
193
+ ```
194
+
195
+ ### Fix Workflow
196
+
197
+ 1. **Run validation**: `writechoice check links docs.example.com`
198
+ 2. **Review report**: Check the generated `links_report.json` for issues
199
+ 3. **Apply fixes**: `writechoice check links docs.example.com --fix-from-report`
200
+ 4. **Re-validate**: Run validation again to verify fixes
201
+
202
+ Or use a custom report file:
203
+
204
+ ```bash
205
+ # Generate custom report
206
+ writechoice check links docs.example.com -o my_report.json
207
+
208
+ # Fix from custom report
209
+ writechoice check links docs.example.com --fix-from-report my_report.json
210
+ ```
211
+
212
+ ## Configuration
213
+
214
+ ### Excluded Directories
215
+
216
+ By default, the following directories are excluded from scanning:
217
+
218
+ - `snippets/`
219
+
220
+ You can modify this in the source code at [src/commands/validate/links.js](src/commands/validate/links.js).
221
+
222
+ ### Default Concurrency
223
+
224
+ The default concurrency is set to 25 concurrent browser tabs. Adjust this based on your system resources:
225
+
226
+ - **Lower values** (5-10): Slower but less resource-intensive
227
+ - **Higher values** (50-100): Faster but requires more memory and CPU
228
+
229
+ ## Examples
230
+
231
+ ### Validate all links with verbose output
232
+
233
+ ```bash
234
+ writechoice check links docs.example.com -v
235
+ ```
236
+
237
+ ### Validate and fix issues in one command
238
+
239
+ ```bash
240
+ writechoice check links docs.example.com --fix -v
241
+ ```
242
+
243
+ ### Two-step fix workflow
244
+
245
+ ```bash
246
+ # Step 1: Generate report
247
+ writechoice check links docs.example.com -o issues.json
248
+
249
+ # Step 2: Review and apply fixes
250
+ writechoice check links docs.example.com --fix-from-report issues.json
251
+
252
+ # Or fix from default report (links_report.json)
253
+ writechoice check links docs.example.com --fix-from-report
254
+ ```
255
+
256
+ ### Validate specific directory
257
+
258
+ ```bash
259
+ writechoice check links docs.example.com -d docs/api -v
260
+ ```
261
+
262
+ ## Troubleshooting
263
+
264
+ ### Playwright Not Installed
265
+
266
+ If you get an error about Playwright not being installed:
267
+
268
+ ```bash
269
+ npx playwright install chromium
270
+ ```
271
+
272
+ ### Memory Issues
273
+
274
+ If you encounter memory issues with high concurrency:
275
+
276
+ ```bash
277
+ writechoice check links docs.example.com -c 10
278
+ ```
279
+
280
+ ### Browser Launch Failed
281
+
282
+ If the browser fails to launch in headless mode:
283
+
284
+ ```bash
285
+ writechoice check links docs.example.com --no-headless
286
+ ```
287
+
288
+ ## Development
289
+
290
+ ### Project Structure
291
+
292
+ ```
293
+ writechoice-mint-cli/
294
+ ├── bin/
295
+ │ └── cli.js # CLI entry point
296
+ ├── src/
297
+ │ ├── commands/
298
+ │ │ └── validate/
299
+ │ │ └── links.js # Link validation logic
300
+ │ └── utils/
301
+ │ └── helpers.js # Helper functions
302
+ ├── package.json
303
+ └── README.md
304
+ ```
305
+
306
+ ### Running Tests
307
+
308
+ ```bash
309
+ npm test
310
+ ```
311
+
312
+ ### Adding New Commands
313
+
314
+ 1. Create a new command file in `src/commands/`
315
+ 2. Add the command to `bin/cli.js`
316
+ 3. Update this README with usage instructions
317
+
318
+ ## License
319
+
320
+ MIT
321
+
322
+ ## Contributing
323
+
324
+ Contributions are welcome! Please open an issue or submit a pull request.
package/bin/cli.js ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from "commander";
4
+ import { fileURLToPath } from "url";
5
+ import { dirname, join } from "path";
6
+ import { readFileSync } from "fs";
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+
11
+ // Read package.json for version
12
+ const packageJson = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
13
+
14
+ const program = new Command();
15
+
16
+ program
17
+ .name("writechoice")
18
+ .description("CLI tool for Mintlify documentation validation and utilities")
19
+ .version(packageJson.version);
20
+
21
+ // Validate command
22
+ const check = program.command("check").description("Validation commands for documentation");
23
+
24
+ // Validate links subcommand
25
+ check
26
+ .command("links <baseUrl>")
27
+ .description("Validate internal links and anchors in MDX documentation files")
28
+ .option("-f, --file <path>", "Validate links in a single MDX file")
29
+ .option("-d, --dir <path>", "Validate links in a specific directory")
30
+ .option("-o, --output <path>", "Output path for JSON report", "links_report.json")
31
+ .option("--dry-run", "Extract and show links without validating")
32
+ .option("-v, --verbose", "Print detailed progress information")
33
+ .option("--quiet", "Suppress stdout output (only generate report)")
34
+ .option("-c, --concurrency <number>", "Number of concurrent browser tabs", "25")
35
+ .option("--headless", "Run browser in headless mode (default)", true)
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
+ .action(async (baseUrl, options) => {
40
+ const { validateLinks } = await import("../src/commands/validate/links.js");
41
+ await validateLinks(baseUrl, options);
42
+ });
43
+
44
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@writechoice/mint-cli",
3
+ "version": "0.0.1",
4
+ "description": "CLI tool for Mintlify documentation validation and utilities",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "writechoice": "bin/cli.js",
9
+ "wc": "bin/cli.js"
10
+ },
11
+ "scripts": {
12
+ "test": "echo \"Error: no test specified\" && exit 1",
13
+ "dev": "node bin/cli.js",
14
+ "postinstall": "echo \"\\n⚠️ Don't forget to install Playwright browsers:\\n npx playwright install chromium\\n\""
15
+ },
16
+ "keywords": [
17
+ "mintlify",
18
+ "documentation",
19
+ "validation",
20
+ "cli",
21
+ "mdx",
22
+ "links",
23
+ "anchor",
24
+ "link-checker"
25
+ ],
26
+ "author": "WriteChoice",
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/writechoice/mint-cli.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/writechoice/mint-cli/issues"
34
+ },
35
+ "homepage": "https://github.com/writechoice/mint-cli#readme",
36
+ "files": [
37
+ "bin/",
38
+ "src/",
39
+ "README.md",
40
+ "LICENSE",
41
+ "PUBLISH.md"
42
+ ],
43
+ "dependencies": {
44
+ "commander": "^12.0.0",
45
+ "playwright": "^1.40.0",
46
+ "chalk": "^5.3.0"
47
+ },
48
+ "engines": {
49
+ "node": ">=18.0.0"
50
+ }
51
+ }