mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
160cb07e02
no issue Part of the effort to split ghost into smaller, decoupled parts. The @root-utils package lets us avoid hard-coding a path to package.json, and means that the ghost-version.js file could eventually be moved into a separate module. This commit uses a patched version of @tryghost/root-utils which checks for the existence of a `current` directory, as used in Ghost-CLI. Since this is very specific to Ghost and Ghost CLI, there's a new method called "getGhostRoot" for this purpose.
27 lines
837 B
JavaScript
27 lines
837 B
JavaScript
const path = require('path');
|
|
const semver = require('semver');
|
|
const rootUtils = require('@tryghost/root-utils');
|
|
const packageInfo = require(path.join(rootUtils.getProcessRoot(), 'package.json'));
|
|
const version = packageInfo.version;
|
|
const plainVersion = version.match(/^(\d+\.)?(\d+\.)?(\d+)/)[0];
|
|
|
|
let _private = {};
|
|
|
|
_private.compose = function compose(type) {
|
|
switch (type) {
|
|
case 'pre':
|
|
return plainVersion + '-' + semver.prerelease(version).join('.');
|
|
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;
|
|
|