2
2
const fs = require ( 'fs' ) ;
3
3
const path = require ( 'path' ) ;
4
4
const KnexMigrator = require ( 'knex-migrator' ) ;
5
+ const Listr = require ( 'listr' ) ;
5
6
6
7
const Config = require ( '../utils/config' ) ;
7
8
const errors = require ( '../errors' ) ;
9
+ const startupChecks = require ( './doctor/checks/startup' ) ;
8
10
const checkValidInstall = require ( '../utils/check-valid-install' ) ;
9
11
10
12
function register ( config , environment ) {
@@ -25,6 +27,7 @@ module.exports.execute = function execute(options) {
25
27
checkValidInstall ( 'start' ) ;
26
28
27
29
options = options || { } ;
30
+ let config , cliConfig ;
28
31
29
32
// If we are starting in production mode but a development config exists and a production config doesn't,
30
33
// we want to start in development mode anyways.
@@ -35,47 +38,49 @@ module.exports.execute = function execute(options) {
35
38
process . env . NODE_ENV = this . environment = 'development' ;
36
39
}
37
40
38
- let config = Config . load ( this . environment ) ;
39
- let cliConfig = Config . load ( '.ghost-cli' ) ;
41
+ return new Listr ( startupChecks , { renderer : this . renderer } ) . run ( this ) . then ( ( ) => {
42
+ config = Config . load ( this . environment ) ;
43
+ cliConfig = Config . load ( '.ghost-cli' ) ;
40
44
41
- if ( cliConfig . has ( 'running' ) ) {
42
- return Promise . reject ( new Error ( 'Ghost is already running.' ) ) ;
43
- }
45
+ if ( cliConfig . has ( 'running' ) ) {
46
+ return Promise . reject ( new Error ( 'Ghost is already running.' ) ) ;
47
+ }
44
48
45
- this . service . setConfig ( config ) ;
49
+ this . service . setConfig ( config ) ;
46
50
47
- process . env . paths__contentPath = path . join ( process . cwd ( ) , 'content' ) ;
51
+ process . env . paths__contentPath = path . join ( process . cwd ( ) , 'content' ) ;
48
52
49
- let knexMigrator = new KnexMigrator ( {
50
- knexMigratorFilePath : path . join ( process . cwd ( ) , 'current' )
51
- } ) ;
52
-
53
- return knexMigrator . isDatabaseOK ( ) . catch ( ( error ) => {
54
- if ( error . code === 'DB_NOT_INITIALISED' ||
55
- error . code === 'MIGRATION_TABLE_IS_MISSING' ) {
56
- return knexMigrator . init ( ) ;
57
- } else if ( error . code === 'DB_NEEDS_MIGRATION' ) {
58
- return knexMigrator . migrate ( ) ;
59
- }
60
-
61
- if ( error . code === 'ENOTFOUND' ) {
62
- // Database not found
63
- error = new errors . ConfigError ( {
64
- configKey : 'database.connection.host' ,
65
- configValue : config . get ( 'database.connection.host' ) ,
66
- message : 'Invalid database host' ,
67
- environment : this . environment
68
- } ) ;
69
- } else if ( error . code === 'ER_ACCESS_DENIED_ERROR' ) {
70
- error = new errors . ConfigError ( {
71
- configKey : 'database.connection.user' ,
72
- configValue : config . get ( 'database.connection.user' ) ,
73
- message : 'Invalid database username or password' ,
74
- environment : this . environment
75
- } ) ;
76
- }
53
+ let knexMigrator = new KnexMigrator ( {
54
+ knexMigratorFilePath : path . join ( process . cwd ( ) , 'current' )
55
+ } ) ;
77
56
78
- return Promise . reject ( error ) ;
57
+ return knexMigrator . isDatabaseOK ( ) . catch ( ( error ) => {
58
+ if ( error . code === 'DB_NOT_INITIALISED' ||
59
+ error . code === 'MIGRATION_TABLE_IS_MISSING' ) {
60
+ return knexMigrator . init ( ) ;
61
+ } else if ( error . code === 'DB_NEEDS_MIGRATION' ) {
62
+ return knexMigrator . migrate ( ) ;
63
+ }
64
+
65
+ if ( error . code === 'ENOTFOUND' ) {
66
+ // Database not found
67
+ error = new errors . ConfigError ( {
68
+ configKey : 'database.connection.host' ,
69
+ configValue : config . get ( 'database.connection.host' ) ,
70
+ message : 'Invalid database host' ,
71
+ environment : this . environment
72
+ } ) ;
73
+ } else if ( error . code === 'ER_ACCESS_DENIED_ERROR' ) {
74
+ error = new errors . ConfigError ( {
75
+ configKey : 'database.connection.user' ,
76
+ configValue : config . get ( 'database.connection.user' ) ,
77
+ message : 'Invalid database username or password' ,
78
+ environment : this . environment
79
+ } ) ;
80
+ }
81
+
82
+ return Promise . reject ( error ) ;
83
+ } ) ;
79
84
} ) . then ( ( ) => {
80
85
let start = ( ) => Promise . resolve ( this . service . process . start ( process . cwd ( ) , this . environment ) ) . then ( ( ) => {
81
86
register ( config , this . environment ) ;
0 commit comments