Hemanth's Scribes

web

Program Dependency Management With node.js

Author Photo

Hemanth HM

Thumbnail

Program Dependency Management With node.js

Lately was working with a few PRs for The Yeoman project and tried to hack through a shelljs script to audit the OS before installation.

P.S : npm install shelljs as this is the dependency for this dependency management script :D

The code :

require(‘shelljs/global’); var os = require(‘os’); var sys = require(‘sys’);

var os_type = os.type(); var installed = []; var not_installed = [];

var deps = { curl : ”, git : ”, ruby : ‘1.8’, node : ‘0.8’, compass : ‘0.12’, gem : ”, phantomjs : ”, jpegtran : ”, optipng : ”, yeoman : ”, clang : ”, brew : ” };

if(os_type == “Linux”) { //This is Linux so remove Mac deps. delete deps[‘clang’]; delete deps[‘brew’]; }

for(var dep in deps) { if (!which(dep)) {

not_installed.push(dep);

} else{

if(deps[dep]){
  var version = exec(dep +' -v', {silent:true}).output;
  console.log(version);
  console.log(deps[dep]);
  if(version.search(deps[dep]) == -1){
    not_installed.push(dep); // Installed, but version mismatch.
  }
}
else{
  installed.push(dep);
}

}
}

console.log(installed); console.log(not_installed);

Do let me know your thoughts on the same, happy hacking!

#javascript#linux
Author Photo

About Hemanth HM

Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.