@@ -76,7 +76,7 @@ class StartCommand extends Command {
76
76
return 'Start server at prod mode' ;
77
77
}
78
78
79
- * run ( context ) {
79
+ async run ( context ) {
80
80
context . execArgvObj = context . execArgvObj || { } ;
81
81
const { argv, env, cwd, execArgvObj } = context ;
82
82
const HOME = homedir ( ) ;
@@ -91,12 +91,12 @@ class StartCommand extends Command {
91
91
92
92
const isDaemon = argv . daemon ;
93
93
94
- argv . framework = yield this . getFrameworkPath ( {
94
+ argv . framework = await this . getFrameworkPath ( {
95
95
framework : argv . framework ,
96
96
baseDir,
97
97
} ) ;
98
98
99
- this . frameworkName = yield this . getFrameworkName ( argv . framework ) ;
99
+ this . frameworkName = await this . getFrameworkName ( argv . framework ) ;
100
100
101
101
const pkgInfo = require ( path . join ( baseDir , 'package.json' ) ) ;
102
102
argv . title = argv . title || `egg-server-${ pkgInfo . name } ` ;
@@ -121,7 +121,7 @@ class StartCommand extends Command {
121
121
// for alinode
122
122
env . ENABLE_NODE_LOG = 'YES' ;
123
123
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 ) ;
125
125
126
126
// cli argv -> process.env.EGG_SERVER_ENV -> `undefined` then egg will use `prod`
127
127
if ( argv . env ) {
@@ -132,6 +132,14 @@ class StartCommand extends Command {
132
132
// additional execArgv
133
133
execArgvObj . deprecation = false ; // --no-deprecation
134
134
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
+ }
135
143
136
144
const command = argv . node || 'node' ;
137
145
@@ -154,7 +162,10 @@ class StartCommand extends Command {
154
162
// whether run in the background.
155
163
if ( isDaemon ) {
156
164
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
+ ] ) ;
158
169
options . stdio = [ 'ignore' , stdout , stderr , 'ipc' ] ;
159
170
options . detached = true ;
160
171
@@ -173,7 +184,7 @@ class StartCommand extends Command {
173
184
} ) ;
174
185
175
186
// check start status
176
- yield this . checkStatus ( argv ) ;
187
+ await this . checkStatus ( argv ) ;
177
188
} else {
178
189
options . stdio = [ 'inherit' , 'inherit' , 'inherit' , 'ipc' ] ;
179
190
debug ( 'Run spawn `%s %s`' , command , eggArgs . join ( ' ' ) ) ;
@@ -194,11 +205,24 @@ class StartCommand extends Command {
194
205
}
195
206
}
196
207
197
- * getFrameworkPath ( params ) {
208
+ async getFrameworkPath ( params ) {
198
209
return utils . getFrameworkPath ( params ) ;
199
210
}
200
211
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 ) {
202
226
const pkgPath = path . join ( framework , 'package.json' ) ;
203
227
let name = 'egg' ;
204
228
try {
@@ -211,14 +235,14 @@ class StartCommand extends Command {
211
235
return name ;
212
236
}
213
237
214
- * checkStatus ( { stderr, timeout, 'ignore-stderr' : ignoreStdErr } ) {
238
+ async checkStatus ( { stderr, timeout, 'ignore-stderr' : ignoreStdErr } ) {
215
239
let count = 0 ;
216
240
let hasError = false ;
217
241
let isSuccess = true ;
218
242
timeout = timeout / 1000 ;
219
243
while ( ! this . isReady ) {
220
244
try {
221
- const stat = yield fs . stat ( stderr ) ;
245
+ const stat = await fs . stat ( stderr ) ;
222
246
if ( stat && stat . size > 0 ) {
223
247
hasError = true ;
224
248
break ;
@@ -233,15 +257,15 @@ class StartCommand extends Command {
233
257
break ;
234
258
}
235
259
236
- yield sleep ( 1000 ) ;
260
+ await sleep ( 1000 ) ;
237
261
this . logger . log ( 'Wait Start: %d...' , ++ count ) ;
238
262
}
239
263
240
264
if ( hasError ) {
241
265
try {
242
266
const args = [ '-n' , '100' , stderr ] ;
243
267
this . logger . error ( 'tail %s' , args . join ( ' ' ) ) ;
244
- const [ stdout ] = yield execFile ( 'tail' , args ) ;
268
+ const [ stdout ] = await execFile ( 'tail' , args ) ;
245
269
this . logger . error ( 'Got error when startup: ' ) ;
246
270
this . logger . error ( stdout ) ;
247
271
} catch ( err ) {
@@ -254,23 +278,23 @@ class StartCommand extends Command {
254
278
255
279
if ( ! isSuccess ) {
256
280
this . child . kill ( 'SIGTERM' ) ;
257
- yield sleep ( 1000 ) ;
281
+ await sleep ( 1000 ) ;
258
282
this . exit ( 1 ) ;
259
283
}
260
284
}
261
285
}
262
286
263
- function * getRotatelog ( logfile ) {
264
- yield mkdirp ( path . dirname ( logfile ) ) ;
287
+ async function getRotatelog ( logfile ) {
288
+ await mkdirp ( path . dirname ( logfile ) ) ;
265
289
266
- if ( yield fs . exists ( logfile ) ) {
290
+ if ( await fs . exists ( logfile ) ) {
267
291
// format style: .20150602.193100
268
292
const timestamp = moment ( ) . format ( '.YYYYMMDD.HHmmss' ) ;
269
293
// 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 ) ;
271
295
}
272
296
273
- return yield fs . open ( logfile , 'a' ) ;
297
+ return await fs . open ( logfile , 'a' ) ;
274
298
}
275
299
276
300
function stringify ( obj , ignore ) {
0 commit comments