-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
78 lines (71 loc) · 2.06 KB
/
index.ts
File metadata and controls
78 lines (71 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import fs from 'node:fs'
import path from 'node:path'
import { addTrailingSlash, type RspressPlugin } from '@rspress/shared'
import { ACP_BASE, type DoomSite } from '../../shared/index.js'
import type { ExportItem } from '../../types.js'
import { baseResolve, pkgResolve } from '../../utils/index.js'
const globalComponentsDir = baseResolve('global')
const componentsDir = baseResolve('runtime/components')
export interface GlobalPluginOptions {
version?: string
download?: boolean
}
export interface GlobalVirtual extends GlobalPluginOptions {
userBase?: string
prefix?: string
sites?: DoomSite[]
export?: ExportItem[]
}
// @internal
declare module 'doom-@global-virtual' {
const virtual: GlobalVirtual
}
export const globalPlugin = ({
version,
download,
}: GlobalPluginOptions): RspressPlugin => {
return {
name: 'doom-global',
globalStyles: pkgResolve('styles/global.scss'),
globalUIComponents: fs
.readdirSync(globalComponentsDir, 'utf8')
.map((component) =>
path.resolve(globalComponentsDir, component, 'index'),
),
markdown: {
globalComponents: fs
.readdirSync(componentsDir)
.filter((file) => {
const basename = path.basename(file, path.extname(file))
return (
!basename.startsWith('_') &&
!basename.endsWith('.d') &&
basename !== 'index'
)
})
.map((file) => path.resolve(componentsDir, file)),
},
addRuntimeModules(config, isProd) {
return {
'doom-@global-virtual': `export default ${JSON.stringify(
{
userBase: config.userBase,
prefix: config.prefix,
version,
download,
sites: config.sites?.map((site) => ({
...site,
base: addTrailingSlash(
site.base || (site.name === 'acp' ? ACP_BASE : ''),
),
version: site.version,
})),
export: config.export,
},
null,
isProd ? 0 : 2,
)}`,
}
},
}
}