Skip to content

Commit

Permalink
feat($core): theme entry file as plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Oct 5, 2018
1 parent d03b10d commit 3fbef0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/@vuepress/core/lib/prepare/AppContext.js
Expand Up @@ -106,6 +106,7 @@ module.exports = class AppContext {
this.pluginAPI
// internl core plugins
.use(Object.assign({}, siteConfig, { name: '@vuepress/internal-site-config' }))
.use(Object.assign({}, this.themeEntryFile, { name: '@vuepress/internal-theme-entry-file' }))
.use(require('../internal-plugins/siteData'))
.use(require('../internal-plugins/routes'))
.use(require('../internal-plugins/rootMixins'))
Expand Down Expand Up @@ -161,7 +162,7 @@ module.exports = class AppContext {
*
* 1. siteConfig.devTemplate
* 2. `dev.html` located at .vuepress/templates
* 3. themeIndexFile.devTemplate
* 3. themeEntryFile.devTemplate
* 4. default devTemplate
*
* @api private
Expand All @@ -174,7 +175,7 @@ module.exports = class AppContext {
const siteSsrTemplate2 = path.resolve(templateDir, 'dev.html')
const siteDevTemplate2 = path.resolve(templateDir, 'ssr.html')

const { themeSsrTemplate, themeDevTemplate } = this.themeIndexFile
const { themeSsrTemplate, themeDevTemplate } = this.themeEntryFile

const defaultSsrTemplate = path.resolve(__dirname, '../app/index.ssr.html')
const defaultDevTemplate = path.resolve(__dirname, '../app/index.dev.html')
Expand Down
10 changes: 5 additions & 5 deletions packages/@vuepress/core/lib/prepare/loadTheme.js
Expand Up @@ -36,7 +36,7 @@ module.exports = async function loadTheme (theme, sourceDir, vuepressDir) {
(fs.readdirSync(localThemePath)).length > 0

let themePath = null // Mandatory
let themeIndexFile = null // Optional
let themeEntryFile = null // Optional
let themeName
let themeShortcut

Expand All @@ -58,16 +58,16 @@ module.exports = async function loadTheme (theme, sourceDir, vuepressDir) {
}

try {
themeIndexFile = require(themePath)
themeEntryFile = require(themePath)
} catch (error) {
themeIndexFile = {}
themeEntryFile = {}
}

// handle theme api
const {
plugins: themePlugins,
palette: themePalette
} = themeIndexFile
} = themeEntryFile

const layoutDirs = [
path.resolve(themePath, 'layouts'),
Expand Down Expand Up @@ -132,7 +132,7 @@ module.exports = async function loadTheme (theme, sourceDir, vuepressDir) {
return {
themePath,
layoutComponentMap,
themeIndexFile,
themeEntryFile,
themePlugins,
themePalette,
themeName,
Expand Down

0 comments on commit 3fbef0d

Please sign in to comment.