boltdocs 1.10.2 → 2.0.0
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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/dist/cache-7G6D532T.mjs +1 -0
- package/dist/chunk-A4HQPEPU.mjs +1 -0
- package/dist/chunk-BA5NH5HU.mjs +1 -0
- package/dist/chunk-BQCD3DWG.mjs +1 -0
- package/dist/chunk-H63UMKYF.mjs +1 -0
- package/dist/chunk-IWHRQHS7.mjs +1 -0
- package/dist/chunk-JZXLCA2E.mjs +1 -0
- package/dist/chunk-MFU7Q6WF.mjs +1 -0
- package/dist/chunk-QYPNX5UN.mjs +1 -0
- package/dist/chunk-XEAPSFMB.mjs +1 -0
- package/dist/client/components/mdx/index.d.mts +209 -0
- package/dist/client/components/mdx/index.d.ts +209 -0
- package/dist/client/components/mdx/index.js +1 -0
- package/dist/client/components/mdx/index.mjs +1 -0
- package/dist/client/hooks/index.d.mts +133 -0
- package/dist/client/hooks/index.d.ts +133 -0
- package/dist/client/hooks/index.js +1 -0
- package/dist/client/hooks/index.mjs +1 -0
- package/dist/client/index.d.mts +138 -298
- package/dist/client/index.d.ts +138 -298
- package/dist/client/index.js +1 -3630
- package/dist/client/index.mjs +1 -697
- package/dist/client/ssr.d.mts +7 -3
- package/dist/client/ssr.d.ts +7 -3
- package/dist/client/ssr.js +1 -2928
- package/dist/client/ssr.mjs +1 -33
- package/dist/{config-BsFQ-ErD.d.ts → config-CX4l-ZNp.d.mts} +42 -35
- package/dist/{config-BsFQ-ErD.d.mts → config-CX4l-ZNp.d.ts} +42 -35
- package/dist/node/index.d.mts +2 -4
- package/dist/node/index.d.ts +2 -4
- package/dist/node/index.js +31 -1161
- package/dist/node/index.mjs +31 -736
- package/dist/search-dialog-EB3N4TYM.mjs +1 -0
- package/dist/types-BuZWFT7r.d.ts +159 -0
- package/dist/types-CvT-SGbK.d.mts +159 -0
- package/dist/use-routes-5bAtAAYX.d.mts +30 -0
- package/dist/use-routes-BefRXY3v.d.ts +30 -0
- package/package.json +34 -12
- package/src/client/app/config-context.tsx +18 -0
- package/src/client/app/docs-layout.tsx +14 -0
- package/src/client/app/index.tsx +137 -262
- package/src/client/app/mdx-component.tsx +52 -0
- package/src/client/app/mdx-components-context.tsx +23 -0
- package/src/client/app/mdx-page.tsx +20 -0
- package/src/client/app/preload.tsx +38 -30
- package/src/client/app/router.tsx +30 -0
- package/src/client/app/scroll-handler.tsx +40 -0
- package/src/client/app/theme-context.tsx +75 -0
- package/src/client/components/default-layout.tsx +80 -0
- package/src/client/components/docs-layout.tsx +105 -0
- package/src/client/components/icons-dev.tsx +74 -0
- package/src/client/components/mdx/admonition.tsx +107 -0
- package/src/client/components/mdx/badge.tsx +41 -0
- package/src/client/components/mdx/button.tsx +35 -0
- package/src/client/components/mdx/card.tsx +124 -0
- package/src/client/components/mdx/code-block.tsx +119 -0
- package/src/client/components/mdx/component-preview.tsx +47 -0
- package/src/client/components/mdx/component-props.tsx +83 -0
- package/src/client/components/mdx/field.tsx +66 -0
- package/src/client/components/mdx/file-tree.tsx +287 -0
- package/src/client/components/mdx/hooks/use-code-block.ts +56 -0
- package/src/client/components/mdx/hooks/use-component-preview.ts +16 -0
- package/src/client/components/mdx/hooks/useTable.ts +74 -0
- package/src/client/components/mdx/hooks/useTabs.ts +68 -0
- package/src/client/components/mdx/image.tsx +23 -0
- package/src/client/components/mdx/index.ts +53 -0
- package/src/client/components/mdx/link.tsx +38 -0
- package/src/client/components/mdx/list.tsx +192 -0
- package/src/client/components/mdx/table.tsx +156 -0
- package/src/client/components/mdx/tabs.tsx +135 -0
- package/src/client/components/mdx/video.tsx +68 -0
- package/src/client/components/primitives/breadcrumbs.tsx +79 -0
- package/src/client/components/primitives/button-group.tsx +54 -0
- package/src/client/components/primitives/button.tsx +145 -0
- package/src/client/components/primitives/helpers/observer.ts +120 -0
- package/src/client/components/primitives/index.ts +17 -0
- package/src/client/components/primitives/link.tsx +122 -0
- package/src/client/components/primitives/menu.tsx +159 -0
- package/src/client/components/primitives/navbar.tsx +359 -0
- package/src/client/components/primitives/navigation-menu.tsx +116 -0
- package/src/client/components/primitives/on-this-page.tsx +461 -0
- package/src/client/components/primitives/page-nav.tsx +87 -0
- package/src/client/components/primitives/popover.tsx +47 -0
- package/src/client/components/primitives/search-dialog.tsx +183 -0
- package/src/client/components/primitives/sidebar.tsx +154 -0
- package/src/client/components/primitives/tabs.tsx +90 -0
- package/src/client/components/primitives/tooltip.tsx +83 -0
- package/src/client/components/primitives/types.ts +11 -0
- package/src/client/components/ui-base/breadcrumbs.tsx +42 -0
- package/src/client/components/ui-base/copy-markdown.tsx +112 -0
- package/src/client/components/ui-base/error-boundary.tsx +52 -0
- package/src/client/components/ui-base/github-stars.tsx +27 -0
- package/src/client/components/ui-base/head.tsx +69 -0
- package/src/client/components/ui-base/loading.tsx +87 -0
- package/src/client/components/ui-base/navbar.tsx +138 -0
- package/src/client/components/ui-base/not-found.tsx +24 -0
- package/src/client/components/ui-base/on-this-page.tsx +152 -0
- package/src/client/components/ui-base/page-nav.tsx +39 -0
- package/src/client/components/ui-base/powered-by.tsx +19 -0
- package/src/client/components/ui-base/progress-bar.tsx +67 -0
- package/src/client/components/ui-base/search-dialog.tsx +82 -0
- package/src/client/components/ui-base/sidebar.tsx +104 -0
- package/src/client/components/ui-base/tabs.tsx +65 -0
- package/src/client/components/ui-base/theme-toggle.tsx +32 -0
- package/src/client/hooks/index.ts +12 -0
- package/src/client/hooks/use-breadcrumbs.ts +22 -0
- package/src/client/hooks/use-i18n.ts +84 -0
- package/src/client/hooks/use-localized-to.ts +95 -0
- package/src/client/hooks/use-location.ts +5 -0
- package/src/client/hooks/use-navbar.ts +60 -0
- package/src/client/hooks/use-onthispage.ts +23 -0
- package/src/client/hooks/use-page-nav.ts +22 -0
- package/src/client/hooks/use-routes.ts +72 -0
- package/src/client/hooks/use-search.ts +71 -0
- package/src/client/hooks/use-sidebar.ts +49 -0
- package/src/client/hooks/use-tabs.ts +43 -0
- package/src/client/hooks/use-version.ts +78 -0
- package/src/client/index.ts +55 -17
- package/src/client/integrations/codesandbox.ts +179 -0
- package/src/client/ssr.tsx +27 -16
- package/src/client/theme/neutral.css +360 -0
- package/src/client/types.ts +131 -27
- package/src/client/utils/cn.ts +6 -0
- package/src/client/utils/copy-clipboard.ts +22 -0
- package/src/client/utils/get-base-file-path.ts +21 -0
- package/src/client/utils/github.ts +121 -0
- package/src/client/utils/use-on-change.ts +15 -0
- package/src/client/virtual.d.ts +24 -0
- package/src/node/cache.ts +156 -156
- package/src/node/config.ts +159 -103
- package/src/node/index.ts +13 -13
- package/src/node/mdx.ts +213 -61
- package/src/node/plugin/entry.ts +29 -18
- package/src/node/plugin/html.ts +11 -11
- package/src/node/plugin/index.ts +161 -84
- package/src/node/plugin/types.ts +2 -4
- package/src/node/routes/cache.ts +6 -6
- package/src/node/routes/index.ts +206 -113
- package/src/node/routes/parser.ts +102 -82
- package/src/node/routes/sorter.ts +15 -15
- package/src/node/routes/types.ts +24 -24
- package/src/node/ssg/index.ts +73 -47
- package/src/node/ssg/meta.ts +4 -4
- package/src/node/ssg/options.ts +5 -5
- package/src/node/ssg/sitemap.ts +14 -14
- package/src/node/utils.ts +54 -31
- package/tsconfig.json +25 -20
- package/tsup.config.ts +23 -14
- package/dist/PackageManagerTabs-NVT7G625.mjs +0 -99
- package/dist/SearchDialog-AGVF6JBO.mjs +0 -194
- package/dist/SearchDialog-YPDOM7Q6.css +0 -2847
- package/dist/Video-KNTY5BNO.mjs +0 -6
- package/dist/cache-KNL5B4EE.mjs +0 -12
- package/dist/chunk-7SFUJWTB.mjs +0 -211
- package/dist/chunk-FFBNU6IJ.mjs +0 -386
- package/dist/chunk-FMTOYQLO.mjs +0 -37
- package/dist/chunk-TKLQWU7H.mjs +0 -1920
- package/dist/chunk-Z7JHYNAS.mjs +0 -57
- package/dist/client/index.css +0 -2847
- package/dist/client/ssr.css +0 -2847
- package/dist/types-Dj-bfnC3.d.mts +0 -74
- package/dist/types-Dj-bfnC3.d.ts +0 -74
- package/src/client/theme/components/CodeBlock/CodeBlock.tsx +0 -61
- package/src/client/theme/components/CodeBlock/index.ts +0 -1
- package/src/client/theme/components/PackageManagerTabs/PackageManagerTabs.tsx +0 -131
- package/src/client/theme/components/PackageManagerTabs/index.ts +0 -1
- package/src/client/theme/components/PackageManagerTabs/pkg-tabs.css +0 -64
- package/src/client/theme/components/Playground/Playground.tsx +0 -180
- package/src/client/theme/components/Playground/index.ts +0 -1
- package/src/client/theme/components/Playground/playground.css +0 -238
- package/src/client/theme/components/Video/Video.tsx +0 -84
- package/src/client/theme/components/Video/index.ts +0 -1
- package/src/client/theme/components/Video/video.css +0 -41
- package/src/client/theme/components/mdx/Admonition.tsx +0 -80
- package/src/client/theme/components/mdx/Badge.tsx +0 -31
- package/src/client/theme/components/mdx/Button.tsx +0 -50
- package/src/client/theme/components/mdx/Card.tsx +0 -80
- package/src/client/theme/components/mdx/Field.tsx +0 -60
- package/src/client/theme/components/mdx/FileTree.tsx +0 -229
- package/src/client/theme/components/mdx/List.tsx +0 -57
- package/src/client/theme/components/mdx/Table.tsx +0 -151
- package/src/client/theme/components/mdx/Tabs.tsx +0 -123
- package/src/client/theme/components/mdx/index.ts +0 -27
- package/src/client/theme/components/mdx/mdx-components.css +0 -764
- package/src/client/theme/icons/bun.tsx +0 -62
- package/src/client/theme/icons/deno.tsx +0 -20
- package/src/client/theme/icons/discord.tsx +0 -12
- package/src/client/theme/icons/github.tsx +0 -15
- package/src/client/theme/icons/npm.tsx +0 -13
- package/src/client/theme/icons/pnpm.tsx +0 -72
- package/src/client/theme/icons/twitter.tsx +0 -12
- package/src/client/theme/styles/markdown.css +0 -394
- package/src/client/theme/styles/variables.css +0 -175
- package/src/client/theme/styles.css +0 -39
- package/src/client/theme/ui/Breadcrumbs/Breadcrumbs.tsx +0 -68
- package/src/client/theme/ui/Breadcrumbs/index.ts +0 -1
- package/src/client/theme/ui/CopyMarkdown/CopyMarkdown.tsx +0 -82
- package/src/client/theme/ui/CopyMarkdown/copy-markdown.css +0 -112
- package/src/client/theme/ui/CopyMarkdown/index.ts +0 -1
- package/src/client/theme/ui/ErrorBoundary/ErrorBoundary.tsx +0 -50
- package/src/client/theme/ui/ErrorBoundary/error-boundary.css +0 -55
- package/src/client/theme/ui/ErrorBoundary/index.ts +0 -1
- package/src/client/theme/ui/Footer/footer.css +0 -32
- package/src/client/theme/ui/Head/Head.tsx +0 -69
- package/src/client/theme/ui/Head/index.ts +0 -1
- package/src/client/theme/ui/LanguageSwitcher/LanguageSwitcher.tsx +0 -125
- package/src/client/theme/ui/LanguageSwitcher/index.ts +0 -1
- package/src/client/theme/ui/LanguageSwitcher/language-switcher.css +0 -98
- package/src/client/theme/ui/Layout/Layout.tsx +0 -203
- package/src/client/theme/ui/Layout/base.css +0 -106
- package/src/client/theme/ui/Layout/index.ts +0 -2
- package/src/client/theme/ui/Layout/pagination.css +0 -72
- package/src/client/theme/ui/Layout/responsive.css +0 -47
- package/src/client/theme/ui/Link/Link.tsx +0 -392
- package/src/client/theme/ui/Link/LinkPreview.tsx +0 -59
- package/src/client/theme/ui/Link/index.ts +0 -2
- package/src/client/theme/ui/Link/link-preview.css +0 -48
- package/src/client/theme/ui/Loading/Loading.tsx +0 -10
- package/src/client/theme/ui/Loading/index.ts +0 -1
- package/src/client/theme/ui/Loading/loading.css +0 -30
- package/src/client/theme/ui/Navbar/GithubStars.tsx +0 -27
- package/src/client/theme/ui/Navbar/Navbar.tsx +0 -193
- package/src/client/theme/ui/Navbar/Tabs.tsx +0 -99
- package/src/client/theme/ui/Navbar/index.ts +0 -2
- package/src/client/theme/ui/Navbar/navbar.css +0 -347
- package/src/client/theme/ui/NotFound/NotFound.tsx +0 -19
- package/src/client/theme/ui/NotFound/index.ts +0 -1
- package/src/client/theme/ui/NotFound/not-found.css +0 -64
- package/src/client/theme/ui/OnThisPage/OnThisPage.tsx +0 -244
- package/src/client/theme/ui/OnThisPage/index.ts +0 -1
- package/src/client/theme/ui/OnThisPage/toc.css +0 -152
- package/src/client/theme/ui/PoweredBy/PoweredBy.tsx +0 -18
- package/src/client/theme/ui/PoweredBy/index.ts +0 -1
- package/src/client/theme/ui/PoweredBy/powered-by.css +0 -76
- package/src/client/theme/ui/ProgressBar/ProgressBar.css +0 -17
- package/src/client/theme/ui/ProgressBar/ProgressBar.tsx +0 -51
- package/src/client/theme/ui/ProgressBar/index.ts +0 -1
- package/src/client/theme/ui/SearchDialog/SearchDialog.tsx +0 -209
- package/src/client/theme/ui/SearchDialog/index.ts +0 -1
- package/src/client/theme/ui/SearchDialog/search.css +0 -152
- package/src/client/theme/ui/Sidebar/Sidebar.tsx +0 -244
- package/src/client/theme/ui/Sidebar/index.ts +0 -1
- package/src/client/theme/ui/Sidebar/sidebar.css +0 -230
- package/src/client/theme/ui/ThemeToggle/ThemeToggle.tsx +0 -69
- package/src/client/theme/ui/ThemeToggle/index.ts +0 -1
- package/src/client/theme/ui/VersionSwitcher/VersionSwitcher.tsx +0 -136
- package/src/client/theme/ui/VersionSwitcher/index.ts +0 -1
- package/src/client/utils.ts +0 -49
package/src/node/plugin/index.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { Plugin, ResolvedConfig, loadEnv } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import { injectHtmlMeta } from "./html";
|
|
16
|
-
|
|
17
|
-
export * from "./types";
|
|
1
|
+
import { type Plugin, type ResolvedConfig, loadEnv } from 'vite'
|
|
2
|
+
import { generateRoutes, invalidateRouteCache, invalidateFile } from '../routes'
|
|
3
|
+
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer'
|
|
4
|
+
import { resolveConfig, type BoltdocsConfig, CONFIG_FILES } from '../config'
|
|
5
|
+
import { generateStaticPages } from '../ssg'
|
|
6
|
+
import { normalizePath, isDocFile } from '../utils'
|
|
7
|
+
import path from 'path'
|
|
8
|
+
|
|
9
|
+
import type { BoltdocsPluginOptions } from './types'
|
|
10
|
+
import { generateEntryCode } from './entry'
|
|
11
|
+
import { injectHtmlMeta } from './html'
|
|
12
|
+
import fs from 'fs'
|
|
13
|
+
|
|
14
|
+
export * from './types'
|
|
18
15
|
|
|
19
16
|
/**
|
|
20
17
|
* The core Boltdocs Vite plugin.
|
|
@@ -29,147 +26,228 @@ export function boltdocsPlugin(
|
|
|
29
26
|
options: BoltdocsPluginOptions = {},
|
|
30
27
|
passedConfig?: BoltdocsConfig,
|
|
31
28
|
): Plugin[] {
|
|
32
|
-
const docsDir = path.resolve(process.cwd(), options.docsDir ||
|
|
33
|
-
const normalizedDocsDir = normalizePath(docsDir)
|
|
34
|
-
let config: BoltdocsConfig = passedConfig
|
|
35
|
-
let viteConfig: ResolvedConfig
|
|
36
|
-
let isBuild = false
|
|
29
|
+
const docsDir = path.resolve(process.cwd(), options.docsDir || 'docs')
|
|
30
|
+
const normalizedDocsDir = normalizePath(docsDir)
|
|
31
|
+
let config: BoltdocsConfig = passedConfig!
|
|
32
|
+
let viteConfig: ResolvedConfig
|
|
33
|
+
let isBuild = false
|
|
37
34
|
|
|
38
35
|
const extraVitePlugins =
|
|
39
|
-
config?.plugins?.flatMap((p) => p.vitePlugins || []) || []
|
|
36
|
+
config?.plugins?.flatMap((p) => p.vitePlugins || []) || []
|
|
40
37
|
|
|
41
38
|
return [
|
|
42
39
|
{
|
|
43
|
-
name:
|
|
44
|
-
enforce:
|
|
40
|
+
name: 'vite-plugin-boltdocs',
|
|
41
|
+
enforce: 'pre',
|
|
45
42
|
|
|
46
43
|
async config(userConfig, env) {
|
|
47
|
-
isBuild = env.command ===
|
|
44
|
+
isBuild = env.command === 'build'
|
|
48
45
|
|
|
49
46
|
// Load env variables and inject into process.env so they are available in boltdocs.config.js
|
|
50
|
-
const envDir = userConfig.envDir || process.cwd()
|
|
51
|
-
const envs = loadEnv(env.mode, envDir,
|
|
52
|
-
Object.assign(process.env, envs)
|
|
47
|
+
const envDir = userConfig.envDir || process.cwd()
|
|
48
|
+
const envs = loadEnv(env.mode, envDir, '')
|
|
49
|
+
Object.assign(process.env, envs)
|
|
53
50
|
|
|
54
51
|
// Resolve config async if not already passed
|
|
55
52
|
if (!config) {
|
|
56
|
-
config = await resolveConfig(docsDir)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// If customCss specified in user's config file, use it
|
|
60
|
-
if (!options.customCss && config.themeConfig?.customCss) {
|
|
61
|
-
options.customCss = config.themeConfig.customCss;
|
|
53
|
+
config = await resolveConfig(docsDir)
|
|
62
54
|
}
|
|
63
55
|
|
|
64
56
|
return {
|
|
65
|
-
optimizeDeps: { include: [
|
|
66
|
-
}
|
|
57
|
+
optimizeDeps: { include: ['react', 'react-dom'] },
|
|
58
|
+
}
|
|
67
59
|
},
|
|
68
60
|
|
|
69
61
|
configResolved(resolved) {
|
|
70
|
-
viteConfig = resolved
|
|
62
|
+
viteConfig = resolved
|
|
71
63
|
},
|
|
72
64
|
|
|
73
65
|
configureServer(server) {
|
|
74
|
-
// Explicitly watch config files to trigger server restarts
|
|
66
|
+
// Explicitly watch config files and mdx-components to trigger server restarts or module invalidations
|
|
75
67
|
const configPaths = CONFIG_FILES.map((c) =>
|
|
76
68
|
path.resolve(process.cwd(), c),
|
|
77
|
-
)
|
|
78
|
-
|
|
69
|
+
)
|
|
70
|
+
const compExtensions = ['tsx', 'jsx']
|
|
71
|
+
const layoutCompPaths = compExtensions.map((ext) =>
|
|
72
|
+
path.resolve(docsDir, `layout.${ext}`),
|
|
73
|
+
)
|
|
74
|
+
const mdxCompExtensions = ['tsx', 'ts', 'jsx', 'js']
|
|
75
|
+
const mdxCompPaths = mdxCompExtensions.map((ext) =>
|
|
76
|
+
path.resolve(docsDir, `mdx-components.${ext}`),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
server.watcher.add([
|
|
80
|
+
...configPaths,
|
|
81
|
+
...mdxCompPaths,
|
|
82
|
+
...layoutCompPaths,
|
|
83
|
+
])
|
|
79
84
|
|
|
80
85
|
const handleFileEvent = async (
|
|
81
86
|
file: string,
|
|
82
|
-
type:
|
|
87
|
+
type: 'add' | 'unlink' | 'change',
|
|
83
88
|
) => {
|
|
84
|
-
const normalized = normalizePath(file)
|
|
89
|
+
const normalized = normalizePath(file)
|
|
85
90
|
|
|
86
91
|
// Restart the Vite server if the Boltdocs config changes
|
|
87
92
|
if (CONFIG_FILES.some((c) => normalized.endsWith(c))) {
|
|
88
|
-
server.restart()
|
|
89
|
-
return
|
|
93
|
+
server.restart()
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// If mdx-components file changes, invalidate the virtual module
|
|
98
|
+
if (
|
|
99
|
+
mdxCompExtensions.some((ext) =>
|
|
100
|
+
normalized.endsWith(`mdx-components.${ext}`),
|
|
101
|
+
)
|
|
102
|
+
) {
|
|
103
|
+
const mod = server.moduleGraph.getModuleById(
|
|
104
|
+
'\0virtual:boltdocs-mdx-components',
|
|
105
|
+
)
|
|
106
|
+
if (mod) server.moduleGraph.invalidateModule(mod)
|
|
107
|
+
server.ws.send({ type: 'full-reload' })
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// If layout.tsx/jsx file changes, invalidate the virtual module
|
|
112
|
+
if (
|
|
113
|
+
compExtensions.some((ext) => normalized.endsWith(`layout.${ext}`))
|
|
114
|
+
) {
|
|
115
|
+
const mod = server.moduleGraph.getModuleById(
|
|
116
|
+
'\0virtual:boltdocs-layout',
|
|
117
|
+
)
|
|
118
|
+
if (mod) server.moduleGraph.invalidateModule(mod)
|
|
119
|
+
server.ws.send({ type: 'full-reload' })
|
|
120
|
+
return
|
|
90
121
|
}
|
|
91
122
|
|
|
92
123
|
if (
|
|
93
124
|
!normalized.startsWith(normalizedDocsDir) ||
|
|
94
125
|
!isDocFile(normalized)
|
|
95
126
|
)
|
|
96
|
-
return
|
|
127
|
+
return
|
|
97
128
|
|
|
98
129
|
// Invalidate appropriately
|
|
99
|
-
if (type ===
|
|
100
|
-
invalidateRouteCache()
|
|
130
|
+
if (type === 'add' || type === 'unlink') {
|
|
131
|
+
invalidateRouteCache()
|
|
101
132
|
} else {
|
|
102
|
-
invalidateFile(file)
|
|
133
|
+
invalidateFile(file)
|
|
103
134
|
}
|
|
104
135
|
|
|
105
136
|
// Regenerate and push to client
|
|
106
|
-
const newRoutes = await generateRoutes(docsDir, config)
|
|
137
|
+
const newRoutes = await generateRoutes(docsDir, config)
|
|
107
138
|
|
|
108
139
|
const routesMod = server.moduleGraph.getModuleById(
|
|
109
|
-
|
|
110
|
-
)
|
|
111
|
-
if (routesMod) server.moduleGraph.invalidateModule(routesMod)
|
|
140
|
+
'\0virtual:boltdocs-routes',
|
|
141
|
+
)
|
|
142
|
+
if (routesMod) server.moduleGraph.invalidateModule(routesMod)
|
|
112
143
|
|
|
113
144
|
server.ws.send({
|
|
114
|
-
type:
|
|
115
|
-
event:
|
|
145
|
+
type: 'custom',
|
|
146
|
+
event: 'boltdocs:routes-update',
|
|
116
147
|
data: newRoutes,
|
|
117
|
-
})
|
|
118
|
-
}
|
|
148
|
+
})
|
|
149
|
+
}
|
|
119
150
|
|
|
120
|
-
server.watcher.on(
|
|
121
|
-
server.watcher.on(
|
|
122
|
-
server.watcher.on(
|
|
151
|
+
server.watcher.on('add', (f) => handleFileEvent(f, 'add'))
|
|
152
|
+
server.watcher.on('unlink', (f) => handleFileEvent(f, 'unlink'))
|
|
153
|
+
server.watcher.on('change', (f) => handleFileEvent(f, 'change'))
|
|
123
154
|
},
|
|
124
155
|
|
|
125
156
|
resolveId(id) {
|
|
126
157
|
if (
|
|
127
|
-
id ===
|
|
128
|
-
id ===
|
|
129
|
-
id ===
|
|
158
|
+
id === 'virtual:boltdocs-routes' ||
|
|
159
|
+
id === 'virtual:boltdocs-config' ||
|
|
160
|
+
id === 'virtual:boltdocs-entry' ||
|
|
161
|
+
id === 'virtual:boltdocs-mdx-components' ||
|
|
162
|
+
id === 'virtual:boltdocs-layout'
|
|
130
163
|
) {
|
|
131
|
-
return
|
|
164
|
+
return '\0' + id
|
|
132
165
|
}
|
|
133
166
|
},
|
|
134
167
|
|
|
135
168
|
async load(id) {
|
|
136
|
-
if (id ===
|
|
137
|
-
const routes = await generateRoutes(docsDir, config)
|
|
138
|
-
return `export default ${JSON.stringify(routes, null, 2)}
|
|
169
|
+
if (id === '\0virtual:boltdocs-routes') {
|
|
170
|
+
const routes = await generateRoutes(docsDir, config)
|
|
171
|
+
return `export default ${JSON.stringify(routes, null, 2)};`
|
|
139
172
|
}
|
|
140
|
-
if (id ===
|
|
173
|
+
if (id === '\0virtual:boltdocs-config') {
|
|
141
174
|
const clientConfig = {
|
|
142
175
|
themeConfig: config?.themeConfig,
|
|
176
|
+
integrations: config?.integrations,
|
|
143
177
|
i18n: config?.i18n,
|
|
144
178
|
versions: config?.versions,
|
|
145
179
|
siteUrl: config?.siteUrl,
|
|
146
|
-
}
|
|
147
|
-
return `export default ${JSON.stringify(clientConfig, null, 2)}
|
|
180
|
+
}
|
|
181
|
+
return `export default ${JSON.stringify(clientConfig, null, 2)};`
|
|
182
|
+
}
|
|
183
|
+
if (id === '\0virtual:boltdocs-entry') {
|
|
184
|
+
const code = generateEntryCode(options, config)
|
|
185
|
+
return code
|
|
148
186
|
}
|
|
149
|
-
if (id ===
|
|
150
|
-
const
|
|
151
|
-
|
|
187
|
+
if (id === '\0virtual:boltdocs-mdx-components') {
|
|
188
|
+
const extensions = ['tsx', 'ts', 'jsx', 'js']
|
|
189
|
+
let userMdxPath = null
|
|
190
|
+
|
|
191
|
+
for (const ext of extensions) {
|
|
192
|
+
const p = path.resolve(docsDir, `mdx-components.${ext}`)
|
|
193
|
+
if (fs.existsSync(p)) {
|
|
194
|
+
userMdxPath = p
|
|
195
|
+
break
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (userMdxPath) {
|
|
200
|
+
const normalizedPath = normalizePath(userMdxPath)
|
|
201
|
+
return `import * as components from '${normalizedPath}';
|
|
202
|
+
const mdxComponents = components.default || components;
|
|
203
|
+
export default mdxComponents;
|
|
204
|
+
export * from '${normalizedPath}';`
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return `export default {};`
|
|
208
|
+
}
|
|
209
|
+
if (id === '\0virtual:boltdocs-layout') {
|
|
210
|
+
const extensions = ['tsx', 'jsx']
|
|
211
|
+
let userLayoutPath = null
|
|
212
|
+
|
|
213
|
+
for (const ext of extensions) {
|
|
214
|
+
const p = path.resolve(docsDir, `layout.${ext}`)
|
|
215
|
+
if (fs.existsSync(p)) {
|
|
216
|
+
userLayoutPath = p
|
|
217
|
+
break
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (userLayoutPath) {
|
|
222
|
+
const normalizedPath = normalizePath(userLayoutPath)
|
|
223
|
+
return `import UserLayout from '${normalizedPath}';
|
|
224
|
+
export default UserLayout;`
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// No user layout — return the built-in default
|
|
228
|
+
return `import { DefaultLayout } from 'boltdocs/client';
|
|
229
|
+
export default DefaultLayout;`
|
|
152
230
|
}
|
|
153
231
|
},
|
|
154
232
|
|
|
155
233
|
transformIndexHtml: {
|
|
156
|
-
order:
|
|
234
|
+
order: 'pre',
|
|
157
235
|
handler(html) {
|
|
158
|
-
return injectHtmlMeta(html, config)
|
|
236
|
+
return injectHtmlMeta(html, config)
|
|
159
237
|
},
|
|
160
238
|
},
|
|
161
239
|
|
|
162
240
|
async closeBundle() {
|
|
163
|
-
if (!isBuild) return
|
|
241
|
+
if (!isBuild) return
|
|
164
242
|
const outDir = viteConfig?.build?.outDir
|
|
165
243
|
? path.resolve(viteConfig.root, viteConfig.build.outDir)
|
|
166
|
-
: path.resolve(process.cwd(),
|
|
244
|
+
: path.resolve(process.cwd(), 'dist')
|
|
167
245
|
|
|
168
|
-
const docsDirName = path.basename(docsDir ||
|
|
169
|
-
await generateStaticPages({ docsDir, docsDirName, outDir, config })
|
|
246
|
+
const docsDirName = path.basename(docsDir || 'docs')
|
|
247
|
+
await generateStaticPages({ docsDir, docsDirName, outDir, config })
|
|
170
248
|
|
|
171
|
-
const { flushCache } = await import(
|
|
172
|
-
await flushCache()
|
|
249
|
+
const { flushCache } = await import('../cache')
|
|
250
|
+
await flushCache()
|
|
173
251
|
},
|
|
174
252
|
},
|
|
175
253
|
ViteImageOptimizer({
|
|
@@ -183,12 +261,11 @@ export function boltdocsPlugin(
|
|
|
183
261
|
multipass: true,
|
|
184
262
|
plugins: [
|
|
185
263
|
{
|
|
186
|
-
name:
|
|
187
|
-
params: { overrides: { removeViewBox: false } },
|
|
264
|
+
name: 'preset-default',
|
|
188
265
|
},
|
|
189
266
|
] as any,
|
|
190
267
|
},
|
|
191
268
|
}),
|
|
192
269
|
...extraVitePlugins.filter((p): p is Plugin => !!p),
|
|
193
|
-
]
|
|
270
|
+
]
|
|
194
271
|
}
|
package/src/node/plugin/types.ts
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export interface BoltdocsPluginOptions {
|
|
5
5
|
/** The root directory containing markdown files (default: 'docs') */
|
|
6
|
-
docsDir?: string
|
|
6
|
+
docsDir?: string
|
|
7
7
|
/** Path to a custom home page component (relative to project root) to render at '/' */
|
|
8
|
-
homePage?: string
|
|
9
|
-
/** Path to a custom CSS file to override theme variables. Can also be set in boltdocs.config.js */
|
|
10
|
-
customCss?: string;
|
|
8
|
+
homePage?: string
|
|
11
9
|
}
|
package/src/node/routes/cache.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { FileCache } from
|
|
2
|
-
import { ParsedDocFile } from
|
|
1
|
+
import { FileCache } from '../cache'
|
|
2
|
+
import type { ParsedDocFile } from './types'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Persistent cache for parsed documentation files.
|
|
6
6
|
* Saves data to `.boltdocs/routes.json`.
|
|
7
7
|
*/
|
|
8
|
-
const docCache = new FileCache<ParsedDocFile>({ name:
|
|
8
|
+
const docCache = new FileCache<ParsedDocFile>({ name: 'routes' })
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Invalidate all cached routes.
|
|
12
12
|
* Typically called when a file is added or deleted, requiring a complete route rebuild.
|
|
13
13
|
*/
|
|
14
14
|
export function invalidateRouteCache(): void {
|
|
15
|
-
docCache.invalidateAll()
|
|
15
|
+
docCache.invalidateAll()
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -22,7 +22,7 @@ export function invalidateRouteCache(): void {
|
|
|
22
22
|
* @param filePath - The absolute path of the file to invalidate
|
|
23
23
|
*/
|
|
24
24
|
export function invalidateFile(filePath: string): void {
|
|
25
|
-
docCache.invalidate(filePath)
|
|
25
|
+
docCache.invalidate(filePath)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export { docCache }
|
|
28
|
+
export { docCache }
|