Skip to content
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
14 Gearfile
@@ -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
22 bin/gear.js
@@ -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
21 build/gear.js
@@ -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
2 build/gear.min.js
@@ -1,4 +1,4 @@
-!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.Gear=e()}}(function(){var define,module,exports;return function e(t,r,n){function i(s,f){if(!r[s]){if(!t[s]){var o="function"==typeof require&&require;if(!f&&o)return o(s,!0);if(a)return a(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var d=r[s]={exports:{}};t[s][0].call(d.exports,function(e){var r=t[s][1][e];return i(r?r:e)},d,d.exports,e,t,r,n)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t,r){(function(t){var n=r.Blob=function s(e,t){function r(e,t){Object.keys(t).forEach(function(r){e[r]=t[r]})}e="undefined"==typeof e?[]:Array.prototype.concat(e),t=t||{};var n=e.length?e.shift():"",i={},a=this;n instanceof s&&(r(i,n),n=n.result),e.forEach(function(e){e instanceof s?(r(i,e),n+=e.result):n+=e}),r(i,t),Object.keys(i).forEach(function(e){"result"!==e&&Object.defineProperty(a,e,{enumerable:!0,value:i[e]})}),Object.defineProperty(this,"result",{value:n})};n.prototype.toString=function(){return this.result};var i={server:function(t,r,a,s){var f=e("fs");s?i.serverSync(t,r,a):f.readFile(t,"bin"===r?void 0:r,function(e,r){e?a(e):a(null,new n(r,{name:t}))})},serverSync:function(t,r,i){var a,s=e("fs");try{a=s.readFileSync(t,"bin"===r?void 0:r),i(null,new n(a,{name:t}))}catch(f){i(f)}},client:function(e,t,r){e in localStorage?r(null,new n(localStorage[e],{name:e})):r("localStorage has no item "+e)}};n.readFile=n.prototype.readFile=t.browser?i.client:i.server;var a={server:function(t,r,i,a){function s(e,t){o.writeFile(e,t.result,"bin"===i?void 0:i,function(r){a(r,new n(t,{name:e}))})}var f,o=e("fs"),c=e("path"),d=o.exists||c.exists,u=e("mkdirp").mkdirp,h=e("crypto"),l=c.resolve(c.dirname(t));t.indexOf("{checksum}")>-1&&(f=h.createHash("md5"),f.update(r.result),t=t.replace("{checksum}",f.digest("hex"))),d(l,function(e){e?s(t,r):u(l,"0755",function(e){e?a(e):s(t,r)})})},client:function(e,t,r,n){localStorage[e]=t.result,n(null,new t.constructor(t,{name:e}))}};n.writeFile=n.prototype.writeFile=t.browser?a.client:a.server}).call(this,e("_process"))},{_process:163,crypto:21,fs:15,mkdirp:179,path:162}],2:[function(e,t){t.exports={Registry:e("./registry").Registry,Blob:e("./blob").Blob,Queue:e("./queue").Queue,Util:e("./util"),tasks:e("./tasks")}},{"./blob":1,"./queue":3,"./registry":4,"./tasks":7,"./util":13}],3:[function(e,t,r){function n(e,t){for(var r=[],n=0;n<Math.min(e.length,t.length);n++)r.push([e[n],t[n]]);return r}function i(e){return"undefined"==typeof e?[]:Array.prototype.concat(e)}var a=e("async"),s=e("./registry").Registry,f=e("./blob").Blob,o=r.Queue=function(e){var t=this;e=e||{},this._logger=e.logger||console,this._registry="string"==typeof e.registry?new s({module:e.registry}):e.registry||new s,this._clear(),this._registry.tasks.forEach(function(e){t[e]=t.task.bind(t,e)})};o.prototype._clear=function(){this._queue=[function(e){e(null,[])}]},o.prototype._log=function(e){this._logger.log(e)},o.prototype._dispatch=function(e,t,r,s){function o(t,r){t&&(t={task:e,error:t}),s(t,r)}var c=this._registry.task(e),d={2:"append",3:"map",4:"reduce"},u=c.type?c.type:d[c.length];switch(u){case"append":a.map(i(t),c.bind(this),function(e,t){o(e,r.concat(t))});break;case"prepend":a.map(i(t),c.bind(this),function(e,t){o(e,t.concat(r))});break;case"collect":c.call(this,t,r,o);break;case"slice":a.map(n(i(t),r),function(e,t){c.call(this,e[0],e[1],t)}.bind(this),o);break;case"each":a.forEach(r,c.bind(this,t),function(e){o(e,r)});break;case"map":a.map(r,c.bind(this,t),o);break;case"syncmap":a.mapSeries(r,c.bind(this,t),o);break;case"reduce":a.reduce(r,new f,c.bind(this,t),function(e,t){o(e,[t])});break;default:throw new Error('Task "'+e+'" has unknown type. Add a type property to the task function.')}},o.prototype.task=function(e,t){return this._queue.push(this._dispatch.bind(this,e,t)),this},o.prototype.run=function(e){var t=this;a.waterfall(this._queue,e||function(e){e&&t._log(e)})}},{"./blob":1,"./registry":4,async:14}],4:[function(e,t,r){(function(t,n){var i=e("fs"),a=e("path"),s=r.Registry=function(r){var i=this;this._tasks={},this.load(t.browser?{tasks:e("./tasks")}:{dirname:n+"/tasks"}),r&&this.load(r),Object.defineProperty(this,"tasks",{get:function(){return Object.keys(i._tasks)}})};s.prototype={load:function(e){e=e||{};var t=e.module,r=e.dirname,n=e.filename,i=e.tasks;if(t&&!this._loadModule(t))throw new Error("Module "+t+" doesn't exist");if(r&&!this._loadDir(r))throw new Error("Directory "+r+" doesn't exist");if(n&&!this._loadFile(n))throw new Error("File "+n+" doesn't exist");if(i&&!this._loadTasks(i))throw new Error("Failed to load tasks");return this},_loadModule:function(t){if(e)try{return this._loadTasks(e(t))}catch(r){}return this._loadDir(a.resolve("node_modules",t,"lib"))},_loadDir:function(e){if(!i.existsSync(e))return!1;var t=i.readdirSync(e),r=this;return t.forEach(function(t){var n=a.join(e,t);".js"===a.extname(n)&&r._loadFile(n)}),!0},_loadFile:function(t){return i.existsSync(t)?this._loadTasks(e(t)):!1},_loadTasks:function(e){var t;for(t in e)this._tasks[t]=e[t];return!0},task:function(e){if(!(e in this._tasks))throw new Error("Task "+e+" doesn't exist");return this._tasks[e]}}}).call(this,e("_process"),"/lib")},{"./tasks":7,_process:163,fs:15,path:162}],5:[function(e,t,r){r.concat=function(e,t,r,n){e=e||{},n(null,new r.constructor([t,e.callback?e.callback(r):r]))}},{}],6:[function(e,t,r){function n(){return function(e,t){t(null,new i(e))}}var i=e("../blob").Blob;r.append=r.load=n();var a=r.prepend=n();a.type="prepend";var s=r.test=function(e,t,r){e=e||{},r(e.callback?e.callback(t):null)};s.type="each";var f=r.get=function(e,t,r){r(null,t.slice(e,e+1))};f.type="collect";var o=r.log=function(e,t,r){this._log(e),r(null,t)};o.type="collect";var c=r.inspect=function(e,t,r){var n=this;t.forEach(function(e,t){var r={result:e.result};Object.keys(e).forEach(function(t){r[t]=e[t]}),n._log("blob "+(t+1)+": "+JSON.stringify(r,null," "))}),r(null,t)};c.type="collect",r.noop=function(e,t,r){r(null,t)}},{"../blob":1}],7:[function(e,t){function r(e){Object.keys(e).map(function(t){n[t]=e[t]})}var n={write:e("./write").write,tasks:e("./tasks").tasks,stamp:e("./stamp").stamp,replace:e("./replace").replace,concat:e("./concat").concat};r(e("./core")),r(e("./read")),t.exports=n},{"./concat":5,"./core":6,"./read":8,"./replace":9,"./stamp":10,"./tasks":11,"./write":12}],8:[function(e,t,r){function n(){return function(e,t){e="string"==typeof e?{name:e}:e;var r=e.encoding||"utf8";i.readFile(e.name,r,t,e.sync)}}var i=e("../blob").Blob;r.read=n();var a=r.readBefore=n();a.type="prepend"},{"../blob":1}],9:[function(e,t,r){r.replace=function(e,t,r){var n=t.result;Array.isArray(e)||(e=[e]),e.forEach(function(e){var t=e.replace||"",r=void 0!==e.flags?e.flags:"mg",i="string"==typeof e.regex?new RegExp(e.regex,r):e.regex;n=n.replace(i,t)}),r(null,new t.constructor(n,t))}},{}],10:[function(e,t,r){r.stamp=function(e,t,r){e=e||{},e.prefix=e.prefix||"",e.postfix=e.postfix||"";var n=e.callback?e.callback(t):t.result,i=e.prefix+n+e.postfix;r(null,new t.constructor(i,t))}},{}],11:[function(e,t,r){var n=e("async"),i=r.tasks=function(e,t,r){function i(e,r,n){return function(i,a){var s=n.length?[]:t;a=a||[],n.forEach(function(e){s=s.concat(a[e])}),d._dispatch(e,r,s,i)}}var a,s,f,o,c={},d=this;for(a in e)s=e[a].task,void 0===s?s=["noop"]:Array.isArray(s)||(s=[s]),f=e[a].requires,void 0===f?f=[]:Array.isArray(f)||(f=[f]),o=i(s[0],s[1],f),c[a]=f?f.concat(o):o;n.auto(c,function(e,t){return e?void r(e):void r(e,t&&t.join?t.join:[])})};i.type="collect"},{async:14}],12:[function(e,t,r){var n=r.write=function(e,t,r){e="string"==typeof e?{name:e}:e;var n=e.encoding||"utf8";t.writeFile(e.name,t,n,r)};n.type="slice"},{}],13:[function(e,t){(function(r){function n(e){return localStorage[e]}function i(e){return JSON.parse(f(e)+"")}function a(e){return JSON.parse(s(f(e)+""))}function s(e){var t,r,n,i,a=/"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g,s=!1,f=!1,o=!1,c=[],d=0,u=0;for(a.lastIndex=0;t=a.exec(e);)n=RegExp.leftContext,i=RegExp.rightContext,f||o||(r=n.substring(u),s||(r=r.replace(/(\n|\r|\s)*/g,"")),c[d++]=r),u=a.lastIndex,'"'!=t[0]||f||o?"/*"!=t[0]||s||f||o?"*/"!=t[0]||s||!f||o?"//"!=t[0]||s||f||o?"\n"!=t[0]&&"\r"!=t[0]||s||f||!o?f||o||/\n|\r|\s/.test(t[0])||(c[d++]=t[0]):o=!1:o=!0:f=!1:f=!0:(r=n.match(/(\\)*$/),s&&r&&r[0].length%2!==0||(s=!s),u--,i=e.substring(u));return c[d++]=i,c.join("")}var f=r.browser?n:e("fs").readFileSync;t.exports={readJSON:i,readJSONC:a}}).call(this,e("_process"))},{_process:163,fs:15}],14:[function(e,t){(function(e){/*!
+!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.Gear=e()}}(function(){var define,module,exports;return function e(t,r,n){function i(s,f){if(!r[s]){if(!t[s]){var o="function"==typeof require&&require;if(!f&&o)return o(s,!0);if(a)return a(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var d=r[s]={exports:{}};t[s][0].call(d.exports,function(e){var r=t[s][1][e];return i(r?r:e)},d,d.exports,e,t,r,n)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t,r){(function(t){var n=r.Blob=function s(e,t){function r(e,t){Object.keys(t).forEach(function(r){e[r]=t[r]})}e="undefined"==typeof e?[]:Array.prototype.concat(e),t=t||{};var n=e.length?e.shift():"",i={},a=this;n instanceof s&&(r(i,n),n=n.result),e.forEach(function(e){e instanceof s?(r(i,e),n+=e.result):n+=e}),r(i,t),Object.keys(i).forEach(function(e){"result"!==e&&Object.defineProperty(a,e,{enumerable:!0,value:i[e]})}),Object.defineProperty(this,"result",{value:n})};n.prototype.toString=function(){return this.result};var i={server:function(t,r,a,s){var f=e("fs");s?i.serverSync(t,r,a):f.readFile(t,"bin"===r?void 0:r,function(e,r){e?a(e):a(null,new n(r,{name:t}))})},serverSync:function(t,r,i){var a,s=e("fs");try{a=s.readFileSync(t,"bin"===r?void 0:r),i(null,new n(a,{name:t}))}catch(f){i(f)}},client:function(e,t,r){e in localStorage?r(null,new n(localStorage[e],{name:e})):r("localStorage has no item "+e)}};n.readFile=n.prototype.readFile=t.browser?i.client:i.server;var a={server:function(t,r,i,a){function s(e,t){o.writeFile(e,t.result,"bin"===i?void 0:i,function(r){a(r,new n(t,{name:e}))})}var f,o=e("fs"),c=e("path"),d=o.exists||c.exists,u=e("mkdirp").mkdirp,h=e("crypto"),l=c.resolve(c.dirname(t));t.indexOf("{checksum}")>-1&&(f=h.createHash("md5"),f.update(r.result),t=t.replace("{checksum}",f.digest("hex"))),d(l,function(e){e?s(t,r):u(l,"0755",function(e){e?a(e):s(t,r)})})},client:function(e,t,r,n){localStorage[e]=t.result,n(null,new t.constructor(t,{name:e}))}};n.writeFile=n.prototype.writeFile=t.browser?a.client:a.server}).call(this,e("_process"))},{_process:163,crypto:21,fs:15,mkdirp:179,path:162}],2:[function(e,t){t.exports={Registry:e("./registry").Registry,Blob:e("./blob").Blob,Queue:e("./queue").Queue,Util:e("./util"),tasks:e("./tasks")}},{"./blob":1,"./queue":3,"./registry":4,"./tasks":7,"./util":13}],3:[function(e,t,r){function n(e,t){for(var r=[],n=0;n<Math.min(e.length,t.length);n++)r.push([e[n],t[n]]);return r}function i(e){return"undefined"==typeof e?[]:Array.prototype.concat(e)}function a(e){return function(t,r){e._queue[0]=function(e){e(null,t)},e.run(r)}}var s=e("async"),f=e("./registry").Registry,o=e("./blob").Blob,c=r.Queue=function(e){var t=this;e=e||{},this._logger=e.logger||console,this._registry="string"==typeof e.registry?new f({module:e.registry}):e.registry||new f,this._clear(),this._registry.tasks.forEach(function(e){t[e]=t.task.bind(t,e)})};c.prototype._clear=function(){this._queue=[function(e){e(null,[])}]},c.prototype._log=function(e){this._logger.log(e)},c.prototype._dispatch=function(e,t,r,f){function d(t,r){t&&(t={task:e,error:t}),f(t,r)}if(e instanceof c)return a(e)(r,f);var u=this._registry.task(e),h={2:"append",3:"map",4:"reduce"},l=u.type?u.type:h[u.length];switch(l){case"append":s.map(i(t),u.bind(this),function(e,t){d(e,r.concat(t))});break;case"prepend":s.map(i(t),u.bind(this),function(e,t){d(e,t.concat(r))});break;case"collect":u.call(this,t,r,d);break;case"slice":s.map(n(i(t),r),function(e,t){u.call(this,e[0],e[1],t)}.bind(this),d);break;case"each":s.forEach(r,u.bind(this,t),function(e){d(e,r)});break;case"map":s.map(r,u.bind(this,t),d);break;case"syncmap":s.mapSeries(r,u.bind(this,t),d);break;case"reduce":s.reduce(r,new o,u.bind(this,t),function(e,t){d(e,[t])});break;default:throw new Error('Task "'+e+'" has unknown type. Add a type property to the task function.')}},c.prototype.task=function(e,t){return this._queue.push(this._dispatch.bind(this,e,t)),this},c.prototype.series=function(e){return e instanceof c&&(e=[].slice.call(arguments)),this._queue=this._queue.concat(e.map(a)),this},c.prototype.run=function(e){var t=this;s.waterfall(this._queue,e||function(e){e&&t._log(e)})}},{"./blob":1,"./registry":4,async:14}],4:[function(e,t,r){(function(t,n){var i=e("fs"),a=e("path"),s=r.Registry=function(r){var i=this;this._tasks={},this.load(t.browser?{tasks:e("./tasks")}:{dirname:n+"/tasks"}),r&&this.load(r),Object.defineProperty(this,"tasks",{get:function(){return Object.keys(i._tasks)}})};s.prototype={load:function(e){e=e||{};var t=e.module,r=e.dirname,n=e.filename,i=e.tasks;if(t&&!this._loadModule(t))throw new Error("Module "+t+" doesn't exist");if(r&&!this._loadDir(r))throw new Error("Directory "+r+" doesn't exist");if(n&&!this._loadFile(n))throw new Error("File "+n+" doesn't exist");if(i&&!this._loadTasks(i))throw new Error("Failed to load tasks");return this},_loadModule:function(t){if(e)try{return this._loadTasks(e(t))}catch(r){}return this._loadDir(a.resolve("node_modules",t,"lib"))},_loadDir:function(e){if(!i.existsSync(e))return!1;var t=i.readdirSync(e),r=this;return t.forEach(function(t){var n=a.join(e,t);".js"===a.extname(n)&&r._loadFile(n)}),!0},_loadFile:function(t){return i.existsSync(t)?this._loadTasks(e(t)):!1},_loadTasks:function(e){var t;for(t in e)this._tasks[t]=e[t];return!0},task:function(e){if(!(e in this._tasks))throw new Error("Task "+e+" doesn't exist");return this._tasks[e]}}}).call(this,e("_process"),"/lib")},{"./tasks":7,_process:163,fs:15,path:162}],5:[function(e,t,r){r.concat=function(e,t,r,n){e=e||{},n(null,new r.constructor([t,e.callback?e.callback(r):r]))}},{}],6:[function(e,t,r){function n(){return function(e,t){t(null,new i(e))}}var i=e("../blob").Blob;r.append=r.load=n();var a=r.prepend=n();a.type="prepend";var s=r.test=function(e,t,r){e=e||{},r(e.callback?e.callback(t):null)};s.type="each";var f=r.get=function(e,t,r){r(null,t.slice(e,e+1))};f.type="collect";var o=r.log=function(e,t,r){this._log(e),r(null,t)};o.type="collect";var c=r.inspect=function(e,t,r){var n=this;t.forEach(function(e,t){var r={result:e.result};Object.keys(e).forEach(function(t){r[t]=e[t]}),n._log("blob "+(t+1)+": "+JSON.stringify(r,null," "))}),r(null,t)};c.type="collect",r.noop=function(e,t,r){r(null,t)}},{"../blob":1}],7:[function(e,t){function r(e){Object.keys(e).map(function(t){n[t]=e[t]})}var n={write:e("./write").write,tasks:e("./tasks").tasks,stamp:e("./stamp").stamp,replace:e("./replace").replace,concat:e("./concat").concat};r(e("./core")),r(e("./read")),t.exports=n},{"./concat":5,"./core":6,"./read":8,"./replace":9,"./stamp":10,"./tasks":11,"./write":12}],8:[function(e,t,r){function n(){return function(e,t){e="string"==typeof e?{name:e}:e;var r=e.encoding||"utf8";i.readFile(e.name,r,t,e.sync)}}var i=e("../blob").Blob;r.read=n();var a=r.readBefore=n();a.type="prepend"},{"../blob":1}],9:[function(e,t,r){r.replace=function(e,t,r){var n=t.result;Array.isArray(e)||(e=[e]),e.forEach(function(e){var t=e.replace||"",r=void 0!==e.flags?e.flags:"mg",i="string"==typeof e.regex?new RegExp(e.regex,r):e.regex;n=n.replace(i,t)}),r(null,new t.constructor(n,t))}},{}],10:[function(e,t,r){r.stamp=function(e,t,r){e=e||{},e.prefix=e.prefix||"",e.postfix=e.postfix||"";var n=e.callback?e.callback(t):t.result,i=e.prefix+n+e.postfix;r(null,new t.constructor(i,t))}},{}],11:[function(e,t,r){var n=e("async"),i=r.tasks=function(e,t,r){function i(e,r,n){return function(i,a){var s=n.length?[]:t;a=a||[],n.forEach(function(e){s=s.concat(a[e])}),d._dispatch(e,r,s,i)}}var a,s,f,o,c={},d=this;for(a in e)s=e[a].task,void 0===s?s=["noop"]:Array.isArray(s)||(s=[s]),f=e[a].requires,void 0===f?f=[]:Array.isArray(f)||(f=[f]),o=i(s[0],s[1],f),c[a]=f?f.concat(o):o;n.auto(c,function(e,t){return e?void r(e):void r(e,t&&t.join?t.join:[])})};i.type="collect"},{async:14}],12:[function(e,t,r){var n=r.write=function(e,t,r){e="string"==typeof e?{name:e}:e;var n=e.encoding||"utf8";t.writeFile(e.name,t,n,r)};n.type="slice"},{}],13:[function(e,t){(function(r){function n(e){return localStorage[e]}function i(e){return JSON.parse(f(e)+"")}function a(e){return JSON.parse(s(f(e)+""))}function s(e){var t,r,n,i,a=/"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g,s=!1,f=!1,o=!1,c=[],d=0,u=0;for(a.lastIndex=0;t=a.exec(e);)n=RegExp.leftContext,i=RegExp.rightContext,f||o||(r=n.substring(u),s||(r=r.replace(/(\n|\r|\s)*/g,"")),c[d++]=r),u=a.lastIndex,'"'!=t[0]||f||o?"/*"!=t[0]||s||f||o?"*/"!=t[0]||s||!f||o?"//"!=t[0]||s||f||o?"\n"!=t[0]&&"\r"!=t[0]||s||f||!o?f||o||/\n|\r|\s/.test(t[0])||(c[d++]=t[0]):o=!1:o=!0:f=!1:f=!0:(r=n.match(/(\\)*$/),s&&r&&r[0].length%2!==0||(s=!s),u--,i=e.substring(u));return c[d++]=i,c.join("")}var f=r.browser?n:e("fs").readFileSync;t.exports={readJSON:i,readJSONC:a}}).call(this,e("_process"))},{_process:163,fs:15}],14:[function(e,t){(function(e){/*!
* async
* https://github.com/caolan/async
*
View
21 lib/queue.js
@@ -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
2 package.json
@@ -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
20 test/queue.js
@@ -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.
Something went wrong with that request. Please try again.