-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathindex.js
45 lines (34 loc) · 1.52 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
const { fs, path, logger, chalk } = require('@vuepress/shared-utils')
/**
* @param options
* @param {AppContext} ctx
*/
module.exports = (options, ctx) => ({
name: '@vuepress/internal-style',
enhanceAppFiles: [path.resolve(__dirname, 'client.js')],
async ready () {
const { sourceDir, writeTemp, themeAPI } = ctx
const overridePath = path.resolve(sourceDir, '.vuepress/override.styl')
const hasUserOverride = fs.existsSync(overridePath)
if (hasUserOverride) {
logger.tip(`${chalk.magenta('override.styl')} has been deprecated from v1.0.0, using ${chalk.cyan('.vuepress/styles/palette.styl')} instead.\n`)
}
const themeStyle = path.resolve(themeAPI.theme.path, 'styles/index.styl')
const userStyle = path.resolve(sourceDir, '.vuepress/styles/index.styl')
const themeStyleContent = fs.existsSync(themeStyle)
? `@import(${JSON.stringify(themeStyle.replace(/[\\]+/g, '/'))})`
: ''
const userStyleContent = fs.existsSync(userStyle)
? `@import(${JSON.stringify(userStyle.replace(/[\\]+/g, '/'))})`
: ''
let styleContent = themeStyleContent + userStyleContent
if (themeAPI.existsParentTheme) {
const parentThemeStyle = path.resolve(themeAPI.parentTheme.path, 'styles/index.styl')
const parentThemeStyleContent = fs.existsSync(parentThemeStyle)
? `@import(${JSON.stringify(parentThemeStyle.replace(/[\\]+/g, '/'))})`
: ''
styleContent = parentThemeStyleContent + styleContent
}
await writeTemp('style.styl', styleContent)
}
})