#!/usr/bin/env node
const { resolve, join } = require('path')
const { existsSync } = require('fs')
const parseArgs = require('minimist')
const del = require('del')
const { build } = require('@healthline/six-million')
const createWebpack = require('../node/server/webpack').default
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help'
},
boolean: ['h']
})
if (argv.help) {
console.log(`
Description
Compiles the application for production deployment
Usage
$ next build
represents where the compiled dist folder should go.
If no directory is provided, the dist folder will be created in the current directory.
You can set a custom folder in config https://github.com/zeit/next.js#custom-configuration, otherwise it will be created inside '.next'
`)
process.exit(0)
}
const dir = resolve(argv._[0] || '.')
// Check if pages dir exists and warn if not
if (!existsSync(dir)) {
console.error(`> No such directory exists as the project root: ${dir}`)
process.exit(1)
}
del(join(dir, '.next'), { force: true })
.then(() => build(dir, argv.s, createWebpack))
.catch((err) => {
console.error(err)
process.exit(1)
})