Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: basic plugin support #196

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,33 @@ if (!Object.assign) Object.assign = require('object-assign')`
fs.existsSync(options.themeEnhanceAppPath)
)

// 7. handle plugins
const pluginFiles = [
path.resolve(options.themeDir),
path.resolve(sourceDir, '.vuepress')
]

for (const pluginFile of pluginFiles) {
await loadPlugin(pluginFile, options)
}

return options
}

async function loadPlugin (pluginPath, options) {
let plugin

try {
plugin = require(pluginPath)
} catch (e) {
return
}

if (plugin) {
await plugin({ options })
}
}

async function resolveOptions (sourceDir) {
const vuepressDir = path.resolve(sourceDir, '.vuepress')
const configPath = path.resolve(vuepressDir, 'config.js')
Expand Down Expand Up @@ -143,6 +167,7 @@ async function resolveOptions (sourceDir) {

if (useDefaultTheme) {
// use default theme
options.themeDir = path.resolve(__dirname, 'default-theme')
options.themePath = path.resolve(__dirname, 'default-theme/Layout.vue')
options.notFoundPath = path.resolve(__dirname, 'default-theme/NotFound.vue')
} else {
Expand Down