Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #9866 - we fallback to v0.1 by default - we support different formats - this opens the box to switch the ghost api version for the whole blog site - i had to add a different notation for overrides.json, because the structure is not optimal (i only want the versions, not the shortcuts)
- Loading branch information
Showing
6 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const _ = require('lodash'); | ||
const semver = require('semver'); | ||
const config = require('../../../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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ghost-api": "v0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
get create() { | ||
return require('./create'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
const should = require('should'); | ||
const sinon = require('sinon'); | ||
const themeEngines = require('../../../../../server/services/themes/engines'); | ||
const sandbox = sinon.sandbox.create(); | ||
|
||
describe('Themes: engines', function () { | ||
afterEach(function () { | ||
sandbox.restore(); | ||
}); | ||
|
||
it('no engines', function () { | ||
const engines = themeEngines.create(); | ||
engines.should.eql({ | ||
'ghost-api': 'v0.1' | ||
}); | ||
}); | ||
|
||
describe('ghost-api', function () { | ||
it('v2', function () { | ||
const engines = themeEngines.create({ | ||
engines: { | ||
'ghost-api': 'v2' | ||
} | ||
}); | ||
|
||
engines.should.eql({ | ||
'ghost-api': 'v2' | ||
}); | ||
}); | ||
|
||
it('v10', function () { | ||
const engines = themeEngines.create({ | ||
engines: { | ||
'ghost-api': 'v10' | ||
} | ||
}); | ||
|
||
engines.should.eql({ | ||
'ghost-api': 'v0.1' | ||
}); | ||
}); | ||
|
||
it('^0.1', function () { | ||
const engines = themeEngines.create({ | ||
engines: { | ||
'ghost-api': '^0.1' | ||
} | ||
}); | ||
|
||
engines.should.eql({ | ||
'ghost-api': 'v0.1' | ||
}); | ||
}); | ||
|
||
it('^2', function () { | ||
const engines = themeEngines.create({ | ||
engines: { | ||
'ghost-api': '^2' | ||
} | ||
}); | ||
|
||
engines.should.eql({ | ||
'ghost-api': 'v2' | ||
}); | ||
}); | ||
|
||
it('2.0.0', function () { | ||
const engines = themeEngines.create({ | ||
engines: { | ||
'ghost-api': '2.0.0' | ||
} | ||
}); | ||
|
||
engines.should.eql({ | ||
'ghost-api': 'v2' | ||
}); | ||
}); | ||
|
||
it('2.17.0', function () { | ||
const engines = themeEngines.create({ | ||
engines: { | ||
'ghost-api': '2.17.0' | ||
} | ||
}); | ||
|
||
engines.should.eql({ | ||
'ghost-api': 'v2' | ||
}); | ||
}); | ||
|
||
it('3', function () { | ||
const engines = themeEngines.create({ | ||
engines: { | ||
'ghost-api': '3' | ||
} | ||
}); | ||
|
||
engines.should.eql({ | ||
'ghost-api': 'v0.1' | ||
}); | ||
}); | ||
}); | ||
}); |