Merge branch 'features/upgrade-tool' of github.com:strapi/strapi into upgrade-tool/chores

This commit is contained in:
Convly 2023-12-14 10:26:11 +01:00
commit c56802ae6f
2 changed files with 21 additions and 15 deletions

View File

@ -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('<command> [options]')

View File

@ -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 <major + 1>.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');