|
2 | 2 | import 'source-map-support/register' |
3 | 3 | import { resolve, join } from 'path' |
4 | 4 | import parseArgs from 'minimist' |
5 | | -import { exists } from 'mz/fs' |
| 5 | +import { existsSync } from 'fs' |
6 | 6 | import Server from '../server' |
| 7 | +import { printAndExit } from '../lib/utils' |
7 | 8 |
|
8 | 9 | const argv = parseArgs(process.argv.slice(2), { |
9 | 10 | alias: { |
@@ -38,21 +39,17 @@ if (argv.help) { |
38 | 39 | const dir = resolve(argv._[0] || '.') |
39 | 40 |
|
40 | 41 | // Check if pages dir exists and warn if not |
41 | | -exists(dir) |
42 | | -.then(async () => { |
43 | | - if (!(await exists(join(dir, 'pages')))) { |
44 | | - if (await exists(join(dir, '..', 'pages'))) { |
45 | | - console.error('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?') |
46 | | - } else { |
47 | | - console.error('> Couldn\'t find a `pages` directory. Please create one under the project root') |
48 | | - } |
49 | | - process.exit(1) |
| 42 | +if (!existsSync(dir)) { |
| 43 | + printAndExit(`> No such directory exists as the project root: ${dir}`) |
| 44 | +} |
| 45 | + |
| 46 | +if (!existsSync(join(dir, 'pages'))) { |
| 47 | + if (existsSync(join(dir, '..', 'pages'))) { |
| 48 | + printAndExit('> No `pages` directory found. Did you mean to run `next` in the parent (`../`) directory?') |
50 | 49 | } |
51 | | -}) |
52 | | -.catch((err) => { |
53 | | - console.error(err) |
54 | | - process.exit(1) |
55 | | -}) |
| 50 | + |
| 51 | + printAndExit('> Couldn\'t find a `pages` directory. Please create one under the project root') |
| 52 | +} |
56 | 53 |
|
57 | 54 | const srv = new Server({ dir, dev: true }) |
58 | 55 | srv.start(argv.port) |
|
0 commit comments