Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// render pages
logger.wait('Rendering static HTML...')
const pagePaths = []
for (const page of this.context.pages) {
pagePaths.push(await this.renderPage(page))
}
readline.clearLine(process.stdout, 0)
readline.cursorTo(process.stdout, 0)
await this.context.pluginAPI.applyAsyncOption('generated', pagePaths)
// DONE.
const relativeDir = path.relative(this.context.cwd, this.outDir)
logger.success(`Generated static files in ${chalk.cyan(relativeDir)}.`)
const { duration } = performance.stop()
logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress build')}.`)
console.log()
}
// render pages
logger.wait('Rendering static HTML...')
const pagePaths = []
for (const page of ctx.pages) {
pagePaths.push(await renderPage(page))
}
readline.clearLine(process.stdout, 0)
readline.cursorTo(process.stdout, 0)
await ctx.pluginAPI.options.generated.apply(pagePaths)
// DONE.
const relativeDir = path.relative(cwd, outDir)
logger.success(`Generated static files in ${chalk.cyan(relativeDir)}.`)
const { duration } = performance.stop()
logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress build')}.`)
console.log()
// --- helpers ---
function compile (config) {
return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err) {
return reject(err)
}
if (stats.hasErrors()) {
stats.toJson().errors.forEach(err => {
console.error(err)
})
await renderPage(page)
}
// if the user does not have a custom 404.md, generate the theme's default
if (!options.pages.some(p => p.path === '/404.html')) {
await renderPage({ path: '/404.html' })
}
readline.clearLine(process.stdout, 0)
readline.cursorTo(process.stdout, 0)
await options.pluginAPI.options.generated.apply()
// DONE.
const relativeDir = path.relative(process.cwd(), outDir)
logger.success(`\n${chalk.green('Success!')} Generated static files in ${chalk.cyan(relativeDir)}.\n`)
// --- helpers ---
function compile (config) {
return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err) {
return reject(err)
}
if (stats.hasErrors()) {
stats.toJson().errors.forEach(err => {
console.error(err)
})
reject(new Error(`Failed to compile with errors.`))
return
}
compiler.hooks.done.tap('vuepress-log', stats => {
if (shouldClearScreen) {
clearScreen()
}
const time = new Date().toTimeString().match(/^[\d:]+/)[0]
const displayUrl = `http://${displayHost}:${port}${publicPath}`
logger.success(
`${chalk.gray(`[${time}]`)} Build ${chalk.italic(stats.hash.slice(0, 6))} `
+ `finished in ${stats.endTime - stats.startTime} ms! `
+ (
isFirst
? ''
: `${chalk.gray(`(${displayUrl})`)}`
)
)
if (isFirst) {
isFirst = false
console.log(`${chalk.gray('>')} VuePress dev server listening at ${chalk.cyan(displayUrl)}`)
const { duration } = performance.stop()
logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress dev')} for the first time.`)
}
})
if (shouldClearScreen) {
const command = [
'node',
docgenMainScript,
'-f', 'json-raw',
inputPaths.shift(),
...inputPaths.reduce((acc, cur) => {
acc.push('-a', cur)
return acc
}, []),
'-o', outputPath
]
logger.wait('Generating API metadata file...')
try {
logger.debug(`Running command ${command.join(' ')}`)
await execAsync(command.join(' '))
logger.success(`Done! Metadata file generated to ${path.join(outputPath, 'api.json')}`)
} catch (e) {
logger.error('Failed to generate API metadata.')
throw e
}
})
}
return false
}
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}`)
})
},
path: pagePath,
url,
title
} = exportPages[i]
await browserPage.goto(
location,
{ waitUntil: 'networkidle2' }
)
await browserPage.pdf({
path: pagePath,
format: 'A4'
})
logger.success(`Generated ${yellow(title)} ${gray(`${url}`)}`)
}
const files = exportPages.map(({ path }) => path)
const outputFilename = siteConfig.title || 'site'
const outputFile = `${outputFilename}.pdf`
await new Promise(resolve => {
PDFMerge(files, outputFile, err => {
if (err) {
throw err
}
logger.success(`Export ${yellow(outputFile)} file!`)
resolve()
})
})
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
}
if (relative) {
logger.debug('Copied', chalk.cyan(relative))
}
return true
}
})
logger.success(`Copied default theme into ${chalk.cyan(targetDir)}.\n`)
}