@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.
- package/dist/__tests__/dev.test.d.ts +1 -0
- package/dist/__tests__/dev.test.js +125 -0
- package/dist/__tests__/downloadTargetMint.test.d.ts +1 -0
- package/dist/__tests__/downloadTargetMint.test.js +220 -0
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js +3 -2
- package/dist/local-preview/client.d.ts +5 -3
- package/dist/local-preview/client.js +40 -57
- package/dist/local-preview/index.js +18 -107
- package/dist/local-preview/listener/generate.js +15 -21
- package/dist/local-preview/listener/generateDependentSnippets.js +23 -26
- package/dist/local-preview/listener/generatePagesWithImports.js +11 -20
- package/dist/local-preview/listener/getDocsState.js +10 -19
- package/dist/local-preview/listener/getSnippets.js +6 -15
- package/dist/local-preview/listener/index.js +45 -54
- package/dist/local-preview/listener/resolveAllImports.js +4 -13
- package/dist/local-preview/listener/update.js +14 -23
- package/dist/local-preview/listener/utils.js +6 -15
- package/dist/local-preview/run.d.ts +2 -0
- package/dist/local-preview/run.js +47 -0
- package/dist/local-preview/setupNext.d.ts +22 -0
- package/dist/local-preview/setupNext.js +41 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/util.d.ts +2 -0
- package/dist/util.js +11 -0
- package/package.json +6 -3
|
@@ -1,59 +1,46 @@
|
|
|
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 { prebuild } from '@mintlify/prebuild';
|
|
11
|
-
import open from 'better-opn';
|
|
12
|
-
import Chalk from 'chalk';
|
|
13
|
-
import express from 'express';
|
|
14
2
|
import fse, { pathExists } from 'fs-extra';
|
|
15
|
-
import { createServer } from 'http';
|
|
16
3
|
import isOnline from 'is-online';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { CLIENT_PATH, DOT_MINTLIFY, CMD_EXEC_PATH, VERSION_PATH, NEXT_CONFIG_PATH, NEXT_PUBLIC_PATH, NEXT_PROPS_PATH, NEXT_SIDE_EFFECT_PATH, NEXT_ROUTER_SERVER_PATH, } from '../constants.js';
|
|
20
|
-
import { buildLogger, maybeFixMissingWindowsEnvVar } from '../util.js';
|
|
4
|
+
import { CLIENT_PATH, DOT_MINTLIFY, CMD_EXEC_PATH, VERSION_PATH, NEXT_PUBLIC_PATH, NEXT_PROPS_PATH, } from '../constants.js';
|
|
5
|
+
import { buildLogger } from '../util.js';
|
|
21
6
|
import { getTargetMintVersion, downloadTargetMint } from './client.js';
|
|
22
|
-
import
|
|
23
|
-
const dev = (argv) =>
|
|
7
|
+
import { run } from './run.js';
|
|
8
|
+
const dev = async (argv) => {
|
|
24
9
|
// Note: We wait for specific text in the logger to be sure the server is ready when we e2e test the cli.
|
|
25
10
|
// If the cli output does not exactly match:
|
|
26
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."
|
|
27
12
|
// the test will fail/require an update.
|
|
28
13
|
const logger = buildLogger('Preparing local Mintlify instance...');
|
|
29
|
-
const hasInternet =
|
|
14
|
+
const hasInternet = await isOnline();
|
|
30
15
|
const localSchema = argv['local-schema'];
|
|
31
16
|
const clientVersion = argv['client-version'];
|
|
32
|
-
|
|
33
|
-
const versionString = (
|
|
17
|
+
await fse.ensureDir(DOT_MINTLIFY);
|
|
18
|
+
const versionString = (await pathExists(VERSION_PATH))
|
|
34
19
|
? fse.readFileSync(VERSION_PATH, 'utf8')
|
|
35
20
|
: null;
|
|
36
21
|
if (!versionString && !hasInternet) {
|
|
37
22
|
logger.fail('Running mintlify dev afer updating requires an internet connection.');
|
|
38
23
|
process.exit(1);
|
|
39
24
|
}
|
|
40
|
-
const targetMintVersion =
|
|
25
|
+
const targetMintVersion = await getTargetMintVersion(logger);
|
|
41
26
|
if (!targetMintVersion) {
|
|
42
|
-
logger.
|
|
43
|
-
|
|
44
|
-
versionString +
|
|
45
|
-
', which may not be the latest Mintlify client version.';
|
|
27
|
+
logger.stopAndPersist({ symbol: '✓' });
|
|
28
|
+
logger.warn(`Failed to get latest Mintlify client version. Your current version is: ${versionString?.trim()}, which may not be the latest Mintlify client version.`);
|
|
46
29
|
}
|
|
47
30
|
const shouldDownload = versionString !== targetMintVersion || clientVersion !== undefined;
|
|
48
31
|
if (shouldDownload && hasInternet && targetMintVersion) {
|
|
49
|
-
|
|
32
|
+
await downloadTargetMint({
|
|
33
|
+
logger,
|
|
34
|
+
targetVersion: clientVersion ?? targetMintVersion,
|
|
35
|
+
existingVersion: versionString,
|
|
36
|
+
});
|
|
50
37
|
}
|
|
51
38
|
// clear preexisting prebuild files
|
|
52
39
|
fse.emptyDirSync(NEXT_PUBLIC_PATH);
|
|
53
40
|
fse.emptyDirSync(NEXT_PROPS_PATH);
|
|
54
41
|
process.chdir(CLIENT_PATH);
|
|
55
42
|
try {
|
|
56
|
-
|
|
43
|
+
await prebuild(CMD_EXEC_PATH, { localSchema });
|
|
57
44
|
}
|
|
58
45
|
catch (err) {
|
|
59
46
|
const errorText = err instanceof Error && err.message ? err.message : 'Prebuild step failed';
|
|
@@ -61,82 +48,6 @@ const dev = (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
61
48
|
process.exit(1);
|
|
62
49
|
}
|
|
63
50
|
logger.succeed('Local Mintlify instance is ready. Launching your site...');
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* When creating a standalone build, next.js outputs a server.js file that can be used as
|
|
68
|
-
* an entry point into the server. However, because we want to customize some parts of the
|
|
69
|
-
* http server (adding a socket.io server, serving the whole public directory), we
|
|
70
|
-
* create the server ourselves, and just reproduce the setup that next.js would do.
|
|
71
|
-
*
|
|
72
|
-
* Because we need to directly import from node_modules files, this solution seems very hacky,
|
|
73
|
-
* but it is arguably no more hacky than using the server.js that ships with the standalone
|
|
74
|
-
* build.
|
|
75
|
-
*
|
|
76
|
-
* This function attempts to replicate the behavior of two next.js files:
|
|
77
|
-
* - environment setup from server.js
|
|
78
|
-
* - initialization of the request handler from start-server.ts
|
|
79
|
-
*
|
|
80
|
-
* Links:
|
|
81
|
-
* - [standalone build](https://nextjs.org/docs/pages/api-reference/next-config-js/output#automatically-copying-traced-files)
|
|
82
|
-
* - [server.js](https://github.com/vercel/next.js/blob/492156b4c5e2559b2a280f7d483cd85a8e8742a9/packages/next/src/build/utils.ts#L2108-L2113) (created programmatically)
|
|
83
|
-
* - [start-server.ts](https://github.com/vercel/next.js/blob/492156b4c5e2559b2a280f7d483cd85a8e8742a9/packages/next/src/server/lib/start-server.ts#L296-L308)
|
|
84
|
-
*
|
|
85
|
-
* @returns the request handler provided by next.js
|
|
86
|
-
*/
|
|
87
|
-
const setupNext = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
-
const hostname = process.env.HOSTNAME || 'localhost';
|
|
89
|
-
const { config } = yield JSON.parse(fse.readFileSync(NEXT_CONFIG_PATH, 'utf8'));
|
|
90
|
-
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config);
|
|
91
|
-
// The server.js provided by next.js's standalone build does a similar import of this file.
|
|
92
|
-
// Not sure what side effects are being created, but want to change as little as possible.
|
|
93
|
-
// Also, Windows requires us to use `pathToFileURL` (see #899)
|
|
94
|
-
yield import(pathToFileURL(NEXT_SIDE_EFFECT_PATH).href);
|
|
95
|
-
const { initialize } = yield import(pathToFileURL(NEXT_ROUTER_SERVER_PATH).href);
|
|
96
|
-
const [requestHandler] = yield initialize({
|
|
97
|
-
dir: CLIENT_PATH,
|
|
98
|
-
dev: false,
|
|
99
|
-
hostname,
|
|
100
|
-
minimalMode: true,
|
|
101
|
-
});
|
|
102
|
-
return requestHandler;
|
|
103
|
-
});
|
|
104
|
-
const run = (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
-
const port = argv.port || '3000';
|
|
106
|
-
const currentPort = parseInt(port, 10) || 3000;
|
|
107
|
-
const app = express();
|
|
108
|
-
const server = createServer(app);
|
|
109
|
-
const io = new SocketServer(server);
|
|
110
|
-
const requestHandler = yield setupNext();
|
|
111
|
-
// next-server is bugged, public files added after starting aren't served
|
|
112
|
-
app.use('/', express.static(NEXT_PUBLIC_PATH));
|
|
113
|
-
app.all('*', (req, res) => requestHandler(req, res));
|
|
114
|
-
const onChange = () => {
|
|
115
|
-
io.emit('reload');
|
|
116
|
-
};
|
|
117
|
-
server.listen(currentPort, () => {
|
|
118
|
-
console.log(`${Chalk.green(`Your local preview is available at http://localhost:${port}`)}`);
|
|
119
|
-
// Note: We wait for this exact text to be sure the server is ready in the cli e2e test,
|
|
120
|
-
// if it changes, the test will fail/require an update.
|
|
121
|
-
console.log(`${Chalk.green('Press Ctrl+C any time to stop the local preview.')}`);
|
|
122
|
-
/**
|
|
123
|
-
* We're running into a known bug with the `open` package, where Windows machines error out because process.env.SYSTEMROOT is not set:
|
|
124
|
-
* https://github.com/sindresorhus/open/issues/292
|
|
125
|
-
*
|
|
126
|
-
* Let's use the same workaround that this project did:
|
|
127
|
-
* https://github.com/sanity-io/sanity/pull/4221/files#diff-aeb574e1becf61f21fdf87fbea709669c93d604d660dad4b0f9e24527a2fb54bR256-R262
|
|
128
|
-
*/
|
|
129
|
-
maybeFixMissingWindowsEnvVar();
|
|
130
|
-
if (argv.open) {
|
|
131
|
-
void open(`http://localhost:${port}`);
|
|
132
|
-
}
|
|
133
|
-
// exit with successful status
|
|
134
|
-
const onExit = () => {
|
|
135
|
-
process.exit(0);
|
|
136
|
-
};
|
|
137
|
-
process.on('SIGINT', onExit);
|
|
138
|
-
process.on('SIGTERM', onExit);
|
|
139
|
-
});
|
|
140
|
-
listener(onChange);
|
|
141
|
-
});
|
|
51
|
+
await run(argv);
|
|
52
|
+
};
|
|
142
53
|
export default dev;
|
|
@@ -1,33 +1,27 @@
|
|
|
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 { categorizeFilePaths, createPage, generateDecoratedDocsNavigationFromPages, } from '@mintlify/prebuild';
|
|
11
2
|
import { promises as _promises } from 'fs';
|
|
12
3
|
import { join } from 'path';
|
|
13
4
|
import { CMD_EXEC_PATH } from '../../constants.js';
|
|
14
5
|
const { readFile } = _promises;
|
|
15
|
-
const createFilenamePageMetadataMap =
|
|
6
|
+
const createFilenamePageMetadataMap = async ({ contentDirectoryPath, contentFilenames, openApiFiles, asyncApiFiles, pagesAcc = {}, }) => {
|
|
16
7
|
const contentPromises = [];
|
|
17
8
|
contentFilenames.forEach((filename) => {
|
|
18
|
-
contentPromises.push((() =>
|
|
9
|
+
contentPromises.push((async () => {
|
|
19
10
|
const sourcePath = join(contentDirectoryPath, filename);
|
|
20
|
-
const contentStr = (
|
|
21
|
-
const { slug, pageMetadata } =
|
|
22
|
-
pagesAcc =
|
|
23
|
-
|
|
11
|
+
const contentStr = (await readFile(sourcePath)).toString();
|
|
12
|
+
const { slug, pageMetadata } = await createPage(filename, contentStr, contentDirectoryPath, openApiFiles, asyncApiFiles, true);
|
|
13
|
+
pagesAcc = {
|
|
14
|
+
...pagesAcc,
|
|
15
|
+
[slug]: pageMetadata,
|
|
16
|
+
};
|
|
17
|
+
})());
|
|
24
18
|
});
|
|
25
|
-
|
|
19
|
+
await Promise.all(contentPromises);
|
|
26
20
|
return pagesAcc;
|
|
27
|
-
}
|
|
28
|
-
export const generateNav = (pagesAcc, docsConfig) =>
|
|
29
|
-
const { contentFilenames, openApiFiles, asyncApiFiles } =
|
|
30
|
-
const filenamePageMetadataMap =
|
|
21
|
+
};
|
|
22
|
+
export const generateNav = async (pagesAcc, docsConfig) => {
|
|
23
|
+
const { contentFilenames, openApiFiles, asyncApiFiles } = await categorizeFilePaths(CMD_EXEC_PATH);
|
|
24
|
+
const filenamePageMetadataMap = await createFilenamePageMetadataMap({
|
|
31
25
|
contentDirectoryPath: CMD_EXEC_PATH,
|
|
32
26
|
contentFilenames,
|
|
33
27
|
openApiFiles,
|
|
@@ -36,4 +30,4 @@ export const generateNav = (pagesAcc, docsConfig) => __awaiter(void 0, void 0, v
|
|
|
36
30
|
});
|
|
37
31
|
const generatedDocsNav = generateDecoratedDocsNavigationFromPages(filenamePageMetadataMap, docsConfig.navigation);
|
|
38
32
|
return generatedDocsNav;
|
|
39
|
-
}
|
|
33
|
+
};
|
|
@@ -1,19 +1,10 @@
|
|
|
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 { findAndRemoveImports, stringifyTree, topologicalSort, hasImports, optionallyAddLeadingSlash, optionallyRemoveLeadingSlash, } from '@mintlify/common';
|
|
11
2
|
import { outputFile } from 'fs-extra';
|
|
12
3
|
import { join } from 'path';
|
|
13
4
|
import { NEXT_PUBLIC_PATH } from '../../constants.js';
|
|
14
5
|
import { getOriginalSnippets } from './getSnippets.js';
|
|
15
6
|
import { resolveAllImports } from './resolveAllImports.js';
|
|
16
|
-
const findAllDependents = (initialFileWithSlash, allSnippets, processedDataCache) =>
|
|
7
|
+
const findAllDependents = async (initialFileWithSlash, allSnippets, processedDataCache) => {
|
|
17
8
|
const affected = new Set([initialFileWithSlash]);
|
|
18
9
|
const queue = [initialFileWithSlash];
|
|
19
10
|
while (queue.length > 0) {
|
|
@@ -25,7 +16,7 @@ const findAllDependents = (initialFileWithSlash, allSnippets, processedDataCache
|
|
|
25
16
|
let processedData = processedDataCache.get(potentialDependentFile);
|
|
26
17
|
if (processedData == null) {
|
|
27
18
|
const clonedTree = structuredClone(snippet.tree);
|
|
28
|
-
processedData =
|
|
19
|
+
processedData = await findAndRemoveImports(clonedTree);
|
|
29
20
|
processedDataCache.set(potentialDependentFile, processedData);
|
|
30
21
|
}
|
|
31
22
|
if (processedData.importMap[currentSourceFile]) {
|
|
@@ -37,30 +28,36 @@ const findAllDependents = (initialFileWithSlash, allSnippets, processedDataCache
|
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
30
|
return affected;
|
|
40
|
-
}
|
|
41
|
-
export const generateDependentSnippets = (changedFilename, newImportData) =>
|
|
31
|
+
};
|
|
32
|
+
export const generateDependentSnippets = async (changedFilename, newImportData) => {
|
|
42
33
|
const processedDataCache = new Map();
|
|
43
|
-
const allOriginalSnippets =
|
|
34
|
+
const allOriginalSnippets = await getOriginalSnippets();
|
|
44
35
|
const updatedSnippetFileKey = optionallyAddLeadingSlash(changedFilename);
|
|
45
|
-
const affectedSnippets =
|
|
46
|
-
const snippetPromises = Array.from(affectedSnippets).map((filename) =>
|
|
36
|
+
const affectedSnippets = await findAllDependents(updatedSnippetFileKey, allOriginalSnippets, processedDataCache);
|
|
37
|
+
const snippetPromises = Array.from(affectedSnippets).map(async (filename) => {
|
|
47
38
|
const cachedData = processedDataCache.get(filename);
|
|
48
39
|
if (cachedData)
|
|
49
|
-
return
|
|
40
|
+
return { filename, ...cachedData };
|
|
50
41
|
const originalSnippet = allOriginalSnippets.find((s) => optionallyAddLeadingSlash(s.filename) === filename);
|
|
51
42
|
if (!originalSnippet)
|
|
52
43
|
return null;
|
|
53
|
-
const processed =
|
|
44
|
+
const processed = await findAndRemoveImports(structuredClone(originalSnippet.tree));
|
|
54
45
|
processedDataCache.set(filename, processed);
|
|
55
|
-
return
|
|
56
|
-
})
|
|
57
|
-
const snippets = (
|
|
46
|
+
return { filename, ...processed };
|
|
47
|
+
});
|
|
48
|
+
const snippets = (await Promise.all(snippetPromises)).filter((item) => item != null);
|
|
58
49
|
const idx = snippets.findIndex((item) => item.filename === updatedSnippetFileKey);
|
|
59
50
|
if (idx !== -1) {
|
|
60
|
-
snippets[idx] =
|
|
51
|
+
snippets[idx] = {
|
|
52
|
+
...newImportData,
|
|
53
|
+
filename: updatedSnippetFileKey,
|
|
54
|
+
};
|
|
61
55
|
}
|
|
62
56
|
else {
|
|
63
|
-
snippets.push(
|
|
57
|
+
snippets.push({
|
|
58
|
+
...newImportData,
|
|
59
|
+
filename: updatedSnippetFileKey,
|
|
60
|
+
});
|
|
64
61
|
}
|
|
65
62
|
const graph = {};
|
|
66
63
|
snippets.forEach((item) => {
|
|
@@ -75,12 +72,12 @@ export const generateDependentSnippets = (changedFilename, newImportData) => __a
|
|
|
75
72
|
for (const currentSnippet of orderedSnippets) {
|
|
76
73
|
let processedTree = currentSnippet.tree;
|
|
77
74
|
if (currentSnippet.filename !== updatedSnippetFileKey && hasImports(currentSnippet)) {
|
|
78
|
-
processedTree =
|
|
75
|
+
processedTree = await resolveAllImports(currentSnippet);
|
|
79
76
|
}
|
|
80
77
|
const targetFilename = optionallyRemoveLeadingSlash(currentSnippet.filename);
|
|
81
78
|
const targetPath = join(NEXT_PUBLIC_PATH, targetFilename);
|
|
82
|
-
|
|
79
|
+
await outputFile(targetPath, stringifyTree(processedTree), { flag: 'w' });
|
|
83
80
|
processedSnippets.push(targetFilename);
|
|
84
81
|
}
|
|
85
82
|
return processedSnippets;
|
|
86
|
-
}
|
|
83
|
+
};
|
|
@@ -1,12 +1,3 @@
|
|
|
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 { findAndRemoveImports, optionallyRemoveLeadingSlash, resolveAllImports, stringifyTree, } from '@mintlify/common';
|
|
11
2
|
import { preparseMdxTree, getFileListSync } from '@mintlify/prebuild';
|
|
12
3
|
import { promises as _promises } from 'fs';
|
|
@@ -15,22 +6,22 @@ import { join } from 'path';
|
|
|
15
6
|
import { CMD_EXEC_PATH, NEXT_PROPS_PATH } from '../../constants.js';
|
|
16
7
|
import { getProcessedSnippets } from './getSnippets.js';
|
|
17
8
|
const { readFile } = _promises;
|
|
18
|
-
export const generatePagesWithImports = (updatedSnippets) =>
|
|
19
|
-
const snippets =
|
|
9
|
+
export const generatePagesWithImports = async (updatedSnippets) => {
|
|
10
|
+
const snippets = await getProcessedSnippets();
|
|
20
11
|
const pageFilenames = getFileListSync(CMD_EXEC_PATH).filter((file) => file.endsWith('.mdx') && !file.startsWith('_snippets/') && !file.startsWith('snippets/'));
|
|
21
|
-
|
|
12
|
+
await Promise.all(pageFilenames.map(async (pageFilename) => {
|
|
22
13
|
const sourcePath = join(CMD_EXEC_PATH, pageFilename);
|
|
23
|
-
const contentStr = (
|
|
14
|
+
const contentStr = (await readFile(sourcePath)).toString();
|
|
24
15
|
try {
|
|
25
|
-
const tree =
|
|
26
|
-
const importsResponse =
|
|
16
|
+
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, sourcePath);
|
|
17
|
+
const importsResponse = await findAndRemoveImports(tree);
|
|
27
18
|
if (Object.keys(importsResponse.importMap).some((importPath) => updatedSnippets.has(optionallyRemoveLeadingSlash(importPath)))) {
|
|
28
|
-
const content =
|
|
19
|
+
const content = await resolveAllImports({
|
|
29
20
|
snippets,
|
|
30
|
-
fileWithImports:
|
|
21
|
+
fileWithImports: { ...importsResponse, filename: pageFilename },
|
|
31
22
|
});
|
|
32
23
|
const targetPath = join(NEXT_PROPS_PATH, pageFilename);
|
|
33
|
-
|
|
24
|
+
await outputFile(targetPath, stringifyTree(content), {
|
|
34
25
|
flag: 'w',
|
|
35
26
|
});
|
|
36
27
|
}
|
|
@@ -40,5 +31,5 @@ export const generatePagesWithImports = (updatedSnippets) => __awaiter(void 0, v
|
|
|
40
31
|
console.log(pageFilename);
|
|
41
32
|
console.log(err);
|
|
42
33
|
}
|
|
43
|
-
}))
|
|
44
|
-
}
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
@@ -1,24 +1,15 @@
|
|
|
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 { generateOpenApiAnchorsOrTabs, categorizeFilePaths, generateOpenApiDivisions, MintConfigUpdater, DocsConfigUpdater, } from '@mintlify/prebuild';
|
|
11
2
|
import { upgradeToDocsConfig } from '@mintlify/validation';
|
|
12
3
|
import fse from 'fs-extra';
|
|
13
4
|
import { join } from 'path';
|
|
14
5
|
import { CMD_EXEC_PATH, CLIENT_PATH } from '../../constants.js';
|
|
15
|
-
export const getDocsState = () =>
|
|
16
|
-
const { openApiFiles } =
|
|
6
|
+
export const getDocsState = async () => {
|
|
7
|
+
const { openApiFiles } = await categorizeFilePaths(CMD_EXEC_PATH);
|
|
17
8
|
try {
|
|
18
|
-
const mintConfig =
|
|
9
|
+
const mintConfig = await MintConfigUpdater.getConfig(join(CMD_EXEC_PATH, 'mint.json'));
|
|
19
10
|
const docsConfig = upgradeToDocsConfig(mintConfig);
|
|
20
|
-
const { mintConfig: newMintConfig } =
|
|
21
|
-
const { newDocsConfig, pagesAcc, openApiFiles: newOpenApiFiles, } =
|
|
11
|
+
const { mintConfig: newMintConfig } = await generateOpenApiAnchorsOrTabs(mintConfig, openApiFiles, CLIENT_PATH);
|
|
12
|
+
const { newDocsConfig, pagesAcc, openApiFiles: newOpenApiFiles, } = await generateOpenApiDivisions(docsConfig, openApiFiles, CLIENT_PATH);
|
|
22
13
|
return {
|
|
23
14
|
mintConfig: newMintConfig,
|
|
24
15
|
pagesAcc,
|
|
@@ -26,12 +17,12 @@ export const getDocsState = () => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
26
17
|
docsConfig: newDocsConfig,
|
|
27
18
|
};
|
|
28
19
|
}
|
|
29
|
-
catch
|
|
20
|
+
catch {
|
|
30
21
|
const docsJsonPath = join(CMD_EXEC_PATH, 'docs.json');
|
|
31
|
-
if (!(
|
|
22
|
+
if (!(await fse.pathExists(docsJsonPath)))
|
|
32
23
|
throw new Error('No config found');
|
|
33
|
-
const docsConfig =
|
|
34
|
-
const { newDocsConfig, pagesAcc, openApiFiles: newOpenApiFiles, } =
|
|
24
|
+
const docsConfig = await DocsConfigUpdater.getConfig(docsJsonPath);
|
|
25
|
+
const { newDocsConfig, pagesAcc, openApiFiles: newOpenApiFiles, } = await generateOpenApiDivisions(docsConfig, openApiFiles, CLIENT_PATH);
|
|
35
26
|
return { pagesAcc, openApiFiles: newOpenApiFiles, docsConfig: newDocsConfig };
|
|
36
27
|
}
|
|
37
|
-
}
|
|
28
|
+
};
|
|
@@ -1,23 +1,14 @@
|
|
|
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 { optionallyAddLeadingSlash } from '@mintlify/common';
|
|
11
2
|
import { getFileListSync, preparseMdxTree } from '@mintlify/prebuild';
|
|
12
3
|
import { promises as _promises } from 'fs';
|
|
13
4
|
import { join } from 'path';
|
|
14
5
|
import { CMD_EXEC_PATH, NEXT_PUBLIC_PATH } from '../../constants.js';
|
|
15
6
|
const { readFile } = _promises;
|
|
16
|
-
const getSnippetBase = (BASE_DIR) =>
|
|
7
|
+
const getSnippetBase = async (BASE_DIR) => {
|
|
17
8
|
const snippetFilenames = getFileListSync(BASE_DIR).filter((file) => file.endsWith('.mdx') && file.startsWith('snippets/'));
|
|
18
|
-
const promises = snippetFilenames.map((snippetFilename) =>
|
|
9
|
+
const promises = snippetFilenames.map(async (snippetFilename) => {
|
|
19
10
|
try {
|
|
20
|
-
const tree =
|
|
11
|
+
const tree = await preparseMdxTree((await readFile(join(BASE_DIR, snippetFilename))).toString(), BASE_DIR, join(BASE_DIR, snippetFilename));
|
|
21
12
|
return {
|
|
22
13
|
filename: optionallyAddLeadingSlash(snippetFilename),
|
|
23
14
|
tree,
|
|
@@ -27,8 +18,8 @@ const getSnippetBase = (BASE_DIR) => __awaiter(void 0, void 0, void 0, function*
|
|
|
27
18
|
console.warn(`Error reading snippet file ${snippetFilename}`);
|
|
28
19
|
return;
|
|
29
20
|
}
|
|
30
|
-
})
|
|
31
|
-
return (
|
|
32
|
-
}
|
|
21
|
+
});
|
|
22
|
+
return (await Promise.all(promises)).filter(Boolean);
|
|
23
|
+
};
|
|
33
24
|
export const getProcessedSnippets = () => getSnippetBase(NEXT_PUBLIC_PATH);
|
|
34
25
|
export const getOriginalSnippets = () => getSnippetBase(CMD_EXEC_PATH);
|