@mintlify/cli 4.0.1738 → 4.0.1740

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.
@@ -1,8 +1,10 @@
1
- import { addLog, validateBuild } from '@mintlify/previewing';
1
+ import { addLog, checkBuild } from '@mintlify/previewing';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'node:path';
4
4
  import { mockProcessExit } from 'vitest-mock-process';
5
5
 
6
+ import { sendPublishPrompt } from '../src/signup.js';
7
+ import { toReport } from '../src/validate/report.js';
6
8
  import { runCommand } from './utils.js';
7
9
 
8
10
  const { dir } = vi.hoisted(() => ({
@@ -14,9 +16,19 @@ vi.mock('../src/helpers.js', async (importOriginal) => {
14
16
  return { ...mod, CMD_EXEC_PATH: dir, autoUpgradeIfNeeded: vi.fn() };
15
17
  });
16
18
 
19
+ vi.mock('../src/signup.js', async (importOriginal) => {
20
+ const mod = await importOriginal<typeof import('../src/signup.js')>();
21
+ return { ...mod, sendPublishPrompt: vi.fn() };
22
+ });
23
+
17
24
  vi.mock('@mintlify/previewing', async (importOriginal) => {
18
25
  const mod = await importOriginal<typeof import('@mintlify/previewing')>();
19
- return { ...mod, addLog: vi.fn(), validateBuild: vi.fn() };
26
+ return { ...mod, addLog: vi.fn(), checkBuild: vi.fn() };
27
+ });
28
+
29
+ vi.mock('../src/validate/report.js', async (importOriginal) => {
30
+ const mod = await importOriginal<typeof import('../src/validate/report.js')>();
31
+ return { ...mod, toReport: vi.fn(mod.toReport) };
20
32
  });
21
33
 
22
34
  const processExitMock = mockProcessExit();
@@ -37,80 +49,353 @@ const writeSite = (files: Record<string, string>, config: Record<string, unknown
37
49
  }
38
50
  };
39
51
 
52
+ const report = async (...args: string[]) => {
53
+ await runCommand(...args);
54
+ const result = vi.mocked(toReport).mock.results.at(-1);
55
+ expect(result?.type).toBe('return');
56
+ return result?.value as ReturnType<typeof toReport>;
57
+ };
58
+
40
59
  const logged = () => JSON.stringify(vi.mocked(addLog).mock.calls);
41
60
 
61
+ const rules = (result: { diagnostics: { rule: string }[] }) =>
62
+ result.diagnostics.map(({ rule }) => rule);
63
+
42
64
  describe('mint validate', () => {
43
65
  beforeEach(() => {
44
66
  vi.clearAllMocks();
45
- vi.mocked(validateBuild).mockResolvedValue(undefined as never);
67
+ vi.mocked(checkBuild).mockResolvedValue({ passed: true, warnings: [] });
46
68
  });
47
69
 
48
70
  afterAll(() => {
49
71
  fs.removeSync(dir);
50
72
  });
51
73
 
52
- it('logs lint findings by file and exits 1 before the build', async () => {
74
+ it('builds one report with a summary and every diagnostic', async () => {
53
75
  writeSite({
54
76
  'index.mdx': '---\ntitle: Home\n---\n\nline<br>\n',
55
77
  'other.mdx': '---\ntitle: Other\n---\n\nText {broken\n',
56
78
  });
57
79
 
58
- await runCommand('validate');
80
+ const result = await report('validate', '--no-build');
59
81
 
60
- const text = logged();
61
- expect(text).toContain('index.mdx');
62
- expect(text).toContain('must be self-closed');
63
- expect(text).toContain('other.mdx');
64
- expect(text).toContain('other checks were skipped for this file');
65
- expect(text).toContain('2 errors');
66
- expect(validateBuild).not.toHaveBeenCalled();
82
+ expect(result).toEqual({
83
+ passed: false,
84
+ summary: { errors: 2, warnings: 0, byRule: { 'parse-error': 1, 'void-tags': 1 } },
85
+ diagnostics: [
86
+ expect.objectContaining({
87
+ rule: 'void-tags',
88
+ group: 'content',
89
+ severity: 'error',
90
+ file: 'index.mdx',
91
+ line: 5,
92
+ fix: { file: 'index.mdx', start: 25, end: 29, text: '<br />' },
93
+ }),
94
+ expect.objectContaining({
95
+ rule: 'parse-error',
96
+ severity: 'error',
97
+ file: 'other.mdx',
98
+ message: expect.stringContaining('(other checks were skipped for this file)'),
99
+ }),
100
+ ],
101
+ build: { ran: false, reason: 'disabled' },
102
+ });
67
103
  expect(processExitMock).toHaveBeenCalledWith(1);
68
104
  });
69
105
 
70
- it('continues into the build when the lint pass is clean', async () => {
106
+ it('passes and runs the build', async () => {
71
107
  writeSite({ 'index.mdx': HOME });
72
108
 
73
- await runCommand('validate');
109
+ const result = await report('validate');
74
110
 
75
- expect(validateBuild).toHaveBeenCalledWith(
76
- expect.objectContaining({ packageName: 'mint' }),
77
- expect.any(Function)
78
- );
79
- expect(processExitMock).not.toHaveBeenCalled();
111
+ expect(result).toMatchObject({ passed: true, build: { ran: true, passed: true } });
112
+ expect(rules(result)).toEqual([]);
113
+ expect(checkBuild).toHaveBeenCalled();
114
+ expect(sendPublishPrompt).toHaveBeenCalled();
115
+ expect(processExitMock).toHaveBeenCalledWith(0);
80
116
  });
81
117
 
82
- it('keeps --disable-openapi working', async () => {
83
- writeSite({ 'index.mdx': HOME }, { api: { openapi: 'missing.json' } });
118
+ it('skips the build while there are errors', async () => {
119
+ writeSite({ 'index.mdx': '---\ntitle: Home\n---\n\nline<br>\n' });
84
120
 
85
- await runCommand('validate', '--disable-openapi');
121
+ const result = await report('validate');
86
122
 
87
- expect(validateBuild).toHaveBeenCalled();
123
+ expect(result.build).toEqual({ ran: false, reason: 'errors found' });
124
+ expect(checkBuild).not.toHaveBeenCalled();
125
+ expect(processExitMock).toHaveBeenCalledWith(1);
88
126
  });
89
127
 
90
- it('turns rules and groups on and off', async () => {
91
- writeSite({ 'index.mdx': '---\ntitle: Home\n---\n\nline<br>\n' });
128
+ it('turns build warnings into diagnostics', async () => {
129
+ writeSite({ 'index.mdx': HOME });
130
+ vi.mocked(checkBuild).mockResolvedValue({
131
+ passed: false,
132
+ error: 'Build validation failed with 1 warning(s). See above for details.',
133
+ strict: true,
134
+ warnings: [
135
+ {
136
+ type: 'missing-nav-page',
137
+ message: '"gone" is referenced in the docs.json navigation but the file does not exist.',
138
+ },
139
+ ],
140
+ });
92
141
 
93
- await runCommand('validate', '--disable', 'content');
94
- expect(logged()).toContain('parse-error');
95
- expect(logged()).not.toContain('void-tags');
142
+ const result = await report('validate');
96
143
 
97
- vi.clearAllMocks();
98
- await runCommand('validate', '--disable', 'all', '--enable', 'void-tags');
99
- expect(logged()).toContain('void-tags');
144
+ expect(result.diagnostics).toEqual([
145
+ expect.objectContaining({ rule: 'missing-nav-page', group: 'nav', file: 'docs.json' }),
146
+ ]);
147
+ expect(result.build).toEqual({ ran: true, passed: false });
148
+ expect(processExitMock).toHaveBeenCalledWith(1);
149
+ });
150
+
151
+ it('attributes a missing nav page that looks like a file to the config', async () => {
152
+ writeSite({ 'index.mdx': HOME }, { navigation: { pages: ['index', 'guides/setup.md'] } });
153
+ vi.mocked(checkBuild).mockResolvedValue({
154
+ passed: false,
155
+ error: 'Build validation failed with 1 warning(s). See above for details.',
156
+ strict: true,
157
+ warnings: [
158
+ {
159
+ type: 'missing-nav-page',
160
+ message:
161
+ '"guides/setup.md" is referenced in the docs.json navigation but the file does not exist.',
162
+ },
163
+ ],
164
+ });
165
+
166
+ const result = await report('validate');
167
+
168
+ expect(result.diagnostics).toEqual([
169
+ expect.objectContaining({
170
+ rule: 'missing-nav-page',
171
+ file: 'docs.json',
172
+ line: expect.any(Number),
173
+ }),
174
+ ]);
175
+ });
176
+
177
+ it('reports a build failure no rule explains', async () => {
178
+ writeSite({ 'index.mdx': HOME });
179
+ vi.mocked(checkBuild).mockResolvedValue({
180
+ passed: false,
181
+ error: 'boom',
182
+ strict: false,
183
+ warnings: [],
184
+ });
185
+
186
+ const result = await report('validate');
187
+
188
+ expect(result.diagnostics).toEqual([
189
+ expect.objectContaining({ rule: 'build-failed', message: 'boom' }),
190
+ ]);
191
+ });
192
+
193
+ it('passes when the build fails only on disabled rules', async () => {
194
+ writeSite({ 'index.mdx': HOME });
195
+ vi.mocked(checkBuild).mockResolvedValue({
196
+ passed: false,
197
+ error: 'Build validation failed with 1 warning(s). See above for details.',
198
+ strict: true,
199
+ warnings: [
200
+ {
201
+ type: 'missing-nav-page',
202
+ message: '"gone" is referenced in the docs.json navigation but the file does not exist.',
203
+ },
204
+ ],
205
+ });
206
+
207
+ const result = await report('validate', '--disable', 'missing-nav-page');
208
+
209
+ expect(result).toMatchObject({ passed: true, build: { ran: true, passed: false } });
210
+ expect(rules(result)).toEqual([]);
211
+ expect(sendPublishPrompt).not.toHaveBeenCalled();
212
+ expect(processExitMock).toHaveBeenCalledWith(0);
213
+ });
214
+
215
+ it('fails on a build error even when a disabled rule covers its warnings', async () => {
216
+ writeSite({ 'index.mdx': HOME });
217
+ vi.mocked(checkBuild).mockResolvedValue({
218
+ passed: false,
219
+ error: 'Unexpected token } in docs.json',
220
+ strict: false,
221
+ warnings: [{ type: 'openapi', message: 'Could not read OpenAPI overlay settings' }],
222
+ });
223
+
224
+ const result = await report('validate', '--disable', 'openapi');
225
+
226
+ expect(result.passed).toBe(false);
227
+ expect(result.diagnostics).toEqual([
228
+ expect.objectContaining({ rule: 'build-failed', message: 'Unexpected token } in docs.json' }),
229
+ ]);
230
+ expect(processExitMock).toHaveBeenCalledWith(1);
231
+ });
232
+
233
+ it('skips OpenAPI generation in the build only when no openapi rule is selected', async () => {
234
+ writeSite({ 'index.mdx': HOME });
235
+
236
+ await report('validate', '--disable', 'openapi');
237
+ expect(checkBuild).toHaveBeenLastCalledWith(expect.objectContaining({ disableOpenapi: true }));
238
+
239
+ await report('validate');
240
+ expect(checkBuild).toHaveBeenLastCalledWith(expect.objectContaining({ disableOpenapi: false }));
241
+ });
242
+
243
+ it('cleans build warning messages and lifts their position', async () => {
244
+ writeSite({ 'index.mdx': HOME });
245
+ vi.mocked(checkBuild).mockResolvedValue({
246
+ passed: false,
247
+ error: 'Build validation failed with 1 warning(s). See above for details.',
248
+ strict: true,
249
+ warnings: [
250
+ { type: 'parse-error', message: '\n\u001b[31m./index.mdx:3:7 Unexpected token\u001b[39m' },
251
+ ],
252
+ });
253
+
254
+ const result = await report('validate');
255
+
256
+ expect(result.diagnostics).toEqual([
257
+ expect.objectContaining({
258
+ rule: 'parse-error',
259
+ file: 'index.mdx',
260
+ line: 3,
261
+ column: 7,
262
+ message: './index.mdx:3:7 Unexpected token',
263
+ }),
264
+ ]);
265
+ });
266
+
267
+ it('fails when the build fails on a parse error outside --files', async () => {
268
+ writeSite({ 'index.mdx': HOME, 'other.mdx': HOME });
269
+ vi.mocked(checkBuild).mockResolvedValue({
270
+ passed: false,
271
+ error: 'Build validation failed with 1 warning(s). See above for details.',
272
+ strict: true,
273
+ warnings: [{ type: 'parse-error', message: './other.mdx:3:7 Unexpected token' }],
274
+ });
275
+
276
+ const result = await report('validate', '--files', 'index.mdx');
277
+
278
+ expect(result.passed).toBe(false);
279
+ expect(result.diagnostics).toEqual([
280
+ expect.objectContaining({ rule: 'build-failed', file: 'other.mdx' }),
281
+ ]);
100
282
  expect(processExitMock).toHaveBeenCalledWith(1);
101
283
  });
102
284
 
285
+ it('attributes import warnings to the importing page', async () => {
286
+ writeSite({ 'index.mdx': HOME });
287
+ vi.mocked(checkBuild).mockResolvedValue({
288
+ passed: false,
289
+ error: 'Build validation failed with 3 warning(s). See above for details.',
290
+ strict: true,
291
+ warnings: [
292
+ {
293
+ type: 'missing-file',
294
+ message: 'Could not find file snippets/gone.mdx - imported from index.mdx',
295
+ },
296
+ {
297
+ type: 'invalid-import-path',
298
+ message:
299
+ 'Invalid import path https://example.com/a.jsx in index.mdx. Only local imports are supported.',
300
+ },
301
+ {
302
+ type: 'export-collision',
303
+ message: 'Widget is exported by snippets/a.jsx (in index.mdx, importing snippets/b.mdx)',
304
+ },
305
+ ],
306
+ });
307
+
308
+ const result = await report('validate');
309
+
310
+ expect(result.diagnostics.map(({ file }) => file)).toEqual([
311
+ 'index.mdx',
312
+ 'index.mdx',
313
+ 'index.mdx',
314
+ ]);
315
+ });
316
+
317
+ it('reports missing imported files with the content group', async () => {
318
+ writeSite({ 'index.mdx': HOME });
319
+ vi.mocked(checkBuild).mockResolvedValue({
320
+ passed: false,
321
+ error: 'Build validation failed with 1 warning(s). See above for details.',
322
+ strict: true,
323
+ warnings: [
324
+ {
325
+ type: 'missing-file',
326
+ message: 'Could not find file snippets/gone.mdx - imported from index.mdx',
327
+ },
328
+ ],
329
+ });
330
+
331
+ const result = await report('validate', '--disable', 'all', '--enable', 'content');
332
+
333
+ expect(result.diagnostics).toEqual([
334
+ expect.objectContaining({ rule: 'missing-file', group: 'content', file: 'index.mdx' }),
335
+ ]);
336
+ expect(processExitMock).toHaveBeenCalledWith(1);
337
+ });
338
+
339
+ it('keeps skipped-spec notices as warnings', async () => {
340
+ writeSite({ 'index.mdx': HOME }, { api: { openapi: 'http://example.com/openapi.json' } });
341
+
342
+ const result = await report('validate', '--no-build');
343
+
344
+ expect(result.passed).toBe(true);
345
+ expect(result.diagnostics).toEqual([
346
+ expect.objectContaining({
347
+ rule: 'openapi-spec',
348
+ severity: 'warning',
349
+ message: expect.stringContaining('--local-schema'),
350
+ }),
351
+ expect.objectContaining({
352
+ rule: 'openapi-spec',
353
+ severity: 'warning',
354
+ message: 'only https protocol is supported in production',
355
+ }),
356
+ ]);
357
+ });
358
+
359
+ it('exits 2 when the build could not be prepared', async () => {
360
+ writeSite({ 'index.mdx': HOME });
361
+ vi.mocked(checkBuild).mockRejectedValue(new Error('requires an internet connection'));
362
+
363
+ await runCommand('validate');
364
+
365
+ expect(logged()).toContain('requires an internet connection');
366
+ expect(processExitMock).toHaveBeenCalledWith(2);
367
+ });
368
+
369
+ it('turns rules and groups on and off', async () => {
370
+ writeSite({
371
+ 'index.mdx': '---\ntitle: Home\n---\n\nline<br>\n',
372
+ });
373
+
374
+ // Without void-tags, nothing makes the page parseable
375
+ expect(rules(await report('validate', '--no-build', '--disable', 'content'))).toEqual([
376
+ 'parse-error',
377
+ ]);
378
+ expect(rules(await report('validate', '--no-build', '--disable', 'all'))).toEqual([
379
+ 'parse-error',
380
+ ]);
381
+ expect(
382
+ rules(await report('validate', '--no-build', '--disable', 'all', '--enable', 'void-tags'))
383
+ ).toEqual(['void-tags']);
384
+ expect(
385
+ rules(await report('validate', '--no-build', '--disable', 'openapi, missing-nav-page'))
386
+ ).toEqual(['void-tags']);
387
+ });
388
+
103
389
  it('rejects unknown rules and disabling parse-error', async () => {
104
390
  writeSite({ 'index.mdx': HOME });
105
391
 
106
392
  await runCommand('validate', '--disable', 'nope');
107
393
  expect(logged()).toContain('unknown rule or group');
108
- expect(processExitMock).toHaveBeenLastCalledWith(1);
394
+ expect(processExitMock).toHaveBeenLastCalledWith(2);
109
395
 
110
396
  await runCommand('validate', '--disable', 'parse-error');
111
397
  expect(logged()).toContain("parse-error always runs and can't be disabled");
112
- expect(processExitMock).toHaveBeenLastCalledWith(1);
113
- expect(validateBuild).not.toHaveBeenCalled();
398
+ expect(processExitMock).toHaveBeenLastCalledWith(2);
114
399
  });
115
400
 
116
401
  it('limits page findings to --files', async () => {
@@ -122,11 +407,67 @@ describe('mint validate', () => {
122
407
  { navigation: { pages: ['index', 'other'] } }
123
408
  );
124
409
 
125
- await runCommand('validate', '--files', 'other.mdx');
410
+ const result = await report('validate', '--no-build', '--files', 'other.mdx');
126
411
 
127
- expect(logged()).toContain('other.mdx');
128
- expect(logged()).not.toContain('index.mdx');
129
- expect(processExitMock).toHaveBeenCalledWith(1);
412
+ expect(result.diagnostics.map(({ file }: { file: string }) => file)).toEqual([
413
+ 'other.mdx',
414
+ 'other.mdx',
415
+ ]);
416
+ });
417
+
418
+ it('posix-normalizes Windows paths in build warnings', async () => {
419
+ writeSite({ 'index.mdx': HOME, 'snippets/card.mdx': 'Card\n' });
420
+ vi.mocked(checkBuild).mockResolvedValue({
421
+ passed: false,
422
+ error: 'Build validation failed with 1 warning(s). See above for details.',
423
+ strict: true,
424
+ warnings: [{ type: 'parse-error', message: '.\\snippets\\card.mdx:2:1 Unexpected token' }],
425
+ });
426
+
427
+ const result = await report('validate');
428
+
429
+ expect(result.diagnostics).toEqual([
430
+ expect.objectContaining({ rule: 'parse-error', file: 'snippets/card.mdx', line: 2 }),
431
+ ]);
432
+ });
433
+
434
+ it('checks every OpenAPI spec and sorts findings by file', async () => {
435
+ writeSite({ 'index.mdx': HOME }, { api: { openapi: ['b.json', 'a.json'] } });
436
+ fs.writeFileSync(path.join(dir, 'a.json'), '{ not json');
437
+ fs.writeFileSync(path.join(dir, 'b.json'), '{ not json');
438
+
439
+ const result = await report('validate', '--no-build');
440
+
441
+ expect(result.diagnostics.map(({ rule, file }) => [rule, file])).toEqual([
442
+ ['openapi-spec', 'a.json'],
443
+ ['openapi-spec', 'b.json'],
444
+ ]);
445
+ });
446
+
447
+ it('reports invalid OpenAPI specs and skips them with --disable openapi', async () => {
448
+ writeSite({ 'index.mdx': HOME }, { api: { openapi: 'openapi.json' } });
449
+ fs.writeFileSync(path.join(dir, 'openapi.json'), '{ not json');
450
+
451
+ expect(rules(await report('validate', '--no-build'))).toEqual(['openapi-spec']);
452
+ expect(rules(await report('validate', '--no-build', '--disable', 'openapi'))).toEqual([]);
453
+ });
454
+
455
+ it('checks the OpenAPI specs a mint.json lists', async () => {
456
+ writeSite({ 'index.mdx': HOME });
457
+ fs.removeSync(path.join(dir, 'docs.json'));
458
+ fs.writeJSONSync(path.join(dir, 'mint.json'), {
459
+ name: 'Test',
460
+ colors: { primary: '#000000' },
461
+ navigation: [{ group: 'Home', pages: ['index'] }],
462
+ openapi: 'openapi.json',
463
+ });
464
+ fs.writeFileSync(path.join(dir, 'openapi.json'), '{ not json');
465
+
466
+ const result = await report('validate', '--no-build');
467
+
468
+ expect(result.diagnostics).toEqual([
469
+ expect.objectContaining({ rule: 'openapi-spec', file: 'openapi.json' }),
470
+ ]);
130
471
  });
131
472
 
132
473
  it('rejects --files that match nothing', async () => {
@@ -135,7 +476,29 @@ describe('mint validate', () => {
135
476
  await runCommand('validate', '--files', 'missing.mdx');
136
477
 
137
478
  expect(logged()).toContain('No matching files');
479
+ expect(processExitMock).toHaveBeenCalledWith(2);
480
+ expect(checkBuild).not.toHaveBeenCalled();
481
+ });
482
+
483
+ it('rejects the removed --disable-openapi flag', async () => {
484
+ writeSite({ 'index.mdx': HOME });
485
+ const error = vi.spyOn(console, 'error').mockImplementation(() => undefined);
486
+
487
+ await expect(runCommand('validate', '--no-build', '--disable-openapi')).rejects.toThrow();
488
+
489
+ expect(error).toHaveBeenCalledWith(expect.stringContaining('Unknown argument'));
490
+ error.mockRestore();
491
+ });
492
+
493
+ it('logs diagnostics by file and a verdict in text mode', async () => {
494
+ writeSite({ 'index.mdx': '---\ntitle: Home\n---\n\nline<br>\n' });
495
+
496
+ await runCommand('validate', '--no-build');
497
+
498
+ const text = logged();
499
+ expect(text).toContain('index.mdx');
500
+ expect(text).toContain('must be self-closed');
501
+ expect(text).toContain('1 error');
138
502
  expect(processExitMock).toHaveBeenCalledWith(1);
139
- expect(validateBuild).not.toHaveBeenCalled();
140
503
  });
141
504
  });
@@ -13,7 +13,7 @@ describe('selectRules', () => {
13
13
  it('turns on the rules of an enabled group', () => {
14
14
  const content = ids(selectRules({ disable: ['all'], enable: ['content'] }));
15
15
 
16
- expect(content).toEqual(['void-tags']);
16
+ expect(content).toEqual(['void-tags', 'missing-file', 'import-error']);
17
17
  });
18
18
 
19
19
  it('applies --enable after --disable', () => {
package/bin/cli.js CHANGED
@@ -8,11 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
- import { addLog, dev, exportSite, validateBuild, ErrorLog, SuccessLog, Logs, WarningLog, } from '@mintlify/previewing';
11
+ import { addLog, dev, exportSite, ErrorLog, SuccessLog, Logs, WarningLog, } from '@mintlify/previewing';
12
12
  import { thumbnailOverrideSchema } from '@mintlify/validation';
13
13
  import { render, Text } from 'ink';
14
- import fs from 'node:fs/promises';
15
- import path from 'path';
16
14
  import yargs from 'yargs';
17
15
  import { hideBin } from 'yargs/helpers';
18
16
  import { accessibilityCheck } from './accessibilityCheck.js';
@@ -29,7 +27,7 @@ import { formatGithubSetup, setupGithubDeployment } from './deploy-github-setup.
29
27
  import { DEPLOY_HELP, deploymentInstructions } from './deploy-instructions.js';
30
28
  import { formatDeployment, prepareAgentDeployment } from './deploy.js';
31
29
  import { formatHandler } from './format.js';
32
- import { CMD_EXEC_PATH, checkPort, checkNodeVersion, autoUpgradeIfNeeded, getVersions, isAI, suppressConsoleWarnings, terminate, } from './helpers.js';
30
+ import { checkPort, checkNodeVersion, autoUpgradeIfNeeded, getVersions, isAI, suppressConsoleWarnings, terminate, } from './helpers.js';
33
31
  import { init } from './init.js';
34
32
  import { getAccessToken } from './keyring.js';
35
33
  import { login } from './login.js';
@@ -37,13 +35,16 @@ import { logout } from './logout.js';
37
35
  import { mdxLinter } from './mdxLinter.js';
38
36
  import { createTelemetryMiddleware } from './middlewares/telemetryMiddleware.js';
39
37
  import { ogCommand } from './og.js';
40
- import { buildOverlayRegistryForCheck, checkOpenApiFile, getOpenApiFilenamesFromDocsConfig, } from './openApiCheck.js';
38
+ import { buildOverlayRegistryForCheck, checkOpenApiFile } from './openApiCheck.js';
41
39
  import { scoreHandler } from './score/index.js';
42
- import { sendPublishPrompt, signup } from './signup.js';
40
+ import { signup } from './signup.js';
43
41
  import { status, getCliSubdomains } from './status.js';
44
42
  import { trackTelemetryPreferenceChange } from './telemetry/track.js';
45
43
  import { update } from './update.js';
46
- import { runLintStep, splitList } from './validate/command.js';
44
+ import { splitList, validateHandler } from './validate/command.js';
45
+ import { RULES } from './validate/rules/index.js';
46
+ import { PARSE_ERROR } from './validate/rules/parseError.js';
47
+ import { GROUPS } from './validate/types.js';
47
48
  import { renderWelcome } from './welcome.js';
48
49
  import { workflowsBuilder } from './workflows/index.js';
49
50
  // The branded welcome screen replaces yargs' default help, but only for an
@@ -290,7 +291,7 @@ export const cli = ({ packageName = 'mint' }) => {
290
291
  yield terminate(1);
291
292
  }
292
293
  }))
293
- .command('validate', 'Validate the documentation build (strict mode, exits on warnings or errors)', (yargs) => yargs
294
+ .command('validate', 'Check the docs: content, OpenAPI specs, then a strict build. Exits 0 with no errors, 1 with errors, 2 when validate itself could not run', (yargs) => yargs
294
295
  .option('local-schema', {
295
296
  type: 'boolean',
296
297
  default: false,
@@ -305,16 +306,16 @@ export const cli = ({ packageName = 'mint' }) => {
305
306
  .option('groups', {
306
307
  type: 'array',
307
308
  description: 'Mock user groups for validation',
308
- })
309
- .option('disable-openapi', {
310
- type: 'boolean',
311
- default: false,
312
- description: 'Disable OpenAPI file generation',
313
309
  })
314
310
  .option('files', {
315
311
  type: 'string',
316
312
  array: true,
317
313
  description: 'Limit page checks to these files or globs; site-wide checks and the build still cover the whole site',
314
+ })
315
+ .option('build', {
316
+ type: 'boolean',
317
+ default: true,
318
+ description: 'Run the strict build after the other checks pass; --no-build skips it, so no client download is needed. Remote OpenAPI specs are still fetched unless openapi rules are disabled',
318
319
  })
319
320
  .option('enable', {
320
321
  type: 'string',
@@ -328,37 +329,16 @@ export const cli = ({ packageName = 'mint' }) => {
328
329
  coerce: splitList,
329
330
  description: 'Turn off rules or groups (comma-separated), or all; parse errors are still reported',
330
331
  })
331
- .usage('usage: mintlify validate [options]')
332
- .example('mintlify validate', 'validate the build'), (argv) => __awaiter(void 0, void 0, void 0, function* () {
333
- const lintPassed = yield runLintStep(argv);
334
- if (!lintPassed)
335
- return;
336
- if (!argv['disable-openapi']) {
337
- let openApiFilenames = [];
338
- try {
339
- const docsJson = yield fs.readFile(path.join(CMD_EXEC_PATH, 'docs.json'), 'utf-8');
340
- openApiFilenames = getOpenApiFilenamesFromDocsConfig(JSON.parse(docsJson));
341
- }
342
- catch (_a) { }
343
- let overlayRegistry;
344
- try {
345
- overlayRegistry = yield buildOverlayRegistryForCheck(argv['local-schema']);
346
- }
347
- catch (error) {
348
- addLog(_jsx(ErrorLog, { message: error instanceof Error ? error.message : String(error) }));
349
- yield terminate(1);
350
- return;
351
- }
352
- const results = yield Promise.all(openApiFilenames.map((file) => checkOpenApiFile(file, argv['local-schema'], overlayRegistry)));
353
- if (results.some((valid) => !valid)) {
354
- yield terminate(1);
355
- return;
356
- }
357
- }
358
- const { cli: cliVersion } = getVersions(packageName);
359
- yield validateBuild(Object.assign(Object.assign({}, argv), { packageName,
360
- cliVersion }), sendPublishPrompt);
361
- }))
332
+ .usage('usage: mint validate [options]')
333
+ .epilogue([
334
+ `Groups: ${GROUPS.join(', ')}. Rules:`,
335
+ ...RULES.map(({ id, description }) => ` ${id} — ${description}`),
336
+ ` parse-error — ${PARSE_ERROR.description} (always runs)`,
337
+ ].join('\n'))
338
+ .example('mint validate', 'run every check and the build')
339
+ .example('mint validate --files "guides/**/*.mdx"', 'check some pages')
340
+ .example('mint validate --disable all --enable content', 'run the content rules only; missing-file and import-error still run the build')
341
+ .strict(), (argv) => validateHandler(argv, packageName))
362
342
  .command('export', 'Export a static site for air-gapped deployment', (yargs) => yargs
363
343
  .option('output', {
364
344
  type: 'string',
package/bin/helpers.js CHANGED
@@ -210,6 +210,7 @@ export const readLocalOpenApiFile = (filename) => __awaiter(void 0, void 0, void
210
210
  const document = yaml.load(file);
211
211
  return document;
212
212
  });
213
+ export const errorMessage = (error) => error instanceof Error ? error.message : String(error);
213
214
  export const terminate = (code) => __awaiter(void 0, void 0, void 0, function* () {
214
215
  // Wait for the logs to be fully rendered before exiting
215
216
  yield new Promise((resolve) => setTimeout(resolve, 50));