@mintlify/prebuild 1.0.798 → 1.0.800

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,6 +1,6 @@
1
1
  import { AsyncAPIFile } from '@mintlify/common';
2
2
  import { OpenApiFile, DecoratedNavigationPage } from '@mintlify/models';
3
- export declare const createPage: (pagePath: string, pageContent: string, contentDirectoryPath: string, openApiFiles: OpenApiFile[], asyncApiFiles: AsyncAPIFile[], suppressErrLog?: boolean) => Promise<{
3
+ export declare const createPage: (pagePath: string, pageContent: string, contentDirectoryPath: string, openApiFiles: OpenApiFile[], asyncApiFiles: AsyncAPIFile[], onError?: (message: string) => void) => Promise<{
4
4
  pageMetadata: DecoratedNavigationPage;
5
5
  pageContent: string;
6
6
  slug: string;
@@ -1,17 +1,23 @@
1
1
  import { getDecoratedNavPageAndSlug } from '@mintlify/common';
2
2
  import { getLocationErrString } from '../errorMessages/getLocationErrString.js';
3
3
  import { preparseMdx } from './preparseMdx/index.js';
4
- export const createPage = async (pagePath, pageContent, contentDirectoryPath, openApiFiles, asyncApiFiles, suppressErrLog = false) => {
4
+ export const createPage = async (pagePath, pageContent, contentDirectoryPath, openApiFiles, asyncApiFiles, onError) => {
5
5
  let pageMetadata;
6
6
  let slug;
7
7
  try {
8
8
  const { pageMetadata: metadata, slug: pageSlug } = getDecoratedNavPageAndSlug(pagePath, pageContent, openApiFiles, asyncApiFiles);
9
9
  pageMetadata = metadata;
10
10
  slug = pageSlug;
11
- pageContent = await preparseMdx(pageContent, contentDirectoryPath, pagePath, suppressErrLog);
11
+ pageContent = await preparseMdx(pageContent, contentDirectoryPath, pagePath, onError);
12
12
  }
13
13
  catch (err) {
14
- console.log(`\n ⚠️ Parsing error in the frontmatter: ${getLocationErrString(pagePath, contentDirectoryPath, err)}: `);
14
+ const message = `\n ⚠️ Parsing error in the frontmatter: ${getLocationErrString(pagePath, contentDirectoryPath, err)}: `;
15
+ if (onError) {
16
+ onError(message);
17
+ }
18
+ else {
19
+ console.log(message);
20
+ }
15
21
  // TODO - pages completely break in our backend when frontmatter is broken.
16
22
  // Unify "createPage" function across applications and properly catch errors
17
23
  throw err;
@@ -1,2 +1,4 @@
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
+ import { formatError } from '../../errorMessages/formatError.js';
2
+ export { formatError };
3
+ export declare const preparseMdx: (fileContent: string, contentDirectoryPath: string, filePath: string, onError?: (message: string) => void) => Promise<string>;
4
+ export declare const preparseMdxTree: (fileContent: string, contentDirectoryPath: string, filePath: string, onError?: (message: string) => void) => Promise<import("mdast").Root>;
@@ -1,23 +1,32 @@
1
1
  import { coreRemark, getAST } from '@mintlify/common';
2
2
  import { formatError } from '../../errorMessages/formatError.js';
3
- export const preparseMdx = async (fileContent, contentDirectoryPath, filePath, suppressErrLog = false) => {
3
+ export { formatError };
4
+ export const preparseMdx = async (fileContent, contentDirectoryPath, filePath, onError) => {
4
5
  try {
5
6
  return String(await coreRemark().process(fileContent));
6
7
  }
7
8
  catch (error) {
8
- if (!suppressErrLog) {
9
- console.log(formatError(error, filePath, contentDirectoryPath));
9
+ const message = formatError(error, filePath, contentDirectoryPath);
10
+ if (onError) {
11
+ onError(message);
12
+ }
13
+ else {
14
+ console.log(message);
10
15
  }
11
16
  return `🚧 A parsing error occured. Please contact the owner of this website.`;
12
17
  }
13
18
  };
14
- export const preparseMdxTree = async (fileContent, contentDirectoryPath, filePath, suppressErrLog = false) => {
19
+ export const preparseMdxTree = async (fileContent, contentDirectoryPath, filePath, onError) => {
15
20
  try {
16
21
  return getAST(fileContent, filePath);
17
22
  }
18
23
  catch (error) {
19
- if (!suppressErrLog) {
20
- console.error(formatError(error, filePath, contentDirectoryPath));
24
+ const message = formatError(error, filePath, contentDirectoryPath);
25
+ if (onError) {
26
+ onError(message);
27
+ }
28
+ else {
29
+ console.error(message);
21
30
  }
22
31
  return getAST(`🚧 A parsing error occured. Please contact the owner of this website.`);
23
32
  }
@@ -3,8 +3,8 @@ export declare class ConfigUpdater<T> {
3
3
  private type;
4
4
  constructor(type: ConfigType);
5
5
  getConfigType(): "mint" | "docs";
6
- getConfig(configPath: string): Promise<T>;
7
- validateConfigJsonString: (configContents: string) => Promise<{
6
+ getConfig(configPath: string, onError?: (message: string) => void): Promise<T>;
7
+ validateConfigJsonString: (configContents: string, onError?: (message: string) => void) => Promise<{
8
8
  data: T;
9
9
  warnings: import("zod").ZodIssue[];
10
10
  success: true;
@@ -6,18 +6,32 @@ import { join } from 'path';
6
6
  const { readFile } = _promises;
7
7
  export class ConfigUpdater {
8
8
  constructor(type) {
9
- this.validateConfigJsonString = async (configContents) => {
10
- const configObj = this.parseConfigJson(configContents);
9
+ this.validateConfigJsonString = async (configContents, onError) => {
10
+ const configObj = this.parseConfigJson(configContents, onError);
11
11
  const validationResults = this.type === 'mint' ? validateMintConfig(configObj) : validateDocsConfig(configObj);
12
12
  if (!validationResults.success) {
13
- console.error(Chalk.red(`🚨 Invalid ${this.type}.json:`));
14
- validationResults.error.issues.forEach((issue) => console.error(Chalk.red(formatIssue(issue))));
13
+ const errorMsg = `🚨 Invalid ${this.type}.json:`;
14
+ const issues = validationResults.error.issues.map((issue) => formatIssue(issue));
15
+ if (onError) {
16
+ onError(errorMsg);
17
+ issues.forEach((issue) => onError(issue));
18
+ }
19
+ else {
20
+ console.error(Chalk.red(errorMsg));
21
+ issues.forEach((issue) => console.error(Chalk.red(issue)));
22
+ }
15
23
  throw Error();
16
24
  }
17
- if (validationResults.warnings.length > 0) {
18
- if (validationResults.warnings.length > 0) {
19
- console.warn(Chalk.yellow(`⚠️ Warnings found in ${this.type}.json:`));
20
- validationResults.warnings.forEach((issue) => console.warn(Chalk.yellow(formatIssue(issue))));
25
+ if ('warnings' in validationResults && validationResults.warnings.length > 0) {
26
+ const warnMsg = `⚠️ Warnings found in ${this.type}.json:`;
27
+ const warnings = validationResults.warnings.map((issue) => formatIssue(issue));
28
+ if (onError) {
29
+ onError(warnMsg);
30
+ warnings.forEach((warning) => onError(warning));
31
+ }
32
+ else {
33
+ console.warn(Chalk.yellow(warnMsg));
34
+ warnings.forEach((warning) => console.warn(Chalk.yellow(warning)));
21
35
  }
22
36
  }
23
37
  return { ...validationResults, data: validationResults.data };
@@ -42,7 +56,7 @@ export class ConfigUpdater {
42
56
  throw Error(`Unable to write ${this.type}.json: ${err}`);
43
57
  }
44
58
  };
45
- this.parseConfigJson = (configContents) => {
59
+ this.parseConfigJson = (configContents, onError) => {
46
60
  let configObj;
47
61
  try {
48
62
  configObj = JSON.parse(configContents);
@@ -50,10 +64,22 @@ export class ConfigUpdater {
50
64
  catch (e) {
51
65
  if (typeof e === 'object' && e != null) {
52
66
  if ('name' in e && e.name === 'SyntaxError') {
53
- console.error(`🚨 ${Chalk.red(`${this.type}.json has invalid JSON. You are likely missing a comma or a bracket. You can paste your ${this.type}.json file into https://jsonlint.com/ to get a more specific error message.`)}`);
67
+ const msg = `🚨 ${this.type}.json has invalid JSON. You are likely missing a comma or a bracket. You can paste your ${this.type}.json file into https://jsonlint.com/ to get a more specific error message.`;
68
+ if (onError) {
69
+ onError(msg);
70
+ }
71
+ else {
72
+ console.error(Chalk.red(msg));
73
+ }
54
74
  }
55
75
  else if ('message' in e) {
56
- console.error(`🚨 ${Chalk.red(e.message)}`);
76
+ const msg = `🚨 ${e.message}`;
77
+ if (onError) {
78
+ onError(msg);
79
+ }
80
+ else {
81
+ console.error(Chalk.red(msg));
82
+ }
57
83
  }
58
84
  }
59
85
  throw Error();
@@ -65,9 +91,9 @@ export class ConfigUpdater {
65
91
  getConfigType() {
66
92
  return this.type;
67
93
  }
68
- async getConfig(configPath) {
94
+ async getConfig(configPath, onError) {
69
95
  const configContents = await this.readConfigFile(configPath);
70
- const validationResults = await this.validateConfigJsonString(configContents);
96
+ const validationResults = await this.validateConfigJsonString(configContents, onError);
71
97
  return validationResults.data;
72
98
  }
73
99
  }
@@ -82,31 +82,41 @@ export const generateOpenApiFromDocsConfig = async (navigation, openApiFiles, pa
82
82
  if ('openapi' in nav && nav.openapi !== null) {
83
83
  const openapiProp = nav.openapi;
84
84
  if (typeof openapiProp === 'string') {
85
- return openapiProp;
85
+ return { source: openapiProp, directory: undefined };
86
86
  }
87
87
  else if (Array.isArray(openapiProp) && openapiProp.length > 0) {
88
- return openapiProp[0];
88
+ return { source: openapiProp[0], directory: undefined };
89
89
  }
90
90
  else if (typeof openapiProp === 'object' &&
91
91
  'source' in openapiProp &&
92
92
  typeof openapiProp.source === 'string') {
93
- return openapiProp.source;
93
+ const directory = 'directory' in openapiProp && typeof openapiProp.directory === 'string'
94
+ ? openapiProp.directory
95
+ : undefined;
96
+ return {
97
+ source: openapiProp.source,
98
+ directory,
99
+ };
94
100
  }
95
101
  }
96
- return undefined;
102
+ return { source: undefined, directory: undefined };
97
103
  }
98
104
  const skipBulkForNode = new Set();
99
105
  const skipBulkForNodeId = new Set();
100
106
  let numNodes = 0;
101
- async function processNav(nav, inheritedOpenApi, openApiOwner) {
107
+ async function processNav(nav, inheritedOpenApi, inheritedDirectory, openApiOwner) {
102
108
  const nodeId = numNodes++;
103
- const currentOpenApi = extractOpenApiFromNav(nav) ?? inheritedOpenApi;
104
- const currentOpenApiOwner = extractOpenApiFromNav(nav) ? nodeId : openApiOwner;
109
+ const extracted = extractOpenApiFromNav(nav);
110
+ const currentOpenApi = extracted.source ?? inheritedOpenApi;
111
+ const currentDirectory = extracted.source
112
+ ? extracted.directory
113
+ : extracted.directory ?? inheritedDirectory;
114
+ const currentOpenApiOwner = extracted.source ? nodeId : openApiOwner;
105
115
  let newNav = nav;
106
116
  if ('pages' in newNav) {
107
117
  newNav.pages = await Promise.all(newNav.pages.map(async (page) => {
108
118
  if (typeof page === 'object' && page !== null && 'group' in page) {
109
- return processNav(page, currentOpenApi, currentOpenApiOwner);
119
+ return processNav(page, currentOpenApi, currentDirectory, currentOpenApiOwner);
110
120
  }
111
121
  if (typeof page !== 'string') {
112
122
  return page;
@@ -152,7 +162,7 @@ export const generateOpenApiFromDocsConfig = async (navigation, openApiFiles, pa
152
162
  processOpenApiWebhook(endpoint, webhookObject, schema, tempNav, tempDecoratedNav, writePromises, pagesAcc, {
153
163
  openApiFilePath: openApiFile.originalFileLocation,
154
164
  writeFiles,
155
- outDir: DEFAULT_OUTPUT_DIR,
165
+ outDir: currentDirectory ?? DEFAULT_OUTPUT_DIR,
156
166
  outDirBasePath: path.join(targetDir ?? '', 'src', '_props'),
157
167
  overwrite,
158
168
  localSchema,
@@ -170,7 +180,7 @@ export const generateOpenApiFromDocsConfig = async (navigation, openApiFiles, pa
170
180
  processOpenApiPath(endpoint, { [method.toLowerCase()]: opObject }, schema, tempNav, tempDecoratedNav, writePromises, pagesAcc, {
171
181
  openApiFilePath: openApiFile.originalFileLocation,
172
182
  writeFiles,
173
- outDir: DEFAULT_OUTPUT_DIR,
183
+ outDir: currentDirectory ?? DEFAULT_OUTPUT_DIR,
174
184
  outDirBasePath: path.join(targetDir ?? '', 'src', '_props'),
175
185
  overwrite,
176
186
  localSchema,
@@ -209,7 +219,7 @@ export const generateOpenApiFromDocsConfig = async (navigation, openApiFiles, pa
209
219
  const items = newNav[division];
210
220
  newNav = {
211
221
  ...newNav,
212
- [division]: await Promise.all(items.map((item) => processNav(item, currentOpenApi, currentOpenApiOwner))),
222
+ [division]: await Promise.all(items.map((item) => processNav(item, currentOpenApi, currentDirectory, currentOpenApiOwner))),
213
223
  };
214
224
  }
215
225
  }
@@ -218,10 +228,10 @@ export const generateOpenApiFromDocsConfig = async (navigation, openApiFiles, pa
218
228
  }
219
229
  return newNav;
220
230
  }
221
- const navAfterExplicit = await processNav(navigation, undefined);
231
+ const navAfterExplicit = await processNav(navigation, undefined, undefined, undefined);
222
232
  async function generateBulkNav(node) {
223
233
  let updated = node;
224
- if (extractOpenApiFromNav(updated) && !skipBulkForNode.has(updated)) {
234
+ if (extractOpenApiFromNav(updated).source && !skipBulkForNode.has(updated)) {
225
235
  const processed = await processOpenApiInNav(updated);
226
236
  if (processed)
227
237
  updated = processed;