@mintlify/cli 4.0.1076 → 4.0.1078
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/__test__/openApiCheck.test.ts +48 -8
- package/bin/cli.js +21 -31
- package/bin/login.js +21 -6
- package/bin/openApiCheck.js +54 -0
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/cli.tsx +27 -39
- package/src/login.tsx +40 -5
- package/src/openApiCheck.tsx +51 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1078",
|
|
4
4
|
"description": "The Mintlify CLI",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"inquirer": "12.3.0",
|
|
63
63
|
"js-yaml": "4.1.0",
|
|
64
64
|
"mdast-util-mdx-jsx": "3.2.0",
|
|
65
|
+
"open": "^8.4.2",
|
|
65
66
|
"openid-client": "^6.8.2",
|
|
66
67
|
"posthog-node": "5.17.2",
|
|
67
68
|
"react": "19.2.3",
|
|
@@ -94,5 +95,5 @@
|
|
|
94
95
|
"vitest": "2.1.9",
|
|
95
96
|
"vitest-mock-process": "1.0.4"
|
|
96
97
|
},
|
|
97
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "9649cbed95403dc2d61e4f4a3b02a307ad7528ea"
|
|
98
99
|
}
|
package/src/cli.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { validate, getOpenApiDocumentFromUrl, isAllowedLocalSchemaUrl } from '@mintlify/common';
|
|
2
1
|
import {
|
|
3
2
|
buildGraph,
|
|
4
3
|
getBrokenExternalLinks,
|
|
@@ -19,12 +18,14 @@ import {
|
|
|
19
18
|
} from '@mintlify/previewing';
|
|
20
19
|
import { checkUrl } from '@mintlify/scraping';
|
|
21
20
|
import { render, Text } from 'ink';
|
|
21
|
+
import fs from 'node:fs/promises';
|
|
22
22
|
import path from 'path';
|
|
23
23
|
import yargs from 'yargs';
|
|
24
24
|
import { hideBin } from 'yargs/helpers';
|
|
25
25
|
|
|
26
26
|
import { accessibilityCheck } from './accessibilityCheck.js';
|
|
27
27
|
import { setTelemetryEnabled } from './config.js';
|
|
28
|
+
import { CMD_EXEC_PATH } from './constants.js';
|
|
28
29
|
import {
|
|
29
30
|
checkPort,
|
|
30
31
|
checkNodeVersion,
|
|
@@ -32,13 +33,13 @@ import {
|
|
|
32
33
|
getVersions,
|
|
33
34
|
suppressConsoleWarnings,
|
|
34
35
|
terminate,
|
|
35
|
-
readLocalOpenApiFile,
|
|
36
36
|
} from './helpers.js';
|
|
37
37
|
import { init } from './init.js';
|
|
38
38
|
import { login } from './login.js';
|
|
39
39
|
import { logout } from './logout.js';
|
|
40
40
|
import { mdxLinter } from './mdxLinter.js';
|
|
41
41
|
import { migrateMdx } from './migrateMdx.js';
|
|
42
|
+
import { checkOpenApiFile, getOpenApiFilenamesFromDocsConfig } from './openApiCheck.js';
|
|
42
43
|
import { scrapeSite, scrapePage, scrapeOpenApi } from './scrape.js';
|
|
43
44
|
import { status } from './status.js';
|
|
44
45
|
import { createTelemetryMiddleware } from './telemetry/middleware.js';
|
|
@@ -154,6 +155,24 @@ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
|
|
|
154
155
|
.usage('usage: mintlify validate [options]')
|
|
155
156
|
.example('mintlify validate', 'validate the build'),
|
|
156
157
|
async (argv) => {
|
|
158
|
+
if (!argv['disable-openapi']) {
|
|
159
|
+
let openApiFilenames: string[] = [];
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
const docsJson = await fs.readFile(path.join(CMD_EXEC_PATH, 'docs.json'), 'utf-8');
|
|
163
|
+
openApiFilenames = getOpenApiFilenamesFromDocsConfig(JSON.parse(docsJson));
|
|
164
|
+
} catch {}
|
|
165
|
+
|
|
166
|
+
const results = await Promise.all(
|
|
167
|
+
openApiFilenames.map((file) => checkOpenApiFile(file, argv['local-schema']))
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
if (results.some((valid) => !valid)) {
|
|
171
|
+
await terminate(1);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
157
176
|
const { cli: cliVersion } = getVersions();
|
|
158
177
|
await validateBuild({
|
|
159
178
|
...argv,
|
|
@@ -200,7 +219,7 @@ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
|
|
|
200
219
|
)
|
|
201
220
|
.command(
|
|
202
221
|
'openapi-check <filename>',
|
|
203
|
-
|
|
222
|
+
false,
|
|
204
223
|
(yargs) =>
|
|
205
224
|
yargs
|
|
206
225
|
.positional('filename', {
|
|
@@ -216,42 +235,11 @@ export const cli = ({ packageName = 'mint' }: { packageName?: string }) => {
|
|
|
216
235
|
'use a locally hosted schema file (note: only https protocol is supported in production)',
|
|
217
236
|
}),
|
|
218
237
|
async ({ filename, 'local-schema': localSchema }) => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (filename.startsWith('http://') && !localSchema) {
|
|
227
|
-
addLog(
|
|
228
|
-
<WarningLog message="include the --local-schema flag to check locally hosted OpenAPI files" />
|
|
229
|
-
);
|
|
230
|
-
addLog(<WarningLog message="only https protocol is supported in production" />);
|
|
231
|
-
await terminate(0);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const document = await readLocalOpenApiFile(filename);
|
|
235
|
-
|
|
236
|
-
if (!document) {
|
|
237
|
-
throw new Error(
|
|
238
|
-
'failed to parse OpenAPI spec: could not parse file correctly, please check for any syntax errors.'
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
await validate(document);
|
|
242
|
-
addLog(<SuccessLog message="OpenAPI definition is valid." />);
|
|
243
|
-
} catch (err) {
|
|
244
|
-
if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
|
|
245
|
-
addLog(
|
|
246
|
-
<ErrorLog message={`file not found, please check the path provided: ${filename}`} />
|
|
247
|
-
);
|
|
248
|
-
} else {
|
|
249
|
-
addLog(<ErrorLog message={err instanceof Error ? err.message : 'unknown error'} />);
|
|
250
|
-
}
|
|
251
|
-
await terminate(1);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
await terminate(0);
|
|
238
|
+
addLog(
|
|
239
|
+
<WarningLog message="openapi-check is deprecated, use `mintlify validate` instead" />
|
|
240
|
+
);
|
|
241
|
+
const valid = await checkOpenApiFile(filename, localSchema);
|
|
242
|
+
await terminate(valid ? 0 : 1);
|
|
255
243
|
}
|
|
256
244
|
)
|
|
257
245
|
.command(
|
package/src/login.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { input } from '@inquirer/prompts';
|
|
2
2
|
import { addLog } from '@mintlify/previewing';
|
|
3
|
-
import
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { Box, Text } from 'ink';
|
|
5
|
+
import open from 'open';
|
|
4
6
|
import {
|
|
5
7
|
calculatePKCECodeChallenge,
|
|
6
8
|
randomNonce,
|
|
@@ -32,10 +34,41 @@ export async function login(): Promise<void> {
|
|
|
32
34
|
const authorizeUrl = new URL('/api/cli/oauth/authorize', DASHBOARD_URL);
|
|
33
35
|
authorizeUrl.searchParams.set('state', state);
|
|
34
36
|
authorizeUrl.searchParams.set('code_challenge', codeChallenge);
|
|
37
|
+
const url = authorizeUrl.toString();
|
|
35
38
|
|
|
36
|
-
addLog(
|
|
39
|
+
addLog(
|
|
40
|
+
<Box flexDirection="column" gap={1} paddingY={1}>
|
|
41
|
+
<Text bold>
|
|
42
|
+
<Text color="green">◆ </Text>A browser window will open for Mintlify authentication
|
|
43
|
+
</Text>
|
|
44
|
+
<Box flexDirection="column" paddingLeft={3} gap={1}>
|
|
45
|
+
<Text dimColor>If your browser doesn't open automatically, copy this URL:</Text>
|
|
46
|
+
<Text color="cyan">{url}</Text>
|
|
47
|
+
</Box>
|
|
48
|
+
</Box>
|
|
49
|
+
);
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
open(url).catch(() => {});
|
|
52
|
+
|
|
53
|
+
addLog(
|
|
54
|
+
<Box flexDirection="column" paddingLeft={1} marginTop={1}>
|
|
55
|
+
<Text dimColor>╭─ Paste the authorization code from your browser</Text>
|
|
56
|
+
<Text dimColor>│</Text>
|
|
57
|
+
</Box>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// Let ink finish rendering before inquirer takes over stdout
|
|
61
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
62
|
+
|
|
63
|
+
const code = await input({
|
|
64
|
+
message: '█',
|
|
65
|
+
theme: {
|
|
66
|
+
prefix: chalk.dim(' │'),
|
|
67
|
+
style: {
|
|
68
|
+
answer: (text: string) => chalk.cyan(text),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
39
72
|
|
|
40
73
|
const res = await fetch(TOKEN_ENDPOINT, {
|
|
41
74
|
method: 'POST',
|
|
@@ -53,7 +86,9 @@ export async function login(): Promise<void> {
|
|
|
53
86
|
|
|
54
87
|
if (!res.ok) {
|
|
55
88
|
addLog(
|
|
56
|
-
<Text color="red">
|
|
89
|
+
<Text color="red">
|
|
90
|
+
✖ Login failed: {body.error_message ?? body.error ?? 'unknown error'}
|
|
91
|
+
</Text>
|
|
57
92
|
);
|
|
58
93
|
return;
|
|
59
94
|
}
|
|
@@ -61,5 +96,5 @@ export async function login(): Promise<void> {
|
|
|
61
96
|
const token = body as TokenResponse;
|
|
62
97
|
await storeCredentials(token.access_token, token.refresh_token);
|
|
63
98
|
|
|
64
|
-
addLog(<Text color="green"
|
|
99
|
+
addLog(<Text color="green">✔ Logged in successfully.</Text>);
|
|
65
100
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { validate, getOpenApiDocumentFromUrl, isAllowedLocalSchemaUrl } from '@mintlify/common';
|
|
2
|
+
import { addLog, ErrorLog, SuccessLog, WarningLog } from '@mintlify/previewing';
|
|
3
|
+
import type { DocsConfig } from '@mintlify/validation';
|
|
4
|
+
|
|
5
|
+
import { readLocalOpenApiFile } from './helpers.js';
|
|
6
|
+
|
|
7
|
+
export const getOpenApiFilenamesFromDocsConfig = (config: Pick<DocsConfig, 'api'>): string[] => {
|
|
8
|
+
const openapi = config.api?.openapi;
|
|
9
|
+
if (openapi === undefined) return [];
|
|
10
|
+
if (typeof openapi === 'string') return [openapi];
|
|
11
|
+
if (Array.isArray(openapi)) return openapi;
|
|
12
|
+
return [openapi.source];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const checkOpenApiFile = async (
|
|
16
|
+
filename: string,
|
|
17
|
+
localSchema: boolean
|
|
18
|
+
): Promise<boolean> => {
|
|
19
|
+
try {
|
|
20
|
+
if (isAllowedLocalSchemaUrl(filename, localSchema)) {
|
|
21
|
+
await getOpenApiDocumentFromUrl(filename);
|
|
22
|
+
addLog(<SuccessLog message="OpenAPI definition is valid." />);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (filename.startsWith('http://') && !localSchema) {
|
|
27
|
+
addLog(
|
|
28
|
+
<WarningLog message="include the --local-schema flag to check locally hosted OpenAPI files" />
|
|
29
|
+
);
|
|
30
|
+
addLog(<WarningLog message="only https protocol is supported in production" />);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const document = await readLocalOpenApiFile(filename);
|
|
35
|
+
if (!document) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
'failed to parse OpenAPI spec: could not parse file correctly, please check for any syntax errors.'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
await validate(document);
|
|
41
|
+
addLog(<SuccessLog message="OpenAPI definition is valid." />);
|
|
42
|
+
return true;
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
|
|
45
|
+
addLog(<ErrorLog message={`file not found, please check the path provided: ${filename}`} />);
|
|
46
|
+
} else {
|
|
47
|
+
addLog(<ErrorLog message={err instanceof Error ? err.message : 'unknown error'} />);
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
};
|