How to use es6-promisify - 10 common examples

To help you get started, we’ve selected a few es6-promisify 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 youzan / zan-proxy / src / core / App / services / mockData.ts View on Github external
import { promisify } from 'es6-promisify';
import EventEmitter from 'events';
import fs from 'fs-extra';
import { find, forEach } from 'lodash';
import path from 'path';
import { Service } from 'typedi';
import { AppInfoService } from './appInfo';

const fsReadFile = promisify(fs.readFile);
const fsWriteFile = promisify(fs.writeFile);
const fsUnlink = promisify(fs.unlink);

/**
 * 数据mock
 */
@Service()
export class MockDataService extends EventEmitter {
  private mockListDir: string;
  private mockDataDir: string;
  private mockDataList: object;
  constructor(appInfoService: AppInfoService) {
    super();
    const proxyDataDir = appInfoService.getProxyDataDir();
    // 存放mock data的目录
    this.mockDataDir = path.join(proxyDataDir, 'mock-data');
    this.mockListDir = path.join(proxyDataDir, 'mock-list');
    // userId -> datalist
github bholloway / resolve-url-loader / packages / test-my-cli / lib / fs.js View on Github external
        .then((content) => promisify(writeFile)(this.destPath, content))
        .then(constant(this))
github pivotal-cf / pivotal-ui / tasks / helpers / publish-helper.js View on Github external
return map(async (packageInfos, callback) => {
    try {
      await npmLoad({});

      const npmPublish = promisify(npm.commands.publish);
      const npmOwner = promisify(npm.commands.owner);

      for (const packageInfo of packageInfos) {
        log('Publishing', packageInfo.name);
        await npmPublish([packageInfo.dir]);

        const owners = ['mattroyal', 'gpleiss', 'stubbornella', 'ctaymor', 'atomanyih', 'kennyw1019', 'd-reinhold'];
        for (const owner of owners) {
          await npmOwner(['add', owner, packageInfo.name]);
        }
      }
      callback();
    }
    catch(e) {
      console.error(e.stack);
      callback(e);
github jcoreio / react-router-drilldown / scripts / gen-flow-files.js View on Github external
await Promise.all(files.map(async file => {
    const stdout = await promisify(exec)(`${flow} gen-flow-files ${file}`)
    const outfile = path.join(lib, path.relative(src, file)) + '.flow'
    await promisify(fs.writeFile)(outfile, stdout, 'utf8')
    console.log('wrote', outfile)
  }))
})
github mjmlio / mjml-app / src / helpers / fs.js View on Github external
import fs from 'fs'
import { ncp } from 'ncp'
import path from 'path'
import { promisify } from 'es6-promisify'
import { remote } from 'electron'
import { exec as x, execFile as xFile } from 'child_process'

const { dialog } = remote

export const fsReadDir = promisify(fs.readdir)
export const fsRename = promisify(fs.rename)
export const fsReadFile = promisify(fs.readFile)
export const fsWriteFile = promisify(fs.writeFile)
export const fsAccess = promisify(fs.access)
export const fsStat = promisify(fs.stat)
export const fsMkdir = promisify(fs.mkdir)
export const fsUnlink = promisify(fs.unlink)
export const recursiveCopy = promisify(ncp)

function getFileInfoFactory(p) {
  return async name => {
    const fullPath = path.resolve(p, name)
    try {
      const stats = await fsStat(fullPath)
      return {
        name,
        path: fullPath,
github coderaiser / cloudcmd / client / dom / files.js View on Github external
path += '.hbs';
    } else if (isJSON) {
        path = DIR_JSON + name + '.json';
    }
    
    return path;
}

function showError(name) {
    const str = 'Wrong file name: ' + name;
    const error = new Error(str);
    
    throw error;
}

const getSystemFile = promisify((file, callback) => {
    const {prefix} = CloudCmd;
    
    if (!Promises[file])
        Promises[file] = new Promise((success, error) => {
            const url = prefix + file;
            
            load.ajax({
                url,
                success,
                error,
            });
        });
    
    Promises[file].then((data) => {
        callback(null, data);
    }, (error) => {
github youzan / zan-proxy / src / cli / selfUpdate.ts View on Github external
import childProcess from 'child_process';
import { promisify } from 'es6-promisify';
import fs from 'fs';
import { prompt } from 'inquirer';
import ora from 'ora';
import path from 'path';
import selfupdate from 'selfupdate';
import packageInfo from '../../package.json';

const update = promisify(selfupdate.update);
const isUpdated = promisify(selfupdate.isUpdated);
const exec = promisify(childProcess.exec);

const lastCheckTime = {
  encoding: 'utf-8',
  file: path.join(__dirname, 'zanproxy.last-check.tmp'),
  get: () => {
    const { file, encoding } = lastCheckTime;
    if (!fs.existsSync(file)) {
      return null;
    }
    const content = fs.readFileSync(file, { encoding });
    if (!content.length) {
      return null;
    }
    try {
github Dexus / pem / lib / pem.js View on Github external
* @property {function}  createCertificate - How much gold the party starts with.
 */
module.exports.promisified = {
  createPrivateKey: promisify(createPrivateKey),
  createDhparam: promisify(createDhparam),
  createEcparam: promisify(createEcparam),
  createCSR: promisify(createCSR),
  createCertificate: promisify(createCertificate),
  readCertificateInfo: promisify(readCertificateInfo),
  getPublicKey: promisify(getPublicKey),
  getFingerprint: promisify(getFingerprint),
  getModulus: promisify(getModulus),
  getDhparamInfo: promisify(getDhparamInfo),
  createPkcs12: promisify(createPkcs12),
  readPkcs12: promisify(readPkcs12),
  verifySigningChain: promisify(verifySigningChain),
  checkCertificate: promisify(checkCertificate),
  checkPkcs12: promisify(checkPkcs12)
}
github Dexus / pem / lib / pem.js View on Github external
* @property {function}  createCSR      - The default treasure.
 * @property {function}  createCertificate - How much gold the party starts with.
 */
module.exports.promisified = {
  createPrivateKey: promisify(createPrivateKey),
  createDhparam: promisify(createDhparam),
  createEcparam: promisify(createEcparam),
  createCSR: promisify(createCSR),
  createCertificate: promisify(createCertificate),
  readCertificateInfo: promisify(readCertificateInfo),
  getPublicKey: promisify(getPublicKey),
  getFingerprint: promisify(getFingerprint),
  getModulus: promisify(getModulus),
  getDhparamInfo: promisify(getDhparamInfo),
  createPkcs12: promisify(createPkcs12),
  readPkcs12: promisify(readPkcs12),
  verifySigningChain: promisify(verifySigningChain),
  checkCertificate: promisify(checkCertificate),
  checkPkcs12: promisify(checkPkcs12)
}

es6-promisify

Converts callback-based functions to ES6 Promises

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis