Skip to content

Commit

Permalink
Output the major version that was checked (#128)
Browse files Browse the repository at this point in the history
refs #116

- uses the versions util to fetch the major version and pass it along our `theme` object
- outputs the tested version for CLI and App usage
- for module usage, GScan returns a `checkedVersion` property with the major version that it was checked for
- updated README to include version usage
  • Loading branch information
aileen authored Aug 8, 2018
1 parent 9d5603c commit ba6b511
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ To run a local zip file through the checks:

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

You can also pass a version. Currently supported is `--v1` or `-1`, which will check the theme
for 1.0.0 requirements. By default, GScan will always check for the latest version:

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

or

`gscan /path/to/theme/directory --v1`

### 3. Lib usage

Install using yarn/npm and then:
Expand All @@ -34,6 +43,11 @@ var gscan = require('gscan');

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',
name: 'my-theme'
}).then(function (result) {
console.log(result);
Expand Down
4 changes: 4 additions & 0 deletions app/tpl/result.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

<div class="inner report-body">
<div class="results report-section">
{{!-- TODO: make this pretty --}}
<div>
<p>Result for version {{checkedVersion}}:</p>
</div>
{{#if results.error}}
<section class="level-group">
<header class="level-group-header">
Expand Down
18 changes: 9 additions & 9 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env node

var pkgJson = require('../package.json'),
program = require('commander'),
_ = require('lodash'),
chalk = require('chalk'),
gscan = require('../lib'),
const pkgJson = require('../package.json');
const program = require('commander');
const _ = require('lodash');
const chalk = require('chalk');
const gscan = require('../lib');

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

program
.version(pkgJson.version)
Expand Down Expand Up @@ -37,7 +37,7 @@ function outputResult(result) {
function outputResults(theme, options) {
theme = gscan.format(theme, options);

console.log(chalk.bold.underline('\nRule Report:'));
console.log(chalk.bold.underline(`\nRule Report for v${theme.checkedVersion}:`));

if (!_.isEmpty(theme.results.error)) {
console.log(chalk.red.bold.underline('\n! Must fix:'));
Expand Down
5 changes: 5 additions & 0 deletions lib/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Promise = require('bluebird');
const _ = require('lodash');
const requireDir = require('require-dir');
const readTheme = require('./read-theme');
const versions = require('./utils').versions;

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

Expand All @@ -16,9 +17,13 @@ const checks = requireDir('./checks');
*/
const checker = function checkAll(themePath, options) {
options = options || {};
const passedVersion = _.get(options, 'checkVersion', 'latest');

return readTheme(themePath)
.then(function (theme) {
// set the major version to check
theme.checkedVersion = versions[passedVersion].major;

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

0 comments on commit ba6b511

Please sign in to comment.