How to use the bluebird.promisify function in bluebird

To help you get started, we’ve selected a few bluebird 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 oleksiyk / riakfs / test / siblings.js View on Github external
it.skip('file + file siblings without proper content', function () {
            var id;
            return Promise.promisify(fs.readFile)(f.path).then(function (data) {
                return riakfs.writeFile('/' + path.basename(f.path), data);
            })
            .then(function () {
                return riakfs.stat('/' + path.basename(f.path)).then(function (stats) {
                    id = stats.file.id;
                });
            })
            .then(function () {
                // make several siblings
                return Promise.map([0, 123, 456, 789], function (len) {
                    return riakfs.riak.put({
                        bucket: riakfs.filesBucket,
                        key: '/' + path.basename(f.path),
                        content: {
                            value: JSON.stringify({
                                id: uid2(32),
github Jense5 / consultant-cli / src / add.js View on Github external
* @author  Jensen Bernard
 * @version 0.2.0
 */

import fs from 'fs';
import path from 'path';
import Promise from 'bluebird';
import validURL from 'valid-url';
import { exec } from 'child_process';

import content from './content';

// eslint-disable-next-line no-console
const info = console.info;

const execute = Promise.promisify(exec);

const name = (uri: string): string => path.basename(uri, '.git');
const folder = (uri: string, base: string): string => path.resolve(base, name(uri));
const canCreate = (uri: string, base: string): boolean => fs.existsSync(folder(uri, base));

const cmd = (uri: string, out: string): string => `git clone ${uri} ${out}`;
const clone = (uri: string, tmpl: string): Promise<> => execute(cmd(uri, folder(uri, tmpl)));

const add = (uri: string, templates: string): Promise<> =>
  new Promise((resolve, reject) => {
    if (validURL.isWebUri(uri)) {
      if (canCreate(uri, templates)) {
        clone(uri, templates).then(resolve).catch(reject);
      } else { info(content.duplicateName()); }
    } else {
      info(content.invalidURI());
github cucumber / cucumber-js / src / cli / install_validator.js View on Github external
export async function validateInstall(cwd) {
  const projectPath = path.join(__dirname, '..', '..')
  if (projectPath === cwd) {
    return // cucumber testing itself
  }
  const currentCucumberPath = require.resolve(projectPath)
  let localCucumberPath = await promisify(resolve)('cucumber', {
    basedir: cwd,
  })
  localCucumberPath = await fs.realpath(localCucumberPath)
  if (localCucumberPath !== currentCucumberPath) {
    throw new Error(
      `
      You appear to be executing an install of cucumber (most likely a global install)
      that is different from your local install (the one required in your support files).
      For cucumber to work, you need to execute the same install that is required in your support files.
      Please execute the locally installed version to run your tests.

      Executed Path: ${currentCucumberPath}
      Local Path:    ${localCucumberPath}
      `
    )
  }
github Gravebot / Gravebot / src / commands / fun / comics.js View on Github external
import Promise from 'bluebird';
import cheerio from 'cheerio';
import _request from 'request';
import R from 'ramda';

import { subCommands as helpText } from '../help';
import sentry from '../../sentry';


const request = Promise.promisify(_request);

// Cyanide and Happiness
function cah(bot, msg) {
  request('http://explosm.net/comics/random/')
    .then(R.prop('body'))
    .then(cheerio.load)
    .then($ => $('#main-comic').attr('src'))
    .then(url => bot.sendMessage(msg.channel, `http:${url}`))
    .catch(err => {
      sentry(err, 'comics', 'cah');
      bot.sendMessage(msg.channel, `Error: ${err.message}`);
    });
}

// Saturday Morning Breakfast Cereal
function smbc(bot, msg) {
github carbon-design-system / carbon / packages / components / gulpfile.js View on Github external
const rollupConfigDev = require('./tools/rollup.config.dev');
const rollupConfigProd = require('./tools/rollup.config');

// WebPack
const webpack = require('webpack');

const webpackPromisified = promisify(webpack);

// JSDoc
const jsdocConfig = require('gulp-jsdoc3/dist/jsdocConfig.json');

// Generic utility
const del = require('del');

const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
const mkdirp = promisify(require('mkdirp'));

const portscanner = require('portscanner');

// Test environment
const { Server } = require('karma');
const commander = require('commander');

// Fractal templates, deferred require is so that we can run `gulp clean`
// without depending on `@carbon/icons` to be available
let templates;
function getTemplates() {
  if (!templates) {
    // eslint-disable-next-line global-require
    templates = require('./tools/templates');
  }
github serverless / serverless / lib / utils / open.js View on Github external
// changes:
//  * use bluebird.promisify instead of util.promisfy
//  * Object.assign instead of spread
//  * use Array.prototype.push.apply(a,b) instead of a.push(...b)
//  * async/await -> then :|
//  * prettified with our config

const { promisify } = require('bluebird');
const chalk = require('chalk');
const path = require('path');
const childProcess = require('child_process');
const fs = require('fs');
const isWsl = require('is-wsl');

const pAccess = promisify(fs.access);
const pExecFile = promisify(childProcess.execFile);

// Path to included `xdg-open`
const localXdgOpenPath = path.join(__dirname, 'xdg-open');

// Convert a path from WSL format to Windows format:
// `/mnt/c/Program Files/Example/MyApp.exe` → `C:\Program Files\Example\MyApp.exe`
const wslToWindowsPath = filePath =>
  pExecFile('wslpath', ['-w', filePath]).then(({ stdout }) => stdout.trim());

module.exports = (target, options) => {
  if (typeof target !== 'string') {
    throw new TypeError('Expected a `target`');
  }

  options = Object.assign(
    {
github iExecBlockchainComputing / PoCo / test / callback / checkBalance.js View on Github external
const Promise = require('bluebird');
const Web3 = require('web3');
const fs = require('fs-extra');
const openAsync = Promise.promisify(fs.open);
const writeAsync = Promise.promisify(fs.write);
const readFileAsync = Promise.promisify(fs.readFile);
const writeFileAsync = Promise.promisify(fs.writeFile);

var MSG_SENDER = process.argv[2] || "0x8bd535d49b095ef648cd85ea827867d358872809";
var SMART_CONTRACT_ADDRESS = process.argv[3] || "0xc4e4a08bf4c6fd11028b714038846006e27d7be8";
var NODE_TARGET = process.argv[3] || "http://localhost:8545";

web3 = new Web3(new Web3.providers.HttpProvider(NODE_TARGET));

Promise.promisifyAll(web3.eth, {
  suffix: "Promise"
});

async function getAbiContent() {
  try {
    var abiFileContent = await readFileAsync("../../deployed/contracts/IexecHub.json");
    return JSON.parse(abiFileContent).abi;
  } catch (err) {
github mattdesl / ghrepo / cmd.js View on Github external
#!/usr/bin/env node
const Promise = require('bluebird')
const argv = require('minimist')(process.argv.slice(2))
const chalk = require('chalk')
const github = require('./lib/github')
const open = require('opn')
const path = require('path')
const noop = require('no-op')
const baseName = require('require-package-name').base
const githubUrl = require('github-url-to-object')

const publish = Promise.promisify(github.publish) 
const auth = Promise.promisify(github.auth) 
const config = Promise.promisify(require('./lib/config')) 
const gitCommit = Promise.promisify(require('./lib/commit')) 
const confirm = Promise.promisify(require('./lib/confirm')) 
const loadPackage = Promise.promisify(require('./lib/package')) 

//get organization
var org = argv.o || argv.org
if (org && typeof org !== 'string') {
  console.error("No --org specified")
  process.exit(1)
}

  
if (argv.v || argv.version) {
  var version = require('./package.json').version
  console.log(version)
github wix-incubator / node-workshop / 01-tutorial-code / 02-es6 / 10-promisify.js View on Github external
function copyFile(sourceFile, targetFile) {
  return Promise.promisify(fs.readFile)(sourceFile)
    .then(contentBuffer => {
      return Promise.promisify(fs.writeFile)(targetFile, contentBuffer)
    })
}
github TryStarboard / Starboard / source / server / util / auth.js View on Github external
import passport from 'koa-passport';
import { Strategy as LocalStrategy } from 'passport-local';
import { wrap } from 'co';
import { hash as _hash, compare } from 'bcrypt';
import { promisify } from 'bluebird';
import db from './db';

const hashAsync = promisify(_hash);
const compareAsync = promisify(compare);

const opts = {
  usernameField: 'email',
  passwordField: 'password',
};

export class EmailPassNotMatchError extends Error {
  constructor() {
    super();
    Error.captureStackTrace(this, EmailPassNotMatchError);
    this.name = 'EmailPassNotMatchError';
  }
}

export class EmailExistError extends Error {
  constructor() {