Skip to content

Commit

Permalink
feat(flag): add --v1 flag to install and update
Browse files Browse the repository at this point in the history
refs #759
- adds --v1 flag to install and update commands
- add arg to resolveVersion util that limits versions to 1.x releases
  • Loading branch information
acburdine committed Aug 16, 2018
1 parent f56e600 commit eb315c3
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 71 deletions.
20 changes: 14 additions & 6 deletions lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class InstallCommand extends Command {
categories: ['install'],
skipInstanceCheck: true,
quiet: true
}, argv, {local: local})).then(() => {
}, argv, {local})).then(() => {
return this.ui.listr([{
title: 'Checking for latest Ghost version',
task: this.version
Expand All @@ -64,8 +64,9 @@ class InstallCommand extends Command {
task: this.casper
}], false)
}], {
version,
zip: argv.zip,
version: version,
v1: argv.v1,
cliVersion: this.system.cliVersion
})
}).then(() => {
Expand All @@ -80,11 +81,13 @@ class InstallCommand extends Command {
}

version(ctx) {
const versionResolver = ctx.zip ?
require('../utils/version-from-zip') :
require('../utils/resolve-version');
const {version, zip, v1} = ctx;

return versionResolver(ctx.zip || ctx.version).then((version) => {
const resolveVersion = zip ?
() => require('../utils/version-from-zip')(zip) :
() => require('../utils/resolve-version')(version, null, v1);

return resolveVersion().then((version) => {
ctx.version = version;
ctx.installPath = path.join(process.cwd(), 'versions', version);
});
Expand Down Expand Up @@ -133,6 +136,11 @@ InstallCommand.options = {
description: '[--no-setup] Enable/Disable auto-running the setup command',
type: 'boolean',
default: true
},
v1: {
describe: 'Limit install to Ghost 1.x releases',
type: 'boolean',
default: false
}
};
InstallCommand.checkVersion = true;
Expand Down
32 changes: 20 additions & 12 deletions lib/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ class UpdateCommand extends Command {
);
}

const {force, version, zip, v1} = argv;

const context = {
instance: instance,
force: argv.force,
instance,
force,
activeVersion: instance.cliConfig.get('active-version'),
version: argv.version,
zip: argv.zip
version,
zip,
v1
};

if (argv.rollback) {
Expand Down Expand Up @@ -169,18 +172,18 @@ class UpdateCommand extends Command {
}

version(context) {
if (context.rollback) {
const {rollback, zip, v1, version, force, activeVersion} = context;

if (rollback) {
return Promise.resolve(true);
}

const versionResolver = context.zip ?
require('../utils/version-from-zip') :
require('../utils/resolve-version');
const updateVersion = force ? null : activeVersion;
const resolveVersion = zip ?
() => require('../utils/version-from-zip')(zip, updateVersion) :
() => require('../utils/resolve-version')(version, updateVersion, v1);

return versionResolver(
context.zip || context.version,
context.force ? null : context.activeVersion
).then((version) => {
return resolveVersion().then((version) => {
context.version = version;
context.installPath = path.join(process.cwd(), 'versions', version);
return true;
Expand Down Expand Up @@ -225,6 +228,11 @@ UpdateCommand.options = {
description: '[--no-restart] Enable/Disable restarting Ghost after updating',
type: 'boolean',
default: true
},
v1: {
describe: 'Limit update to Ghost 1.x releases',
type: 'boolean',
default: false
}
};
UpdateCommand.checkVersion = true;
Expand Down
13 changes: 9 additions & 4 deletions lib/utils/resolve-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ const MIN_RELEASE = '>= 1.0.0';
* Resolves the ghost version to installed based on available NPM versions
* and/or a passed version & any locally installed versions
*
* @param {string} version Any version supplied manually by the user
* @param {string} update Current version if we are updating
* @param {String} version Any version supplied manually by the user
* @param {String} update Current version if we are updating
* @param {Boolean} v1 Whether or not to limit versions to 1.x release versions
* @return Promise<string> Promise that resolves with the version to install
*/
module.exports = function resolveVersion(version, update) {
module.exports = function resolveVersion(version, update, v1 = false) {
// If version contains a leading v, remove it
if (version && version.match(/^v[0-9]/)) {
version = version.slice(1);
Expand All @@ -28,7 +29,11 @@ module.exports = function resolveVersion(version, update) {
}

return yarn(['info', 'ghost', 'versions', '--json']).then((result) => {
const comparator = update ? `>${update}` : MIN_RELEASE;
let comparator = update ? `>${update}` : MIN_RELEASE;

if (v1) {
comparator += ' <2.0.0';
}

try {
let versions = JSON.parse(result.stdout).data || [];
Expand Down
10 changes: 6 additions & 4 deletions test/unit/commands/install-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('Unit: Commands > Install', function () {
const testInstance = new InstallCommand({listr: listrStub}, {cliVersion: '1.0.0', setEnvironment: setEnvironmentStub});
const runCommandStub = sinon.stub(testInstance, 'runCommand').resolves();

return testInstance.run({version: 'local', zip: ''}).then(() => {
return testInstance.run({version: 'local', zip: '', v1: true}).then(() => {
expect(false, 'run should have rejected').to.be.true;
}).catch(() => {
expect(readdirStub.calledOnce).to.be.true;
Expand All @@ -105,7 +105,8 @@ describe('Unit: Commands > Install', function () {
expect(listrStub.args[0][1]).to.deep.equal({
version: null,
cliVersion: '1.0.0',
zip: ''
zip: '',
v1: true
});
expect(setEnvironmentStub.calledOnce).to.be.true;
expect(setEnvironmentStub.calledWithExactly(true, true)).to.be.true;
Expand All @@ -125,7 +126,7 @@ describe('Unit: Commands > Install', function () {
const testInstance = new InstallCommand({listr: listrStub}, {cliVersion: '1.0.0', setEnvironment: setEnvironmentStub});
const runCommandStub = sinon.stub(testInstance, 'runCommand').resolves();

return testInstance.run({version: '1.5.0', local: true, zip: ''}).then(() => {
return testInstance.run({version: '1.5.0', local: true, zip: '', v1: false}).then(() => {
expect(false, 'run should have rejected').to.be.true;
}).catch(() => {
expect(readdirStub.calledOnce).to.be.true;
Expand All @@ -134,7 +135,8 @@ describe('Unit: Commands > Install', function () {
expect(listrStub.args[0][1]).to.deep.equal({
version: '1.5.0',
cliVersion: '1.0.0',
zip: ''
zip: '',
v1: false
});
expect(setEnvironmentStub.calledOnce).to.be.true;
expect(setEnvironmentStub.calledWithExactly(true, true)).to.be.true;
Expand Down
Loading

0 comments on commit eb315c3

Please sign in to comment.