@mintlify/previewing 4.0.630 → 4.0.631

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.
@@ -3,15 +3,15 @@ import fse from 'fs-extra';
3
3
  import isOnline from 'is-online';
4
4
  import { mockProcessExit } from 'vitest-mock-process';
5
5
  import { dev } from '../index.js';
6
- import { downloadTargetMint, getTargetMintVersion } from '../local-preview/client.js';
7
6
  import { run } from '../local-preview/run.js';
7
+ import { silentUpdateClient } from '../local-preview/update.js';
8
8
  import * as logs from '../logging-state.js';
9
9
  const originalChdir = process.chdir;
10
10
  vi.mock('fs-extra', () => {
11
11
  const mocks = {
12
12
  ensureDir: vi.fn().mockResolvedValue(undefined),
13
13
  pathExists: vi.fn().mockResolvedValue(true),
14
- readFileSync: vi.fn().mockReturnValue('1.0.0'),
14
+ readFileSync: vi.fn().mockReturnValue('0.0.100'),
15
15
  emptyDirSync: vi.fn().mockResolvedValue(undefined),
16
16
  };
17
17
  return {
@@ -19,9 +19,8 @@ vi.mock('fs-extra', () => {
19
19
  default: mocks,
20
20
  };
21
21
  });
22
- vi.mock('../local-preview/client.js', () => ({
23
- getTargetMintVersion: vi.fn().mockResolvedValue('1.0.0'),
24
- downloadTargetMint: vi.fn().mockResolvedValue(undefined),
22
+ vi.mock('../local-preview/update.js', () => ({
23
+ silentUpdateClient: vi.fn().mockResolvedValue({ needsUpdate: false, error: undefined }),
25
24
  }));
26
25
  vi.mock('is-online', () => ({
27
26
  default: vi.fn().mockResolvedValue(true),
@@ -39,11 +38,12 @@ vi.mock('../util.js', () => {
39
38
  });
40
39
  const prebuildMock = vi.mocked(prebuild);
41
40
  const runMock = vi.mocked(run);
42
- const downloadTargetMintMock = vi.mocked(downloadTargetMint);
41
+ const silentUpdateClientMock = vi.mocked(silentUpdateClient);
43
42
  const defaultYargs = {
44
43
  _: [],
45
44
  $0: '',
46
45
  packageName: 'mintlify',
46
+ cliVersion: '1.0.0',
47
47
  };
48
48
  const addLogSpy = vi.spyOn(logs, 'addLog');
49
49
  const processExitMock = mockProcessExit();
@@ -58,6 +58,7 @@ describe('dev', () => {
58
58
  it('happy path', async () => {
59
59
  await dev(defaultYargs);
60
60
  expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'preparing local preview...' } }));
61
+ expect(silentUpdateClientMock).toHaveBeenCalled();
61
62
  expect(prebuildMock).toHaveBeenCalled();
62
63
  expect(runMock).toHaveBeenCalled();
63
64
  });
@@ -87,45 +88,4 @@ describe('dev', () => {
87
88
  }));
88
89
  expect(processExitMock).toHaveBeenCalledWith(1);
89
90
  });
90
- it('has existing version but fails to get targetMintVersion', async () => {
91
- vi.mocked(isOnline).mockResolvedValueOnce(false);
92
- vi.mocked(getTargetMintVersion).mockResolvedValueOnce(undefined);
93
- await dev(defaultYargs);
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
- }));
99
- expect(prebuildMock).toHaveBeenCalled();
100
- expect(runMock).toHaveBeenCalled();
101
- });
102
- it('downloads client with --client-version arg', async () => {
103
- await dev({ ...defaultYargs, 'client-version': '1.0.3' });
104
- expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'preparing local preview...' } }));
105
- expect(downloadTargetMintMock).toHaveBeenCalled();
106
- expect(prebuildMock).toHaveBeenCalled();
107
- expect(runMock).toHaveBeenCalled();
108
- });
109
- it('downloads client if no existing version', async () => {
110
- vi.mocked(fse.pathExists).mockResolvedValueOnce();
111
- await dev(defaultYargs);
112
- expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'preparing local preview...' } }));
113
- expect(downloadTargetMintMock).toHaveBeenCalled();
114
- expect(prebuildMock).toHaveBeenCalled();
115
- expect(runMock).toHaveBeenCalled();
116
- });
117
- it('warns about update if target version is different from existing version', async () => {
118
- vi.mocked(getTargetMintVersion).mockResolvedValueOnce('1.0.1');
119
- await dev(defaultYargs);
120
- expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { updateCommand: 'mintlify update' } }));
121
- expect(prebuildMock).toHaveBeenCalled();
122
- expect(runMock).toHaveBeenCalled();
123
- });
124
- it('warns about update if target version is different from existing version - mint command', async () => {
125
- vi.mocked(getTargetMintVersion).mockResolvedValueOnce('1.0.1');
126
- await dev({ ...defaultYargs, packageName: 'mint' });
127
- expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { updateCommand: 'mint update' } }));
128
- expect(prebuildMock).toHaveBeenCalled();
129
- expect(runMock).toHaveBeenCalled();
130
- });
131
91
  });
@@ -1,10 +1,8 @@
1
1
  import fse from 'fs-extra';
2
2
  import { pipeline } from 'node:stream/promises';
3
3
  import tar from 'tar';
4
- import { mockProcessExit } from 'vitest-mock-process';
5
4
  import * as constants from '../constants.js';
6
5
  import { downloadTargetMint } from '../local-preview/client.js';
7
- import * as logs from '../logging-state.js';
8
6
  import * as utils from '../util.js';
9
7
  vi.mock('fs-extra', () => {
10
8
  const mocks = {
@@ -53,8 +51,6 @@ const tarMock = vi.mocked(tar);
53
51
  const existsSyncMock = vi.mocked(fse.existsSync);
54
52
  const moveSyncMock = vi.mocked(fse.moveSync);
55
53
  const removeSyncMock = vi.mocked(fse.removeSync);
56
- const processExitMock = mockProcessExit();
57
- const addLogSpy = vi.spyOn(logs, 'addLog');
58
54
  describe('downloadTargetMint', () => {
59
55
  beforeEach(() => {
60
56
  vi.clearAllMocks();
@@ -74,10 +70,8 @@ describe('downloadTargetMint', () => {
74
70
  });
75
71
  expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
76
72
  // Verify download and extraction
77
- expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'installing mintlify framework...' } }));
78
73
  expect(getTarUrlMock).toHaveBeenCalledWith(targetMintVersion);
79
74
  expect(pipelineMock).toHaveBeenCalled();
80
- expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'extracting mintlify framework...' } }));
81
75
  expect(tarMock.x).toHaveBeenCalled();
82
76
  // Verify cleanup
83
77
  expect(removeSyncMock).toHaveBeenCalledWith(constants.TAR_PATH);
@@ -101,10 +95,8 @@ describe('downloadTargetMint', () => {
101
95
  });
102
96
  expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
103
97
  // Verify download and extraction
104
- expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'installing mintlify framework...' } }));
105
98
  expect(getTarUrlMock).toHaveBeenCalledWith(clientVersion);
106
99
  expect(pipelineMock).toHaveBeenCalled();
107
- expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'extracting mintlify framework...' } }));
108
100
  expect(tarMock.x).toHaveBeenCalled();
109
101
  // Verify cleanup
110
102
  expect(removeSyncMock).toHaveBeenCalledWith(constants.TAR_PATH);
@@ -122,6 +114,7 @@ describe('downloadTargetMint', () => {
122
114
  const versionString = '1.0.0';
123
115
  const errorMessage = 'connection timed out';
124
116
  pipelineMock.mockRejectedValue(new Error(errorMessage));
117
+ // does not throw
125
118
  await downloadTargetMint({
126
119
  targetVersion: targetMintVersion,
127
120
  existingVersion: versionString,
@@ -132,13 +125,6 @@ describe('downloadTargetMint', () => {
132
125
  overwrite: true,
133
126
  });
134
127
  expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
135
- // Verify download fail
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
- }));
142
128
  // Verify use backup version
143
129
  expect(restoreMintlifyLastMock).toHaveBeenCalled();
144
130
  // Verify no extraction
@@ -155,6 +141,7 @@ describe('downloadTargetMint', () => {
155
141
  tarMock.x.mockImplementation(() => {
156
142
  throw new Error(errorMessage);
157
143
  });
144
+ // does not throw
158
145
  await downloadTargetMint({
159
146
  targetVersion: targetMintVersion,
160
147
  existingVersion: versionString,
@@ -166,15 +153,7 @@ describe('downloadTargetMint', () => {
166
153
  });
167
154
  expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
168
155
  // Verify download success
169
- expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({ props: { message: 'installing mintlify framework...' } }));
170
156
  expect(pipelineMock).toHaveBeenCalled();
171
- // Verify extraction fail
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
- }));
178
157
  // Verify use backup version
179
158
  expect(restoreMintlifyLastMock).toHaveBeenCalled();
180
159
  // Verify no cleanup
@@ -191,17 +170,10 @@ describe('downloadTargetMint', () => {
191
170
  const versionString = null;
192
171
  const errorMessage = 'connection timed out';
193
172
  pipelineMock.mockRejectedValue(new Error(errorMessage));
194
- await downloadTargetMint({
173
+ await expect(downloadTargetMint({
195
174
  targetVersion: targetMintVersion,
196
175
  existingVersion: versionString,
197
- });
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
- }));
204
- expect(processExitMock).toHaveBeenCalledWith(1);
176
+ })).rejects.toThrow(`failed to install mintlify framework version ${targetMintVersion}, Error: ${errorMessage}`);
205
177
  });
206
178
  it('fails to extract new version with no fallback', async () => {
207
179
  const targetMintVersion = '1.0.1';
@@ -211,16 +183,10 @@ describe('downloadTargetMint', () => {
211
183
  tarMock.x.mockImplementation(() => {
212
184
  throw new Error(errorMessage);
213
185
  });
214
- await downloadTargetMint({
186
+ await expect(downloadTargetMint({
215
187
  targetVersion: targetMintVersion,
216
188
  existingVersion: versionString,
217
- });
218
- expect(addLogSpy).toHaveBeenCalledWith(expect.objectContaining({
219
- props: {
220
- message: `failed to extract mintlify framework version ${targetMintVersion}, Error: ${errorMessage}`,
221
- },
222
- }));
223
- expect(processExitMock).toHaveBeenCalledWith(1);
189
+ })).rejects.toThrow(`failed to extract mintlify framework version ${targetMintVersion}, Error: ${errorMessage}`);
224
190
  });
225
191
  });
226
192
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,142 @@
1
+ import { LOCAL_LINKED_CLI_VERSION } from '../constants.js';
2
+ import * as client from '../local-preview/client.js';
3
+ import { silentUpdateClient } from '../local-preview/update.js';
4
+ vi.mock('../local-preview/client.js', () => ({
5
+ getLatestClientVersion: vi.fn().mockResolvedValue('0.0.100'),
6
+ downloadTargetMint: vi.fn().mockResolvedValue(undefined),
7
+ tryDownloadTargetMint: vi.fn().mockResolvedValue(undefined),
8
+ getCompatibleClientVersion: vi.fn().mockResolvedValue('latest'),
9
+ }));
10
+ const tryDownloadTargetMintSpy = vi.spyOn(client, 'tryDownloadTargetMint');
11
+ describe('silentUpdateClient', () => {
12
+ beforeEach(() => {
13
+ vi.clearAllMocks();
14
+ });
15
+ afterEach(() => {
16
+ vi.clearAllMocks();
17
+ });
18
+ it('has latest client version already', async () => {
19
+ const versionString = '0.0.100';
20
+ const clientVersion = undefined;
21
+ const cliVersion = undefined;
22
+ const { needsUpdate, error } = await silentUpdateClient({
23
+ versionString,
24
+ clientVersion,
25
+ cliVersion,
26
+ });
27
+ expect(tryDownloadTargetMintSpy).not.toHaveBeenCalled();
28
+ expect(needsUpdate).toBe(false);
29
+ expect(error).toBeUndefined();
30
+ });
31
+ it('has no client version and downloads latest', async () => {
32
+ const versionString = null;
33
+ const clientVersion = undefined;
34
+ const cliVersion = undefined;
35
+ const { needsUpdate, error } = await silentUpdateClient({
36
+ versionString,
37
+ clientVersion,
38
+ cliVersion,
39
+ });
40
+ expect(tryDownloadTargetMintSpy).toHaveBeenCalledWith({
41
+ targetVersion: '0.0.100',
42
+ existingVersion: null,
43
+ });
44
+ expect(needsUpdate).toBe(false);
45
+ expect(error).toBeUndefined();
46
+ });
47
+ it('always downloads latest for locally linked cli', async () => {
48
+ const versionString = null;
49
+ const clientVersion = undefined;
50
+ const cliVersion = LOCAL_LINKED_CLI_VERSION;
51
+ const { needsUpdate, error } = await silentUpdateClient({
52
+ versionString,
53
+ clientVersion,
54
+ cliVersion,
55
+ });
56
+ expect(tryDownloadTargetMintSpy).toHaveBeenCalledWith({
57
+ targetVersion: '0.0.100',
58
+ existingVersion: null,
59
+ });
60
+ expect(needsUpdate).toBe(false);
61
+ expect(error).toBeUndefined();
62
+ });
63
+ it('compatible client version is latest and downloads latest', async () => {
64
+ const versionString = null;
65
+ const clientVersion = undefined;
66
+ const cliVersion = '4.2.0';
67
+ const { needsUpdate, error } = await silentUpdateClient({
68
+ versionString,
69
+ clientVersion,
70
+ cliVersion,
71
+ });
72
+ expect(tryDownloadTargetMintSpy).toHaveBeenCalledWith({
73
+ targetVersion: '0.0.100',
74
+ existingVersion: null,
75
+ });
76
+ expect(needsUpdate).toBe(false);
77
+ expect(error).toBeUndefined();
78
+ });
79
+ it('compatible client version is max and already has max', async () => {
80
+ vi.mocked(client.getCompatibleClientVersion).mockResolvedValueOnce('0.0.99');
81
+ const versionString = '0.0.99';
82
+ const clientVersion = undefined;
83
+ const cliVersion = '4.2.0';
84
+ const { needsUpdate, error } = await silentUpdateClient({
85
+ versionString,
86
+ clientVersion,
87
+ cliVersion,
88
+ });
89
+ expect(tryDownloadTargetMintSpy).not.toHaveBeenCalled();
90
+ expect(needsUpdate).toBe(true);
91
+ expect(error).toBeUndefined();
92
+ });
93
+ it('compatible client version is max and downloads max', async () => {
94
+ vi.mocked(client.getCompatibleClientVersion).mockResolvedValueOnce('0.0.99');
95
+ const versionString = '0.0.98';
96
+ const clientVersion = undefined;
97
+ const cliVersion = '4.2.0';
98
+ const { needsUpdate, error } = await silentUpdateClient({
99
+ versionString,
100
+ clientVersion,
101
+ cliVersion,
102
+ });
103
+ expect(tryDownloadTargetMintSpy).toHaveBeenCalledWith({
104
+ targetVersion: '0.0.99',
105
+ existingVersion: '0.0.98',
106
+ });
107
+ expect(needsUpdate).toBe(true);
108
+ expect(error).toBeUndefined();
109
+ });
110
+ it('compatible client version not found', async () => {
111
+ vi.mocked(client.getCompatibleClientVersion).mockResolvedValueOnce(undefined);
112
+ const versionString = '0.0.98';
113
+ const clientVersion = undefined;
114
+ const cliVersion = '4.2.0';
115
+ const { needsUpdate, error } = await silentUpdateClient({
116
+ versionString,
117
+ clientVersion,
118
+ cliVersion,
119
+ });
120
+ expect(tryDownloadTargetMintSpy).not.toHaveBeenCalled();
121
+ expect(needsUpdate).toBe(true);
122
+ expect(error).toBeUndefined();
123
+ });
124
+ it('error with downloading target mint', async () => {
125
+ vi.mocked(client.downloadTargetMint).mockRejectedValueOnce(new Error('some error'));
126
+ vi.mocked(client.tryDownloadTargetMint).mockResolvedValueOnce('some error');
127
+ const versionString = null;
128
+ const clientVersion = undefined;
129
+ const cliVersion = '4.2.0';
130
+ const { needsUpdate, error } = await silentUpdateClient({
131
+ versionString,
132
+ clientVersion,
133
+ cliVersion,
134
+ });
135
+ expect(tryDownloadTargetMintSpy).toHaveBeenCalledWith({
136
+ targetVersion: '0.0.100',
137
+ existingVersion: null,
138
+ });
139
+ expect(needsUpdate).toBe(false);
140
+ expect(error).toBe('some error');
141
+ });
142
+ });
@@ -12,6 +12,8 @@ export declare const NEXT_PUBLIC_PATH: string;
12
12
  export declare const NEXT_PROPS_PATH: string;
13
13
  export declare const MINT_CLIENT_RELEASES_CLOUDFRONT_URL = "https://releases.mintlify.com";
14
14
  export declare const TARGET_MINT_VERSION_URL = "https://releases.mintlify.com/mint-version.txt";
15
+ export declare const MINT_VERSION_MAP_URL = "https://releases.mintlify.com/mint-version-map.json";
15
16
  export declare const TAR_PATH: string;
16
17
  export declare const CMD_EXEC_PATH: string;
17
18
  export declare const SUPPORTED_MEDIA_EXTENSIONS: string[];
19
+ export declare const LOCAL_LINKED_CLI_VERSION = "linked to local package";
package/dist/constants.js CHANGED
@@ -17,6 +17,7 @@ export const NEXT_PUBLIC_PATH = path.join(CLIENT_PATH, 'public');
17
17
  export const NEXT_PROPS_PATH = path.join(CLIENT_PATH, 'src', '_props');
18
18
  export const MINT_CLIENT_RELEASES_CLOUDFRONT_URL = 'https://releases.mintlify.com';
19
19
  export const TARGET_MINT_VERSION_URL = `${MINT_CLIENT_RELEASES_CLOUDFRONT_URL}/mint-version.txt`;
20
+ export const MINT_VERSION_MAP_URL = `${MINT_CLIENT_RELEASES_CLOUDFRONT_URL}/mint-version-map.json`;
20
21
  export const TAR_PATH = path.join(DOT_MINTLIFY, `mint.tar.gz`);
21
22
  // command execution location
22
23
  export const CMD_EXEC_PATH = process.cwd();
@@ -37,3 +38,4 @@ export const SUPPORTED_MEDIA_EXTENSIONS = [
37
38
  'bmp',
38
39
  'mp4',
39
40
  ];
41
+ export const LOCAL_LINKED_CLI_VERSION = 'linked to local package';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { getTargetMintVersion, downloadTargetMint } from './local-preview/client.js';
1
+ import { LOCAL_LINKED_CLI_VERSION } from './constants.js';
2
+ import { getLatestClientVersion, downloadTargetMint, getVersionMap } from './local-preview/client.js';
2
3
  import dev from './local-preview/index.js';
3
4
  import { getClientVersion } from './util.js';
4
5
  export * from './logs.js';
5
6
  export * from './logging-state.js';
6
- export { dev, getClientVersion, getTargetMintVersion, downloadTargetMint };
7
+ export { dev, getClientVersion, getLatestClientVersion, downloadTargetMint, getVersionMap, LOCAL_LINKED_CLI_VERSION, };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
- import { getTargetMintVersion, downloadTargetMint } from './local-preview/client.js';
1
+ import { LOCAL_LINKED_CLI_VERSION } from './constants.js';
2
+ import { getLatestClientVersion, downloadTargetMint, getVersionMap, } from './local-preview/client.js';
2
3
  import dev from './local-preview/index.js';
3
4
  import { getClientVersion } from './util.js';
4
5
  export * from './logs.js';
5
6
  export * from './logging-state.js';
6
- export { dev, getClientVersion, getTargetMintVersion, downloadTargetMint };
7
+ export { dev, getClientVersion, getLatestClientVersion, downloadTargetMint, getVersionMap, LOCAL_LINKED_CLI_VERSION, };
@@ -1,5 +1,13 @@
1
- export declare const getTargetMintVersion: () => Promise<string | undefined>;
1
+ export declare const getLatestClientVersion: () => Promise<string | undefined>;
2
2
  export declare const downloadTargetMint: ({ targetVersion, existingVersion, }: {
3
3
  targetVersion: string;
4
4
  existingVersion: string | null;
5
5
  }) => Promise<void>;
6
+ export declare const getVersionMap: () => Promise<string | undefined>;
7
+ export declare const getCompatibleClientVersion: ({ cliVersion }: {
8
+ cliVersion: string;
9
+ }) => Promise<string | undefined>;
10
+ export declare const tryDownloadTargetMint: ({ targetVersion, existingVersion }: {
11
+ targetVersion: string;
12
+ existingVersion: string | null;
13
+ }) => Promise<string | undefined>;
@@ -1,14 +1,12 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
1
  import fse from 'fs-extra';
3
2
  import got from 'got';
4
3
  import isOnline from 'is-online';
5
4
  import { pipeline } from 'node:stream/promises';
6
5
  import tar from 'tar';
7
- import { DOT_MINTLIFY, DOT_MINTLIFY_LAST, VERSION_PATH, TAR_PATH, TARGET_MINT_VERSION_URL, } from '../constants.js';
8
- import { addLog, clearLogs } from '../logging-state.js';
9
- import { ErrorLog, SpinnerLog, WarningLog } from '../logs.js';
6
+ import yaml from 'js-yaml';
7
+ import { DOT_MINTLIFY, DOT_MINTLIFY_LAST, VERSION_PATH, TAR_PATH, TARGET_MINT_VERSION_URL, MINT_VERSION_MAP_URL, } from '../constants.js';
10
8
  import { restoreMintlifyLast, getTarUrl } from '../util.js';
11
- export const getTargetMintVersion = async () => {
9
+ export const getLatestClientVersion = async () => {
12
10
  const hasInternet = await isOnline();
13
11
  if (!hasInternet) {
14
12
  return undefined;
@@ -26,8 +24,6 @@ export const downloadTargetMint = async ({ targetVersion, existingVersion, }) =>
26
24
  fse.moveSync(DOT_MINTLIFY, DOT_MINTLIFY_LAST, { overwrite: true });
27
25
  }
28
26
  fse.ensureDirSync(DOT_MINTLIFY);
29
- clearLogs();
30
- addLog(_jsx(SpinnerLog, { message: "installing mintlify framework..." }));
31
27
  const tarUrl = getTarUrl(targetVersion);
32
28
  let currentVersion = targetVersion.trim();
33
29
  try {
@@ -35,21 +31,15 @@ export const downloadTargetMint = async ({ targetVersion, existingVersion, }) =>
35
31
  }
36
32
  catch (error) {
37
33
  if (existingVersion) {
38
- clearLogs();
39
- addLog(_jsx(WarningLog, { message: `failed to install mintlify framework version ${currentVersion}, ${error}, falling back to existing version: ${existingVersion}` }));
40
34
  currentVersion = existingVersion;
41
35
  restoreMintlifyLast();
42
36
  return;
43
37
  }
44
38
  else {
45
- clearLogs();
46
- addLog(_jsx(ErrorLog, { message: `failed to install mintlify framework version ${currentVersion}, ${error}` }));
47
- process.exit(1);
39
+ throw new Error(`failed to install mintlify framework version ${currentVersion}, ${error}`);
48
40
  }
49
41
  }
50
42
  try {
51
- clearLogs();
52
- addLog(_jsx(SpinnerLog, { message: "extracting mintlify framework..." }));
53
43
  tar.x({
54
44
  sync: true,
55
45
  file: TAR_PATH,
@@ -61,22 +51,53 @@ export const downloadTargetMint = async ({ targetVersion, existingVersion, }) =>
61
51
  }
62
52
  catch (error) {
63
53
  if (existingVersion) {
64
- clearLogs();
65
- addLog(_jsx(WarningLog, { message: `failed to extract mintlify framework version ${currentVersion}, ${error}, using existing version: ${existingVersion}` }));
66
54
  currentVersion = existingVersion;
67
55
  restoreMintlifyLast();
68
56
  return;
69
57
  }
70
58
  else {
71
- clearLogs();
72
- addLog(_jsx(ErrorLog, { message: `failed to extract mintlify framework version ${currentVersion}, ${error}` }));
73
- process.exit(1);
59
+ throw new Error(`failed to extract mintlify framework version ${currentVersion}, ${error}`);
74
60
  }
75
61
  }
76
- clearLogs();
77
62
  fse.removeSync(TAR_PATH);
78
63
  if (fse.existsSync(DOT_MINTLIFY_LAST)) {
79
64
  fse.removeSync(DOT_MINTLIFY_LAST);
80
65
  }
81
66
  fse.writeFileSync(VERSION_PATH, currentVersion);
82
67
  };
68
+ export const getVersionMap = async () => {
69
+ try {
70
+ const response = await got(MINT_VERSION_MAP_URL);
71
+ return response.body;
72
+ }
73
+ catch (error) {
74
+ return undefined;
75
+ }
76
+ };
77
+ export const getCompatibleClientVersion = async ({ cliVersion }) => {
78
+ const versionMap = await getVersionMap();
79
+ if (!versionMap) {
80
+ return undefined;
81
+ }
82
+ const versionMapObj = yaml.load(versionMap);
83
+ if (cliVersion && versionMapObj[cliVersion]) {
84
+ const { max } = versionMapObj[cliVersion];
85
+ if (max !== "") {
86
+ return max;
87
+ }
88
+ else {
89
+ return "latest";
90
+ }
91
+ }
92
+ return undefined;
93
+ };
94
+ export const tryDownloadTargetMint = async ({ targetVersion, existingVersion }) => {
95
+ let error;
96
+ try {
97
+ await downloadTargetMint({ targetVersion, existingVersion });
98
+ }
99
+ catch (err) {
100
+ error = err instanceof Error ? err.message : 'unknown error';
101
+ }
102
+ return error;
103
+ };
@@ -4,8 +4,8 @@ import fse, { pathExists } from 'fs-extra';
4
4
  import isOnline from 'is-online';
5
5
  import { CLIENT_PATH, DOT_MINTLIFY, CMD_EXEC_PATH, VERSION_PATH, NEXT_PUBLIC_PATH, NEXT_PROPS_PATH, } from '../constants.js';
6
6
  import { addLog, clearLogs } from '../logging-state.js';
7
- import { ErrorLog, SpinnerLog, UpdateLog, WarningLog } from '../logs.js';
8
- import { getTargetMintVersion, downloadTargetMint } from './client.js';
7
+ import { ErrorLog, SpinnerLog } from '../logs.js';
8
+ import { silentUpdateClient } from './update.js';
9
9
  import { run } from './run.js';
10
10
  const dev = async (argv) => {
11
11
  const hasInternet = await isOnline();
@@ -13,6 +13,7 @@ const dev = async (argv) => {
13
13
  const clientVersion = argv['client-version'];
14
14
  const packageName = argv.packageName;
15
15
  const groups = argv.groups;
16
+ const cliVersion = argv.cliVersion;
16
17
  await fse.ensureDir(DOT_MINTLIFY);
17
18
  const versionString = (await pathExists(VERSION_PATH))
18
19
  ? fse.readFileSync(VERSION_PATH, 'utf8')
@@ -23,31 +24,19 @@ const dev = async (argv) => {
23
24
  await new Promise((resolve) => setTimeout(resolve, 50));
24
25
  process.exit(1);
25
26
  }
26
- const targetMintVersion = await getTargetMintVersion();
27
- if (!targetMintVersion) {
28
- addLog(_jsx(WarningLog, { message: `failed to retrieve latest version. Your current version is: ${versionString?.trim()}, which may not be the latest version.` }));
29
- }
30
- // update the client if the user has provided a version with --client-version
31
- // or if there is no version and there is internet and the target version is available
32
- if (clientVersion !== undefined || (!versionString && hasInternet && targetMintVersion)) {
33
- const version = clientVersion ?? targetMintVersion;
34
- if (version) {
35
- await downloadTargetMint({
36
- targetVersion: version,
37
- existingVersion: versionString,
38
- });
39
- }
40
- }
41
- if (versionString && targetMintVersion && versionString.trim() !== targetMintVersion.trim()) {
42
- addLog(_jsx(UpdateLog, { updateCommand: `${packageName} update` }));
27
+ addLog(_jsx(SpinnerLog, { message: "preparing local preview..." }));
28
+ const { needsUpdate, error } = await silentUpdateClient({ versionString, clientVersion, cliVersion });
29
+ if (error) {
30
+ clearLogs();
31
+ addLog(_jsx(ErrorLog, { message: error }));
32
+ await new Promise((resolve) => setTimeout(resolve, 50));
33
+ process.exit(1);
43
34
  }
44
35
  // clear preexisting prebuild files
45
36
  fse.emptyDirSync(NEXT_PUBLIC_PATH);
46
37
  fse.emptyDirSync(NEXT_PROPS_PATH);
47
38
  process.chdir(CLIENT_PATH);
48
39
  try {
49
- clearLogs();
50
- addLog(_jsx(SpinnerLog, { message: "preparing local preview..." }));
51
40
  await prebuild(CMD_EXEC_PATH, { localSchema, groups });
52
41
  }
53
42
  catch (err) {
@@ -57,6 +46,6 @@ const dev = async (argv) => {
57
46
  await new Promise((resolve) => setTimeout(resolve, 50));
58
47
  process.exit(1);
59
48
  }
60
- await run(argv);
49
+ await run({ ...argv, needsUpdate });
61
50
  };
62
51
  export default dev;
@@ -1,2 +1,4 @@
1
1
  import { ArgumentsCamelCase } from 'yargs';
2
- export declare const run: (argv: ArgumentsCamelCase) => Promise<void>;
2
+ export declare const run: (argv: ArgumentsCamelCase & {
3
+ needsUpdate: boolean;
4
+ }) => Promise<void>;
@@ -5,7 +5,7 @@ import { createServer } from 'http';
5
5
  import { Server as SocketServer } from 'socket.io';
6
6
  import { NEXT_PUBLIC_PATH } from '../constants.js';
7
7
  import { addLog, removeLastLog } from '../logging-state.js';
8
- import { LaunchLog } from '../logs.js';
8
+ import { LaunchLog, UpdateLog } from '../logs.js';
9
9
  import { maybeFixMissingWindowsEnvVar } from '../util.js';
10
10
  import listener from './listener/index.js';
11
11
  import { getLocalNetworkIp } from './network.js';
@@ -26,6 +26,9 @@ export const run = async (argv) => {
26
26
  };
27
27
  server.listen(currentPort, () => {
28
28
  removeLastLog();
29
+ if (argv.needsUpdate) {
30
+ addLog(_jsx(UpdateLog, { updateCommand: `${argv.packageName} update` }));
31
+ }
29
32
  addLog(_jsx(LaunchLog, { localUrl: `http://localhost:${port}`, networkUrl: localIp ? `http://${localIp}:${port}` : undefined }));
30
33
  /**
31
34
  * We're running into a known bug with the `open` package, where Windows machines error out because process.env.SYSTEMROOT is not set:
@@ -0,0 +1,6 @@
1
+ export type VersionMap = {
2
+ [key: string]: {
3
+ min: string;
4
+ max: string;
5
+ };
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare const silentUpdateClient: ({ versionString, clientVersion, cliVersion }: {
2
+ versionString: string | null;
3
+ clientVersion: string | undefined;
4
+ cliVersion: string | undefined;
5
+ }) => Promise<{
6
+ needsUpdate: boolean;
7
+ error: string | undefined;
8
+ }>;