diff --git a/extensions/package-manager/js/src/admin/components/ExtensionCard.tsx b/extensions/package-manager/js/src/admin/components/ExtensionCard.tsx index 97f2a13f2..2f5294a68 100644 --- a/extensions/package-manager/js/src/admin/components/ExtensionCard.tsx +++ b/extensions/package-manager/js/src/admin/components/ExtensionCard.tsx @@ -130,7 +130,7 @@ export default class ExtensionCard {
{this.controlItems().toArray()}
{this.availableUpdatesView()} , - core && core.package['latest-major'] ? ( + core && core.package['latest-major'] && isProductionReady(core.package['latest-major']) ? ( ) : null, ]; diff --git a/extensions/package-manager/js/src/admin/models/ExternalExtension.ts b/extensions/package-manager/js/src/admin/models/ExternalExtension.ts index 895b3cf42..fd1692a8a 100644 --- a/extensions/package-manager/js/src/admin/models/ExternalExtension.ts +++ b/extensions/package-manager/js/src/admin/models/ExternalExtension.ts @@ -1,6 +1,7 @@ import Model from 'flarum/common/Model'; import app from 'flarum/admin/app'; import type { Extension } from 'flarum/admin/AdminApplication'; +import { isProductionReady } from '../utils/versions'; export default class ExternalExtension extends Model { extensionId = Model.attribute('extensionId'); @@ -36,16 +37,8 @@ export default class ExternalExtension extends Model { return currentVersion.split('.')[0] === latestCompatibleVersion.split('.')[0]; } - public isStable(): boolean { - const split = this.highestVersion().split('-'); - - if (split.length === 1) { - return true; - } - - const stability = split[1].split('.'); - - return stability[0] === 'stable'; + public isProductionReady(): boolean { + return isProductionReady(this.highestVersion()); } public toLocalExtension(): Extension { diff --git a/extensions/package-manager/js/src/admin/utils/versions.ts b/extensions/package-manager/js/src/admin/utils/versions.ts new file mode 100644 index 000000000..0f291a500 --- /dev/null +++ b/extensions/package-manager/js/src/admin/utils/versions.ts @@ -0,0 +1,32 @@ +export enum VersionStability { + Stable = 'stable', + Alpha = 'alpha', + Beta = 'beta', + RC = 'rc', + Dev = 'dev', +} + +export function isProductionReady(version: string): boolean { + return [VersionStability.Stable, VersionStability.RC].includes(stability(version)); +} + +export function stability(version: string): VersionStability { + const split = version.split('-'); + + if (split.length === 1) { + return VersionStability.Stable; + } + + const stab = split[1].split('.')[0].toLowerCase(); + + switch (stab) { + case 'alpha': + return VersionStability.Alpha; + case 'beta': + return VersionStability.Beta; + case 'rc': + return VersionStability.RC; + default: + return VersionStability.Dev; + } +}