signal-desktop/ts/util/version.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as semver from 'semver';
2021-08-06 21:21:01 +00:00
import moment from 'moment';
export const isProduction = (version: string): boolean => {
const parsed = semver.parse(version);
if (!parsed) {
return false;
}
return !parsed.prerelease.length && !parsed.build.length;
};
export const isBeta = (version: string): boolean =>
semver.parse(version)?.prerelease[0] === 'beta';
2021-08-06 21:21:01 +00:00
export const isAlpha = (version: string): boolean =>
semver.parse(version)?.prerelease[0] === 'alpha';
export const generateAlphaVersion = (options: {
currentVersion: string;
shortSha: string;
}): string => {
const { currentVersion, shortSha } = options;
const parsed = semver.parse(currentVersion);
if (!parsed) {
throw new Error(`generateAlphaVersion: Invalid version ${currentVersion}`);
}
const formattedDate = moment().utc().format('YYYYMMDD.HH');
const formattedVersion = `${parsed.major}.${parsed.minor}.${parsed.patch}`;
return `${formattedVersion}-alpha.${formattedDate}-${shortSha}`;
};