Created
October 19, 2012 22:42
-
-
Save cbrammer/3921148 to your computer and use it in GitHub Desktop.
NPM Sucks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var npm = require('npm') | |
, pack = require('./package.json') | |
, modules = {} | |
; | |
if(pack.dependencies) build(pack.dependencies); | |
if(pack.optionalDependencies) build(pack.optionalDependencies); | |
if(pack.devDependencies) build(pack.devDependencies); | |
function build(dependancies) { | |
for (var i in dependancies) { | |
modules[i] = {name: i, success: false, retries: 0}; | |
} | |
} | |
npm.load({}, function (er) { | |
console.log('modules', modules); | |
install(function(err, data){ | |
console.log('finished', err, data); | |
}) | |
npm.on("log", console.log) | |
}); | |
function install(cb) { | |
for(var i in modules) { | |
var module = modules[i]; | |
if(module.success) continue; | |
if(module.retries == 4) | |
return cb(new Error('failed to install ' + module.name)); | |
console.log('') | |
console.log('starting install for: ' + module.name + ' -- ' + module.retries + ' retries'); | |
console.log('') | |
npm.commands.install([module.name], function (err, data) { | |
module.retries++; | |
module.success = !err; | |
install(cb); | |
// command succeeded, and data might have some info | |
}); | |
return; | |
} | |
cb(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment