Beispiel #1
0
 }).end(() => {
   assert(!fs.existsSync(path.join(path.join(root, 'node_modules/pkg'))));
   assert(!fs.existsSync(path.join(path.join(root, 'node_modules/.pkg@1.0.0'))));
   const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json')));
   assert(!pkg.optionalDependencies.pkg);
   done();
 });
Beispiel #2
0
function loadSysFile(file) {
	var filepath = path.join(process.cwd(), file);
	if (!mzfs.existsSync(filepath)) {
		filepath = path.join(__dirname, file);
	}
	return mzfs.readFileSync(filepath, 'utf-8');
}
  /**
   * Write the tarball to a directory (the new way)
   */
  async write({docsDir}) {
    if (!docsDir) {
      throw new Error('docsDir is not set');
    } else if (fs.existsSync(docsDir)) {
      throw new Error(`docsDir ${docsDir} already exists`);
    }

    // For the moment, this untar's the tarball created elsewhere in this file;
    // when the "old way' is no longer used, this should be refactored to just
    // write the files to the directory directly.
    const extract = tar.extract();

    await new Promise((resolve, reject) => {
      extract.on('entry', (header, stream, next) => {
        // NOTE: we ignore permissions, ownership, etc..
        const pathname = path.join(docsDir, header.name);
        mkdirp(path.dirname(pathname)).then(() => {
          stream.once('end', next);
          stream.once('error', reject);
          stream.pipe(fs.createWriteStream(pathname));
        }).catch(reject);
      });

      extract.on('finish', resolve);
      extract.on('error', reject);

      this._tarballStream()
        .then(tbStream => tbStream.pipe(zlib.Unzip()).pipe(extract))
        .catch(reject);
    });
  }
Beispiel #4
0
export default async function detect(url) {
  if (fs.existsSync(url)) {
    return detectLocal(url);
  } else {
    return detectRemote(url);
  }
}
 it('should install bundleDependencies not exist(nyc@6.4.2)', function*() {
   yield npminstall({
     root: tmp,
     pkgs: [
       { name: 'nyc', version: '6.4.2' },
     ],
   });
   const exists = fs.existsSync(path.join(tmp, 'node_modules/nyc/node_modules/foreground-child'));
   assert(exists);
 });
Beispiel #6
0
  constructor(options = {}) {
    super();

    this.file = options.file;
    this.store = fs.existsSync(this.file) ? require(this.file) : {};

    // clean files which is not exist
    Object.keys(this.store).forEach(file => {
      if (!fs.existsSync(file)) delete this.store[file];
    });
  }
  /*
   * Given a docker image tarball, the repositories file within the tarball
   * will be overwritten with a unique name used for tagging the image when calling
   * 'docker load'
   *
   * @param {String} imageName - New name of the image
   * @param {String} tarballPath - Path to the docker image tarball
   *
   * @returns {String} Path to the new tarball
   */
  async renameImageInTarball(imageName, tarballPath) {
    let dir = path.dirname(tarballPath);
    let filename = path.basename(tarballPath, '.tar');
    let editedTarballPath = path.join(dir, filename + '-edited.tar');
    let extractedPath = path.join(dir, filename);
    let manifestPath = path.join(extractedPath, 'manifest.json');

    let extractStream = tarfs.extract(extractedPath);
    await pipe(fs.createReadStream(tarballPath), extractStream);

    let repositories = fs.readFileSync(path.join(extractedPath, 'repositories'));
    let repoInfo = JSON.parse(repositories);

    let keys = Object.keys(repoInfo);
    if (keys.length > 1) {
      throw new Error('Image tarballs must only contain one image');
    }

    let oldRepoName = keys[0];
    let oldTag = Object.keys(repoInfo[oldRepoName])[0];
    let newRepoInfo = {};
    newRepoInfo[imageName] = repoInfo[oldRepoName];

    if (oldTag !== 'latest') {
      newRepoInfo[imageName]['latest'] = newRepoInfo[imageName][oldTag];
      delete newRepoInfo[imageName][oldTag];
    }

    newRepoInfo = JSON.stringify(newRepoInfo);
    fs.writeFileSync(path.join(extractedPath, 'repositories'), newRepoInfo);

    if (fs.existsSync(manifestPath)) {
      let manifest = JSON.parse(fs.readFileSync(manifestPath));
      if (manifest.length > 1) {
        throw new Error('Image tarballs must only contain one image');
      }

      manifest[0]['RepoTags'] = [`${imageName}:latest`];
      fs.writeFileSync(manifestPath, JSON.stringify(manifest));
    }

    let pack = tarfs.pack(path.join(dir, filename));
    await pipe(pack, fs.createWriteStream(editedTarballPath));

    try {
      await removeDir(extractedPath);
    } catch(e) {
      debug('Error removing temporary task image directory. ' +
            `Path: ${extractedPath}. Error: ${e.message}`);
    }

    return editedTarballPath;
  }
    async function checkout() {
      await run(['repo-checkout', dest, url, manifest]);
      let statsUrl = fsPath.join(dest, '.repo', '.tc-vcs-cache-stats.json');

      let alias = 'bitbucket.org/lightsofapollo/gittesting/master';
      let cachePath = `${home}/repo/sources/${alias}.tar.gz`;
      assert.ok(await fs.exists(cachePath), 'cache exists...');

      let [rev] = await run(['revision', `${dest}/gittesting`]);
      assert.equal(rev, '3d8bd58cddfa558b78e947ed04ad8f9a3359ed73');

      assert.ok(
        await fs.existsSync(statsUrl),
        'uses cache'
      );

      let cache = require(statsUrl);
      assert.ok(cache.projects['gittesting']);
    }
Beispiel #9
0
 function handleCallback(err) {
   if (err) {
     err.message += ` (${pkg.name}@${pkg.version})`;
     if (readstream.tarballFile && fs.existsSync(readstream.tarballFile)) {
       debug('[%s@%s] remove tarball file: %s, because %s',
         pkg.name, pkg.version, readstream.tarballFile, err);
       // remove tarball cache file
       fs.unlinkSync(readstream.tarballFile);
     }
   }
   if (!callback) {
     // ignore it
     return;
   }
   // ensure callback once
   const cb = callback;
   callback = null;
   cb(err);
 }
Beispiel #10
0
'use strict';

let config = require('config');
let request = require('request-promise');
let fs = require('mz/fs');
let log = require('log')();
let exec = require('child_process').exec;
let tmpRoot = config.tmpRoot + '/iprotect';
if (!fs.existsSync(tmpRoot)) fs.mkdirSync(tmpRoot);

// protect("/path/to/record.mp4")
function* protect(name, filePath, targetDir) {

  validateName(name);

  let uniqueName = Math.random().toString(36).slice(2);

  log.debug("submit for protect", name, uniqueName, filePath);

  let options = {
    json:     true,
    formData: {
      file: {
        value:   fs.createReadStream(filePath),
        options: {
          filename:    uniqueName + '.mp4',
          contentType: 'video/mp4'
        }
      }
    },
    url:      config.iprotect.url.upload
Beispiel #11
0
 this.syncTimeout = setTimeout(() => {
   if (fs.existsSync(this.file)) {
     fs.writeFileSync(this.file, JSON.stringify(this.store));
   }
 }, 2000);
Beispiel #12
0
 Object.keys(this.store).forEach(file => {
   if (!fs.existsSync(file)) delete this.store[file];
 });
Beispiel #13
0
 }).end(() => {
   assert(fs.existsSync(path.join(path.join(root, 'node_modules/.pkg@1.0.0'))));
   done();
 });
Beispiel #14
0
console.log("Program started");
var t0 = process.hrtime(); // Start timer

// Read and log out options
var opts = {};
console.log("Optional parameter: " + process.argv[2]);
for (var i = 3; i < process.argv.length; i += 2) {
  opts[process.argv[i]] = process.argv[i + 1];
}
console.log("Options: ");
console.log(opts);


// Make results directory
if (!fs.existsSync("experiments")) {
  fs.mkdirSync("experiments");
}
fs.mkdirSync(path.join("experiments", opts._id));

// Store source code
fs.writeFileSync(path.join("experiments", opts._id, "source_code.js"), fs.readFileSync("./rand.js"));
// Store image
fs.writeFileSync(path.join("experiments", opts._id, "mnist.png"), fs.readFileSync("./mnist.png"));
// Store custom fields
fs.writeFileSync(path.join("experiments", opts._id, "notes.json"), JSON.stringify({"Notes": "This field is being used to store notes about the experiment.", "Version": "Node.js " + process.version}));


// Creates a linear scale
var linScale = function(numEls, step, start) {
  return _.map(Array(numEls), (val, ind) => {
Beispiel #15
0
function validateBuildpack (d) {
  if (!fs.existsSync(path.join(d, 'bin', 'detect')) ||
      !fs.existsSync(path.join(d, 'bin', 'compile'))) {
    throw new Error(`Buildpack ${d} missing bin/detect or bin/compile`)
  }
}