コード例 #1
0
module.exports = function findFileInDirs (dirs, file, cb) {

    if (typeof file === "function") {
        cb = file;
        file = "";
    }

    sameTime(dirs.map(cDir => {
        return cb => {
            let cPath = path.resolve(cDir, file);
            isThere(cPath, exists => {
                cb(null, cPath, exists);
            });
        }
    }), (err, fields, exists) => {
        if (err) { return cb(err); }
        for (let i = 0; i < exists.length; ++i) {
            if (exists[i]) {
                return cb(null, fields[i], arrsToObj(fields, exists));
            }
        }

        cb(new Err("Cannot find finded file: <fileName>", {
            fileName: file
          , code: "FILE_DOES_NOT_EXIST"
        }));
    });
};
コード例 #2
0
ファイル: index.js プロジェクト: IonicaBizau/gh-repeat
    ghRepos(selector, token, (err, repos, gh) => {
        if (err) { return cb(err); }
        sameTime(repos.map(c => done => {
            let cData = doWhat(c)
              , args = [cData.url]
              ;

            if (cData.options) {
                args.push(cData.options);
            }

            args.push((err, data) => {
                if (err) {
                    ev.emit("repo-error", err, c);
                } else {
                    ev.emit("repo-success", data, c);
                }
                ev.emit("repo-progress", err, data);
                done(err, { data: data, repo: c });
            });

            gh.get.apply(gh, args);
        }), (err, data) => {
            ev.emit("done", err, data);
        });
    });
コード例 #3
0
ファイル: index.js プロジェクト: IonicaBizau/asyncer.js
/**
 * asyncer
 * Run groups of (a)sync functions.
 *
 * @name asyncer
 * @function
 * @param {Array|Object} tasks The tasks to run in parallel or one by one.
 * @param {Function} cb The callback function.
 */
function asyncer (tasks, cb) {

    cb = cb || noop6;

    if (typpy(tasks, Function)) {
        if (tasks.length >= 1) {
            return tasks(cb);
        }
        return fnResult(tasks, cb);
    }

    let normalize = tsks => tsks.map(c => {
        if (typpy(c, Function) && c.length >= 1) {
            return c;
        }

        return done => {
            asyncer(c, done)
        };
    });

    if (typpy(tasks, Object)) {
        tasks = normalize(tasks.parallel || tasks.p);
        sameTime(tasks, cb);
        return;
    }

    if (typpy(tasks, Array)) {
        tasks = normalize(tasks);
        oneByOne(tasks, cb);
        return;
    }

    throw new TypeError("The tasks should be an array or an object.");
};
コード例 #4
0
ファイル: index.js プロジェクト: jxoss/engine-parser
    /**
     * save
     *
     * @name save
     * @function
     * @param {Object} options An object containing the following fields:
     *
     *  - `save` (Object|String): The instance name to save or an object with the instance names (e.g. `{ "layout": true }`).
     *  - `delete` (Object|String): The instance name to delete or an object with the instance names (e.g. `{ "layout": true }`).
     *
     * @param {Function} cb The callback function.
     */
    save (options, cb) {
        var foos = [];

        if (!options.save && !options.delete) {
            return cb(null, null);
        }

        // { save: "layout" }
        if (typeof options.save === "string") {
            let s = options.save;
            options.save = {};
            options.save[s] = true;
        }

        // { delete: "layout" }
        if (typeof options.delete === "string") {
            let d = options.delete;
            options.delete = {};
            options.delete[d] = true;
        }

        // Collect delete
        iterateObject(options.delete, (_, cDelete) => {
            foos.push(done => {
                this.removeInstance(cDelete, done);
            });
        });

        // Collect save
        iterateObject(options.save, (_, _cSave) => {
            var cSave = this.parser.instances[_cSave] || _cSave;

            // Push the new function
            foos.push(done => {
                this.upsertInstance(cSave.name, cSave, done);
            });
        });

        sameTime(foos, cb);
    }
コード例 #5
0
ファイル: index.js プロジェクト: IonicaBizau/node-mongof
function Mongof(options, callback) {
    var self = this;
    callback = callback || function () {};
    options = Ul.merge(options, {
        collections: []
      , uri: null
      , ignore_sync_for: []
      , ignore_callback_for: ["find", "findOne"]
    });

    if (options.db) {
        options.uri = "mongodb://localhost:27017/" + options.db;
        delete options.db;
    }

    self.options = options;

    // Init the initial collections
    if (!options.collections.length) {
        callback(null, null, null);
        return self;
    }

    self.cols = {};
    SameTime(options.collections.map(function (cCol) {
        return function (cb) {
            self.cols[cCol.collection] = self.initCollection(cCol, function (err, data) {
                if (err) {
                    delete self.cols[cCol.collection];
                    cb(err);
                }
                cb(null, data);
            });
        };
    }), function (err, data) {
        if (err) { return callback(err); }
        callback(null, self.cols, data);
    });
}
コード例 #6
0
ファイル: index.js プロジェクト: jxoss/flow-packages
const packageJson = require("package.json")
    , packages = require("./packages")
    , sameTime = require("same-time")
    , bindy = require("bindy")
    , log = require("bug-killer").log
    , writeJson = require("w-json")
    ;

sameTime(bindy(packages, (repoUrl, cb) => {
    packageJson(repoUrl, (err, data) => {
        log(`Fetched ${repoUrl}.`);
        err && log(err);
        cb(err, data);
    });
}), (err, data) => {
    if (err) {
        return log(err);
    }
    writeJson(`${__dirname}/../lib/packages.json`, data, err => log(err || "Done."));
});
コード例 #7
0
ファイル: index.js プロジェクト: IonicaBizau/gm-tools
 /**
  * parse
  * Parses the image internally.
  *
  * @name parse
  * @function
  * @param {Function} cb The callback function.
  */
 parse (cb) {
     sameTime([
         this.toPNGBuffer.bind(this)
       , this.getSize.bind(this)
     ], cb);
 }