Skip to content

Commit

Permalink
Update tooling (eslint + prettier)
Browse files Browse the repository at this point in the history
  • Loading branch information
amasad committed May 30, 2017
1 parent 52ca8fe commit 34defa0
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 217 deletions.
17 changes: 17 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "eslint:recommended",
"env": {
"browser": true,
"commonjs": true,
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 6
},
"rules": {
"no-console": "off",
"strict": ["error", "global"],
"curly": "warn"
}
}
76 changes: 0 additions & 76 deletions .jshintrc

This file was deleted.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
],
"scripts": {
"prepublish": "jshint --config=.jshintrc src/ index.js && mocha --bail",
"test": "jshint --config=.jshintrc src/ index.js && mocha --bail test/test.js && mocha --bail test/utils-test.js",
"test:debug": "mocha debug --bail"
"test": "npm run format && eslint src/ index.js && mocha --bail test/test.js && mocha --bail test/utils-test.js",
"test:debug": "mocha debug --bail",
"format": "prettier --trailing-comma es5 --single-quote --write index.js 'src/**/*.js'"
},
"bin": "./src/cli.js",
"keywords": [
Expand All @@ -37,8 +38,9 @@
"watch": "~0.10.0"
},
"devDependencies": {
"jshint": "^2.5.10",
"eslint": "^3.19.0",
"mocha": "~1.17.1",
"prettier": "^1.3.1",
"rimraf": "~2.2.6",
"tmp": "0.0.27"
},
Expand Down
33 changes: 22 additions & 11 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ var sane = require('../');
var argv = require('minimist')(process.argv.slice(2));
var execshell = require('exec-sh');

if(argv._.length === 0) {
var msg = 'Usage: sane <command> [...directory] [--glob=<filePattern>] ' +
'[--poll] [--watchman] [--dot] [--wait=<seconds>]';
if (argv._.length === 0) {
var msg =
'Usage: sane <command> [...directory] [--glob=<filePattern>] ' +
'[--poll] [--watchman] [--dot] [--wait=<seconds>]';
console.error(msg);
process.exit();
}
Expand All @@ -21,27 +22,37 @@ var glob = argv.glob || argv.g;
var poll = argv.poll || argv.p;
var watchman = argv.watchman || argv.w;

if (dot) { opts.dot = true; }
if (glob) { opts.glob = glob; }
if (poll) { opts.poll = true; }
if (watchman) { opts.watchman = true; }
if (dot) {
opts.dot = true;
}
if (glob) {
opts.glob = glob;
}
if (poll) {
opts.poll = true;
}
if (watchman) {
opts.watchman = true;
}

var wait = false;
var watcher = sane(dir, opts);

watcher.on('ready', function () {
watcher.on('ready', function() {
console.log('Watching: ', dir + '/' + (opts.glob || ''));
execshell(command);
});

watcher.on('change', function (filepath) {
if (wait) { return; }
watcher.on('change', function(filepath) {
if (wait) {
return;
}
console.log('Change detected in:', filepath);
execshell(command);

if (waitTime > 0) {
wait = true;
setTimeout(function () {
setTimeout(function() {
wait = false;
}, waitTime * 1000);
}
Expand Down
22 changes: 13 additions & 9 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ exports.assignOptions = function(watcher, opts) {
if (!Array.isArray(watcher.globs)) {
watcher.globs = [watcher.globs];
}
watcher.hasIgnore = Boolean(opts.ignored) &&
!(Array.isArray(opts) && opts.length > 0);
watcher.doIgnore = opts.ignored ? anymatch(opts.ignored) : function () {
return false;
};
watcher.hasIgnore =
Boolean(opts.ignored) && !(Array.isArray(opts) && opts.length > 0);
watcher.doIgnore = opts.ignored
? anymatch(opts.ignored)
: function() {
return false;
};
return opts;
};

Expand All @@ -52,16 +54,18 @@ exports.isFileIncluded = function(globs, dot, doIgnore, relativePath) {
var matched;
if (globs.length) {
for (var i = 0; i < globs.length; i++) {
if (minimatch(relativePath, globs[i], {dot: dot}) &&
!doIgnore(relativePath)) {
if (
minimatch(relativePath, globs[i], { dot: dot }) &&
!doIgnore(relativePath)
) {
matched = true;
break;
}
}
} else {
// Make sure we honor the dot option if even we're not using globs.
matched = (dot || minimatch(relativePath, '**/*')) &&
!doIgnore(relativePath);
matched =
(dot || minimatch(relativePath, '**/*')) && !doIgnore(relativePath);
}
return matched;
};
Loading

0 comments on commit 34defa0

Please sign in to comment.