Skip to content

Commit

Permalink
fix($core): theme/styles/palette.styl doesn't work
Browse files Browse the repository at this point in the history
BTW, remove Object usage of palette.
  • Loading branch information
ulivz committed Oct 7, 2018
1 parent 0a142ef commit 0a7e38a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/@vuepress/core/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
return console.error(logger.error(chalk.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
}
await fs.remove(outDir)
logger.debug('Dist directory: ' + chalk.gray(require('path').resolve(process.cwd(), outDir)))
logger.debug('Dist directory: ' + chalk.gray(path.resolve(process.cwd(), outDir)))

let clientConfig = createClientConfig(options, cliOptions).toConfig()
let serverConfig = createServerConfig(options, cliOptions).toConfig()
Expand Down
22 changes: 7 additions & 15 deletions packages/@vuepress/core/lib/internal-plugins/palette/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@ module.exports = (options, ctx) => ({
// 2. write palette.styl
const { sourceDir, writeTemp } = ctx

const themePalette = ctx.themePalette
const { palette: userPalette } = ctx.siteConfig
const palettePath = path.resolve(sourceDir, '.vuepress/styles/palette.styl')
const themePalette = path.resolve(ctx.themePath, 'styles/palette.styl')
const userPalette = path.resolve(sourceDir, '.vuepress/styles/palette.styl')

const themePaletteContent = resolvePaletteContent(themePalette)
const userPaletteContent = resolvePaletteContent(userPalette)
const userPaletteContent2 = resolvePaletteContent(palettePath)

// user's palette can override theme's palette.
const paletteContent = themePaletteContent + userPaletteContent + userPaletteContent2
const paletteContent = themePaletteContent + userPaletteContent
await writeTemp('palette.styl', paletteContent)
}
})

/**
* resolve palette content
* @param {string|object} palette
* @param {string} palette
* @returns {string}
*/

Expand All @@ -55,14 +53,8 @@ function resolvePaletteContent (palette) {
return ''
}

if (isString(palette)) {
if (fs.existsSync(palette)) {
return `@import(${JSON.stringify(palette)})\n`
}
return ''
} else if (isPlainObject(palette)) {
return Object.keys(palette).map(variableName => {
return `${variableName} = ${palette[variableName]}`
}).join('\n') + '\n'
if (isString(palette) && fs.existsSync(palette)) {
return `@import(${JSON.stringify(palette)})\n`
}
return ''
}
3 changes: 0 additions & 3 deletions packages/@vuepress/core/lib/prepare/loadTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ module.exports = async function loadTheme (ctx) {
}

// handle theme api
const { palette: themePalette } = themeEntryFile

const layoutDirs = [
path.resolve(themePath, 'layouts'),
path.resolve(themePath, '.')
Expand Down Expand Up @@ -135,7 +133,6 @@ module.exports = async function loadTheme (ctx) {
themePath,
layoutComponentMap,
themeEntryFile,
themePalette,
themeName,
themeShortcut
}
Expand Down

0 comments on commit 0a7e38a

Please sign in to comment.