Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bin/m.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

/* eslint no-sync:0 no-octal-escape:0, no-path-concat:0 */
/* eslint no-sync:0, no-console:0, no-octal-escape:0, no-path-concat:0 */
var fs = require('fs');
var docopt = require('docopt').docopt;
var pkg = require('../package.json');
Expand Down Expand Up @@ -39,7 +39,7 @@ var abortIfError = function(err) {
console.error(chalk.bold.red(figures.cross),
' Error:', chalk.bold.red(err.message));

console.error('We apologize for this issue and welcome your bug reports.')
console.error('We apologize for this issue and welcome your bug reports.');
console.error('Please visit: https://github.com/mongodb-js/version-manager/issues');
console.error();
console.error('Try running your command again with debugging on:');
Expand Down Expand Up @@ -86,6 +86,7 @@ var commands = {
};

mvm.installed(function(err, installed) {
/* eslint no-shadow:0 */
abortIfError(err);

mvm.available(opts, function(err, versions) {
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ module.exports.is = function(s, done) {
};

module.exports.current = function(fn) {
which('mongod', function(err, mongod_bin) {
if (err || !mongod_bin) {
which('mongod', function(err, mongodBin) {
/* eslint no-shadow:0 */
if (err || !mongodBin) {
return fn(null);
}
exec(mongod_bin + ' --version', function(err, stdout) {
exec(mongodBin + ' --version', function(err, stdout) {
if (err) return fn(err);

var shellVersion = stdout
Expand Down
6 changes: 3 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ var untildify = require('untildify');
module.exports = {};

var dest;
var module_path = path.join(process.cwd(), 'node_modules', 'mongodb-version-manager');
var modulePath = path.join(process.cwd(), 'node_modules', 'mongodb-version-manager');
if (process.env.MONGODB_VERSIONS) {
dest = untildify(process.env.MONGODB_VERSIONS);
} else {
try {
/* eslint no-sync:0 */
isLocal = fs.statSync(module_path).isDirectory();
var isLocal = fs.statSync(modulePath).isDirectory();
if (isLocal) {
dest = path.join(module_path, '.mongodb');
dest = path.join(modulePath, '.mongodb');
} else {
dest = untildify('~/.mongodb/versions');
}
Expand Down
5 changes: 4 additions & 1 deletion lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ function progressbar(pkg, res, totalSize) {
bar.tick(chunk.length);
});
}
/* eslint no-sync:0 */

// @todo (kangas): Needs cleanup
module.exports = function(pkg, fn) {
var dest = path.artifact(pkg);
var url = pkg.url;
var version = pkg.version;

fs.mkdirs(path.artifacts(), function(err) {
/* eslint no-console:0, no-shadow:0 */
if (err) {
return fn(err);
}
Expand All @@ -41,6 +43,7 @@ module.exports = function(pkg, fn) {
debug('downloading artifact from `%s` to `%s`...', url, tildify(dest));

var out = fs.createWriteStream(dest);
var onFinish;
var onError = function(err) {
out.removeListener('finish', onFinish);
debug('removing incomplete artifact from `%s`', dest);
Expand Down
48 changes: 25 additions & 23 deletions lib/extract.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
var fs = require('fs-extra');
var zlib = require('zlib');
var unzip = require('unzip');
var tar = require('tar');
var path = require('./path');
var tildify = require('tildify');
var debug = require('debug')('mongodb-version-manager::extract');

function unzip(src, dest, done) {
var extractor = unzip.Extract({
path: dest
});
// @todo (kangas): this is broken
function unzipWrapper(src, dest, done) {
return done(new Error('unzipWrapper not implemented'));

var onSuccess = function() {
debug('unzipped `%s`', tildify(dest));
var full = path.join(dest, nodePath.basename(pkg.artifact, '.zip'));
fs.move(full, dest, function(err) {
if (err) {
return done(err, null);
}
done(null, dest);
});
};
// var extractor = unzip.Extract({
// path: dest
// });

src.pipe(extractor);
extractor.once('close', onSuccess);
extractor.once('error', function(err) {
extractor.removeListener('close', onSuccess);
done(err);
});
// var onSuccess = function() {
// debug('unzipped `%s`', tildify(dest));
// var full = path.join(dest, nodePath.basename(pkg.artifact, '.zip'));
// fs.move(full, dest, function(err) {
// if (err) {
// return done(err, null);
// }
// done(null, dest);
// });
// };

// src.pipe(extractor);
// extractor.once('close', onSuccess);
// extractor.once('error', function(err) {
// extractor.removeListener('close', onSuccess);
// done(err);
// });
}

function untar(src, dest, done) {
var ungzip = zlib.createGunzip();
extractor = tar.Extract({
var extractor = new tar.Extract({
path: dest,
strip: 1
});
Expand Down Expand Up @@ -74,7 +76,7 @@ module.exports = function extract(pkg, done) {
debug('reading %s', tildify(archive));
var src = fs.createReadStream(archive);

var transform = archive.indexOf('zip') > -1 ? unzip : untar;
var transform = archive.indexOf('zip') > -1 ? unzipWrapper : untar;
transform(src, dest, function(err) {
if (err) {
return onError(err);
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"devDependencies": {
"coveralls": "^2.11.4",
"eslint-config-mongodb-js": "^0.1.6",
"eslint-config-mongodb-js": "^1.0.3",
"istanbul": "^0.4.0",
"mocha": "~2.3.3",
"mongodb-js-fmt": "0.0.3",
Expand All @@ -52,7 +52,6 @@
"tar": "~2.2.1",
"tildify": "~1.1.2",
"untildify": "~2.1.0",
"unzip": "~0.1.11",
"which": "~1.2.0"
},
"license": "Apache-2.0"
Expand Down
1 change: 1 addition & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ debug('path to m bin is %s', M);
debug('path to node bin is %s', NODE);

var run = function(args, done) {
/* eslint no-sync:0 no-console:0 */
if (typeof args === 'function') {
done = args;
args = '';
Expand Down