Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pagesWatcher.on('add', spawnUpdate('add'))
pagesWatcher.on('unlink', spawnUpdate('unlink'))
pagesWatcher.on('addDir', spawnUpdate('addDir'))
pagesWatcher.on('unlinkDir', spawnUpdate('unlinkDir'))
const watchFiles = [
'.vuepress/config.js',
'.vuepress/config.yml',
'.vuepress/config.toml'
].concat(
(
ctx.siteConfig.extraWatchFiles || []
).map(file => normalizeWatchFilePath(file, ctx.sourceDir))
)
logger.debug('watchFiles', watchFiles)
// watch config file
const configWatcher = chokidar.watch(watchFiles, {
cwd: sourceDir,
ignoreInitial: true
})
configWatcher.on('change', spawnUpdate('change'))
// also listen for frontmatter changes from markdown files
frontmatterEmitter.on('update', () => update('frontmatter or headers change'))
// resolve webpack config
let config = createClientConfig(ctx)
config
.plugin('html')
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
})
await app.process()
app.pluginAPI.applySyncOption('extendCli', subCli, app)
console.log()
},
async afterParse (subCli) {
if (!subCli.matchedCommand) {
logUnknownCommand(subCli)
console.log()
}
cli.on('command:*', async () => {
const { args, options: commandoptions } = cli
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)
}
constructor (options = {}) {
this.isProd = process.env.NODE_ENV === 'production'
this.options = options
this.sourceDir = this.options.sourceDir || path.join(__dirname, 'docs.fallback')
logger.debug('sourceDir', this.sourceDir)
if (!fs.existsSync(this.sourceDir)) {
logger.warn(`Source directory doesn't exist: ${chalk.yellow(this.sourceDir)}`)
}
this.vuepressDir = path.resolve(this.sourceDir, '.vuepress')
this.libDir = path.join(__dirname, '../')
}
.action((sourceDir = '.', commandOptions) => {
const { debug, silent } = commandOptions
logger.setOptions({ logLevel: silent ? 1 : debug ? 4 : 3 })
logger.debug('global_options', options)
logger.debug('build_options', commandOptions)
env.setOptions({ isDebug: debug, isTest: process.env.NODE_ENV === 'test' })
wrapCommand(build)({
sourceDir: path.resolve(sourceDir),
...options,
...commandOptions
})
})
applySyncOption (name, ...args) {
logger.debug('applySyncOption: ' + name)
this.getOption(name).apply(...args)
return this
}
watchUserConfig () {
this.watchFiles = [
'.vuepress/config.js',
'.vuepress/config.yml',
'.vuepress/config.toml'
].concat(
(
this.context.siteConfig.extraWatchFiles || []
).map(file => normalizeWatchFilePath(file, this.context.sourceDir))
)
logger.debug('watchFiles', this.watchFiles)
this.configWatcher = chokidar.watch(this.watchFiles, {
cwd: this.context.sourceDir,
ignoreInitial: true
})
this.configWatcher.on('change', target => this.handleUpdate('change', target))
}
logger.warn(e.message)
return this
}
}
if (plugin.multiple !== true) {
const duplicateIndex = this._pluginQueue.findIndex(({ name }) => name === plugin.name)
if (duplicateIndex !== -1) {
this._pluginQueue.splice(duplicateIndex, 1)
}
}
this._pluginQueue.push(plugin)
if (plugin.plugins) {
logger.debug(`Plugins defined at ${chalk.gray(plugin.name)}`, plugin.plugins)
this.useByPluginsConfig(plugin.plugins)
}
return this
}