@mintlify/prebuild 1.0.1156 → 1.0.1158
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.
|
@@ -6,6 +6,12 @@ export type FileWithImportsAndMetadata = FileWithImports & {
|
|
|
6
6
|
metadata?: Record<string, unknown>;
|
|
7
7
|
contentDirectoryPath?: string;
|
|
8
8
|
};
|
|
9
|
+
export type RssCandidatePage = {
|
|
10
|
+
targetPath: string;
|
|
11
|
+
sourcePath: string;
|
|
12
|
+
tree: Root;
|
|
13
|
+
metadata: DecoratedNavigationPage;
|
|
14
|
+
};
|
|
9
15
|
type ReadPageContentsArgs = {
|
|
10
16
|
contentDirectoryPath: string;
|
|
11
17
|
openApiFiles: OpenApiFile[];
|
|
@@ -14,12 +20,7 @@ type ReadPageContentsArgs = {
|
|
|
14
20
|
pagesAcc: Record<string, DecoratedNavigationPage>;
|
|
15
21
|
};
|
|
16
22
|
export declare const readPageContents: ({ contentDirectoryPath, openApiFiles, asyncApiFiles, contentFilenames, pagesAcc, }: ReadPageContentsArgs) => Promise<{
|
|
17
|
-
mdxFilesWithNoImports:
|
|
18
|
-
targetPath: string;
|
|
19
|
-
sourcePath: string;
|
|
20
|
-
tree: Root;
|
|
21
|
-
metadata: DecoratedNavigationPage;
|
|
22
|
-
}[];
|
|
23
|
+
mdxFilesWithNoImports: RssCandidatePage[];
|
|
23
24
|
pagesAcc: Record<string, DecoratedNavigationPage>;
|
|
24
25
|
filesWithImports: FileWithImportsAndMetadata[];
|
|
25
26
|
}>;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import { hasImports, findAndRemoveImports, getDecoratedNavPageAndSlug, parseFrontmatter, replaceVariables, } from '@mintlify/common';
|
|
1
|
+
import { containsUpdates, hasImports, findAndRemoveImports, getDecoratedNavPageAndSlug, parseFrontmatter, replaceVariables, stringifyTree, } from '@mintlify/common';
|
|
2
2
|
import { promises as _promises } from 'fs';
|
|
3
|
+
import { outputFile } from 'fs-extra';
|
|
3
4
|
import { join } from 'path';
|
|
4
5
|
import { preparseMdxTree } from '../../../createPage/preparseMdx/index.js';
|
|
5
6
|
import { preserveAutoGeneratedMetadata } from '../preserveAutoGeneratedMetadata.js';
|
|
6
7
|
const { readFile } = _promises;
|
|
8
|
+
const PAGE_PARSE_CONCURRENCY = 8;
|
|
7
9
|
export const readPageContents = async ({ contentDirectoryPath, openApiFiles, asyncApiFiles, contentFilenames, pagesAcc, }) => {
|
|
8
10
|
const filesWithImports = [];
|
|
9
|
-
const
|
|
11
|
+
const mdxFilesWithNoImports = [];
|
|
12
|
+
const remainingFilenames = [...contentFilenames];
|
|
13
|
+
const processFile = async (filename) => {
|
|
10
14
|
const sourcePath = join(contentDirectoryPath, filename);
|
|
11
15
|
const targetPath = join('src', '_props', filename);
|
|
16
|
+
let treeToWrite;
|
|
12
17
|
try {
|
|
13
18
|
const contentStr = (await readFile(sourcePath)).toString();
|
|
14
19
|
const tree = await preparseMdxTree(contentStr, contentDirectoryPath, sourcePath);
|
|
@@ -29,15 +34,33 @@ export const readPageContents = async ({ contentDirectoryPath, openApiFiles, asy
|
|
|
29
34
|
}
|
|
30
35
|
const { slug, pageMetadata } = getDecoratedNavPageAndSlug(filename, contentStr, openApiFiles, asyncApiFiles);
|
|
31
36
|
preserveAutoGeneratedMetadata(contentStr, slug, pageMetadata, pagesAcc);
|
|
32
|
-
|
|
37
|
+
// Only RSS candidates are needed by later phases (writeRssFiles). All
|
|
38
|
+
// other import-free pages are written and dropped immediately so peak
|
|
39
|
+
// memory does not grow with the number of pages.
|
|
40
|
+
if (pageMetadata.rss === true || containsUpdates(tree)) {
|
|
41
|
+
mdxFilesWithNoImports.push({ targetPath, sourcePath, tree, metadata: pageMetadata });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
treeToWrite = tree;
|
|
33
45
|
}
|
|
34
46
|
catch (error) {
|
|
35
47
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred reading and parsing file.';
|
|
36
48
|
console.error(`${sourcePath}: ${errorMessage}`);
|
|
37
49
|
throw new Error('Failed to parse MDX files, please correct errors before continuing');
|
|
38
50
|
}
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
await outputFile(targetPath, stringifyTree(treeToWrite), {
|
|
52
|
+
flag: 'w',
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const processFilesUntilDone = async () => {
|
|
56
|
+
let filename = remainingFilenames.shift();
|
|
57
|
+
while (filename !== undefined) {
|
|
58
|
+
await processFile(filename);
|
|
59
|
+
filename = remainingFilenames.shift();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const workerCount = Math.min(PAGE_PARSE_CONCURRENCY, remainingFilenames.length);
|
|
63
|
+
await Promise.all(Array.from({ length: workerCount }, processFilesUntilDone));
|
|
41
64
|
return { mdxFilesWithNoImports, pagesAcc, filesWithImports };
|
|
42
65
|
};
|
|
43
66
|
export const readSnippetsV2Contents = (contentDirectoryPath, snippetV2Filenames, variables) => {
|