@mintlify/cli 4.0.603 → 4.0.605
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/CONTRIBUTING.md +4 -0
- package/__test__/brokenLinks.test.ts +106 -0
- package/__test__/{cli.test.ts → checkPort.test.ts} +31 -15
- package/__test__/minVersion.test.ts +24 -10
- package/__test__/openApiCheck.test.ts +127 -0
- package/__test__/update.test.ts +148 -47
- package/__test__/utils.ts +9 -0
- package/bin/cli.js +154 -148
- package/bin/helpers.js +29 -21
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/bin/update.js +22 -22
- package/package.json +11 -10
- package/src/cli.tsx +255 -0
- package/src/{helpers.ts → helpers.tsx} +44 -23
- package/src/update.tsx +79 -0
- package/tsconfig.json +3 -2
- package/src/cli.ts +0 -222
- package/src/update.ts +0 -71
package/bin/update.js
CHANGED
|
@@ -7,17 +7,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { getTargetMintVersion, downloadTargetMint, SpinnerLog, SuccessLog, ErrorLog, addLog, clearLogs, } from '@mintlify/previewing';
|
|
12
|
+
import { execAsync, getLatestCliVersion, getVersions } from './helpers.js';
|
|
13
13
|
export const update = (_a) => __awaiter(void 0, [_a], void 0, function* ({ packageName, silent, }) {
|
|
14
|
-
let logger = undefined;
|
|
15
14
|
if (!silent) {
|
|
16
|
-
|
|
15
|
+
addLog(_jsx(SpinnerLog, { message: "updating..." }));
|
|
17
16
|
}
|
|
18
17
|
const { cli: existingCliVersion, client: existingClientVersion } = getVersions();
|
|
19
18
|
const latestCliVersion = getLatestCliVersion(packageName);
|
|
20
|
-
const latestClientVersion = yield getTargetMintVersion(
|
|
19
|
+
const latestClientVersion = yield getTargetMintVersion();
|
|
21
20
|
const isUpToDate = existingCliVersion &&
|
|
22
21
|
existingClientVersion &&
|
|
23
22
|
latestClientVersion &&
|
|
@@ -25,44 +24,45 @@ export const update = (_a) => __awaiter(void 0, [_a], void 0, function* ({ packa
|
|
|
25
24
|
latestCliVersion.trim() === existingCliVersion.trim() &&
|
|
26
25
|
latestClientVersion.trim() === existingClientVersion.trim();
|
|
27
26
|
if (isUpToDate) {
|
|
28
|
-
if (!silent
|
|
29
|
-
|
|
27
|
+
if (!silent) {
|
|
28
|
+
addLog(_jsx(SuccessLog, { message: "already up to date" }));
|
|
30
29
|
}
|
|
31
30
|
return;
|
|
32
31
|
}
|
|
33
32
|
if (existingCliVersion && latestCliVersion.trim() !== existingCliVersion.trim()) {
|
|
34
33
|
try {
|
|
35
|
-
if (
|
|
36
|
-
|
|
34
|
+
if (!silent) {
|
|
35
|
+
clearLogs();
|
|
36
|
+
addLog(_jsx(SpinnerLog, { message: `updating ${packageName} package...` }));
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
yield execAsync(`npm install -g ${packageName}@latest --silent`);
|
|
39
39
|
}
|
|
40
40
|
catch (err) {
|
|
41
|
-
if (
|
|
42
|
-
|
|
41
|
+
if (!silent) {
|
|
42
|
+
addLog(_jsx(ErrorLog, { message: `failed to update ${packageName}@latest` }));
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
return;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
if (latestClientVersion && latestClientVersion !== existingClientVersion) {
|
|
48
48
|
try {
|
|
49
|
-
if (
|
|
50
|
-
|
|
49
|
+
if (!silent) {
|
|
50
|
+
addLog(_jsx(SpinnerLog, { message: `updating mintlify client to ${latestClientVersion}...` }));
|
|
51
51
|
}
|
|
52
52
|
yield downloadTargetMint({
|
|
53
|
-
logger,
|
|
54
53
|
targetVersion: latestClientVersion,
|
|
55
54
|
existingVersion: existingClientVersion !== null && existingClientVersion !== void 0 ? existingClientVersion : null,
|
|
56
55
|
});
|
|
57
56
|
}
|
|
58
57
|
catch (err) {
|
|
59
|
-
if (
|
|
60
|
-
|
|
58
|
+
if (!silent) {
|
|
59
|
+
addLog(_jsx(ErrorLog, { message: `failed to update mintlify client to ${latestClientVersion}` }));
|
|
61
60
|
}
|
|
62
|
-
|
|
61
|
+
return;
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
64
|
+
if (!silent) {
|
|
65
|
+
clearLogs();
|
|
66
|
+
addLog(_jsx(SuccessLog, { message: `updated ${packageName} to the latest version: ${latestCliVersion}` }));
|
|
67
67
|
}
|
|
68
68
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.605",
|
|
4
4
|
"description": "The Mintlify CLI",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"mintlify": "bin/index.js"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"dev": "yarn build && node bin/index.js
|
|
29
|
+
"dev": "yarn build && NODE_NO_WARNINGS=1 node bin/index.js",
|
|
30
30
|
"prepare": "npm run build",
|
|
31
31
|
"build": "tsc --project tsconfig.build.json",
|
|
32
32
|
"clean:build": "rimraf bin",
|
|
@@ -39,18 +39,19 @@
|
|
|
39
39
|
"format:check": "prettier . --check"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@mintlify/common": "1.0.
|
|
43
|
-
"@mintlify/link-rot": "3.0.
|
|
44
|
-
"@mintlify/models": "0.0.
|
|
45
|
-
"@mintlify/prebuild": "1.0.
|
|
46
|
-
"@mintlify/previewing": "4.0.
|
|
47
|
-
"@mintlify/validation": "0.1.
|
|
42
|
+
"@mintlify/common": "1.0.435",
|
|
43
|
+
"@mintlify/link-rot": "3.0.555",
|
|
44
|
+
"@mintlify/models": "0.0.202",
|
|
45
|
+
"@mintlify/prebuild": "1.0.551",
|
|
46
|
+
"@mintlify/previewing": "4.0.594",
|
|
47
|
+
"@mintlify/validation": "0.1.402",
|
|
48
48
|
"chalk": "^5.2.0",
|
|
49
49
|
"detect-port": "^1.5.1",
|
|
50
50
|
"fs-extra": "^11.2.0",
|
|
51
|
+
"ink": "^6.0.1",
|
|
51
52
|
"inquirer": "^12.3.0",
|
|
52
53
|
"js-yaml": "^4.1.0",
|
|
53
|
-
"
|
|
54
|
+
"react": "^19.1.0",
|
|
54
55
|
"semver": "^7.7.2",
|
|
55
56
|
"yargs": "^17.6.0"
|
|
56
57
|
},
|
|
@@ -72,5 +73,5 @@
|
|
|
72
73
|
"vitest": "^2.0.4",
|
|
73
74
|
"vitest-mock-process": "^1.0.4"
|
|
74
75
|
},
|
|
75
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "5bd2ef4133962495f8e9c4ae006862a1ea23671c"
|
|
76
77
|
}
|
package/src/cli.tsx
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { validate, getOpenApiDocumentFromUrl, isAllowedLocalSchemaUrl } from '@mintlify/common';
|
|
2
|
+
import { getBrokenInternalLinks, renameFilesAndUpdateLinksInContent } from '@mintlify/link-rot';
|
|
3
|
+
import {
|
|
4
|
+
addLog,
|
|
5
|
+
dev,
|
|
6
|
+
ErrorLog,
|
|
7
|
+
SpinnerLog,
|
|
8
|
+
SuccessLog,
|
|
9
|
+
Logs,
|
|
10
|
+
clearLogs,
|
|
11
|
+
BrokenLinksLog,
|
|
12
|
+
} from '@mintlify/previewing';
|
|
13
|
+
import { render, Text } from 'ink';
|
|
14
|
+
import path from 'path';
|
|
15
|
+
import semver from 'semver';
|
|
16
|
+
import yargs from 'yargs';
|
|
17
|
+
import { hideBin } from 'yargs/helpers';
|
|
18
|
+
|
|
19
|
+
import { LOCAL_LINKED_VERSION, MINIMUM_CLI_VERSION } from './constants.js';
|
|
20
|
+
import {
|
|
21
|
+
checkPort,
|
|
22
|
+
checkForMintJson,
|
|
23
|
+
checkNodeVersion,
|
|
24
|
+
upgradeConfig,
|
|
25
|
+
checkForDocsJson,
|
|
26
|
+
getCliVersion,
|
|
27
|
+
getVersions,
|
|
28
|
+
suppressConsoleWarnings,
|
|
29
|
+
terminate,
|
|
30
|
+
readLocalOpenApiFile,
|
|
31
|
+
} from './helpers.js';
|
|
32
|
+
import { update } from './update.js';
|
|
33
|
+
|
|
34
|
+
export const cli = () => {
|
|
35
|
+
render(<Logs />);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
yargs(hideBin(process.argv))
|
|
39
|
+
.middleware(checkNodeVersion)
|
|
40
|
+
.middleware(suppressConsoleWarnings)
|
|
41
|
+
.command(
|
|
42
|
+
'dev',
|
|
43
|
+
'initialize a local preview environment',
|
|
44
|
+
(yargs) =>
|
|
45
|
+
yargs
|
|
46
|
+
.option('open', {
|
|
47
|
+
type: 'boolean',
|
|
48
|
+
default: true,
|
|
49
|
+
description: 'open a local preview in the browser',
|
|
50
|
+
})
|
|
51
|
+
.option('local-schema', {
|
|
52
|
+
type: 'boolean',
|
|
53
|
+
default: false,
|
|
54
|
+
hidden: true,
|
|
55
|
+
description:
|
|
56
|
+
'use a locally hosted schema file (note: only https protocol is supported in production)',
|
|
57
|
+
})
|
|
58
|
+
.option('client-version', {
|
|
59
|
+
type: 'string',
|
|
60
|
+
hidden: true,
|
|
61
|
+
description: 'the version of the client to use for cli testing',
|
|
62
|
+
})
|
|
63
|
+
.usage('usage: mintlify dev [options]')
|
|
64
|
+
.example('mintlify dev', 'run with default settings (opens in browser)')
|
|
65
|
+
.example('mintlify dev --no-open', 'run without opening in browser'),
|
|
66
|
+
async (argv) => {
|
|
67
|
+
const port = await checkPort(argv);
|
|
68
|
+
const packageName = process.argv[1]?.split('/').pop() ?? 'mintlify';
|
|
69
|
+
const cliVersion = getCliVersion();
|
|
70
|
+
if (
|
|
71
|
+
cliVersion &&
|
|
72
|
+
cliVersion !== LOCAL_LINKED_VERSION &&
|
|
73
|
+
semver.lt(cliVersion, MINIMUM_CLI_VERSION)
|
|
74
|
+
) {
|
|
75
|
+
await update({ packageName, silent: true });
|
|
76
|
+
}
|
|
77
|
+
if (port != undefined) {
|
|
78
|
+
await dev({
|
|
79
|
+
...argv,
|
|
80
|
+
port,
|
|
81
|
+
packageName,
|
|
82
|
+
cliVersion: cli,
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
addLog(<ErrorLog message="no available port found" />);
|
|
86
|
+
await terminate(1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
.command(
|
|
91
|
+
'openapi-check <filename>',
|
|
92
|
+
'check if an OpenAPI spec is valid',
|
|
93
|
+
(yargs) =>
|
|
94
|
+
yargs
|
|
95
|
+
.positional('filename', {
|
|
96
|
+
describe:
|
|
97
|
+
'the filename of the OpenAPI spec (e.g. ./openapi.yaml) or the URL to the OpenAPI spec (e.g. https://petstore3.swagger.io/api/v3/openapi.json)',
|
|
98
|
+
type: 'string',
|
|
99
|
+
demandOption: true,
|
|
100
|
+
})
|
|
101
|
+
.option('local-schema', {
|
|
102
|
+
type: 'boolean',
|
|
103
|
+
default: false,
|
|
104
|
+
description:
|
|
105
|
+
'use a locally hosted schema file (note: only https protocol is supported in production)',
|
|
106
|
+
}),
|
|
107
|
+
async ({ filename, 'local-schema': localSchema }) => {
|
|
108
|
+
try {
|
|
109
|
+
if (isAllowedLocalSchemaUrl(filename, localSchema)) {
|
|
110
|
+
await getOpenApiDocumentFromUrl(filename);
|
|
111
|
+
addLog(<SuccessLog message="OpenAPI definition is valid." />);
|
|
112
|
+
await terminate(0);
|
|
113
|
+
}
|
|
114
|
+
const document = await readLocalOpenApiFile(filename);
|
|
115
|
+
|
|
116
|
+
if (!document) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
'failed to parse OpenAPI spec: could not parse file correctly, please check for any syntax errors.'
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
await validate(document);
|
|
122
|
+
addLog(<SuccessLog message="OpenAPI definition is valid." />);
|
|
123
|
+
} catch (err) {
|
|
124
|
+
addLog(<ErrorLog message={err instanceof Error ? err.message : 'unknown error'} />);
|
|
125
|
+
await terminate(1);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
await terminate(0);
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
.command(
|
|
132
|
+
'broken-links',
|
|
133
|
+
'check for invalid internal links',
|
|
134
|
+
() => undefined,
|
|
135
|
+
async () => {
|
|
136
|
+
const hasMintJson = await checkForMintJson();
|
|
137
|
+
if (!hasMintJson) {
|
|
138
|
+
await checkForDocsJson();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
addLog(<SpinnerLog message="checking for broken links..." />);
|
|
142
|
+
try {
|
|
143
|
+
const brokenLinks = await getBrokenInternalLinks();
|
|
144
|
+
if (brokenLinks.length === 0) {
|
|
145
|
+
clearLogs();
|
|
146
|
+
addLog(<SuccessLog message="no broken links found" />);
|
|
147
|
+
await terminate(0);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const brokenLinksByFile: Record<string, string[]> = {};
|
|
151
|
+
brokenLinks.forEach((mdxPath) => {
|
|
152
|
+
const filename = path.join(mdxPath.relativeDir, mdxPath.filename);
|
|
153
|
+
const brokenLinksForFile = brokenLinksByFile[filename];
|
|
154
|
+
if (brokenLinksForFile) {
|
|
155
|
+
brokenLinksForFile.push(mdxPath.originalPath);
|
|
156
|
+
} else {
|
|
157
|
+
brokenLinksByFile[filename] = [mdxPath.originalPath];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
clearLogs();
|
|
161
|
+
addLog(<BrokenLinksLog brokenLinksByFile={brokenLinksByFile} />);
|
|
162
|
+
} catch (err) {
|
|
163
|
+
addLog(<ErrorLog message={err instanceof Error ? err.message : 'unknown error'} />);
|
|
164
|
+
await terminate(1);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
await terminate(0);
|
|
168
|
+
}
|
|
169
|
+
)
|
|
170
|
+
.command(
|
|
171
|
+
'rename <from> <to>',
|
|
172
|
+
'rename a file and update all internal link references',
|
|
173
|
+
(yargs) =>
|
|
174
|
+
yargs
|
|
175
|
+
.positional('from', {
|
|
176
|
+
describe: 'the file to rename',
|
|
177
|
+
type: 'string',
|
|
178
|
+
})
|
|
179
|
+
.positional('to', {
|
|
180
|
+
describe: 'the new name for the file',
|
|
181
|
+
type: 'string',
|
|
182
|
+
})
|
|
183
|
+
.demandOption(['from', 'to'])
|
|
184
|
+
.option('force', {
|
|
185
|
+
type: 'boolean',
|
|
186
|
+
default: false,
|
|
187
|
+
description: 'rename files and skip errors',
|
|
188
|
+
})
|
|
189
|
+
.epilog('example: `mintlify rename introduction.mdx overview.mdx`'),
|
|
190
|
+
async ({ from, to, force }) => {
|
|
191
|
+
const hasMintJson = await checkForMintJson();
|
|
192
|
+
if (!hasMintJson) {
|
|
193
|
+
await checkForDocsJson();
|
|
194
|
+
}
|
|
195
|
+
await renameFilesAndUpdateLinksInContent(from, to, force);
|
|
196
|
+
await terminate(0);
|
|
197
|
+
}
|
|
198
|
+
)
|
|
199
|
+
.command(
|
|
200
|
+
'update',
|
|
201
|
+
'update the CLI to the latest version',
|
|
202
|
+
() => undefined,
|
|
203
|
+
async () => {
|
|
204
|
+
const packageName = process.argv[1]?.split('/').pop() ?? 'mintlify';
|
|
205
|
+
await update({ packageName });
|
|
206
|
+
await terminate(0);
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
.command(
|
|
210
|
+
'upgrade',
|
|
211
|
+
'upgrade mint.json file to docs.json (current format)',
|
|
212
|
+
() => undefined,
|
|
213
|
+
async () => {
|
|
214
|
+
const hasMintJson = await checkForMintJson();
|
|
215
|
+
if (!hasMintJson) {
|
|
216
|
+
await checkForDocsJson();
|
|
217
|
+
}
|
|
218
|
+
await upgradeConfig();
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
.command(
|
|
222
|
+
['version', 'v'],
|
|
223
|
+
'display the current version of the CLI and client',
|
|
224
|
+
() => undefined,
|
|
225
|
+
async () => {
|
|
226
|
+
const { cli, client } = getVersions();
|
|
227
|
+
addLog(
|
|
228
|
+
<Text>
|
|
229
|
+
<Text bold color="green">
|
|
230
|
+
cli version
|
|
231
|
+
</Text>{' '}
|
|
232
|
+
{cli}
|
|
233
|
+
</Text>
|
|
234
|
+
);
|
|
235
|
+
addLog(
|
|
236
|
+
<Text>
|
|
237
|
+
<Text bold color="green">
|
|
238
|
+
client version
|
|
239
|
+
</Text>{' '}
|
|
240
|
+
{client}
|
|
241
|
+
</Text>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
)
|
|
245
|
+
// Print the help menu when the user enters an invalid command.
|
|
246
|
+
.strictCommands()
|
|
247
|
+
.demandCommand(1, 'unknown command. see above for the list of supported commands.')
|
|
248
|
+
|
|
249
|
+
// Alias option flags --help = -h, default --version = -v
|
|
250
|
+
.alias('h', 'help')
|
|
251
|
+
.alias('v', 'version')
|
|
252
|
+
|
|
253
|
+
.parse()
|
|
254
|
+
);
|
|
255
|
+
};
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { getConfigPath } from '@mintlify/prebuild';
|
|
2
2
|
import { MintConfigUpdater } from '@mintlify/prebuild';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
addLog,
|
|
5
|
+
ErrorLog,
|
|
6
|
+
getClientVersion,
|
|
7
|
+
SuccessLog,
|
|
8
|
+
InfoLog,
|
|
9
|
+
SpinnerLog,
|
|
10
|
+
removeLastLog,
|
|
11
|
+
} from '@mintlify/previewing';
|
|
4
12
|
import { upgradeToDocsConfig } from '@mintlify/validation';
|
|
5
|
-
import Chalk from 'chalk';
|
|
6
13
|
import detect from 'detect-port';
|
|
7
14
|
import fse from 'fs-extra';
|
|
8
15
|
import fs from 'fs/promises';
|
|
9
16
|
import inquirer from 'inquirer';
|
|
10
|
-
import
|
|
11
|
-
import
|
|
17
|
+
import yaml from 'js-yaml';
|
|
18
|
+
import { exec, execSync } from 'node:child_process';
|
|
19
|
+
import { promisify } from 'node:util';
|
|
12
20
|
import path from 'path';
|
|
13
21
|
import type { ArgumentsCamelCase } from 'yargs';
|
|
14
22
|
import yargs from 'yargs';
|
|
@@ -20,7 +28,7 @@ export const checkPort = async (argv: ArgumentsCamelCase): Promise<number | unde
|
|
|
20
28
|
if (initialPort === (await detect(initialPort))) return initialPort;
|
|
21
29
|
|
|
22
30
|
for (let port = initialPort + 1; port < initialPort + 10; port++) {
|
|
23
|
-
|
|
31
|
+
addLog(<InfoLog message={`port ${port - 1} is already in use. trying ${port} instead`} />);
|
|
24
32
|
if (port === (await detect(port))) return port;
|
|
25
33
|
}
|
|
26
34
|
};
|
|
@@ -34,19 +42,14 @@ export const checkNodeVersion = async () => {
|
|
|
34
42
|
const majorVersion = parseInt(versionArr[0]!, 10);
|
|
35
43
|
|
|
36
44
|
if (majorVersion < 18) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
addLog(
|
|
46
|
+
<ErrorLog
|
|
47
|
+
message={`mintlify requires a node version >= 18.0.0 (current version ${nodeVersionString}). try removing the mintlify package, upgrading node, reinstalling mintlify, and running again.`}
|
|
48
|
+
/>
|
|
40
49
|
);
|
|
41
|
-
process.exit(1);
|
|
42
50
|
}
|
|
43
51
|
};
|
|
44
52
|
|
|
45
|
-
export const buildLogger = (startText = ''): OraType => {
|
|
46
|
-
const logger = Ora().start(startText);
|
|
47
|
-
return logger;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
53
|
export const checkForMintJson = async () => {
|
|
51
54
|
return !!(await getConfigPath(CMD_EXEC_PATH, 'mint'));
|
|
52
55
|
};
|
|
@@ -54,15 +57,15 @@ export const checkForMintJson = async () => {
|
|
|
54
57
|
export const checkForDocsJson = async () => {
|
|
55
58
|
const docsJsonPath = path.join(CMD_EXEC_PATH, 'docs.json');
|
|
56
59
|
if (!(await fse.pathExists(docsJsonPath))) {
|
|
57
|
-
|
|
60
|
+
addLog(<InfoLog message="new docs.json file is available" />);
|
|
58
61
|
const promptResult = await inquirer.prompt([
|
|
59
62
|
{
|
|
60
63
|
type: 'list',
|
|
61
64
|
name: 'action',
|
|
62
|
-
message: '
|
|
65
|
+
message: 'would you like to upgrade your mint.json to docs.json?',
|
|
63
66
|
choices: [
|
|
64
|
-
{ name: '
|
|
65
|
-
{ name: '
|
|
67
|
+
{ name: 'upgrade (migrate from mint.json to docs.json)', value: 'upgrade' },
|
|
68
|
+
{ name: 'continue (use existing mint.json)', value: 'continue' },
|
|
66
69
|
],
|
|
67
70
|
},
|
|
68
71
|
]);
|
|
@@ -70,11 +73,11 @@ export const checkForDocsJson = async () => {
|
|
|
70
73
|
const { action } = promptResult;
|
|
71
74
|
|
|
72
75
|
if (action === 'continue') {
|
|
73
|
-
|
|
76
|
+
addLog(<InfoLog message="proceeding with the existing mint.json..." />);
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
if (action === 'upgrade') {
|
|
77
|
-
|
|
80
|
+
addLog(<SpinnerLog message="upgrading docs.json..." />);
|
|
78
81
|
await upgradeConfig();
|
|
79
82
|
}
|
|
80
83
|
}
|
|
@@ -91,10 +94,11 @@ export const upgradeConfig = async () => {
|
|
|
91
94
|
shouldUpgradeTheme: true,
|
|
92
95
|
});
|
|
93
96
|
await fs.writeFile(docsJsonPath, JSON.stringify(upgradedDocsConfig, null, 2));
|
|
94
|
-
|
|
97
|
+
removeLastLog();
|
|
98
|
+
addLog(<SuccessLog message="mint.json file has been upgraded to docs.json." />);
|
|
95
99
|
} catch (err) {
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
removeLastLog();
|
|
101
|
+
addLog(<ErrorLog message={err instanceof Error ? err.message : 'an unknown error occurred'} />);
|
|
98
102
|
}
|
|
99
103
|
};
|
|
100
104
|
|
|
@@ -153,3 +157,20 @@ export const suppressConsoleWarnings = (): void => {
|
|
|
153
157
|
originalConsoleWarn.apply(console, args);
|
|
154
158
|
};
|
|
155
159
|
};
|
|
160
|
+
|
|
161
|
+
export const readLocalOpenApiFile = async (
|
|
162
|
+
filename: string
|
|
163
|
+
): Promise<Record<string, unknown> | undefined> => {
|
|
164
|
+
const pathname = path.resolve(process.cwd(), filename);
|
|
165
|
+
const file = await fs.readFile(pathname, 'utf-8');
|
|
166
|
+
const document = yaml.load(file) as Record<string, unknown> | undefined;
|
|
167
|
+
return document;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export const terminate = async (code: number) => {
|
|
171
|
+
// Wait for the logs to be fully rendered before exiting
|
|
172
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
173
|
+
process.exit(code);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export const execAsync = promisify(exec);
|
package/src/update.tsx
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getTargetMintVersion,
|
|
3
|
+
downloadTargetMint,
|
|
4
|
+
SpinnerLog,
|
|
5
|
+
SuccessLog,
|
|
6
|
+
ErrorLog,
|
|
7
|
+
addLog,
|
|
8
|
+
clearLogs,
|
|
9
|
+
} from '@mintlify/previewing';
|
|
10
|
+
|
|
11
|
+
import { execAsync, getLatestCliVersion, getVersions } from './helpers.js';
|
|
12
|
+
|
|
13
|
+
export const update = async ({
|
|
14
|
+
packageName,
|
|
15
|
+
silent,
|
|
16
|
+
}: {
|
|
17
|
+
packageName: string;
|
|
18
|
+
silent?: boolean;
|
|
19
|
+
}) => {
|
|
20
|
+
if (!silent) {
|
|
21
|
+
addLog(<SpinnerLog message="updating..." />);
|
|
22
|
+
}
|
|
23
|
+
const { cli: existingCliVersion, client: existingClientVersion } = getVersions();
|
|
24
|
+
const latestCliVersion = getLatestCliVersion(packageName);
|
|
25
|
+
const latestClientVersion = await getTargetMintVersion();
|
|
26
|
+
const isUpToDate =
|
|
27
|
+
existingCliVersion &&
|
|
28
|
+
existingClientVersion &&
|
|
29
|
+
latestClientVersion &&
|
|
30
|
+
latestCliVersion &&
|
|
31
|
+
latestCliVersion.trim() === existingCliVersion.trim() &&
|
|
32
|
+
latestClientVersion.trim() === existingClientVersion.trim();
|
|
33
|
+
|
|
34
|
+
if (isUpToDate) {
|
|
35
|
+
if (!silent) {
|
|
36
|
+
addLog(<SuccessLog message="already up to date" />);
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (existingCliVersion && latestCliVersion.trim() !== existingCliVersion.trim()) {
|
|
42
|
+
try {
|
|
43
|
+
if (!silent) {
|
|
44
|
+
clearLogs();
|
|
45
|
+
addLog(<SpinnerLog message={`updating ${packageName} package...`} />);
|
|
46
|
+
}
|
|
47
|
+
await execAsync(`npm install -g ${packageName}@latest --silent`);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
if (!silent) {
|
|
50
|
+
addLog(<ErrorLog message={`failed to update ${packageName}@latest`} />);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (latestClientVersion && latestClientVersion !== existingClientVersion) {
|
|
57
|
+
try {
|
|
58
|
+
if (!silent) {
|
|
59
|
+
addLog(<SpinnerLog message={`updating mintlify client to ${latestClientVersion}...`} />);
|
|
60
|
+
}
|
|
61
|
+
await downloadTargetMint({
|
|
62
|
+
targetVersion: latestClientVersion,
|
|
63
|
+
existingVersion: existingClientVersion ?? null,
|
|
64
|
+
});
|
|
65
|
+
} catch (err) {
|
|
66
|
+
if (!silent) {
|
|
67
|
+
addLog(<ErrorLog message={`failed to update mintlify client to ${latestClientVersion}`} />);
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!silent) {
|
|
74
|
+
clearLogs();
|
|
75
|
+
addLog(
|
|
76
|
+
<SuccessLog message={`updated ${packageName} to the latest version: ${latestCliVersion}`} />
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
"extends": "@mintlify/ts-config",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"outDir": "bin",
|
|
5
|
-
"types": ["vitest/globals"]
|
|
5
|
+
"types": ["vitest/globals"],
|
|
6
|
+
"jsx": "react-jsx"
|
|
6
7
|
},
|
|
7
|
-
"include": ["**/*.ts"],
|
|
8
|
+
"include": ["**/*.ts", "src/**/*.tsx"],
|
|
8
9
|
"exclude": ["node_modules", "bin"]
|
|
9
10
|
}
|