@mintlify/previewing 4.0.527 → 4.0.528
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/__tests__/dev.test.d.ts +1 -0
- package/dist/__tests__/dev.test.js +125 -0
- package/dist/__tests__/downloadTargetMint.test.d.ts +1 -0
- package/dist/__tests__/downloadTargetMint.test.js +219 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/local-preview/client.d.ts +5 -3
- package/dist/local-preview/client.js +40 -57
- package/dist/local-preview/index.js +18 -107
- package/dist/local-preview/listener/generate.js +15 -21
- package/dist/local-preview/listener/generateDependentSnippets.js +23 -26
- package/dist/local-preview/listener/generatePagesWithImports.js +11 -20
- package/dist/local-preview/listener/getDocsState.js +10 -19
- package/dist/local-preview/listener/getSnippets.js +6 -15
- package/dist/local-preview/listener/index.js +45 -54
- package/dist/local-preview/listener/resolveAllImports.js +4 -13
- package/dist/local-preview/listener/update.js +14 -23
- package/dist/local-preview/listener/utils.js +6 -15
- package/dist/local-preview/run.d.ts +2 -0
- package/dist/local-preview/run.js +47 -0
- package/dist/local-preview/setupNext.d.ts +22 -0
- package/dist/local-preview/setupNext.js +41 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/util.d.ts +1 -0
- package/dist/util.js +8 -0
- package/package.json +6 -3
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { categorizeFilePaths, createPage, generateDecoratedDocsNavigationFromPages, } from '@mintlify/prebuild';
|
|
11
2
|
import { promises as _promises } from 'fs';
|
|
12
3
|
import { join } from 'path';
|
|
13
4
|
import { CMD_EXEC_PATH } from '../../constants.js';
|
|
14
5
|
const { readFile } = _promises;
|
|
15
|
-
const createFilenamePageMetadataMap =
|
|
6
|
+
const createFilenamePageMetadataMap = async ({ contentDirectoryPath, contentFilenames, openApiFiles, asyncApiFiles, pagesAcc = {}, }) => {
|
|
16
7
|
const contentPromises = [];
|
|
17
8
|
contentFilenames.forEach((filename) => {
|
|
18
|
-
contentPromises.push((() =>
|
|
9
|
+
contentPromises.push((async () => {
|
|
19
10
|
const sourcePath = join(contentDirectoryPath, filename);
|
|
20
|
-
const contentStr = (
|
|
21
|
-
const { slug, pageMetadata } =
|
|
22
|
-
pagesAcc =
|
|
23
|
-
|
|
11
|
+
const contentStr = (await readFile(sourcePath)).toString();
|
|
12
|
+
const { slug, pageMetadata } = await createPage(filename, contentStr, contentDirectoryPath, openApiFiles, asyncApiFiles, true);
|
|
13
|
+
pagesAcc = {
|
|
14
|
+
...pagesAcc,
|
|
15
|
+
[slug]: pageMetadata,
|
|
16
|
+
};
|
|
17
|
+
})());
|
|
24
18
|
});
|
|
25
|
-
|
|
19
|
+
await Promise.all(contentPromises);
|
|
26
20
|
return pagesAcc;
|
|
27
|
-
}
|
|
28
|
-
export const generateNav = (pagesAcc, docsConfig) =>
|
|
29
|
-
const { contentFilenames, openApiFiles, asyncApiFiles } =
|
|
30
|
-
const filenamePageMetadataMap =
|
|
21
|
+
};
|
|
22
|
+
export const generateNav = async (pagesAcc, docsConfig) => {
|
|
23
|
+
const { contentFilenames, openApiFiles, asyncApiFiles } = await categorizeFilePaths(CMD_EXEC_PATH);
|
|
24
|
+
const filenamePageMetadataMap = await createFilenamePageMetadataMap({
|
|
31
25
|
contentDirectoryPath: CMD_EXEC_PATH,
|
|
32
26
|
contentFilenames,
|
|
33
27
|
openApiFiles,
|
|
@@ -36,4 +30,4 @@ export const generateNav = (pagesAcc, docsConfig) => __awaiter(void 0, void 0, v
|
|
|
36
30
|
});
|
|
37
31
|
const generatedDocsNav = generateDecoratedDocsNavigationFromPages(filenamePageMetadataMap, docsConfig.navigation);
|
|
38
32
|
return generatedDocsNav;
|
|
39
|
-
}
|
|
33
|
+
};
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { findAndRemoveImports, stringifyTree, topologicalSort, hasImports, optionallyAddLeadingSlash, optionallyRemoveLeadingSlash, } from '@mintlify/common';
|
|
11
2
|
import { outputFile } from 'fs-extra';
|
|
12
3
|
import { join } from 'path';
|
|
13
4
|
import { NEXT_PUBLIC_PATH } from '../../constants.js';
|
|
14
5
|
import { getOriginalSnippets } from './getSnippets.js';
|
|
15
6
|
import { resolveAllImports } from './resolveAllImports.js';
|
|
16
|
-
const findAllDependents = (initialFileWithSlash, allSnippets, processedDataCache) =>
|
|
7
|
+
const findAllDependents = async (initialFileWithSlash, allSnippets, processedDataCache) => {
|
|
17
8
|
const affected = new Set([initialFileWithSlash]);
|
|
18
9
|
const queue = [initialFileWithSlash];
|
|
19
10
|
while (queue.length > 0) {
|
|
@@ -25,7 +16,7 @@ const findAllDependents = (initialFileWithSlash, allSnippets, processedDataCache
|
|
|
25
16
|
let processedData = processedDataCache.get(potentialDependentFile);
|
|
26
17
|
if (processedData == null) {
|
|
27
18
|
const clonedTree = structuredClone(snippet.tree);
|
|
28
|
-
processedData =
|
|
19
|
+
processedData = await findAndRemoveImports(clonedTree);
|
|
29
20
|
processedDataCache.set(potentialDependentFile, processedData);
|
|
30
21
|
}
|
|
31
22
|
if (processedData.importMap[currentSourceFile]) {
|
|
@@ -37,30 +28,36 @@ const findAllDependents = (initialFileWithSlash, allSnippets, processedDataCache
|
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
30
|
return affected;
|
|
40
|
-
}
|
|
41
|
-
export const generateDependentSnippets = (changedFilename, newImportData) =>
|
|
31
|
+
};
|
|
32
|
+
export const generateDependentSnippets = async (changedFilename, newImportData) => {
|
|
42
33
|
const processedDataCache = new Map();
|
|
43
|
-
const allOriginalSnippets =
|
|
34
|
+
const allOriginalSnippets = await getOriginalSnippets();
|
|
44
35
|
const updatedSnippetFileKey = optionallyAddLeadingSlash(changedFilename);
|
|
45
|
-
const affectedSnippets =
|
|
46
|
-
const snippetPromises = Array.from(affectedSnippets).map((filename) =>
|
|
36
|
+
const affectedSnippets = await findAllDependents(updatedSnippetFileKey, allOriginalSnippets, processedDataCache);
|
|
37
|
+
const snippetPromises = Array.from(affectedSnippets).map(async (filename) => {
|
|
47
38
|
const cachedData = processedDataCache.get(filename);
|
|
48
39
|
if (cachedData)
|
|
49
|
-
return
|
|
40
|
+
return { filename, ...cachedData };
|
|
50
41
|
const originalSnippet = allOriginalSnippets.find((s) => optionallyAddLeadingSlash(s.filename) === filename);
|
|
51
42
|
if (!originalSnippet)
|
|
52
43
|
return null;
|
|
53
|
-
const processed =
|
|
44
|
+
const processed = await findAndRemoveImports(structuredClone(originalSnippet.tree));
|
|
54
45
|
processedDataCache.set(filename, processed);
|
|
55
|
-
return
|
|
56
|
-
})
|
|
57
|
-
const snippets = (
|
|
46
|
+
return { filename, ...processed };
|
|
47
|
+
});
|
|
48
|
+
const snippets = (await Promise.all(snippetPromises)).filter((item) => item != null);
|
|
58
49
|
const idx = snippets.findIndex((item) => item.filename === updatedSnippetFileKey);
|
|
59
50
|
if (idx !== -1) {
|
|
60
|
-
snippets[idx] =
|
|
51
|
+
snippets[idx] = {
|
|
52
|
+
...newImportData,
|
|
53
|
+
filename: updatedSnippetFileKey,
|
|
54
|
+
};
|
|
61
55
|
}
|
|
62
56
|
else {
|
|
63
|
-
snippets.push(
|
|
57
|
+
snippets.push({
|
|
58
|
+
...newImportData,
|
|
59
|
+
filename: updatedSnippetFileKey,
|
|
60
|
+
});
|
|
64
61
|
}
|
|
65
62
|
const graph = {};
|
|
66
63
|
snippets.forEach((item) => {
|
|
@@ -75,12 +72,12 @@ export const generateDependentSnippets = (changedFilename, newImportData) => __a
|
|
|
75
72
|
for (const currentSnippet of orderedSnippets) {
|
|
76
73
|
let processedTree = currentSnippet.tree;
|
|
77
74
|
if (currentSnippet.filename !== updatedSnippetFileKey && hasImports(currentSnippet)) {
|
|
78
|
-
processedTree =
|
|
75
|
+
processedTree = await resolveAllImports(currentSnippet);
|
|
79
76
|
}
|
|
80
77
|
const targetFilename = optionallyRemoveLeadingSlash(currentSnippet.filename);
|
|
81
78
|
const targetPath = join(NEXT_PUBLIC_PATH, targetFilename);
|
|
82
|
-
|
|
79
|
+
await outputFile(targetPath, stringifyTree(processedTree), { flag: 'w' });
|
|
83
80
|
processedSnippets.push(targetFilename);
|
|
84
81
|
}
|
|
85
82
|
return processedSnippets;
|
|
86
|
-
}
|
|
83
|
+
};
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { findAndRemoveImports, optionallyRemoveLeadingSlash, resolveAllImports, stringifyTree, } from '@mintlify/common';
|
|
11
2
|
import { preparseMdxTree, getFileListSync } from '@mintlify/prebuild';
|
|
12
3
|
import { promises as _promises } from 'fs';
|
|
@@ -15,22 +6,22 @@ import { join } from 'path';
|
|
|
15
6
|
import { CMD_EXEC_PATH, NEXT_PROPS_PATH } from '../../constants.js';
|
|
16
7
|
import { getProcessedSnippets } from './getSnippets.js';
|
|
17
8
|
const { readFile } = _promises;
|
|
18
|
-
export const generatePagesWithImports = (updatedSnippets) =>
|
|
19
|
-
const snippets =
|
|
9
|
+
export const generatePagesWithImports = async (updatedSnippets) => {
|
|
10
|
+
const snippets = await getProcessedSnippets();
|
|
20
11
|
const pageFilenames = getFileListSync(CMD_EXEC_PATH).filter((file) => file.endsWith('.mdx') && !file.startsWith('_snippets/') && !file.startsWith('snippets/'));
|
|
21
|
-
|
|
12
|
+
await Promise.all(pageFilenames.map(async (pageFilename) => {
|
|
22
13
|
const sourcePath = join(CMD_EXEC_PATH, pageFilename);
|
|
23
|
-
const contentStr = (
|
|
14
|
+
const contentStr = (await readFile(sourcePath)).toString();
|
|
24
15
|
try {
|
|
25
|
-
const tree =
|
|
26
|
-
const importsResponse =
|
|
16
|
+
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, sourcePath);
|
|
17
|
+
const importsResponse = await findAndRemoveImports(tree);
|
|
27
18
|
if (Object.keys(importsResponse.importMap).some((importPath) => updatedSnippets.has(optionallyRemoveLeadingSlash(importPath)))) {
|
|
28
|
-
const content =
|
|
19
|
+
const content = await resolveAllImports({
|
|
29
20
|
snippets,
|
|
30
|
-
fileWithImports:
|
|
21
|
+
fileWithImports: { ...importsResponse, filename: pageFilename },
|
|
31
22
|
});
|
|
32
23
|
const targetPath = join(NEXT_PROPS_PATH, pageFilename);
|
|
33
|
-
|
|
24
|
+
await outputFile(targetPath, stringifyTree(content), {
|
|
34
25
|
flag: 'w',
|
|
35
26
|
});
|
|
36
27
|
}
|
|
@@ -40,5 +31,5 @@ export const generatePagesWithImports = (updatedSnippets) => __awaiter(void 0, v
|
|
|
40
31
|
console.log(pageFilename);
|
|
41
32
|
console.log(err);
|
|
42
33
|
}
|
|
43
|
-
}))
|
|
44
|
-
}
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { generateOpenApiAnchorsOrTabs, categorizeFilePaths, generateOpenApiDivisions, MintConfigUpdater, DocsConfigUpdater, } from '@mintlify/prebuild';
|
|
11
2
|
import { upgradeToDocsConfig } from '@mintlify/validation';
|
|
12
3
|
import fse from 'fs-extra';
|
|
13
4
|
import { join } from 'path';
|
|
14
5
|
import { CMD_EXEC_PATH, CLIENT_PATH } from '../../constants.js';
|
|
15
|
-
export const getDocsState = () =>
|
|
16
|
-
const { openApiFiles } =
|
|
6
|
+
export const getDocsState = async () => {
|
|
7
|
+
const { openApiFiles } = await categorizeFilePaths(CMD_EXEC_PATH);
|
|
17
8
|
try {
|
|
18
|
-
const mintConfig =
|
|
9
|
+
const mintConfig = await MintConfigUpdater.getConfig(join(CMD_EXEC_PATH, 'mint.json'));
|
|
19
10
|
const docsConfig = upgradeToDocsConfig(mintConfig);
|
|
20
|
-
const { mintConfig: newMintConfig } =
|
|
21
|
-
const { newDocsConfig, pagesAcc, openApiFiles: newOpenApiFiles, } =
|
|
11
|
+
const { mintConfig: newMintConfig } = await generateOpenApiAnchorsOrTabs(mintConfig, openApiFiles, CLIENT_PATH);
|
|
12
|
+
const { newDocsConfig, pagesAcc, openApiFiles: newOpenApiFiles, } = await generateOpenApiDivisions(docsConfig, openApiFiles, CLIENT_PATH);
|
|
22
13
|
return {
|
|
23
14
|
mintConfig: newMintConfig,
|
|
24
15
|
pagesAcc,
|
|
@@ -26,12 +17,12 @@ export const getDocsState = () => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
26
17
|
docsConfig: newDocsConfig,
|
|
27
18
|
};
|
|
28
19
|
}
|
|
29
|
-
catch
|
|
20
|
+
catch {
|
|
30
21
|
const docsJsonPath = join(CMD_EXEC_PATH, 'docs.json');
|
|
31
|
-
if (!(
|
|
22
|
+
if (!(await fse.pathExists(docsJsonPath)))
|
|
32
23
|
throw new Error('No config found');
|
|
33
|
-
const docsConfig =
|
|
34
|
-
const { newDocsConfig, pagesAcc, openApiFiles: newOpenApiFiles, } =
|
|
24
|
+
const docsConfig = await DocsConfigUpdater.getConfig(docsJsonPath);
|
|
25
|
+
const { newDocsConfig, pagesAcc, openApiFiles: newOpenApiFiles, } = await generateOpenApiDivisions(docsConfig, openApiFiles, CLIENT_PATH);
|
|
35
26
|
return { pagesAcc, openApiFiles: newOpenApiFiles, docsConfig: newDocsConfig };
|
|
36
27
|
}
|
|
37
|
-
}
|
|
28
|
+
};
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { optionallyAddLeadingSlash } from '@mintlify/common';
|
|
11
2
|
import { getFileListSync, preparseMdxTree } from '@mintlify/prebuild';
|
|
12
3
|
import { promises as _promises } from 'fs';
|
|
13
4
|
import { join } from 'path';
|
|
14
5
|
import { CMD_EXEC_PATH, NEXT_PUBLIC_PATH } from '../../constants.js';
|
|
15
6
|
const { readFile } = _promises;
|
|
16
|
-
const getSnippetBase = (BASE_DIR) =>
|
|
7
|
+
const getSnippetBase = async (BASE_DIR) => {
|
|
17
8
|
const snippetFilenames = getFileListSync(BASE_DIR).filter((file) => file.endsWith('.mdx') && file.startsWith('snippets/'));
|
|
18
|
-
const promises = snippetFilenames.map((snippetFilename) =>
|
|
9
|
+
const promises = snippetFilenames.map(async (snippetFilename) => {
|
|
19
10
|
try {
|
|
20
|
-
const tree =
|
|
11
|
+
const tree = await preparseMdxTree((await readFile(join(BASE_DIR, snippetFilename))).toString(), BASE_DIR, join(BASE_DIR, snippetFilename));
|
|
21
12
|
return {
|
|
22
13
|
filename: optionallyAddLeadingSlash(snippetFilename),
|
|
23
14
|
tree,
|
|
@@ -27,8 +18,8 @@ const getSnippetBase = (BASE_DIR) => __awaiter(void 0, void 0, void 0, function*
|
|
|
27
18
|
console.warn(`Error reading snippet file ${snippetFilename}`);
|
|
28
19
|
return;
|
|
29
20
|
}
|
|
30
|
-
})
|
|
31
|
-
return (
|
|
32
|
-
}
|
|
21
|
+
});
|
|
22
|
+
return (await Promise.all(promises)).filter(Boolean);
|
|
23
|
+
};
|
|
33
24
|
export const getProcessedSnippets = () => getSnippetBase(NEXT_PUBLIC_PATH);
|
|
34
25
|
export const getOriginalSnippets = () => getSnippetBase(CMD_EXEC_PATH);
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { findAndRemoveImports, hasImports, getFileCategory, openApiCheck, stringifyTree, } from '@mintlify/common';
|
|
11
2
|
import { createPage, MintConfigUpdater, DocsConfigUpdater, preparseMdxTree, } from '@mintlify/prebuild';
|
|
12
3
|
import Chalk from 'chalk';
|
|
@@ -35,9 +26,9 @@ const listener = (callback) => {
|
|
|
35
26
|
.on('change', (filename) => onChangeEvent(filename, callback))
|
|
36
27
|
.on('unlink', onUnlinkEvent);
|
|
37
28
|
};
|
|
38
|
-
const onAddEvent = (filename, callback) =>
|
|
29
|
+
const onAddEvent = async (filename, callback) => {
|
|
39
30
|
try {
|
|
40
|
-
const category =
|
|
31
|
+
const category = await onUpdateEvent(filename, callback);
|
|
41
32
|
switch (category) {
|
|
42
33
|
case 'page':
|
|
43
34
|
console.log('New page detected: ', filename);
|
|
@@ -67,10 +58,10 @@ const onAddEvent = (filename, callback) => __awaiter(void 0, void 0, void 0, fun
|
|
|
67
58
|
catch (error) {
|
|
68
59
|
console.error(error.message);
|
|
69
60
|
}
|
|
70
|
-
}
|
|
71
|
-
const onChangeEvent = (filename, callback) =>
|
|
61
|
+
};
|
|
62
|
+
const onChangeEvent = async (filename, callback) => {
|
|
72
63
|
try {
|
|
73
|
-
const category =
|
|
64
|
+
const category = await onUpdateEvent(filename, callback);
|
|
74
65
|
switch (category) {
|
|
75
66
|
case 'page':
|
|
76
67
|
console.log('Page edited: ', filename);
|
|
@@ -100,8 +91,8 @@ const onChangeEvent = (filename, callback) => __awaiter(void 0, void 0, void 0,
|
|
|
100
91
|
catch (error) {
|
|
101
92
|
console.error(error.message);
|
|
102
93
|
}
|
|
103
|
-
}
|
|
104
|
-
const onUnlinkEvent = (filename) =>
|
|
94
|
+
};
|
|
95
|
+
const onUnlinkEvent = async (filename) => {
|
|
105
96
|
try {
|
|
106
97
|
const potentialCategory = getFileCategory(filename);
|
|
107
98
|
const targetPath = getTargetPath(potentialCategory, filename);
|
|
@@ -113,7 +104,7 @@ const onUnlinkEvent = (filename) => __awaiter(void 0, void 0, void 0, function*
|
|
|
113
104
|
potentialCategory === 'snippet-v2' ||
|
|
114
105
|
potentialCategory === 'css' ||
|
|
115
106
|
potentialCategory === 'js') {
|
|
116
|
-
|
|
107
|
+
await fse.remove(targetPath);
|
|
117
108
|
}
|
|
118
109
|
switch (potentialCategory) {
|
|
119
110
|
case 'page':
|
|
@@ -125,16 +116,16 @@ const onUnlinkEvent = (filename) => __awaiter(void 0, void 0, void 0, function*
|
|
|
125
116
|
break;
|
|
126
117
|
case 'mintConfig':
|
|
127
118
|
console.error('⚠️ mint.json has been deleted.');
|
|
128
|
-
|
|
119
|
+
await validateConfigFiles();
|
|
129
120
|
break;
|
|
130
121
|
case 'docsConfig':
|
|
131
122
|
console.error('⚠️ docs.json has been deleted.');
|
|
132
|
-
|
|
123
|
+
await validateConfigFiles();
|
|
133
124
|
break;
|
|
134
125
|
case 'potentialJsonOpenApiSpec':
|
|
135
126
|
case 'potentialYamlOpenApiSpec':
|
|
136
|
-
|
|
137
|
-
|
|
127
|
+
await updateOpenApiFiles();
|
|
128
|
+
await updateGeneratedNav();
|
|
138
129
|
break;
|
|
139
130
|
case 'css':
|
|
140
131
|
console.log(`CSS file deleted: ${filename}`);
|
|
@@ -150,7 +141,7 @@ const onUnlinkEvent = (filename) => __awaiter(void 0, void 0, void 0, function*
|
|
|
150
141
|
catch (error) {
|
|
151
142
|
console.error(error.message);
|
|
152
143
|
}
|
|
153
|
-
}
|
|
144
|
+
};
|
|
154
145
|
const getTargetPath = (potentialCategory, filePath) => {
|
|
155
146
|
switch (potentialCategory) {
|
|
156
147
|
case 'page':
|
|
@@ -172,12 +163,12 @@ const getTargetPath = (potentialCategory, filePath) => {
|
|
|
172
163
|
throw new Error('Invalid category');
|
|
173
164
|
}
|
|
174
165
|
};
|
|
175
|
-
const validateConfigFiles = () =>
|
|
166
|
+
const validateConfigFiles = async () => {
|
|
176
167
|
try {
|
|
177
168
|
const mintConfigPath = pathUtil.join(CMD_EXEC_PATH, 'mint.json');
|
|
178
169
|
const docsConfigPath = pathUtil.join(CMD_EXEC_PATH, 'docs.json');
|
|
179
|
-
const mintConfigExists =
|
|
180
|
-
const docsConfigExists =
|
|
170
|
+
const mintConfigExists = await fse.pathExists(mintConfigPath);
|
|
171
|
+
const docsConfigExists = await fse.pathExists(docsConfigPath);
|
|
181
172
|
if (!mintConfigExists && !docsConfigExists) {
|
|
182
173
|
console.error('⚠️ Error: Neither mint.json nor docs.json found in the directory');
|
|
183
174
|
process.exit(1);
|
|
@@ -186,13 +177,13 @@ const validateConfigFiles = () => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
186
177
|
catch (error) {
|
|
187
178
|
console.error('⚠️ Error validating configuration files:', error);
|
|
188
179
|
}
|
|
189
|
-
}
|
|
180
|
+
};
|
|
190
181
|
/**
|
|
191
182
|
* This function is called when a file is added or changed
|
|
192
183
|
* @param filename
|
|
193
184
|
* @returns FileCategory
|
|
194
185
|
*/
|
|
195
|
-
const onUpdateEvent = (filename, callback) =>
|
|
186
|
+
const onUpdateEvent = async (filename, callback) => {
|
|
196
187
|
const filePath = pathUtil.join(CMD_EXEC_PATH, filename);
|
|
197
188
|
const potentialCategory = getFileCategory(filename);
|
|
198
189
|
const targetPath = getTargetPath(potentialCategory, filename);
|
|
@@ -204,46 +195,46 @@ const onUpdateEvent = (filename, callback) => __awaiter(void 0, void 0, void 0,
|
|
|
204
195
|
switch (potentialCategory) {
|
|
205
196
|
case 'page': {
|
|
206
197
|
regenerateNav = true;
|
|
207
|
-
let contentStr = (
|
|
208
|
-
const tree =
|
|
209
|
-
const importsResponse =
|
|
198
|
+
let contentStr = (await readFile(filePath)).toString();
|
|
199
|
+
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, filePath);
|
|
200
|
+
const importsResponse = await findAndRemoveImports(tree);
|
|
210
201
|
if (hasImports(importsResponse)) {
|
|
211
|
-
contentStr = stringifyTree(
|
|
202
|
+
contentStr = stringifyTree(await resolveAllImports({ ...importsResponse, filename }));
|
|
212
203
|
}
|
|
213
|
-
const { pageContent } =
|
|
214
|
-
|
|
204
|
+
const { pageContent } = await createPage(filename, contentStr, CMD_EXEC_PATH, [], []);
|
|
205
|
+
await fse.outputFile(targetPath, pageContent, {
|
|
215
206
|
flag: 'w',
|
|
216
207
|
});
|
|
217
208
|
break;
|
|
218
209
|
}
|
|
219
210
|
case 'snippet': {
|
|
220
|
-
|
|
211
|
+
await fse.copy(filePath, targetPath);
|
|
221
212
|
break;
|
|
222
213
|
}
|
|
223
214
|
case 'snippet-v2': {
|
|
224
|
-
let contentStr = (
|
|
225
|
-
const tree =
|
|
226
|
-
const importsResponse =
|
|
215
|
+
let contentStr = (await readFile(filePath)).toString();
|
|
216
|
+
const tree = await preparseMdxTree(contentStr, CMD_EXEC_PATH, filePath);
|
|
217
|
+
const importsResponse = await findAndRemoveImports(tree);
|
|
227
218
|
if (hasImports(importsResponse)) {
|
|
228
|
-
contentStr = stringifyTree(
|
|
219
|
+
contentStr = stringifyTree(await resolveAllImports({ ...importsResponse, filename }));
|
|
229
220
|
}
|
|
230
|
-
|
|
221
|
+
await fse.outputFile(targetPath, contentStr, {
|
|
231
222
|
flag: 'w',
|
|
232
223
|
});
|
|
233
|
-
const updatedSnippets =
|
|
234
|
-
|
|
224
|
+
const updatedSnippets = await generateDependentSnippets(filename, importsResponse);
|
|
225
|
+
await generatePagesWithImports(new Set(updatedSnippets));
|
|
235
226
|
break;
|
|
236
227
|
}
|
|
237
228
|
case 'mintConfig':
|
|
238
229
|
case 'docsConfig': {
|
|
239
230
|
regenerateNav = true;
|
|
240
231
|
try {
|
|
241
|
-
const { mintConfig, openApiFiles, docsConfig } =
|
|
232
|
+
const { mintConfig, openApiFiles, docsConfig } = await getDocsState();
|
|
242
233
|
if (mintConfig) {
|
|
243
|
-
|
|
234
|
+
await MintConfigUpdater.writeConfigFile(mintConfig, CLIENT_PATH);
|
|
244
235
|
}
|
|
245
|
-
|
|
246
|
-
|
|
236
|
+
await DocsConfigUpdater.writeConfigFile(docsConfig, CLIENT_PATH);
|
|
237
|
+
await updateOpenApiFiles(openApiFiles);
|
|
247
238
|
}
|
|
248
239
|
catch (err) {
|
|
249
240
|
console.error(err);
|
|
@@ -254,19 +245,19 @@ const onUpdateEvent = (filename, callback) => __awaiter(void 0, void 0, void 0,
|
|
|
254
245
|
case 'potentialJsonOpenApiSpec': {
|
|
255
246
|
let doc;
|
|
256
247
|
try {
|
|
257
|
-
const file =
|
|
258
|
-
doc =
|
|
248
|
+
const file = await fs.readFile(filePath, 'utf-8');
|
|
249
|
+
doc = await openApiCheck(yaml.load(file));
|
|
259
250
|
}
|
|
260
|
-
catch
|
|
251
|
+
catch {
|
|
261
252
|
doc = undefined;
|
|
262
253
|
}
|
|
263
254
|
if (doc) {
|
|
264
|
-
|
|
255
|
+
await upsertOpenApiFile({
|
|
265
256
|
filename: pathUtil.parse(filename).name,
|
|
266
257
|
originalFileLocation: '/' + filename,
|
|
267
258
|
spec: doc,
|
|
268
259
|
});
|
|
269
|
-
|
|
260
|
+
await updateOpenApiFiles();
|
|
270
261
|
regenerateNav = true;
|
|
271
262
|
category = 'openApi';
|
|
272
263
|
}
|
|
@@ -275,8 +266,8 @@ const onUpdateEvent = (filename, callback) => __awaiter(void 0, void 0, void 0,
|
|
|
275
266
|
case 'css':
|
|
276
267
|
case 'js':
|
|
277
268
|
case 'staticFile': {
|
|
278
|
-
if (
|
|
279
|
-
|
|
269
|
+
if (await isFileSizeValid(filePath, 5)) {
|
|
270
|
+
await fse.copy(filePath, targetPath);
|
|
280
271
|
}
|
|
281
272
|
else {
|
|
282
273
|
console.error(Chalk.red(`🚨 The file at ${filename} is too big. The maximum file size is 5 mb.`));
|
|
@@ -286,9 +277,9 @@ const onUpdateEvent = (filename, callback) => __awaiter(void 0, void 0, void 0,
|
|
|
286
277
|
}
|
|
287
278
|
if (regenerateNav) {
|
|
288
279
|
// TODO: Instead of re-generating the entire nav, optimize by just updating the specific page that changed.
|
|
289
|
-
|
|
280
|
+
await updateGeneratedNav();
|
|
290
281
|
}
|
|
291
282
|
callback();
|
|
292
283
|
return category;
|
|
293
|
-
}
|
|
284
|
+
};
|
|
294
285
|
export default listener;
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { resolveAllImports as baseResolveAllImports } from '@mintlify/common';
|
|
11
2
|
import { getProcessedSnippets } from './getSnippets.js';
|
|
12
|
-
export const resolveAllImports = (fileWithImports) =>
|
|
13
|
-
const snippets =
|
|
14
|
-
return
|
|
3
|
+
export const resolveAllImports = async (fileWithImports) => {
|
|
4
|
+
const snippets = await getProcessedSnippets();
|
|
5
|
+
return await baseResolveAllImports({
|
|
15
6
|
snippets,
|
|
16
7
|
fileWithImports,
|
|
17
8
|
});
|
|
18
|
-
}
|
|
9
|
+
};
|
|
@@ -1,43 +1,34 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import fse from 'fs-extra';
|
|
11
2
|
import { join } from 'path';
|
|
12
3
|
import { NEXT_PROPS_PATH } from '../../constants.js';
|
|
13
4
|
import { generateNav } from './generate.js';
|
|
14
5
|
import { getDocsState } from './getDocsState.js';
|
|
15
6
|
import { readJsonFile } from './utils.js';
|
|
16
|
-
export const updateGeneratedNav = () =>
|
|
17
|
-
const { pagesAcc, docsConfig } =
|
|
18
|
-
const generatedDocsNav =
|
|
7
|
+
export const updateGeneratedNav = async () => {
|
|
8
|
+
const { pagesAcc, docsConfig } = await getDocsState();
|
|
9
|
+
const generatedDocsNav = await generateNav(pagesAcc, docsConfig);
|
|
19
10
|
const targetDocsPath = join(NEXT_PROPS_PATH, 'generatedDocsNav.json');
|
|
20
|
-
|
|
11
|
+
await fse.outputFile(targetDocsPath, JSON.stringify(generatedDocsNav, null, 2), {
|
|
21
12
|
flag: 'w',
|
|
22
13
|
});
|
|
23
|
-
}
|
|
24
|
-
export const updateOpenApiFiles = (providedOpenApiFiles) =>
|
|
14
|
+
};
|
|
15
|
+
export const updateOpenApiFiles = async (providedOpenApiFiles) => {
|
|
25
16
|
if (providedOpenApiFiles == undefined) {
|
|
26
|
-
const { openApiFiles } =
|
|
17
|
+
const { openApiFiles } = await getDocsState();
|
|
27
18
|
providedOpenApiFiles = openApiFiles;
|
|
28
19
|
}
|
|
29
20
|
const targetPath = join(NEXT_PROPS_PATH, 'openApiFiles.json');
|
|
30
|
-
|
|
21
|
+
await fse.outputFile(targetPath, JSON.stringify(providedOpenApiFiles, null, 2), {
|
|
31
22
|
flag: 'w',
|
|
32
23
|
});
|
|
33
|
-
}
|
|
34
|
-
export const upsertOpenApiFile = (openApiFile) =>
|
|
24
|
+
};
|
|
25
|
+
export const upsertOpenApiFile = async (openApiFile) => {
|
|
35
26
|
const sourcePath = join(NEXT_PROPS_PATH, 'openApiFiles.json');
|
|
36
27
|
let existingOpenApiFiles = [];
|
|
37
28
|
try {
|
|
38
|
-
existingOpenApiFiles = (
|
|
29
|
+
existingOpenApiFiles = (await readJsonFile(sourcePath));
|
|
39
30
|
}
|
|
40
|
-
catch
|
|
31
|
+
catch { }
|
|
41
32
|
const existingIndex = existingOpenApiFiles.findIndex((file) => file.originalFileLocation === openApiFile.originalFileLocation);
|
|
42
33
|
if (existingIndex >= 0) {
|
|
43
34
|
existingOpenApiFiles[existingIndex] = openApiFile;
|
|
@@ -45,7 +36,7 @@ export const upsertOpenApiFile = (openApiFile) => __awaiter(void 0, void 0, void
|
|
|
45
36
|
else {
|
|
46
37
|
existingOpenApiFiles.push(openApiFile);
|
|
47
38
|
}
|
|
48
|
-
|
|
39
|
+
await fse.outputFile(sourcePath, JSON.stringify(existingOpenApiFiles, null, 2), {
|
|
49
40
|
flag: 'w',
|
|
50
41
|
});
|
|
51
|
-
}
|
|
42
|
+
};
|
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { promises as _promises } from 'fs';
|
|
11
2
|
import fse from 'fs-extra';
|
|
12
3
|
const { stat } = _promises;
|
|
13
4
|
export const getFileExtension = (filename) => {
|
|
14
5
|
return filename.substring(filename.lastIndexOf('.') + 1, filename.length) || filename;
|
|
15
6
|
};
|
|
16
|
-
export const isFileSizeValid = (path, maxFileSizeInMb) =>
|
|
7
|
+
export const isFileSizeValid = async (path, maxFileSizeInMb) => {
|
|
17
8
|
const maxFileSizeBytes = maxFileSizeInMb * 1000000;
|
|
18
|
-
const stats =
|
|
9
|
+
const stats = await stat(path);
|
|
19
10
|
return stats.size <= maxFileSizeBytes;
|
|
20
|
-
}
|
|
11
|
+
};
|
|
21
12
|
export function isError(obj) {
|
|
22
13
|
return Object.prototype.toString.call(obj) === '[object Error]';
|
|
23
14
|
}
|
|
24
|
-
export const readJsonFile = (path) =>
|
|
25
|
-
const file =
|
|
15
|
+
export const readJsonFile = async (path) => {
|
|
16
|
+
const file = await fse.readFile(path, 'utf-8');
|
|
26
17
|
return JSON.parse(file);
|
|
27
|
-
}
|
|
18
|
+
};
|