コード例 #1
0
ファイル: utils.js プロジェクト: ajainarayanan/gpluscommenter
  return wrapGenerator(function($ctx1) {
    while (1) switch ($ctx1.prev = $ctx1.next) {
    case 0:
      $ctx1.prev = 0;
      $ctx1.next = 3;
      return fs.unlink.bind(null, filename);
    case 3:
      $ctx1.next = 10;
      break;
    case 5:
      $ctx1.prev = 5;
      $ctx1.t1 = $ctx1.catch(0);

      if (!($ctx1.t1.code === 'ENOENT')) {
        $ctx1.next = 9;
        break;
      }

      return $ctx1.abrupt("return");
    case 9:
      throw $ctx1.t1;
    case 10:
    case "end":
      return $ctx1.stop();
    }
  }, this, [[0, 5]]);
コード例 #2
0
ファイル: utils.js プロジェクト: azhang/builder2.js
exports.unlink = function* (filename) {
  try {
    yield fs.unlink.bind(null, filename);
  } catch (err) {
    if (err.code === 'ENOENT') return;
    throw err;
  }
}
コード例 #3
0
ファイル: archive.js プロジェクト: MotiurRahman/testGitPor
  return wrapGenerator(function($ctx0) {
    while (1) switch ($ctx0.prev = $ctx0.next) {
    case 0:
      extract = function extract(done) {
        var reader = fs.createReadStream(ball)
        .on('error', cb);

        debug('extracting "%s" into "%s"', ball, folder);

        var writer = reader.pipe(decompress({
          ext: '.' + format,
          path: folder,
          strip: 1,
        }))
        .on('error', cb)
        .on('close', cb);

        function cb(err) {
          reader.removeListener('error', cb);
          writer.removeListener('error', cb);
          writer.removeListener('close', cb);
          done(err);
        }
      };

      onexit = function onexit() {
        fs.unlinkSync(ball);
      };

      archive = remote.archive(repo, ref);
      uri = remote.name + '//' + repo + '@' + ref;

      if (!(archive.tar && archive.tar.length)) {
        $ctx0.next = 9;
        break;
      }

      format = 'tar.gz';
      url = archive.tar[0];
      $ctx0.next = 15;
      break;
    case 9:
      if (!(archive.zip && archive.zip.length)) {
        $ctx0.next = 14;
        break;
      }

      format = 'zip';
      url = archive.zip[0];
      $ctx0.next = 15;
      break;
    case 14:
      throw new Error('no valid tarballs for "' + uri + '"');
    case 15:
      folder = this.folder(repo, ref);
      ball = folder + '.' + format;
      debug('downloading "%s"', ball);
      return $ctx0.delegateYield(remote.request(url), "t0", 19);
    case 19:
      res = $ctx0.t0;

      if (!(res.statusCode !== 200)) {
        $ctx0.next = 23;
        break;
      }

      res.destroy();
      throw new Error('Error downloading "' + uri + '". Got status code "' + res.statusCode + '"');
    case 23:
      // don't allow half-written balls
      process.on('exit', onexit);

      $ctx0.next = 26;
      return write(res, ball);
    case 26:
      process.removeListener('exit', onexit);
      $ctx0.next = 29;
      return extract;
    case 29:
      $ctx0.next = 31;
      return fs.unlink.bind(null, ball);
    case 31:
      return $ctx0.delegateYield(remote.json(repo, ref), "t1", 32);
    case 32:
      json = $ctx0.t1;
      valid = semver.valid(ref);

      // overwrite the version in case it wasn't updated
      if (valid) json.version = valid;

      // add a repository property
      // to do: handle redirects
      if (!json.repository) json.repository = repo;

      this.removeRelative(json);

      if (!this.hasGlobs(json)) {
        $ctx0.next = 39;
        break;
      }

      return $ctx0.delegateYield(this.unglobFromFolder(json, folder), "t2", 39);
    case 39:
      return $ctx0.delegateYield(this.save(json, folder), "t3", 40);
    case 40:
    case "end":
      return $ctx0.stop();
    }
  }, this);
コード例 #4
0
ファイル: archive.js プロジェクト: MotiurRahman/testGitPor
Downloader.prototype._byArchive = function* (remote, repo, ref) {
  var archive = remote.archive(repo, ref);
  var uri = remote.name + '//' + repo + '@' + ref;

  var format;
  var url;
  if (archive.tar && archive.tar.length) {
    format = 'tar.gz';
    url = archive.tar[0];
  } else if (archive.zip && archive.zip.length) {
    format = 'zip';
    url = archive.zip[0];
  } else {
    throw new Error('no valid tarballs for "' + uri + '"');
  }

  var folder = this.folder(repo, ref);
  var ball = folder + '.' + format;
  debug('downloading "%s"', ball);
  var res = yield* remote.request(url);
  if (res.statusCode !== 200) {
    res.destroy();
    throw new Error('Error downloading "' + uri + '". Got status code "' + res.statusCode + '"');
  }

  // don't allow half-written balls
  process.on('exit', onexit);
  yield write(res, ball);
  process.removeListener('exit', onexit);

  yield extract;
  yield fs.unlink.bind(null, ball);

  // this should already be retrieved in the resolver,
  // so it shouldn't be a big deal.
  var json = yield* remote.json(repo, ref);

  /*
  var component = join(folder, 'component.json');
  var json;
  try {
    json = yield fs.readFile.bind(null, component);
  } catch (err) {
    if (err.code !== 'ENOENT') throw err;
    throw new Error('No component.json for "' + uri + '"');
  }
  try {
    json = JSON.parse(json);
  } catch (err) {
    throw new Error('error parsing "' + uri + '"\'s component.json');
  }
  */

  var valid = semver.valid(ref);
  // overwrite the version in case it wasn't updated
  if (valid) json.version = valid;
  // add a repository property
  // to do: handle redirects
  if (!json.repository) json.repository = repo;

  this.removeRelative(json);

  if (this.hasGlobs(json)) yield* this.unglobFromFolder(json, folder);

  yield* this.save(json, folder);

  function onexit() {
    fs.unlinkSync(ball);
  }

  function extract(done) {
    var reader = fs.createReadStream(ball)
    .on('error', cb);

    debug('extracting "%s" into "%s"', ball, folder);

    var writer = reader.pipe(decompress({
      ext: '.' + format,
      path: folder,
      strip: 1,
    }))
    .on('error', cb)
    .on('close', cb);

    function cb(err) {
      reader.removeListener('error', cb);
      writer.removeListener('error', cb);
      writer.removeListener('close', cb);
      done(err);
    }
  }
}