File tree 6 files changed +43
-7
lines changed 6 files changed +43
-7
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import parseArgs from 'minimist'
4
4
import { exists } from 'mz/fs'
5
5
import Server from '../server'
6
6
import clean from '../server/build/clean'
7
+ import run from './util/run' ;
7
8
8
9
const argv = parseArgs ( process . argv . slice ( 2 ) , {
9
10
alias : {
@@ -21,8 +22,7 @@ const dir = resolve(argv._[0] || '.')
21
22
clean ( dir )
22
23
. then ( async ( ) => {
23
24
const srv = new Server ( { dir, dev : true , hotReload : true } )
24
- await srv . start ( argv . port )
25
- console . log ( '> Ready on http://localhost:%d' , argv . port )
25
+ await run ( srv , argv . port )
26
26
27
27
// Check if pages dir exists and warn if not
28
28
if ( ! ( await exists ( join ( dir , 'pages' ) ) ) ) {
Original file line number Diff line number Diff line change 3
3
import { resolve } from 'path'
4
4
import parseArgs from 'minimist'
5
5
import Server from '../server'
6
+ import run from './util/run' ;
6
7
7
8
const argv = parseArgs ( process . argv . slice ( 2 ) , {
8
9
alias : {
@@ -18,10 +19,8 @@ const argv = parseArgs(process.argv.slice(2), {
18
19
const dir = resolve ( argv . _ [ 0 ] || '.' )
19
20
20
21
const srv = new Server ( { dir } )
21
- srv . start ( argv . port )
22
- . then ( ( ) => {
23
- console . log ( '> Ready on http://localhost:%d' , argv . port )
24
- } )
22
+
23
+ run ( srv , argv . port )
25
24
. catch ( ( err ) => {
26
25
console . error ( err )
27
26
process . exit ( 1 )
Original file line number Diff line number Diff line change
1
+ import rl from 'readline' ;
2
+
3
+ export default function ( question ) {
4
+ const rlInterface = rl . createInterface ( {
5
+ input : process . stdin ,
6
+ output : process . stdout ,
7
+ } ) ;
8
+
9
+ return new Promise ( ( resolve ) => {
10
+ rlInterface . question ( question + '\n' , function ( answer ) {
11
+ rlInterface . close ( ) ;
12
+ resolve ( answer ) ;
13
+ } ) ;
14
+ } ) ;
15
+ } ;
Original file line number Diff line number Diff line change
1
+ import prompt from './prompt' ;
2
+ import detect from 'detect-port' ;
3
+ import chalk from 'chalk' ;
4
+
5
+ export default async function run ( srv , desiredPort ) {
6
+ const port = await detect ( desiredPort ) ;
7
+ if ( port !== desiredPort ) {
8
+ const question = chalk . red ( `Something is already running at port ${ desiredPort } .\n` +
9
+ `Would you like to run the app on port ${ port } instead? [Y/n]` ) ;
10
+ const answer = await prompt ( question ) ;
11
+ const shouldChangePort = ( answer . length === 0 || answer . match ( / ^ y e s | y $ / i) ) ;
12
+ if ( ! shouldChangePort ) {
13
+ console . log ( chalk . red ( 'Exiting.' ) ) ;
14
+ process . exit ( 0 ) ;
15
+ }
16
+ }
17
+ await srv . start ( port ) ;
18
+ console . log ( `Ready on ${ chalk . cyan ( `http://localhost:${ port } ` ) } ` ) ;
19
+ }
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ gulp.task('compile', [
26
26
] )
27
27
28
28
gulp . task ( 'compile-bin' , ( ) => {
29
- return gulp . src ( 'bin/*' )
29
+ return gulp . src ( 'bin/**/*.js ' )
30
30
. pipe ( cache ( 'bin' ) )
31
31
. pipe ( babel ( babelOptions ) )
32
32
. pipe ( gulp . dest ( 'dist/bin' ) )
Original file line number Diff line number Diff line change 47
47
"babel-preset-es2015" : " 6.16.0" ,
48
48
"babel-preset-react" : " 6.16.0" ,
49
49
"babel-runtime" : " 6.11.6" ,
50
+ "chalk" : " ^1.1.3" ,
50
51
"cross-spawn" : " 4.0.2" ,
51
52
"del" : " 2.2.2" ,
53
+ "detect-port" : " ^1.0.1" ,
52
54
"glamor" : " 2.17.10" ,
53
55
"glob-promise" : " 1.0.6" ,
54
56
"htmlescape" : " 1.1.1" ,
59
61
"react" : " 15.3.2" ,
60
62
"react-dom" : " 15.3.2" ,
61
63
"react-hot-loader" : " 3.0.0-beta.6" ,
64
+ "readline" : " ^1.3.0" ,
62
65
"send" : " 0.14.1" ,
63
66
"strip-ansi" : " 3.0.1" ,
64
67
"url" : " 0.11.0" ,
You can’t perform that action at this time.
0 commit comments