@@ -76,7 +76,7 @@ class StartCommand extends Command {
7676 return 'Start server at prod mode' ;
7777 }
7878
79- * run ( context ) {
79+ async run ( context ) {
8080 context . execArgvObj = context . execArgvObj || { } ;
8181 const { argv, env, cwd, execArgvObj } = context ;
8282 const HOME = homedir ( ) ;
@@ -91,12 +91,12 @@ class StartCommand extends Command {
9191
9292 const isDaemon = argv . daemon ;
9393
94- argv . framework = yield this . getFrameworkPath ( {
94+ argv . framework = await this . getFrameworkPath ( {
9595 framework : argv . framework ,
9696 baseDir,
9797 } ) ;
9898
99- this . frameworkName = yield this . getFrameworkName ( argv . framework ) ;
99+ this . frameworkName = await this . getFrameworkName ( argv . framework ) ;
100100
101101 const pkgInfo = require ( path . join ( baseDir , 'package.json' ) ) ;
102102 argv . title = argv . title || `egg-server-${ pkgInfo . name } ` ;
@@ -121,7 +121,7 @@ class StartCommand extends Command {
121121 // for alinode
122122 env . ENABLE_NODE_LOG = 'YES' ;
123123 env . NODE_LOG_DIR = env . NODE_LOG_DIR || path . join ( logDir , 'alinode' ) ;
124- yield mkdirp ( env . NODE_LOG_DIR ) ;
124+ await mkdirp ( env . NODE_LOG_DIR ) ;
125125
126126 // cli argv -> process.env.EGG_SERVER_ENV -> `undefined` then egg will use `prod`
127127 if ( argv . env ) {
@@ -132,6 +132,14 @@ class StartCommand extends Command {
132132 // additional execArgv
133133 execArgvObj . deprecation = false ; // --no-deprecation
134134 execArgvObj . traceWarnings = true ; // --trace-warnings
135+ const eggInfo = pkgInfo . egg || { } ;
136+ if ( eggInfo . revert ) {
137+ context . execArgvObj [ 'security-revert' ] = context . execArgvObj [ 'security-revert' ] || [ ] ;
138+ const reverts = Array . isArray ( eggInfo . revert ) ? eggInfo . revert : [ eggInfo . revert ] ;
139+ for ( const revert of reverts ) {
140+ context . execArgvObj [ 'security-revert' ] . push ( revert ) ;
141+ }
142+ }
135143
136144 const command = argv . node || 'node' ;
137145
@@ -154,7 +162,10 @@ class StartCommand extends Command {
154162 // whether run in the background.
155163 if ( isDaemon ) {
156164 this . logger . info ( `Save log file to ${ logDir } ` ) ;
157- const [ stdout , stderr ] = yield [ getRotatelog ( argv . stdout ) , getRotatelog ( argv . stderr ) ] ;
165+ const [ stdout , stderr ] = await Promise . all ( [
166+ getRotatelog ( argv . stdout ) ,
167+ getRotatelog ( argv . stderr ) ,
168+ ] ) ;
158169 options . stdio = [ 'ignore' , stdout , stderr , 'ipc' ] ;
159170 options . detached = true ;
160171
@@ -173,7 +184,7 @@ class StartCommand extends Command {
173184 } ) ;
174185
175186 // check start status
176- yield this . checkStatus ( argv ) ;
187+ await this . checkStatus ( argv ) ;
177188 } else {
178189 options . stdio = [ 'inherit' , 'inherit' , 'inherit' , 'ipc' ] ;
179190 debug ( 'Run spawn `%s %s`' , command , eggArgs . join ( ' ' ) ) ;
@@ -194,11 +205,24 @@ class StartCommand extends Command {
194205 }
195206 }
196207
197- * getFrameworkPath ( params ) {
208+ async getFrameworkPath ( params ) {
198209 return utils . getFrameworkPath ( params ) ;
199210 }
200211
201- * getFrameworkName ( framework ) {
212+ async getFrameworkName ( framework ) {
213+ const pkgPath = path . join ( framework , 'package.json' ) ;
214+ let name = 'egg' ;
215+ try {
216+ const pkg = require ( pkgPath ) ;
217+ /* istanbul ignore else */
218+ if ( pkg . name ) name = pkg . name ;
219+ } catch ( _ ) {
220+ /* istanbul next */
221+ }
222+ return name ;
223+ }
224+
225+ async getRevert ( framework ) {
202226 const pkgPath = path . join ( framework , 'package.json' ) ;
203227 let name = 'egg' ;
204228 try {
@@ -211,14 +235,14 @@ class StartCommand extends Command {
211235 return name ;
212236 }
213237
214- * checkStatus ( { stderr, timeout, 'ignore-stderr' : ignoreStdErr } ) {
238+ async checkStatus ( { stderr, timeout, 'ignore-stderr' : ignoreStdErr } ) {
215239 let count = 0 ;
216240 let hasError = false ;
217241 let isSuccess = true ;
218242 timeout = timeout / 1000 ;
219243 while ( ! this . isReady ) {
220244 try {
221- const stat = yield fs . stat ( stderr ) ;
245+ const stat = await fs . stat ( stderr ) ;
222246 if ( stat && stat . size > 0 ) {
223247 hasError = true ;
224248 break ;
@@ -233,15 +257,15 @@ class StartCommand extends Command {
233257 break ;
234258 }
235259
236- yield sleep ( 1000 ) ;
260+ await sleep ( 1000 ) ;
237261 this . logger . log ( 'Wait Start: %d...' , ++ count ) ;
238262 }
239263
240264 if ( hasError ) {
241265 try {
242266 const args = [ '-n' , '100' , stderr ] ;
243267 this . logger . error ( 'tail %s' , args . join ( ' ' ) ) ;
244- const [ stdout ] = yield execFile ( 'tail' , args ) ;
268+ const [ stdout ] = await execFile ( 'tail' , args ) ;
245269 this . logger . error ( 'Got error when startup: ' ) ;
246270 this . logger . error ( stdout ) ;
247271 } catch ( err ) {
@@ -254,23 +278,23 @@ class StartCommand extends Command {
254278
255279 if ( ! isSuccess ) {
256280 this . child . kill ( 'SIGTERM' ) ;
257- yield sleep ( 1000 ) ;
281+ await sleep ( 1000 ) ;
258282 this . exit ( 1 ) ;
259283 }
260284 }
261285}
262286
263- function * getRotatelog ( logfile ) {
264- yield mkdirp ( path . dirname ( logfile ) ) ;
287+ async function getRotatelog ( logfile ) {
288+ await mkdirp ( path . dirname ( logfile ) ) ;
265289
266- if ( yield fs . exists ( logfile ) ) {
290+ if ( await fs . exists ( logfile ) ) {
267291 // format style: .20150602.193100
268292 const timestamp = moment ( ) . format ( '.YYYYMMDD.HHmmss' ) ;
269293 // Note: rename last log to next start time, not when last log file created
270- yield fs . rename ( logfile , logfile + timestamp ) ;
294+ await fs . rename ( logfile , logfile + timestamp ) ;
271295 }
272296
273- return yield fs . open ( logfile , 'a' ) ;
297+ return await fs . open ( logfile , 'a' ) ;
274298}
275299
276300function stringify ( obj , ignore ) {
0 commit comments