Ghost/core/frontend/services/themes/engines/create.js
Naz Gargol df7e64fafa
Extracted frontend folder (#10780)
refs #10790

- Moved /core/apps into core/frontend
- Moved /core/server/helpers to /core/frontend/helpers along with /core/server/services/themes
- Changed helper location in overrides
- Moved /core/server/services/routing to /core/frontend/services
- Moved /core/server/services/url to /core/frontend/services
- Moved /core/server/data/meta to /core/frontend/meta
- Moved /core/server/services/rss to /core/frontend/services
- Moved /core/server/data/xml to /core/frontend/services
2019-06-19 11:30:28 +02:00

50 lines
1.3 KiB
JavaScript

const _ = require('lodash');
const semver = require('semver');
const config = require('../../../../server/config');
const DEFAULTS = require('./defaults');
const allowedKeys = ['ghost-api'];
/**
* Valid definitions for "ghost-api":
*
* ^0.1
* ^2
* ^0.1.0
* ^2.0.0
* 2.0.0
* v2
* v0.1
*
* Goal: Extract major version from input.
*
* @param packageJson
* @returns {*}
*/
module.exports = (packageJson) => {
let themeEngines = _.cloneDeep(DEFAULTS);
if (packageJson && packageJson.hasOwnProperty('engines')) {
// CASE: validate
if (packageJson.engines['ghost-api']) {
const availableApiVersions = {};
config.get('api:versions:all').forEach((version) => {
availableApiVersions[semver(semver.coerce(version).version).major] = version;
});
const apiVersion = packageJson.engines['ghost-api'];
const apiVersionMajor = semver(semver.coerce(apiVersion).version).major;
if (availableApiVersions[apiVersionMajor]) {
packageJson.engines['ghost-api'] = availableApiVersions[apiVersionMajor];
} else {
packageJson.engines['ghost-api'] = 'v0.1';
}
}
themeEngines = _.assign(themeEngines, _.pick(packageJson.engines, allowedKeys));
}
return themeEngines;
};