diff --git a/packages/utils/upgrade/src/cli/index.ts b/packages/utils/upgrade/src/cli/index.ts index 9c4124b102..c79149160a 100644 --- a/packages/utils/upgrade/src/cli/index.ts +++ b/packages/utils/upgrade/src/cli/index.ts @@ -32,17 +32,15 @@ addReleaseUpgradeCommand( 'Upgrade to the next available major version of Strapi' ); -// TODO: Add back the command when adding the support for minor upgrades -// addReleaseUpgradeCommand( -// Version.ReleaseType.Minor, -// 'Upgrade to the latest minor/patch version of Strapi for the current major' -// ); +addReleaseUpgradeCommand( + Version.ReleaseType.Minor, + 'Upgrade to the latest minor and patch version of Strapi for the current major' +); -// TODO: Add back the command when adding the support for patch upgrades -// addReleaseUpgradeCommand( -// Version.ReleaseType.Patch, -// 'Upgrade to latest patch version of Strapi for the current major and minor' -// ); +addReleaseUpgradeCommand( + Version.ReleaseType.Patch, + 'Upgrade to latest patch version of Strapi for the current major and minor' +); program .usage(' [options]') diff --git a/packages/utils/upgrade/src/modules/version/range.ts b/packages/utils/upgrade/src/modules/version/range.ts index e97b90bdb2..9aff5ab365 100644 --- a/packages/utils/upgrade/src/modules/version/range.ts +++ b/packages/utils/upgrade/src/modules/version/range.ts @@ -8,16 +8,24 @@ export const rangeFactory = (range: string): Version.Range => { }; export const rangeFromReleaseType = (current: Version.SemVer, identifier: Version.ReleaseType) => { - const fromCurrentTo = (version: Version.LiteralVersion) => { - return rangeFactory(`>${current.raw} <=${version}`); - }; - switch (identifier) { case Version.ReleaseType.Major: { // semver.inc(_, 'major') will target .0.0 which is what we want // e.g. for 4.15.4, it'll return 5.0.0 const nextMajor = semver.inc(current, 'major') as Version.LiteralSemVer; - return fromCurrentTo(nextMajor); + return rangeFactory(`>${current.raw} <=${nextMajor}`); + } + case Version.ReleaseType.Patch: { + // This will return the minor for the next minor + // e.g. for 4.15.4, it'll return 4.16.0 + const minor = semver.inc(current, 'minor') as Version.LiteralSemVer; + return rangeFactory(`>${current.raw} <${minor}`); + } + case Version.ReleaseType.Minor: { + // This will return the major for the next major + // e.g. for 4.15.4, it'll return 5.0.0 + const major = semver.inc(current, 'major') as Version.LiteralSemVer; + return rangeFactory(`>${current.raw} <${major}`); } default: { throw new Error('Not implemented');