@mintlify/previewing 4.0.593 → 4.0.595
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/dist/__tests__/dev.test.js +21 -29
- package/dist/__tests__/downloadTargetMint.test.js +38 -32
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/local-preview/client.d.ts +2 -4
- package/dist/local-preview/client.js +17 -24
- package/dist/local-preview/index.js +12 -15
- package/dist/local-preview/listener/index.js +9 -75
- package/dist/local-preview/network.d.ts +1 -0
- package/dist/local-preview/network.js +11 -0
- package/dist/local-preview/run.js +6 -5
- package/dist/logs.d.ts +44 -0
- package/dist/logs.js +66 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/util.d.ts +0 -2
- package/dist/util.js +0 -5
- package/package.json +7 -5
|
@@ -5,7 +5,7 @@ import { mockProcessExit } from 'vitest-mock-process';
|
|
|
5
5
|
import { dev } from '../index.js';
|
|
6
6
|
import { downloadTargetMint, getTargetMintVersion } from '../local-preview/client.js';
|
|
7
7
|
import { run } from '../local-preview/run.js';
|
|
8
|
-
import * as
|
|
8
|
+
import * as logs from '../logs.js';
|
|
9
9
|
const originalChdir = process.chdir;
|
|
10
10
|
vi.mock('fs-extra', () => {
|
|
11
11
|
const mocks = {
|
|
@@ -33,30 +33,20 @@ vi.mock('../local-preview/run.js', () => ({
|
|
|
33
33
|
run: vi.fn().mockResolvedValue(undefined),
|
|
34
34
|
}));
|
|
35
35
|
vi.mock('../util.js', () => {
|
|
36
|
-
const mockLogger = {
|
|
37
|
-
text: '',
|
|
38
|
-
succeed: vi.fn(),
|
|
39
|
-
fail: vi.fn(),
|
|
40
|
-
warn: vi.fn(),
|
|
41
|
-
start: vi.fn(),
|
|
42
|
-
stop: vi.fn(),
|
|
43
|
-
stopAndPersist: vi.fn(),
|
|
44
|
-
};
|
|
45
36
|
return {
|
|
46
|
-
buildLogger: vi.fn().mockReturnValue(mockLogger),
|
|
47
37
|
maybeFixMissingWindowsEnvVar: vi.fn(),
|
|
48
38
|
};
|
|
49
39
|
});
|
|
50
40
|
const prebuildMock = vi.mocked(prebuild);
|
|
51
41
|
const runMock = vi.mocked(run);
|
|
52
|
-
const buildLoggerMock = vi.mocked(utils.buildLogger);
|
|
53
|
-
const processExitMock = mockProcessExit();
|
|
54
42
|
const downloadTargetMintMock = vi.mocked(downloadTargetMint);
|
|
55
43
|
const defaultYargs = {
|
|
56
44
|
_: [],
|
|
57
45
|
$0: '',
|
|
58
46
|
packageName: 'mintlify',
|
|
59
47
|
};
|
|
48
|
+
const addLogSpy = vi.spyOn(logs, 'addLog');
|
|
49
|
+
const processExitMock = mockProcessExit();
|
|
60
50
|
describe('dev', () => {
|
|
61
51
|
beforeEach(() => {
|
|
62
52
|
process.chdir = vi.fn();
|
|
@@ -67,73 +57,75 @@ describe('dev', () => {
|
|
|
67
57
|
});
|
|
68
58
|
it('happy path', async () => {
|
|
69
59
|
await dev(defaultYargs);
|
|
70
|
-
expect(
|
|
60
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'preparing local preview...' } }));
|
|
71
61
|
expect(prebuildMock).toHaveBeenCalled();
|
|
72
|
-
expect(buildLoggerMock().succeed).toHaveBeenCalledWith('Local Mintlify instance is ready. Launching your site...');
|
|
73
62
|
expect(runMock).toHaveBeenCalled();
|
|
74
63
|
});
|
|
75
64
|
it('prebuild fails', async () => {
|
|
76
65
|
const errorText = 'Some OpenAPI or docs.json schema error';
|
|
77
66
|
prebuildMock.mockRejectedValueOnce(new Error(errorText));
|
|
78
67
|
await dev(defaultYargs);
|
|
79
|
-
expect(
|
|
80
|
-
expect(
|
|
68
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'preparing local preview...' } }));
|
|
69
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: errorText } }));
|
|
81
70
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
82
71
|
});
|
|
83
72
|
it('fails if no existing client version and no internet', async () => {
|
|
84
73
|
vi.mocked(isOnline).mockResolvedValueOnce(false);
|
|
85
74
|
vi.mocked(fse.pathExists).mockResolvedValueOnce();
|
|
86
75
|
await dev(defaultYargs).catch(() => { });
|
|
76
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
77
|
+
props: { message: 'running mintlify dev after updating requires an internet connection.' },
|
|
78
|
+
}));
|
|
87
79
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
88
|
-
expect(buildLoggerMock().fail).toHaveBeenCalledWith('Running mintlify dev after updating requires an internet connection.');
|
|
89
80
|
});
|
|
90
81
|
it('fails if no existing client version and no internet - mint command', async () => {
|
|
91
82
|
vi.mocked(isOnline).mockResolvedValueOnce(false);
|
|
92
83
|
vi.mocked(fse.pathExists).mockResolvedValueOnce();
|
|
93
84
|
await dev({ ...defaultYargs, packageName: 'mint' }).catch(() => { });
|
|
85
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
86
|
+
props: { message: 'running mint dev after updating requires an internet connection.' },
|
|
87
|
+
}));
|
|
94
88
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
95
|
-
expect(buildLoggerMock().fail).toHaveBeenCalledWith('Running mint dev after updating requires an internet connection.');
|
|
96
89
|
});
|
|
97
90
|
it('has existing version but fails to get targetMintVersion', async () => {
|
|
98
91
|
vi.mocked(isOnline).mockResolvedValueOnce(false);
|
|
99
92
|
vi.mocked(getTargetMintVersion).mockResolvedValueOnce(undefined);
|
|
100
93
|
await dev(defaultYargs);
|
|
101
|
-
expect(
|
|
94
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
95
|
+
props: {
|
|
96
|
+
message: 'failed to retrieve latest version. Your current version is: 1.0.0, which may not be the latest version.',
|
|
97
|
+
},
|
|
98
|
+
}));
|
|
102
99
|
expect(prebuildMock).toHaveBeenCalled();
|
|
103
|
-
expect(buildLoggerMock().succeed).toHaveBeenCalledWith('Local Mintlify instance is ready. Launching your site...');
|
|
104
100
|
expect(runMock).toHaveBeenCalled();
|
|
105
101
|
});
|
|
106
102
|
it('downloads client with --client-version arg', async () => {
|
|
107
103
|
await dev({ ...defaultYargs, 'client-version': '1.0.3' });
|
|
108
|
-
expect(
|
|
104
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'preparing local preview...' } }));
|
|
109
105
|
expect(downloadTargetMintMock).toHaveBeenCalled();
|
|
110
106
|
expect(prebuildMock).toHaveBeenCalled();
|
|
111
|
-
expect(buildLoggerMock().succeed).toHaveBeenCalledWith('Local Mintlify instance is ready. Launching your site...');
|
|
112
107
|
expect(runMock).toHaveBeenCalled();
|
|
113
108
|
});
|
|
114
109
|
it('downloads client if no existing version', async () => {
|
|
115
110
|
vi.mocked(fse.pathExists).mockResolvedValueOnce();
|
|
116
111
|
await dev(defaultYargs);
|
|
117
|
-
expect(
|
|
112
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'preparing local preview...' } }));
|
|
118
113
|
expect(downloadTargetMintMock).toHaveBeenCalled();
|
|
119
114
|
expect(prebuildMock).toHaveBeenCalled();
|
|
120
|
-
expect(buildLoggerMock().succeed).toHaveBeenCalledWith('Local Mintlify instance is ready. Launching your site...');
|
|
121
115
|
expect(runMock).toHaveBeenCalled();
|
|
122
116
|
});
|
|
123
117
|
it('warns about update if target version is different from existing version', async () => {
|
|
124
118
|
vi.mocked(getTargetMintVersion).mockResolvedValueOnce('1.0.1');
|
|
125
119
|
await dev(defaultYargs);
|
|
126
|
-
expect(
|
|
120
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { updateCommand: 'mintlify update' } }));
|
|
127
121
|
expect(prebuildMock).toHaveBeenCalled();
|
|
128
|
-
expect(buildLoggerMock().succeed).toHaveBeenCalledWith('Local Mintlify instance is ready. Launching your site...');
|
|
129
122
|
expect(runMock).toHaveBeenCalled();
|
|
130
123
|
});
|
|
131
124
|
it('warns about update if target version is different from existing version - mint command', async () => {
|
|
132
125
|
vi.mocked(getTargetMintVersion).mockResolvedValueOnce('1.0.1');
|
|
133
126
|
await dev({ ...defaultYargs, packageName: 'mint' });
|
|
134
|
-
expect(
|
|
127
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { updateCommand: 'mint update' } }));
|
|
135
128
|
expect(prebuildMock).toHaveBeenCalled();
|
|
136
|
-
expect(buildLoggerMock().succeed).toHaveBeenCalledWith('Local Mintlify instance is ready. Launching your site...');
|
|
137
129
|
expect(runMock).toHaveBeenCalled();
|
|
138
130
|
});
|
|
139
131
|
});
|
|
@@ -4,6 +4,7 @@ import tar from 'tar';
|
|
|
4
4
|
import { mockProcessExit } from 'vitest-mock-process';
|
|
5
5
|
import * as constants from '../constants.js';
|
|
6
6
|
import { downloadTargetMint } from '../local-preview/client.js';
|
|
7
|
+
import * as logs from '../logs.js';
|
|
7
8
|
import * as utils from '../util.js';
|
|
8
9
|
vi.mock('fs-extra', () => {
|
|
9
10
|
const mocks = {
|
|
@@ -20,15 +21,6 @@ vi.mock('fs-extra', () => {
|
|
|
20
21
|
};
|
|
21
22
|
});
|
|
22
23
|
vi.mock('../util.js', () => ({
|
|
23
|
-
buildLogger: vi.fn().mockReturnValue({
|
|
24
|
-
text: '',
|
|
25
|
-
succeed: vi.fn(),
|
|
26
|
-
fail: vi.fn(),
|
|
27
|
-
warn: vi.fn(),
|
|
28
|
-
start: vi.fn(),
|
|
29
|
-
stop: vi.fn(),
|
|
30
|
-
stopAndPersist: vi.fn(),
|
|
31
|
-
}),
|
|
32
24
|
restoreMintlifyLast: vi.fn().mockReturnValue(undefined),
|
|
33
25
|
getTarUrl: vi.fn().mockReturnValue('https://asdfghjkl.cloudfront.net/mint-1.0.1.tar.gz'),
|
|
34
26
|
}));
|
|
@@ -53,7 +45,6 @@ vi.mock('tar', () => {
|
|
|
53
45
|
default: mocks,
|
|
54
46
|
};
|
|
55
47
|
});
|
|
56
|
-
const buildLoggerMock = vi.mocked(utils.buildLogger);
|
|
57
48
|
const restoreMintlifyLastMock = vi.mocked(utils.restoreMintlifyLast);
|
|
58
49
|
const pipelineMock = vi.mocked(pipeline);
|
|
59
50
|
const getTarUrlMock = vi.mocked(utils.getTarUrl);
|
|
@@ -63,17 +54,16 @@ const existsSyncMock = vi.mocked(fse.existsSync);
|
|
|
63
54
|
const moveSyncMock = vi.mocked(fse.moveSync);
|
|
64
55
|
const removeSyncMock = vi.mocked(fse.removeSync);
|
|
65
56
|
const processExitMock = mockProcessExit();
|
|
57
|
+
const addLogSpy = vi.spyOn(logs, 'addLog');
|
|
66
58
|
describe('downloadTargetMint', () => {
|
|
67
59
|
beforeEach(() => {
|
|
68
60
|
vi.clearAllMocks();
|
|
69
61
|
});
|
|
70
62
|
it('downloads and extracts a new version happy path', async () => {
|
|
71
|
-
const logger = buildLoggerMock();
|
|
72
63
|
const targetMintVersion = '1.0.1';
|
|
73
64
|
const versionString = '1.0.0';
|
|
74
65
|
pipelineMock.mockResolvedValue(undefined);
|
|
75
66
|
await downloadTargetMint({
|
|
76
|
-
logger,
|
|
77
67
|
targetVersion: targetMintVersion,
|
|
78
68
|
existingVersion: versionString,
|
|
79
69
|
});
|
|
@@ -84,10 +74,11 @@ describe('downloadTargetMint', () => {
|
|
|
84
74
|
});
|
|
85
75
|
expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
|
|
86
76
|
// Verify download and extraction
|
|
77
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'installing mintlify framework...' } }));
|
|
87
78
|
expect(getTarUrlMock).toHaveBeenCalledWith(targetMintVersion);
|
|
88
79
|
expect(pipelineMock).toHaveBeenCalled();
|
|
80
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'extracting mintlify framework...' } }));
|
|
89
81
|
expect(tarMock.x).toHaveBeenCalled();
|
|
90
|
-
expect(logger.text).toBe('Extracting Mintlify framework...');
|
|
91
82
|
// Verify cleanup
|
|
92
83
|
expect(removeSyncMock).toHaveBeenCalledWith(constants.TAR_PATH);
|
|
93
84
|
expect(removeSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY_LAST);
|
|
@@ -96,12 +87,10 @@ describe('downloadTargetMint', () => {
|
|
|
96
87
|
expect(restoreMintlifyLastMock).not.toHaveBeenCalled();
|
|
97
88
|
});
|
|
98
89
|
it('downloads and extracts a specific client version happy path', async () => {
|
|
99
|
-
const logger = buildLoggerMock();
|
|
100
90
|
const versionString = '1.0.0';
|
|
101
91
|
const clientVersion = '2.0.0';
|
|
102
92
|
pipelineMock.mockResolvedValue(undefined);
|
|
103
93
|
await downloadTargetMint({
|
|
104
|
-
logger,
|
|
105
94
|
targetVersion: clientVersion,
|
|
106
95
|
existingVersion: versionString,
|
|
107
96
|
});
|
|
@@ -112,10 +101,11 @@ describe('downloadTargetMint', () => {
|
|
|
112
101
|
});
|
|
113
102
|
expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
|
|
114
103
|
// Verify download and extraction
|
|
104
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'installing mintlify framework...' } }));
|
|
115
105
|
expect(getTarUrlMock).toHaveBeenCalledWith(clientVersion);
|
|
116
106
|
expect(pipelineMock).toHaveBeenCalled();
|
|
107
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'extracting mintlify framework...' } }));
|
|
117
108
|
expect(tarMock.x).toHaveBeenCalled();
|
|
118
|
-
expect(logger.text).toBe('Extracting Mintlify framework...');
|
|
119
109
|
// Verify cleanup
|
|
120
110
|
expect(removeSyncMock).toHaveBeenCalledWith(constants.TAR_PATH);
|
|
121
111
|
expect(removeSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY_LAST);
|
|
@@ -128,12 +118,11 @@ describe('downloadTargetMint', () => {
|
|
|
128
118
|
vi.clearAllMocks();
|
|
129
119
|
});
|
|
130
120
|
it('fails to download new version', async () => {
|
|
131
|
-
const logger = buildLoggerMock();
|
|
132
121
|
const targetMintVersion = '1.0.1';
|
|
133
122
|
const versionString = '1.0.0';
|
|
134
|
-
|
|
123
|
+
const errorMessage = 'connection timed out';
|
|
124
|
+
pipelineMock.mockRejectedValue(new Error(errorMessage));
|
|
135
125
|
await downloadTargetMint({
|
|
136
|
-
logger,
|
|
137
126
|
targetVersion: targetMintVersion,
|
|
138
127
|
existingVersion: versionString,
|
|
139
128
|
});
|
|
@@ -144,7 +133,12 @@ describe('downloadTargetMint', () => {
|
|
|
144
133
|
});
|
|
145
134
|
expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
|
|
146
135
|
// Verify download fail
|
|
147
|
-
expect(
|
|
136
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'installing mintlify framework...' } }));
|
|
137
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
138
|
+
props: {
|
|
139
|
+
message: `failed to install mintlify framework version ${targetMintVersion}, Error: ${errorMessage}, falling back to existing version: ${versionString}`,
|
|
140
|
+
},
|
|
141
|
+
}));
|
|
148
142
|
// Verify use backup version
|
|
149
143
|
expect(restoreMintlifyLastMock).toHaveBeenCalled();
|
|
150
144
|
// Verify no extraction
|
|
@@ -154,15 +148,14 @@ describe('downloadTargetMint', () => {
|
|
|
154
148
|
expect(writeFileSyncMock).not.toHaveBeenCalled();
|
|
155
149
|
});
|
|
156
150
|
it('fails to extract new version', async () => {
|
|
157
|
-
const logger = buildLoggerMock();
|
|
158
151
|
const targetMintVersion = '1.0.1';
|
|
159
152
|
const versionString = '1.0.0';
|
|
153
|
+
const errorMessage = 'zlib error';
|
|
160
154
|
pipelineMock.mockResolvedValue(undefined);
|
|
161
155
|
tarMock.x.mockImplementation(() => {
|
|
162
|
-
throw new Error(
|
|
156
|
+
throw new Error(errorMessage);
|
|
163
157
|
});
|
|
164
158
|
await downloadTargetMint({
|
|
165
|
-
logger,
|
|
166
159
|
targetVersion: targetMintVersion,
|
|
167
160
|
existingVersion: versionString,
|
|
168
161
|
});
|
|
@@ -173,9 +166,15 @@ describe('downloadTargetMint', () => {
|
|
|
173
166
|
});
|
|
174
167
|
expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
|
|
175
168
|
// Verify download success
|
|
169
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'installing mintlify framework...' } }));
|
|
176
170
|
expect(pipelineMock).toHaveBeenCalled();
|
|
177
171
|
// Verify extraction fail
|
|
178
|
-
expect(
|
|
172
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'extracting mintlify framework...' } }));
|
|
173
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
174
|
+
props: {
|
|
175
|
+
message: `failed to extract mintlify framework version ${targetMintVersion}, Error: ${errorMessage}, using existing version: ${versionString}`,
|
|
176
|
+
},
|
|
177
|
+
}));
|
|
179
178
|
// Verify use backup version
|
|
180
179
|
expect(restoreMintlifyLastMock).toHaveBeenCalled();
|
|
181
180
|
// Verify no cleanup
|
|
@@ -188,32 +187,39 @@ describe('downloadTargetMint', () => {
|
|
|
188
187
|
vi.clearAllMocks();
|
|
189
188
|
});
|
|
190
189
|
it('fails to download new version with no fallback', async () => {
|
|
191
|
-
const logger = buildLoggerMock();
|
|
192
190
|
const targetMintVersion = '1.0.1';
|
|
193
191
|
const versionString = null;
|
|
194
|
-
|
|
192
|
+
const errorMessage = 'connection timed out';
|
|
193
|
+
pipelineMock.mockRejectedValue(new Error(errorMessage));
|
|
195
194
|
await downloadTargetMint({
|
|
196
|
-
logger,
|
|
197
195
|
targetVersion: targetMintVersion,
|
|
198
196
|
existingVersion: versionString,
|
|
199
197
|
});
|
|
200
|
-
expect(
|
|
198
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'installing mintlify framework...' } }));
|
|
199
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
200
|
+
props: {
|
|
201
|
+
message: `failed to install mintlify framework version ${targetMintVersion}, Error: ${errorMessage}`,
|
|
202
|
+
},
|
|
203
|
+
}));
|
|
201
204
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
202
205
|
});
|
|
203
206
|
it('fails to extract new version with no fallback', async () => {
|
|
204
|
-
const logger = buildLoggerMock();
|
|
205
207
|
const targetMintVersion = '1.0.1';
|
|
206
208
|
const versionString = null;
|
|
209
|
+
const errorMessage = 'zlib error';
|
|
207
210
|
pipelineMock.mockResolvedValue(undefined);
|
|
208
211
|
tarMock.x.mockImplementation(() => {
|
|
209
|
-
throw new Error(
|
|
212
|
+
throw new Error(errorMessage);
|
|
210
213
|
});
|
|
211
214
|
await downloadTargetMint({
|
|
212
|
-
logger,
|
|
213
215
|
targetVersion: targetMintVersion,
|
|
214
216
|
existingVersion: versionString,
|
|
215
217
|
});
|
|
216
|
-
expect(
|
|
218
|
+
expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
219
|
+
props: {
|
|
220
|
+
message: `failed to extract mintlify framework version ${targetMintVersion}, Error: ${errorMessage}`,
|
|
221
|
+
},
|
|
222
|
+
}));
|
|
217
223
|
expect(processExitMock).toHaveBeenCalledWith(1);
|
|
218
224
|
});
|
|
219
225
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getTargetMintVersion, downloadTargetMint } from './local-preview/client.js';
|
|
2
2
|
import dev from './local-preview/index.js';
|
|
3
3
|
import { getClientVersion } from './util.js';
|
|
4
|
+
export * from './logs.js';
|
|
4
5
|
export { dev, getClientVersion, getTargetMintVersion, downloadTargetMint };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getTargetMintVersion, downloadTargetMint } from './local-preview/client.js';
|
|
2
2
|
import dev from './local-preview/index.js';
|
|
3
3
|
import { getClientVersion } from './util.js';
|
|
4
|
+
export * from './logs.js';
|
|
4
5
|
export { dev, getClientVersion, getTargetMintVersion, downloadTargetMint };
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const downloadTargetMint: ({ logger, targetVersion, existingVersion, }: {
|
|
4
|
-
logger: OraType | undefined;
|
|
1
|
+
export declare const getTargetMintVersion: () => Promise<string | undefined>;
|
|
2
|
+
export declare const downloadTargetMint: ({ targetVersion, existingVersion, }: {
|
|
5
3
|
targetVersion: string;
|
|
6
4
|
existingVersion: string | null;
|
|
7
5
|
}) => Promise<void>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
import fse from 'fs-extra';
|
|
2
3
|
import got from 'got';
|
|
3
4
|
import isOnline from 'is-online';
|
|
4
5
|
import { pipeline } from 'node:stream/promises';
|
|
5
6
|
import tar from 'tar';
|
|
6
7
|
import { DOT_MINTLIFY, DOT_MINTLIFY_LAST, VERSION_PATH, TAR_PATH, TARGET_MINT_VERSION_URL, } from '../constants.js';
|
|
8
|
+
import { addLog, clearLogs, ErrorLog, SpinnerLog, WarningLog } from '../logs.js';
|
|
7
9
|
import { restoreMintlifyLast, getTarUrl } from '../util.js';
|
|
8
|
-
export const getTargetMintVersion = async (
|
|
10
|
+
export const getTargetMintVersion = async () => {
|
|
9
11
|
const hasInternet = await isOnline();
|
|
10
12
|
if (!hasInternet) {
|
|
11
13
|
return undefined;
|
|
@@ -15,20 +17,16 @@ export const getTargetMintVersion = async (logger) => {
|
|
|
15
17
|
return response.body;
|
|
16
18
|
}
|
|
17
19
|
catch (error) {
|
|
18
|
-
|
|
19
|
-
logger.text = `Failed to fetch the latest Mintlify version: ${error instanceof Error ? error.message : 'Unknown error'}`;
|
|
20
|
-
}
|
|
20
|
+
return undefined;
|
|
21
21
|
}
|
|
22
|
-
return undefined;
|
|
23
22
|
};
|
|
24
|
-
export const downloadTargetMint = async ({
|
|
23
|
+
export const downloadTargetMint = async ({ targetVersion, existingVersion, }) => {
|
|
25
24
|
if (fse.existsSync(DOT_MINTLIFY)) {
|
|
26
25
|
fse.moveSync(DOT_MINTLIFY, DOT_MINTLIFY_LAST, { overwrite: true });
|
|
27
26
|
}
|
|
28
27
|
fse.ensureDirSync(DOT_MINTLIFY);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
28
|
+
clearLogs();
|
|
29
|
+
addLog(_jsx(SpinnerLog, { message: "installing mintlify framework..." }));
|
|
32
30
|
const tarUrl = getTarUrl(targetVersion);
|
|
33
31
|
let currentVersion = targetVersion.trim();
|
|
34
32
|
try {
|
|
@@ -36,24 +34,21 @@ export const downloadTargetMint = async ({ logger, targetVersion, existingVersio
|
|
|
36
34
|
}
|
|
37
35
|
catch (error) {
|
|
38
36
|
if (existingVersion) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
37
|
+
clearLogs();
|
|
38
|
+
addLog(_jsx(WarningLog, { message: `failed to install mintlify framework version ${currentVersion}, ${error}, falling back to existing version: ${existingVersion}` }));
|
|
42
39
|
currentVersion = existingVersion;
|
|
43
40
|
restoreMintlifyLast();
|
|
44
41
|
return;
|
|
45
42
|
}
|
|
46
43
|
else {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
44
|
+
clearLogs();
|
|
45
|
+
addLog(_jsx(ErrorLog, { message: `failed to install mintlify framework version ${currentVersion}, ${error}` }));
|
|
50
46
|
process.exit(1);
|
|
51
47
|
}
|
|
52
48
|
}
|
|
53
49
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
50
|
+
clearLogs();
|
|
51
|
+
addLog(_jsx(SpinnerLog, { message: "extracting mintlify framework..." }));
|
|
57
52
|
tar.x({
|
|
58
53
|
sync: true,
|
|
59
54
|
file: TAR_PATH,
|
|
@@ -65,17 +60,15 @@ export const downloadTargetMint = async ({ logger, targetVersion, existingVersio
|
|
|
65
60
|
}
|
|
66
61
|
catch (error) {
|
|
67
62
|
if (existingVersion) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
63
|
+
clearLogs();
|
|
64
|
+
addLog(_jsx(WarningLog, { message: `failed to extract mintlify framework version ${currentVersion}, ${error}, using existing version: ${existingVersion}` }));
|
|
71
65
|
currentVersion = existingVersion;
|
|
72
66
|
restoreMintlifyLast();
|
|
73
67
|
return;
|
|
74
68
|
}
|
|
75
69
|
else {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
70
|
+
clearLogs();
|
|
71
|
+
addLog(_jsx(ErrorLog, { message: `failed to extract mintlify framework version ${currentVersion}, ${error}` }));
|
|
79
72
|
process.exit(1);
|
|
80
73
|
}
|
|
81
74
|
}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
import { prebuild } from '@mintlify/prebuild';
|
|
2
3
|
import fse, { pathExists } from 'fs-extra';
|
|
3
4
|
import isOnline from 'is-online';
|
|
4
5
|
import { CLIENT_PATH, DOT_MINTLIFY, CMD_EXEC_PATH, VERSION_PATH, NEXT_PUBLIC_PATH, NEXT_PROPS_PATH, } from '../constants.js';
|
|
5
|
-
import {
|
|
6
|
+
import { addLog, clearLogs, ErrorLog, SpinnerLog, UpdateLog, WarningLog } from '../logs.js';
|
|
6
7
|
import { getTargetMintVersion, downloadTargetMint } from './client.js';
|
|
7
8
|
import { run } from './run.js';
|
|
8
9
|
const dev = async (argv) => {
|
|
9
|
-
// Note: We wait for specific text in the logger to be sure the server is ready when we e2e test the cli.
|
|
10
|
-
// If the cli output does not exactly match:
|
|
11
|
-
// "- Preparing local Mintlify instance...\n✔ Local Mintlify instance is ready. Launching your site...\nYour local preview is available at http://localhost:3000\nPress Ctrl+C any time to stop the local preview."
|
|
12
|
-
// the test will fail/require an update.
|
|
13
|
-
const logger = buildLogger('Preparing local Mintlify instance...');
|
|
14
10
|
const hasInternet = await isOnline();
|
|
15
11
|
const localSchema = argv['local-schema'];
|
|
16
12
|
const clientVersion = argv['client-version'];
|
|
@@ -20,13 +16,14 @@ const dev = async (argv) => {
|
|
|
20
16
|
? fse.readFileSync(VERSION_PATH, 'utf8')
|
|
21
17
|
: null;
|
|
22
18
|
if (!versionString && !hasInternet) {
|
|
23
|
-
|
|
19
|
+
clearLogs();
|
|
20
|
+
addLog(_jsx(ErrorLog, { message: `running ${packageName} dev after updating requires an internet connection.` }));
|
|
21
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
24
22
|
process.exit(1);
|
|
25
23
|
}
|
|
26
|
-
const targetMintVersion = await getTargetMintVersion(
|
|
24
|
+
const targetMintVersion = await getTargetMintVersion();
|
|
27
25
|
if (!targetMintVersion) {
|
|
28
|
-
|
|
29
|
-
logger.warn(`Failed to get latest Mintlify client version. Your current version is: ${versionString?.trim()}, which may not be the latest Mintlify client version.`);
|
|
26
|
+
addLog(_jsx(WarningLog, { message: `failed to retrieve latest version. Your current version is: ${versionString?.trim()}, which may not be the latest version.` }));
|
|
30
27
|
}
|
|
31
28
|
// update the client if the user has provided a version with --client-version
|
|
32
29
|
// or if there is no version and there is internet and the target version is available
|
|
@@ -34,28 +31,28 @@ const dev = async (argv) => {
|
|
|
34
31
|
const version = clientVersion ?? targetMintVersion;
|
|
35
32
|
if (version) {
|
|
36
33
|
await downloadTargetMint({
|
|
37
|
-
logger,
|
|
38
34
|
targetVersion: version,
|
|
39
35
|
existingVersion: versionString,
|
|
40
36
|
});
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
39
|
if (versionString && targetMintVersion && versionString.trim() !== targetMintVersion.trim()) {
|
|
44
|
-
|
|
40
|
+
addLog(_jsx(UpdateLog, { updateCommand: `${packageName} update` }));
|
|
45
41
|
}
|
|
46
42
|
// clear preexisting prebuild files
|
|
47
43
|
fse.emptyDirSync(NEXT_PUBLIC_PATH);
|
|
48
44
|
fse.emptyDirSync(NEXT_PROPS_PATH);
|
|
49
45
|
process.chdir(CLIENT_PATH);
|
|
50
46
|
try {
|
|
47
|
+
addLog(_jsx(SpinnerLog, { message: "preparing local preview..." }));
|
|
51
48
|
await prebuild(CMD_EXEC_PATH, { localSchema });
|
|
52
49
|
}
|
|
53
50
|
catch (err) {
|
|
54
|
-
const errorText = err instanceof Error && err.message ? err.message : '
|
|
55
|
-
|
|
51
|
+
const errorText = err instanceof Error && err.message ? err.message : 'prebuild step failed';
|
|
52
|
+
addLog(_jsx(ErrorLog, { message: errorText }));
|
|
53
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
56
54
|
process.exit(1);
|
|
57
55
|
}
|
|
58
|
-
logger.succeed('Local Mintlify instance is ready. Launching your site...');
|
|
59
56
|
await run(argv);
|
|
60
57
|
};
|
|
61
58
|
export default dev;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
import { findAndRemoveImports, hasImports, getFileCategory, openApiCheck, stringifyTree, } from '@mintlify/common';
|
|
2
3
|
import { createPage, MintConfigUpdater, DocsConfigUpdater, preparseMdxTree, } from '@mintlify/prebuild';
|
|
3
4
|
import Chalk from 'chalk';
|
|
@@ -8,6 +9,7 @@ import fs from 'fs/promises';
|
|
|
8
9
|
import yaml from 'js-yaml';
|
|
9
10
|
import pathUtil from 'path';
|
|
10
11
|
import { CMD_EXEC_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH, CLIENT_PATH } from '../../constants.js';
|
|
12
|
+
import { AddedLog, addChangeLog, DeletedLog, EditedLog } from '../../logs.js';
|
|
11
13
|
import { generateDependentSnippets } from './generateDependentSnippets.js';
|
|
12
14
|
import { generatePagesWithImports } from './generatePagesWithImports.js';
|
|
13
15
|
import { getDocsState } from './getDocsState.js';
|
|
@@ -28,32 +30,8 @@ const listener = (callback) => {
|
|
|
28
30
|
};
|
|
29
31
|
const onAddEvent = async (filename, callback) => {
|
|
30
32
|
try {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
case 'page':
|
|
34
|
-
console.log('New page detected: ', filename);
|
|
35
|
-
break;
|
|
36
|
-
case 'snippet-v2':
|
|
37
|
-
case 'snippet':
|
|
38
|
-
console.log('New snippet detected: ', filename);
|
|
39
|
-
break;
|
|
40
|
-
case 'mintConfig':
|
|
41
|
-
case 'docsConfig':
|
|
42
|
-
console.log('Config added');
|
|
43
|
-
break;
|
|
44
|
-
case 'openApi':
|
|
45
|
-
console.log('OpenApi spec added: ', filename);
|
|
46
|
-
break;
|
|
47
|
-
case 'css':
|
|
48
|
-
console.log('CSS file added: ', filename);
|
|
49
|
-
break;
|
|
50
|
-
case 'js':
|
|
51
|
-
console.log('JS file added: ', filename);
|
|
52
|
-
break;
|
|
53
|
-
case 'staticFile':
|
|
54
|
-
console.log('Static file added: ', filename);
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
33
|
+
await onUpdateEvent(filename, callback);
|
|
34
|
+
addChangeLog(_jsx(AddedLog, { filename: filename }));
|
|
57
35
|
}
|
|
58
36
|
catch (error) {
|
|
59
37
|
console.error(error.message);
|
|
@@ -61,32 +39,8 @@ const onAddEvent = async (filename, callback) => {
|
|
|
61
39
|
};
|
|
62
40
|
const onChangeEvent = async (filename, callback) => {
|
|
63
41
|
try {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
case 'page':
|
|
67
|
-
console.log('Page edited: ', filename);
|
|
68
|
-
break;
|
|
69
|
-
case 'snippet-v2':
|
|
70
|
-
case 'snippet':
|
|
71
|
-
console.log('Snippet edited: ', filename);
|
|
72
|
-
break;
|
|
73
|
-
case 'mintConfig':
|
|
74
|
-
case 'docsConfig':
|
|
75
|
-
console.log('Config edited');
|
|
76
|
-
break;
|
|
77
|
-
case 'openApi':
|
|
78
|
-
console.log('OpenApi spec edited: ', filename);
|
|
79
|
-
break;
|
|
80
|
-
case 'css':
|
|
81
|
-
console.log('CSS file edited: ', filename);
|
|
82
|
-
break;
|
|
83
|
-
case 'js':
|
|
84
|
-
console.log('JS file edited: ', filename);
|
|
85
|
-
break;
|
|
86
|
-
case 'staticFile':
|
|
87
|
-
console.log('Static file edited: ', filename);
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
42
|
+
await onUpdateEvent(filename, callback);
|
|
43
|
+
addChangeLog(_jsx(EditedLog, { filename: filename }));
|
|
90
44
|
}
|
|
91
45
|
catch (error) {
|
|
92
46
|
console.error(error.message);
|
|
@@ -107,36 +61,16 @@ const onUnlinkEvent = async (filename) => {
|
|
|
107
61
|
await fse.remove(targetPath);
|
|
108
62
|
}
|
|
109
63
|
switch (potentialCategory) {
|
|
110
|
-
case 'page':
|
|
111
|
-
console.log(`Page deleted: ${filename}`);
|
|
112
|
-
break;
|
|
113
|
-
case 'snippet-v2':
|
|
114
|
-
case 'snippet':
|
|
115
|
-
console.log(`Snippet deleted: ${filename}`);
|
|
116
|
-
break;
|
|
117
64
|
case 'mintConfig':
|
|
118
|
-
console.error('
|
|
65
|
+
console.error('mint.json has been deleted.');
|
|
119
66
|
await validateConfigFiles();
|
|
120
67
|
break;
|
|
121
68
|
case 'docsConfig':
|
|
122
|
-
console.error('
|
|
69
|
+
console.error('docs.json has been deleted.');
|
|
123
70
|
await validateConfigFiles();
|
|
124
71
|
break;
|
|
125
|
-
case 'potentialJsonOpenApiSpec':
|
|
126
|
-
case 'potentialYamlOpenApiSpec':
|
|
127
|
-
await updateOpenApiFiles();
|
|
128
|
-
await updateGeneratedNav();
|
|
129
|
-
break;
|
|
130
|
-
case 'css':
|
|
131
|
-
console.log(`CSS file deleted: ${filename}`);
|
|
132
|
-
break;
|
|
133
|
-
case 'js':
|
|
134
|
-
console.log(`JS file deleted: ${filename}`);
|
|
135
|
-
break;
|
|
136
|
-
case 'staticFile':
|
|
137
|
-
console.log('Static file deleted: ', filename);
|
|
138
|
-
break;
|
|
139
72
|
}
|
|
73
|
+
addChangeLog(_jsx(DeletedLog, { filename: filename }));
|
|
140
74
|
}
|
|
141
75
|
catch (error) {
|
|
142
76
|
console.error(error.message);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getLocalNetworkIp: () => string | undefined;
|