From 870bbdeb599baaecd175e1b1344a2a56da79f0fe Mon Sep 17 00:00:00 2001 From: Judah Schvimer Date: Wed, 7 Oct 2015 15:17:44 -0400 Subject: [PATCH] Fixed Version Manager to work on Windows --- index.js | 7 ++++++- lib/activate.js | 7 ++++++- lib/extract.js | 30 +++++++++++++++--------------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 3e214e5..bc56661 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,7 @@ var activate = require('./lib/activate'); var download = require('./lib/download'); var extract = require('./lib/extract'); var debug = require('debug')('mongodb-version-manager'); +var os = require('os'); var VERSION = /[0-9]+\.[0-9]+\.[0-9]+([-_\.][a-zA-Z0-9]+)?/; @@ -20,7 +21,11 @@ var bin = path.join(path.current({ }), 'bin'); if (process.env.PATH.indexOf(bin) === -1) { - process.env.PATH = bin + ':' + process.env.PATH; + if (os.platform() === 'win32') { + process.env.PATH = bin + ';' + process.env.PATH; + } else { + process.env.PATH = bin + ':' + process.env.PATH; + } } module.exports = function(opts, fn) { diff --git a/lib/activate.js b/lib/activate.js index c893d1a..d2aa323 100644 --- a/lib/activate.js +++ b/lib/activate.js @@ -2,12 +2,17 @@ var debug = require('debug')('mvm:activate'); var path = require('./path'); var fs = require('fs-extra'); var tildify = require('tildify'); +var os = require('os'); module.exports = function(pkg, fn) { var bin = path.resolve(path.current(pkg) + '/bin'); if (process.env.PATH.indexOf(bin) === -1) { - process.env.PATH = bin + ':' + process.env.PATH; + if (os.platform() === 'win32') { + process.env.PATH = bin + ';' + process.env.PATH; + } else { + process.env.PATH = bin + ':' + process.env.PATH; + } debug('added to PATH %s', tildify(bin)); } diff --git a/lib/extract.js b/lib/extract.js index ceb6dd8..32c8f56 100644 --- a/lib/extract.js +++ b/lib/extract.js @@ -4,6 +4,7 @@ var unzip = require('unzip'); var tar = require('tar'); var createCleanupCrew = require('./cleanup'); var path = require('./path'); +var nodePath = require('path'); var tildify = require('tildify'); var debug = require('debug')('mvm::extract'); @@ -35,6 +36,15 @@ module.exports = function extract(pkg, fn) { path: dest }); input.pipe(extractor); + extractor.on('close', function() { + debug('created %s', tildify(dest)); + cleanup.clear(); + var full = nodePath.join(dest, nodePath.basename(pkg.artifact, '.zip')); + fs.move(full, dest, function(err) { + if (err) return fn(err, null); + fn(null, dest); + }); + }); } else { var ungzip = zlib.createGunzip(); extractor = tar.Extract({ @@ -49,25 +59,15 @@ module.exports = function extract(pkg, fn) { debug('untar-ing....'); ungzip.pipe(extractor); + extractor.on('end', function() { + debug('created %s', tildify(dest)); + cleanup.clear(); + fn(null, dest); + }); } extractor.on('error', function(err) { console.error(err); }); - var onClose; - - var onEnd = function() { - debug('created %s', tildify(dest)); - cleanup.clear(); - extractor.removeListener('readable', onClose); - fn(null, dest); - }; - onClose = function() { - debug('created %s', tildify(dest)); - cleanup.clear(); - extractor.removeListener('readable', onEnd); - fn(null, dest); - }; - extractor.once('end', onEnd).once('close', onClose); }); };