Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
prepare(sourceDir, cliOptions, false /* isProd */).catch(err => {
console.error(logger.error(chalk.red(err.stack), false))
})
}
const pageMeta = renderPageMeta(meta)
const context = {
url: page.path,
userHeadTags: this.userHeadTags,
pageMeta,
title: 'VuePress',
lang: 'en',
description: ''
}
let html
try {
html = await this.renderer.renderToString(context)
} catch (e) {
console.error(logger.error(chalk.red(`Error rendering ${pagePath}:`), false))
throw e
}
const filename = pagePath.replace(/\/$/, '/index.html').replace(/^\//, '')
const filePath = path.resolve(this.outDir, filename)
await fs.ensureDir(path.dirname(filePath))
await fs.writeFile(filePath, html)
return filePath
}
}
.action(async (dir, version,) => {
if (versions.includes(version)) {
logger.error(`Version ${version} already exists in version.json. Please use a different version.`)
return
}
logger.wait(`Creating new version ${version} ...`)
const versionDestPath = path.join(versionedSourceDir, version)
await fs.copy(context.sourceDir, versionDestPath, {
filter: (src, dest) => {
if (src === context.vuepressDir) {
return false
}
return true
}
})
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
}
})
}
const pageMeta = renderPageMeta(meta)
const context = {
url: pagePath,
userHeadTags,
pageMeta,
title: 'VuePress',
lang: 'en',
description: ''
}
let html
try {
html = await renderer.renderToString(context)
} catch (e) {
console.error(logger.error(chalk.red(`Error rendering ${pagePath}:`), false))
throw e
}
const filename = decodeURIComponent(pagePath.replace(/\/$/, '/index.html').replace(/^\//, ''))
const filePath = path.resolve(outDir, filename)
await fs.ensureDir(path.dirname(filePath))
await fs.writeFile(filePath, html)
}
const pageMeta = renderPageMeta(meta)
const context = {
url: pagePath,
userHeadTags,
pageMeta,
title: 'VuePress',
lang: 'en',
description: ''
}
let html
try {
html = await renderer.renderToString(context)
} catch (e) {
console.error(logger.error(chalk.red(`Error rendering ${pagePath}:`), false))
throw e
}
const filename = decodeURIComponent(pagePath.replace(/\/$/, '/index.html').replace(/^\//, ''))
const filePath = path.resolve(outDir, filename)
await fs.ensureDir(path.dirname(filePath))
await fs.writeFile(filePath, html)
return filePath
}
syncApply (...args) {
const rawItems = this.items
this.items = []
this.appliedItems = this.items
for (const { name, value } of rawItems) {
try {
this.add(
name,
isFunction(value)
? value(...args)
: value
)
} catch (error) {
logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`)
throw error
}
}
this.items = rawItems
}
async asyncApply (...args) {
const rawItems = this.items
this.items = []
this.appliedItems = this.items
for (const { name, value } of rawItems) {
try {
this.add(
name,
isFunction(value)
? await value(...args)
: value
)
} catch (error) {
logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`)
throw error
}
}
this.items = rawItems
}
md.renderer.rules.fence = (...args) => {
const [tokens, idx, , { loader }] = args
const token = tokens[idx]
const { src } = token
if (src) {
if (loader) {
loader.addDependency(src)
}
if (fs.existsSync(src)) {
token.content = fs.readFileSync(src, 'utf8')
} else {
token.content = `Code snippet path not found: ${src}`
token.info = ''
logger.error(token.content)
}
}
return fence(...args)
}
await Promise.all(rawItems.map(async ({ name, value }) => {
try {
this.add(
name,
isFunction(value)
? await value(...args)
: value
)
} catch (error) {
logger.error(`${chalk.cyan(name)} apply ${chalk.cyan(this.key)} failed.`)
throw error
}
})).catch(error => {
throw error