Code coverage report for mongodb-version-manager/lib/activate.js

Statements: 52.63% (10 / 19)      Branches: 50% (1 / 2)      Functions: 20% (1 / 5)      Lines: 52.63% (10 / 19)      Ignored: none     

All files » mongodb-version-manager/lib/ » activate.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 391 1 1 1 1 1                   1 1           1                             1  
var path = require('./path');
var fs = require('fs-extra');
var tildify = require('tildify');
var async = require('async');
var delimiter = require('path').delimiter;
var debug = require('debug')('mongodb-version-manager:activate');
 
/**
 * Make sure the bin directory for the current version
 * is in `$PATH`.
 * @param {String} directory
 *
 * @todo (imlucas): :axe: env helper from `mongodb-js/mj`
 * and use it here.
 */
function addToPath(directory) {
  Iif (process.env.PATH.indexOf(directory) === -1) {
    process.env.PATH = [directory, process.env.PATH].join(delimiter);
    debug('added `%s` to $PATH', tildify(directory));
  }
}
 
module.exports = function(pkg, done) {
  addToPath(path.join(path.current(pkg), 'bin'));
 
  async.series([function(cb) {
    debug('removing old symlink if it exists...');
    fs.remove(path.current(pkg), function() {
      cb();
    });
  }, function(cb) {
    debug('symlinking `%s` -> `%s`...', path.dest(pkg), path.current(pkg));
    fs.symlink(path.dest(pkg), path.current(pkg), fn);
  }
  ], done);
};
 
module.exports.addToPath = addToPath;