Skip to content

Commit

Permalink
run build before start
Browse files Browse the repository at this point in the history
  • Loading branch information
ntwcklng committed Jan 11, 2017
1 parent aaedc11 commit 171b544
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bin/next-start
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env node

import { resolve } from 'path'
import { resolve, join } from 'path'
import parseArgs from 'minimist'
import Server from '../server'
import {exists} from 'mz/fs'
import { spawn } from 'cross-spawn'

const argv = parseArgs(process.argv.slice(2), {
alias: {
Expand Down Expand Up @@ -40,11 +41,13 @@ const dir = resolve(argv._[0] || '.')

const srv = new Server({ dir })

exists(resolve(process.cwd(), '.next')).then(exists => {
exists(resolve(dir, '.next')).then(exists => {
if (!exists) {
console.error(`> Error! The application should be compiled with \`next build\` first.`)
process.exit(0)
console.log(`> Running \`next build\` first...`)
return spawn.sync(join(__dirname, 'next-build'), { stdio: 'inherit', customFds: [0, 1, 2] })
}
})
.then(() => {
srv.start(argv.port)
})
.then(() => {
Expand Down

0 comments on commit 171b544

Please sign in to comment.