@mintlify/previewing 4.0.527 → 4.0.529

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,125 @@
1
+ import { prebuild } from '@mintlify/prebuild';
2
+ import fse from 'fs-extra';
3
+ import isOnline from 'is-online';
4
+ import { mockProcessExit } from 'vitest-mock-process';
5
+ import { dev } from '../index.js';
6
+ import { downloadTargetMint, getTargetMintVersion } from '../local-preview/client.js';
7
+ import { run } from '../local-preview/run.js';
8
+ import * as utils from '../util.js';
9
+ const originalChdir = process.chdir;
10
+ vi.mock('fs-extra', () => {
11
+ const mocks = {
12
+ ensureDir: vi.fn().mockResolvedValue(undefined),
13
+ pathExists: vi.fn().mockResolvedValue(true),
14
+ readFileSync: vi.fn().mockReturnValue('1.0.0'),
15
+ emptyDirSync: vi.fn().mockResolvedValue(undefined),
16
+ };
17
+ return {
18
+ ...mocks,
19
+ default: mocks,
20
+ };
21
+ });
22
+ vi.mock('../local-preview/client.js', () => ({
23
+ getTargetMintVersion: vi.fn().mockResolvedValue('1.0.0'),
24
+ downloadTargetMint: vi.fn().mockResolvedValue(undefined),
25
+ }));
26
+ vi.mock('is-online', () => ({
27
+ default: vi.fn().mockResolvedValue(true),
28
+ }));
29
+ vi.mock('@mintlify/prebuild', () => ({
30
+ prebuild: vi.fn().mockResolvedValue(undefined),
31
+ }));
32
+ vi.mock('../local-preview/run.js', () => ({
33
+ run: vi.fn().mockResolvedValue(undefined),
34
+ }));
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
+ return {
46
+ buildLogger: vi.fn().mockReturnValue(mockLogger),
47
+ maybeFixMissingWindowsEnvVar: vi.fn(),
48
+ };
49
+ });
50
+ const prebuildMock = vi.mocked(prebuild);
51
+ const runMock = vi.mocked(run);
52
+ const buildLoggerMock = vi.mocked(utils.buildLogger);
53
+ const processExitMock = mockProcessExit();
54
+ const downloadTargetMintMock = vi.mocked(downloadTargetMint);
55
+ const emptyYargs = {
56
+ _: [],
57
+ $0: '',
58
+ };
59
+ describe('dev', () => {
60
+ beforeEach(() => {
61
+ process.chdir = vi.fn();
62
+ vi.clearAllMocks();
63
+ });
64
+ afterEach(() => {
65
+ process.chdir = originalChdir;
66
+ });
67
+ it('happy path', async () => {
68
+ await dev(emptyYargs);
69
+ expect(buildLoggerMock).toHaveBeenCalledWith('Preparing local Mintlify instance...');
70
+ expect(prebuildMock).toHaveBeenCalled();
71
+ expect(buildLoggerMock().succeed).toHaveBeenCalledWith('Local Mintlify instance is ready. Launching your site...');
72
+ expect(runMock).toHaveBeenCalled();
73
+ });
74
+ it('prebuild fails', async () => {
75
+ const errorText = 'Some OpenAPI or docs.json schema error';
76
+ prebuildMock.mockRejectedValueOnce(new Error(errorText));
77
+ await dev(emptyYargs);
78
+ expect(buildLoggerMock).toHaveBeenCalledWith('Preparing local Mintlify instance...');
79
+ expect(buildLoggerMock().fail).toHaveBeenCalledWith(errorText);
80
+ expect(processExitMock).toHaveBeenCalledWith(1);
81
+ });
82
+ });
83
+ describe('dev with no internet', () => {
84
+ beforeEach(() => {
85
+ process.chdir = vi.fn();
86
+ vi.clearAllMocks();
87
+ });
88
+ afterEach(() => {
89
+ process.chdir = originalChdir;
90
+ });
91
+ it('fails if no existing version', async () => {
92
+ vi.mocked(isOnline).mockResolvedValueOnce(false);
93
+ vi.mocked(fse.pathExists).mockResolvedValueOnce();
94
+ await dev(emptyYargs).catch(() => { });
95
+ expect(processExitMock).toHaveBeenCalledWith(1);
96
+ expect(buildLoggerMock().fail).toHaveBeenCalledWith('Running mintlify dev afer updating requires an internet connection.');
97
+ });
98
+ it('has existing version but fails to get targetMintVersion', async () => {
99
+ vi.mocked(isOnline).mockResolvedValueOnce(false);
100
+ vi.mocked(getTargetMintVersion).mockResolvedValueOnce(undefined);
101
+ await dev(emptyYargs);
102
+ expect(buildLoggerMock().warn).toHaveBeenCalledWith('Failed to get latest Mintlify client version. Your current version is: 1.0.0, which may not be the latest Mintlify client version.');
103
+ expect(prebuildMock).toHaveBeenCalled();
104
+ expect(buildLoggerMock().succeed).toHaveBeenCalledWith('Local Mintlify instance is ready. Launching your site...');
105
+ expect(runMock).toHaveBeenCalled();
106
+ });
107
+ });
108
+ describe('dev downloads new version', () => {
109
+ beforeEach(() => {
110
+ process.chdir = vi.fn();
111
+ vi.clearAllMocks();
112
+ });
113
+ afterEach(() => {
114
+ process.chdir = originalChdir;
115
+ });
116
+ it('happy path', async () => {
117
+ vi.mocked(getTargetMintVersion).mockResolvedValueOnce('1.0.1');
118
+ await dev(emptyYargs);
119
+ expect(buildLoggerMock).toHaveBeenCalledWith('Preparing local Mintlify instance...');
120
+ expect(downloadTargetMintMock).toHaveBeenCalled();
121
+ expect(prebuildMock).toHaveBeenCalled();
122
+ expect(buildLoggerMock().succeed).toHaveBeenCalledWith('Local Mintlify instance is ready. Launching your site...');
123
+ expect(runMock).toHaveBeenCalled();
124
+ });
125
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,220 @@
1
+ import fse from 'fs-extra';
2
+ import { pipeline } from 'node:stream/promises';
3
+ import tar from 'tar';
4
+ import { mockProcessExit } from 'vitest-mock-process';
5
+ import * as constants from '../constants.js';
6
+ import { downloadTargetMint } from '../local-preview/client.js';
7
+ import * as utils from '../util.js';
8
+ vi.mock('fs-extra', () => {
9
+ const mocks = {
10
+ existsSync: vi.fn().mockReturnValue(true),
11
+ moveSync: vi.fn().mockReturnValue(undefined),
12
+ ensureDirSync: vi.fn().mockReturnValue(undefined),
13
+ removeSync: vi.fn().mockReturnValue(undefined),
14
+ writeFileSync: vi.fn().mockReturnValue(undefined),
15
+ createWriteStream: vi.fn().mockReturnValue({ write: vi.fn(), end: vi.fn() }),
16
+ };
17
+ return {
18
+ ...mocks,
19
+ default: mocks,
20
+ };
21
+ });
22
+ 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
+ restoreMintlifyLast: vi.fn().mockReturnValue(undefined),
33
+ getTarUrl: vi.fn().mockReturnValue('https://asdfghjkl.cloudfront.net/mint-1.0.1.tar.gz'),
34
+ }));
35
+ vi.mock('node:stream/promises', () => ({
36
+ pipeline: vi.fn(),
37
+ }));
38
+ vi.mock('got', () => {
39
+ const mocks = {
40
+ stream: vi.fn().mockReturnValue({ pipe: vi.fn(), on: vi.fn() }),
41
+ };
42
+ return {
43
+ ...mocks,
44
+ default: mocks,
45
+ };
46
+ });
47
+ vi.mock('tar', () => {
48
+ const mocks = {
49
+ x: vi.fn(),
50
+ };
51
+ return {
52
+ ...mocks,
53
+ default: mocks,
54
+ };
55
+ });
56
+ const buildLoggerMock = vi.mocked(utils.buildLogger);
57
+ const restoreMintlifyLastMock = vi.mocked(utils.restoreMintlifyLast);
58
+ const pipelineMock = vi.mocked(pipeline);
59
+ const getTarUrlMock = vi.mocked(utils.getTarUrl);
60
+ const writeFileSyncMock = vi.mocked(fse.writeFileSync);
61
+ const tarMock = vi.mocked(tar);
62
+ const existsSyncMock = vi.mocked(fse.existsSync);
63
+ const moveSyncMock = vi.mocked(fse.moveSync);
64
+ const removeSyncMock = vi.mocked(fse.removeSync);
65
+ const processExitMock = mockProcessExit();
66
+ describe('downloadTargetMint', () => {
67
+ beforeEach(() => {
68
+ vi.clearAllMocks();
69
+ });
70
+ it('downloads and extracts a new version happy path', async () => {
71
+ const logger = buildLoggerMock();
72
+ const targetMintVersion = '1.0.1';
73
+ const versionString = '1.0.0';
74
+ pipelineMock.mockResolvedValue(undefined);
75
+ await downloadTargetMint({
76
+ logger,
77
+ targetVersion: targetMintVersion,
78
+ existingVersion: versionString,
79
+ });
80
+ // Verify backup was created
81
+ expect(existsSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
82
+ expect(moveSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY, constants.DOT_MINTLIFY_LAST, {
83
+ overwrite: true,
84
+ });
85
+ expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
86
+ // Verify download and extraction
87
+ expect(getTarUrlMock).toHaveBeenCalledWith(targetMintVersion);
88
+ expect(pipelineMock).toHaveBeenCalled();
89
+ expect(tarMock.x).toHaveBeenCalled();
90
+ expect(logger.text).toBe('Extracting Mintlify framework...');
91
+ // Verify cleanup
92
+ expect(removeSyncMock).toHaveBeenCalledWith(constants.TAR_PATH);
93
+ expect(removeSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY_LAST);
94
+ expect(writeFileSyncMock).toHaveBeenCalledWith(constants.VERSION_PATH, targetMintVersion);
95
+ // Verify no restore was needed
96
+ expect(restoreMintlifyLastMock).not.toHaveBeenCalled();
97
+ });
98
+ it('downloads and extracts a specific client version happy path', async () => {
99
+ const logger = buildLoggerMock();
100
+ const versionString = '1.0.0';
101
+ const clientVersion = '2.0.0';
102
+ pipelineMock.mockResolvedValue(undefined);
103
+ await downloadTargetMint({
104
+ logger,
105
+ targetVersion: clientVersion,
106
+ existingVersion: versionString,
107
+ });
108
+ // Verify backup was created
109
+ expect(existsSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
110
+ expect(moveSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY, constants.DOT_MINTLIFY_LAST, {
111
+ overwrite: true,
112
+ });
113
+ expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
114
+ // Verify download and extraction
115
+ expect(getTarUrlMock).toHaveBeenCalledWith(clientVersion);
116
+ expect(pipelineMock).toHaveBeenCalled();
117
+ expect(tarMock.x).toHaveBeenCalled();
118
+ expect(logger.text).toBe('Extracting Mintlify framework...');
119
+ // Verify cleanup
120
+ expect(removeSyncMock).toHaveBeenCalledWith(constants.TAR_PATH);
121
+ expect(removeSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY_LAST);
122
+ expect(writeFileSyncMock).toHaveBeenCalledWith(constants.VERSION_PATH, clientVersion);
123
+ // Verify no restore was needed
124
+ expect(restoreMintlifyLastMock).not.toHaveBeenCalled();
125
+ });
126
+ describe('downloadTargetMint with backup version', () => {
127
+ beforeEach(() => {
128
+ vi.clearAllMocks();
129
+ });
130
+ it('fails to download new version', async () => {
131
+ const logger = buildLoggerMock();
132
+ const targetMintVersion = '1.0.1';
133
+ const versionString = '1.0.0';
134
+ pipelineMock.mockRejectedValue(new Error('connection timed out'));
135
+ await downloadTargetMint({
136
+ logger,
137
+ targetVersion: targetMintVersion,
138
+ existingVersion: versionString,
139
+ });
140
+ // Verify backup was created
141
+ expect(existsSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
142
+ expect(moveSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY, constants.DOT_MINTLIFY_LAST, {
143
+ overwrite: true,
144
+ });
145
+ expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
146
+ // Verify download fail
147
+ expect(logger.warn).toHaveBeenCalledWith('Failed to download Mintlify framework version 1.0.1, Error: connection timed out, falling back to existing version: 1.0.0');
148
+ // Verify use backup version
149
+ expect(restoreMintlifyLastMock).toHaveBeenCalled();
150
+ // Verify no extraction
151
+ expect(tarMock.x).not.toHaveBeenCalled();
152
+ // Verify no cleanup
153
+ expect(removeSyncMock).not.toHaveBeenCalled();
154
+ expect(writeFileSyncMock).not.toHaveBeenCalled();
155
+ });
156
+ it('fails to extract new version', async () => {
157
+ const logger = buildLoggerMock();
158
+ const targetMintVersion = '1.0.1';
159
+ const versionString = '1.0.0';
160
+ pipelineMock.mockResolvedValue(undefined);
161
+ tarMock.x.mockImplementation(() => {
162
+ throw new Error('Zlib error');
163
+ });
164
+ await downloadTargetMint({
165
+ logger,
166
+ targetVersion: targetMintVersion,
167
+ existingVersion: versionString,
168
+ });
169
+ // Verify backup was created
170
+ expect(existsSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
171
+ expect(moveSyncMock).toHaveBeenCalledWith(constants.DOT_MINTLIFY, constants.DOT_MINTLIFY_LAST, {
172
+ overwrite: true,
173
+ });
174
+ expect(fse.ensureDirSync).toHaveBeenCalledWith(constants.DOT_MINTLIFY);
175
+ // Verify download success
176
+ expect(pipelineMock).toHaveBeenCalled();
177
+ // Verify extraction fail
178
+ expect(logger.warn).toHaveBeenCalledWith('Failed to extract Mintlify framework version 1.0.1, Error: Zlib error, using existing version: 1.0.0');
179
+ // Verify use backup version
180
+ expect(restoreMintlifyLastMock).toHaveBeenCalled();
181
+ // Verify no cleanup
182
+ expect(removeSyncMock).not.toHaveBeenCalled();
183
+ expect(writeFileSyncMock).not.toHaveBeenCalled();
184
+ });
185
+ });
186
+ describe('downloadTargetMint without backup version', () => {
187
+ beforeEach(() => {
188
+ vi.clearAllMocks();
189
+ });
190
+ it('fails to download new version with no fallback', async () => {
191
+ const logger = buildLoggerMock();
192
+ const targetMintVersion = '1.0.1';
193
+ const versionString = null;
194
+ pipelineMock.mockRejectedValue(new Error('connection timed out'));
195
+ await downloadTargetMint({
196
+ logger,
197
+ targetVersion: targetMintVersion,
198
+ existingVersion: versionString,
199
+ });
200
+ expect(logger.fail).toHaveBeenCalledWith('Failed to download Mintlify framework version 1.0.1, Error: connection timed out');
201
+ expect(processExitMock).toHaveBeenCalledWith(1);
202
+ });
203
+ it('fails to extract new version with no fallback', async () => {
204
+ const logger = buildLoggerMock();
205
+ const targetMintVersion = '1.0.1';
206
+ const versionString = null;
207
+ pipelineMock.mockResolvedValue(undefined);
208
+ tarMock.x.mockImplementation(() => {
209
+ throw new Error('Zlib error');
210
+ });
211
+ await downloadTargetMint({
212
+ logger,
213
+ targetVersion: targetMintVersion,
214
+ existingVersion: versionString,
215
+ });
216
+ expect(logger.fail).toHaveBeenCalledWith('Failed to extract Mintlify framework version 1.0.1, Error: Zlib error');
217
+ expect(processExitMock).toHaveBeenCalledWith(1);
218
+ });
219
+ });
220
+ });
@@ -1,6 +1,7 @@
1
1
  export declare const INSTALL_PATH: string;
2
2
  export declare const HOME_DIR: string;
3
3
  export declare const DOT_MINTLIFY: string;
4
+ export declare const DOT_MINTLIFY_LAST = ".mintlify-last";
4
5
  export declare const MINT_PATH: string;
5
6
  export declare const VERSION_PATH: string;
6
7
  export declare const CLIENT_PATH: string;
@@ -9,8 +10,8 @@ export declare const NEXT_ROUTER_SERVER_PATH: string;
9
10
  export declare const NEXT_CONFIG_PATH: string;
10
11
  export declare const NEXT_PUBLIC_PATH: string;
11
12
  export declare const NEXT_PROPS_PATH: string;
12
- export declare const TARGET_MINT_VERSION_URL = "https://mint-releases.b-cdn.net/mint-version.txt";
13
- export declare const GET_TAR_URL: (version: string) => string;
13
+ export declare const MINT_CLIENT_RELEASES_CLOUDFRONT_URL = "https://d1ctpt7j8wusba.cloudfront.net";
14
+ export declare const TARGET_MINT_VERSION_URL = "https://d1ctpt7j8wusba.cloudfront.net/mint-version.txt";
14
15
  export declare const TAR_PATH: string;
15
16
  export declare const CMD_EXEC_PATH: string;
16
17
  export declare const SUPPORTED_MEDIA_EXTENSIONS: string[];
package/dist/constants.js CHANGED
@@ -5,6 +5,7 @@ import * as url from 'url';
5
5
  export const INSTALL_PATH = url.fileURLToPath(new URL('.', import.meta.url));
6
6
  export const HOME_DIR = os.homedir();
7
7
  export const DOT_MINTLIFY = path.join(HOME_DIR, '.mintlify');
8
+ export const DOT_MINTLIFY_LAST = '.mintlify-last';
8
9
  export const MINT_PATH = path.join(DOT_MINTLIFY, 'mint');
9
10
  export const VERSION_PATH = path.join(MINT_PATH, 'mint-version.txt');
10
11
  export const CLIENT_PATH = path.join(MINT_PATH, 'apps', 'client');
@@ -14,8 +15,8 @@ export const NEXT_ROUTER_SERVER_PATH = path.join(NEXT_DIST_SERVER_PATH, 'lib', '
14
15
  export const NEXT_CONFIG_PATH = path.join(CLIENT_PATH, '.next', 'required-server-files.json');
15
16
  export const NEXT_PUBLIC_PATH = path.join(CLIENT_PATH, 'public');
16
17
  export const NEXT_PROPS_PATH = path.join(CLIENT_PATH, 'src', '_props');
17
- export const TARGET_MINT_VERSION_URL = 'https://mint-releases.b-cdn.net/mint-version.txt';
18
- export const GET_TAR_URL = (version) => `https://mint-releases.b-cdn.net/mint-${version}.tar.gz`;
18
+ export const MINT_CLIENT_RELEASES_CLOUDFRONT_URL = 'https://d1ctpt7j8wusba.cloudfront.net';
19
+ export const TARGET_MINT_VERSION_URL = `${MINT_CLIENT_RELEASES_CLOUDFRONT_URL}/mint-version.txt`;
19
20
  export const TAR_PATH = path.join(DOT_MINTLIFY, `mint.tar.gz`);
20
21
  // command execution location
21
22
  export const CMD_EXEC_PATH = process.cwd();
@@ -1,5 +1,7 @@
1
1
  import type { Ora as OraType } from 'ora';
2
2
  export declare const getTargetMintVersion: (logger: OraType) => Promise<string | undefined>;
3
- export declare const fallbackMintClient: (logger: OraType, versionString: string) => Promise<void>;
4
- export declare const extractMintClient: (logger: OraType) => Promise<void>;
5
- export declare const downloadTargetMint: (logger: OraType, targetMintVersion: string, versionString: string | null, clientVersion: string | undefined) => Promise<void>;
3
+ export declare const downloadTargetMint: ({ logger, targetVersion, existingVersion, }: {
4
+ logger: OraType;
5
+ targetVersion: string;
6
+ existingVersion: string | null;
7
+ }) => Promise<void>;
@@ -1,90 +1,73 @@
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
1
  import fse from 'fs-extra';
11
2
  import got from 'got';
12
3
  import isOnline from 'is-online';
13
4
  import { pipeline } from 'node:stream/promises';
14
5
  import tar from 'tar';
15
- import { DOT_MINTLIFY, VERSION_PATH, MINT_PATH, TAR_PATH, TARGET_MINT_VERSION_URL, GET_TAR_URL, } from '../constants.js';
16
- export const getTargetMintVersion = (logger) => __awaiter(void 0, void 0, void 0, function* () {
17
- const hasInternet = yield isOnline();
6
+ import { DOT_MINTLIFY, DOT_MINTLIFY_LAST, VERSION_PATH, TAR_PATH, TARGET_MINT_VERSION_URL, } from '../constants.js';
7
+ import { restoreMintlifyLast, getTarUrl } from '../util.js';
8
+ export const getTargetMintVersion = async (logger) => {
9
+ const hasInternet = await isOnline();
18
10
  if (!hasInternet) {
19
11
  return undefined;
20
12
  }
21
13
  try {
22
- const response = yield got(TARGET_MINT_VERSION_URL);
14
+ const response = await got(TARGET_MINT_VERSION_URL);
23
15
  return response.body;
24
16
  }
25
17
  catch (error) {
26
18
  logger.text = `Failed to fetch the latest Mintlify version: ${error instanceof Error ? error.message : 'Unknown error'}`;
27
- return undefined;
28
- }
29
- });
30
- export const fallbackMintClient = (logger, versionString) => __awaiter(void 0, void 0, void 0, function* () {
31
- logger.text = `Using version: ${versionString}`;
32
- const oldTarUrl = GET_TAR_URL(versionString);
33
- try {
34
- yield pipeline(got.stream(oldTarUrl), fse.createWriteStream(TAR_PATH));
35
- }
36
- catch (error) {
37
- logger.fail(`Failed to download Mintlify framework version ${versionString}, ${error}`);
38
- process.exit(1);
39
19
  }
40
- try {
41
- yield extractMintClient(logger);
42
- }
43
- catch (error) {
44
- logger.fail(`Failed to extract Mintlify framework version ${versionString}, ${error}`);
45
- process.exit(1);
20
+ return undefined;
21
+ };
22
+ export const downloadTargetMint = async ({ logger, targetVersion, existingVersion, }) => {
23
+ if (fse.existsSync(DOT_MINTLIFY)) {
24
+ fse.moveSync(DOT_MINTLIFY, DOT_MINTLIFY_LAST, { overwrite: true });
46
25
  }
47
- });
48
- export const extractMintClient = (logger) => __awaiter(void 0, void 0, void 0, function* () {
49
- logger.text = 'Extracting Mintlify framework...';
50
- tar.x({
51
- sync: true,
52
- file: TAR_PATH,
53
- cwd: DOT_MINTLIFY,
54
- onwarn: (_code, message, _data) => {
55
- throw new Error(message);
56
- },
57
- });
58
- });
59
- export const downloadTargetMint = (logger, targetMintVersion, versionString, clientVersion) => __awaiter(void 0, void 0, void 0, function* () {
60
- fse.emptyDirSync(MINT_PATH);
26
+ fse.ensureDirSync(DOT_MINTLIFY);
61
27
  logger.text = 'Downloading Mintlify framework...';
62
- const tarUrl = clientVersion ? GET_TAR_URL(clientVersion) : GET_TAR_URL(targetMintVersion);
63
- let currentVersion = clientVersion || targetMintVersion;
28
+ const tarUrl = getTarUrl(targetVersion);
29
+ let currentVersion = targetVersion.trim();
64
30
  try {
65
- yield pipeline(got.stream(tarUrl), fse.createWriteStream(TAR_PATH));
31
+ await pipeline(got.stream(tarUrl), fse.createWriteStream(TAR_PATH));
66
32
  }
67
33
  catch (error) {
68
- if (versionString) {
69
- currentVersion = versionString;
70
- yield fallbackMintClient(logger, versionString);
34
+ if (existingVersion) {
35
+ logger.warn(`Failed to download Mintlify framework version ${currentVersion}, ${error}, falling back to existing version: ${existingVersion}`);
36
+ currentVersion = existingVersion;
37
+ restoreMintlifyLast();
38
+ return;
71
39
  }
72
40
  else {
41
+ logger.fail(`Failed to download Mintlify framework version ${currentVersion}, ${error}`);
73
42
  process.exit(1);
74
43
  }
75
44
  }
76
45
  try {
77
- yield extractMintClient(logger);
46
+ logger.text = 'Extracting Mintlify framework...';
47
+ tar.x({
48
+ sync: true,
49
+ file: TAR_PATH,
50
+ cwd: DOT_MINTLIFY,
51
+ onwarn: (_code, message, _data) => {
52
+ throw new Error(message);
53
+ },
54
+ });
78
55
  }
79
56
  catch (error) {
80
- if (versionString && currentVersion !== versionString) {
81
- currentVersion = versionString;
82
- yield fallbackMintClient(logger, versionString);
57
+ if (existingVersion) {
58
+ logger.warn(`Failed to extract Mintlify framework version ${currentVersion}, ${error}, using existing version: ${existingVersion}`);
59
+ currentVersion = existingVersion;
60
+ restoreMintlifyLast();
61
+ return;
83
62
  }
84
63
  else {
64
+ logger.fail(`Failed to extract Mintlify framework version ${currentVersion}, ${error}`);
85
65
  process.exit(1);
86
66
  }
87
67
  }
88
68
  fse.removeSync(TAR_PATH);
89
- fse.writeFileSync(VERSION_PATH, targetMintVersion);
90
- });
69
+ if (fse.existsSync(DOT_MINTLIFY_LAST)) {
70
+ fse.removeSync(DOT_MINTLIFY_LAST);
71
+ }
72
+ fse.writeFileSync(VERSION_PATH, currentVersion);
73
+ };