提交 430789b9 编写于 作者: A Arunoda Susiripala

By default print some messages to the console.

Also added a silent option if someone don't want
those messages.
上级 d7048e13
......@@ -10,12 +10,12 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
v: 'verbose',
s: 'silent',
o: 'outdir'
},
boolean: ['h'],
default: {
v: false,
s: false,
o: null
}
})
......@@ -34,8 +34,8 @@ if (argv.help) {
Options
-h - list this help
-v - run export with the verbose mode
-o - set the output dir (defaults to '.out')
-s - do not print any messages to console
`)
process.exit(0)
}
......@@ -56,7 +56,7 @@ if (!existsSync(join(dir, 'pages'))) {
}
const options = {
verbose: argv.verbose,
silent: argv.silent,
outdir: argv.outdir ? resolve(argv.outdir) : resolve(dir, '.out')
}
......
......@@ -13,6 +13,8 @@ export default async function (dir, options) {
const outDir = options.outdir
const nextDir = join(dir, '.next')
log(` Exporting to: ${outDir}\n`)
if (!existsSync(nextDir)) {
console.error('Build your with "next build" before running "next start".')
process.exit(1)
......@@ -64,9 +66,7 @@ export default async function (dir, options) {
}
for (const path of exportPaths) {
if (options.verbose) {
console.log(` exporing path: ${path}`)
}
log(` exporing path: ${path}`)
const { page, query } = exportPathMap[path]
const req = { url: path }
......@@ -81,6 +81,14 @@ export default async function (dir, options) {
const html = await renderToHTML(req, res, page, query, renderOpts)
writeFileSync(htmlFilepath, html, 'utf8')
}
// Add an empty line to the console for the better readability.
log('')
function log (message) {
if (options.silent) return
console.log(message)
}
}
function copyPages (nextDir, outDir, buildId) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册