@mintlify/cli 4.0.590 → 4.0.592
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__/cli.test.ts +1 -11
- package/__test__/minVersion.test.ts +59 -0
- package/__test__/update.test.ts +4 -1
- package/__test__/utils.ts +11 -0
- package/bin/cli.js +19 -2
- package/bin/constants.js +2 -0
- package/bin/helpers.js +8 -6
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/bin/update.js +23 -8
- package/package.json +4 -3
- package/src/cli.ts +21 -0
- package/src/constants.ts +2 -0
- package/src/helpers.ts +8 -6
- package/src/update.ts +30 -8
package/__test__/cli.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { dev } from '@mintlify/previewing';
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { runCommand } from './utils.js';
|
|
5
5
|
|
|
6
6
|
vi.mock('@mintlify/previewing', () => ({ dev: vi.fn() }));
|
|
7
7
|
|
|
@@ -74,13 +74,3 @@ describe('cli', () => {
|
|
|
74
74
|
);
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Programmatically set arguments and execute the CLI script
|
|
80
|
-
*
|
|
81
|
-
* @param {...string} args - Additional command arguments.
|
|
82
|
-
*/
|
|
83
|
-
async function runCommand(...args: string[]) {
|
|
84
|
-
process.argv = ['node', 'cli.js', ...args];
|
|
85
|
-
return cli();
|
|
86
|
-
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { dev } from '@mintlify/previewing';
|
|
2
|
+
|
|
3
|
+
import { LOCAL_LINKED_VERSION } from '../src/constants.js';
|
|
4
|
+
import { getCliVersion } from '../src/helpers.js';
|
|
5
|
+
import * as updateModule from '../src/update.js';
|
|
6
|
+
import { runCommand } from './utils.js';
|
|
7
|
+
|
|
8
|
+
vi.mock('../src/helpers.js', async (importOriginal) => {
|
|
9
|
+
const original = await importOriginal();
|
|
10
|
+
return {
|
|
11
|
+
// @ts-expect-error - this is a mock
|
|
12
|
+
...original,
|
|
13
|
+
getCliVersion: vi.fn(),
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
vi.mock('@mintlify/previewing', () => ({ dev: vi.fn() }));
|
|
18
|
+
|
|
19
|
+
vi.mock('../src/update.js', () => ({
|
|
20
|
+
update: vi.fn().mockResolvedValue(undefined),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
describe('minimum version', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
vi.clearAllMocks();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
vi.resetAllMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should automatically update the cli if the version is below the minimum', async () => {
|
|
33
|
+
vi.mocked(getCliVersion).mockReturnValueOnce('4.1.0');
|
|
34
|
+
const updateSpy = vi.spyOn(updateModule, 'update');
|
|
35
|
+
|
|
36
|
+
await runCommand('dev');
|
|
37
|
+
|
|
38
|
+
expect(updateSpy).toHaveBeenCalled();
|
|
39
|
+
expect(dev).toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
it('should not update the cli if the version is above the minimum', async () => {
|
|
42
|
+
vi.mocked(getCliVersion).mockReturnValueOnce('4.2.1');
|
|
43
|
+
const updateSpy = vi.spyOn(updateModule, 'update');
|
|
44
|
+
|
|
45
|
+
await runCommand('dev');
|
|
46
|
+
|
|
47
|
+
expect(updateSpy).not.toHaveBeenCalled();
|
|
48
|
+
expect(dev).toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
it('should not update the cli if the version is linked to local package', async () => {
|
|
51
|
+
vi.mocked(getCliVersion).mockReturnValueOnce(LOCAL_LINKED_VERSION);
|
|
52
|
+
const updateSpy = vi.spyOn(updateModule, 'update');
|
|
53
|
+
|
|
54
|
+
await runCommand('dev');
|
|
55
|
+
|
|
56
|
+
expect(updateSpy).not.toHaveBeenCalled();
|
|
57
|
+
expect(dev).toHaveBeenCalled();
|
|
58
|
+
});
|
|
59
|
+
});
|
package/__test__/update.test.ts
CHANGED
|
@@ -21,7 +21,10 @@ vi.mock('../src/helpers.js', async (importOriginal) => {
|
|
|
21
21
|
// @ts-expect-error - this is a mock
|
|
22
22
|
...original,
|
|
23
23
|
getLatestCliVersion: vi.fn(),
|
|
24
|
-
getVersions: vi.fn()
|
|
24
|
+
getVersions: vi.fn().mockReturnValue({
|
|
25
|
+
cli: '1.0.0',
|
|
26
|
+
client: '1.0.0',
|
|
27
|
+
}),
|
|
25
28
|
};
|
|
26
29
|
});
|
|
27
30
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { cli } from '../src/cli.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Programmatically set arguments and execute the CLI script
|
|
5
|
+
*
|
|
6
|
+
* @param {...string} args - Additional command arguments.
|
|
7
|
+
*/
|
|
8
|
+
export async function runCommand(...args: string[]) {
|
|
9
|
+
process.argv = ['node', 'cli.js', ...args];
|
|
10
|
+
return cli();
|
|
11
|
+
}
|
package/bin/cli.js
CHANGED
|
@@ -14,9 +14,11 @@ import Chalk from 'chalk';
|
|
|
14
14
|
import fs from 'fs/promises';
|
|
15
15
|
import yaml from 'js-yaml';
|
|
16
16
|
import path from 'path';
|
|
17
|
+
import semver from 'semver';
|
|
17
18
|
import yargs from 'yargs';
|
|
18
19
|
import { hideBin } from 'yargs/helpers';
|
|
19
|
-
import {
|
|
20
|
+
import { LOCAL_LINKED_VERSION, MINIMUM_CLI_VERSION } from './constants.js';
|
|
21
|
+
import { checkPort, checkForMintJson, checkNodeVersion, upgradeConfig, checkForDocsJson, getCliVersion, getVersions, } from './helpers.js';
|
|
20
22
|
import { update } from './update.js';
|
|
21
23
|
export const cli = () => yargs(hideBin(process.argv))
|
|
22
24
|
.middleware(checkNodeVersion)
|
|
@@ -41,11 +43,26 @@ export const cli = () => yargs(hideBin(process.argv))
|
|
|
41
43
|
.example('mintlify dev', 'Run with default settings (opens in browser)')
|
|
42
44
|
.example('mintlify dev --no-open', 'Run without opening in browser'), (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
45
|
var _a, _b;
|
|
46
|
+
// Suppress deprecation warning for punycode
|
|
47
|
+
const originalConsoleError = console.error;
|
|
48
|
+
console.error = (...args) => {
|
|
49
|
+
const message = args.join(' ');
|
|
50
|
+
if (message.includes('DeprecationWarning')) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
originalConsoleError.apply(console, args);
|
|
54
|
+
};
|
|
44
55
|
const port = yield checkPort(argv);
|
|
45
56
|
const packageName = (_b = (_a = process.argv[1]) === null || _a === void 0 ? void 0 : _a.split('/').pop()) !== null && _b !== void 0 ? _b : 'mintlify';
|
|
57
|
+
const cliVersion = getCliVersion();
|
|
58
|
+
if (cliVersion &&
|
|
59
|
+
cliVersion !== LOCAL_LINKED_VERSION &&
|
|
60
|
+
semver.lt(cliVersion, MINIMUM_CLI_VERSION)) {
|
|
61
|
+
yield update({ packageName, silent: true });
|
|
62
|
+
}
|
|
46
63
|
if (port != undefined) {
|
|
47
64
|
yield dev(Object.assign(Object.assign({}, argv), { port,
|
|
48
|
-
packageName }));
|
|
65
|
+
packageName, cliVersion: cli }));
|
|
49
66
|
}
|
|
50
67
|
else {
|
|
51
68
|
console.error(`No available port found.`);
|
package/bin/constants.js
CHANGED
package/bin/helpers.js
CHANGED
|
@@ -20,7 +20,7 @@ import { execSync } from 'node:child_process';
|
|
|
20
20
|
import Ora from 'ora';
|
|
21
21
|
import path from 'path';
|
|
22
22
|
import yargs from 'yargs';
|
|
23
|
-
import { CMD_EXEC_PATH } from './constants.js';
|
|
23
|
+
import { CMD_EXEC_PATH, LOCAL_LINKED_VERSION } from './constants.js';
|
|
24
24
|
export const checkPort = (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
25
|
const initialPort = typeof argv.port === 'number' ? argv.port : 3000;
|
|
26
26
|
if (initialPort === (yield detect(initialPort)))
|
|
@@ -94,20 +94,22 @@ export const upgradeConfig = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
94
94
|
process.exit(1);
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
|
-
const getCliVersion = () => {
|
|
97
|
+
export const getCliVersion = () => {
|
|
98
98
|
const y = yargs();
|
|
99
99
|
let version = undefined;
|
|
100
100
|
y.showVersion((s) => {
|
|
101
101
|
version = s;
|
|
102
102
|
return false;
|
|
103
103
|
});
|
|
104
|
+
// when running `npm link` the version is 'unknown'
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
106
|
+
if (version === 'unknown') {
|
|
107
|
+
version = LOCAL_LINKED_VERSION;
|
|
108
|
+
}
|
|
104
109
|
return version;
|
|
105
110
|
};
|
|
106
111
|
export const getVersions = () => {
|
|
107
|
-
|
|
108
|
-
if (cli === 'unknown') {
|
|
109
|
-
cli = 'linked to local package';
|
|
110
|
-
}
|
|
112
|
+
const cli = getCliVersion();
|
|
111
113
|
const client = getClientVersion().trim();
|
|
112
114
|
return { cli, client };
|
|
113
115
|
};
|