@mintlify/previewing 4.0.173 → 4.0.175

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
- export declare const generateNav: () => Promise<import("@mintlify/models").DecoratedNavigation>;
1
+ import type { DecoratedNavigationPage } from '@mintlify/models';
2
+ export declare const generateNav: (pagesAcc?: Record<string, DecoratedNavigationPage>) => Promise<import("@mintlify/models").DecoratedNavigation>;
@@ -9,35 +9,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { generateDecoratedMintNavigationFromPages, getConfigObj, categorizeFilePaths, createPage, } from '@mintlify/prebuild';
11
11
  import { promises as _promises } from 'fs';
12
- import { outputFile } from 'fs-extra';
13
12
  import { join } from 'path';
14
- import { CMD_EXEC_PATH } from '../../constants.js';
13
+ import { CMD_EXEC_PATH, NEXT_PROPS_PATH } from '../../constants.js';
15
14
  const { readFile } = _promises;
16
- const createFilenamePageMetadataMap = (contentDirectoryPath, contentFilenames, openApiFiles, clientPath, writeFiles = false) => __awaiter(void 0, void 0, void 0, function* () {
17
- let pagesAcc = {};
15
+ const createFilenamePageMetadataMap = (contentDirectoryPath, contentFilenames, openApiFiles, pagesAcc = {}) => __awaiter(void 0, void 0, void 0, function* () {
18
16
  const contentPromises = [];
19
17
  contentFilenames.forEach((filename) => {
20
18
  contentPromises.push((() => __awaiter(void 0, void 0, void 0, function* () {
21
19
  const sourcePath = join(contentDirectoryPath, filename);
22
20
  const contentStr = (yield readFile(sourcePath)).toString();
23
- const { slug, pageMetadata, pageContent } = yield createPage(filename, contentStr, contentDirectoryPath, openApiFiles, true);
24
- if (clientPath && writeFiles) {
25
- const targetPath = join(clientPath, 'src', '_props', filename);
26
- yield outputFile(targetPath, pageContent, {
27
- flag: 'w',
28
- });
29
- }
21
+ const { slug, pageMetadata } = yield createPage(filename, contentStr, contentDirectoryPath, openApiFiles, true);
30
22
  pagesAcc = Object.assign(Object.assign({}, pagesAcc), { [slug]: pageMetadata });
31
23
  }))());
32
24
  });
33
25
  yield Promise.all(contentPromises);
34
26
  return pagesAcc;
35
27
  });
36
- export const generateNav = () => __awaiter(void 0, void 0, void 0, function* () {
28
+ export const generateNav = (pagesAcc) => __awaiter(void 0, void 0, void 0, function* () {
37
29
  const { contentFilenames, openApiFiles } = yield categorizeFilePaths(CMD_EXEC_PATH);
38
30
  const [filenamePageMetadataMap, configObj] = yield Promise.all([
39
- createFilenamePageMetadataMap(CMD_EXEC_PATH, contentFilenames, openApiFiles),
40
- getConfigObj(CMD_EXEC_PATH),
31
+ createFilenamePageMetadataMap(CMD_EXEC_PATH, contentFilenames, openApiFiles, pagesAcc),
32
+ getConfigObj(NEXT_PROPS_PATH),
41
33
  ]);
42
34
  return generateDecoratedMintNavigationFromPages(filenamePageMetadataMap, configObj === null || configObj === void 0 ? void 0 : configObj.navigation);
43
35
  });
@@ -8,14 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { findAndRemoveImports, hasImports, getFileCategory, openApiCheck } from '@mintlify/common';
11
- import { createPage, preparseMdx } from '@mintlify/prebuild';
12
- import { formatIssue, validateMintConfig } from '@mintlify/validation';
11
+ import { createPage, preparseMdx, validateMintJson, generateOpenApiAnchorsOrTabs, writeMintConfigFile, categorizeFilePaths, } from '@mintlify/prebuild';
13
12
  import Chalk from 'chalk';
14
13
  import chokidar from 'chokidar';
15
14
  import { promises as _promises } from 'fs';
16
15
  import fse from 'fs-extra';
17
16
  import pathUtil from 'path';
18
- import { CMD_EXEC_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH } from '../../constants.js';
17
+ import { CMD_EXEC_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH, CLIENT_PATH } from '../../constants.js';
19
18
  import { generatePagesWithImports } from './generatePagesWithImports.js';
20
19
  import { resolveAllImports } from './resolveAllImports.js';
21
20
  import { updateGeneratedNav, updateOpenApiFiles } from './update.js';
@@ -169,6 +168,7 @@ const onUpdateEvent = (filename, callback) => __awaiter(void 0, void 0, void 0,
169
168
  const potentialCategory = getFileCategory(filename);
170
169
  const targetPath = getTargetPath(potentialCategory, filename);
171
170
  let regenerateNav = false;
171
+ let pagesAcc = {};
172
172
  let category = potentialCategory === 'potentialYamlOpenApiSpec' ||
173
173
  potentialCategory === 'potentialJsonOpenApiSpec'
174
174
  ? 'staticFile'
@@ -205,30 +205,17 @@ const onUpdateEvent = (filename, callback) => __awaiter(void 0, void 0, void 0,
205
205
  }
206
206
  case 'mintConfig':
207
207
  regenerateNav = true;
208
- const mintJsonFileContent = (yield readFile(filePath)).toString();
209
208
  try {
210
- const configObj = JSON.parse(mintJsonFileContent);
211
- const validationResults = validateMintConfig(configObj);
212
- if (validationResults.success) {
213
- if (validationResults.warnings.length > 0) {
214
- console.warn(Chalk.yellow('⚠️ Warnings found in mint.json:'));
215
- validationResults.warnings.forEach((issue) => console.warn(Chalk.yellow(formatIssue(issue))));
216
- }
217
- yield fse.copy(filePath, targetPath);
218
- }
219
- else {
220
- console.error(Chalk.red('🚨 Invalid mint.json:'));
221
- validationResults.error.issues.forEach((issue) => console.error(Chalk.red(formatIssue(issue))));
222
- }
209
+ const mintJsonFileContent = (yield readFile(filePath)).toString();
210
+ const validationResults = yield validateMintJson(mintJsonFileContent);
211
+ const { openApiFiles } = yield categorizeFilePaths(CMD_EXEC_PATH);
212
+ const { mintConfig, pagesAcc: pagesAccFromGeneratedPages, openApiFiles: newOpenApiFiles, } = yield generateOpenApiAnchorsOrTabs(validationResults.data, openApiFiles, CLIENT_PATH);
213
+ pagesAcc = pagesAccFromGeneratedPages;
214
+ yield writeMintConfigFile(mintConfig, CLIENT_PATH);
215
+ yield updateOpenApiFiles(newOpenApiFiles);
223
216
  }
224
- catch (e) {
225
- const error = e;
226
- if (error.name === 'SyntaxError') {
227
- console.error(`🚨 ${Chalk.red('mint.json has invalid JSON. You are likely missing a comma or a bracket. You can paste your mint.json file into https://jsonlint.com/ to get a more specific error message.')}`);
228
- }
229
- else {
230
- console.error(`🚨 ${Chalk.red(error.message)}`);
231
- }
217
+ catch (err) {
218
+ console.error(err);
232
219
  }
233
220
  break;
234
221
  case 'potentialYamlOpenApiSpec':
@@ -254,7 +241,7 @@ const onUpdateEvent = (filename, callback) => __awaiter(void 0, void 0, void 0,
254
241
  }
255
242
  if (regenerateNav) {
256
243
  // TODO: Instead of re-generating the entire nav, optimize by just updating the specific page that changed.
257
- yield updateGeneratedNav();
244
+ yield updateGeneratedNav(pagesAcc);
258
245
  }
259
246
  callback();
260
247
  return category;
@@ -1,2 +1,3 @@
1
- export declare const updateGeneratedNav: () => Promise<void>;
2
- export declare const updateOpenApiFiles: () => Promise<void>;
1
+ import { DecoratedNavigationPage, OpenApiFile } from '@mintlify/models';
2
+ export declare const updateGeneratedNav: (pagesAcc?: Record<string, DecoratedNavigationPage>) => Promise<void>;
3
+ export declare const updateOpenApiFiles: (providedOpenApiFiles?: OpenApiFile[]) => Promise<void>;
@@ -7,24 +7,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- // TODO: Add Types
11
10
  import { categorizeFilePaths } from '@mintlify/prebuild';
12
11
  import fse from 'fs-extra';
13
12
  import { join } from 'path';
14
13
  import { CLIENT_PATH, CMD_EXEC_PATH } from '../../constants.js';
15
14
  import { generateNav } from './generate.js';
16
- // TODO: Put in prebuild package
17
- export const updateGeneratedNav = () => __awaiter(void 0, void 0, void 0, function* () {
18
- const generatedNav = yield generateNav();
15
+ export const updateGeneratedNav = (pagesAcc) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const generatedNav = yield generateNav(pagesAcc);
19
17
  const targetPath = join(CLIENT_PATH, 'src', '_props', 'generatedNav.json');
20
18
  yield fse.outputFile(targetPath, JSON.stringify(generatedNav, null, 2), {
21
19
  flag: 'w',
22
20
  });
23
21
  });
24
- export const updateOpenApiFiles = () => __awaiter(void 0, void 0, void 0, function* () {
25
- const { openApiFiles } = yield categorizeFilePaths(CMD_EXEC_PATH);
22
+ export const updateOpenApiFiles = (providedOpenApiFiles) => __awaiter(void 0, void 0, void 0, function* () {
23
+ if (providedOpenApiFiles == undefined) {
24
+ const { openApiFiles } = yield categorizeFilePaths(CMD_EXEC_PATH);
25
+ providedOpenApiFiles = openApiFiles;
26
+ }
26
27
  const targetPath = join(CLIENT_PATH, 'src', '_props', 'openApiFiles.json');
27
- yield fse.outputFile(targetPath, JSON.stringify(openApiFiles, null, 2), {
28
+ yield fse.outputFile(targetPath, JSON.stringify(providedOpenApiFiles, null, 2), {
28
29
  flag: 'w',
29
30
  });
30
31
  });