1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/bin/next-build
Arana Jhonny e363e73715 Fix Improve "pages/ not found error" (#624)
* fix not found error

* add comment
2017-01-05 13:00:55 -08:00

53 lines
1.1 KiB
JavaScript
Executable file

#!/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 <dir>
<dir> 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)
})