Skip to content

Commit

Permalink
✨ Allow GScan to scan different versions
Browse files Browse the repository at this point in the history
closes #116

- CLI
    - Added `-1, --v1` option to allow cli usage of GScan to check for 1.0 theme compatibility
    - Passed `options` that includes a `checkVersion` property, which is set to `v1` when cli called with `-1`, or `latest` by default.
- Restructure current specs
    - created a new `/specs` directory
    - renamed current `spec.js` to `v1.js`
    - duplicated current `spec.js` to `latest.js` -> will contain only differences later
    - the latest version will inherit the ruleset from `v1`, but overwrite properties that exist in both
- App
    - Offered a select box with the - currently - two accepted versions, whereas the latest is set to default
    - Passed the selected version to gscan
- Checks
    - moveed checks properties (regex, helpername, cssclass) to the rules in spec
    - useed list of rules to specify which rules have to run for each version (concat them, if applicable)
    - require the version of the spec that we need for the checks only
  • Loading branch information
aileen authored and kirrg001 committed Aug 14, 2018
1 parent 0af076e commit be78ccb
Show file tree
Hide file tree
Showing 24 changed files with 947 additions and 641 deletions.
14 changes: 11 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,18 @@ app.get('/example/', function (req, res) {
app.post('/',
upload.single('theme'),
function (req, res, next) {
var zip = {
const zip = {
path: req.file.path,
name: req.file.originalname
};
const options = {
checkVersion: req.body.version || 'latest'
};

debug('Uploaded: ' + zip.name + ' to ' + zip.path);
debug('Version to check: ' + options.checkVersion);

gscan.checkZip(zip)
gscan.checkZip(zip, options)
.then(function processResult(theme) {
debug('Checked: ' + zip.name);
res.theme = theme;
Expand All @@ -67,8 +72,11 @@ app.post('/',
});
},
function doRender(req, res) {
const options = {
checkVersion: req.body.version || 'latest'
};
debug('Formatting result');
var result = gscan.format(res.theme);
const result = gscan.format(res.theme, options);
debug('Rendering result');
scanHbs.handlebars.logger.level = 0;
res.render('result', result);
Expand Down
2 changes: 1 addition & 1 deletion app/public/gscan.css

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions app/tpl/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@
<header class="gh-header">
<h1>Scan Your Theme</h1>
<p class="gh-subhead">Upload a zip to check for errors, deprecations and other compatibility issues.</p>
<p class="gh-subhead warning"><strong>GScan validates your theme based on the Ghost 1.0 requirements.</strong></p>
<a href="https://themes.ghost.org/v1.25.0/docs/changelog#ghost-100" target=_blank class="gh-morelink">
See the changelog for Ghost 1.0 themes
<p class="gh-subhead warning"><strong>GScan validates your theme based on the Ghost 2.0 requirements by default.</strong></p>
<p>You can select a different version if you need to check your theme for a previous major version.</p>

<a href="https://themes.ghost.org/v2.0.0/docs/changelog" target=_blank class="gh-morelink">
See the changelog for Ghost 2.0 themes
<svg viewBox="0 0 18 27" xmlns="http://www.w3.org/2000/svg"><path d="M2.397 25.426l13.143-11.5-13.143-11.5" stroke-width="3" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg>
</a>
</header>
<section class="gh-gscan-uploader">
<form action="/" method="post" enctype="multipart/form-data" class="clearfix">
<input type="file" name="theme" id="theme" />
<button class="gh-btn gh-btn-blue" id="theme-submit" type="submit"><span>Upload</span></button>
<form class="gh-gscan-uploader-form" action="/" method="post" enctype="multipart/form-data">
<div class="gh-form-group">
<input class="gh-input" type="file" name="theme" id="theme" />
</div>
<div class="gh-form-group">
<label for="version">Select version:</label>
<select class="gh-input gh-select" name="version" id="version">
<option value="latest" selected>2.0 (latest)</option>
<option value="v1">1.0</option>
</select>
</div>

<button class="gh-btn gh-btn-blue" id="theme-submit" type="submit"><span>Upload</span></button>
</form>
</section>
</div>
Expand Down
33 changes: 22 additions & 11 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var pkgJson = require('../package.json'),
chalk = require('chalk'),
gscan = require('../lib'),

options = {},
themePath = '',
levels;

Expand All @@ -15,6 +16,7 @@ program
.arguments('cmd <themePath>')
.option('-p, --pre', 'Run a pre-check only')
.option('-z, --zip', 'Theme path points to a zip file')
.option('-1, --v1', 'Check theme for Ghost 1.0 compatibility, instead of 2.0')
.action(function (theme) {
themePath = theme;
})
Expand All @@ -32,8 +34,8 @@ function outputResult(result) {
console.log('-', levels[result.level](result.level), result.rule);
}

function outputResults(theme) {
theme = gscan.format(theme);
function outputResults(theme, options) {
theme = gscan.format(theme, options);

console.log(chalk.bold.underline('\nRule Report:'));

Expand Down Expand Up @@ -62,21 +64,30 @@ function outputResults(theme) {
if (!program.args.length) {
program.help();
} else {
if (program.v1) {
options.checkVersion = 'v1';
} else {
// CASE: set default value
options.checkVersion = 'latest';
}

if (program.zip) {
console.log('Checking zip file...');
gscan.checkZip(themePath)
.then(outputResults)
.catch(function (error) {
gscan.checkZip(themePath, options)
.then(theme => outputResults(theme, options))
.catch((error) => {
console.error(error);
});
} else {
console.log('Checking directory...');
gscan.check(themePath).then(outputResults).catch(function ENOTDIRPredicate(err) {
return err.code === 'ENOTDIR';
}, function (err) {
console.error(err.message);
console.error('Did you mean to add the -z flag to read a zip file?');
gscan.check(themePath, options)
.then(theme => outputResults(theme, options))
.catch(function ENOTDIRPredicate(err) {
return err.code === 'ENOTDIR';
}, function (err) {
console.error(err.message);
console.error('Did you mean to add the -z flag to read a zip file?');
/* eslint-enable no-console */
});
});
}
}
26 changes: 13 additions & 13 deletions lib/checker.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
var Promise = require('bluebird'),
_ = require('lodash'),
requireDir = require('require-dir'),
readTheme = require('./read-theme'),
checker,
checks;
const Promise = require('bluebird');
const _ = require('lodash');
const requireDir = require('require-dir');
const readTheme = require('./read-theme');

checks = requireDir('./checks');
const checks = requireDir('./checks');

/**
* Check theme
*
* Takes a theme path, reads the theme, and checks it for issues.
* Returns a theme object.
* @param themePath
* @param options
* @returns {Object}
*/
checker = function checkAll(themePath, options) {
const checker = function checkAll(themePath, options) {
options = options || {};

return readTheme(themePath).then(function (theme) {
return Promise.reduce(_.values(checks), function (theme, check) {
return check(theme, themePath, options);
}, theme);
});
return readTheme(themePath)
.then(function (theme) {
return Promise.reduce(_.values(checks), function (theme, check) {
return check(theme, options, themePath);
}, theme);
});
};

module.exports = checker;
Loading

0 comments on commit be78ccb

Please sign in to comment.