Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
themeIndexFile = requireResolve(`vuepress-theme-${theme}/index.js`)
} catch (e) {
try {
themeIndexFile = requireResolve(`@vuepress/theme-${theme}`)
themePath = path.dirname(themeIndexFile)
themeIndexFile = require(themeIndexFile)
themeLayoutPath = themeIndexFile.layout
themeNotFoundPath = themeIndexFile.notFound
themePlugins = themeIndexFile.plugins
} catch (e) {
throw new Error(`[vuepress] Failed to load custom theme "${theme}". File vuepress-theme-${theme}/Layout.vue does not exist.`)
}
}
}
logger.tip(`\nApply theme ${chalk.gray(theme)}`)
} else {
throw new Error(`[vuepress] You must specify a theme, or create a local custom theme. \n For more details, refer to https://vuepress.vuejs.org/guide/custom-themes.html#custom-themes. \n`)
}
// resolve theme config
const themeConfig = siteConfig.themeConfig || {}
// resolve markdown
const markdown = createMarkdown(siteConfig)
// resolve pageFiles
const patterns = ['**/*.md', '!.vuepress', '!node_modules']
if (siteConfig.dest) {
// #654 exclude dest folder when dest dir was set in
// sourceDir but not in '.vuepress'
const outDirRelative = path.relative(sourceDir, outDir)
logger.debug('global_options', options)
logger.debug('cli_options', commandoptions)
logger.debug('cli_args', args)
const [commandName] = args
const sourceDir = args[1] ? path.resolve(args[1]) : pwd
const inferredUserDocsDirectory = await inferUserDocsDirectory(pwd)
logger.developer('inferredUserDocsDirectory', inferredUserDocsDirectory)
logger.developer('sourceDir', sourceDir)
if (inferredUserDocsDirectory && sourceDir !== inferredUserDocsDirectory) {
logUnknownCommand(cli)
console.log()
logger.tip(`Did you miss to specify the target docs dir? e.g. ${chalk.cyan(`vuepress ${commandName} [targetDir]`)}.`)
logger.tip(`A custom command registered by a plugin requires VuePress to locate your site configuration like ${chalk.cyan('vuepress dev')} or ${chalk.cyan('vuepress build')}.`)
console.log()
process.exit(1)
}
if (!inferredUserDocsDirectory) {
logUnknownCommand(cli)
process.exit(1)
}
logger.debug('Custom command', chalk.cyan(commandName))
CLI({
async beforeParse (subCli) {
const app = createApp({
sourceDir: sourceDir,
...options,
...commandoptions
let name
let shortcut
let entry = {}
/**
* 1. From `.vuepress/theme` directory.
*/
if (
!ignoreLocal
&& !fs.existsSync(theme)
&& fs.existsSync(localThemePath)
&& fs.readdirSync(localThemePath).length > 0
) {
path = localThemePath
name = shortcut = 'local'
logger.tip(`Apply local theme at ${chalk.gray(path)}...`)
/**
* 2. From deps or custom local path.
* - vuepress-plugin-foo
* - /path/to/a-theme/index.js
*/
} else if (isString(theme)) {
/**
* To let theme resolver get the correct theme name.
*/
if (theme.endsWith('/index.js')) {
theme = theme.replace(/\/index\.js$/, '')
}
const resolved = resolver.resolve(theme, sourceDir)
if (resolved.entry === null) {
'[vuepress] You must specify a theme, or create a local custom theme. \n'
+ 'For more details, refer to https://vuepress.vuejs.org/guide/custom-themes.html#custom-themes. \n'
)
}
let applyTip = `Apply theme ${chalk.magenta(theme.name)}`
theme.entry.name = '@vuepress/internal-theme-entry-file'
let parentTheme = {}
if (theme.entry.extend) {
parentTheme = resolveTheme(ctx, themeResolver, true, theme.entry.extend)
parentTheme.entry.name = '@vuepress/internal-parent-theme-entry-file'
applyTip += chalk.gray(` (extends ${chalk.magenta(parentTheme.name)})`)
}
logger.tip(applyTip + ' ...')
logger.debug('theme', theme.name, theme.path)
logger.debug('parentTheme', parentTheme.name, parentTheme.path)
return new ThemeAPI(theme, parentTheme)
}
}
return true
}
})
await snapshotSidebar(context.siteConfig, versionDestPath)
if (typeof options.onNewVersion === 'function') {
await options.onNewVersion(version, versionDestPath)
}
versions.unshift(version)
await fs.writeFile(versionsFilePath, JSON.stringify(versions, null, 2))
logger.success(`Snapshotted your current docs as version ${version}`)
logger.tip(`You can find them under ${versionDestPath}`)
})
},
.extensions
.merge(['.js', '.jsx', '.vue', '.json', '.styl'])
.end()
.modules
.merge(modulePaths)
config.resolveLoader
.set('symlinks', true)
.modules
.merge(modulePaths)
config.module
.noParse(/^(vue|vue-router|vuex|vuex-router-sync)$/)
if (cache === false) {
logger.tip('Clean cache...\n')
fs.emptyDirSync(cacheDirectory)
}
const finalCacheIdentifier = cacheIdentifier + `isServer:${isServer}`
function applyVuePipeline (rule) {
rule
.use('cache-loader')
.loader('cache-loader')
.options({
cacheDirectory,
cacheIdentifier: finalCacheIdentifier
})
rule
.use('vue-loader')