Skip to content

Commit

Permalink
feat(install): allow specifying short versions
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine committed Nov 8, 2019
1 parent 9494d51 commit 46f4da5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/utils/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const utils = {
const majorToUse = semver.major(versionToUse);
throw new CliError({
message: `You are trying to update to Ghost v${majorToUse}, but your blog is not on the latest Ghost 1.0 version`,
help: 'Instead run "ghost update --v1".'
help: 'Instead run "ghost update v1".'
});
}

Expand All @@ -123,7 +123,11 @@ const utils = {
return latestVersion;
}

let version = customVersion ? utils.checkCustomVersion(customVersion, versions.all, activeVersion, opts) : null;
let version = null;
if (customVersion) {
const normalizedVersion = versions.latestMajor[customVersion.replace(/^v?/, 'v')] || customVersion;
version = utils.checkCustomVersion(normalizedVersion, versions.all, activeVersion, opts);
}
const latest = version || latestVersion;

if (!activeVersion) {
Expand Down
28 changes: 28 additions & 0 deletions test/unit/utils/version-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,34 @@ describe('Unit: Utils: version', function () {
expect(result).to.equal('2.0.0');
});

it('returns latest v1 version if only 1 is specified', async function () {
loadVersions.resolves({
latest: '2.2.0',
latestMajor: {
v1: '1.1.0',
v2: '2.2.0'
},
all: ['2.2.0', '2.1.0', '2.0.0', '1.1.0', '1.0.0']
});

const result = await resolveVersion('1');
expect(result).to.equal('1.1.0');
});

it('returns latest v2 version if only v2 is specified', async function () {
loadVersions.resolves({
latest: '2.2.0',
latestMajor: {
v1: '1.1.0',
v2: '2.2.0'
},
all: ['2.2.0', '2.1.0', '2.0.0', '1.1.0', '1.0.0']
});

const result = await resolveVersion('v2');
expect(result).to.equal('2.2.0');
});

it('returns latest version if active version and no custom version', async function () {
loadVersions.resolves({
latest: '2.2.0',
Expand Down

0 comments on commit 46f4da5

Please sign in to comment.