Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const readline = require('readline')
const escape = require('escape-html')
const { chalk, fs, path, logger, env, performance } = require('@vuepress/shared-utils')
const prepare = require('./prepare/index')
const createClientConfig = require('./webpack/createClientConfig')
const createServerConfig = require('./webpack/createServerConfig')
const { createBundleRenderer } = require('vue-server-renderer')
const { normalizeHeadTag, applyUserWebpackConfig } = require('./util/index')
logger.wait('Extracting site metadata...')
const ctx = await prepare(sourceDir, cliOptions, true /* isProd */)
const { outDir, cwd } = ctx
if (cwd === outDir) {
return console.error(logger.error(chalk.red('Unexpected option: outDir cannot be set to the current working directory.\n'), false))
}
await fs.emptyDir(outDir)
logger.debug('Dist directory: ' + chalk.gray(outDir))
let clientConfig = createClientConfig(ctx, cliOptions).toConfig()
let serverConfig = createServerConfig(ctx, cliOptions).toConfig()
// apply user config...
const userConfig = ctx.siteConfig.configureWebpack
if (userConfig) {
clientConfig = applyUserWebpackConfig(userConfig, clientConfig, false)
serverConfig = applyUserWebpackConfig(userConfig, serverConfig, true)
}
// compile!
const { chalk, fs, logger } = require('@vuepress/shared-utils')
const prepare = require('./prepare/index')
const createClientConfig = require('./webpack/createClientConfig')
const createServerConfig = require('./webpack/createServerConfig')
const { createBundleRenderer } = require('vue-server-renderer')
const { normalizeHeadTag, applyUserWebpackConfig } = require('./util/index')
logger.wait('\nExtracting site metadata...')
const options = await prepare(sourceDir, cliOptions, true /* isProd */)
if (cliOptions.outDir) {
options.outDir = cliOptions.outDir
}
const { outDir } = options
if (process.cwd() === outDir) {
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)))
let clientConfig = createClientConfig(options, cliOptions).toConfig()
let serverConfig = createServerConfig(options, cliOptions).toConfig()
// apply user config...
const userConfig = options.siteConfig.configureWebpack
if (userConfig) {
clientConfig = applyUserWebpackConfig(userConfig, clientConfig, false)
serverConfig = applyUserWebpackConfig(userConfig, serverConfig, true)
}
// compile!
const stats = await compile([clientConfig, serverConfig])
const spawnUpdate = updateType => file => {
const target = path.join(sourceDir, file)
// Bust cache.
delete require.cache[target]
update(`${chalk.red(updateType)} ${chalk.cyan(file)}`)
}
try {
require.resolve('@vuepress/core')
} catch (err) {
console.log(chalk.red(
`\n[vuepress] @vuepress/cli ` +
`requires @vuepress/core to be installed.\n`
))
process.exit(1)
}
const pkg = require('@vuepress/core/package.json')
const requiredVersion = pkg.engines.node
if (!semver.satisfies(process.version, requiredVersion)) {
console.log(chalk.red(
`\n[vuepress] minimum Node version not met:` +
`\nYou are using Node ${process.version}, but VuePress ` +
`requires Node ${requiredVersion}.\nPlease upgrade your Node version.\n`
))
process.exit(1)
}
const cli = require('cac')()
exports.cli = cli
exports.bootstrap = function ({
plugins,
theme
} = {}) {
const { path, logger, env } = require('@vuepress/shared-utils')
const { dev, build, eject } = require('@vuepress/core')
module.exports = async (dir) => {
try {
require.resolve('@vuepress/theme-default')
} catch (err) {
console.log(chalk.red(`\n[vuepress] cannot find '@vuepress/theme-default'\n`))
process.exit(1)
}
const source = require.resolve('@vuepress/theme-default')
logger.debug('entry', chalk.cyan(source))
const sourceDir = path.parse(source).dir
const targetDir = path.resolve(dir, '.vuepress/theme')
logger.debug('sourceDir', chalk.cyan(sourceDir))
logger.debug('targetDir', chalk.cyan(targetDir))
await fs.copy(sourceDir, targetDir, {
filter: src => {
const relative = path.relative(sourceDir, src)
if (EXCLUDED_FILES.includes(relative)) {
return false
}
module.exports = function checkEnv (pkg) {
const requiredVersion = pkg.engines.node
if (!semver.satisfies(process.version, requiredVersion)) {
console.log(chalk.red(
`\n[vuepress] minimum Node version not met:` +
`\nYou are using Node ${process.version}, but VuePress ` +
`requires Node ${requiredVersion}.\nPlease upgrade your Node version.\n`
))
process.exit(1)
}
}
return fn(...args).catch(err => {
console.error(chalk.red(err.stack))
process.exitCode = 1
})
}