next init: Exit non-zero when refusing to run in 'pages' dir. (#156)

Should only exit `0` if the command was successful. The command refusing to execute should be considered a failure.

Also, this condition can be detected synchronously, no need to wait on the async existence check.
This commit is contained in:
Tim Oxley 2016-10-29 23:03:05 -07:00 committed by Naoyuki Kanezawa
parent 4c2f381e74
commit 5595232f58

View file

@ -12,13 +12,13 @@ const argv = parseArgs(process.argv.slice(2), {
const dir = resolve(argv._[0] || '.')
if (basename(dir) === 'pages') {
console.warn('Your root directory is named "pages". This looks suspicious. You probably want to go one directory up.')
process.exit(1)
}
exists(join(dir, 'package.json'))
.then(async present => {
if (basename(dir) === 'pages') {
console.warn('Your root directory is named "pages". This looks suspicious. You probably want to go one directory up.')
return
}
if (!present) {
await writeFile(join(dir, 'package.json'), basePackage.replace(/my-app/g, basename(dir)))
}