How to use the when/node.call function in when

To help you get started, we’ve selected a few when examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-red / node-red / red / nodes.js View on Github external
return when.promise(function(resolve,reject) {
                var promises = [];
                
                whenNode.call(fs.readdir,dir).done(function(files) {
                    files = files.sort();
                    files.forEach(function(fn) {
                        var stats = fs.statSync(path.join(dir,fn));
                        if (stats.isFile()) {
                            if (/\.js$/.test(fn)) {
                                promises.push(when.promise(function(resolve,reject) {
                                    loadNode(dir,fn).then(resolve, function(err) {
                                        resolve({'fn':fn,err:err});
                                    });
                                }));
                            }
                        } else if (stats.isDirectory()) {
                            // Ignore /.dirs/, /lib/ /node_modules/ 
                            if (!/^(\..*|lib|icons|node_modules|test)$/.test(fn)) {
                                promises.push(when.promise(function(resolve,reject) {
                                    loadNodes(path.join(dir,fn)).then(function(errs) {
github static-dev / spike-records / lib / index.js View on Github external
const tpl = this.opts[k].template
  const root = compiler.options.context

  // If the template option doesn't exist or is malformed, we return or error.
  if (!tpl) { return _data }
  if (!tpl.path) { throw new Error('missing template.path') }
  if (!tpl.output) { throw new Error('missing template.output') }

  // If there is also a template transform function, we run that here
  const data = tpl.transform ? tpl.transform(_data) : _data
  // We must ensure that template data is an array to render each item
  if (!Array.isArray(data)) { throw new Error('template data is not an array') }

  // First we read the template file
  const tplPath = path.join(root, tpl.path)
  return node.call(fs.readFile.bind(fs), tplPath, 'utf8')
    .then((template) => {
      // Now we go through each item in the data array to render a template
      return W.map(data, (item) => {
        // The template gets all the default locals as well as an "item" prop
        // that contains the data specific to the template, and a filename
        const newLocals = Object.assign({}, this.opts.addDataTo, {
          item,
          filename: path.join(root, tpl.path)
        })

        // We need to precisely replicate the way reshape is set up internally
        // in order to render the template correctly, so we run the reshape
        // loader's options parsing with the real loader context and the user's
        // reshape options from the config
        const options = loader.parseOptions.call(this.loaderContext, this.util.getSpikeOptions().reshape, {})
github mozilla-jetpack / jpm / lib / utils.js View on Github external
function getXpiInfoFromInstallRdf(installRdf) {
  var parser = new xml2js.Parser();
  return nodefn.call(parser.parseString, installRdf)
    .catch(function(parseError) {
      parseError.message = "install.rdf: " + parseError.message;
      throw parseError;
    })
    .then(function(result) {
      var info = {
        manifest: null,
      };
      // RDF is one of those sick and twisted XML variants.
      var root = result.RDF || result["RDF:RDF"];

      if (!root) {
        throw new Error("Could not find root RDF element in install.rdf");
      }
      var descriptions = root.Description || root["RDF:Description"];
      if (!descriptions) {
github netlify / js-client / lib / deploy.js View on Github external
sem.take(function() {
        return nodefn.call(fs.readFile, file.abs).then(function(data) {
          var filePath = file.rel.split("/").map(function(segment) {
            return encodeURIComponent(segment);
          }).join("/");

          return self.client.request({
            url: "/deploys/" + self.id + "/files/" + filePath,
            type: "put",
            body: data,
            contentType: "application/octet-stream",
            ignoreResponse: true
          }).then(function(response) {
            progress && progress("upload", {file: file, total: files.length});
            sem.leave();
            return file;
          }).catch(function(response) {
            progress && progress("uploadError", {file:file, message: response.data});
github readfwd / macovei / gulp / build.js View on Github external
gulp.task('mktmp', function () {
  return nodefn.call(exec, 'mkdir -p "' + paths.tmp + '"');
});
github megamsys / varai / varai / nodes / registry.js View on Github external
return when.promise(function(resolve,reject) {
        whenNode.call(fs.readFile,templateFilename,'utf8').done(function(content) {
            try {
                registerConfig(content);
            } catch(err) {
                reject("invalid template file: "+err.message);
            }
            resolve();
        }, function(err) {
            reject("missing template file");
        });
        
    });
}
github release-it / release-it / lib / globcp.js View on Github external
  return when.map(Object.keys(patternObj), patternBase => when.map(patternObj[patternBase], pattern => fn.call(glob, pattern, {cwd: patternBase})
    .then(matches => when.map(matches, match => {
      const src = path.resolve(patternBase, match);
      return fn.call(fs.stat, src).then(stat => {
        const dst = path.resolve(target, match);
        if(stat.isDirectory()) {
          return mkdirAsync(dst);
        } else {
          return copyAsync(src, dst);
        }
      });
    }))
  ));
github release-it / release-it / lib / globcp.js View on Github external
function mkdirAsync(path) {
    return dirCache[path] || (dirCache[path] = fn.call(mkdirp, path));
  }
github JetBrains / ring-ui / tools / generate-documentation.js View on Github external
return when.all(deployment.stylesheets.map(function (filePath) {
              var fileName = path.basename(filePath);
              var source = path.resolve(__dirname, '..', filePath);
              var target = path.resolve(__dirname, writeFilesProcessor.outputFolder, fileName);
              stylesheets.push(fileName);

              return nodefn.call(fs.copy, source, target);
            }));
          }