Skip to content

Commit

Permalink
Replace deprecated grunt.util libs
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Dec 8, 2013
1 parent a1cb33b commit bc14a58
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
},
"dependencies": {
"gaze": "~0.4.0",
"tiny-lr": "0.0.5"
"tiny-lr": "0.0.5",
"lodash": "~2.4.1",
"async": "~0.2.9"
},
"devDependencies": {
"grunt": "~0.4.0",
"grunt-contrib-jshint": "~0.4.3",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt-contrib-internal": "~0.4.6"
"grunt-contrib-internal": "~0.4.6",
"underscore.string": "~2.3.3"
},
"peerDependencies": {
"grunt": "~0.4.0"
Expand Down
3 changes: 2 additions & 1 deletion tasks/lib/livereload.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'use strict';

var tinylr = require('tiny-lr');
var _ = require('lodash');

// Holds the servers out of scope in case watch is reloaded
var servers = Object.create(null);
Expand All @@ -23,7 +24,7 @@ module.exports = function(grunt) {
} else if (typeof options === 'number') {
options = {port: options};
} else {
options = grunt.util._.defaults(options, defaults);
options = _.defaults(options, defaults);
}
if (servers[options.port]) {
this.server = servers[options.port];
Expand Down
12 changes: 7 additions & 5 deletions tasks/lib/taskrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
var path = require('path');
var EE = require('events').EventEmitter;
var util = require('util');
var _ = require('lodash');
var async = require('async');

// Track which targets to run after reload
var reloadTargets = [];
Expand Down Expand Up @@ -144,19 +146,19 @@ module.exports = function(grunt) {
// The cwd to spawn within
cwd: process.cwd(),
// Additional cli args to append when spawning
cliArgs: grunt.util._.without.apply(null, [[].slice.call(process.argv, 2)].concat(grunt.cli.tasks)),
cliArgs: _.without.apply(null, [[].slice.call(process.argv, 2)].concat(grunt.cli.tasks)),
interrupt: false,
nospawn: false,
spawn: true,
atBegin: false,
event: ['all'],
target: null,
});
return grunt.util._.defaults.apply(grunt.util._, args);
return _.defaults.apply(_, args);
};

// Run the current queue of task runs
Runner.prototype.run = grunt.util._.debounce(function run() {
Runner.prototype.run = _.debounce(function run() {
var self = this;
if (self.queue.length < 1) {
self.running = false;
Expand Down Expand Up @@ -193,7 +195,7 @@ module.exports = function(grunt) {

// Run each target
var shouldComplete = true;
grunt.util.async.forEachSeries(self.queue, function(name, next) {
async.forEachSeries(self.queue, function(name, next) {
var tr = self.targets[name];
if (!tr) { return next(); }

Expand Down Expand Up @@ -308,7 +310,7 @@ module.exports = function(grunt) {
Runner.prototype.clearRequireCache = function() {
// If a non-string argument is passed, it's an array of filepaths, otherwise
// each filepath is passed individually.
var filepaths = typeof arguments[0] !== 'string' ? arguments[0] : grunt.util.toArray(arguments);
var filepaths = typeof arguments[0] !== 'string' ? arguments[0] : Array.prototype.slice(arguments);
// For each filepath, clear the require cache, if necessary.
filepaths.forEach(function(filepath) {
var abspath = path.resolve(filepath);
Expand Down
7 changes: 4 additions & 3 deletions tasks/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

var path = require('path');
var Gaze = require('gaze').Gaze;
var _ = require('lodash');
var waiting = 'Waiting...';
var changedFiles = Object.create(null);
var watchers = [];
Expand Down Expand Up @@ -85,7 +86,7 @@ module.exports = function(grunt) {
if (typeof target.files === 'string') { target.files = [target.files]; }

// Process into raw patterns
var patterns = grunt.util._.chain(target.files).flatten().map(function(pattern) {
var patterns = _.chain(target.files).flatten().map(function(pattern) {
return grunt.config.process(pattern);
}).value();

Expand Down Expand Up @@ -122,8 +123,8 @@ module.exports = function(grunt) {
this.on('all', function(status, filepath) {

// Skip events not specified
if (!grunt.util._.contains(target.options.event, 'all') &&
!grunt.util._.contains(target.options.event, status)) {
if (!_.contains(target.options.event, 'all') &&
!_.contains(target.options.event, status)) {
return;
}

Expand Down
7 changes: 4 additions & 3 deletions test/tasks/helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var grunt = require('grunt');
var path = require('path');
var _ = require('lodash');

module.exports = helper = {};

Expand All @@ -8,7 +9,7 @@ helper.fixtures = path.join(__dirname, '..', 'fixtures');

// If verbose flag set, display output
helper.verboseLog = function() {};
if (grunt.util._.indexOf(process.argv, '-v') !== -1) {
if (_.indexOf(process.argv, '-v') !== -1) {
helper.verboseLog = function() { console.log.apply(null, arguments); };
}

Expand All @@ -29,7 +30,7 @@ helper.assertTask = function assertTask(task, options) {
// Use grunt this process uses
var spawnOptions = [process.argv[1]];
// Turn options into spawn options
grunt.util._.each(options, function(val, key) {
_.each(options, function(val, key) {
spawnOptions.push('--' + key);
spawnOptions.push(val);
});
Expand All @@ -42,7 +43,7 @@ helper.assertTask = function assertTask(task, options) {
var spawnGrunt = spawn(process.argv[0], spawnOptions, {cwd:cwd});
var out = '';

if (!grunt.util._.isArray(runs)) {
if (!Array.isArray(runs)) {
runs = [runs];
}

Expand Down
5 changes: 3 additions & 2 deletions test/tasks/watch_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var grunt = require('grunt');
var path = require('path');
var fs = require('fs');
var helper = require('./helper');
var _s = require('underscore.string');

var fixtures = helper.fixtures;
var useFixtures = ['multiTargets', 'oneTarget', 'atBegin', 'dateFormat'];
Expand Down Expand Up @@ -153,7 +154,7 @@ exports.watch = {
}, function(result) {
helper.verboseLog(result);
test.ok(result.toLowerCase().indexOf('fatal') !== -1, 'Task should have been fatal.');
test.equal(grunt.util._(result).count('Waiting...'), 2, 'Should have displayed "Wating..." twice');
test.equal(_s.count(result, 'Waiting...'), 2, 'Should have displayed "Wating..." twice');
test.done();
});
},
Expand All @@ -166,7 +167,7 @@ exports.watch = {
}, function(result) {
helper.verboseLog(result);
test.ok(result.toLowerCase().indexOf('cwd works') !== -1, 'Task should have shown "cwd works".');
test.equal(grunt.util._(result).count('Waiting...'), 2, 'Should have displayed "Wating..." twice');
test.equal(_s.count(result, 'Waiting...'), 2, 'Should have displayed "Wating..." twice');
test.done();
});
},
Expand Down

0 comments on commit bc14a58

Please sign in to comment.