Lint tweaks.

This commit is contained in:
XhmikosR 2016-01-15 09:19:40 +02:00
parent d57ca3cbba
commit 47eb4b070b
4 changed files with 53 additions and 22 deletions

View File

@ -43,7 +43,9 @@ module.exports = function(grunt) {
process.exit(1); process.exit(1);
}); });
this.server.listen(options.port, options.host, function(err) { this.server.listen(options.port, options.host, function(err) {
if (err) { return grunt.fatal(err); } if (err) {
return grunt.fatal(err);
}
grunt.log.verbose.writeln('Live reload server started on ' + host); grunt.log.verbose.writeln('Live reload server started on ' + host);
}); });
servers[host] = this.server; servers[host] = this.server;

View File

@ -39,7 +39,9 @@ module.exports = function(grunt) {
var self = this; var self = this;
// Dont run if already running // Dont run if already running
if (self.startedAt !== false) { return; } if (self.startedAt !== false) {
return;
}
// Start this task run // Start this task run
self.startedAt = Date.now(); self.startedAt = Date.now();
@ -55,7 +57,9 @@ module.exports = function(grunt) {
} }
// If no tasks just call done to trigger potential livereload // If no tasks just call done to trigger potential livereload
if (self.tasks.length < 1) { return done(); } if (self.tasks.length < 1) {
return done();
}
if (self.options.spawn === false || self.options.nospawn === true) { if (self.options.spawn === false || self.options.nospawn === true) {
grunt.task.run(self.tasks); grunt.task.run(self.tasks);
@ -67,10 +71,10 @@ module.exports = function(grunt) {
// Run from current working dir and inherit stdio from process // Run from current working dir and inherit stdio from process
opts: { opts: {
cwd: self.options.cwd.spawn, cwd: self.options.cwd.spawn,
stdio: 'inherit', stdio: 'inherit'
}, },
// Run grunt this process uses, append the task to be run and any cli options // Run grunt this process uses, append the task to be run and any cli options
args: self.tasks.concat(self.options.cliArgs || []), args: self.tasks.concat(self.options.cliArgs || [])
}, function(err, res, code) { }, function(err, res, code) {
self.spawnTaskFailure = (code !== 0); self.spawnTaskFailure = (code !== 0);
if (self.options.interrupt !== true || (code !== 130 && code !== 1)) { if (self.options.interrupt !== true || (code !== 130 && code !== 1)) {

View File

@ -57,7 +57,7 @@ module.exports = function(grunt) {
self.name = name || grunt.task.current.name || 'watch'; self.name = name || grunt.task.current.name || 'watch';
self.options = self._options(grunt.config([self.name, 'options']) || {}, defaults || {}); self.options = self._options(grunt.config([self.name, 'options']) || {}, defaults || {});
self.reload = false; self.reload = false;
self.nameArgs = (grunt.task.current.nameArgs) ? grunt.task.current.nameArgs : self.name; self.nameArgs = grunt.task.current.nameArgs ? grunt.task.current.nameArgs : self.name;
// Normalize cwd option // Normalize cwd option
if (typeof self.options.cwd === 'string') { if (typeof self.options.cwd === 'string') {
@ -121,10 +121,12 @@ module.exports = function(grunt) {
grunt.task.current.requiresConfig(name); grunt.task.current.requiresConfig(name);
var config = grunt.config(name); var config = grunt.config(name);
var onlyTarget = (self.options.target) ? self.options.target : false; var onlyTarget = self.options.target ? self.options.target : false;
var targets = (onlyTarget ? [onlyTarget] : Object.keys(config)).filter(function(key) { var targets = (onlyTarget ? [onlyTarget] : Object.keys(config)).filter(function(key) {
if (key === 'options') { return false; } if (key === 'options') {
return false;
}
return typeof config[key] !== 'string' && !Array.isArray(config[key]); return typeof config[key] !== 'string' && !Array.isArray(config[key]);
}).map(function(target) { }).map(function(target) {
// Fail if any required config properties have been omitted // Fail if any required config properties have been omitted
@ -142,7 +144,7 @@ module.exports = function(grunt) {
files: config.files, files: config.files,
tasks: config.tasks, tasks: config.tasks,
name: defaultTargetName, name: defaultTargetName,
options: self._options(config.options || {}, self.options), options: self._options(config.options || {}, self.options)
}; };
targets.push(cfg); targets.push(cfg);
self.add(cfg); self.add(cfg);
@ -163,7 +165,7 @@ module.exports = function(grunt) {
spawn: true, spawn: true,
atBegin: false, atBegin: false,
event: ['all'], event: ['all'],
target: null, target: null
}); });
return _.defaults.apply(_, args); return _.defaults.apply(_, args);
}; };
@ -198,7 +200,9 @@ module.exports = function(grunt) {
} }
// If we should reload // If we should reload
if (self.reload) { return self.reloadTask(); } if (self.reload) {
return self.reloadTask();
}
// Trigger that tasks runs have started // Trigger that tasks runs have started
self.emit('start'); self.emit('start');
@ -208,7 +212,9 @@ module.exports = function(grunt) {
var shouldComplete = true; var shouldComplete = true;
async.forEachSeries(self.queue, function(name, next) { async.forEachSeries(self.queue, function(name, next) {
var tr = self.targets[name]; var tr = self.targets[name];
if (!tr) { return next(); } if (!tr) {
return next();
}
// Re-grab options in case they changed between runs // Re-grab options in case they changed between runs
tr.options = self._options(grunt.config([self.name, name, 'options']) || {}, tr.options, self.options); tr.options = self._options(grunt.config([self.name, name, 'options']) || {}, tr.options, self.options);
@ -235,8 +241,12 @@ module.exports = function(grunt) {
// Private method for getting latest config for a watch target // Private method for getting latest config for a watch target
target._getConfig = function(name) { target._getConfig = function(name) {
var cfgPath = [self.name]; var cfgPath = [self.name];
if (target.name !== defaultTargetName) { cfgPath.push(target.name); } if (target.name !== defaultTargetName) {
if (name) { cfgPath.push(name); } cfgPath.push(target.name);
}
if (name) {
cfgPath.push(name);
}
return grunt.config(cfgPath); return grunt.config(cfgPath);
}; };
@ -262,13 +272,17 @@ module.exports = function(grunt) {
// Do this when queued task runs have completed/scheduled // Do this when queued task runs have completed/scheduled
Runner.prototype.complete = function complete() { Runner.prototype.complete = function complete() {
var self = this; var self = this;
if (self.running === false) { return; } if (self.running === false) {
return;
}
self.running = false; self.running = false;
var time = 0; var time = 0;
for (var i = 0, len = self.queue.length; i < len; ++i) { for (var i = 0, len = self.queue.length; i < len; ++i) {
var name = self.queue[i]; var name = self.queue[i];
var target = self.targets[name]; var target = self.targets[name];
if (!target) { return; } if (!target) {
return;
}
if (target.startedAt !== false) { if (target.startedAt !== false) {
time += target.complete(); time += target.complete();
self.queue.splice(i--, 1); self.queue.splice(i--, 1);
@ -291,7 +305,9 @@ module.exports = function(grunt) {
var self = this; var self = this;
self.queue.forEach(function(name) { self.queue.forEach(function(name) {
var target = self.targets[name]; var target = self.targets[name];
if (!target) { return; } if (!target) {
return;
}
target.complete(); target.complete();
}); });
}; };

View File

@ -6,6 +6,8 @@
* Licensed under the MIT license. * Licensed under the MIT license.
*/ */
'use strict';
var path = require('path'); var path = require('path');
var Gaze = require('gaze').Gaze; var Gaze = require('gaze').Gaze;
var _ = require('lodash'); var _ = require('lodash');
@ -14,7 +16,6 @@ var changedFiles = Object.create(null);
var watchers = []; var watchers = [];
module.exports = function(grunt) { module.exports = function(grunt) {
'use strict';
var taskrun = require('./lib/taskrunner')(grunt); var taskrun = require('./lib/taskrunner')(grunt);
@ -77,13 +78,17 @@ module.exports = function(grunt) {
dateFormat = df; dateFormat = df;
} }
if (taskrun.running === false) { grunt.log.writeln(waiting); } if (taskrun.running === false) {
grunt.log.writeln(waiting);
}
// Initialize taskrun // Initialize taskrun
var targets = taskrun.init(name, {target: target}); var targets = taskrun.init(name, {target: target});
targets.forEach(function(target) { targets.forEach(function(target) {
if (typeof target.files === 'string') { target.files = [target.files]; } if (typeof target.files === 'string') {
target.files = [target.files];
}
// Process into raw patterns // Process into raw patterns
var patterns = _.chain(target.files).flatten().map(function(pattern) { var patterns = _.chain(target.files).flatten().map(function(pattern) {
@ -108,7 +113,9 @@ module.exports = function(grunt) {
// Create watcher per target // Create watcher per target
watchers.push(new Gaze(patterns, target.options, function(err) { watchers.push(new Gaze(patterns, target.options, function(err) {
if (err) { if (err) {
if (typeof err === 'string') { err = new Error(err); } if (typeof err === 'string') {
err = new Error(err);
}
grunt.log.writeln('ERROR'.red); grunt.log.writeln('ERROR'.red);
grunt.fatal(err); grunt.fatal(err);
return taskrun.done(); return taskrun.done();
@ -172,7 +179,9 @@ module.exports = function(grunt) {
// On watcher error // On watcher error
this.on('error', function(err) { this.on('error', function(err) {
if (typeof err === 'string') { err = new Error(err); } if (typeof err === 'string') {
err = new Error(err);
}
grunt.log.error(err.message); grunt.log.error(err.message);
}); });
})); }));