1
1
'use strict' ;
2
2
const fs = require ( 'fs-extra' ) ;
3
3
const path = require ( 'path' ) ;
4
+ const map = require ( 'lodash/map' ) ;
4
5
5
6
// Utils
6
7
const errors = require ( '../errors' ) ;
@@ -60,6 +61,18 @@ class UpdateCommand extends Command {
60
61
61
62
// TODO: add meaningful update checks after this task
62
63
const tasks = [ {
64
+ title : 'Updating to a major version' ,
65
+ task : this . majorSupport . bind ( this ) ,
66
+ // CASE: Skip if you are already on ^2 or you update from v1 to v1.
67
+ enabled : ( ) => {
68
+ if ( semver . satisfies ( instance . cliConfig . get ( 'active-version' ) , '^2.0.0' ) ||
69
+ ! semver . satisfies ( context . version , '^2.0.0' ) ) {
70
+ return false ;
71
+ }
72
+
73
+ return true ;
74
+ }
75
+ } , {
63
76
title : 'Downloading and updating Ghost' ,
64
77
skip : ( ctx ) => ctx . rollback ,
65
78
task : this . downloadAndUpdate
@@ -75,7 +88,7 @@ class UpdateCommand extends Command {
75
88
skip : ( ctx ) => ctx . rollback ,
76
89
task : migrate ,
77
90
// CASE: We have moved the execution of knex-migrator into Ghost 2.0.0.
78
- // If you are already on ^2 or you update from ^1 to ^2 , then skip the task.
91
+ // If you are already on v2 or you update from v1 to v2 , then skip the task.
79
92
enabled : ( ) => {
80
93
if ( semver . satisfies ( instance . cliConfig . get ( 'active-version' ) , '^2.0.0' ) ||
81
94
semver . satisfies ( context . version , '^2.0.0' ) ) {
@@ -128,6 +141,69 @@ class UpdateCommand extends Command {
128
141
return yarnInstall ( ctx . ui , ctx . zip ) ;
129
142
}
130
143
144
+ majorSupport ( ctx ) {
145
+ const majorSupport = require ( '../utils/major-support' ) ;
146
+ let gscanReport ;
147
+ let demoPost ;
148
+
149
+ return majorSupport ( {
150
+ dir : ctx . instance . dir ,
151
+ database : ctx . instance . config . get ( 'database' )
152
+ } ) . then ( ( response ) => {
153
+ gscanReport = response . gscanReport ;
154
+ demoPost = response . demoPost ;
155
+
156
+ this . ui . log ( `\nYou are about to migrate to Ghost 2.0.0.` , 'green' ) ;
157
+
158
+ this . ui . log ( `\n## Theme compatibility` , 'magenta' , null , true ) ;
159
+
160
+ if ( ! gscanReport . results . error . length && ! gscanReport . results . warning . length ) {
161
+ this . ui . log ( '\nYour theme is compatible.\n' )
162
+ } else {
163
+ this . ui . log ( `\nYour theme has ${ gscanReport . results . error . length } errors and ${ gscanReport . results . warning . length } warnings.\n` ) ;
164
+ this . ui . log ( 'We recommend visiting https://gscan.ghost.org to take a look at the full report.\n' ) ;
165
+ return this . ui . confirm ( 'Would you like to print the full report anyway?' ) ;
166
+ }
167
+ } ) . then ( ( answer ) => {
168
+ if ( answer ) {
169
+ if ( gscanReport . results . error . length ) {
170
+ this . ui . log ( '\n### Errors\n' , 'red' ) ;
171
+ gscanReport . results . error . forEach ( ( error ) => {
172
+ this . ui . log ( `Rule: ${ error . rule } ` ) ;
173
+ this . ui . log ( `File: ${ map ( error . failures , 'ref' ) . join ( ',' ) } ` ) ;
174
+ } ) ;
175
+ this . ui . log ( '\n' ) ;
176
+ }
177
+
178
+ if ( gscanReport . results . warning . length ) {
179
+ this . ui . log ( '\n### Warnings\n' , 'yellow' ) ;
180
+ gscanReport . results . warning . forEach ( ( warning ) => {
181
+ this . ui . log ( `Rule: ${ warning . rule } ` ) ;
182
+ this . ui . log ( `File: ${ map ( warning . failures , 'ref' ) . join ( ',' ) } ` ) ;
183
+ } ) ;
184
+ this . ui . log ( '\n' ) ;
185
+ }
186
+ }
187
+
188
+ return this . ui . confirm ( 'Would you like to look at the demo post?' ) ;
189
+ } ) . then ( ( answer ) => {
190
+ if ( answer ) {
191
+ this . ui . log ( '\n' ) ;
192
+ this . ui . log ( `${ ctx . instance . config . get ( 'url' ) } p/${ demoPost . uuid } /` ) ;
193
+ this . ui . log ( '\n' ) ;
194
+ }
195
+
196
+ return this . ui . confirm ( 'Continue with updating to the next major version?' )
197
+ . then ( ( answer ) => {
198
+ if ( ! answer ) {
199
+ return Promise . reject ( new errors . CliError ( {
200
+ message : 'Update aborted. Nothing happens.'
201
+ } ) ) ;
202
+ }
203
+ } ) ;
204
+ } ) ;
205
+ }
206
+
131
207
stop ( ) {
132
208
const StopCommand = require ( './stop' ) ;
133
209
0 commit comments