Skip to content

Commit

Permalink
feat(v3): make v2 specific logic work for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine committed Oct 16, 2019
1 parent e74d1fc commit 3d3a0e7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
26 changes: 3 additions & 23 deletions lib/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,7 @@ class UpdateCommand extends Command {
}, {
title: 'Updating to a major version',
task: majorUpdate,
// CASE: Skip if you are already on ^2 or you update from v1 to v1.
enabled: () => {
if (semver.major(instance.version) === 2 ||
semver.major(context.version) === 1) {
return false;
}

return true;
}
enabled: () => semver.major(context.version) > semver.major(instance.version)
}, {
title: 'Stopping Ghost',
enabled: () => isRunning,
Expand All @@ -103,14 +95,7 @@ class UpdateCommand extends Command {
// CASE: We have moved the execution of knex-migrator into Ghost 2.0.0.
// If you are already on v2 or you update from v1 to v2, then skip the task.
// We compare the major versions, otherwise pre-releases won't match.
enabled: () => {
if (semver.major(instance.version) === 2 ||
semver.major(context.version) === 2) {
return false;
}

return true;
}
enabled: () => semver.major(context.version) < 2
}, {
title: 'Restarting Ghost',
enabled: () => argv.restart,
Expand Down Expand Up @@ -182,17 +167,12 @@ class UpdateCommand extends Command {
const semver = require('semver');

return fs.readdir(path.join(process.cwd(), 'versions')).then((versions) => {
versions = versions.filter(semver.valid);
versions = versions.filter(semver.valid).sort(semver.compare);
if (versions.length <= 5) {
task.skip();
return;
}

// eslint-disable-next-line arrow-body-style
versions.sort((a, b) => {
return semver.lt(a, b) ? -1 : 1;
});

const promises = versions.slice(0, -5)
.map(version => fs.remove(path.join(process.cwd(), 'versions', version)));

Expand Down
2 changes: 1 addition & 1 deletion lib/process-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ProcessManager {
stopOnError: true,
port: this.instance.config.get('server.port'),
host: this.instance.config.get('server.host', 'localhost'),
useNetServer: semver.major(this.instance.version) === 2
useNetServer: semver.major(this.instance.version) >= 2
}, options || {});

try {
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module.exports.rollback = function runRollback(context) {

// Ghost 2.0.0 uses the new knex-migrator version. We have to ensure you can still use CLI 1.9 with an older blog, because
// we haven't restricted a CLI version range in Ghost (we only used cli: > X.X.X)
if (semver.major(version) === 2) {
if (semver.major(version) >= 2) {
args = ['--force', '--v', previousVersion, '--mgpath', currentDir];
} else {
args = ['--force', '--mgpath', currentDir];
Expand Down

0 comments on commit 3d3a0e7

Please sign in to comment.