@mintlify/previewing 4.0.948 → 4.0.950
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.
- package/dist/local-preview/listener/getSnippets.js +4 -3
- package/dist/local-preview/listener/index.js +9 -3
- package/dist/local-preview/listener/regenerateAllSnippets.d.ts +1 -0
- package/dist/local-preview/listener/regenerateAllSnippets.js +81 -0
- package/dist/local-preview/listener/utils.d.ts +1 -0
- package/dist/local-preview/listener/utils.js +11 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { optionallyAddLeadingSlash, isSnippetExtension, isImportedAsSnippet, } from '@mintlify/common';
|
|
1
|
+
import { optionallyAddLeadingSlash, replaceVariables, isSnippetExtension, isImportedAsSnippet, } from '@mintlify/common';
|
|
2
2
|
import { getFileListSync, preparseMdxTree, getFileExtension } from '@mintlify/prebuild';
|
|
3
3
|
import { promises as _promises } from 'fs';
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
import { CMD_EXEC_PATH, NEXT_PUBLIC_PATH } from '../../constants.js';
|
|
6
6
|
import { getImportedFilesFromCache } from './importCache.js';
|
|
7
|
-
import { handleParseError } from './utils.js';
|
|
7
|
+
import { handleParseError, getCurrentVariables } from './utils.js';
|
|
8
8
|
const { readFile } = _promises;
|
|
9
9
|
const getSnippetBase = async (baseDir) => {
|
|
10
10
|
const importedFiles = getImportedFilesFromCache();
|
|
11
|
+
const variables = await getCurrentVariables();
|
|
11
12
|
const allSnippetFilenames = getFileListSync(baseDir).filter((file) => {
|
|
12
13
|
if (!isSnippetExtension(getFileExtension(file))) {
|
|
13
14
|
return false;
|
|
@@ -22,7 +23,7 @@ const getSnippetBase = async (baseDir) => {
|
|
|
22
23
|
});
|
|
23
24
|
const promises = allSnippetFilenames.map(async (snippetFilename) => {
|
|
24
25
|
try {
|
|
25
|
-
const tree = await preparseMdxTree((await readFile(join(baseDir, snippetFilename))).toString(), baseDir, join(baseDir, snippetFilename), handleParseError);
|
|
26
|
+
const tree = await preparseMdxTree(replaceVariables((await readFile(join(baseDir, snippetFilename))).toString(), variables), baseDir, join(baseDir, snippetFilename), handleParseError);
|
|
26
27
|
return {
|
|
27
28
|
filename: optionallyAddLeadingSlash(snippetFilename),
|
|
28
29
|
tree,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { findAndRemoveImports, hasImports, getFileCategory, validate, stringifyTree, isMintIgnored, } from '@mintlify/common';
|
|
2
|
+
import { findAndRemoveImports, hasImports, getFileCategory, validate, stringifyTree, isMintIgnored, replaceVariables, } 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';
|
|
@@ -15,9 +15,10 @@ import { generateDependentSnippets } from './generateDependentSnippets.js';
|
|
|
15
15
|
import { generatePagesWithImports } from './generatePagesWithImports.js';
|
|
16
16
|
import { getDocsState } from './getDocsState.js';
|
|
17
17
|
import { initializeImportCache, updateImportCacheForFile, removeFromImportCache, getImportedFilesFromCache, syncImportedFileLocations, } from './importCache.js';
|
|
18
|
+
import { regenerateAllSnippets } from './regenerateAllSnippets.js';
|
|
18
19
|
import { resolveAllImports } from './resolveAllImports.js';
|
|
19
20
|
import { updateCustomLanguages, updateGeneratedNav, updateOpenApiFiles, upsertOpenApiFile, } from './update.js';
|
|
20
|
-
import { getMintIgnoreGlobs, handleParseError, isFileSizeValid, isJsonValid, shouldRegenerateNavForPage, suppressParseError, } from './utils.js';
|
|
21
|
+
import { getCurrentVariables, getMintIgnoreGlobs, handleParseError, isFileSizeValid, isJsonValid, shouldRegenerateNavForPage, suppressParseError, } from './utils.js';
|
|
21
22
|
const { readFile } = _promises;
|
|
22
23
|
const frontmatterHashes = new Map();
|
|
23
24
|
const listener = (callback, options = {}) => {
|
|
@@ -204,7 +205,8 @@ const onUpdateEvent = async (filename, callback, options = {}) => {
|
|
|
204
205
|
break;
|
|
205
206
|
}
|
|
206
207
|
case 'snippet-v2': {
|
|
207
|
-
|
|
208
|
+
const variables = await getCurrentVariables();
|
|
209
|
+
let contentStr = replaceVariables((await readFile(filePath)).toString(), variables);
|
|
208
210
|
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, filePath, handleParseError);
|
|
209
211
|
const importsResponse = await findAndRemoveImports(tree);
|
|
210
212
|
if (hasImports(importsResponse)) {
|
|
@@ -243,6 +245,10 @@ const onUpdateEvent = async (filename, callback, options = {}) => {
|
|
|
243
245
|
console.error(err);
|
|
244
246
|
}
|
|
245
247
|
}
|
|
248
|
+
if (potentialCategory === 'docsConfig') {
|
|
249
|
+
const updatedSnippets = await regenerateAllSnippets();
|
|
250
|
+
await generatePagesWithImports(new Set(updatedSnippets));
|
|
251
|
+
}
|
|
246
252
|
break;
|
|
247
253
|
}
|
|
248
254
|
case 'mintIgnore': {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const regenerateAllSnippets: () => Promise<string[]>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { findAndRemoveImports, replaceVariables, stringifyTree, topologicalSort, hasImports, optionallyAddLeadingSlash, optionallyRemoveLeadingSlash, resolveImportPath, resolveAllImports as baseResolveAllImports, isSnippetExtension, isImportedAsSnippet, } from '@mintlify/common';
|
|
2
|
+
import { preparseMdxTree, getFileListSync, getFileExtension } from '@mintlify/prebuild';
|
|
3
|
+
import { outputFile } from 'fs-extra';
|
|
4
|
+
import { readFile } from 'fs/promises';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { CMD_EXEC_PATH, NEXT_PUBLIC_PATH } from '../../constants.js';
|
|
7
|
+
import { getImportedFilesFromCache } from './importCache.js';
|
|
8
|
+
import { getCurrentVariables, handleParseError } from './utils.js';
|
|
9
|
+
const getV2SnippetFilenames = () => {
|
|
10
|
+
const importedFiles = getImportedFilesFromCache();
|
|
11
|
+
return getFileListSync(CMD_EXEC_PATH).filter((file) => {
|
|
12
|
+
if (!isSnippetExtension(getFileExtension(file)))
|
|
13
|
+
return false;
|
|
14
|
+
if (file.startsWith('snippets/'))
|
|
15
|
+
return true;
|
|
16
|
+
if (getFileExtension(file) === 'jsx')
|
|
17
|
+
return true;
|
|
18
|
+
return isImportedAsSnippet(file, importedFiles);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const regenerateAllSnippets = async () => {
|
|
22
|
+
const variables = await getCurrentVariables();
|
|
23
|
+
const vars = variables ?? {};
|
|
24
|
+
const snippetFilenames = getV2SnippetFilenames();
|
|
25
|
+
const processedSnippets = [];
|
|
26
|
+
const resolvedTrees = [];
|
|
27
|
+
const v2Parsed = [];
|
|
28
|
+
for (const filename of snippetFilenames) {
|
|
29
|
+
try {
|
|
30
|
+
const targetFilename = optionallyRemoveLeadingSlash(filename);
|
|
31
|
+
const rawContent = await readFile(join(CMD_EXEC_PATH, targetFilename), 'utf8');
|
|
32
|
+
const content = replaceVariables(rawContent, vars);
|
|
33
|
+
const tree = await preparseMdxTree(content, CMD_EXEC_PATH, join(CMD_EXEC_PATH, targetFilename), handleParseError);
|
|
34
|
+
const normalizedFilename = optionallyAddLeadingSlash(filename);
|
|
35
|
+
const processed = await findAndRemoveImports(tree);
|
|
36
|
+
v2Parsed.push({
|
|
37
|
+
filename: normalizedFilename,
|
|
38
|
+
content,
|
|
39
|
+
importData: { filename: normalizedFilename, ...processed },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
console.warn(`Failed to parse snippet ${filename}:`, err);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const graph = {};
|
|
47
|
+
for (const { importData } of v2Parsed) {
|
|
48
|
+
graph[importData.filename] = Object.keys(importData.importMap)
|
|
49
|
+
.map((dep) => resolveImportPath(dep, importData.filename))
|
|
50
|
+
.filter((resolvedDep) => resolvedDep != null);
|
|
51
|
+
}
|
|
52
|
+
const sortedFilenames = topologicalSort(graph).reverse();
|
|
53
|
+
const v2Map = new Map(v2Parsed.map((item) => [item.filename, item]));
|
|
54
|
+
const orderedV2 = sortedFilenames
|
|
55
|
+
.map((filename) => v2Map.get(filename))
|
|
56
|
+
.filter((item) => item != null);
|
|
57
|
+
for (const { filename, content, importData } of orderedV2) {
|
|
58
|
+
try {
|
|
59
|
+
const targetFilename = optionallyRemoveLeadingSlash(filename);
|
|
60
|
+
if (!hasImports(importData)) {
|
|
61
|
+
await outputFile(join(NEXT_PUBLIC_PATH, targetFilename), content, { flag: 'w' });
|
|
62
|
+
resolvedTrees.push({ filename, tree: importData.tree });
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const resolvedTree = await baseResolveAllImports({
|
|
66
|
+
snippets: resolvedTrees,
|
|
67
|
+
fileWithImports: importData,
|
|
68
|
+
});
|
|
69
|
+
await outputFile(join(NEXT_PUBLIC_PATH, targetFilename), stringifyTree(resolvedTree), {
|
|
70
|
+
flag: 'w',
|
|
71
|
+
});
|
|
72
|
+
resolvedTrees.push({ filename, tree: resolvedTree });
|
|
73
|
+
}
|
|
74
|
+
processedSnippets.push(targetFilename);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.warn(`Failed to regenerate snippet ${filename}:`, err);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return processedSnippets;
|
|
81
|
+
};
|
|
@@ -11,3 +11,4 @@ export declare const shouldRegenerateNavForPage: (filename: string, contentStr:
|
|
|
11
11
|
export declare function normalizePathForComparison(filePath: string): string;
|
|
12
12
|
export declare const handleParseError: (message: string) => void;
|
|
13
13
|
export declare const suppressParseError: () => void;
|
|
14
|
+
export declare const getCurrentVariables: () => Promise<Record<string, string> | undefined>;
|
|
@@ -5,7 +5,7 @@ import fse from 'fs-extra';
|
|
|
5
5
|
import pathUtil from 'path';
|
|
6
6
|
import { CMD_EXEC_PATH } from '../../constants.js';
|
|
7
7
|
import { addRawErrorLog } from '../../logging-state.js';
|
|
8
|
-
const { stat } = _promises;
|
|
8
|
+
const { stat, readFile } = _promises;
|
|
9
9
|
export const getFileExtension = (filename) => {
|
|
10
10
|
return filename.substring(filename.lastIndexOf('.') + 1, filename.length) || filename;
|
|
11
11
|
};
|
|
@@ -84,3 +84,13 @@ export const handleParseError = (message) => {
|
|
|
84
84
|
export const suppressParseError = () => {
|
|
85
85
|
// no-op to suppress duplicate error logging
|
|
86
86
|
};
|
|
87
|
+
export const getCurrentVariables = async () => {
|
|
88
|
+
try {
|
|
89
|
+
const content = await readFile(pathUtil.join(CMD_EXEC_PATH, 'docs.json'), 'utf8');
|
|
90
|
+
const parsed = JSON.parse(content);
|
|
91
|
+
return parsed.variables;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
};
|