@mintlify/previewing 4.0.1517 → 4.0.1519

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Lets `mint dev` run on a plain folder of Markdown: when there is no docs.json or mint.json,
3
+ * writes a docs.json whose navigation mirrors the folder structure.
4
+ */
5
+ export declare const ensureDocsConfig: () => Promise<void>;
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { slugToTitle } from '@mintlify/common';
3
+ import { generateDocsConfig, getFileListSync, getMintIgnore } from '@mintlify/prebuild';
4
+ import fse from 'fs-extra';
5
+ import pathUtil from 'path';
6
+ import { CMD_EXEC_PATH } from '../constants.js';
7
+ import { addLog } from '../logging-state.js';
8
+ import { InfoLog } from '../logs.js';
9
+ const readPackageName = async (directory) => {
10
+ try {
11
+ const packageJson = await fse.readJson(pathUtil.join(directory, 'package.json'));
12
+ if (packageJson && typeof packageJson === 'object' && 'name' in packageJson) {
13
+ const { name } = packageJson;
14
+ if (typeof name === 'string' && name)
15
+ return name.replace(/^@[^/]+\//, '');
16
+ }
17
+ }
18
+ catch { }
19
+ return undefined;
20
+ };
21
+ /**
22
+ * Lets `mint dev` run on a plain folder of Markdown: when there is no docs.json or mint.json,
23
+ * writes a docs.json whose navigation mirrors the folder structure.
24
+ */
25
+ export const ensureDocsConfig = async () => {
26
+ const hasConfig = await Promise.all(['docs.json', 'mint.json'].map((file) => fse.pathExists(pathUtil.join(CMD_EXEC_PATH, file))));
27
+ if (hasConfig.some(Boolean))
28
+ return;
29
+ const mintIgnore = await getMintIgnore(CMD_EXEC_PATH);
30
+ const files = getFileListSync(CMD_EXEC_PATH, CMD_EXEC_PATH, mintIgnore);
31
+ const name = (await readPackageName(CMD_EXEC_PATH)) ??
32
+ (await readPackageName(pathUtil.dirname(CMD_EXEC_PATH))) ??
33
+ slugToTitle(pathUtil.basename(CMD_EXEC_PATH));
34
+ const docsConfig = generateDocsConfig(files, name);
35
+ if (!docsConfig.navigation.groups.length)
36
+ return;
37
+ await fse.writeJson(pathUtil.join(CMD_EXEC_PATH, 'docs.json'), docsConfig, { spaces: 2 });
38
+ addLog(_jsx(InfoLog, { message: "No docs.json found, so one was generated from your folder structure.", detail: "Edit docs.json to customize navigation, theme, and colors." }));
39
+ };
@@ -9,6 +9,7 @@ import { ErrorLog, SpinnerLog } from '../logs.js';
9
9
  import { isNativePackagesEnabled } from '../packages/flag.js';
10
10
  import { seedPreviewFromShared } from '../util.js';
11
11
  import { timeDev, timeDevSync } from './dev-timing.js';
12
+ import { ensureDocsConfig } from './ensure-docs-config.js';
12
13
  import { startPackagesDev } from './packages/index.js';
13
14
  import { acquirePreviewLock } from './preview-lock.js';
14
15
  import { run } from './run.js';
@@ -67,6 +68,7 @@ const startDev = async (argv) => {
67
68
  await new Promise((resolve) => setTimeout(resolve, 50));
68
69
  process.exit(1);
69
70
  }
71
+ await timeDev('ensure docs.json', () => ensureDocsConfig());
70
72
  // clear preexisting prebuild files
71
73
  timeDevSync('clear prebuild output', () => {
72
74
  fse.emptyDirSync(NEXT_PROPS_PATH);