示例#1
0
    atom.workspace.observeTextEditors (editor => {
      const wannabeRunner = new AtomWannabe (editor);

      let edited = 0;

      this.subscriptions.add (
        editor.onDidStopChanging (
          watt (function* () {
            ++edited;
            if (edited > 1) {
              return;
            }

            while (edited > 0) {
              try {
                yield wannabeRunner.run ();
              } catch (ex) {
                console.error (ex.stack || ex);
              } finally {
                --edited;
                if (edited > 1) {
                  edited = 1;
                }
              }
            }
          })
        )
      );

      this.subscriptions.add (
        editor.onDidDestroy (() => {
          wannabeRunner.dispose ();
        })
      );
    });
示例#2
0
'use strict';

const path = require('path');
const fse = require('fs-extra');
const watt = require('watt');
const shrew = require('shrew');
const clc = require('cli-color');

const root = shrew();

module.exports = watt(function*(next) {
  const lockFiles = ['package-lock.json', 'yarn.lock'];

  console.log(
    clc.yellowBright(`Remove all lock files (${lockFiles.join(', ')})`)
  );

  for (const file of lockFiles) {
    try {
      yield fse.unlink(path.join(root, file), next);
    } catch (ex) {
      if (ex.code !== 'ENOENT') {
        throw ex;
      }
    }
  }
});
示例#3
0
  child.stderr.on('data', waitForReady)
  child.stdout.pipe(log)
  child.stderr.pipe(log)
  function waitForReady (data) {
    if (!data.toString().includes('Serving on')) return
    child.removeListener('data', waitForReady)
    cb(null)
  }
  return child
}

let initialBchomeDataPath = watt(function * (next) {
  let path = join(__dirname, '../../bchome')
  let err = yield fs.access(path, next.arg(0))
  if (err && err.code !== 'ENOENT') throw err
  if (err && err.code === 'ENOENT') {
    return join(__dirname, '../bchome')
  }
  return path
})

let initBasecoin = watt(function * (root, next) {
  let err = yield fs.access(root, next.arg(0))
  if (err && err.code !== 'ENOENT') throw err
  if (!err) return // if already exists, skip init
  let opts = {
    env: {
      BCHOME: root,
      TMROOT: root
    }
  }
示例#4
0
const install = watt(function*(src, dst, next) {
  const copyModule = () => {
    if (helpers.useSymlinks()) {
      fse.symlinkSync(path.relative(path.dirname(dst), src), dst, 'junction');
    } else {
      fse.copySync(src, dst);
    }
  };

  try {
    copyModule();
  } catch (ex) {
    if (ex.code !== 'EEXIST') {
      throw ex;
    }

    /* Check if it's a symlink otherwise check the version and replace by
     * the right module if it matches.
     */
    const st = fse.lstatSync(dst);
    if (!st.isSymbolicLink()) {
      const pkgSrc = JSON.parse(
        fse.readFileSync(path.join(src, 'package.json'))
      );
      const pkgDst = JSON.parse(
        fse.readFileSync(path.join(dst, 'package.json'))
      );
      const list = [pkgSrc.version, pkgDst.version];

      if (!helpers.isSemverSatisfies(list)) {
        throw new Error(
          `Clash with ${path.basename(src)} versions ${list.join(', ')}`
        );
      }
    }

    /* Replace by the right module */
    fse.removeSync(dst);
    copyModule();
  }

  /* Remove obsolete nested node_modules */
  fse.removeSync(path.join(dst, 'node_modules'));

  yield npm('build', [dst], root, next);
});