Permalink
Browse files

merge

  • Loading branch information...
2 parents 594cf89 + 3561efa commit e8d66cc65df6387ad21d2715e1366856f55b3a28 Stephen Murphy committed Jan 21, 2015
Showing with 91 additions and 11 deletions.
  1. +6 −8 Gearfile
  2. +21 −1 bin/gear.js
  3. +21 −0 build/gear.js
  4. +1 −1 build/gear.min.js
  5. +21 −0 lib/queue.js
  6. +1 −1 package.json
  7. +20 −0 test/queue.js
View
@@ -1,8 +1,6 @@
-(function() {
- return {
- log: {task: ['log', 'Minifying gear for the browser']},
- read: {requires: 'log', task: ['read', 'build/gear.js']},
- min: {requires: 'read', task: 'jsminify'},
- write: {requires: 'min', task: ['write', 'build/gear.min.js']}
- };
-})()
+{
+ log: {task: ['log', 'Minifying gear for the browser']},
+ read: {requires: 'log', task: ['read', 'build/gear.js']},
+ min: {requires: 'read', task: 'jsminify'},
+ write: {requires: 'min', task: ['write', 'build/gear.min.js']}
+}
View
@@ -28,6 +28,15 @@ var GearCLI = new Liftoff({
}
});
+function stripStartingComments(s) {
+ var s2;
+ while (s2 !== s) {
+ s2 = s;
+ s = s2.replace(/^(\s+|\/\/.*|\/\*[^]*?\*\/)/, '');
+ }
+ return s;
+}
+
GearCLI.launch({
cwd: argv.cwd,
configPath: argv.Gearfile
@@ -38,14 +47,25 @@ GearCLI.launch({
process.chdir(env.configBase);
}
+ if (argv.v || argv.version) {
+ var pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json')) + '');
+ console.log('gear version ' + pkg.version);
+ }
+
if (!env.configPath) {
notify(filename + ' not found');
process.exit(1);
}
var tasks;
+ var gearfile = fs.readFileSync(env.configPath) + '';
+
try {
- tasks = vm.runInNewContext('var tasks = ' + fs.readFileSync(env.configPath) + '; tasks;', {
+ // workaround for a bug which makes runInNewContext unable to evaluate an object literal.
+ var script = (stripStartingComments(gearfile).charAt(0) === '{') ?
+ '(' + gearfile + ')' :
+ gearfile;
+ tasks = vm.runInNewContext(script, {
require: require,
process: process,
console: console,
View
@@ -220,7 +220,20 @@ Queue.prototype._log = function(message) {
this._logger.log(message);
};
+function asTask(queue) {
+ return function(result, callback) {
+ queue._queue[0]= function(done) {
+ done(null, result);
+ };
+ queue.run(callback);
+ };
+}
+
Queue.prototype._dispatch = function(name, options, blobs, done) {
+ if (name instanceof Queue) {
+ return asTask(name)(blobs, done);
+ }
+
var task = this._registry.task(name),
types = { // Allow task type to be inferred based on task params
2: 'append',
@@ -290,6 +303,14 @@ Queue.prototype.task = function(name, options) {
return this;
};
+Queue.prototype.series = function(sequence) {
+ if (sequence instanceof Queue) {
+ sequence = [].slice.call(arguments);
+ }
+ this._queue = this._queue.concat(sequence.map(asTask));
+ return this;
+};
+
Queue.prototype.run = function(callback) {
var self = this;
async.waterfall(this._queue, callback || function(err, res) {if (err) {self._log(err);}});
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -54,7 +54,20 @@ Queue.prototype._log = function(message) {
this._logger.log(message);
};
+function asTask(queue) {
+ return function(result, callback) {
+ queue._queue[0]= function(done) {
+ done(null, result);
+ };
+ queue.run(callback);
+ };
+}
+
Queue.prototype._dispatch = function(name, options, blobs, done) {
+ if (name instanceof Queue) {
+ return asTask(name)(blobs, done);
+ }
+
var task = this._registry.task(name),
types = { // Allow task type to be inferred based on task params
2: 'append',
@@ -124,6 +137,14 @@ Queue.prototype.task = function(name, options) {
return this;
};
+Queue.prototype.series = function(sequence) {
+ if (sequence instanceof Queue) {
+ sequence = [].slice.call(arguments);
+ }
+ this._queue = this._queue.concat(sequence.map(asTask));
+ return this;
+};
+
Queue.prototype.run = function(callback) {
var self = this;
async.waterfall(this._queue, callback || function(err, res) {if (err) {self._log(err);}});
View
@@ -1,6 +1,6 @@
{
"name": "gear",
- "version": "0.9.5",
+ "version": "0.9.7",
"description": "Gear.js - Build System for Node.js and the Browser",
"author": "Stephen Murphy <stephen@hypernaut.com>",
"keywords": ["task", "build"],
View
@@ -107,6 +107,26 @@ describe('Queue', function() {
done();
}
});
+
+ it('should allow queues to be run in sequence', function(done) {
+ var q1 = new gear.Queue()
+ .append('hello')
+ .append('world!');
+ var q2 = new gear.Queue()
+ .append('HELLO')
+ .append('WORLD!');
+ new gear.Queue()
+ .series(q1, q2)
+ .run(function(err, results) {
+ results.should.have.length(4);
+ results[0].result.should.equal('hello');
+ results[1].result.should.equal('world!');
+ results[2].result.should.equal('HELLO');
+ results[3].result.should.equal('WORLD!');
+ done(err);
+ });
+ });
+
});
describe('run', function() {

0 comments on commit e8d66cc

Please sign in to comment.