@@ -91,7 +91,8 @@ module.exports = class App {
91
91
}
92
92
93
93
/**
94
- * Load pages, load plugins, apply plugins / plugin options, etc.
94
+ * A asynchronous method used to prepare the context of the current app. which
95
+ * contains loading pages and plugins, apply plugins, etc.
95
96
*
96
97
* @returns {Promise<void> }
97
98
* @api private
@@ -445,30 +446,39 @@ module.exports = class App {
445
446
}
446
447
447
448
/**
448
- * Start a dev process with correct app context
449
+ * Launch a dev process with current app context.
449
450
*
450
- * @returns {Promise<void > }
451
+ * @returns {Promise<App > }
451
452
* @api public
452
453
*/
453
454
454
- async dev ( callback ) {
455
+ async dev ( ) {
455
456
this . isProd = false
456
457
this . devProcess = new DevProcess ( this )
457
458
await this . devProcess . process ( )
458
-
459
- this . devProcess
460
- . on ( 'fileChanged' , ( { type, target } ) => {
461
- console . log ( `Reload due to ${ chalk . red ( type ) } ${ chalk . cyan ( path . relative ( this . sourceDir , target ) ) } ` )
462
- this . process ( )
463
- } )
464
- . createServer ( )
465
- . listen ( callback )
459
+ const error = await new Promise ( resolve => {
460
+ try {
461
+ this . devProcess
462
+ . on ( 'fileChanged' , ( { type, target } ) => {
463
+ console . log ( `Reload due to ${ chalk . red ( type ) } ${ chalk . cyan ( path . relative ( this . sourceDir , target ) ) } ` )
464
+ this . process ( )
465
+ } )
466
+ . createServer ( )
467
+ . listen ( resolve )
468
+ } catch ( err ) {
469
+ resolve ( err )
470
+ }
471
+ } )
472
+ if ( error ) {
473
+ throw error
474
+ }
475
+ return this
466
476
}
467
477
468
478
/**
469
- * Start a build process with correct app context
479
+ * Launch a build process with current app context
470
480
*
471
- * @returns {Promise<void > }
481
+ * @returns {Promise<App > }
472
482
* @api public
473
483
*/
474
484
@@ -477,6 +487,7 @@ module.exports = class App {
477
487
this . buildProcess = new BuildProcess ( this )
478
488
await this . buildProcess . process ( )
479
489
await this . buildProcess . render ( )
490
+ return this
480
491
}
481
492
}
482
493
0 commit comments