Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added v4 spec support as "canary" and set "latest" to v3 spec #251

Merged
merged 10 commits into from
Sep 13, 2019
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ To run a local zip file through the checks:

`gscan /path/to/theme.zip -z`

By default, GScan scans themes for the latest Ghost version compatibility. You can also specify a Ghost version by using the following parameters (for Ghost 1.0, 2.0 and 3.0):
By default, GScan scans themes for the latest Ghost version compatibility. You can also specify a Ghost version by using the following parameters (for Ghost 1.0, 2.0, 3.0 and 4.0):

`--v1` or `-1`
`--v2` or `-2`
`--v3` or `-3`
`--v4` or `-4`

Use the `--canary` parameter to check for the upcoming Ghost version.

Expand All @@ -61,9 +62,9 @@ gscan.checkZip({
path: 'path-to-zip',
// if you need to check the theme for a different
// major Ghost version, you can pass it. Currently
// v1, which is Ghost 1.0 is supported. Default is
// the latest Ghost version 2.0:
// checkVersion: 'v1',
// v1, v2, v3 and v4 are supported. Default is
// the latest Ghost version 3.0:
// checkVersion: 'v3',
name: 'my-theme'
}).then(function (result) {
console.log(result);
Expand Down
5 changes: 3 additions & 2 deletions app/tpl/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
<span class="gh-input-icon select-arrow">{{> icon-arrow-up}}</span>
<span class="gh-input-icon select-arrow active">{{> icon-arrow-down}}</span>
<select class="gh-input gh-select" name="version" id="version">
<option value="v3">{{ghostVersions.v3.major}} (canary)</option>
<option value="v2" selected>{{ghostVersions.v2.major}} (latest)</option>
<option value="v4">{{ghostVersions.v4.major}} (canary)</option>
<option value="v3" selected>{{ghostVersions.v3.major}} (latest)</option>
<option value="v2">{{ghostVersions.v2.major}}</option>
<option value="v1">{{ghostVersions.v1.major}}</option>
</select>
</div>
Expand Down
2 changes: 2 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ prettyCLI
options.checkVersion = 'v2';
} else if (argv.v3) {
options.checkVersion = 'v3';
} else if (argv.v4) {
options.checkVersion = 'v4';
} else if (argv.canary) {
options.checkVersion = 'canary';
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const checks = requireDir('./checks');
const checker = function checkAll(themePath, options) {
options = options || {};

const passedVersion = _.get(options, 'checkVersion', 'v2');
const passedVersion = _.get(options, 'checkVersion', 'v3');
let version = passedVersion;

if (passedVersion === 'latest') {
version = 'v2';
} else if (passedVersion === 'canary') {
version = 'v3';
} else if (passedVersion === 'canary') {
version = 'v4';
}

return readTheme(themePath)
Expand Down
4 changes: 2 additions & 2 deletions lib/specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module.exports = {
let [version] = key;

if (version === 'latest') {
version = 'v2';
} else if (version === 'canary') {
version = 'v3';
} else if (version === 'canary') {
version = 'v4';
}

debug('Checking against version: ', version);
Expand Down
34 changes: 34 additions & 0 deletions lib/specs/v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const _ = require('lodash');
const previousSpec = require('./v3');
const ghostVersions = require('../utils').versions;
const docsBaseUrl = `https://ghost.org/docs/api/handlebars-themes/`;
const prevDocsBaseUrl = `https://themes.ghost.org/v${ghostVersions.v3.docs}/docs/`;
const prevDocsBaseUrlRegEx = new RegExp(prevDocsBaseUrl, 'g');

const previousKnownHelpers = previousSpec.knownHelpers;
const previousTemplates = previousSpec.templates;
const previousRules = previousSpec.rules;

// assign new or overwrite existing knownHelpers, templates, or rules here:
let knownHelpers = [];
let templates = [];
let rules = {
// New rules
};

knownHelpers = _.union(previousKnownHelpers, knownHelpers);
templates = _.union(previousTemplates, templates);

// Merge the previous rules into the new rules, but overwrite any specified property,
// as well as adding any new rule to the spec.
// Furthermore, replace the usage of the old doc URLs that we're linking to, with the
// new version.
rules = _.each(_.merge({}, previousRules, rules), function replaceDocsUrl(value) {
value.details = value.details.replace(prevDocsBaseUrlRegEx, docsBaseUrl);
});

module.exports = {
knownHelpers: knownHelpers,
templates: templates,
rules: rules
};
26 changes: 15 additions & 11 deletions lib/utils/versions.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"v1": {
"major": "1.x",
"docs": "1.25.0"
},
"v2": {
"major": "2.x",
"docs": "2.1.0"
},
"v3": {
"major": "3.x",
"docs": "3.0.0"
"v1": {
"major": "1.x",
"docs": "1.25.0"
},
"v2": {
"major": "2.x",
"docs": "2.1.0"
},
"v3": {
"major": "3.x",
"docs": "3.0.0"
},
"v4": {
"major": "4.x",
"docs": "4.0.0"
}
}
Loading