#!/usr/bin/env node import { resolve, join } from 'path' import { exists } from 'mz/fs' import parseArgs from 'minimist' import build from '../server/build' 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 .next folder should go. If no directory is provided, .next will be created in the current directory `) process.exit(0) } const dir = resolve(argv._[0] || '.') // Check if pages dir exists and warn if not exists(dir) .then(async () => { if (!(await exists(join(dir, 'pages')))) { if (await exists(join(dir, '..', 'pages'))) { console.error('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?') } else { console.error('> Couldn\'t find a `pages` directory. Please create one under the project root') } process.exit(1) } }) .catch((err) => { console.error(err) process.exit(1) }) build(dir) .catch((err) => { console.error(err) process.exit(1) })