Skip to content
Browse files

initial commit

  • Loading branch information...
1 parent 4bd37bd commit 6c1de36fa5dba65dc9fe9e3c3d56301a26336e04 @crcn crcn committed Mar 14, 2013
View
11 README.md
@@ -1,5 +1,10 @@
Nojam combines [npm](http://npmjs.org) modules with [jam](http://jamjs.org) modules, essentially making your node.js code accessible on the web!
+### Requirements
+
+- [node.js](http://nodejs.org)
+- [jamjs](http://jamjs.org) - `npm install jamjs -g`
+
## Installation
```
@@ -15,15 +20,11 @@ To install a node module for the web, call:
nojam install sift
```
-To install a jam module, call:
-
-```bash
-nojam install jam:jquery
-```
You can also be explicit about installing from npm as well:
```bash
nojam install npm:sift
+nojam install jam:jquery
```
View
35 bin/nojam
@@ -1 +1,36 @@
#!/usr/bin/env node
+var commander = require("commander"),
+NoJam = require("../"),
+noJam = new NoJam({
+ pkg: loadPackage()
+});
+
+commander.
+command("install").
+description("installs a package from NPM, or JAM").
+action(function() {
+ var packages = Array.prototype.slice.call(arguments);
+ packages.pop()
+ noJam.install(packages);
+})
+
+
+commander.
+command("rebuild").
+description("rebuilds the NPM modules as JAM modules").
+action(function() {
+ noJam.rebuild();
+})
+
+
+commander.parse(process.argv);
+
+
+
+function loadPackage() {
+ try {
+ return require(process.cwd() + "/package.json");
+ } catch(e) {
+ return {}
+ }
+}
View
0 docs/brainstorm.md
No changes.
View
993 jam/async/lib/async.js
@@ -0,0 +1,993 @@
+define([], function(require) {
+
+ var __dirname = "async/lib",
+ __filename = "async/lib/async.js",
+ module = { exports: {} },
+ exports = module.exports;
+
+ /*global setImmediate: false, setTimeout: false, console: false */
+(function () {
+
+ var async = {};
+
+ // global on the server, window in the browser
+ var root, previous_async;
+
+ root = this;
+ if (root != null) {
+ previous_async = root.async;
+ }
+
+ async.noConflict = function () {
+ root.async = previous_async;
+ return async;
+ };
+
+ function only_once(fn) {
+ var called = false;
+ return function() {
+ if (called) throw new Error("Callback was already called.");
+ called = true;
+ fn.apply(root, arguments);
+ }
+ }
+
+ //// cross-browser compatiblity functions ////
+
+ var _each = function (arr, iterator) {
+ if (arr.forEach) {
+ return arr.forEach(iterator);
+ }
+ for (var i = 0; i < arr.length; i += 1) {
+ iterator(arr[i], i, arr);
+ }
+ };
+
+ var _map = function (arr, iterator) {
+ if (arr.map) {
+ return arr.map(iterator);
+ }
+ var results = [];
+ _each(arr, function (x, i, a) {
+ results.push(iterator(x, i, a));
+ });
+ return results;
+ };
+
+ var _reduce = function (arr, iterator, memo) {
+ if (arr.reduce) {
+ return arr.reduce(iterator, memo);
+ }
+ _each(arr, function (x, i, a) {
+ memo = iterator(memo, x, i, a);
+ });
+ return memo;
+ };
+
+ var _keys = function (obj) {
+ if (Object.keys) {
+ return Object.keys(obj);
+ }
+ var keys = [];
+ for (var k in obj) {
+ if (obj.hasOwnProperty(k)) {
+ keys.push(k);
+ }
+ }
+ return keys;
+ };
+
+ //// exported async module functions ////
+
+ //// nextTick implementation with browser-compatible fallback ////
+ if (typeof process === 'undefined' || !(process.nextTick)) {
+ if (typeof setImmediate === 'function') {
+ async.nextTick = function (fn) {
+ setImmediate(fn);
+ };
+ }
+ else {
+ async.nextTick = function (fn) {
+ setTimeout(fn, 0);
+ };
+ }
+ }
+ else {
+ async.nextTick = process.nextTick;
+ }
+
+ async.each = function (arr, iterator, callback) {
+ callback = callback || function () {};
+ if (!arr.length) {
+ return callback();
+ }
+ var completed = 0;
+ _each(arr, function (x) {
+ iterator(x, only_once(function (err) {
+ if (err) {
+ callback(err);
+ callback = function () {};
+ }
+ else {
+ completed += 1;
+ if (completed >= arr.length) {
+ callback(null);
+ }
+ }
+ }));
+ });
+ };
+ async.forEach = async.each;
+
+ async.eachSeries = function (arr, iterator, callback) {
+ callback = callback || function () {};
+ if (!arr.length) {
+ return callback();
+ }
+ var completed = 0;
+ var iterate = function () {
+ var sync = true;
+ iterator(arr[completed], function (err) {
+ if (err) {
+ callback(err);
+ callback = function () {};
+ }
+ else {
+ completed += 1;
+ if (completed >= arr.length) {
+ callback(null);
+ }
+ else {
+ if (sync) {
+ async.nextTick(iterate);
+ }
+ else {
+ iterate();
+ }
+ }
+ }
+ });
+ sync = false;
+ };
+ iterate();
+ };
+ async.forEachSeries = async.eachSeries;
+
+ async.eachLimit = function (arr, limit, iterator, callback) {
+ var fn = _eachLimit(limit);
+ fn.apply(null, [arr, iterator, callback]);
+ };
+ async.forEachLimit = async.eachLimit;
+
+ var _eachLimit = function (limit) {
+
+ return function (arr, iterator, callback) {
+ callback = callback || function () {};
+ if (!arr.length || limit <= 0) {
+ return callback();
+ }
+ var completed = 0;
+ var started = 0;
+ var running = 0;
+
+ (function replenish () {
+ if (completed >= arr.length) {
+ return callback();
+ }
+
+ while (running < limit && started < arr.length) {
+ started += 1;
+ running += 1;
+ iterator(arr[started - 1], function (err) {
+ if (err) {
+ callback(err);
+ callback = function () {};
+ }
+ else {
+ completed += 1;
+ running -= 1;
+ if (completed >= arr.length) {
+ callback();
+ }
+ else {
+ replenish();
+ }
+ }
+ });
+ }
+ })();
+ };
+ };
+
+
+ var doParallel = function (fn) {
+ return function () {
+ var args = Array.prototype.slice.call(arguments);
+ return fn.apply(null, [async.each].concat(args));
+ };
+ };
+ var doParallelLimit = function(limit, fn) {
+ return function () {
+ var args = Array.prototype.slice.call(arguments);
+ return fn.apply(null, [_eachLimit(limit)].concat(args));
+ };
+ };
+ var doSeries = function (fn) {
+ return function () {
+ var args = Array.prototype.slice.call(arguments);
+ return fn.apply(null, [async.eachSeries].concat(args));
+ };
+ };
+
+
+ var _asyncMap = function (eachfn, arr, iterator, callback) {
+ var results = [];
+ arr = _map(arr, function (x, i) {
+ return {index: i, value: x};
+ });
+ eachfn(arr, function (x, callback) {
+ iterator(x.value, function (err, v) {
+ results[x.index] = v;
+ callback(err);
+ });
+ }, function (err) {
+ callback(err, results);
+ });
+ };
+ async.map = doParallel(_asyncMap);
+ async.mapSeries = doSeries(_asyncMap);
+ async.mapLimit = function (arr, limit, iterator, callback) {
+ return _mapLimit(limit)(arr, iterator, callback);
+ };
+
+ var _mapLimit = function(limit) {
+ return doParallelLimit(limit, _asyncMap);
+ };
+
+ // reduce only has a series version, as doing reduce in parallel won't
+ // work in many situations.
+ async.reduce = function (arr, memo, iterator, callback) {
+ async.eachSeries(arr, function (x, callback) {
+ iterator(memo, x, function (err, v) {
+ memo = v;
+ callback(err);
+ });
+ }, function (err) {
+ callback(err, memo);
+ });
+ };
+ // inject alias
+ async.inject = async.reduce;
+ // foldl alias
+ async.foldl = async.reduce;
+
+ async.reduceRight = function (arr, memo, iterator, callback) {
+ var reversed = _map(arr, function (x) {
+ return x;
+ }).reverse();
+ async.reduce(reversed, memo, iterator, callback);
+ };
+ // foldr alias
+ async.foldr = async.reduceRight;
+
+ var _filter = function (eachfn, arr, iterator, callback) {
+ var results = [];
+ arr = _map(arr, function (x, i) {
+ return {index: i, value: x};
+ });
+ eachfn(arr, function (x, callback) {
+ iterator(x.value, function (v) {
+ if (v) {
+ results.push(x);
+ }
+ callback();
+ });
+ }, function (err) {
+ callback(_map(results.sort(function (a, b) {
+ return a.index - b.index;
+ }), function (x) {
+ return x.value;
+ }));
+ });
+ };
+ async.filter = doParallel(_filter);
+ async.filterSeries = doSeries(_filter);
+ // select alias
+ async.select = async.filter;
+ async.selectSeries = async.filterSeries;
+
+ var _reject = function (eachfn, arr, iterator, callback) {
+ var results = [];
+ arr = _map(arr, function (x, i) {
+ return {index: i, value: x};
+ });
+ eachfn(arr, function (x, callback) {
+ iterator(x.value, function (v) {
+ if (!v) {
+ results.push(x);
+ }
+ callback();
+ });
+ }, function (err) {
+ callback(_map(results.sort(function (a, b) {
+ return a.index - b.index;
+ }), function (x) {
+ return x.value;
+ }));
+ });
+ };
+ async.reject = doParallel(_reject);
+ async.rejectSeries = doSeries(_reject);
+
+ var _detect = function (eachfn, arr, iterator, main_callback) {
+ eachfn(arr, function (x, callback) {
+ iterator(x, function (result) {
+ if (result) {
+ main_callback(x);
+ main_callback = function () {};
+ }
+ else {
+ callback();
+ }
+ });
+ }, function (err) {
+ main_callback();
+ });
+ };
+ async.detect = doParallel(_detect);
+ async.detectSeries = doSeries(_detect);
+
+ async.some = function (arr, iterator, main_callback) {
+ async.each(arr, function (x, callback) {
+ iterator(x, function (v) {
+ if (v) {
+ main_callback(true);
+ main_callback = function () {};
+ }
+ callback();
+ });
+ }, function (err) {
+ main_callback(false);
+ });
+ };
+ // any alias
+ async.any = async.some;
+
+ async.every = function (arr, iterator, main_callback) {
+ async.each(arr, function (x, callback) {
+ iterator(x, function (v) {
+ if (!v) {
+ main_callback(false);
+ main_callback = function () {};
+ }
+ callback();
+ });
+ }, function (err) {
+ main_callback(true);
+ });
+ };
+ // all alias
+ async.all = async.every;
+
+ async.sortBy = function (arr, iterator, callback) {
+ async.map(arr, function (x, callback) {
+ iterator(x, function (err, criteria) {
+ if (err) {
+ callback(err);
+ }
+ else {
+ callback(null, {value: x, criteria: criteria});
+ }
+ });
+ }, function (err, results) {
+ if (err) {
+ return callback(err);
+ }
+ else {
+ var fn = function (left, right) {
+ var a = left.criteria, b = right.criteria;
+ return a < b ? -1 : a > b ? 1 : 0;
+ };
+ callback(null, _map(results.sort(fn), function (x) {
+ return x.value;
+ }));
+ }
+ });
+ };
+
+ async.auto = function (tasks, callback) {
+ callback = callback || function () {};
+ var keys = _keys(tasks);
+ if (!keys.length) {
+ return callback(null);
+ }
+
+ var results = {};
+
+ var listeners = [];
+ var addListener = function (fn) {
+ listeners.unshift(fn);
+ };
+ var removeListener = function (fn) {
+ for (var i = 0; i < listeners.length; i += 1) {
+ if (listeners[i] === fn) {
+ listeners.splice(i, 1);
+ return;
+ }
+ }
+ };
+ var taskComplete = function () {
+ _each(listeners.slice(0), function (fn) {
+ fn();
+ });
+ };
+
+ addListener(function () {
+ if (_keys(results).length === keys.length) {
+ callback(null, results);
+ callback = function () {};
+ }
+ });
+
+ _each(keys, function (k) {
+ var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k];
+ var taskCallback = function (err) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ if (args.length <= 1) {
+ args = args[0];
+ }
+ if (err) {
+ var safeResults = {};
+ _each(_keys(results), function(rkey) {
+ safeResults[rkey] = results[rkey];
+ });
+ safeResults[k] = args;
+ callback(err, safeResults);
+ // stop subsequent errors hitting callback multiple times
+ callback = function () {};
+ }
+ else {
+ results[k] = args;
+ async.nextTick(taskComplete);
+ }
+ };
+ var requires = task.slice(0, Math.abs(task.length - 1)) || [];
+ var ready = function () {
+ return _reduce(requires, function (a, x) {
+ return (a && results.hasOwnProperty(x));
+ }, true) && !results.hasOwnProperty(k);
+ };
+ if (ready()) {
+ task[task.length - 1](taskCallback, results);
+ }
+ else {
+ var listener = function () {
+ if (ready()) {
+ removeListener(listener);
+ task[task.length - 1](taskCallback, results);
+ }
+ };
+ addListener(listener);
+ }
+ });
+ };
+
+ async.waterfall = function (tasks, callback) {
+ callback = callback || function () {};
+ if (!tasks.length) {
+ return callback();
+ }
+ var wrapIterator = function (iterator) {
+ return function (err) {
+ if (err) {
+ callback.apply(null, arguments);
+ callback = function () {};
+ }
+ else {
+ var args = Array.prototype.slice.call(arguments, 1);
+ var next = iterator.next();
+ if (next) {
+ args.push(wrapIterator(next));
+ }
+ else {
+ args.push(callback);
+ }
+ async.nextTick(function () {
+ iterator.apply(null, args);
+ });
+ }
+ };
+ };
+ wrapIterator(async.iterator(tasks))();
+ };
+
+ var _parallel = function(eachfn, tasks, callback) {
+ callback = callback || function () {};
+ if (tasks.constructor === Array) {
+ eachfn.map(tasks, function (fn, callback) {
+ if (fn) {
+ fn(function (err) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ if (args.length <= 1) {
+ args = args[0];
+ }
+ callback.call(null, err, args);
+ });
+ }
+ }, callback);
+ }
+ else {
+ var results = {};
+ eachfn.each(_keys(tasks), function (k, callback) {
+ tasks[k](function (err) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ if (args.length <= 1) {
+ args = args[0];
+ }
+ results[k] = args;
+ callback(err);
+ });
+ }, function (err) {
+ callback(err, results);
+ });
+ }
+ };
+
+ async.parallel = function (tasks, callback) {
+ _parallel({ map: async.map, each: async.each }, tasks, callback);
+ };
+
+ async.parallelLimit = function(tasks, limit, callback) {
+ _parallel({ map: _mapLimit(limit), each: _eachLimit(limit) }, tasks, callback);
+ };
+
+ async.series = function (tasks, callback) {
+ callback = callback || function () {};
+ if (tasks.constructor === Array) {
+ async.mapSeries(tasks, function (fn, callback) {
+ if (fn) {
+ fn(function (err) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ if (args.length <= 1) {
+ args = args[0];
+ }
+ callback.call(null, err, args);
+ });
+ }
+ }, callback);
+ }
+ else {
+ var results = {};
+ async.eachSeries(_keys(tasks), function (k, callback) {
+ tasks[k](function (err) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ if (args.length <= 1) {
+ args = args[0];
+ }
+ results[k] = args;
+ callback(err);
+ });
+ }, function (err) {
+ callback(err, results);
+ });
+ }
+ };
+
+ async.iterator = function (tasks) {
+ var makeCallback = function (index) {
+ var fn = function () {
+ if (tasks.length) {
+ tasks[index].apply(null, arguments);
+ }
+ return fn.next();
+ };
+ fn.next = function () {
+ return (index < tasks.length - 1) ? makeCallback(index + 1): null;
+ };
+ return fn;
+ };
+ return makeCallback(0);
+ };
+
+ async.apply = function (fn) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ return function () {
+ return fn.apply(
+ null, args.concat(Array.prototype.slice.call(arguments))
+ );
+ };
+ };
+
+ var _concat = function (eachfn, arr, fn, callback) {
+ var r = [];
+ eachfn(arr, function (x, cb) {
+ fn(x, function (err, y) {
+ r = r.concat(y || []);
+ cb(err);
+ });
+ }, function (err) {
+ callback(err, r);
+ });
+ };
+ async.concat = doParallel(_concat);
+ async.concatSeries = doSeries(_concat);
+
+ async.whilst = function (test, iterator, callback) {
+ if (test()) {
+ var sync = true;
+ iterator(function (err) {
+ if (err) {
+ return callback(err);
+ }
+ if (sync) {
+ async.nextTick(function () {
+ async.whilst(test, iterator, callback);
+ });
+ }
+ else {
+ async.whilst(test, iterator, callback);
+ }
+ });
+ sync = false;
+ }
+ else {
+ callback();
+ }
+ };
+
+ async.doWhilst = function (iterator, test, callback) {
+ var sync = true;
+ iterator(function (err) {
+ if (err) {
+ return callback(err);
+ }
+ if (test()) {
+ if (sync) {
+ async.nextTick(function () {
+ async.doWhilst(iterator, test, callback);
+ });
+ }
+ else {
+ async.doWhilst(iterator, test, callback);
+ }
+ }
+ else {
+ callback();
+ }
+ });
+ sync = false;
+ };
+
+ async.until = function (test, iterator, callback) {
+ if (!test()) {
+ var sync = true;
+ iterator(function (err) {
+ if (err) {
+ return callback(err);
+ }
+ if (sync) {
+ async.nextTick(function () {
+ async.until(test, iterator, callback);
+ });
+ }
+ else {
+ async.until(test, iterator, callback);
+ }
+ });
+ sync = false;
+ }
+ else {
+ callback();
+ }
+ };
+
+ async.doUntil = function (iterator, test, callback) {
+ var sync = true;
+ iterator(function (err) {
+ if (err) {
+ return callback(err);
+ }
+ if (!test()) {
+ if (sync) {
+ async.nextTick(function () {
+ async.doUntil(iterator, test, callback);
+ });
+ }
+ else {
+ async.doUntil(iterator, test, callback);
+ }
+ }
+ else {
+ callback();
+ }
+ });
+ sync = false;
+ };
+
+ async.queue = function (worker, concurrency) {
+ if (concurrency === undefined) {
+ concurrency = 1;
+ }
+ function _insert(q, data, pos, callback) {
+ if(data.constructor !== Array) {
+ data = [data];
+ }
+ _each(data, function(task) {
+ var item = {
+ data: task,
+ callback: typeof callback === 'function' ? callback : null
+ };
+
+ if (pos) {
+ q.tasks.unshift(item);
+ } else {
+ q.tasks.push(item);
+ }
+
+ if (q.saturated && q.tasks.length === concurrency) {
+ q.saturated();
+ }
+ async.nextTick(q.process);
+ });
+ }
+
+ var workers = 0;
+ var q = {
+ tasks: [],
+ concurrency: concurrency,
+ saturated: null,
+ empty: null,
+ drain: null,
+ push: function (data, callback) {
+ _insert(q, data, false, callback);
+ },
+ unshift: function (data, callback) {
+ _insert(q, data, true, callback);
+ },
+ process: function () {
+ if (workers < q.concurrency && q.tasks.length) {
+ var task = q.tasks.shift();
+ if (q.empty && q.tasks.length === 0) {
+ q.empty();
+ }
+ workers += 1;
+ var sync = true;
+ var next = function () {
+ workers -= 1;
+ if (task.callback) {
+ task.callback.apply(task, arguments);
+ }
+ if (q.drain && q.tasks.length + workers === 0) {
+ q.drain();
+ }
+ q.process();
+ };
+ var cb = only_once(function () {
+ var cbArgs = arguments;
+
+ if (sync) {
+ async.nextTick(function () {
+ next.apply(null, cbArgs);
+ });
+ } else {
+ next.apply(null, arguments);
+ }
+ });
+ worker(task.data, cb);
+ sync = false;
+ }
+ },
+ length: function () {
+ return q.tasks.length;
+ },
+ running: function () {
+ return workers;
+ }
+ };
+ return q;
+ };
+
+ async.cargo = function (worker, payload) {
+ var working = false,
+ tasks = [];
+
+ var cargo = {
+ tasks: tasks,
+ payload: payload,
+ saturated: null,
+ empty: null,
+ drain: null,
+ push: function (data, callback) {
+ if(data.constructor !== Array) {
+ data = [data];
+ }
+ _each(data, function(task) {
+ tasks.push({
+ data: task,
+ callback: typeof callback === 'function' ? callback : null
+ });
+ if (cargo.saturated && tasks.length === payload) {
+ cargo.saturated();
+ }
+ });
+ async.nextTick(cargo.process);
+ },
+ process: function process() {
+ if (working) return;
+ if (tasks.length === 0) {
+ if(cargo.drain) cargo.drain();
+ return;
+ }
+
+ var ts = typeof payload === 'number'
+ ? tasks.splice(0, payload)
+ : tasks.splice(0);
+
+ var ds = _map(ts, function (task) {
+ return task.data;
+ });
+
+ if(cargo.empty) cargo.empty();
+ working = true;
+ worker(ds, function () {
+ working = false;
+
+ var args = arguments;
+ _each(ts, function (data) {
+ if (data.callback) {
+ data.callback.apply(null, args);
+ }
+ });
+
+ process();
+ });
+ },
+ length: function () {
+ return tasks.length;
+ },
+ running: function () {
+ return working;
+ }
+ };
+ return cargo;
+ };
+
+ var _console_fn = function (name) {
+ return function (fn) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ fn.apply(null, args.concat([function (err) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ if (typeof console !== 'undefined') {
+ if (err) {
+ if (console.error) {
+ console.error(err);
+ }
+ }
+ else if (console[name]) {
+ _each(args, function (x) {
+ console[name](x);
+ });
+ }
+ }
+ }]));
+ };
+ };
+ async.log = _console_fn('log');
+ async.dir = _console_fn('dir');
+ /*async.info = _console_fn('info');
+ async.warn = _console_fn('warn');
+ async.error = _console_fn('error');*/
+
+ async.memoize = function (fn, hasher) {
+ var memo = {};
+ var queues = {};
+ hasher = hasher || function (x) {
+ return x;
+ };
+ var memoized = function () {
+ var args = Array.prototype.slice.call(arguments);
+ var callback = args.pop();
+ var key = hasher.apply(null, args);
+ if (key in memo) {
+ callback.apply(null, memo[key]);
+ }
+ else if (key in queues) {
+ queues[key].push(callback);
+ }
+ else {
+ queues[key] = [callback];
+ fn.apply(null, args.concat([function () {
+ memo[key] = arguments;
+ var q = queues[key];
+ delete queues[key];
+ for (var i = 0, l = q.length; i < l; i++) {
+ q[i].apply(null, arguments);
+ }
+ }]));
+ }
+ };
+ memoized.memo = memo;
+ memoized.unmemoized = fn;
+ return memoized;
+ };
+
+ async.unmemoize = function (fn) {
+ return function () {
+ return (fn.unmemoized || fn).apply(null, arguments);
+ };
+ };
+
+ async.times = function (count, iterator, callback) {
+ var counter = [];
+ for (var i = 0; i < count; i++) {
+ counter.push(i);
+ }
+ return async.map(counter, iterator, callback);
+ };
+
+ async.timesSeries = function (count, iterator, callback) {
+ var counter = [];
+ for (var i = 0; i < count; i++) {
+ counter.push(i);
+ }
+ return async.mapSeries(counter, iterator, callback);
+ };
+
+ async.compose = function (/* functions... */) {
+ var fns = Array.prototype.reverse.call(arguments);
+ return function () {
+ var that = this;
+ var args = Array.prototype.slice.call(arguments);
+ var callback = args.pop();
+ async.reduce(fns, args, function (newargs, fn, cb) {
+ fn.apply(that, newargs.concat([function () {
+ var err = arguments[0];
+ var nextargs = Array.prototype.slice.call(arguments, 1);
+ cb(err, nextargs);
+ }]))
+ },
+ function (err, results) {
+ callback.apply(that, [err].concat(results));
+ });
+ };
+ };
+
+ async.applyEach = function (fns /*args...*/) {
+ var go = function () {
+ var that = this;
+ var args = Array.prototype.slice.call(arguments);
+ var callback = args.pop();
+ return async.each(fns, function (fn, cb) {
+ fn.apply(that, args.concat([cb]));
+ },
+ callback);
+ };
+ if (arguments.length > 1) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ return go.apply(this, args);
+ }
+ else {
+ return go;
+ }
+ };
+
+ // AMD / RequireJS
+ if (typeof define !== 'undefined' && define.amd) {
+ define([], function () {
+ return async;
+ });
+ }
+ // Node.js
+ else if (typeof module !== 'undefined' && module.exports) {
+ module.exports = async;
+ }
+ // included directly via <script> tag
+ else {
+ root.async = async;
+ }
+
+}());
+
+
+ return module;
+});
View
42 jam/async/package.json
@@ -0,0 +1,42 @@
+{
+ "name": "async",
+ "description": "Higher-order functions and common patterns for asynchronous code",
+ "main": "./lib/async.js",
+ "author": {
+ "name": "Caolan McMahon"
+ },
+ "version": "0.2.6",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/caolan/async.git"
+ },
+ "bugs": {
+ "url": "http://github.com/caolan/async/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://github.com/caolan/async/raw/master/LICENSE"
+ }
+ ],
+ "devDependencies": {
+ "nodeunit": ">0.0.0",
+ "uglify-js": "1.2.x",
+ "nodelint": ">0.0.0"
+ },
+ "jam": {
+ "main": "lib/async.js",
+ "include": [
+ "lib/async.js",
+ "README.md",
+ "LICENSE"
+ ]
+ },
+ "scripts": {
+ "test": "nodeunit test/test-async.js"
+ },
+ "readme": "# Async.js\n\nAsync is a utility module which provides straight-forward, powerful functions\nfor working with asynchronous JavaScript. Although originally designed for\nuse with [node.js](http://nodejs.org), it can also be used directly in the\nbrowser.\n\nAsync provides around 20 functions that include the usual 'functional'\nsuspects (map, reduce, filter, each…) as well as some common patterns\nfor asynchronous control flow (parallel, series, waterfall…). All these\nfunctions assume you follow the node.js convention of providing a single\ncallback as the last argument of your async function.\n\n\n## Quick Examples\n\n```javascript\nasync.map(['file1','file2','file3'], fs.stat, function(err, results){\n // results is now an array of stats for each file\n});\n\nasync.filter(['file1','file2','file3'], path.exists, function(results){\n // results now equals an array of the existing files\n});\n\nasync.parallel([\n function(){ ... },\n function(){ ... }\n], callback);\n\nasync.series([\n function(){ ... },\n function(){ ... }\n]);\n```\n\nThere are many more functions available so take a look at the docs below for a\nfull list. This module aims to be comprehensive, so if you feel anything is\nmissing please create a GitHub issue for it.\n\n\n## Download\n\nReleases are available for download from\n[GitHub](http://github.com/caolan/async/downloads).\nAlternatively, you can install using Node Package Manager (npm):\n\n npm install async\n\n\n__Development:__ [async.js](https://github.com/caolan/async/raw/master/lib/async.js) - 17.5kb Uncompressed\n\n__Production:__ [async.min.js](https://github.com/caolan/async/raw/master/dist/async.min.js) - 1.7kb Packed and Gzipped\n\n\n## In the Browser\n\nSo far its been tested in IE6, IE7, IE8, FF3.6 and Chrome 5. Usage:\n\n```html\n<script type=\"text/javascript\" src=\"async.js\"></script>\n<script type=\"text/javascript\">\n\n async.map(data, asyncProcess, function(err, results){\n alert(results);\n });\n\n</script>\n```\n\n## Documentation\n\n### Collections\n\n* [each](#each)\n* [map](#map)\n* [filter](#filter)\n* [reject](#reject)\n* [reduce](#reduce)\n* [detect](#detect)\n* [sortBy](#sortBy)\n* [some](#some)\n* [every](#every)\n* [concat](#concat)\n\n### Control Flow\n\n* [series](#series)\n* [parallel](#parallel)\n* [whilst](#whilst)\n* [doWhilst](#doWhilst)\n* [until](#until)\n* [doUntil](#doUntil)\n* [waterfall](#waterfall)\n* [compose](#compose)\n* [applyEach](#applyEach)\n* [queue](#queue)\n* [cargo](#cargo)\n* [auto](#auto)\n* [iterator](#iterator)\n* [apply](#apply)\n* [nextTick](#nextTick)\n* [times](#times)\n* [timesSeries](#timesSeries)\n\n### Utils\n\n* [memoize](#memoize)\n* [unmemoize](#unmemoize)\n* [log](#log)\n* [dir](#dir)\n* [noConflict](#noConflict)\n\n\n## Collections\n\n<a name=\"forEach\" />\n<a name=\"each\" />\n### each(arr, iterator, callback)\n\nApplies an iterator function to each item in an array, in parallel.\nThe iterator is called with an item from the list and a callback for when it\nhas finished. If the iterator passes an error to this callback, the main\ncallback for the each function is immediately called with the error.\n\nNote, that since this function applies the iterator to each item in parallel\nthere is no guarantee that the iterator functions will complete in order.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err) which must be called once it has \n completed. If no error has occured, the callback should be run without \n arguments or with an explicit null argument.\n* callback(err) - A callback which is called after all the iterator functions\n have finished, or an error has occurred.\n\n__Example__\n\n```js\n// assuming openFiles is an array of file names and saveFile is a function\n// to save the modified contents of that file:\n\nasync.each(openFiles, saveFile, function(err){\n // if any of the saves produced an error, err would equal that error\n});\n```\n\n---------------------------------------\n\n<a name=\"forEachSeries\" />\n<a name=\"eachSeries\" />\n### eachSeries(arr, iterator, callback)\n\nThe same as each only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. This means the iterator functions will complete in order.\n\n\n---------------------------------------\n\n<a name=\"forEachLimit\" />\n<a name=\"eachLimit\" />\n### eachLimit(arr, limit, iterator, callback)\n\nThe same as each only no more than \"limit\" iterators will be simultaneously \nrunning at any time.\n\nNote that the items are not processed in batches, so there is no guarantee that\n the first \"limit\" iterator functions will complete before any others are \nstarted.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* limit - The maximum number of iterators to run at any time.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err) which must be called once it has \n completed. If no error has occured, the callback should be run without \n arguments or with an explicit null argument.\n* callback(err) - A callback which is called after all the iterator functions\n have finished, or an error has occurred.\n\n__Example__\n\n```js\n// Assume documents is an array of JSON objects and requestApi is a\n// function that interacts with a rate-limited REST api.\n\nasync.eachLimit(documents, 20, requestApi, function(err){\n // if any of the saves produced an error, err would equal that error\n});\n```\n\n---------------------------------------\n\n<a name=\"map\" />\n### map(arr, iterator, callback)\n\nProduces a new array of values by mapping each value in the given array through\nthe iterator function. The iterator is called with an item from the array and a\ncallback for when it has finished processing. The callback takes 2 arguments, \nan error and the transformed item from the array. If the iterator passes an\nerror to this callback, the main callback for the map function is immediately\ncalled with the error.\n\nNote, that since this function applies the iterator to each item in parallel\nthere is no guarantee that the iterator functions will complete in order, however\nthe results array will be in the same order as the original array.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, transformed) which must be called once \n it has completed with an error (which can be null) and a transformed item.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is an array of the\n transformed items from the original array.\n\n__Example__\n\n```js\nasync.map(['file1','file2','file3'], fs.stat, function(err, results){\n // results is now an array of stats for each file\n});\n```\n\n---------------------------------------\n\n<a name=\"mapSeries\" />\n### mapSeries(arr, iterator, callback)\n\nThe same as map only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. The results array will be in the same order as the original.\n\n\n---------------------------------------\n\n<a name=\"mapLimit\" />\n### mapLimit(arr, limit, iterator, callback)\n\nThe same as map only no more than \"limit\" iterators will be simultaneously \nrunning at any time.\n\nNote that the items are not processed in batches, so there is no guarantee that\n the first \"limit\" iterator functions will complete before any others are \nstarted.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* limit - The maximum number of iterators to run at any time.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, transformed) which must be called once \n it has completed with an error (which can be null) and a transformed item.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is an array of the\n transformed items from the original array.\n\n__Example__\n\n```js\nasync.map(['file1','file2','file3'], 1, fs.stat, function(err, results){\n // results is now an array of stats for each file\n});\n```\n\n---------------------------------------\n\n<a name=\"filter\" />\n### filter(arr, iterator, callback)\n\n__Alias:__ select\n\nReturns a new array of all the values which pass an async truth test.\n_The callback for each iterator call only accepts a single argument of true or\nfalse, it does not accept an error argument first!_ This is in-line with the\nway node libraries work with truth tests like path.exists. This operation is\nperformed in parallel, but the results array will be in the same order as the\noriginal.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(results) - A callback which is called after all the iterator\n functions have finished.\n\n__Example__\n\n```js\nasync.filter(['file1','file2','file3'], path.exists, function(results){\n // results now equals an array of the existing files\n});\n```\n\n---------------------------------------\n\n<a name=\"filterSeries\" />\n### filterSeries(arr, iterator, callback)\n\n__alias:__ selectSeries\n\nThe same as filter only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. The results array will be in the same order as the original.\n\n---------------------------------------\n\n<a name=\"reject\" />\n### reject(arr, iterator, callback)\n\nThe opposite of filter. Removes values that pass an async truth test.\n\n---------------------------------------\n\n<a name=\"rejectSeries\" />\n### rejectSeries(arr, iterator, callback)\n\nThe same as reject, only the iterator is applied to each item in the array\nin series.\n\n\n---------------------------------------\n\n<a name=\"reduce\" />\n### reduce(arr, memo, iterator, callback)\n\n__aliases:__ inject, foldl\n\nReduces a list of values into a single value using an async iterator to return\neach successive step. Memo is the initial state of the reduction. This\nfunction only operates in series. For performance reasons, it may make sense to\nsplit a call to this function into a parallel map, then use the normal\nArray.prototype.reduce on the results. This function is for situations where\neach step in the reduction needs to be async, if you can get the data before\nreducing it then its probably a good idea to do so.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* memo - The initial state of the reduction.\n* iterator(memo, item, callback) - A function applied to each item in the\n array to produce the next step in the reduction. The iterator is passed a\n callback(err, reduction) which accepts an optional error as its first \n argument, and the state of the reduction as the second. If an error is \n passed to the callback, the reduction is stopped and the main callback is \n immediately called with the error.\n* callback(err, result) - A callback which is called after all the iterator\n functions have finished. Result is the reduced value.\n\n__Example__\n\n```js\nasync.reduce([1,2,3], 0, function(memo, item, callback){\n // pointless async:\n process.nextTick(function(){\n callback(null, memo + item)\n });\n}, function(err, result){\n // result is now equal to the last value of memo, which is 6\n});\n```\n\n---------------------------------------\n\n<a name=\"reduceRight\" />\n### reduceRight(arr, memo, iterator, callback)\n\n__Alias:__ foldr\n\nSame as reduce, only operates on the items in the array in reverse order.\n\n\n---------------------------------------\n\n<a name=\"detect\" />\n### detect(arr, iterator, callback)\n\nReturns the first value in a list that passes an async truth test. The\niterator is applied in parallel, meaning the first iterator to return true will\nfire the detect callback with that result. That means the result might not be\nthe first item in the original array (in terms of order) that passes the test.\n\nIf order within the original array is important then look at detectSeries.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(result) - A callback which is called as soon as any iterator returns\n true, or after all the iterator functions have finished. Result will be\n the first item in the array that passes the truth test (iterator) or the\n value undefined if none passed.\n\n__Example__\n\n```js\nasync.detect(['file1','file2','file3'], path.exists, function(result){\n // result now equals the first file in the list that exists\n});\n```\n\n---------------------------------------\n\n<a name=\"detectSeries\" />\n### detectSeries(arr, iterator, callback)\n\nThe same as detect, only the iterator is applied to each item in the array\nin series. This means the result is always the first in the original array (in\nterms of array order) that passes the truth test.\n\n\n---------------------------------------\n\n<a name=\"sortBy\" />\n### sortBy(arr, iterator, callback)\n\nSorts a list by the results of running each value through an async iterator.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, sortValue) which must be called once it\n has completed with an error (which can be null) and a value to use as the sort\n criteria.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is the items from\n the original array sorted by the values returned by the iterator calls.\n\n__Example__\n\n```js\nasync.sortBy(['file1','file2','file3'], function(file, callback){\n fs.stat(file, function(err, stats){\n callback(err, stats.mtime);\n });\n}, function(err, results){\n // results is now the original array of files sorted by\n // modified date\n});\n```\n\n---------------------------------------\n\n<a name=\"some\" />\n### some(arr, iterator, callback)\n\n__Alias:__ any\n\nReturns true if at least one element in the array satisfies an async test.\n_The callback for each iterator call only accepts a single argument of true or\nfalse, it does not accept an error argument first!_ This is in-line with the\nway node libraries work with truth tests like path.exists. Once any iterator\ncall returns true, the main callback is immediately called.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(result) - A callback which is called as soon as any iterator returns\n true, or after all the iterator functions have finished. Result will be\n either true or false depending on the values of the async tests.\n\n__Example__\n\n```js\nasync.some(['file1','file2','file3'], path.exists, function(result){\n // if result is true then at least one of the files exists\n});\n```\n\n---------------------------------------\n\n<a name=\"every\" />\n### every(arr, iterator, callback)\n\n__Alias:__ all\n\nReturns true if every element in the array satisfies an async test.\n_The callback for each iterator call only accepts a single argument of true or\nfalse, it does not accept an error argument first!_ This is in-line with the\nway node libraries work with truth tests like path.exists.\n\n__Arguments__\n\n* arr - An array to iterate over.\n* iterator(item, callback) - A truth test to apply to each item in the array.\n The iterator is passed a callback(truthValue) which must be called with a \n boolean argument once it has completed.\n* callback(result) - A callback which is called after all the iterator\n functions have finished. Result will be either true or false depending on\n the values of the async tests.\n\n__Example__\n\n```js\nasync.every(['file1','file2','file3'], path.exists, function(result){\n // if result is true then every file exists\n});\n```\n\n---------------------------------------\n\n<a name=\"concat\" />\n### concat(arr, iterator, callback)\n\nApplies an iterator to each item in a list, concatenating the results. Returns the\nconcatenated list. The iterators are called in parallel, and the results are\nconcatenated as they return. There is no guarantee that the results array will\nbe returned in the original order of the arguments passed to the iterator function.\n\n__Arguments__\n\n* arr - An array to iterate over\n* iterator(item, callback) - A function to apply to each item in the array.\n The iterator is passed a callback(err, results) which must be called once it \n has completed with an error (which can be null) and an array of results.\n* callback(err, results) - A callback which is called after all the iterator\n functions have finished, or an error has occurred. Results is an array containing\n the concatenated results of the iterator function.\n\n__Example__\n\n```js\nasync.concat(['dir1','dir2','dir3'], fs.readdir, function(err, files){\n // files is now a list of filenames that exist in the 3 directories\n});\n```\n\n---------------------------------------\n\n<a name=\"concatSeries\" />\n### concatSeries(arr, iterator, callback)\n\nSame as async.concat, but executes in series instead of parallel.\n\n\n## Control Flow\n\n<a name=\"series\" />\n### series(tasks, [callback])\n\nRun an array of functions in series, each one running once the previous\nfunction has completed. If any functions in the series pass an error to its\ncallback, no more functions are run and the callback for the series is\nimmediately called with the value of the error. Once the tasks have completed,\nthe results are passed to the final callback as an array.\n\nIt is also possible to use an object instead of an array. Each property will be\nrun as a function and the results will be passed to the final callback as an object\ninstead of an array. This can be a more readable way of handling results from\nasync.series.\n\n\n__Arguments__\n\n* tasks - An array or object containing functions to run, each function is passed\n a callback(err, result) it must call on completion with an error (which can\n be null) and an optional result value.\n* callback(err, results) - An optional callback to run once all the functions\n have completed. This function gets a results array (or object) containing all \n the result arguments passed to the task callbacks.\n\n__Example__\n\n```js\nasync.series([\n function(callback){\n // do some stuff ...\n callback(null, 'one');\n },\n function(callback){\n // do some more stuff ...\n callback(null, 'two');\n }\n],\n// optional callback\nfunction(err, results){\n // results is now equal to ['one', 'two']\n});\n\n\n// an example using an object instead of an array\nasync.series({\n one: function(callback){\n setTimeout(function(){\n callback(null, 1);\n }, 200);\n },\n two: function(callback){\n setTimeout(function(){\n callback(null, 2);\n }, 100);\n }\n},\nfunction(err, results) {\n // results is now equal to: {one: 1, two: 2}\n});\n```\n\n---------------------------------------\n\n<a name=\"parallel\" />\n### parallel(tasks, [callback])\n\nRun an array of functions in parallel, without waiting until the previous\nfunction has completed. If any of the functions pass an error to its\ncallback, the main callback is immediately called with the value of the error.\nOnce the tasks have completed, the results are passed to the final callback as an\narray.\n\nIt is also possible to use an object instead of an array. Each property will be\nrun as a function and the results will be passed to the final callback as an object\ninstead of an array. This can be a more readable way of handling results from\nasync.parallel.\n\n\n__Arguments__\n\n* tasks - An array or object containing functions to run, each function is passed \n a callback(err, result) it must call on completion with an error (which can\n be null) and an optional result value.\n* callback(err, results) - An optional callback to run once all the functions\n have completed. This function gets a results array (or object) containing all \n the result arguments passed to the task callbacks.\n\n__Example__\n\n```js\nasync.parallel([\n function(callback){\n setTimeout(function(){\n callback(null, 'one');\n }, 200);\n },\n function(callback){\n setTimeout(function(){\n callback(null, 'two');\n }, 100);\n }\n],\n// optional callback\nfunction(err, results){\n // the results array will equal ['one','two'] even though\n // the second function had a shorter timeout.\n});\n\n\n// an example using an object instead of an array\nasync.parallel({\n one: function(callback){\n setTimeout(function(){\n callback(null, 1);\n }, 200);\n },\n two: function(callback){\n setTimeout(function(){\n callback(null, 2);\n }, 100);\n }\n},\nfunction(err, results) {\n // results is now equals to: {one: 1, two: 2}\n});\n```\n\n---------------------------------------\n\n<a name=\"parallel\" />\n### parallelLimit(tasks, limit, [callback])\n\nThe same as parallel only the tasks are executed in parallel with a maximum of \"limit\" \ntasks executing at any time.\n\nNote that the tasks are not executed in batches, so there is no guarantee that \nthe first \"limit\" tasks will complete before any others are started.\n\n__Arguments__\n\n* tasks - An array or object containing functions to run, each function is passed \n a callback(err, result) it must call on completion with an error (which can\n be null) and an optional result value.\n* limit - The maximum number of tasks to run at any time.\n* callback(err, results) - An optional callback to run once all the functions\n have completed. This function gets a results array (or object) containing all \n the result arguments passed to the task callbacks.\n\n---------------------------------------\n\n<a name=\"whilst\" />\n### whilst(test, fn, callback)\n\nRepeatedly call fn, while test returns true. Calls the callback when stopped,\nor an error occurs.\n\n__Arguments__\n\n* test() - synchronous truth test to perform before each execution of fn.\n* fn(callback) - A function to call each time the test passes. The function is\n passed a callback(err) which must be called once it has completed with an \n optional error argument.\n* callback(err) - A callback which is called after the test fails and repeated\n execution of fn has stopped.\n\n__Example__\n\n```js\nvar count = 0;\n\nasync.whilst(\n function () { return count < 5; },\n function (callback) {\n count++;\n setTimeout(callback, 1000);\n },\n function (err) {\n // 5 seconds have passed\n }\n);\n```\n\n---------------------------------------\n\n<a name=\"doWhilst\" />\n### doWhilst(fn, test, callback)\n\nThe post check version of whilst. To reflect the difference in the order of operations `test` and `fn` arguments are switched. `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.\n\n---------------------------------------\n\n<a name=\"until\" />\n### until(test, fn, callback)\n\nRepeatedly call fn, until test returns true. Calls the callback when stopped,\nor an error occurs.\n\nThe inverse of async.whilst.\n\n---------------------------------------\n\n<a name=\"doUntil\" />\n### doUntil(fn, test, callback)\n\nLike doWhilst except the test is inverted. Note the argument ordering differs from `until`.\n\n\n---------------------------------------\n\n<a name=\"waterfall\" />\n### waterfall(tasks, [callback])\n\nRuns an array of functions in series, each passing their results to the next in\nthe array. However, if any of the functions pass an error to the callback, the\nnext function is not executed and the main callback is immediately called with\nthe error.\n\n__Arguments__\n\n* tasks - An array of functions to run, each function is passed a \n callback(err, result1, result2, ...) it must call on completion. The first\n argument is an error (which can be null) and any further arguments will be \n passed as arguments in order to the next task.\n* callback(err, [results]) - An optional callback to run once all the functions\n have completed. This will be passed the results of the last task's callback.\n\n\n\n__Example__\n\n```js\nasync.waterfall([\n function(callback){\n callback(null, 'one', 'two');\n },\n function(arg1, arg2, callback){\n callback(null, 'three');\n },\n function(arg1, callback){\n // arg1 now equals 'three'\n callback(null, 'done');\n }\n], function (err, result) {\n // result now equals 'done' \n});\n```\n\n---------------------------------------\n<a name=\"compose\" />\n### compose(fn1, fn2...)\n\nCreates a function which is a composition of the passed asynchronous\nfunctions. Each function consumes the return value of the function that\nfollows. Composing functions f(), g() and h() would produce the result of\nf(g(h())), only this version uses callbacks to obtain the return values.\n\nEach function is executed with the `this` binding of the composed function.\n\n__Arguments__\n\n* functions... - the asynchronous functions to compose\n\n\n__Example__\n\n```js\nfunction add1(n, callback) {\n setTimeout(function () {\n callback(null, n + 1);\n }, 10);\n}\n\nfunction mul3(n, callback) {\n setTimeout(function () {\n callback(null, n * 3);\n }, 10);\n}\n\nvar add1mul3 = async.compose(mul3, add1);\n\nadd1mul3(4, function (err, result) {\n // result now equals 15\n});\n```\n\n---------------------------------------\n<a name=\"applyEach\" />\n### applyEach(fns, args..., callback)\n\nApplies the provided arguments to each function in the array, calling the\ncallback after all functions have completed. If you only provide the first\nargument then it will return a function which lets you pass in the\narguments as if it were a single function call.\n\n__Arguments__\n\n* fns - the asynchronous functions to all call with the same arguments\n* args... - any number of separate arguments to pass to the function\n* callback - the final argument should be the callback, called when all\n functions have completed processing\n\n\n__Example__\n\n```js\nasync.applyEach([enableSearch, updateSchema], 'bucket', callback);\n\n// partial application example:\nasync.each(\n buckets,\n async.applyEach([enableSearch, updateSchema]),\n callback\n);\n```\n\n---------------------------------------\n\n<a name=\"queue\" />\n### queue(worker, concurrency)\n\nCreates a queue object with the specified concurrency. Tasks added to the\nqueue will be processed in parallel (up to the concurrency limit). If all\nworkers are in progress, the task is queued until one is available. Once\na worker has completed a task, the task's callback is called.\n\n__Arguments__\n\n* worker(task, callback) - An asynchronous function for processing a queued\n task, which must call its callback(err) argument when finished, with an \n optional error as an argument.\n* concurrency - An integer for determining how many worker functions should be\n run in parallel.\n\n__Queue objects__\n\nThe queue object returned by this function has the following properties and\nmethods:\n\n* length() - a function returning the number of items waiting to be processed.\n* concurrency - an integer for determining how many worker functions should be\n run in parallel. This property can be changed after a queue is created to\n alter the concurrency on-the-fly.\n* push(task, [callback]) - add a new task to the queue, the callback is called\n once the worker has finished processing the task.\n instead of a single task, an array of tasks can be submitted. the respective callback is used for every task in the list.\n* unshift(task, [callback]) - add a new task to the front of the queue.\n* saturated - a callback that is called when the queue length hits the concurrency and further tasks will be queued\n* empty - a callback that is called when the last item from the queue is given to a worker\n* drain - a callback that is called when the last item from the queue has returned from the worker\n\n__Example__\n\n```js\n// create a queue object with concurrency 2\n\nvar q = async.queue(function (task, callback) {\n console.log('hello ' + task.name);\n callback();\n}, 2);\n\n\n// assign a callback\nq.drain = function() {\n console.log('all items have been processed');\n}\n\n// add some items to the queue\n\nq.push({name: 'foo'}, function (err) {\n console.log('finished processing foo');\n});\nq.push({name: 'bar'}, function (err) {\n console.log('finished processing bar');\n});\n\n// add some items to the queue (batch-wise)\n\nq.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function (err) {\n console.log('finished processing bar');\n});\n\n// add some items to the front of the queue\n\nq.unshift({name: 'bar'}, function (err) {\n console.log('finished processing bar');\n});\n```\n\n---------------------------------------\n\n<a name=\"cargo\" />\n### cargo(worker, [payload])\n\nCreates a cargo object with the specified payload. Tasks added to the\ncargo will be processed altogether (up to the payload limit). If the\nworker is in progress, the task is queued until it is available. Once\nthe worker has completed some tasks, each callback of those tasks is called.\n\n__Arguments__\n\n* worker(tasks, callback) - An asynchronous function for processing queued\n tasks, which must call its callback(err) argument when finished, with an \n optional error as an argument.\n* payload - An optional integer for determining how many tasks should be\n process per round, default is unlimited.\n\n__Cargo objects__\n\nThe cargo object returned by this function has the following properties and\nmethods:\n\n* length() - a function returning the number of items waiting to be processed.\n* payload - an integer for determining how many tasks should be\n process per round. This property can be changed after a cargo is created to\n alter the payload on-the-fly.\n* push(task, [callback]) - add a new task to the queue, the callback is called\n once the worker has finished processing the task.\n instead of a single task, an array of tasks can be submitted. the respective callback is used for every task in the list.\n* saturated - a callback that is called when the queue length hits the concurrency and further tasks will be queued\n* empty - a callback that is called when the last item from the queue is given to a worker\n* drain - a callback that is called when the last item from the queue has returned from the worker\n\n__Example__\n\n```js\n// create a cargo object with payload 2\n\nvar cargo = async.cargo(function (task, callback) {\n console.log('hello ' + task.name);\n callback();\n}, 2);\n\n\n// add some items\n\ncargo.push({name: 'foo'}, function (err) {\n console.log('finished processing foo');\n});\ncargo.push({name: 'bar'}, function (err) {\n console.log('finished processing bar');\n});\ncargo.push({name: 'baz'}, function (err) {\n console.log('finished processing baz');\n});\n```\n\n---------------------------------------\n\n<a name=\"auto\" />\n### auto(tasks, [callback])\n\nDetermines the best order for running functions based on their requirements.\nEach function can optionally depend on other functions being completed first,\nand each function is run as soon as its requirements are satisfied. If any of\nthe functions pass an error to their callback, that function will not complete\n(so any other functions depending on it will not run) and the main callback\nwill be called immediately with the error. Functions also receive an object\ncontaining the results of functions which have completed so far.\n\nNote, all functions are called with a results object as a second argument, \nso it is unsafe to pass functions in the tasks object which cannot handle the\nextra argument. For example, this snippet of code:\n\n```js\nasync.auto({\n readData: async.apply(fs.readFile, 'data.txt', 'utf-8');\n}, callback);\n```\n\nwill have the effect of calling readFile with the results object as the last\nargument, which will fail:\n\n```js\nfs.readFile('data.txt', 'utf-8', cb, {});\n```\n\nInstead, wrap the call to readFile in a function which does not forward the \nresults object:\n\n```js\nasync.auto({\n readData: function(cb, results){\n fs.readFile('data.txt', 'utf-8', cb);\n }\n}, callback);\n```\n\n__Arguments__\n\n* tasks - An object literal containing named functions or an array of\n requirements, with the function itself the last item in the array. The key\n used for each function or array is used when specifying requirements. The \n function receives two arguments: (1) a callback(err, result) which must be \n called when finished, passing an error (which can be null) and the result of \n the function's execution, and (2) a results object, containing the results of\n the previously executed functions.\n* callback(err, results) - An optional callback which is called when all the\n tasks have been completed. The callback will receive an error as an argument\n if any tasks pass an error to their callback. Results will always be passed\n\tbut if an error occurred, no other tasks will be performed, and the results\n\tobject will only contain partial results.\n \n\n__Example__\n\n```js\nasync.auto({\n get_data: function(callback){\n // async code to get some data\n },\n make_folder: function(callback){\n // async code to create a directory to store a file in\n // this is run at the same time as getting the data\n },\n write_file: ['get_data', 'make_folder', function(callback){\n // once there is some data and the directory exists,\n // write the data to a file in the directory\n callback(null, filename);\n }],\n email_link: ['write_file', function(callback, results){\n // once the file is written let's email a link to it...\n // results.write_file contains the filename returned by write_file.\n }]\n});\n```\n\nThis is a fairly trivial example, but to do this using the basic parallel and\nseries functions would look like this:\n\n```js\nasync.parallel([\n function(callback){\n // async code to get some data\n },\n function(callback){\n // async code to create a directory to store a file in\n // this is run at the same time as getting the data\n }\n],\nfunction(err, results){\n async.series([\n function(callback){\n // once there is some data and the directory exists,\n // write the data to a file in the directory\n },\n function(callback){\n // once the file is written let's email a link to it...\n }\n ]);\n});\n```\n\nFor a complicated series of async tasks using the auto function makes adding\nnew tasks much easier and makes the code more readable.\n\n\n---------------------------------------\n\n<a name=\"iterator\" />\n### iterator(tasks)\n\nCreates an iterator function which calls the next function in the array,\nreturning a continuation to call the next one after that. Its also possible to\n'peek' the next iterator by doing iterator.next().\n\nThis function is used internally by the async module but can be useful when\nyou want to manually control the flow of functions in series.\n\n__Arguments__\n\n* tasks - An array of functions to run.\n\n__Example__\n\n```js\nvar iterator = async.iterator([\n function(){ sys.p('one'); },\n function(){ sys.p('two'); },\n function(){ sys.p('three'); }\n]);\n\nnode> var iterator2 = iterator();\n'one'\nnode> var iterator3 = iterator2();\n'two'\nnode> iterator3();\n'three'\nnode> var nextfn = iterator2.next();\nnode> nextfn();\n'three'\n```\n\n---------------------------------------\n\n<a name=\"apply\" />\n### apply(function, arguments..)\n\nCreates a continuation function with some arguments already applied, a useful\nshorthand when combined with other control flow functions. Any arguments\npassed to the returned function are added to the arguments originally passed\nto apply.\n\n__Arguments__\n\n* function - The function you want to eventually apply all arguments to.\n* arguments... - Any number of arguments to automatically apply when the\n continuation is called.\n\n__Example__\n\n```js\n// using apply\n\nasync.parallel([\n async.apply(fs.writeFile, 'testfile1', 'test1'),\n async.apply(fs.writeFile, 'testfile2', 'test2'),\n]);\n\n\n// the same process without using apply\n\nasync.parallel([\n function(callback){\n fs.writeFile('testfile1', 'test1', callback);\n },\n function(callback){\n fs.writeFile('testfile2', 'test2', callback);\n }\n]);\n```\n\nIt's possible to pass any number of additional arguments when calling the\ncontinuation:\n\n```js\nnode> var fn = async.apply(sys.puts, 'one');\nnode> fn('two', 'three');\none\ntwo\nthree\n```\n\n---------------------------------------\n\n<a name=\"nextTick\" />\n### nextTick(callback)\n\nCalls the callback on a later loop around the event loop. In node.js this just\ncalls process.nextTick, in the browser it falls back to setImmediate(callback)\nif available, otherwise setTimeout(callback, 0), which means other higher priority\nevents may precede the execution of the callback.\n\nThis is used internally for browser-compatibility purposes.\n\n__Arguments__\n\n* callback - The function to call on a later loop around the event loop.\n\n__Example__\n\n```js\nvar call_order = [];\nasync.nextTick(function(){\n call_order.push('two');\n // call_order now equals ['one','two']\n});\ncall_order.push('one')\n```\n\n<a name=\"times\" />\n### times(n, callback)\n\nCalls the callback n times and accumulates results in the same manner\nyou would use with async.map.\n\n__Arguments__\n\n* n - The number of times to run the function.\n* callback - The function to call n times.\n\n__Example__\n\n```js\n// Pretend this is some complicated async factory\nvar createUser = function(id, callback) {\n callback(null, {\n id: 'user' + id\n })\n}\n// generate 5 users\nasync.times(5, function(n, next){\n createUser(n, function(err, user) {\n next(err, user)\n })\n}, function(err, users) {\n // we should now have 5 users\n});\n```\n\n<a name=\"timesSeries\" />\n### timesSeries(n, callback)\n\nThe same as times only the iterator is applied to each item in the array in\nseries. The next iterator is only called once the current one has completed\nprocessing. The results array will be in the same order as the original.\n\n\n## Utils\n\n<a name=\"memoize\" />\n### memoize(fn, [hasher])\n\nCaches the results of an async function. When creating a hash to store function\nresults against, the callback is omitted from the hash and an optional hash\nfunction can be used.\n\nThe cache of results is exposed as the `memo` property of the function returned\nby `memoize`.\n\n__Arguments__\n\n* fn - the function you to proxy and cache results from.\n* hasher - an optional function for generating a custom hash for storing\n results, it has all the arguments applied to it apart from the callback, and\n must be synchronous.\n\n__Example__\n\n```js\nvar slow_fn = function (name, callback) {\n // do something\n callback(null, result);\n};\nvar fn = async.memoize(slow_fn);\n\n// fn can now be used as if it were slow_fn\nfn('some name', function () {\n // callback\n});\n```\n\n<a name=\"unmemoize\" />\n### unmemoize(fn)\n\nUndoes a memoized function, reverting it to the original, unmemoized\nform. Comes handy in tests.\n\n__Arguments__\n\n* fn - the memoized function\n\n<a name=\"log\" />\n### log(function, arguments)\n\nLogs the result of an async function to the console. Only works in node.js or\nin browsers that support console.log and console.error (such as FF and Chrome).\nIf multiple arguments are returned from the async function, console.log is\ncalled on each argument in order.\n\n__Arguments__\n\n* function - The function you want to eventually apply all arguments to.\n* arguments... - Any number of arguments to apply to the function.\n\n__Example__\n\n```js\nvar hello = function(name, callback){\n setTimeout(function(){\n callback(null, 'hello ' + name);\n }, 1000);\n};\n```\n```js\nnode> async.log(hello, 'world');\n'hello world'\n```\n\n---------------------------------------\n\n<a name=\"dir\" />\n### dir(function, arguments)\n\nLogs the result of an async function to the console using console.dir to\ndisplay the properties of the resulting object. Only works in node.js or\nin browsers that support console.dir and console.error (such as FF and Chrome).\nIf multiple arguments are returned from the async function, console.dir is\ncalled on each argument in order.\n\n__Arguments__\n\n* function - The function you want to eventually apply all arguments to.\n* arguments... - Any number of arguments to apply to the function.\n\n__Example__\n\n```js\nvar hello = function(name, callback){\n setTimeout(function(){\n callback(null, {hello: name});\n }, 1000);\n};\n```\n```js\nnode> async.dir(hello, 'world');\n{hello: 'world'}\n```\n\n---------------------------------------\n\n<a name=\"noConflict\" />\n### noConflict()\n\nChanges the value of async back to its original value, returning a reference to the\nasync object.\n",
+ "readmeFilename": "README.md",
+ "_id": "async@0.2.6",
+ "_from": "async@"
+}
View
88 jam/dref/lib/index.js
@@ -0,0 +1,88 @@
+define([], function(require) {
+
+ var __dirname = "dref/lib",
+ __filename = "dref/lib/index.js",
+ module = { exports: {} },
+ exports = module.exports;
+
+ /**
+ * finds references
+ */
+
+var _findValues = function(keyParts, target, create, index, values) {
+
+ if(!values) {
+ keyParts = (keyParts instanceof Array ? keyParts : keyParts.split(".")).filter(function(part) {
+ return !!part.length;
+ })
+ values = [];
+ index = 0;
+ }
+
+ var ct, j, kp, i = index, n = keyParts.length, pt = target;
+
+
+ for(;i < n; i++) {
+ kp = keyParts[i];
+ ct = pt[kp];
+
+ if(kp == '$') {
+ for(j = pt.length; j--;) {
+ _findValues(keyParts, pt[j], create, i + 1, values);
+ }
+ return values;
+ } else
+ if(!ct) {
+ if(!create) return values;
+ ct = pt[kp] = {};
+ }
+
+ pt = ct;
+ }
+
+ if(ct) {
+ values.push(ct);
+ } else {
+ values.push(pt);
+ }
+
+ return values;
+}
+
+
+/**
+ */
+
+var getValue = function(target, key) {
+ var values = _findValues(key, target);
+
+ return key.indexOf('.$.') == -1 ? values[0] : values;
+}
+
+/**
+ */
+
+var setValue = function(target, key, newValue) {
+ var keyParts = key.split("."),
+ keySet = keyParts.pop();
+
+ if(keySet == '$') {
+ keySet = keyParts.pop();
+ }
+
+ var values = _findValues(keyParts, target, true);
+
+
+ for(var i = values.length; i--;) {
+ values[i][keySet] = newValue;
+ }
+
+}
+
+
+exports.get = getValue;
+exports.set = setValue;
+
+
+ return module;
+});
View
23 jam/dref/package.json
@@ -0,0 +1,23 @@
+{
+ "author": {
+ "name": "Craig Condon"
+ },
+ "name": "dref",
+ "description": "deep object refs",
+ "version": "0.0.2",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/crcn/dref.js.git"
+ },
+ "main": "./lib/index.js",
+ "dependencies": {},
+ "devDependencies": {},
+ "readme": "### Features\n\n- Ability to deep reference an object\n- Ability to scan arrays, and return an array of values, e.g, `users.$.name`.\n\n\n### Usage\n\n```javascript\n\nvar dref = require(\"dref\");\n\nvar target = [\n\t{\n\t\tname: \"Craig\", \n\t\tlocation: {\n\t\t\tcity: \"minneapolis\"\n\t\t}\n\t},\n\t{\n\t\tname: \"Tim\", \n\t\tlocation: {\n\t\t\tcity: \"St. Paul\"\n\t\t}\n\t}\n];\n\n\nconsole.log(dref.get(target, '$.name')); //[\"Craig\", \"Tim\"]\nconsole.log(dref.get(target, '$.location.city')); //[\"Minneapolis\", \"St. Paul\"]\ndref.set(target, '$.name', \"BLAH\");\nconsole.log(dref.get(target, '$.name')); //[\"BLAH\", \"BLAH\"]\n```\n",
+ "readmeFilename": "README.md",
+ "_id": "dref@0.0.2",
+ "dist": {
+ "shasum": "abfb3c00c2c73c392da06ae5a7dc411292cce6a2"
+ },
+ "_from": "dref@",
+ "_resolved": "http://registry.npmjs.org/dref/-/dref-0.0.2.tgz"
+}
View
226 jam/events/index.js
@@ -0,0 +1,226 @@
+define([], function(require) {
+
+ var __dirname = "events",
+ __filename = "events/index.js",
+ module = { exports: {} },
+ exports = module.exports;
+
+ // Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var isArray = Array.isArray;
+
+function EventEmitter() { }
+exports.EventEmitter = EventEmitter;
+
+// By default EventEmitters will print a warning if more than
+// 10 listeners are added to it. This is a useful default which
+// helps finding memory leaks.
+//
+// Obviously not all Emitters should be limited to 10. This function allows
+// that to be increased. Set to zero for unlimited.
+var defaultMaxListeners = 10;
+EventEmitter.prototype.setMaxListeners = function(n) {
+ if (!this._events) this._events = {};
+ this._events.maxListeners = n;
+};
+
+
+EventEmitter.prototype.emit = function() {
+ var type = arguments[0];
+ // If there is no 'error' event listener then throw.
+ if (type === 'error') {
+ if (!this._events || !this._events.error ||
+ (isArray(this._events.error) && !this._events.error.length))
+ {
+ if (arguments[1] instanceof Error) {
+ throw arguments[1]; // Unhandled 'error' event
+ } else {
+ throw new Error("Uncaught, unspecified 'error' event.");
+ }
+ return false;
+ }
+ }
+
+ if (!this._events) return false;
+ var handler = this._events[type];
+ if (!handler) return false;
+
+ if (typeof handler == 'function') {
+ switch (arguments.length) {
+ // fast cases
+ case 1:
+ handler.call(this);
+ break;
+ case 2:
+ handler.call(this, arguments[1]);
+ break;
+ case 3:
+ handler.call(this, arguments[1], arguments[2]);
+ break;
+ // slower
+ default:
+ var l = arguments.length;
+ var args = new Array(l - 1);
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
+ handler.apply(this, args);
+ }
+ return true;
+
+ } else if (isArray(handler)) {
+ var l = arguments.length;
+ var args = new Array(l - 1);
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
+
+ var listeners = handler.slice();
+ for (var i = 0, l = listeners.length; i < l; i++) {
+ listeners[i].apply(this, args);
+ }
+ return true;
+
+ } else {
+ return false;
+ }
+};
+
+// EventEmitter is defined in src/node_events.cc
+// EventEmitter.prototype.emit() is also defined there.
+EventEmitter.prototype.addListener = function(type, listener) {
+ if ('function' !== typeof listener) {
+ throw new Error('addListener only takes instances of Function');
+ }
+
+ if (!this._events) this._events = {};
+
+ // To avoid recursion in the case that type == "newListeners"! Before
+ // adding it to the listeners, first emit "newListeners".
+ this.emit('newListener', type, listener);
+
+ if (!this._events[type]) {
+ // Optimize the case of one listener. Don't need the extra array object.
+ this._events[type] = listener;
+ } else if (isArray(this._events[type])) {
+
+ // If we've already got an array, just append.
+ this._events[type].push(listener);
+
+ // Check for listener leak
+ if (!this._events[type].warned) {
+ var m;
+ if (this._events.maxListeners !== undefined) {
+ m = this._events.maxListeners;
+ } else {
+ m = defaultMaxListeners;
+ }
+
+ if (m && m > 0 && this._events[type].length > m) {
+ this._events[type].warned = true;
+ console.error('(node) warning: possible EventEmitter memory ' +
+ 'leak detected. %d listeners added. ' +
+ 'Use emitter.setMaxListeners() to increase limit.',
+ this._events[type].length);
+ console.trace();
+ }
+ }
+ } else {
+ // Adding the second element, need to change to array.
+ this._events[type] = [this._events[type], listener];
+ }
+
+ return this;
+};
+
+EventEmitter.prototype.on = EventEmitter.prototype.addListener;
+
+EventEmitter.prototype.once = function(type, listener) {
+ if ('function' !== typeof listener) {
+ throw new Error('.once only takes instances of Function');
+ }
+
+ var self = this;
+ function g() {
+ self.removeListener(type, g);
+ listener.apply(this, arguments);
+ };
+
+ g.listener = listener;
+ self.on(type, g);
+
+ return this;
+};
+
+EventEmitter.prototype.removeListener = function(type, listener) {
+ if ('function' !== typeof listener) {
+ throw new Error('removeListener only takes instances of Function');
+ }
+
+ // does not use listeners(), so no side effect of creating _events[type]
+ if (!this._events || !this._events[type]) return this;
+
+ var list = this._events[type];
+
+ if (isArray(list)) {
+ var position = -1;
+ for (var i = 0, length = list.length; i < length; i++) {
+ if (list[i] === listener ||
+ (list[i].listener && list[i].listener === listener))
+ {
+ position = i;
+ break;
+ }
+ }
+
+ if (position < 0) return this;
+ list.splice(position, 1);
+ if (list.length == 0)
+ delete this._events[type];
+ } else if (list === listener ||
+ (list.listener && list.listener === listener))
+ {
+ delete this._events[type];
+ }
+
+ return this;
+};
+
+EventEmitter.prototype.removeAllListeners = function(type) {
+ if (arguments.length === 0) {
+ this._events = {};
+ return this;
+ }
+
+ // does not use listeners(), so no side effect of creating _events[type]
+ if (type && this._events && this._events[type]) this._events[type] = null;
+ return this;
+};
+
+EventEmitter.prototype.listeners = function(type) {
+ if (!this._events) this._events = {};
+ if (!this._events[type]) this._events[type] = [];
+ if (!isArray(this._events[type])) {
+ this._events[type] = [this._events[type]];
+ }
+ return this._events[type];
+};
+
+
+ return module;
+});
View
5 jam/events/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "events",
+ "main": "./index.js",
+ "description": ""
+}
View
193 jam/outcome/lib/index.js
@@ -0,0 +1,193 @@
+define(["events/index.js"], function(require) {
+
+ var __dirname = "outcome/lib",
+ __filename = "outcome/lib/index.js",
+ module = { exports: {} },
+ exports = module.exports;
+
+ var EventEmitter = require('events').EventEmitter,
+
+//used for dispatching unhandledError messages
+globalEmitter = new EventEmitter();
+
+var Chain = function(listeners) {
+
+ if(!listeners) listeners = { };
+
+ var runFn = function(event, callback, args) {
+ if(!!listeners[callback].emit) {
+ listeners[callback].emit.apply(listeners[callback], [event].concat(args));
+ } else {
+ listeners[callback].apply(this, args);
+ }
+ }
+
+ var runErr = function(args) {
+ runFn("error", "error", args);
+ }
+
+
+ var fn = function() {
+
+ var args = Array.apply(null, arguments), orgArgs = arguments;
+
+
+ //it might be useful to log ALL errors handled.
+ if(args[0]) {
+ globalEmitter.emit("handledError", args[0]);
+ }
+
+ if(listeners.callback) {
+ listeners.callback.apply(this, args);
+ }
+
+ if(listeners.handle) {
+ listeners.handle.apply(listeners, args);
+ } else {
+
+ var e = args.shift();
+
+ //on error
+ if(e) {
+ runErr.call(this, [e]);
+ } else
+
+ if(listeners.success) {
+ try {
+ runFn.call(this, "complete", "success", args);
+ } catch(e) {
+ runErr.call(this, [e]);
+ }
+ }
+
+ }
+
+ };
+
+ fn.listeners = listeners;
+
+ //DEPRECATED
+ fn.done = function(fn) {
+ return fn.callback(fn);
+ }
+
+ fn.handle = function(value) {
+ return _copy({ handle: value });
+ }
+
+ fn.vine = function() {
+ return fn.handle(function(resp) {
+ if(resp.errors) {
+ this.error(resp.errors);
+ } else {
+ this.success(resp.result);
+ }
+ });
+ }
+
+
+ fn.callback = function(value) {
+ return _copy({ callback: value });
+ }
+
+ fn.success = fn.s = function(value) {
+ return _copy({ success: value });
+ }
+
+ fn.error = fn.e = function(value) {
+ return _copy({ error: value });
+ }
+
+ fn.throwError = function(err) {
+ if(!globalEmitter.emit('unhandledError', err) && !listeners.callback) throw err;
+ }
+
+
+ //error does not exist? set the default which throws one
+ if(!listeners.error) {
+
+ listeners.error = function(err) {
+
+ //no error callback? check of unhandled error is present, or throw
+ // if(!globalEmitter.emit('unhandledError', err) && !listeners.callback) throw err;
+ fn.throwError(err);
+ }
+
+ }
+
+
+
+ function _copy(childListeners) {
+
+ //copy these listeners to a new chain
+ for(var type in listeners) {
+
+ if(childListeners[type]) continue;
+
+ childListeners[type] = listeners[type];
+
+ }
+
+ return Chain(childListeners);
+
+ }
+
+ return fn;
+}
+
+
+module.exports = function(listeners) {
+ return Chain(listeners);
+}
+
+
+module.exports.on = function() {
+ globalEmitter.on.apply(globalEmitter, arguments);
+}
+
+module.exports.once = function() {
+ globalEmitter.once.apply(globalEmitter, arguments);
+}
+
+//bleh this could be better. Need to copy the chain functions to the module.exports var
+var chain = Chain();
+
+//copy the obj keys to module.exports
+Object.keys(chain).forEach(function(prop) {
+
+ //on call of error, success, callback - make a new chain
+ module.exports[prop] = function() {
+
+ var child = Chain();
+
+ return child[prop].apply(child, arguments);
+ }
+
+});
+
+module.exports.logAllErrors = function(v) {
+ if(v) {
+ globalEmitter.on("handledError", onGlobalError);
+ } else {
+ globalEmitter.removeListener("handledError", onGlobalError);
+ }
+}
+
+
+function onGlobalError(e) {
+ console.error(e.stack);
+}
+
+
+//running online?
+if(typeof window != 'undefined') {
+ window.outcome = module.exports;
+}
+
+
+
+
+
+
+ return module;
+});
View
23 jam/outcome/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "outcome",
+ "description": "DRY error handling",
+ "author": {
+ "name": "Craig Condon"
+ },
+ "repository": {},
+ "version": "0.0.14",
+ "engines": {},
+ "dependencies": {},
+ "devDependencies": {
+ "expect.js": "0.2.x",
+ "mocha": "1.8.x"
+ },
+ "scripts": {
+ "test": "mocha --reporter min"
+ },
+ "main": "./lib/index.js",
+ "readme": "\n\nOutcome.js is a simple flow-control library which wraps your `.callback(err, result)` functions. \n\n### Motiviation\n\n- Write less code for handling errors.\n- Easier to maintain.\n- Keep error handling code separate. \n\n\n\n### Basic Example\n\nHere's the traditional method of handling errors:\n\n```javascript\n\nvar fs = require('fs');\n\nfunction doSomething(path, callback) {\n\n\tfs.realpath(path, onRealPath);\n\n\tfunction onRealPath(err, path) {\n\t\tif(err) return callback(err);\n\t\tfs.lstat(path, onStat);\n\t}\n\n\tfunction onStat(err, stats) {\n\t\tif(err) return callback(err);\n\t\tcallback(err, stats);\n\t}\n\n}\n\ndoSomething('/path/to/something', function(err, result) {\n\t\n\t//inline with result handling - yuck\n\tif(err) {\n\n\t\t//do something with error\n\t\treturn;\n\t}\n\n\t//do something with result\n})\n```\n\nThe outcome.js way:\n\n```javascript\n\nvar fs = require('fs'),\noutcome = require('outcome');\n\nfunction doSomething(path, callback) {\n\n\t//wrap the callback around an error handler so any errors in *this* function\n\t//bubble back up to the callback - I'm lazy and I don't wanna write this stuff...\n\tvar on = outcome.error(callback);\n\n\t//on success, call onRealPath. Any errors caught will be sent back\n\t//automatically\n\tfs.realpath(path, on.success(onRealPath));\n\n\tfunction onRealPath(path) {\n\n\t\t//ONLY call onStat if we've successfuly grabbed the file stats\n\t\tfs.lstat(path, on.success(onStat));\n\t}\n\n\tfunction onStat(stats) {\n\n\t\t//no errors, so send a response back\n\t\tcallback(null, stats);\n\t}\n}\n\n\nvar on = outcome.error(function(error) {\n\t//do something with error\n}));\n\ndoSomething('/path/to/something', on.success(function(response) {\n\t//do something with result\n}));\n\n```\n\n## API\n\n### outcome(listeners)\n\n- `listeners` - Object of listeners you want to attach to outcome.\n\n```javascript\n\nvar onResult = outcome({\n\t\n\t//called when an error is caught\n\terror: function(error) {\n\t\t\n\t},\n\n\t//called when an error is NOT present\n\tsuccess: function(result, thirdParam) {\n\t\t\n\t},\n\n\t//called back when an error, or result is present\n\tcallback: function(err, result, thirdParam) {\n\t\t\n\t}\n})\n\n```\n\nAs shown in the example above, you can also wrap-around an existing callback:\n\n```javascript\nvar onResult = outcome.error(function(error) {\n\t\n}).\nsuccess(function(result, thirdParam) {\n\t\n}).\ncallback(function(error, result, thirdParam) {\n\t\n});\n```\n\n\nBy default, any unhandled errors are thrown. To get around this, you'll need to listen for an `unhandledError`:\n\n```javascript\noutcome.on('unhandledError', function(error) {\n\t//report bugs here..., then throw again.\n});\n\n\n//fails\nfs.stat('s'+__filename, outcome.success(function() {\n\n\n});\n```\n\n\n\n### .callback()\n\nCalled when on error/success. `Same as function(err, data) { }`\n\nHere's a redundant example:\n\n```javascript\n\nfs.stat(__filename, outcome.error(function(err) {\n\t//handle error\n}).success(function(data) {\n\t//handle result\n}.callback(function(err, result) {\n\t//called on fn complete regardless if there's an error, or success\n}));\n\n```\n\n### .success(fn)\n\nCalled on Success.\n\n```javascript\nvar onOutcome = outcome.success(function(data, anotherParam, andAnotherParam) {\n\t//handle success data\n});\n\nonOutcome(null, \"success!\", \"more data!\", \"more results..\");\n```\n\n### .error(fn)\n\nCalled on error.\n\n```javascript\n\nvar onOutcome = outcome.error(function(err) {\n\t\n});\n\nonOutcome(new Error(\"something went wrong...\")); \n```\n\n### .handle(fn)\n\nCustom response handler\n\n```javascript\n\noutcome.handle(function(response) {\n\t\n\tif(response.errors) this.error(response);\n\tif(response.data) this.success(response);\n});\n\n```\n\n\n## CoffeeScript Example\n\n```coffeescript\n\noutcome = require \"outcome\"\n\ndoSomething(path, callback) ->\n\t\n\ton = outcome.error callback\n\n\t# first get the realpath\n\tfs.realpath path, on.success onRealPath\n\n\t# on real path, get stats\n\tonRealPath(path) -> fs.lstat path, on.success onStat\n\n\t# on stat, finish\n\tonStat(stats) -> callback null, stats\n\n\n# call do something\ndoSomething '/path/to/something', outcome \n\n\tsuccess: (statis) ->\n\t\t# do something\n\n\terror: (error) ->\n\t\t# do something else\n\n\n```\n\n\n### Note\n\nCalling `.error()`, `.success()`, `.callback()` generates a new function which copies the previous listeners. \nCheckout [fs-test](outcome.js/blob/master/examples/fs-test.js) in the [examples](outcome.js/blog/master/examples) folder.\n",
+ "readmeFilename": "README.md",
+ "_id": "outcome@0.0.14",
+ "_from": "outcome@"
+}
View
115 jam/require.config.js
@@ -0,0 +1,115 @@
+var jam = {
+ "packages": [
+ {
+ "name": "async",
+ "location": "jam/async",
+ "main": "lib/async.js"
+ },
+ {
+ "name": "dref",
+ "location": "jam/dref",
+ "main": "./lib/index.js"
+ },
+ {
+ "name": "events",
+ "location": "jam/events",
+ "main": "./index.js"
+ },
+ {
+ "name": "outcome",
+ "location": "jam/outcome",
+ "main": "./lib/index.js"
+ },
+ {
+ "name": "stepc",
+ "location": "jam/stepc",
+ "main": "./lib/step.js"
+ },
+ {
+ "name": "toarray",
+ "location": "jam/toarray",
+ "main": "./index.js"
+ }
+ ],
+ "version": "0.2.15",
+ "shim": {}
+};
+
+if (typeof require !== "undefined" && require.config) {
+ require.config({
+ "packages": [
+ {
+ "name": "async",
+ "location": "jam/async",
+ "main": "lib/async.js"
+ },
+ {
+ "name": "dref",
+ "location": "jam/dref",
+ "main": "./lib/index.js"
+ },
+ {
+ "name": "events",
+ "location": "jam/events",
+ "main": "./index.js"
+ },
+ {
+ "name": "outcome",
+ "location": "jam/outcome",
+ "main": "./lib/index.js"
+ },
+ {
+ "name": "stepc",
+ "location": "jam/stepc",
+ "main": "./lib/step.js"
+ },
+ {
+ "name": "toarray",
+ "location": "jam/toarray",
+ "main": "./index.js"
+ }
+ ],
+ "shim": {}
+});
+}
+else {
+ var require = {
+ "packages": [
+ {
+ "name": "async",
+ "location": "jam/async",
+ "main": "lib/async.js"
+ },
+ {
+ "name": "dref",
+ "location": "jam/dref",
+ "main": "./lib/index.js"
+ },
+ {
+ "name": "events",
+ "location": "jam/events",
+ "main": "./index.js"
+ },
+ {
+ "name": "outcome",
+ "location": "jam/outcome",
+ "main": "./lib/index.js"
+ },
+ {
+ "name": "stepc",
+ "location": "jam/stepc",
+ "main": "./lib/step.js"
+ },
+ {
+ "name": "toarray",
+ "location": "jam/toarray",
+ "main": "./index.js"
+ }
+ ],
+ "shim": {}
+};
+}
+
+if (typeof exports !== "undefined" && typeof module !== "undefined") {
+ module.exports = jam;
+}
View
2,116 jam/require.js
2,116 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
203 jam/stepc/lib/step.js
@@ -0,0 +1,203 @@
+define([], function(require) {
+
+ var __dirname = "stepc/lib",
+ __filename = "stepc/lib/step.js",
+ module = { exports: {} },
+ exports = module.exports;
+
+ /*
+Copyright (c) 2010 Tim Caswell <tim@creationix.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+// Inspired by http://github.com/willconant/flow-js, but reimplemented and
+// modified to fit my taste and the node.JS error handling system.
+var slice = Array.prototype.slice;
+
+function _Step(steps, context, ignoreReturn) {
+ var counter, results, lock;
+
+ // Define the main callback that's given as `this` to the steps.
+ function next() {
+
+ // Check if there are no steps left
+ if (steps.length === 0) {
+ // Throw uncaught errors
+ if (arguments[0]) {
+ throw arguments[0];
+ }
+ return;
+ }
+
+ // Get the next step to execute
+ var fn = steps.shift();
+ counter = 0;
+ results = [];
+
+ // Run the step in a try..catch block so exceptions don't get out of hand.
+ try {
+ lock = true;
+ var result;
+
+ // Argument preparation
+ if (context === next) {
+ result = fn.apply(context, arguments);
+ }
+ else {
+ var args = slice.call(arguments);
+ if (args.length === 0) args.push(null);
+ if (fn.length === 0) {
+ args.push(next);
+ }
+ else {
+ if (args.length < fn.length) args[fn.length - 1 || 1] = next;
+ else args.push(next);
+ }
+ result = fn.apply(context, args);
+ }
+ } catch (e) {
+ // Pass any exceptions on through the next callback
+ next(e);
+ }
+
+
+ // If a synchronous return is used, pass it to the callback
+ if (result !== undefined && !ignoreReturn) {
+ next(undefined, result);
+ }
+ lock = false;
+ }
+
+ // Add a special callback generator `this.parallel()` that groups stuff.
+ next.parallel = function () {
+ var i = counter;
+ counter++;
+ function check() {
+ counter--;
+ if (counter === 0) {
+ // When they're all done, call the callback
+ next.apply(null, results);
+ }
+ }
+ return function () {
+ // Compress the error from any result to the first argument
+ if (arguments[0]) {
+ results[0] = arguments[0];
+ }
+ // Send the other results as arguments
+ results[i + 1] = arguments[1];
+ if (lock) {
+ process.nextTick(check);
+ return
+ }
+ check();
+ };
+ };
+
+ // Generates a callback generator for grouped results
+ next.group = function () {
+ var localCallback = next.parallel();
+ var counter = 0;
+ var result = [];
+ var error = undefined;
+ // Generates a callback for the group
+ return function () {
+ var i = counter;
+ counter++;
+ function check() {
+ counter--;
+ if (counter === 0) {
+ // When they're all done, call the callback
+ localCallback(error, result);
+ }
+ }
+ return function () {
+ // Compress the error from any result to the first argument
+ if (arguments[0]) {
+ error = arguments[0];
+ }
+ // Send the other results as arguments
+ result[i] = arguments[1];
+ if (lock) {
+ process.nextTick(check);
+ return
+ }
+ check();
+ }
+
+ }
+ };
+
+ if (!context) context = next;
+
+ // Start the engine an pass nothing to the first step.
+ next();
+}
+
+function Step() {
+
+ var args = slice.call(arguments),
+ context = args.length > 1 && typeof args[0] !== 'function'
+ ? args.shift()
+ : undefined;
+ _Step(args, context, false);
+}
+
+Step.async = function () {
+
+ var args = slice.call(arguments),
+ context = args.length > 1 && typeof args[0] !== 'function'
+ ? args.shift()
+ : undefined;
+ _Step(args, context, true);
+};
+
+// Tack on leading and tailing steps for input and output and return
+// the whole thing as a function. Basically turns step calls into function
+// factories.
+Step.fn = function StepFn() {
+ var steps = Array.prototype.slice.call(arguments);
+ return function () {
+ var args = Array.prototype.slice.call(arguments);
+
+ // Insert a first step that primes the data stream
+ var toRun = [function () {
+ this.apply(null, args);
+ }].concat(steps);
+
+ // If the last arg is a function add it as a last step
+ if (typeof args[args.length-1] === 'function') {
+ toRun.push(args.pop());
+ }
+
+
+ Step.apply(null, toRun);
+ }
+}
+
+
+// Hook into commonJS module systems
+if (typeof module !== 'undefined' && "exports" in module) {
+ module.exports = Step;
+}
+
+
+ return module;
+});
View
33 jam/stepc/package.json
@@ -0,0 +1,33 @@
+{
+ "name": "stepc",
+ "version": "0.0.3",
+ "description": "A CoffeeScript-safe version of creationix' step",
+ "keywords": [
+ "flow",
+ "step",
+ "control-flow",
+ "coffeescript",
+ "control",
+ "asynchronous",
+ "async"
+ ],
+ "homepage": "https://github.com/akidee/stepc",
+ "author": {
+ "name": "Andreas Kalsch",
+ "url": "http://akidee.de/"
+ },
+ "main": "./lib/step.js",
+ "dependencies": {},
+ "devDependencies": {},
+ "engines": {
+ "node": ">=0.2.5"
+ },
+ "readme": "# Step\n\nA simple control-flow library for node.JS that makes parallel execution, serial execution, and error handling painless.\n\n## Installation\n\n```sh\nnpm install stepc\n```\n\n## How to use\n\nThe step library exports a single function I call `Step`. It accepts any number of functions as arguments and runs them in serial order using the passed in `this` context as the callback to the next step.\n\n Step(\n function readSelf() {\n fs.readFile(__filename, this);\n },\n function capitalize(err, text) {\n if (err) throw err;\n return text.toUpperCase();\n },\n function showIt(err, newText) {\n if (err) throw err;\n console.log(newText);\n }\n );\n\nNotice that we pass in `this` as the callback to `fs.readFile`. When the file read completes, step will send the result as the arguments to the next function in the chain. Then in the `capitalize` function we're doing synchronous work so we can simple return the new value and Step will route it as if we called the callback.\n\nThe first parameter is reserved for errors since this is the node standard. Also any exceptions thrown are caught and passed as the first argument to the next function. As long as you don't nest callback functions inline your main functions this prevents there from ever being any uncaught exceptions. This is very important for long running node.JS servers since a single uncaught exception can bring the whole server down.\n\nAlso there is support for parallel actions:\n\n Step(\n // Loads two files in parallel\n function loadStuff() {\n fs.readFile(__filename, this.parallel());\n fs.readFile(\"/etc/passwd\", this.parallel());\n },\n // Show the result when done\n function showStuff(err, code, users) {\n if (err) throw err;\n sys.puts(code);\n sys.puts(users);\n }\n )\n\nHere we pass `this.parallel()` instead of `this` as the callback. It internally keeps track of the number of callbacks issued and preserves their order then giving the result to the next step after all have finished. If there is an error in any of the parallel actions, it will be passed as the first argument to the next step.\n\nAlso you can use group with a dynamic number of common tasks.\n\n Step(\n function readDir() {\n fs.readdir(__dirname, this);\n },\n function readFiles(err, results) {\n if (err) throw err;\n // Create a new group\n var group = this.group();\n results.forEach(function (filename) {\n if (/\\.js$/.test(filename)) {\n fs.readFile(__dirname + \"/\" + filename, 'utf8', group());\n }\n });\n },\n function showAll(err , files) {\n if (err) throw err;\n sys.p(files);\n }\n );\n\n*Note* that we both call `this.group()` and `group()`. The first reserves a slot in the parameters of the next step, then calling `group()` generates the individual callbacks and increments the internal counter.\n\n### Ignore returned values\n\nIt can be useful to ignore the functions' returned values, especially in JavaScript compiled from CoffeeScript, where the result of the last expression is always returned and will trigger the next step while ignoring callbacks. The way to be sure that all steps are asynchronous is:\n\n Step.async(\n function () {\n\n // This is what the CoffeeScript compiler does\n return fs.readdir(__dirname, this);\n },\n function (err, results) {\n // ...\n }\n )\n\n### Preserve context\n\nTo preserve the current context is to pass it to Step() as the first argument. `this` will be the context you provide, your callback is now an additional argument that is passed to every function:\n\n Step(\n this,\n function(e, next) {\n // You can continue to use `this` here, how you would expect it.\n doAsync(..., next);\n },\n function(e, result, next) {\n doAsync(..., next.parallel());\n doAsync(..., next.parallel());\n },\n function(e, result1, result2) {\n // ...\n }\n )\n\n`next` can never be the first argument, since, by convention, it points to an error.\n",
+ "readmeFilename": "README.markdown",
+ "_id": "stepc@0.0.3",
+ "dist": {
+ "shasum": "1d8659172d8b2806ba39058564df5c9e63acaa9b"
+ },
+ "_from": "stepc@",
+ "_resolved": "http://registry.npmjs.org/stepc/-/stepc-0.0.3.tgz"
+}
View
14 jam/toarray/index.js
@@ -0,0 +1,14 @@
+define([], function(require) {
+
+ var __dirname = "toarray",
+ __filename = "toarray/index.js",
+ module = { exports: {} },
+ exports = module.exports;
+
+ module.exports = function(item) {
+ if(item === undefined) return [];
+ return item instanceof Array ? item : [item];
+}
+
+ return module;
+});
View
19 jam/toarray/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "toarray",
+ "version": "0.0.0",
+ "description": "I find myself writing `item = item instanceof Array ? item : [item]` a lot, so I decided to make a simple library to does it for me. A few examples:",
+ "main": "./index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/crcn/toarray.js.git"
+ },
+ "author": "",
+ "license": "BSD",
+ "readmeFilename": "README.md",
+ "readme": "I find myself writing `item = item instanceof Array ? item : [item]` a lot, so I decided to make a simple library to does\nit for me. A few examples:\n\n```javascript\ntoArray = require(\"toarray\");\n\nconsole.log(toArray(\"hello-world!\")); //[\"hello-world!\"]\nconsole.log(toArray([\"hello-world!\"])); //[\"hello-world!\"]\nconsole.log(toArray(undefined)); //[]\n```\n",
+ "_id": "toarray@0.0.0",
+ "_from": "toarray@"
+}
View
94 lib/build.js
@@ -0,0 +1,94 @@
+// Generated by CoffeeScript 1.4.0
+(function() {
+ var amdify, async, at, dref, fs, outcome, path, stepc;
+
+ amdify = require("amdify");
+
+ at = amdify.transformers;
+
+ async = require("async");
+
+ stepc = require("stepc");
+
+ outcome = require("outcome");
+
+ fs = require("fs");
+
+ path = require("path");
+
+ dref = require("dref");
+
+ module.exports = (function() {
+ /*
+ */
+
+ function _Class(ops, packageManagers) {
+ this._jam = packageManagers.packageManagers.jam;
+ this._directory = process.cwd();
+ this._output = this._directory + "/" + (dref.get(ops.pkg, "jam.public.vendor") || "jam");
+ console.log(this._output);
+ }
+
+ /*
+ */
+
+
+ _Class.prototype.run = function(callback) {
+ var dir, o, output, self;
+ o = outcome.e(callback);
+ dir = this._directory + "/node_modules";
+ output = this._output;
+ self = this;
+ return stepc.async((function() {
+ return fs.readdir(dir, this);
+ }), o.s(function(dirs) {
+ dirs = dirs.map(function(d) {
+ return dir + "/" + d;
+ }).filter(function(d) {
+ return path.basename(d).substr(0, 1) !== "." && fs.lstatSync(d).isDirectory();
+ });
+ return this(null, dirs);
+ }), o.s(function(dirs) {
+ return self._amdifyAll(dirs, this);
+ }), o.s(function() {
+ return self._jam.rebuild(this);
+ }), callback);
+ };
+
+ /*
+ */
+
+
+ _Class.prototype._amdifyAll = function(dirs, callback) {
+ var _this = this;
+ return async.map(dirs, (function(dir, callback) {
+ return _this._amdify(dir, function(err) {
+ return callback();
+ });
+ }), callback);
+ };
+
+ /*
+ */
+
+
+ _Class.prototype._amdify = function(dir, callback) {
+ var _this = this;
+ return amdify({
+ entry: require.resolve(dir),
+ directory: this._output
+ }, outcome.e(callback).s(function(bundle) {
+ var transformer;
+ transformer = new at.Template("amd");
+ transformer = new at.Copy({
+ output: _this._output
+ }, transformer);
+ return bundle.transform(transformer, callback);
+ }));
+ };
+
+ return _Class;
+
+ })();
+
+}).call(this);
View
48 lib/index.js
@@ -0,0 +1,48 @@
+// Generated by CoffeeScript 1.4.0
+(function() {
+ var Build, NoJam, PackageManagers, outcome;
+
+ PackageManagers = require("./packageManagers");
+
+ Build = require("./build");
+
+ outcome = require("outcome");
+
+ NoJam = (function() {
+ /*
+ */
+
+ function NoJam(ops) {
+ this._packageManager = new PackageManagers();
+ this._build = new Build(ops, this._packageManager);
+ }
+