@mintlify/prebuild 1.0.472 → 1.0.474

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 +1,2 @@
1
1
  export declare const preparseMdx: (fileContent: string, contentDirectoryPath: string, filePath: string, suppressErrLog?: boolean) => Promise<string>;
2
+ export declare const preparseMdxTree: (fileContent: string, contentDirectoryPath: string, filePath: string, suppressErrLog?: boolean) => Promise<import("mdast").Root>;
@@ -1,4 +1,4 @@
1
- import { coreRemark } from '@mintlify/common';
1
+ import { coreRemark, getAST } from '@mintlify/common';
2
2
  import { formatError } from '../../errorMessages/formatError.js';
3
3
  export const preparseMdx = async (fileContent, contentDirectoryPath, filePath, suppressErrLog = false) => {
4
4
  try {
@@ -11,3 +11,14 @@ export const preparseMdx = async (fileContent, contentDirectoryPath, filePath, s
11
11
  return `🚧 A parsing error occured. Please contact the owner of this website.`;
12
12
  }
13
13
  };
14
+ export const preparseMdxTree = async (fileContent, contentDirectoryPath, filePath, suppressErrLog = false) => {
15
+ try {
16
+ return getAST(fileContent);
17
+ }
18
+ catch (error) {
19
+ if (!suppressErrLog) {
20
+ console.error(formatError(error, filePath, contentDirectoryPath));
21
+ }
22
+ return getAST(`🚧 A parsing error occured. Please contact the owner of this website.`);
23
+ }
24
+ };
@@ -1,5 +1,6 @@
1
1
  import { AsyncAPIFile } from '@mintlify/common';
2
2
  import type { OpenApiFile } from '@mintlify/models';
3
+ import { Root } from 'mdast';
3
4
  type UpdateArgs = {
4
5
  contentDirectoryPath: string;
5
6
  staticFilenames: string[];
@@ -1951,7 +1952,7 @@ export declare const update: ({ contentDirectoryPath, staticFilenames, openApiFi
1951
1952
  }>;
1952
1953
  export declare const writeMdxFilesWithNoImports: (mdxFilesWithNoImports: {
1953
1954
  targetPath: string;
1954
- fileContent: string;
1955
+ tree: Root;
1955
1956
  }[]) => Promise<void>[];
1956
1957
  export * from './mintConfig/index.js';
1957
1958
  export * from './docsConfig/index.js';
@@ -1,3 +1,4 @@
1
+ import { stringifyTree } from '@mintlify/common';
1
2
  import { upgradeToDocsConfig } from '@mintlify/validation';
2
3
  import { outputFile } from 'fs-extra';
3
4
  import { updateDocsConfigFile } from './docsConfig/index.js';
@@ -49,8 +50,8 @@ export const update = async ({ contentDirectoryPath, staticFilenames, openApiFil
49
50
  };
50
51
  export const writeMdxFilesWithNoImports = (mdxFilesWithNoImports) => {
51
52
  return mdxFilesWithNoImports.map(async (response) => {
52
- const { targetPath, fileContent } = response;
53
- await outputFile(targetPath, fileContent, {
53
+ const { targetPath, tree } = response;
54
+ await outputFile(targetPath, stringifyTree(tree), {
54
55
  flag: 'w',
55
56
  });
56
57
  });
@@ -1,6 +1,7 @@
1
1
  import type { FileWithImports } from '@mintlify/common';
2
2
  import { AsyncAPIFile } from '@mintlify/common';
3
3
  import type { OpenApiFile, DecoratedNavigationPage } from '@mintlify/models';
4
+ import { Root } from 'mdast';
4
5
  type ReadPageContentsArgs = {
5
6
  contentDirectoryPath: string;
6
7
  openApiFiles: OpenApiFile[];
@@ -11,13 +12,13 @@ type ReadPageContentsArgs = {
11
12
  export declare const readPageContents: ({ contentDirectoryPath, openApiFiles, asyncApiFiles, contentFilenames, pagesAcc, }: ReadPageContentsArgs) => Promise<{
12
13
  mdxFilesWithNoImports: {
13
14
  targetPath: string;
14
- fileContent: string;
15
+ tree: Root;
15
16
  }[];
16
17
  pagesAcc: Record<string, DecoratedNavigationPage>;
17
18
  filesWithImports: FileWithImports[];
18
19
  }>;
19
20
  export declare const readSnippetsV2Contents: (contentDirectoryPath: string, snippetV2Filenames: string[]) => Promise<{
20
21
  filename: string;
21
- content: string;
22
+ tree: Root;
22
23
  }[]>;
23
24
  export {};
@@ -1,7 +1,7 @@
1
1
  import { hasImports, findAndRemoveImports, getDecoratedNavPageAndSlug } from '@mintlify/common';
2
2
  import { promises as _promises } from 'fs';
3
3
  import { join } from 'path';
4
- import { preparseMdx } from '../../../createPage/preparseMdx/index.js';
4
+ import { preparseMdxTree } from '../../../createPage/preparseMdx/index.js';
5
5
  const { readFile } = _promises;
6
6
  export const readPageContents = async ({ contentDirectoryPath, openApiFiles, asyncApiFiles, contentFilenames, pagesAcc, }) => {
7
7
  const filesWithImports = [];
@@ -11,8 +11,8 @@ export const readPageContents = async ({ contentDirectoryPath, openApiFiles, asy
11
11
  try {
12
12
  const contentStr = (await readFile(sourcePath)).toString();
13
13
  // if is snippet add to static file array
14
- const fileContent = await preparseMdx(contentStr, contentDirectoryPath, sourcePath);
15
- const importsResponse = await findAndRemoveImports(fileContent);
14
+ const tree = await preparseMdxTree(contentStr, contentDirectoryPath, sourcePath);
15
+ const importsResponse = await findAndRemoveImports(tree);
16
16
  if (hasImports(importsResponse)) {
17
17
  filesWithImports.push({
18
18
  ...importsResponse,
@@ -22,7 +22,7 @@ export const readPageContents = async ({ contentDirectoryPath, openApiFiles, asy
22
22
  }
23
23
  const { slug, pageMetadata } = getDecoratedNavPageAndSlug(filename, contentStr, openApiFiles, asyncApiFiles);
24
24
  pagesAcc[slug] = pageMetadata;
25
- return { targetPath, fileContent };
25
+ return { targetPath, tree };
26
26
  }
27
27
  catch (error) {
28
28
  const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred reading and parsing file.';
@@ -37,8 +37,8 @@ export const readSnippetsV2Contents = (contentDirectoryPath, snippetV2Filenames)
37
37
  const snippetV2Promises = snippetV2Filenames.map(async (filename) => {
38
38
  const sourcePath = join(contentDirectoryPath, filename);
39
39
  const contentStr = await readFile(sourcePath, 'utf8');
40
- const fileContent = await preparseMdx(contentStr, contentDirectoryPath, sourcePath);
41
- return { filename, content: fileContent };
40
+ const tree = await preparseMdxTree(contentStr, contentDirectoryPath, sourcePath);
41
+ return { filename, tree };
42
42
  });
43
43
  return Promise.all(snippetV2Promises);
44
44
  };
@@ -1,4 +1,4 @@
1
- import { resolveAllImports, hasImports, findAndRemoveImports, getDecoratedNavPageAndSlug, topologicalSort, } from '@mintlify/common';
1
+ import { resolveAllImports, hasImports, findAndRemoveImports, getDecoratedNavPageAndSlug, topologicalSort, stringifyTree, } from '@mintlify/common';
2
2
  import { outputFile } from 'fs-extra';
3
3
  import { join } from 'path';
4
4
  export const resolveImportsAndWriteFiles = async ({ openApiFiles, asyncApiFiles, pagesAcc, snippetsV2, filesWithImports, }) => {
@@ -16,7 +16,7 @@ export const resolveImportsAndWriteFiles = async ({ openApiFiles, asyncApiFiles,
16
16
  };
17
17
  const resolveImportsInSnippets = async (snippetsV2) => {
18
18
  const snippetsWithImportsPromises = snippetsV2.map(async (snippet) => ({
19
- ...(await findAndRemoveImports(snippet.content)),
19
+ ...(await findAndRemoveImports(snippet.tree)),
20
20
  filename: snippet.filename,
21
21
  }));
22
22
  const snippetsWithImports = await Promise.all(snippetsWithImportsPromises);
@@ -32,7 +32,7 @@ const resolveImportsInSnippets = async (snippetsV2) => {
32
32
  .filter(Boolean);
33
33
  for (const snippetWithImports of orderedSnippetsWithImports) {
34
34
  if (hasImports(snippetWithImports)) {
35
- snippetWithImports.content = await resolveAllImports({
35
+ snippetWithImports.tree = await resolveAllImports({
36
36
  snippets: orderedSnippetsWithImports,
37
37
  fileWithImports: snippetWithImports,
38
38
  });
@@ -42,28 +42,29 @@ const resolveImportsInSnippets = async (snippetsV2) => {
42
42
  };
43
43
  const writeSnippets = async (snippetsWithImports) => snippetsWithImports.map(async (snippetWithImports) => {
44
44
  const targetPath = join('public', snippetWithImports.filename);
45
- await outputFile(targetPath, snippetWithImports.content, {
45
+ await outputFile(targetPath, stringifyTree(snippetWithImports.tree), {
46
46
  flag: 'w',
47
47
  });
48
48
  });
49
49
  const resolveImportsInPages = async ({ openApiFiles, asyncApiFiles, snippetsWithResolvedImports, filesWithImports, pagesAcc, }) => {
50
50
  const filesWithResolvedImportsPromises = filesWithImports.map(async (fileWithImports) => {
51
- const content = await resolveAllImports({
51
+ const tree = await resolveAllImports({
52
52
  snippets: snippetsWithResolvedImports,
53
53
  fileWithImports,
54
54
  });
55
- const { slug, pageMetadata } = getDecoratedNavPageAndSlug(fileWithImports.filename, content, openApiFiles, asyncApiFiles);
55
+ const contentStr = stringifyTree(tree);
56
+ const { slug, pageMetadata } = getDecoratedNavPageAndSlug(fileWithImports.filename, contentStr, openApiFiles, asyncApiFiles);
56
57
  pagesAcc[slug] = pageMetadata;
57
58
  const targetPath = join('src', '_props', fileWithImports.filename);
58
59
  return {
59
60
  targetPath,
60
- content,
61
+ tree,
61
62
  };
62
63
  });
63
64
  return await Promise.all(filesWithResolvedImportsPromises);
64
65
  };
65
- const writePages = (filesWithResolvedImports) => filesWithResolvedImports.map(async ({ targetPath, content }) => {
66
- await outputFile(targetPath, content, {
66
+ const writePages = (filesWithResolvedImports) => filesWithResolvedImports.map(async ({ targetPath, tree }) => {
67
+ await outputFile(targetPath, stringifyTree(tree), {
67
68
  flag: 'w',
68
69
  });
69
70
  });