Skip to content

Commit

Permalink
restructure so coverage is more accurate (cli needs more testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
clux committed Mar 28, 2015
1 parent 183d73f commit 8c680e7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 51 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ notifications:
email: true

after_script:
- npm run instrument
- npm run coveralls
40 changes: 1 addition & 39 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,4 @@ var argv = require('yargs')
.help('h')
.argv;

// can do multiple unnamed arguments for directories relative to cwd
var join = require('path').join;
var dirs = argv._.map(function (dir) {
return join(process.cwd(), dir);
});
var cp = require('child_process');
var async = require('async');

require('./')(dirs, argv.g || [], function (err, cmds) {
if (err) {
console.error(err.message);
process.exit(1);
}

if (argv.d) { // dry run
console.log(JSON.stringify(cmds, null, " "));
}
else {
// create one cp function cmd that execs and cbs to next in async series
var execs = cmds.map(function (cmd) {
return function (cb) {
console.log(cmd);
cp.exec(cmd, function (error, stdout) {
console.log(stdout);
cb(error);
});
};
});

// exec commands synchronously
async.series(execs, function (err) {
if (err) {
console.error(err.message);
process.exit(1);
}
process.exit(0);
});
}
});
require('./lib/cli').run(argv);
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module.exports = process.env.SYMLINK_COV
? require('./lib-cov/symlink.js')
: require('./lib/symlink.js');
module.exports = process.env.SYMLINK_COV ?
require('./lib-cov/symlink.js'):
require('./lib/symlink.js');

module.exports.cli = process.env.SYMLINK_COV ?
require('./lib-cov/cli.js'):
require('./lib/cli.js');
46 changes: 46 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var cp = require('child_process');
var path = require('path');
var async = require('async');

var handleError = function (err) {
if (err) {
console.error(err.message);
process.exit(1);
}
};

var dryRunHandler = function (err, cmds) {
handleError(err);
console.log(JSON.stringify(cmds, null, " "));
};
var executeHandler = function (err, cmds) {
handleError(err);
// create one cp function cmd that execs and cbs to next in async series
var execs = cmds.map(function (cmd) {
return function (cb) {
console.log(cmd);
cp.exec(cmd, function (error, stdout) {
console.log(stdout);
cb(error);
});
};
});

// exec commands synchronously
async.series(execs, function (err) {
handleError(err);
process.exit(0);
});
};


exports.run = function (argv) {
// repoDirs are the unnamed arguments (usually just one super dir)
var dirs = argv._.map(function (dir) {
return path.join(process.cwd(), dir);
});

// execute main module function with one of the handlers as the cb
var handler = argv.d ? dryRunHandler : executeHandler;
require('./symlink')(dirs, argv.g || [], handler);
};
1 change: 0 additions & 1 deletion lib/symlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,4 @@ module.exports = function (dirs, globals, cb) {
}
return cb(null, cmds);
});

};
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
"url": "clux/symlink"
},
"keywords": [
"link",
"install",
"npm",
"dependency",
"management"
"development",
"repository",
"install"
],
"scripts": {
"test": "$(npm bin)/nodeunit --reporter=verbose test/*.js",
"instrument": "$(npm bin)/jscoverage lib",
"coverage": "SYMLINK_COV=1 $(npm bin)/nodeunit --reporter=lcov test/*.js",
"test": "nodeunit --reporter=verbose test/*.js",
"precoverage": "jscoverage lib",
"coverage": "SYMLINK_COV=1 nodeunit --reporter=lcov test/*.js",
"coveralls": "npm run coverage | coveralls"
},
"bin": "bin.js",
Expand Down

0 comments on commit 8c680e7

Please sign in to comment.