@mintlify/prebuild 1.0.797 → 1.0.799

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
  }