Skip to content

Commit

Permalink
rewrite
Browse files Browse the repository at this point in the history
make the code simpler and faster
  • Loading branch information
sindresorhus committed Jan 20, 2015
1 parent 7aa161d commit ee0d0bc
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 43 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# editorconfig.org
root = true

[*]
Expand Down
9 changes: 1 addition & 8 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
"noarg": true,
"undef": true,
"strict": false,
"indent": 2,
"quotmark": "single",
"laxbreak": true,
"globals": {
"describe": true,
"it": true,
"beforeEach": true,
"afterEach": true
}
"mocha": true
}
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node
'use strict';
require('./').run();
require('./')();
47 changes: 19 additions & 28 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
'use strict';
var chalk = require('chalk');
var requireall = require('require-dir');
var objectValues = require('object-values');
var async = require('async');
var eachAsync = require('each-async');
var symbols = require('log-symbols');
var rules = require('./rules');

module.exports = {
rules: requireall('./rules'),
module.exports = function () {
var errCount = 0;

run: function () {
this.errorCount = 0;
console.log('\n' + chalk.underline.blue('Yeoman Doctor'));
console.log('Running sanity checks on your system\n');
async.map(objectValues(this.rules), this.processRule.bind(this), this.onEnd.bind(this));
},
console.log('\n' + chalk.underline.blue('Yeoman Doctor'));
console.log('Running sanity checks on your system\n');

processRule: function (rule, cb) {
rule.verify(function (error) {
this.logResult(rule.description, error);
cb();
}.bind(this));
},
eachAsync(objectValues(rules), function (rule, i, cb) {
rule.verify(function (err) {
console.log(err ? symbols.error : symbols.success + ' ' + rule.description);

if (err) {
errCount++;
console.log(err);
}

onEnd: function (err) {
if (this.errorCount === 0) {
cb();
});
}, function () {
if (errCount === 0) {
console.log(chalk.green('\nEverything looks all right!'));
} else {
console.log(chalk.red('\nFound potential issues on your machine :('));
}
},

logResult: function (description, error) {
console.log(error ? symbols.error : symbols.success + ' ' + description);

if (error) {
this.errorCount++;
console.log(error);
}
}
});
};
5 changes: 5 additions & 0 deletions lib/rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
exports['bowerrc-home'] = require('./bowerrc-home');
exports['global_config'] = require('./global_config');
exports['node_path'] = require('./node_path');
exports['yo-rc-home'] = require('./yo-rc-home');
2 changes: 1 addition & 1 deletion lib/rules/node_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var path = require('path');
var childProcess = require('child_process');
var message = require('../message');

exports.description = 'NODE_PATH match the npm root';
exports.description = 'NODE_PATH matches the npm root';

var errors = exports.errors = {
npmFailure: function () {
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "lib/index.js",
"description": "Detect potential issues with users system that could prevent Yeoman from working correctly",
"license": "BSD",
"author": "Yeoman team",
"author": "Yeoman",
"repository": "yeoman/doctor",
"engines": {
"node": ">=0.10.0"
Expand All @@ -21,14 +21,17 @@
"keywords": [
"yeoman",
"yo",
"doctor"
"doctor",
"system",
"health",
"report",
"check"
],
"dependencies": {
"async": "^0.9.0",
"chalk": "^0.5.1",
"each-async": "^1.1.1",
"log-symbols": "^1.0.1",
"object-values": "^1.0.0",
"require-dir": "^0.1.0",
"twig": "^0.7.2",
"user-home": "^1.1.0"
},
Expand Down

0 comments on commit ee0d0bc

Please sign in to comment.