@mintlify/cli 4.0.571 → 4.0.572
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__/update.test.ts +137 -0
- package/bin/cli.js +10 -1
- package/bin/helpers.js +7 -0
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/bin/update.js +53 -0
- package/package.json +5 -4
- package/src/cli.ts +12 -0
- package/src/helpers.ts +8 -0
- package/src/update.ts +49 -0
package/bin/update.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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 { getTargetMintVersion, downloadTargetMint } from '@mintlify/previewing';
|
|
11
|
+
import { execSync } from 'node:child_process';
|
|
12
|
+
import { buildLogger, getLatestCliVersion, getVersions } from './helpers.js';
|
|
13
|
+
export const update = (_a) => __awaiter(void 0, [_a], void 0, function* ({ packageName }) {
|
|
14
|
+
const logger = buildLogger(`Updating ${packageName} to the latest version...`);
|
|
15
|
+
const { cli: existingCliVersion, client: existingClientVersion } = getVersions();
|
|
16
|
+
const latestCliVersion = getLatestCliVersion(packageName);
|
|
17
|
+
const latestClientVersion = yield getTargetMintVersion(logger);
|
|
18
|
+
const isUpToDate = existingCliVersion &&
|
|
19
|
+
existingClientVersion &&
|
|
20
|
+
latestClientVersion &&
|
|
21
|
+
latestCliVersion &&
|
|
22
|
+
latestCliVersion.trim() === existingCliVersion.trim() &&
|
|
23
|
+
latestClientVersion.trim() === existingClientVersion.trim();
|
|
24
|
+
if (isUpToDate) {
|
|
25
|
+
logger.succeed('Already up to date.');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (existingCliVersion && latestCliVersion.trim() !== existingCliVersion.trim()) {
|
|
29
|
+
try {
|
|
30
|
+
logger.text = `Updating ${packageName} package...`;
|
|
31
|
+
execSync(`npm install -g ${packageName}@latest --silent`);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
logger.fail(`Failed to update ${packageName}@latest`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (latestClientVersion && latestClientVersion !== existingClientVersion) {
|
|
39
|
+
try {
|
|
40
|
+
logger.text = `Updating Mintlify client to ${latestClientVersion}...`;
|
|
41
|
+
yield downloadTargetMint({
|
|
42
|
+
logger,
|
|
43
|
+
targetVersion: latestClientVersion,
|
|
44
|
+
existingVersion: existingClientVersion !== null && existingClientVersion !== void 0 ? existingClientVersion : null,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
logger.fail(`Failed to update Mintlify client to ${latestClientVersion}`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
logger.succeed(`Updated ${packageName} to the latest version: ${latestCliVersion}`);
|
|
53
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.572",
|
|
4
4
|
"description": "The Mintlify CLI",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.0.0"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@mintlify/link-rot": "3.0.525",
|
|
44
44
|
"@mintlify/models": "0.0.195",
|
|
45
45
|
"@mintlify/prebuild": "1.0.522",
|
|
46
|
-
"@mintlify/previewing": "4.0.
|
|
46
|
+
"@mintlify/previewing": "4.0.563",
|
|
47
47
|
"@mintlify/validation": "0.1.390",
|
|
48
48
|
"chalk": "^5.2.0",
|
|
49
49
|
"detect-port": "^1.5.1",
|
|
@@ -68,7 +68,8 @@
|
|
|
68
68
|
"prettier": "^3.1.1",
|
|
69
69
|
"rimraf": "^5.0.1",
|
|
70
70
|
"typescript": "^5.5.3",
|
|
71
|
-
"vitest": "^2.0.4"
|
|
71
|
+
"vitest": "^2.0.4",
|
|
72
|
+
"vitest-mock-process": "^1.0.4"
|
|
72
73
|
},
|
|
73
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "5ca64a06ad9b1c7d52f0a98eb00cd4bdc4a48c7e"
|
|
74
75
|
}
|
package/src/cli.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
checkForDocsJson,
|
|
17
17
|
getVersions,
|
|
18
18
|
} from './helpers.js';
|
|
19
|
+
import { update } from './update.js';
|
|
19
20
|
|
|
20
21
|
export const cli = () =>
|
|
21
22
|
yargs(hideBin(process.argv))
|
|
@@ -47,10 +48,12 @@ export const cli = () =>
|
|
|
47
48
|
.example('mintlify dev --no-open', 'Run without opening in browser'),
|
|
48
49
|
async (argv) => {
|
|
49
50
|
const port = await checkPort(argv);
|
|
51
|
+
const packageName = process.argv[1]?.split('/').pop() ?? 'mintlify';
|
|
50
52
|
if (port != undefined) {
|
|
51
53
|
await dev({
|
|
52
54
|
...argv,
|
|
53
55
|
port,
|
|
56
|
+
packageName,
|
|
54
57
|
});
|
|
55
58
|
} else {
|
|
56
59
|
console.error(`No available port found.`);
|
|
@@ -163,6 +166,15 @@ export const cli = () =>
|
|
|
163
166
|
await renameFilesAndUpdateLinksInContent(from, to);
|
|
164
167
|
}
|
|
165
168
|
)
|
|
169
|
+
.command(
|
|
170
|
+
'update',
|
|
171
|
+
'Update the Mintlify client and cli to the latest version',
|
|
172
|
+
() => undefined,
|
|
173
|
+
async () => {
|
|
174
|
+
const packageName = process.argv[1]?.split('/').pop() ?? 'mintlify';
|
|
175
|
+
await update({ packageName });
|
|
176
|
+
}
|
|
177
|
+
)
|
|
166
178
|
.command(
|
|
167
179
|
'upgrade',
|
|
168
180
|
'Upgrade the mint.json file to v2 (docs.json)',
|
package/src/helpers.ts
CHANGED
|
@@ -7,6 +7,7 @@ import detect from 'detect-port';
|
|
|
7
7
|
import fse from 'fs-extra';
|
|
8
8
|
import fs from 'fs/promises';
|
|
9
9
|
import inquirer from 'inquirer';
|
|
10
|
+
import { execSync } from 'node:child_process';
|
|
10
11
|
import Ora, { Ora as OraType } from 'ora';
|
|
11
12
|
import path from 'path';
|
|
12
13
|
import type { ArgumentsCamelCase } from 'yargs';
|
|
@@ -118,3 +119,10 @@ export const getVersions = (): {
|
|
|
118
119
|
const client = getClientVersion().trim();
|
|
119
120
|
return { cli, client };
|
|
120
121
|
};
|
|
122
|
+
|
|
123
|
+
export const getLatestCliVersion = (packageName: string) => {
|
|
124
|
+
return execSync(`npm view ${packageName} version --silent`, {
|
|
125
|
+
encoding: 'utf-8',
|
|
126
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
127
|
+
}).trim();
|
|
128
|
+
};
|
package/src/update.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getTargetMintVersion, downloadTargetMint } from '@mintlify/previewing';
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
3
|
+
|
|
4
|
+
import { buildLogger, getLatestCliVersion, getVersions } from './helpers.js';
|
|
5
|
+
|
|
6
|
+
export const update = async ({ packageName }: { packageName: string }) => {
|
|
7
|
+
const logger = buildLogger(`Updating ${packageName} to the latest version...`);
|
|
8
|
+
const { cli: existingCliVersion, client: existingClientVersion } = getVersions();
|
|
9
|
+
const latestCliVersion = getLatestCliVersion(packageName);
|
|
10
|
+
const latestClientVersion = await getTargetMintVersion(logger);
|
|
11
|
+
const isUpToDate =
|
|
12
|
+
existingCliVersion &&
|
|
13
|
+
existingClientVersion &&
|
|
14
|
+
latestClientVersion &&
|
|
15
|
+
latestCliVersion &&
|
|
16
|
+
latestCliVersion.trim() === existingCliVersion.trim() &&
|
|
17
|
+
latestClientVersion.trim() === existingClientVersion.trim();
|
|
18
|
+
|
|
19
|
+
if (isUpToDate) {
|
|
20
|
+
logger.succeed('Already up to date.');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (existingCliVersion && latestCliVersion.trim() !== existingCliVersion.trim()) {
|
|
25
|
+
try {
|
|
26
|
+
logger.text = `Updating ${packageName} package...`;
|
|
27
|
+
execSync(`npm install -g ${packageName}@latest --silent`);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
logger.fail(`Failed to update ${packageName}@latest`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (latestClientVersion && latestClientVersion !== existingClientVersion) {
|
|
35
|
+
try {
|
|
36
|
+
logger.text = `Updating Mintlify client to ${latestClientVersion}...`;
|
|
37
|
+
await downloadTargetMint({
|
|
38
|
+
logger,
|
|
39
|
+
targetVersion: latestClientVersion,
|
|
40
|
+
existingVersion: existingClientVersion ?? null,
|
|
41
|
+
});
|
|
42
|
+
} catch (err) {
|
|
43
|
+
logger.fail(`Failed to update Mintlify client to ${latestClientVersion}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
logger.succeed(`Updated ${packageName} to the latest version: ${latestCliVersion}`);
|
|
49
|
+
};
|