@mintlify/cli 4.0.1068 → 4.0.1070
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/bin/cli.js +9 -16
- package/bin/constants.js +4 -0
- package/bin/helpers.js +13 -1
- package/bin/login.js +48 -0
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/cli.tsx +12 -22
- package/src/constants.ts +5 -0
- package/src/helpers.tsx +14 -0
- package/src/login.tsx +62 -0
package/bin/cli.js
CHANGED
|
@@ -18,8 +18,9 @@ import yargs from 'yargs';
|
|
|
18
18
|
import { hideBin } from 'yargs/helpers';
|
|
19
19
|
import { accessibilityCheck } from './accessibilityCheck.js';
|
|
20
20
|
import { setTelemetryEnabled } from './config.js';
|
|
21
|
-
import { checkPort,
|
|
21
|
+
import { checkPort, checkNodeVersion, autoUpgradeIfNeeded, getVersions, suppressConsoleWarnings, terminate, readLocalOpenApiFile, } from './helpers.js';
|
|
22
22
|
import { init } from './init.js';
|
|
23
|
+
import { login } from './login.js';
|
|
23
24
|
import { mdxLinter } from './mdxLinter.js';
|
|
24
25
|
import { migrateMdx } from './migrateMdx.js';
|
|
25
26
|
import { scrapeSite, scrapePage, scrapeOpenApi } from './scrape.js';
|
|
@@ -83,6 +84,7 @@ export const cli = ({ packageName = 'mint' }) => {
|
|
|
83
84
|
.usage('usage: mintlify dev [options]')
|
|
84
85
|
.example('mintlify dev', 'run with default settings (opens in browser)')
|
|
85
86
|
.example('mintlify dev --no-open', 'run without opening in browser'), (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
yield autoUpgradeIfNeeded();
|
|
86
88
|
const port = yield checkPort(argv);
|
|
87
89
|
const { cli: cliVersion } = getVersions();
|
|
88
90
|
if (port != undefined) {
|
|
@@ -205,10 +207,7 @@ export const cli = ({ packageName = 'mint' }) => {
|
|
|
205
207
|
default: false,
|
|
206
208
|
description: 'also check links inside <Snippet> components',
|
|
207
209
|
}), (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
208
|
-
|
|
209
|
-
if (!hasMintJson) {
|
|
210
|
-
yield checkForDocsJson();
|
|
211
|
-
}
|
|
210
|
+
yield autoUpgradeIfNeeded();
|
|
212
211
|
addLog(_jsx(SpinnerLog, { message: "checking for broken links..." }));
|
|
213
212
|
try {
|
|
214
213
|
const graph = yield buildGraph(undefined, {
|
|
@@ -276,23 +275,17 @@ export const cli = ({ packageName = 'mint' }) => {
|
|
|
276
275
|
description: 'rename files and skip errors',
|
|
277
276
|
})
|
|
278
277
|
.epilog('example: `mintlify rename introduction.mdx overview.mdx`'), (_a) => __awaiter(void 0, [_a], void 0, function* ({ from, to, force }) {
|
|
279
|
-
|
|
280
|
-
if (!hasMintJson) {
|
|
281
|
-
yield checkForDocsJson();
|
|
282
|
-
}
|
|
278
|
+
yield autoUpgradeIfNeeded();
|
|
283
279
|
yield renameFilesAndUpdateLinksInContent(from, to, force);
|
|
284
280
|
yield terminate(0);
|
|
281
|
+
}))
|
|
282
|
+
.command('login', false, () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
283
|
+
yield login();
|
|
284
|
+
yield terminate(0);
|
|
285
285
|
}))
|
|
286
286
|
.command('update', 'update the CLI to the latest version', () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
287
287
|
yield update({ packageName });
|
|
288
288
|
yield terminate(0);
|
|
289
|
-
}))
|
|
290
|
-
.command('upgrade', 'upgrade mint.json file to docs.json (current format)', () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
291
|
-
const hasMintJson = yield checkForMintJson();
|
|
292
|
-
if (!hasMintJson) {
|
|
293
|
-
yield checkForDocsJson();
|
|
294
|
-
}
|
|
295
|
-
yield upgradeConfig();
|
|
296
289
|
}))
|
|
297
290
|
.command('migrate-mdx', 'migrate mdx openapi endpoint pages to x-mint extensions and docs.json', () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
298
291
|
yield migrateMdx();
|
package/bin/constants.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _a;
|
|
1
2
|
import os from 'os';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
export const HOME_DIR = os.homedir();
|
|
@@ -5,3 +6,6 @@ export const CMD_EXEC_PATH = process.cwd();
|
|
|
5
6
|
export const CONFIG_DIR = path.join(HOME_DIR, '.config', 'mintlify');
|
|
6
7
|
export const CLI_CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
7
8
|
export const TELEMETRY_ASYNC_TIMEOUT_MS = 10000;
|
|
9
|
+
export const DASHBOARD_URL = (_a = process.env.MINTLIFY_DASHBOARD_URL) !== null && _a !== void 0 ? _a : 'http://localhost:3000';
|
|
10
|
+
export const TOKEN_ENDPOINT = 'https://test.stytch.com/v1/public/project-test-2d86347b-dfdb-4609-be69-12d8146220bd/oauth2/token';
|
|
11
|
+
export const STYTCH_CLIENT_ID = 'connected-app-test-b597afb3-304a-420f-bc13-dacca566c59f';
|
package/bin/helpers.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { getConfigPath } from '@mintlify/prebuild';
|
|
12
12
|
import { MintConfigUpdater } from '@mintlify/prebuild';
|
|
13
|
-
import { addLog, ErrorLog, getClientVersion, SuccessLog, InfoLog, SpinnerLog, removeLastLog, LOCAL_LINKED_CLI_VERSION, } from '@mintlify/previewing';
|
|
13
|
+
import { addLog, ErrorLog, getClientVersion, SuccessLog, InfoLog, SpinnerLog, removeLastLog, LOCAL_LINKED_CLI_VERSION, WarningLog, } from '@mintlify/previewing';
|
|
14
14
|
import { upgradeToDocsConfig, validatePathWithinCwd } from '@mintlify/validation';
|
|
15
15
|
import detect from 'detect-port';
|
|
16
16
|
import fse from 'fs-extra';
|
|
@@ -78,6 +78,18 @@ export const checkForDocsJson = () => __awaiter(void 0, void 0, void 0, function
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
|
+
export const autoUpgradeIfNeeded = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
+
const hasMintJson = yield checkForMintJson();
|
|
83
|
+
if (!hasMintJson)
|
|
84
|
+
return;
|
|
85
|
+
const docsJsonPath = path.join(CMD_EXEC_PATH, 'docs.json');
|
|
86
|
+
const hasDocsJson = yield fse.pathExists(docsJsonPath);
|
|
87
|
+
if (!hasDocsJson) {
|
|
88
|
+
addLog(_jsx(WarningLog, { message: "Legacy mint.json detected, auto-upgrading to docs.json" }));
|
|
89
|
+
addLog(_jsx(SpinnerLog, { message: "upgrading mint.json to docs.json..." }));
|
|
90
|
+
yield upgradeConfig();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
81
93
|
export const upgradeConfig = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
94
|
try {
|
|
83
95
|
const mintJsonPath = path.join(CMD_EXEC_PATH, 'mint.json');
|
package/bin/login.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { input } from '@inquirer/prompts';
|
|
12
|
+
import { addLog } from '@mintlify/previewing';
|
|
13
|
+
import { Text } from 'ink';
|
|
14
|
+
import { calculatePKCECodeChallenge, randomNonce, randomPKCECodeVerifier, randomState, } from 'openid-client';
|
|
15
|
+
import { DASHBOARD_URL, STYTCH_CLIENT_ID, TOKEN_ENDPOINT } from './constants.js';
|
|
16
|
+
export function login() {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const codeVerifier = randomPKCECodeVerifier();
|
|
20
|
+
const codeChallenge = yield calculatePKCECodeChallenge(codeVerifier);
|
|
21
|
+
const nonce = randomNonce();
|
|
22
|
+
const clientState = randomState();
|
|
23
|
+
const state = Buffer.from(JSON.stringify({ nonce, clientState })).toString('base64url');
|
|
24
|
+
const authorizeUrl = new URL('/api/cli/oauth/authorize', DASHBOARD_URL);
|
|
25
|
+
authorizeUrl.searchParams.set('state', state);
|
|
26
|
+
authorizeUrl.searchParams.set('code_challenge', codeChallenge);
|
|
27
|
+
addLog(_jsxs(Text, { children: ["Opening browser to log in to Mintlify... ", authorizeUrl.toString()] }));
|
|
28
|
+
const code = yield input({ message: 'Paste the code from your browser:' });
|
|
29
|
+
const res = yield fetch(TOKEN_ENDPOINT, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: { 'Content-Type': 'application/json' },
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
client_id: STYTCH_CLIENT_ID,
|
|
34
|
+
grant_type: 'authorization_code',
|
|
35
|
+
code,
|
|
36
|
+
code_verifier: codeVerifier,
|
|
37
|
+
redirect_uri: `${DASHBOARD_URL}/api/cli/oauth/callback`,
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
const body = yield res.json().catch(() => ({}));
|
|
41
|
+
if (!res.ok) {
|
|
42
|
+
addLog(_jsxs(Text, { color: "red", children: ["Login failed: ", (_b = (_a = body.error_message) !== null && _a !== void 0 ? _a : body.error) !== null && _b !== void 0 ? _b : 'unknown error'] }));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const token = body;
|
|
46
|
+
addLog(_jsx(Text, { color: "green", children: "Logged in successfully." }));
|
|
47
|
+
});
|
|
48
|
+
}
|