@@ -5,44 +5,51 @@ const WebServer = require('./web-server');
55const webServer = new WebServer ( ) ;
66const runCommand = require ( '../src/utility/run-command' ) ;
77const { themes, swatchModes, baseFontFamily } = require ( './constants' ) ;
8- let startedPromise = null ;
98
10- module . exports = class DevServer {
11- constructor ( env ) {
12- this . env = env ;
9+ class nextJsState {
10+ async start ( env ) {
11+ this . proc = runCommand ( 'npm' , [ 'run' , 'start' ] , {
12+ cwd : this . env . appPath ,
13+ noExit : true ,
14+ detached : true ,
15+ // https://github.com/facebook/create-react-app/issues/3657
16+ env : Object . assign ( process . env , { CI : false } )
17+ } ) ;
18+
19+ await this . proc ;
1320 }
1421
15- async start ( ) {
16- if ( this . env . engine . indexOf ( 'nextjs' ) === 0 ) {
17- /* if(startedPromise) {
18- await startedPromise.kill();
19- } */
22+ stop ( ) {
23+ if ( this . proc ) {
24+ this . proc . kill ( ) ;
25+ }
26+ }
27+ }
2028
21- console . log ( '-----start----->' , this . env . appPath ) ;
29+ module . exports = class DevServer {
30+ isNextJs ( ) {
31+ return this . env . engine . indexOf ( 'nextjs' ) === 0 ;
32+ }
2233
23- startedPromise = runCommand ( 'npm' , [ 'run' , 'start' ] , {
24- cwd : this . env . appPath ,
25- noExit : true ,
26- detached : true ,
27- // https://github.com/facebook/create-react-app/issues/3657
28- env : Object . assign ( process . env , { CI : false } )
29- } ) ;
34+ constructor ( env ) {
35+ this . env = env ;
3036
31- await startedPromise ;
37+ if ( this . isNextJs ( ) ) {
38+ this . nextJsState = new nextJsState ( ) ;
39+ }
40+ }
3241
33- console . log ( '-----start--runCommand-executed-->' ) ;
42+ async start ( ) {
43+ if ( this . isNextJs ( ) ) {
44+ await this . nextJsState . start ( ) ;
3445 } else {
3546 await webServer . start ( this . env . deployPath ) ;
3647 }
3748 }
3849
3950 async stop ( ) {
40- if ( this . env . engine . indexOf ( 'nextjs' ) === 0 ) {
41- if ( startedPromise ) {
42- console . log ( '----server.stop()------>' ) ;
43- await startedPromise . kill ( ) ;
44- startedPromise = null ;
45- }
51+ if ( this . isNextJs ( ) ) {
52+ await this . nextJsState . stop ( ) ;
4653 } else {
4754 await webServer . stop ( ) ;
4855 }
0 commit comments