@brettdh/standard-version-expo
Version:
Automatic Expo versioning with Standard Version
28 lines (27 loc) • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("@expo/config");
const semver_1 = require("semver");
/**
* Get the version code from a manifest and target version.
* It's designed for Android using the approach from Maxi Rosson.
*
* @see https://medium.com/@maxirosson/versioning-android-apps-d6ec171cfd82
*/
function getVersionCode(manifest, version) {
const sdkVersion = config_1.getExpoSDKVersion(process.cwd(), manifest.expo);
return getVersionCodeFromSdkVersion(sdkVersion, version);
}
exports.getVersionCode = getVersionCode;
function getVersionCodeFromSdkVersion(sdkVersion, version) {
const expo = semver_1.coerce(sdkVersion);
const target = semver_1.coerce(version);
if (!expo) {
throw new Error('Could not parse the `expo.sdkVersion` from the manifest.');
}
if (!target) {
throw new Error('Could not parse the new version from standard version.');
}
return (expo.major * 10000000) + (target.major * 10000) + (target.minor * 100) + target.patch;
}
exports.getVersionCodeFromSdkVersion = getVersionCodeFromSdkVersion;