Skip to content

Commit

Permalink
✨ Added pakcage.json "ghost-api === v1" error rule in canary set
Browse files Browse the repository at this point in the history
refs TryGhost#144

- Added new rule to detect old ghost-api in engines
  • Loading branch information
naz committed Sep 17, 2019
1 parent 93a7a45 commit 48ae056
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
8 changes: 8 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'},
{isv1EngineGhostAPI: 'GS010-PJ-GHOST-API-V1'},
canaryPackageJSONConditionalRules
);

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

if (packageJSON.engines && packageJSON.engines['ghost-api']) {
// TODO: add more coersion cases for 0.1
if (packageJSON.engines['ghost-api'] === 'v0.1') {
markFailed('isv1EngineGhostAPI');
}
}

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-V1': {
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-V1'
]);

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-V1'
]);

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 48ae056

Please sign in to comment.