Skip to content

Commit

Permalink
Programatically using npm
Browse files Browse the repository at this point in the history
- first take on doug-martin#5.
  • Loading branch information
phtrivier committed Aug 25, 2014
1 parent 980481e commit 97bd912
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tasks/lib/linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ module.exports = function (grunt, npm, options) {
errors = [],
cwd = process.cwd();

function npmCommand(cmd, args) {
if (!comb.isArray(args)) {
args = [args];
}
var ret = new comb.Promise();
npm.commands[cmd](args, function (err, result) {
if (err) {
ret.errback(err);
} else {
ret.callback();
}
});
return ret;
}

function exec(cmds) {
if (!comb.isArray(cmds)) {
cmds = [cmds];
Expand Down Expand Up @@ -92,9 +107,7 @@ module.exports = function (grunt, npm, options) {
}
return cleanPromise.chain(function () {
if (shouldLink(pkg[0])) {
return exec([
{cmd: "npm", args: ["unlink", getPackageName(pkg[0]), "--global"]}
]);
return npmCommand("unlink", getPackageName(pkg[0]));
}
});
} catch (e) {
Expand Down Expand Up @@ -125,7 +138,7 @@ module.exports = function (grunt, npm, options) {
}
chdir(pkg[0]);
if (isBoolean(pkg[2]) ? pkg[2] : true) {
return exec({ cmd: "npm", args: ["link"]});
return npmCommand("link", []);
}
}, 1)
.forEach(function (pkg, i) {
Expand All @@ -136,7 +149,7 @@ module.exports = function (grunt, npm, options) {
if (isBoolean(pkg[2]) ? pkg[2] : true && options.install) {
log.debug(util.format("==== %s ====", getPackageName(pkg[0])));
chdir(pkg[0]);
return exec({cmd: "npm", args: ["install"]});
return npmCommand("install", []);
}
}, 1)
.forEach(function (pkg, i) {
Expand Down

0 comments on commit 97bd912

Please sign in to comment.