341f719d92
refs https://github.com/TryGhost/Ghost-Release/issues/24 - differentiate between 1. original package.json version (can contain pre and build suffix) 2. full package.json version X.X.X-{pre} (optional) 3. safe package.json version X.X (major+minor)
28 lines
821 B
JavaScript
28 lines
821 B
JavaScript
'use strict';
|
|
|
|
const semver = require('semver'),
|
|
packageInfo = require('../../../package.json'),
|
|
version = packageInfo.version,
|
|
plainVersion = version.match(/^(\d+\.)?(\d+\.)?(\d+)/)[0];
|
|
|
|
let _private = {};
|
|
|
|
_private.compose = function compose(type) {
|
|
switch (type) {
|
|
case 'pre':
|
|
return plainVersion + '-' + semver.prerelease(version)[0] + (semver.prerelease(version)[1] ? '.' + semver.prerelease(version)[1] : '');
|
|
default:
|
|
return version;
|
|
}
|
|
};
|
|
|
|
// major.minor
|
|
module.exports.safe = version.match(/^(\d+\.)?(\d+)/)[0];
|
|
|
|
// major.minor.patch-{prerelease}
|
|
module.exports.full = semver.prerelease(version) ? _private.compose('pre') : plainVersion;
|
|
|
|
// original string in package.json (can contain pre-release and build suffix)
|
|
module.exports.original = version;
|
|
|