@mintlify/previewing 4.0.824 → 4.0.826
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,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { findAndRemoveImports, hasImports, getFileCategory, openApiCheck, stringifyTree,
|
|
2
|
+
import { findAndRemoveImports, hasImports, getFileCategory, openApiCheck, stringifyTree, isMintIgnored, } from '@mintlify/common';
|
|
3
3
|
import { createPage, MintConfigUpdater, DocsConfigUpdater, preparseMdxTree, prebuild, } from '@mintlify/prebuild';
|
|
4
4
|
import Chalk from 'chalk';
|
|
5
5
|
import chokidar from 'chokidar';
|
|
@@ -10,38 +10,16 @@ import yaml from 'js-yaml';
|
|
|
10
10
|
import pathUtil from 'path';
|
|
11
11
|
import { CMD_EXEC_PATH, NEXT_PROPS_PATH, NEXT_PUBLIC_PATH, CLIENT_PATH } from '../../constants.js';
|
|
12
12
|
import { addChangeLog } from '../../logging-state.js';
|
|
13
|
-
import { AddedLog, DeletedLog, EditedLog, WarningLog, InfoLog } from '../../logs.js';
|
|
13
|
+
import { AddedLog, DeletedLog, EditedLog, WarningLog, InfoLog, ErrorLog } from '../../logs.js';
|
|
14
14
|
import { generateDependentSnippets } from './generateDependentSnippets.js';
|
|
15
15
|
import { generatePagesWithImports } from './generatePagesWithImports.js';
|
|
16
16
|
import { getDocsState } from './getDocsState.js';
|
|
17
17
|
import { resolveAllImports } from './resolveAllImports.js';
|
|
18
18
|
import { updateCustomLanguages, updateGeneratedNav, updateOpenApiFiles, upsertOpenApiFile, } from './update.js';
|
|
19
|
-
import { isFileSizeValid, shouldRegenerateNavForPage } from './utils.js';
|
|
19
|
+
import { isFileSizeValid, shouldRegenerateNavForPage, getSnippetPatterns, isJsonValid, getMintIgnoreGlobs, } from './utils.js';
|
|
20
20
|
const { readFile } = _promises;
|
|
21
21
|
const frontmatterHashes = new Map();
|
|
22
22
|
let previousSnippetPatternsJson = null;
|
|
23
|
-
const getMintIgnoreGlobs = () => {
|
|
24
|
-
const mintIgnorePath = pathUtil.join(CMD_EXEC_PATH, '.mintignore');
|
|
25
|
-
if (fse.existsSync(mintIgnorePath)) {
|
|
26
|
-
const content = fse.readFileSync(mintIgnorePath, 'utf8');
|
|
27
|
-
return processMintIgnoreString(content);
|
|
28
|
-
}
|
|
29
|
-
return [];
|
|
30
|
-
};
|
|
31
|
-
const getSnippetPatterns = () => {
|
|
32
|
-
const docsConfigPath = pathUtil.join(CMD_EXEC_PATH, 'docs.json');
|
|
33
|
-
if (fse.existsSync(docsConfigPath)) {
|
|
34
|
-
try {
|
|
35
|
-
const configContent = fse.readFileSync(docsConfigPath, 'utf-8');
|
|
36
|
-
const config = JSON.parse(configContent);
|
|
37
|
-
return config.snippets;
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
44
|
-
};
|
|
45
23
|
const listener = (callback, options = {}) => {
|
|
46
24
|
const mintIgnoreGlobs = getMintIgnoreGlobs();
|
|
47
25
|
previousSnippetPatternsJson = JSON.stringify(getSnippetPatterns() ?? []);
|
|
@@ -68,8 +46,10 @@ const onAddEvent = async (filename, callback, options) => {
|
|
|
68
46
|
return;
|
|
69
47
|
}
|
|
70
48
|
try {
|
|
71
|
-
await onUpdateEvent(filename, callback, options);
|
|
72
|
-
|
|
49
|
+
const category = await onUpdateEvent(filename, callback, options);
|
|
50
|
+
if (category) {
|
|
51
|
+
addChangeLog(_jsx(AddedLog, { filename: filename }));
|
|
52
|
+
}
|
|
73
53
|
}
|
|
74
54
|
catch (error) {
|
|
75
55
|
console.error(error.message);
|
|
@@ -80,8 +60,10 @@ const onChangeEvent = async (filename, callback, options) => {
|
|
|
80
60
|
return;
|
|
81
61
|
}
|
|
82
62
|
try {
|
|
83
|
-
await onUpdateEvent(filename, callback, options);
|
|
84
|
-
|
|
63
|
+
const category = await onUpdateEvent(filename, callback, options);
|
|
64
|
+
if (category) {
|
|
65
|
+
addChangeLog(_jsx(EditedLog, { filename: filename }));
|
|
66
|
+
}
|
|
85
67
|
}
|
|
86
68
|
catch (error) {
|
|
87
69
|
console.error(error.message);
|
|
@@ -224,8 +206,14 @@ const onUpdateEvent = async (filename, callback, options = {}) => {
|
|
|
224
206
|
}
|
|
225
207
|
case 'mintConfig':
|
|
226
208
|
case 'docsConfig': {
|
|
209
|
+
const { valid, error } = isJsonValid(filePath);
|
|
210
|
+
if (!valid) {
|
|
211
|
+
addChangeLog(_jsx(ErrorLog, { message: `Syntax error in ${filename}: ${error}` }));
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
227
214
|
if (potentialCategory === 'docsConfig') {
|
|
228
|
-
const
|
|
215
|
+
const freshSnippetPatterns = getSnippetPatterns();
|
|
216
|
+
const currentJson = JSON.stringify(freshSnippetPatterns ?? []);
|
|
229
217
|
if (previousSnippetPatternsJson !== null && currentJson !== previousSnippetPatternsJson) {
|
|
230
218
|
previousSnippetPatternsJson = currentJson;
|
|
231
219
|
addChangeLog(_jsx(InfoLog, { message: "Snippet patterns changed. Rebuilding..." }));
|
|
@@ -2,4 +2,10 @@ 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
4
|
export declare const readJsonFile: (path: string) => Promise<any>;
|
|
5
|
+
export declare const getMintIgnoreGlobs: () => string[];
|
|
6
|
+
export declare const getSnippetPatterns: () => string[] | undefined;
|
|
7
|
+
export declare const isJsonValid: (filePath: string) => {
|
|
8
|
+
valid: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
};
|
|
5
11
|
export declare const shouldRegenerateNavForPage: (filename: string, contentStr: string, frontmatterHashes: Map<string, string>) => Promise<boolean>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { parseFrontmatter } from '@mintlify/common';
|
|
1
|
+
import { parseFrontmatter, processMintIgnoreString } from '@mintlify/common';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
|
-
import { promises as _promises } from 'fs';
|
|
3
|
+
import { promises as _promises, readFileSync, existsSync } from 'fs';
|
|
4
4
|
import fse from 'fs-extra';
|
|
5
|
+
import pathUtil from 'path';
|
|
6
|
+
import { CMD_EXEC_PATH } from '../../constants.js';
|
|
5
7
|
const { stat } = _promises;
|
|
6
8
|
export const getFileExtension = (filename) => {
|
|
7
9
|
return filename.substring(filename.lastIndexOf('.') + 1, filename.length) || filename;
|
|
@@ -18,6 +20,41 @@ export const readJsonFile = async (path) => {
|
|
|
18
20
|
const file = await fse.readFile(path, 'utf-8');
|
|
19
21
|
return JSON.parse(file);
|
|
20
22
|
};
|
|
23
|
+
export const getMintIgnoreGlobs = () => {
|
|
24
|
+
const mintIgnorePath = pathUtil.join(CMD_EXEC_PATH, '.mintignore');
|
|
25
|
+
if (existsSync(mintIgnorePath)) {
|
|
26
|
+
const content = readFileSync(mintIgnorePath, 'utf8');
|
|
27
|
+
return processMintIgnoreString(content);
|
|
28
|
+
}
|
|
29
|
+
return [];
|
|
30
|
+
};
|
|
31
|
+
export const getSnippetPatterns = () => {
|
|
32
|
+
const docsConfigPath = pathUtil.join(CMD_EXEC_PATH, 'docs.json');
|
|
33
|
+
if (existsSync(docsConfigPath)) {
|
|
34
|
+
try {
|
|
35
|
+
const configContent = readFileSync(docsConfigPath, 'utf-8');
|
|
36
|
+
const config = JSON.parse(configContent);
|
|
37
|
+
return config.snippets;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
};
|
|
45
|
+
export const isJsonValid = (filePath) => {
|
|
46
|
+
try {
|
|
47
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
48
|
+
if (!content.trim()) {
|
|
49
|
+
return { valid: false, error: 'File is empty' };
|
|
50
|
+
}
|
|
51
|
+
JSON.parse(content);
|
|
52
|
+
return { valid: true };
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return { valid: false, error: error.message };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
21
58
|
export const shouldRegenerateNavForPage = async (filename, contentStr, frontmatterHashes) => {
|
|
22
59
|
try {
|
|
23
60
|
const { attributes: currentFrontmatter } = parseFrontmatter(contentStr);
|