@mintlify/prebuild 1.0.783 → 1.0.784
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.
|
@@ -1,34 +1,48 @@
|
|
|
1
|
-
import { openApiCheck } from '@mintlify/common';
|
|
2
|
-
import { validateAsyncApi } from '@mintlify/common';
|
|
1
|
+
import { openApiCheck, validateAsyncApi, buildImportMap, getFileCategory, isSnippetExtension, getAST, } from '@mintlify/common';
|
|
3
2
|
import { readFile } from 'fs/promises';
|
|
4
3
|
import yaml from 'js-yaml';
|
|
5
4
|
import * as path from 'path';
|
|
6
5
|
import { getFileList } from '../fs/index.js';
|
|
7
6
|
import { getFileExtension } from '../utils.js';
|
|
8
7
|
export const categorizeFilePaths = async (contentDirectoryPath, mintIgnore = [], disableOpenApi) => {
|
|
9
|
-
const
|
|
8
|
+
const allFiles = getFileList(contentDirectoryPath, contentDirectoryPath, mintIgnore);
|
|
9
|
+
const mdxFiles = [];
|
|
10
|
+
const nonMdxFiles = [];
|
|
11
|
+
for await (const filename of allFiles) {
|
|
12
|
+
const extension = getFileExtension(filename);
|
|
13
|
+
if (isSnippetExtension(extension)) {
|
|
14
|
+
const filePath = path.join(contentDirectoryPath, filename);
|
|
15
|
+
const content = await readFile(filePath, 'utf8');
|
|
16
|
+
const tree = getAST(content, filePath);
|
|
17
|
+
mdxFiles.push({ path: filename, tree });
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
nonMdxFiles.push({ filename, extension });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const { importedFiles, fileImportsMap } = buildImportMap(mdxFiles);
|
|
10
24
|
const contentFilenames = [];
|
|
25
|
+
const snippets = [];
|
|
26
|
+
const snippetsV2 = [];
|
|
27
|
+
for (const file of mdxFiles) {
|
|
28
|
+
const category = getFileCategory(file.path, { importedFiles });
|
|
29
|
+
switch (category) {
|
|
30
|
+
case 'snippet':
|
|
31
|
+
snippets.push(file.path);
|
|
32
|
+
break;
|
|
33
|
+
case 'snippet-v2':
|
|
34
|
+
snippetsV2.push(file.path);
|
|
35
|
+
break;
|
|
36
|
+
case 'page':
|
|
37
|
+
contentFilenames.push(file.path);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
11
41
|
const staticFilenames = [];
|
|
12
42
|
const openApiFiles = [];
|
|
13
43
|
const asyncApiFiles = [];
|
|
14
|
-
const
|
|
15
|
-
const snippetsV2 = [];
|
|
16
|
-
for await (const filename of allFilesInCmdExecutionPath) {
|
|
17
|
-
const extension = getFileExtension(filename);
|
|
44
|
+
for (const { filename, extension } of nonMdxFiles) {
|
|
18
45
|
switch (extension) {
|
|
19
|
-
case 'mdx':
|
|
20
|
-
case 'md':
|
|
21
|
-
case 'jsx':
|
|
22
|
-
if (filename.startsWith('/_snippets/')) {
|
|
23
|
-
snippets.push(filename);
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
if (filename.startsWith('/snippets/')) {
|
|
27
|
-
snippetsV2.push(filename);
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
contentFilenames.push(filename);
|
|
31
|
-
break;
|
|
32
46
|
case 'json':
|
|
33
47
|
case 'yaml':
|
|
34
48
|
case 'yml':
|
|
@@ -71,5 +85,13 @@ export const categorizeFilePaths = async (contentDirectoryPath, mintIgnore = [],
|
|
|
71
85
|
staticFilenames.push(filename);
|
|
72
86
|
}
|
|
73
87
|
}
|
|
74
|
-
return {
|
|
88
|
+
return {
|
|
89
|
+
contentFilenames,
|
|
90
|
+
staticFilenames,
|
|
91
|
+
openApiFiles,
|
|
92
|
+
asyncApiFiles,
|
|
93
|
+
snippets,
|
|
94
|
+
snippetsV2,
|
|
95
|
+
fileImportsMap,
|
|
96
|
+
};
|
|
75
97
|
};
|
package/dist/prebuild/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
export interface PrebuildResult {
|
|
2
|
+
fileImportsMap: Map<string, Set<string>>;
|
|
3
|
+
}
|
|
1
4
|
export declare const prebuild: (contentDirectoryPath: string, { localSchema, groups, disableOpenApi, }?: {
|
|
2
5
|
localSchema?: boolean;
|
|
3
6
|
groups?: string[];
|
|
4
7
|
disableOpenApi?: boolean;
|
|
5
|
-
}) => Promise<
|
|
8
|
+
}) => Promise<PrebuildResult | undefined>;
|
|
6
9
|
export * from './categorizeFilePaths.js';
|
|
7
10
|
export * from '../createPage/index.js';
|
|
8
11
|
export * from '../createPage/preparseMdx/index.js';
|
package/dist/prebuild/index.js
CHANGED
|
@@ -12,7 +12,7 @@ export const prebuild = async (contentDirectoryPath, { localSchema, groups, disa
|
|
|
12
12
|
throw Error('must be run in a directory where a docs.json file exists.');
|
|
13
13
|
}
|
|
14
14
|
const mintIgnore = await getMintIgnore(contentDirectoryPath);
|
|
15
|
-
const { contentFilenames, staticFilenames, openApiFiles, asyncApiFiles, snippets, snippetsV2 } = await categorizeFilePaths(contentDirectoryPath, mintIgnore, disableOpenApi);
|
|
15
|
+
const { contentFilenames, staticFilenames, openApiFiles, asyncApiFiles, snippets, snippetsV2, fileImportsMap, } = await categorizeFilePaths(contentDirectoryPath, mintIgnore, disableOpenApi);
|
|
16
16
|
await update({
|
|
17
17
|
contentDirectoryPath,
|
|
18
18
|
staticFilenames,
|
|
@@ -27,6 +27,7 @@ export const prebuild = async (contentDirectoryPath, { localSchema, groups, disa
|
|
|
27
27
|
mintIgnore,
|
|
28
28
|
disableOpenApi,
|
|
29
29
|
});
|
|
30
|
+
return { fileImportsMap };
|
|
30
31
|
};
|
|
31
32
|
export * from './categorizeFilePaths.js';
|
|
32
33
|
export * from '../createPage/index.js';
|