1
1
'use strict' ;
2
2
const fs = require ( 'fs' ) ;
3
+ const os = require ( 'os' ) ;
3
4
const eol = require ( 'os' ) . EOL ;
4
5
const chalk = require ( 'chalk' ) ;
6
+ const execa = require ( 'execa' ) ;
5
7
const semver = require ( 'semver' ) ;
6
8
const constants = require ( 'constants' ) ;
9
+
10
+ const errors = require ( '../../../errors' ) ;
7
11
const cliPackage = require ( '../../../../package' ) ;
8
12
9
13
module . exports = [ {
10
14
title : 'Checking system node version' ,
11
15
task : ( ) => {
12
16
if ( process . env . GHOST_NODE_VERSION_CHECK !== 'false' &&
13
17
! semver . satisfies ( process . versions . node , cliPackage . engines . node ) ) {
14
- return Promise . reject ( new Error (
18
+ return Promise . reject ( new errors . SystemError (
15
19
`${ chalk . red ( 'The version of node you are using is not supported.' ) } ${ eol } ` +
16
20
`${ chalk . gray ( 'Supported: ' ) } ${ cliPackage . engines . node } ${ eol } ` +
17
21
`${ chalk . gray ( 'Installed: ' ) } ${ process . versions . node } ${ eol } ` +
@@ -26,10 +30,78 @@ module.exports = [{
26
30
try {
27
31
fs . accessSync ( process . cwd ( ) , constants . R_OK | constants . W_OK ) ;
28
32
} catch ( e ) {
29
- return Promise . reject ( new Error (
33
+ return Promise . reject ( new errors . SystemError (
30
34
`The current directory is not writable.${ eol } ` +
31
35
'Please fix your directory permissions.'
32
36
) ) ;
33
37
}
34
38
}
39
+ } , {
40
+ title : 'Checking official system stack' ,
41
+ skip : ( ctx ) => ctx . local || ( ctx . argv && ! ctx . argv . stack ) ,
42
+ task : ( ctx ) => {
43
+ let promise ;
44
+
45
+ if ( os . platform ( ) !== 'linux' ) {
46
+ promise = Promise . reject ( { message : 'Platform is not Linux' } ) ;
47
+ } else {
48
+ promise = execa . shell ( 'lsb_release -a' ) . catch (
49
+ ( ) => Promise . reject ( { message : 'Linux version is not Ubuntu 16' } )
50
+ ) . then ( ( result ) => {
51
+ if ( ! result . stdout || ! result . stdout . match ( / U b u n t u 1 6 / ) ) {
52
+ return Promise . reject ( { message : 'Linux version is not Ubuntu 16' } ) ;
53
+ }
54
+
55
+ return ctx . ui . listr ( [ {
56
+ title : 'Systemd' ,
57
+ task : ( ) => execa . shell ( 'dpkg -l | grep systemd' )
58
+ . catch ( ( ) => Promise . reject ( { missing : 'systemd' } ) )
59
+ } , {
60
+ title : 'Nginx' ,
61
+ task : ( ) => execa . shell ( 'dpkg -l | grep nginx' )
62
+ . catch ( ( ) => Promise . reject ( { missing : 'nginx' } ) )
63
+ } ] , ctx , {
64
+ concurrent : true ,
65
+ exitOnError : false ,
66
+ renderer : ctx . ui . verbose ? 'verbose' : 'silent'
67
+ } ) . catch ( error => Promise . reject ( {
68
+ message : `Missing package(s): ${ error . errors . map ( e => e . missing ) . join ( ', ' ) } `
69
+ } ) )
70
+ } ) ;
71
+ }
72
+
73
+ return promise . then ( ( ) => { return { yes : true } ; } ) . catch ( ( error ) => {
74
+ ctx . ui . log (
75
+ `System Stack checks failed with message: '${ error . message } '${ eol } ` +
76
+ `Some features of Ghost-CLI may not work without additional configuration.${ eol } ` +
77
+ 'For local installs we recommend using `ghost install local` instead.' ,
78
+ 'yellow'
79
+ ) ;
80
+
81
+ return ctx . ui . confirm ( chalk . blue ( 'Continue anyways?' ) , false ) ;
82
+ } ) . then ( answer => answer . yes || Promise . reject (
83
+ new errors . SystemError ( 'System Stack checks failed.' )
84
+ ) ) ;
85
+ }
86
+ } , {
87
+ title : 'Checking for MySQL availability' ,
88
+ skip : ( ctx ) => ctx . local || ( ctx . argv && ctx . argv . db === 'sqlite3' ) ,
89
+ task : ( ctx ) => {
90
+ // Technically this doesn't work on windows, but there's
91
+ // not an easy way to do that anyways so ¯\_(ツ)_/¯
92
+ return execa . shell ( 'which mysqld' ) . catch ( ( ) => {
93
+ ctx . ui . log (
94
+ chalk . yellow ( `Local MySQL install not found. You can ignore this if you are using a remote MySQL host.${ eol } ` ) +
95
+ chalk . yellow ( `Alternatively you could:${ eol } ` ) +
96
+ `${ chalk . blue ( 'a)' ) } install MySQL locally${ eol } ` +
97
+ `${ chalk . blue ( 'b)' ) } run ${ chalk . cyan ( '`ghost install --db=sqlite3`' ) } to use sqlite ${ eol } ` +
98
+ `${ chalk . blue ( 'c)' ) } run ${ chalk . cyan ( '`ghost install local`' ) } to get a non-production install with sqlite3.`
99
+ ) ;
100
+
101
+ return ctx . ui . confirm ( chalk . blue ( 'Continue anyways?' ) , false )
102
+ . then ( answer => answer . yes || Promise . reject (
103
+ new errors . SystemError ( 'MySQL check failed.' )
104
+ ) ) ;
105
+ } ) ;
106
+ }
35
107
} ] ;
0 commit comments