Commit 430789b9 authored by Arunoda Susiripala's avatar Arunoda Susiripala

By default print some messages to the console.

Also added a silent option if someone don't want
those messages.
parent d7048e13
...@@ -10,12 +10,12 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production' ...@@ -10,12 +10,12 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const argv = parseArgs(process.argv.slice(2), { const argv = parseArgs(process.argv.slice(2), {
alias: { alias: {
h: 'help', h: 'help',
v: 'verbose', s: 'silent',
o: 'outdir' o: 'outdir'
}, },
boolean: ['h'], boolean: ['h'],
default: { default: {
v: false, s: false,
o: null o: null
} }
}) })
...@@ -34,8 +34,8 @@ if (argv.help) { ...@@ -34,8 +34,8 @@ if (argv.help) {
Options Options
-h - list this help -h - list this help
-v - run export with the verbose mode
-o - set the output dir (defaults to '.out') -o - set the output dir (defaults to '.out')
-s - do not print any messages to console
`) `)
process.exit(0) process.exit(0)
} }
...@@ -56,7 +56,7 @@ if (!existsSync(join(dir, 'pages'))) { ...@@ -56,7 +56,7 @@ if (!existsSync(join(dir, 'pages'))) {
} }
const options = { const options = {
verbose: argv.verbose, silent: argv.silent,
outdir: argv.outdir ? resolve(argv.outdir) : resolve(dir, '.out') outdir: argv.outdir ? resolve(argv.outdir) : resolve(dir, '.out')
} }
......
...@@ -13,6 +13,8 @@ export default async function (dir, options) { ...@@ -13,6 +13,8 @@ export default async function (dir, options) {
const outDir = options.outdir const outDir = options.outdir
const nextDir = join(dir, '.next') const nextDir = join(dir, '.next')
log(` Exporting to: ${outDir}\n`)
if (!existsSync(nextDir)) { if (!existsSync(nextDir)) {
console.error('Build your with "next build" before running "next start".') console.error('Build your with "next build" before running "next start".')
process.exit(1) process.exit(1)
...@@ -64,9 +66,7 @@ export default async function (dir, options) { ...@@ -64,9 +66,7 @@ export default async function (dir, options) {
} }
for (const path of exportPaths) { for (const path of exportPaths) {
if (options.verbose) { log(` exporing path: ${path}`)
console.log(` exporing path: ${path}`)
}
const { page, query } = exportPathMap[path] const { page, query } = exportPathMap[path]
const req = { url: path } const req = { url: path }
...@@ -81,6 +81,14 @@ export default async function (dir, options) { ...@@ -81,6 +81,14 @@ export default async function (dir, options) {
const html = await renderToHTML(req, res, page, query, renderOpts) const html = await renderToHTML(req, res, page, query, renderOpts)
writeFileSync(htmlFilepath, html, 'utf8') 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) { function copyPages (nextDir, outDir, buildId) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment