diff --git a/tasks/lib/livereload.js b/tasks/lib/livereload.js index 82b5d7e..0bdd848 100644 --- a/tasks/lib/livereload.js +++ b/tasks/lib/livereload.js @@ -43,7 +43,9 @@ module.exports = function(grunt) { process.exit(1); }); 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); }); servers[host] = this.server; diff --git a/tasks/lib/taskrun.js b/tasks/lib/taskrun.js index ced98fc..2b3d382 100644 --- a/tasks/lib/taskrun.js +++ b/tasks/lib/taskrun.js @@ -39,7 +39,9 @@ module.exports = function(grunt) { var self = this; // Dont run if already running - if (self.startedAt !== false) { return; } + if (self.startedAt !== false) { + return; + } // Start this task run self.startedAt = Date.now(); @@ -55,7 +57,9 @@ module.exports = function(grunt) { } // 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) { grunt.task.run(self.tasks); @@ -67,10 +71,10 @@ module.exports = function(grunt) { // Run from current working dir and inherit stdio from process opts: { cwd: self.options.cwd.spawn, - stdio: 'inherit', + stdio: 'inherit' }, // 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) { self.spawnTaskFailure = (code !== 0); if (self.options.interrupt !== true || (code !== 130 && code !== 1)) { diff --git a/tasks/lib/taskrunner.js b/tasks/lib/taskrunner.js index 97f15fd..c1f610c 100644 --- a/tasks/lib/taskrunner.js +++ b/tasks/lib/taskrunner.js @@ -57,7 +57,7 @@ module.exports = function(grunt) { self.name = name || grunt.task.current.name || 'watch'; self.options = self._options(grunt.config([self.name, 'options']) || {}, defaults || {}); 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 if (typeof self.options.cwd === 'string') { @@ -121,10 +121,12 @@ module.exports = function(grunt) { grunt.task.current.requiresConfig(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) { - if (key === 'options') { return false; } + if (key === 'options') { + return false; + } return typeof config[key] !== 'string' && !Array.isArray(config[key]); }).map(function(target) { // Fail if any required config properties have been omitted @@ -142,7 +144,7 @@ module.exports = function(grunt) { files: config.files, tasks: config.tasks, name: defaultTargetName, - options: self._options(config.options || {}, self.options), + options: self._options(config.options || {}, self.options) }; targets.push(cfg); self.add(cfg); @@ -163,7 +165,7 @@ module.exports = function(grunt) { spawn: true, atBegin: false, event: ['all'], - target: null, + target: null }); return _.defaults.apply(_, args); }; @@ -198,7 +200,9 @@ module.exports = function(grunt) { } // If we should reload - if (self.reload) { return self.reloadTask(); } + if (self.reload) { + return self.reloadTask(); + } // Trigger that tasks runs have started self.emit('start'); @@ -208,7 +212,9 @@ module.exports = function(grunt) { var shouldComplete = true; async.forEachSeries(self.queue, function(name, next) { var tr = self.targets[name]; - if (!tr) { return next(); } + if (!tr) { + return next(); + } // Re-grab options in case they changed between runs 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 target._getConfig = function(name) { var cfgPath = [self.name]; - if (target.name !== defaultTargetName) { cfgPath.push(target.name); } - if (name) { cfgPath.push(name); } + if (target.name !== defaultTargetName) { + cfgPath.push(target.name); + } + if (name) { + cfgPath.push(name); + } return grunt.config(cfgPath); }; @@ -262,13 +272,17 @@ module.exports = function(grunt) { // Do this when queued task runs have completed/scheduled Runner.prototype.complete = function complete() { var self = this; - if (self.running === false) { return; } + if (self.running === false) { + return; + } self.running = false; var time = 0; for (var i = 0, len = self.queue.length; i < len; ++i) { var name = self.queue[i]; var target = self.targets[name]; - if (!target) { return; } + if (!target) { + return; + } if (target.startedAt !== false) { time += target.complete(); self.queue.splice(i--, 1); @@ -291,7 +305,9 @@ module.exports = function(grunt) { var self = this; self.queue.forEach(function(name) { var target = self.targets[name]; - if (!target) { return; } + if (!target) { + return; + } target.complete(); }); }; diff --git a/tasks/watch.js b/tasks/watch.js index 77dfee3..9b9a81e 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -6,6 +6,8 @@ * Licensed under the MIT license. */ +'use strict'; + var path = require('path'); var Gaze = require('gaze').Gaze; var _ = require('lodash'); @@ -14,7 +16,6 @@ var changedFiles = Object.create(null); var watchers = []; module.exports = function(grunt) { - 'use strict'; var taskrun = require('./lib/taskrunner')(grunt); @@ -77,13 +78,17 @@ module.exports = function(grunt) { dateFormat = df; } - if (taskrun.running === false) { grunt.log.writeln(waiting); } + if (taskrun.running === false) { + grunt.log.writeln(waiting); + } // Initialize taskrun var targets = taskrun.init(name, {target: 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 var patterns = _.chain(target.files).flatten().map(function(pattern) { @@ -108,7 +113,9 @@ module.exports = function(grunt) { // Create watcher per target watchers.push(new Gaze(patterns, target.options, function(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.fatal(err); return taskrun.done(); @@ -172,7 +179,9 @@ module.exports = function(grunt) { // On watcher error 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); }); }));