boltdocs 2.5.5 → 2.6.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.
Files changed (166) hide show
  1. package/bin/boltdocs.js +2 -2
  2. package/dist/client/index.cjs +6 -0
  3. package/dist/client/index.d.cts +1560 -0
  4. package/dist/client/index.d.ts +1219 -922
  5. package/dist/client/index.js +6 -1
  6. package/dist/client/theme/neutral.css +428 -0
  7. package/dist/node/cli-entry.cjs +8 -0
  8. package/dist/node/cli-entry.d.cts +2 -0
  9. package/dist/node/cli-entry.d.mts +2 -1
  10. package/dist/node/cli-entry.mjs +7 -5
  11. package/dist/node/index.cjs +6 -0
  12. package/dist/node/index.d.cts +519 -0
  13. package/dist/node/index.d.mts +374 -422
  14. package/dist/node/index.mjs +6 -1
  15. package/dist/node-BgvNl2Ay.mjs +89 -0
  16. package/dist/node-vkbb0MK7.cjs +89 -0
  17. package/dist/package-CR0HF9x3.mjs +6 -0
  18. package/dist/package-Dgmsc_l5.cjs +6 -0
  19. package/dist/search-dialog-3lvKsbVG.js +6 -0
  20. package/dist/search-dialog-DMK5OpgH.cjs +6 -0
  21. package/dist/use-search-C9bxCqfF.js +6 -0
  22. package/dist/use-search-DcfZSunO.cjs +6 -0
  23. package/package.json +26 -25
  24. package/src/client/app/config-context.tsx +38 -5
  25. package/src/client/app/doc-page.tsx +34 -0
  26. package/src/client/app/mdx-component.tsx +2 -3
  27. package/src/client/app/mdx-components-context.tsx +27 -2
  28. package/src/client/app/routes-context.tsx +34 -0
  29. package/src/client/app/scroll-handler.tsx +7 -4
  30. package/src/client/app/theme-context.tsx +71 -67
  31. package/src/client/components/default-layout.tsx +34 -33
  32. package/src/client/components/docs-layout.tsx +1 -2
  33. package/src/client/components/icons-dev.tsx +36 -5
  34. package/src/client/components/mdx/admonition.tsx +11 -27
  35. package/src/client/components/mdx/badge.tsx +1 -1
  36. package/src/client/components/mdx/button.tsx +3 -3
  37. package/src/client/components/mdx/card.tsx +1 -1
  38. package/src/client/components/mdx/code-block.tsx +90 -80
  39. package/src/client/components/mdx/component-preview.tsx +1 -5
  40. package/src/client/components/mdx/component-props.tsx +1 -1
  41. package/src/client/components/mdx/field.tsx +4 -5
  42. package/src/client/components/mdx/file-tree.tsx +6 -3
  43. package/src/client/components/mdx/hooks/use-code-block.ts +2 -2
  44. package/src/client/components/mdx/image.tsx +1 -1
  45. package/src/client/components/mdx/link.tsx +2 -2
  46. package/src/client/components/mdx/list.tsx +1 -1
  47. package/src/client/components/mdx/table.tsx +1 -1
  48. package/src/client/components/mdx/tabs.tsx +1 -1
  49. package/src/client/components/primitives/breadcrumbs.tsx +1 -7
  50. package/src/client/components/primitives/button-group.tsx +1 -1
  51. package/src/client/components/primitives/button.tsx +1 -1
  52. package/src/client/components/primitives/code-block.tsx +113 -0
  53. package/src/client/components/primitives/link.tsx +23 -41
  54. package/src/client/components/primitives/menu.tsx +5 -6
  55. package/src/client/components/primitives/navbar.tsx +6 -18
  56. package/src/client/components/primitives/navigation-menu.tsx +4 -4
  57. package/src/client/components/primitives/on-this-page.tsx +6 -10
  58. package/src/client/components/primitives/page-nav.tsx +4 -9
  59. package/src/client/components/primitives/popover.tsx +1 -1
  60. package/src/client/components/primitives/search-dialog.tsx +3 -6
  61. package/src/client/components/primitives/sidebar.tsx +80 -22
  62. package/src/client/components/primitives/skeleton.tsx +1 -1
  63. package/src/client/components/primitives/tabs.tsx +4 -11
  64. package/src/client/components/primitives/tooltip.tsx +3 -3
  65. package/src/client/components/ui-base/breadcrumbs.tsx +4 -6
  66. package/src/client/components/ui-base/copy-markdown.tsx +2 -7
  67. package/src/client/components/ui-base/github-stars.tsx +2 -2
  68. package/src/client/components/ui-base/head.tsx +58 -51
  69. package/src/client/components/ui-base/loading.tsx +2 -2
  70. package/src/client/components/ui-base/navbar.tsx +12 -14
  71. package/src/client/components/ui-base/not-found.tsx +1 -1
  72. package/src/client/components/ui-base/on-this-page.tsx +6 -6
  73. package/src/client/components/ui-base/page-nav.tsx +4 -8
  74. package/src/client/components/ui-base/search-dialog.tsx +10 -8
  75. package/src/client/components/ui-base/sidebar.tsx +76 -23
  76. package/src/client/components/ui-base/tabs.tsx +9 -8
  77. package/src/client/components/ui-base/theme-toggle.tsx +2 -2
  78. package/src/client/hooks/use-i18n.ts +3 -3
  79. package/src/client/hooks/use-localized-to.ts +1 -1
  80. package/src/client/hooks/use-navbar.ts +8 -6
  81. package/src/client/hooks/use-routes.ts +19 -11
  82. package/src/client/hooks/use-search.ts +1 -1
  83. package/src/client/hooks/use-sidebar.ts +48 -2
  84. package/src/client/hooks/use-tabs.ts +6 -2
  85. package/src/client/hooks/use-version.ts +3 -3
  86. package/src/client/index.ts +22 -22
  87. package/src/client/ssg/boltdocs-shell.tsx +127 -0
  88. package/src/client/ssg/create-routes.tsx +179 -0
  89. package/src/client/ssg/index.ts +3 -0
  90. package/src/client/ssg/mdx-page.tsx +37 -0
  91. package/src/client/store/boltdocs-context.tsx +66 -0
  92. package/src/client/theme/neutral.css +90 -50
  93. package/src/client/types.ts +5 -33
  94. package/src/client/utils/react-to-text.ts +34 -0
  95. package/CHANGELOG.md +0 -98
  96. package/dist/cache-3FOEPC2P.mjs +0 -1
  97. package/dist/chunk-5B5NKOW6.mjs +0 -77
  98. package/dist/chunk-J2PTDWZM.mjs +0 -1
  99. package/dist/chunk-TP5KMRD3.mjs +0 -1
  100. package/dist/chunk-Y4RE5KI7.mjs +0 -1
  101. package/dist/client/index.d.mts +0 -1263
  102. package/dist/client/index.mjs +0 -1
  103. package/dist/client/ssr.d.mts +0 -78
  104. package/dist/client/ssr.d.ts +0 -78
  105. package/dist/client/ssr.js +0 -1
  106. package/dist/client/ssr.mjs +0 -1
  107. package/dist/node/cli-entry.d.ts +0 -1
  108. package/dist/node/cli-entry.js +0 -82
  109. package/dist/node/index.d.ts +0 -567
  110. package/dist/node/index.js +0 -77
  111. package/dist/package-QFIAETHR.mjs +0 -1
  112. package/dist/search-dialog-O6VLVSOA.mjs +0 -1
  113. package/src/client/app/index.tsx +0 -345
  114. package/src/client/app/mdx-page.tsx +0 -15
  115. package/src/client/app/preload.tsx +0 -66
  116. package/src/client/app/router.tsx +0 -30
  117. package/src/client/integrations/codesandbox.ts +0 -179
  118. package/src/client/integrations/index.ts +0 -1
  119. package/src/client/ssr.tsx +0 -65
  120. package/src/client/store/use-boltdocs-store.ts +0 -44
  121. package/src/node/cache.ts +0 -408
  122. package/src/node/cli/build.ts +0 -53
  123. package/src/node/cli/dev.ts +0 -22
  124. package/src/node/cli/doctor.ts +0 -243
  125. package/src/node/cli/index.ts +0 -9
  126. package/src/node/cli/ui.ts +0 -54
  127. package/src/node/cli-entry.ts +0 -24
  128. package/src/node/config.ts +0 -382
  129. package/src/node/errors.ts +0 -44
  130. package/src/node/index.ts +0 -84
  131. package/src/node/mdx/cache.ts +0 -12
  132. package/src/node/mdx/highlighter.ts +0 -47
  133. package/src/node/mdx/index.ts +0 -122
  134. package/src/node/mdx/rehype-shiki.ts +0 -62
  135. package/src/node/mdx/remark-code-meta.ts +0 -35
  136. package/src/node/mdx/remark-shiki.ts +0 -61
  137. package/src/node/plugin/entry.ts +0 -87
  138. package/src/node/plugin/html.ts +0 -99
  139. package/src/node/plugin/index.ts +0 -478
  140. package/src/node/plugin/types.ts +0 -9
  141. package/src/node/plugins/index.ts +0 -17
  142. package/src/node/plugins/plugin-errors.ts +0 -62
  143. package/src/node/plugins/plugin-lifecycle.ts +0 -117
  144. package/src/node/plugins/plugin-sandbox.ts +0 -59
  145. package/src/node/plugins/plugin-store.ts +0 -54
  146. package/src/node/plugins/plugin-types.ts +0 -107
  147. package/src/node/plugins/plugin-validator.ts +0 -105
  148. package/src/node/routes/cache.ts +0 -28
  149. package/src/node/routes/index.ts +0 -293
  150. package/src/node/routes/parser.ts +0 -262
  151. package/src/node/routes/sorter.ts +0 -42
  152. package/src/node/routes/types.ts +0 -61
  153. package/src/node/schema/config.ts +0 -195
  154. package/src/node/schema/frontmatter.ts +0 -17
  155. package/src/node/search/index.ts +0 -55
  156. package/src/node/security/constants/index.ts +0 -10
  157. package/src/node/security/csp.ts +0 -31
  158. package/src/node/security/headers.ts +0 -27
  159. package/src/node/ssg/index.ts +0 -205
  160. package/src/node/ssg/meta.ts +0 -33
  161. package/src/node/ssg/options.ts +0 -15
  162. package/src/node/ssg/robots.ts +0 -53
  163. package/src/node/ssg/sitemap.ts +0 -55
  164. package/src/node/utils.ts +0 -349
  165. package/tsconfig.json +0 -26
  166. package/tsup.config.ts +0 -56
package/src/node/cache.ts DELETED
@@ -1,408 +0,0 @@
1
- import fs from 'fs'
2
- import path from 'path'
3
- import crypto from 'crypto'
4
- import zlib from 'zlib'
5
- import { promisify } from 'util'
6
- import { getFileMtime } from './utils'
7
-
8
- const writeFile = promisify(fs.writeFile)
9
- const readFile = promisify(fs.readFile)
10
- const mkdir = promisify(fs.mkdir)
11
- const rename = promisify(fs.rename)
12
- const unlink = promisify(fs.unlink)
13
-
14
- /**
15
- * Configuration constants for the caching system.
16
- */
17
- const CACHE_DIR = process.env.BOLTDOCS_CACHE_DIR || '.boltdocs'
18
- const ASSETS_DIR = 'assets'
19
- const SHARDS_DIR = 'shards'
20
-
21
- /**
22
- * Default limits for the caching system.
23
- */
24
- const DEFAULT_LRU_LIMIT = parseInt(
25
- process.env.BOLTDOCS_CACHE_LRU_LIMIT || '2000',
26
- 10,
27
- )
28
- const DEFAULT_COMPRESS = process.env.BOLTDOCS_CACHE_COMPRESS !== '0'
29
-
30
- /**
31
- * Simple LRU cache implementation to prevent memory leaks.
32
- */
33
- class LRUCache<K, V> {
34
- private cache = new Map<K, V>()
35
- constructor(private limit: number) {}
36
-
37
- get(key: K): V | undefined {
38
- const val = this.cache.get(key)
39
- if (val !== undefined) {
40
- this.cache.delete(key)
41
- this.cache.set(key, val)
42
- }
43
- return val
44
- }
45
-
46
- set(key: K, value: V): void {
47
- if (this.cache.has(key)) {
48
- this.cache.delete(key)
49
- } else if (this.cache.size >= this.limit) {
50
- const firstKey = this.cache.keys().next().value
51
- if (firstKey !== undefined) {
52
- this.cache.delete(firstKey)
53
- }
54
- }
55
- this.cache.set(key, value)
56
- }
57
-
58
- get size() {
59
- return this.cache.size
60
- }
61
- clear() {
62
- this.cache.clear()
63
- }
64
- }
65
-
66
- /**
67
- * Simple background task queue to prevent blocking the main thread during IO.
68
- */
69
- class BackgroundQueue {
70
- private queue: Promise<any> = Promise.resolve()
71
- private pendingCount = 0
72
-
73
- add(task: () => Promise<any>) {
74
- this.pendingCount++
75
- this.queue = this.queue.then(task).finally(() => {
76
- this.pendingCount--
77
- })
78
- }
79
-
80
- async flush() {
81
- await this.queue
82
- }
83
-
84
- get pending() {
85
- return this.pendingCount
86
- }
87
- }
88
-
89
- const backgroundQueue = new BackgroundQueue()
90
-
91
- /**
92
- * Generic file-based cache with per-file granularity and asynchronous persistence.
93
- */
94
- export class FileCache<T> {
95
- private entries = new Map<string, { data: T; mtime: number }>()
96
- private readonly cachePath: string | null = null
97
- private readonly compress: boolean
98
-
99
- constructor(
100
- options: { name?: string; root?: string; compress?: boolean } = {},
101
- ) {
102
- this.compress =
103
- options.compress !== undefined ? options.compress : DEFAULT_COMPRESS
104
- if (options.name) {
105
- const root = options.root || process.cwd()
106
- const ext = this.compress ? 'json.gz' : 'json'
107
- this.cachePath = path.resolve(root, CACHE_DIR, `${options.name}.${ext}`)
108
- }
109
- }
110
-
111
- /**
112
- * Loads the cache. Synchronous for startup simplicity but uses fast I/O.
113
- */
114
- load(): void {
115
- if (process.env.BOLTDOCS_NO_CACHE === '1') return
116
- if (!this.cachePath || !fs.existsSync(this.cachePath)) return
117
-
118
- try {
119
- let raw = fs.readFileSync(this.cachePath)
120
- if (this.cachePath.endsWith('.gz')) {
121
- raw = zlib.gunzipSync(raw)
122
- }
123
- const data = JSON.parse(raw.toString('utf-8'))
124
- this.entries = new Map(Object.entries(data))
125
- } catch (e) {
126
- // Fallback: ignore cache errors
127
- }
128
- }
129
-
130
- /**
131
- * Saves the cache in the background.
132
- */
133
- save(): void {
134
- if (process.env.BOLTDOCS_NO_CACHE === '1') return
135
- if (!this.cachePath) return
136
-
137
- const data = Object.fromEntries(this.entries)
138
- const content = JSON.stringify(data)
139
- const target = this.cachePath
140
- const useCompress = this.compress
141
-
142
- backgroundQueue.add(async () => {
143
- try {
144
- await mkdir(path.dirname(target), { recursive: true })
145
- let buffer = Buffer.from(content)
146
- if (useCompress) {
147
- buffer = zlib.gzipSync(buffer)
148
- }
149
- const tempPath = `${target}.${crypto.randomBytes(4).toString('hex')}.tmp`
150
- await writeFile(tempPath, buffer)
151
- await rename(tempPath, target)
152
- } catch (e) {
153
- // Fallback: critical error logging skipped for performance
154
- }
155
- })
156
- }
157
-
158
- get(filePath: string): T | null {
159
- const entry = this.entries.get(filePath)
160
- if (!entry) return null
161
- if (getFileMtime(filePath) !== entry.mtime) return null
162
- return entry.data
163
- }
164
-
165
- set(filePath: string, data: T): void {
166
- this.entries.set(filePath, {
167
- data,
168
- mtime: getFileMtime(filePath),
169
- })
170
- }
171
-
172
- isValid(filePath: string): boolean {
173
- const entry = this.entries.get(filePath)
174
- if (!entry) return false
175
- return getFileMtime(filePath) === entry.mtime
176
- }
177
-
178
- invalidate(filePath: string): void {
179
- this.entries.delete(filePath)
180
- }
181
-
182
- invalidateAll(): void {
183
- this.entries.clear()
184
- }
185
-
186
- pruneStale(currentFiles: Set<string>): void {
187
- for (const key of this.entries.keys()) {
188
- if (!currentFiles.has(key)) {
189
- this.entries.delete(key)
190
- }
191
- }
192
- }
193
-
194
- get size(): number {
195
- return this.entries.size
196
- }
197
-
198
- async flush() {
199
- await backgroundQueue.flush()
200
- }
201
- }
202
-
203
- /**
204
- * Sharded Cache: Optimized for large-scale data (like MDX transformations).
205
- * Uses a memory index and individual files for each entry to avoid massive JSON parsing.
206
- */
207
- export class TransformCache {
208
- private index = new Map<string, string>() // key -> hash
209
- private memoryCache = new LRUCache<string, string>(DEFAULT_LRU_LIMIT)
210
- private readonly baseDir: string
211
- private readonly shardsDir: string
212
- private readonly indexPath: string
213
-
214
- constructor(name: string, root: string = process.cwd()) {
215
- this.baseDir = path.resolve(root, CACHE_DIR, `transform-${name}`)
216
- this.shardsDir = path.resolve(this.baseDir, SHARDS_DIR)
217
- this.indexPath = path.resolve(this.baseDir, 'index.json')
218
- }
219
-
220
- /**
221
- * Loads the index into memory.
222
- */
223
- load(): void {
224
- if (process.env.BOLTDOCS_NO_CACHE === '1') return
225
- if (!fs.existsSync(this.indexPath)) return
226
-
227
- try {
228
- const data = fs.readFileSync(this.indexPath, 'utf-8')
229
- this.index = new Map(Object.entries(JSON.parse(data)))
230
- } catch (e) {
231
- // Index might be corrupt, ignore
232
- }
233
- }
234
-
235
- /**
236
- * Persists the index in background.
237
- */
238
- save(): void {
239
- if (process.env.BOLTDOCS_NO_CACHE === '1') return
240
- const data = JSON.stringify(Object.fromEntries(this.index))
241
- const target = this.indexPath
242
-
243
- backgroundQueue.add(async () => {
244
- await mkdir(path.dirname(target), { recursive: true })
245
- await writeFile(target, data)
246
- })
247
- }
248
-
249
- /**
250
- * Batch Read: Retrieves multiple transformation results concurrently.
251
- */
252
- async getMany(keys: string[]): Promise<Map<string, string>> {
253
- const results = new Map<string, string>()
254
- const toLoad: string[] = []
255
-
256
- for (const key of keys) {
257
- const mem = this.memoryCache.get(key)
258
- if (mem) results.set(key, mem)
259
- else if (this.index.has(key)) toLoad.push(key)
260
- }
261
-
262
- if (toLoad.length > 0) {
263
- const shards = await Promise.all(
264
- toLoad.map(async (key) => {
265
- const hash = this.index.get(key)!
266
- const shardPath = path.resolve(this.shardsDir, `${hash}.gz`)
267
- try {
268
- const compressed = await readFile(shardPath)
269
- const decompressed = zlib.gunzipSync(compressed).toString('utf-8')
270
- this.memoryCache.set(key, decompressed)
271
- return { key, val: decompressed }
272
- } catch (e) {
273
- return null
274
- }
275
- }),
276
- )
277
-
278
- for (const s of shards) {
279
- if (s) results.set(s.key, s.val)
280
- }
281
- }
282
-
283
- return results
284
- }
285
-
286
- /**
287
- * Retrieves a cached transformation. Fast lookup via index, lazy loading from disk.
288
- */
289
- get(key: string): string | null {
290
- // 1. Check memory first (LRU)
291
- const mem = this.memoryCache.get(key)
292
- if (mem) return mem
293
-
294
- // 2. Check index
295
- const hash = this.index.get(key)
296
- if (!hash) return null
297
-
298
- // 3. Load from shard (synchronous read for Vite's transform hook compatibility)
299
- const shardPath = path.resolve(this.shardsDir, `${hash}.gz`)
300
- if (!fs.existsSync(shardPath)) return null
301
-
302
- try {
303
- const compressed = fs.readFileSync(shardPath)
304
- const decompressed = zlib.gunzipSync(compressed).toString('utf-8')
305
- this.memoryCache.set(key, decompressed)
306
- return decompressed
307
- } catch (e) {
308
- return null
309
- }
310
- }
311
-
312
- /**
313
- * Stores a transformation result.
314
- */
315
- set(key: string, result: string): void {
316
- const hash = crypto.createHash('md5').update(result).digest('hex')
317
- this.index.set(key, hash)
318
- this.memoryCache.set(key, result)
319
-
320
- const shardPath = path.resolve(this.shardsDir, `${hash}.gz`)
321
-
322
- // Background write shard
323
- backgroundQueue.add(async () => {
324
- if (fs.existsSync(shardPath)) return // Already exists
325
- await mkdir(this.shardsDir, { recursive: true })
326
-
327
- const compressed = zlib.gzipSync(Buffer.from(result))
328
- const tempPath = `${shardPath}.${crypto.randomBytes(4).toString('hex')}.tmp`
329
- await writeFile(tempPath, compressed)
330
- await rename(tempPath, shardPath)
331
- })
332
- }
333
-
334
- get size() {
335
- return this.index.size
336
- }
337
-
338
- async flush() {
339
- await backgroundQueue.flush()
340
- }
341
- }
342
-
343
- /**
344
- * Specialized cache for processed assets (e.g., optimized images).
345
- */
346
- export class AssetCache {
347
- private readonly assetsDir: string
348
-
349
- constructor(root: string = process.cwd()) {
350
- this.assetsDir = path.resolve(root, CACHE_DIR, ASSETS_DIR)
351
- }
352
-
353
- private getFileHash(filePath: string): string {
354
- return crypto
355
- .createHash('md5')
356
- .update(fs.readFileSync(filePath))
357
- .digest('hex')
358
- }
359
-
360
- get(sourcePath: string, cacheKey: string): string | null {
361
- if (!fs.existsSync(sourcePath)) return null
362
- const sourceHash = this.getFileHash(sourcePath)
363
- const cachedPath = this.getCachedPath(
364
- sourcePath,
365
- `${cacheKey}-${sourceHash}`,
366
- )
367
- return fs.existsSync(cachedPath) ? cachedPath : null
368
- }
369
-
370
- set(sourcePath: string, cacheKey: string, content: Buffer | string): void {
371
- const sourceHash = this.getFileHash(sourcePath)
372
- const cachedPath = this.getCachedPath(
373
- sourcePath,
374
- `${cacheKey}-${sourceHash}`,
375
- )
376
-
377
- backgroundQueue.add(async () => {
378
- await mkdir(this.assetsDir, { recursive: true })
379
- const tempPath = `${cachedPath}.${crypto.randomBytes(4).toString('hex')}.tmp`
380
- await writeFile(tempPath, content)
381
- await rename(tempPath, cachedPath)
382
- })
383
- }
384
-
385
- private getCachedPath(sourcePath: string, cacheKey: string): string {
386
- const ext = path.extname(sourcePath)
387
- const name = path.basename(sourcePath, ext)
388
- const safeKey = cacheKey.replace(/[^a-z0-9]/gi, '-').toLowerCase()
389
- return path.join(this.assetsDir, `${name}.${safeKey}${ext}`)
390
- }
391
-
392
- clear(): void {
393
- if (fs.existsSync(this.assetsDir)) {
394
- fs.rmSync(this.assetsDir, { recursive: true, force: true })
395
- }
396
- }
397
-
398
- async flush() {
399
- await backgroundQueue.flush()
400
- }
401
- }
402
-
403
- /**
404
- * Flushes all pending background cache operations.
405
- */
406
- export async function flushCache() {
407
- await backgroundQueue.flush()
408
- }
@@ -1,53 +0,0 @@
1
- import { build, preview } from 'vite'
2
- import { createViteConfig, resolveConfig } from '../index'
3
- import { getHtmlTemplate } from '../plugin/html'
4
- import path from 'path'
5
- import fs from 'fs'
6
- import * as ui from './ui'
7
-
8
- /**
9
- * Logic for the `boltdocs build` command.
10
- * Prepares the production bundle and handles dynamic index.html generation.
11
- *
12
- * @param root - The project root directory
13
- */
14
- export async function buildAction(root: string = process.cwd()) {
15
- let createdIndexHtml = false
16
- const indexPath = path.resolve(root, 'index.html')
17
-
18
- try {
19
- if (!fs.existsSync(indexPath)) {
20
- const config = await resolveConfig('docs', root)
21
- fs.writeFileSync(indexPath, getHtmlTemplate(config), 'utf-8')
22
- createdIndexHtml = true
23
- }
24
-
25
- const viteConfig = await createViteConfig(root, 'production')
26
- await build(viteConfig)
27
- ui.success('Build completed successfully.')
28
- } catch (e) {
29
- ui.error('Build failed:', e)
30
- process.exit(1)
31
- } finally {
32
- if (createdIndexHtml && fs.existsSync(indexPath)) {
33
- fs.unlinkSync(indexPath)
34
- }
35
- }
36
- }
37
-
38
- /**
39
- * Logic for the `boltdocs preview` command.
40
- * Serves the production build from the disk.
41
- *
42
- * @param root - The project root directory
43
- */
44
- export async function previewAction(root: string = process.cwd()) {
45
- try {
46
- const viteConfig = await createViteConfig(root, 'production')
47
- const previewServer = await preview(viteConfig)
48
- previewServer.printUrls()
49
- } catch (e) {
50
- ui.error('Failed to start preview server:', e)
51
- process.exit(1)
52
- }
53
- }
@@ -1,22 +0,0 @@
1
- import { createServer } from 'vite'
2
- import { createViteConfig } from '../index'
3
- import * as ui from './ui'
4
-
5
- /**
6
- * Logic for the `boltdocs dev` command.
7
- * Starts a Vite development server and sets up HMR.
8
- *
9
- * @param root - The project root directory
10
- */
11
- export async function devAction(root: string = process.cwd()) {
12
- try {
13
- const viteConfig = await createViteConfig(root, 'development')
14
- const server = await createServer(viteConfig)
15
- await server.listen()
16
- server.printUrls()
17
- server.bindCLIShortcuts({ print: true })
18
- } catch (e) {
19
- ui.error('Failed to start dev server:', e)
20
- process.exit(1)
21
- }
22
- }