2019-02-26 21:57:32 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
import { resolve, join } from 'path'
|
|
|
|
import { existsSync } from 'fs'
|
2019-03-24 23:38:03 +01:00
|
|
|
import arg from 'next/dist/compiled/arg/index.js'
|
2019-02-26 21:57:32 +01:00
|
|
|
import exportApp from '../export'
|
|
|
|
import { printAndExit } from '../server/lib/utils'
|
|
|
|
import { cliCommand } from '../bin/next'
|
|
|
|
|
2019-05-29 13:57:26 +02:00
|
|
|
const nextExport: cliCommand = argv => {
|
|
|
|
const args = arg(
|
|
|
|
{
|
|
|
|
// Types
|
|
|
|
'--help': Boolean,
|
|
|
|
'--silent': Boolean,
|
|
|
|
'--outdir': String,
|
|
|
|
'--threads': Number,
|
2019-02-26 21:57:32 +01:00
|
|
|
|
2019-05-29 13:57:26 +02:00
|
|
|
// Aliases
|
|
|
|
'-h': '--help',
|
|
|
|
'-s': '--silent',
|
|
|
|
'-o': '--outdir',
|
|
|
|
},
|
|
|
|
{ argv }
|
|
|
|
)
|
2019-02-26 21:57:32 +01:00
|
|
|
|
|
|
|
if (args['--help']) {
|
|
|
|
// tslint:disable-next-line
|
|
|
|
console.log(`
|
|
|
|
Description
|
|
|
|
Exports the application for production deployment
|
|
|
|
|
|
|
|
Usage
|
|
|
|
$ next export [options] <dir>
|
|
|
|
|
2020-03-18 10:18:29 +01:00
|
|
|
<dir> represents the directory of the Next.js application.
|
|
|
|
If no directory is provided, the current directory will be used.
|
2019-02-26 21:57:32 +01:00
|
|
|
|
|
|
|
Options
|
|
|
|
-h - list this help
|
|
|
|
-o - set the output dir (defaults to 'out')
|
|
|
|
-s - do not print any messages to console
|
|
|
|
`)
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
const dir = resolve(args._[0] || '.')
|
|
|
|
|
|
|
|
// Check if pages dir exists and warn if not
|
|
|
|
if (!existsSync(dir)) {
|
|
|
|
printAndExit(`> No such directory exists as the project root: ${dir}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
silent: args['--silent'] || false,
|
|
|
|
threads: args['--threads'],
|
|
|
|
outdir: args['--outdir'] ? resolve(args['--outdir']) : join(dir, 'out'),
|
|
|
|
}
|
|
|
|
|
|
|
|
exportApp(dir, options)
|
|
|
|
.then(() => {
|
|
|
|
printAndExit('Export successful', 0)
|
|
|
|
})
|
2019-05-29 13:57:26 +02:00
|
|
|
.catch(err => {
|
2019-02-26 21:57:32 +01:00
|
|
|
printAndExit(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export { nextExport }
|