-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathindex.js
47 lines (38 loc) · 1.61 KB
/
index.js
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
const {
fs, path,
datatypes: { isPlainObject }
} = require('@vuepress/shared-utils')
module.exports = (options, ctx) => ({
name: '@vuepress/internal-palette',
async ready () {
// 1. enable config.styl globally.
const configFile = path.resolve(__dirname, '../../app/style/config.styl')
if (!ctx.siteConfig.stylus) {
ctx.siteConfig.stylus = {
import: [configFile]
}
} else if (isPlainObject(ctx.siteConfig.stylus)) {
ctx.siteConfig.stylus.import = (ctx.siteConfig.stylus.import || []).concat([configFile])
}
// 2. write palette.styl
const { sourceDir, writeTemp } = ctx
const themePalette = path.resolve(ctx.themeAPI.theme.path, 'styles/palette.styl')
const userPalette = path.resolve(sourceDir, '.vuepress/styles/palette.styl')
const themePaletteContent = fs.existsSync(themePalette)
? `@import(${JSON.stringify(themePalette.replace(/[\\]+/g, '/'))})`
: ''
const userPaletteContent = fs.existsSync(userPalette)
? `@import(${JSON.stringify(userPalette.replace(/[\\]+/g, '/'))})`
: ''
// user's palette can override theme's palette.
let paletteContent = themePaletteContent + userPaletteContent
if (ctx.themeAPI.existsParentTheme) {
const parentThemePalette = path.resolve(ctx.themeAPI.parentTheme.path, 'styles/palette.styl')
const parentThemePaletteContent = fs.existsSync(parentThemePalette)
? `@import(${JSON.stringify(parentThemePalette.replace(/[\\]+/g, '/'))})`
: ''
paletteContent = parentThemePaletteContent + paletteContent
}
await writeTemp('palette.styl', paletteContent)
}
})