Skip to content

Commit

Permalink
Added support for major blog update
Browse files Browse the repository at this point in the history
refs #759

[ci skip]
  • Loading branch information
kirrg001 committed Jul 31, 2018
1 parent 06bc19c commit 331b54f
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 1 deletion.
75 changes: 74 additions & 1 deletion lib/commands/update.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const fs = require('fs-extra');
const path = require('path');
const map = require('lodash/map');

// Utils
const errors = require('../errors');
Expand Down Expand Up @@ -60,6 +61,18 @@ class UpdateCommand extends Command {

// TODO: add meaningful update checks after this task
const tasks = [{
title: 'Support for upgrading to a major version',
task: this.majorSupport.bind(this),
// CASE: Skip if you are already on ^2 or you update from v1 to v1.
enabled: () => {
if (semver.satisfies(instance.cliConfig.get('active-version'), '^2.0.0') ||
!semver.satisfies(context.version, '^2.0.0')) {
return false;
}

return true;
}
}, {
title: 'Downloading and updating Ghost',
skip: (ctx) => ctx.rollback,
task: this.downloadAndUpdate
Expand All @@ -75,7 +88,7 @@ class UpdateCommand extends Command {
skip: (ctx) => ctx.rollback,
task: migrate,
// CASE: We have moved the execution of knex-migrator into Ghost 2.0.0.
// If you are already on ^2 or you update from ^1 to ^2, then skip the task.
// If you are already on v2 or you update from v1 to v2, then skip the task.
enabled: () => {
if (semver.satisfies(instance.cliConfig.get('active-version'), '^2.0.0') ||
semver.satisfies(context.version, '^2.0.0')) {
Expand Down Expand Up @@ -128,6 +141,66 @@ class UpdateCommand extends Command {
return yarnInstall(ctx.ui, ctx.zip);
}

majorSupport(ctx) {
const majorSupport = require('../utils/major-support');
let gscanReport;
let demoPost;

return majorSupport({
dir: ctx.instance.dir,
database: ctx.instance.config.get('database')
}).then((response) => {
gscanReport = response.gscanReport;
demoPost = response.demoPost;

this.ui.log(`\nTheme score: ${gscanReport.results.score.value}\n`);

if (gscanReport.results.error.length) {
this.ui.log('### Errors\n');
gscanReport.results.error.forEach((error) => {
this.ui.log(`Rule: ${error.rule}`);
this.ui.log(`File: ${map(error.failures, 'ref').join(',')}`);
});
}

if (gscanReport.results.warning.length) {
this.ui.log('### Warnings\n');
gscanReport.results.warning.forEach((warning) => {
this.ui.log(`Rule: ${warning.rule}`);
this.ui.log(`File: ${map(warning.failures, 'ref').join(',')}`);
});
}

if (!gscanReport.results.error.length && !gscanReport.results.warning.length) {
this.ui.log('Theme is compatible.\n')
}

return this.ui.prompt({
type: 'confirm',
name: 'yes',
message: 'Would you like to look at the demo post?'
});
}).then((answer) => {
if (answer.yes) {
this.ui.log('\n');
this.ui.log(`${ctx.instance.config.get('url')}p/${demoPost.uuid}/`);
this.ui.log('\n');
}

return this.ui.prompt({
type: 'confirm',
name: 'yes',
message: 'Continue with updating to the next major version?'
}).then((answer) => {
if (!answer.yes) {
return Promise.reject(new errors.CliError({
message: 'Update aborted. Nothing happens.'
}));
}
});
});
}

stop() {
const StopCommand = require('./stop');

Expand Down
58 changes: 58 additions & 0 deletions lib/utils/major-support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const errors = require('../errors');

module.exports = function majorSupport(options = {}) {
const path = require('path');

if (!options.dir) {
return Promise.reject(new errors.CliError({
message: '`dir` is required.'
}))
}

if (!options.database) {
return Promise.reject(new errors.CliError({
message: '`database` is required.'
}))
}

const knexPath = options.knexPath || path.resolve(options.dir, 'current/node_modules/knex');
const gscanPath = options.gscanPath || path.resolve(options.dir, 'current/node_modules/gscan');

const knex = require(knexPath);
const gscan = require(gscanPath);

const connection = knex(options.database);

const themeFolder = options.contentPath || path.resolve(options.dir, 'content', 'themes');
let activeTheme;
let gscanReport;

return connection.raw('SELECT * FROM settings WHERE `key`="active_theme";')
.then((response) => {
activeTheme = response[0].value;

return gscan.check(path.resolve(themeFolder, activeTheme));
})
.then((report) => {
gscanReport = gscan.format(report);

return connection.raw('SELECT uuid FROM posts WHERE slug="v2-demo-post";')
})
.then((demoPost) => {
if (demoPost.length) {
demoPost = demoPost[0];
}

return {
gscanReport: gscanReport,
demoPost: demoPost
}
})
.finally(() => {
return new Promise((resolve) => {
connection.destroy(() => {
resolve();
});
});
});
};

0 comments on commit 331b54f

Please sign in to comment.