File tree Expand file tree Collapse file tree 6 files changed +43
-7
lines changed Expand file tree Collapse file tree 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'
44import { exists } from 'mz/fs'
55import Server from '../server'
66import clean from '../server/build/clean'
7+ import run from './util/run' ;
78
89const argv = parseArgs ( process . argv . slice ( 2 ) , {
910 alias : {
@@ -21,8 +22,7 @@ const dir = resolve(argv._[0] || '.')
2122clean ( dir )
2223. then ( async ( ) => {
2324 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 )
2626
2727 // Check if pages dir exists and warn if not
2828 if ( ! ( await exists ( join ( dir , 'pages' ) ) ) ) {
Original file line number Diff line number Diff line change 33import { resolve } from 'path'
44import parseArgs from 'minimist'
55import Server from '../server'
6+ import run from './util/run' ;
67
78const argv = parseArgs ( process . argv . slice ( 2 ) , {
89 alias : {
@@ -18,10 +19,8 @@ const argv = parseArgs(process.argv.slice(2), {
1819const dir = resolve ( argv . _ [ 0 ] || '.' )
1920
2021const 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 )
2524. catch ( ( err ) => {
2625 console . error ( err )
2726 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', [
2626] )
2727
2828gulp . task ( 'compile-bin' , ( ) => {
29- return gulp . src ( 'bin/*' )
29+ return gulp . src ( 'bin/**/*.js ' )
3030 . pipe ( cache ( 'bin' ) )
3131 . pipe ( babel ( babelOptions ) )
3232 . pipe ( gulp . dest ( 'dist/bin' ) )
Original file line number Diff line number Diff line change 4747 "babel-preset-es2015" : " 6.16.0" ,
4848 "babel-preset-react" : " 6.16.0" ,
4949 "babel-runtime" : " 6.11.6" ,
50+ "chalk" : " ^1.1.3" ,
5051 "cross-spawn" : " 4.0.2" ,
5152 "del" : " 2.2.2" ,
53+ "detect-port" : " ^1.0.1" ,
5254 "glamor" : " 2.17.10" ,
5355 "glob-promise" : " 1.0.6" ,
5456 "htmlescape" : " 1.1.1" ,
5961 "react" : " 15.3.2" ,
6062 "react-dom" : " 15.3.2" ,
6163 "react-hot-loader" : " 3.0.0-beta.6" ,
64+ "readline" : " ^1.3.0" ,
6265 "send" : " 0.14.1" ,
6366 "strip-ansi" : " 3.0.1" ,
6467 "url" : " 0.11.0" ,
You can’t perform that action at this time.
0 commit comments