Skip to content

Commit

Permalink
✨ Added rule in canary set for ghost-api=v0.1 detection (#258)
Browse files Browse the repository at this point in the history
refs #144

- Added new "error" level rule to detect old ghost-api (v0.1) in engines.ghost-api property used in package.json
  • Loading branch information
naz authored Sep 17, 2019
1 parent 93a7a45 commit 701467c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
15 changes: 15 additions & 0 deletions lib/checks/010-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const v2PackageJSONValidationRules = _.extend({},
const canaryPackageJSONConditionalRules = {};
const canaryPackageJSONValidationRules = _.extend({},
{isPresentEngineGhostAPI: 'GS010-PJ-GHOST-API'},
{isv01EngineGhostAPI: 'GS010-PJ-GHOST-API-V01'},
canaryPackageJSONConditionalRules
);

Expand Down Expand Up @@ -92,6 +93,20 @@ _private.validatePackageJSONFields = function validatePackageJSONFields(packageJ
markFailed('isPresentEngineGhostAPI');
}

if (packageJSON.engines && packageJSON.engines['ghost-api']) {
// NOTE: checks for same versions as were available in Ghost 2.0 (v0.1, ^0.1 etc.)
// ref.: https://github.com/TryGhost/Ghost/blob/bc41550/core/frontend/services/themes/engines/create.js#L10-L16
const coerced = semver.coerce(packageJSON.engines['ghost-api']);

if (coerced !== null) {
const major = semver(semver(coerced).version).major;

if (major === 0) {
markFailed('isv01EngineGhostAPI');
}
}
}

const failedRules = _private.getFailedRules(failed);
_.each(failedRules, (rule, key) => {
theme.results.fail[key] = {};
Expand Down
7 changes: 7 additions & 0 deletions lib/specs/canary.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ let rules = {
details: oneLineTrim`Please add <code>"ghost-api"</code> to your <code>package.json</code>. E.g. <code>{"engines": {"ghost-api": "v3"}}</code>.<br>
If no <code>"ghost-api"</code> property is provided, Ghost will use its default setting of "v3" Ghost API.<br>
Check the <a href="${docsBaseUrl}packagejson/" target=_blank><code>package.json</code> documentation</a> for further information.`
},
'GS010-PJ-GHOST-API-V01': {
level: 'error',
rule: '<code>package.json</code> property <code>"engines.ghost-api"</code> is incompatible with current version of Ghost API and will fall back to "v3"',
details: oneLineTrim`Please change <code>"ghost-api"</code> in your <code>package.json</code> to higher version. E.g. <code>{"engines": {"ghost-api": "v3"}}</code>.<br>
If <code>"ghost-api"</code> property is left at "v0.1", Ghost will use its default setting of "v3".<br>
Check the <a href="${docsBaseUrl}packagejson/" target=_blank><code>package.json</code> documentation</a> for further information.`
}
};

Expand Down
9 changes: 6 additions & 3 deletions test/010-package-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ describe('010 package.json', function () {
'GS010-PJ-CONF-PPP',
'GS010-PJ-CONF-PPP-INT',
'GS010-PJ-KEYWORDS',
'GS010-PJ-GHOST-API'
'GS010-PJ-GHOST-API',
'GS010-PJ-GHOST-API-V01'
]);

theme.results.fail.should.be.an.Object().which.is.empty();
Expand All @@ -326,7 +327,8 @@ describe('010 package.json', function () {
'GS010-PJ-NAME-REQ',
'GS010-PJ-VERSION-REQ',
'GS010-PJ-AUT-EM-REQ',
'GS010-PJ-CONF-PPP'
'GS010-PJ-CONF-PPP',
'GS010-PJ-GHOST-API'
]);

theme.results.fail.should.be.an.Object().with.keys(
Expand All @@ -350,7 +352,8 @@ describe('010 package.json', function () {

theme.results.pass.should.eql([
'GS010-PJ-REQ',
'GS010-PJ-PARSE'
'GS010-PJ-PARSE',
'GS010-PJ-GHOST-API-V01'
]);

theme.results.fail.should.be.an.Object().with.keys(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"email": "something"
},
"keywords": "ghost-theme",
"engines": {
"ghost-api": "v0.1"
},
"config": {
"posts_per_page": "something"
}
Expand Down

0 comments on commit 701467c

Please sign in to comment.