@mintlify/previewing 4.0.328 → 4.0.329

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.
@@ -20,7 +20,7 @@ import { CMD_EXEC_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH, CLIENT_PATH } from '.
20
20
  import { generatePagesWithImports } from './generatePagesWithImports.js';
21
21
  import { getDocsState } from './getDocsState.js';
22
22
  import { resolveAllImports } from './resolveAllImports.js';
23
- import { updateGeneratedNav, updateOpenApiFiles } from './update.js';
23
+ import { updateGeneratedNav, updateOpenApiFiles, upsertOpenApiFile } from './update.js';
24
24
  import { isFileSizeValid } from './utils.js';
25
25
  const { readFile } = _promises;
26
26
  const listener = (callback) => {
@@ -236,7 +236,11 @@ const onUpdateEvent = (filename, callback) => __awaiter(void 0, void 0, void 0,
236
236
  doc = undefined;
237
237
  }
238
238
  if (doc) {
239
- // TODO: Instead of re-generating all openApi files, optimize by just updating the specific file that changed.
239
+ yield upsertOpenApiFile({
240
+ filename: pathUtil.parse(filename).name,
241
+ originalFileLocation: '/' + filename,
242
+ spec: doc,
243
+ });
240
244
  yield updateOpenApiFiles();
241
245
  regenerateNav = true;
242
246
  category = 'openApi';
@@ -1,3 +1,4 @@
1
1
  import { OpenApiFile } from '@mintlify/models';
2
2
  export declare const updateGeneratedNav: () => Promise<void>;
3
3
  export declare const updateOpenApiFiles: (providedOpenApiFiles?: OpenApiFile[]) => Promise<void>;
4
+ export declare const upsertOpenApiFile: (openApiFile: OpenApiFile) => Promise<void>;
@@ -7,31 +7,49 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { categorizeFilePaths } from '@mintlify/prebuild';
11
10
  import fse from 'fs-extra';
12
11
  import { join } from 'path';
13
- import { CLIENT_PATH, CMD_EXEC_PATH } from '../../constants.js';
12
+ import { NEXT_PROPS_PATH } from '../../constants.js';
14
13
  import { generateNav } from './generate.js';
15
14
  import { getDocsState } from './getDocsState.js';
15
+ import { readJsonFile } from './utils.js';
16
16
  export const updateGeneratedNav = () => __awaiter(void 0, void 0, void 0, function* () {
17
17
  const { pagesAcc } = yield getDocsState();
18
18
  const { generatedNav, generatedDocsNav } = yield generateNav(pagesAcc);
19
- const targetPath = join(CLIENT_PATH, 'src', '_props', 'generatedNav.json');
19
+ const targetPath = join(NEXT_PROPS_PATH, 'generatedNav.json');
20
20
  yield fse.outputFile(targetPath, JSON.stringify(generatedNav, null, 2), {
21
21
  flag: 'w',
22
22
  });
23
- const targetDocsPath = join(CLIENT_PATH, 'src', '_props', 'generatedDocsNav.json');
23
+ const targetDocsPath = join(NEXT_PROPS_PATH, 'generatedDocsNav.json');
24
24
  yield fse.outputFile(targetDocsPath, JSON.stringify(generatedDocsNav, null, 2), {
25
25
  flag: 'w',
26
26
  });
27
27
  });
28
28
  export const updateOpenApiFiles = (providedOpenApiFiles) => __awaiter(void 0, void 0, void 0, function* () {
29
29
  if (providedOpenApiFiles == undefined) {
30
- const { openApiFiles } = yield categorizeFilePaths(CMD_EXEC_PATH);
30
+ const { openApiFiles } = yield getDocsState();
31
31
  providedOpenApiFiles = openApiFiles;
32
32
  }
33
- const targetPath = join(CLIENT_PATH, 'src', '_props', 'openApiFiles.json');
33
+ const targetPath = join(NEXT_PROPS_PATH, 'openApiFiles.json');
34
34
  yield fse.outputFile(targetPath, JSON.stringify(providedOpenApiFiles, null, 2), {
35
35
  flag: 'w',
36
36
  });
37
37
  });
38
+ export const upsertOpenApiFile = (openApiFile) => __awaiter(void 0, void 0, void 0, function* () {
39
+ const sourcePath = join(NEXT_PROPS_PATH, 'openApiFiles.json');
40
+ let existingOpenApiFiles = [];
41
+ try {
42
+ existingOpenApiFiles = (yield readJsonFile(sourcePath));
43
+ }
44
+ catch (_a) { }
45
+ const existingIndex = existingOpenApiFiles.findIndex((file) => file.originalFileLocation === openApiFile.originalFileLocation);
46
+ if (existingIndex >= 0) {
47
+ existingOpenApiFiles[existingIndex] = openApiFile;
48
+ }
49
+ else {
50
+ existingOpenApiFiles.push(openApiFile);
51
+ }
52
+ yield fse.outputFile(sourcePath, JSON.stringify(existingOpenApiFiles, null, 2), {
53
+ flag: 'w',
54
+ });
55
+ });
@@ -1,3 +1,4 @@
1
1
  export declare const getFileExtension: (filename: string) => string;
2
2
  export declare const isFileSizeValid: (path: string, maxFileSizeInMb: number) => Promise<boolean>;
3
3
  export declare function isError(obj: unknown): boolean;
4
+ export declare const readJsonFile: (path: string) => Promise<any>;
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { promises as _promises } from 'fs';
11
+ import fse from 'fs-extra';
11
12
  const { stat } = _promises;
12
13
  export const getFileExtension = (filename) => {
13
14
  return filename.substring(filename.lastIndexOf('.') + 1, filename.length) || filename;
@@ -20,3 +21,7 @@ export const isFileSizeValid = (path, maxFileSizeInMb) => __awaiter(void 0, void
20
21
  export function isError(obj) {
21
22
  return Object.prototype.toString.call(obj) === '[object Error]';
22
23
  }
24
+ export const readJsonFile = (path) => __awaiter(void 0, void 0, void 0, function* () {
25
+ const file = yield fse.readFile(path, 'utf-8');
26
+ return JSON.parse(file);
27
+ });