From 46f4da54a11a709c6f416bde56de17d4a30ed890 Mon Sep 17 00:00:00 2001 From: Austin Burdine Date: Thu, 7 Nov 2019 17:30:12 +0700 Subject: [PATCH] feat(install): allow specifying short versions --- lib/utils/version.js | 8 ++++++-- test/unit/utils/version-spec.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/utils/version.js b/lib/utils/version.js index 0cf0ac731..c43b0f4b6 100644 --- a/lib/utils/version.js +++ b/lib/utils/version.js @@ -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".' }); } @@ -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) { diff --git a/test/unit/utils/version-spec.js b/test/unit/utils/version-spec.js index eaf106ddb..4ec936513 100644 --- a/test/unit/utils/version-spec.js +++ b/test/unit/utils/version-spec.js @@ -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',