@mintlify/cli 4.0.570 → 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 +9 -8
- package/src/cli.ts +12 -0
- package/src/helpers.ts +8 -0
- package/src/update.ts +49 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { getTargetMintVersion, downloadTargetMint } from '@mintlify/previewing';
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
3
|
+
import { mockProcessExit } from 'vitest-mock-process';
|
|
4
|
+
|
|
5
|
+
import { getLatestCliVersion, getVersions } from '../src/helpers.js';
|
|
6
|
+
import { update } from '../src/update.js';
|
|
7
|
+
|
|
8
|
+
vi.mock('node:child_process', () => ({
|
|
9
|
+
execSync: vi.fn(),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
vi.mock('@mintlify/previewing', () => ({
|
|
13
|
+
getClientVersion: vi.fn(),
|
|
14
|
+
getTargetMintVersion: vi.fn(),
|
|
15
|
+
downloadTargetMint: vi.fn(),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
vi.mock('../src/helpers.js', async (importOriginal) => {
|
|
19
|
+
const original = await importOriginal();
|
|
20
|
+
return {
|
|
21
|
+
// @ts-expect-error - this is a mock
|
|
22
|
+
...original,
|
|
23
|
+
getLatestCliVersion: vi.fn(),
|
|
24
|
+
getVersions: vi.fn(),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const processExitMock = mockProcessExit();
|
|
29
|
+
|
|
30
|
+
describe('update', () => {
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
vi.clearAllMocks();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
vi.resetAllMocks();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should update the cli and client successfully', async () => {
|
|
40
|
+
vi.mocked(getVersions).mockReturnValue({
|
|
41
|
+
cli: '1.0.0',
|
|
42
|
+
client: '1.0.0',
|
|
43
|
+
});
|
|
44
|
+
vi.mocked(getTargetMintVersion).mockResolvedValue('2.0.0');
|
|
45
|
+
vi.mocked(getLatestCliVersion).mockReturnValue('2.0.0');
|
|
46
|
+
vi.mocked(execSync).mockReturnValue(Buffer.from(''));
|
|
47
|
+
vi.mocked(downloadTargetMint).mockResolvedValue();
|
|
48
|
+
|
|
49
|
+
await update({ packageName: 'mintlify' });
|
|
50
|
+
|
|
51
|
+
expect(execSync).toHaveBeenCalledWith('npm install -g mintlify@latest --silent');
|
|
52
|
+
expect(downloadTargetMint).toHaveBeenCalledWith({
|
|
53
|
+
logger: expect.any(Object),
|
|
54
|
+
targetVersion: '2.0.0',
|
|
55
|
+
existingVersion: '1.0.0',
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should return when already up to date', async () => {
|
|
60
|
+
vi.mocked(getVersions).mockReturnValue({
|
|
61
|
+
cli: '1.0.0',
|
|
62
|
+
client: '1.0.0',
|
|
63
|
+
});
|
|
64
|
+
vi.mocked(getLatestCliVersion).mockReturnValue('1.0.0');
|
|
65
|
+
vi.mocked(getTargetMintVersion).mockResolvedValue('1.0.0');
|
|
66
|
+
vi.mocked(execSync).mockReturnValue(Buffer.from(''));
|
|
67
|
+
vi.mocked(downloadTargetMint).mockResolvedValue();
|
|
68
|
+
|
|
69
|
+
await update({ packageName: 'mintlify' });
|
|
70
|
+
|
|
71
|
+
expect(execSync).not.toHaveBeenCalled();
|
|
72
|
+
expect(downloadTargetMint).not.toHaveBeenCalled();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should only update cli if client version is up to date', async () => {
|
|
76
|
+
vi.mocked(getVersions).mockReturnValue({
|
|
77
|
+
cli: '1.0.0',
|
|
78
|
+
client: '2.0.0',
|
|
79
|
+
});
|
|
80
|
+
vi.mocked(getLatestCliVersion).mockReturnValue('2.0.0');
|
|
81
|
+
vi.mocked(getTargetMintVersion).mockResolvedValue('2.0.0');
|
|
82
|
+
vi.mocked(execSync).mockReturnValue(Buffer.from(''));
|
|
83
|
+
|
|
84
|
+
await update({ packageName: 'mintlify' });
|
|
85
|
+
|
|
86
|
+
expect(execSync).toHaveBeenCalledWith('npm install -g mintlify@latest --silent');
|
|
87
|
+
expect(downloadTargetMint).not.toHaveBeenCalled();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should only update client if cli version is up to date', async () => {
|
|
91
|
+
vi.mocked(getVersions).mockReturnValue({
|
|
92
|
+
cli: '2.0.0',
|
|
93
|
+
client: '1.0.0',
|
|
94
|
+
});
|
|
95
|
+
vi.mocked(getLatestCliVersion).mockReturnValue('2.0.0');
|
|
96
|
+
vi.mocked(getTargetMintVersion).mockResolvedValue('2.0.0');
|
|
97
|
+
vi.mocked(execSync).mockReturnValue(Buffer.from(''));
|
|
98
|
+
|
|
99
|
+
await update({ packageName: 'mintlify' });
|
|
100
|
+
|
|
101
|
+
expect(execSync).not.toHaveBeenCalled();
|
|
102
|
+
expect(downloadTargetMint).toHaveBeenCalledWith({
|
|
103
|
+
logger: expect.any(Object),
|
|
104
|
+
targetVersion: '2.0.0',
|
|
105
|
+
existingVersion: '1.0.0',
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should handle cli update failure', async () => {
|
|
110
|
+
vi.mocked(getVersions).mockReturnValue({
|
|
111
|
+
cli: '1.0.0',
|
|
112
|
+
client: '1.0.0',
|
|
113
|
+
});
|
|
114
|
+
vi.mocked(getLatestCliVersion).mockReturnValue('2.0.0');
|
|
115
|
+
vi.mocked(getTargetMintVersion).mockResolvedValue('2.0.0');
|
|
116
|
+
vi.mocked(execSync).mockImplementation(() => {
|
|
117
|
+
throw new Error('Update failed');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
await update({ packageName: 'mintlify' });
|
|
121
|
+
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should handle client update failure', async () => {
|
|
125
|
+
vi.mocked(getVersions).mockReturnValue({
|
|
126
|
+
cli: '1.0.0',
|
|
127
|
+
client: '1.0.0',
|
|
128
|
+
});
|
|
129
|
+
vi.mocked(getLatestCliVersion).mockReturnValue('2.0.0');
|
|
130
|
+
vi.mocked(getTargetMintVersion).mockResolvedValue('2.0.0');
|
|
131
|
+
vi.mocked(execSync).mockReturnValue(Buffer.from(''));
|
|
132
|
+
vi.mocked(downloadTargetMint).mockRejectedValue(new Error('Download failed'));
|
|
133
|
+
|
|
134
|
+
await update({ packageName: 'mintlify' });
|
|
135
|
+
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
136
|
+
});
|
|
137
|
+
});
|
package/bin/cli.js
CHANGED
|
@@ -17,6 +17,7 @@ import path from 'path';
|
|
|
17
17
|
import yargs from 'yargs';
|
|
18
18
|
import { hideBin } from 'yargs/helpers';
|
|
19
19
|
import { checkPort, checkForMintJson, checkNodeVersion, upgradeConfig, checkForDocsJson, getVersions, } from './helpers.js';
|
|
20
|
+
import { update } from './update.js';
|
|
20
21
|
export const cli = () => yargs(hideBin(process.argv))
|
|
21
22
|
.middleware(checkNodeVersion)
|
|
22
23
|
.command('dev', 'Runs Mintlify project locally.', (yargs) => yargs
|
|
@@ -39,9 +40,12 @@ export const cli = () => yargs(hideBin(process.argv))
|
|
|
39
40
|
.usage('Usage: mintlify dev [options]')
|
|
40
41
|
.example('mintlify dev', 'Run with default settings (opens in browser)')
|
|
41
42
|
.example('mintlify dev --no-open', 'Run without opening in browser'), (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
var _a, _b;
|
|
42
44
|
const port = yield checkPort(argv);
|
|
45
|
+
const packageName = (_b = (_a = process.argv[1]) === null || _a === void 0 ? void 0 : _a.split('/').pop()) !== null && _b !== void 0 ? _b : 'mintlify';
|
|
43
46
|
if (port != undefined) {
|
|
44
|
-
yield dev(Object.assign(Object.assign({}, argv), { port
|
|
47
|
+
yield dev(Object.assign(Object.assign({}, argv), { port,
|
|
48
|
+
packageName }));
|
|
45
49
|
}
|
|
46
50
|
else {
|
|
47
51
|
console.error(`No available port found.`);
|
|
@@ -130,6 +134,11 @@ export const cli = () => yargs(hideBin(process.argv))
|
|
|
130
134
|
yield checkForDocsJson();
|
|
131
135
|
}
|
|
132
136
|
yield renameFilesAndUpdateLinksInContent(from, to);
|
|
137
|
+
}))
|
|
138
|
+
.command('update', 'Update the Mintlify client and cli to the latest version', () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
+
var _a, _b;
|
|
140
|
+
const packageName = (_b = (_a = process.argv[1]) === null || _a === void 0 ? void 0 : _a.split('/').pop()) !== null && _b !== void 0 ? _b : 'mintlify';
|
|
141
|
+
yield update({ packageName });
|
|
133
142
|
}))
|
|
134
143
|
.command('upgrade', 'Upgrade the mint.json file to v2 (docs.json)', () => undefined, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
144
|
const hasMintJson = yield checkForMintJson();
|
package/bin/helpers.js
CHANGED
|
@@ -16,6 +16,7 @@ import detect from 'detect-port';
|
|
|
16
16
|
import fse from 'fs-extra';
|
|
17
17
|
import fs from 'fs/promises';
|
|
18
18
|
import inquirer from 'inquirer';
|
|
19
|
+
import { execSync } from 'node:child_process';
|
|
19
20
|
import Ora from 'ora';
|
|
20
21
|
import path from 'path';
|
|
21
22
|
import yargs from 'yargs';
|
|
@@ -110,3 +111,9 @@ export const getVersions = () => {
|
|
|
110
111
|
const client = getClientVersion().trim();
|
|
111
112
|
return { cli, client };
|
|
112
113
|
};
|
|
114
|
+
export const getLatestCliVersion = (packageName) => {
|
|
115
|
+
return execSync(`npm view ${packageName} version --silent`, {
|
|
116
|
+
encoding: 'utf-8',
|
|
117
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
118
|
+
}).trim();
|
|
119
|
+
};
|