Permalink
Browse files

Initial import, published to npm already.

  • Loading branch information...
0 parents commit e09c5a58a45e73ba29dee32bc515df719487fa48 @DanBUK committed Jan 24, 2011
Showing with 92 additions and 0 deletions.
  1. +14 −0 example.js
  2. +51 −0 npm-wrapper.js
  3. +15 −0 package.json
  4. +12 −0 readme.txt
@@ -0,0 +1,14 @@
+var npmwrapper = require('npm-wrapper').npmwrapper;
+
+var base_path = '/tmp/npm_test_1';
+var root_path = base_path + '/.root_path';
+var binroot_path = base_path + '/.bin_path';
+var manroot_path = base_path + '/.man_path';
+var action = 'install';
+var package = 'express';
+
+var n = new npmwrapper();
+n.setup(root_path, binroot_path, manroot_path, action, package);
+n.run(function (out) {
+ console.log(out);
+});
@@ -0,0 +1,51 @@
+var npm = require('npm');
+
+var npmwrapper = function () {
+ this.config = {};
+ this.command = "";
+ this.package = "";
+ this.output = "";
+};
+
+npmwrapper.prototype.setup = function (root_path, binroot_path, manroot_path, command, package) {
+ process.env.PATH = binroot_path + ":" + process.env.PATH;
+ this.command = command;
+ this.package = package;
+ this.config = {
+ color: false,
+ root: root_path,
+ binroot: binroot_path,
+ manroot: manroot_path,
+ argv: {
+ remain: [ package ],
+ cooked: [
+ command,
+ package,
+ '--root',
+ root_path,
+ '--binroot',
+ binroot_path,
+ '--manpath',
+ manroot_path
+ ],
+ original: [ ]
+ }
+ };
+ this.config.argv.original = this.config.argv.cooked;
+};
+
+npmwrapper.prototype.run = function (cb) {
+ var self = this;
+ npm.on('output', function (obj) {
+ self.output += obj.message + "\n";
+ npm.output = false;
+ });
+ npm.load(self.config, function (err) {
+ if (err) console.log(err);
+ npm.commands[self.command](self.config.argv.remain, function (err, data) {
+ cb(self.output);
+ });
+ });
+};
+
+exports.npmwrapper = npmwrapper;
@@ -0,0 +1,15 @@
+{
+ "name": "npm-wrapper",
+ "description": "A dumb class wrapper around npm to make it easy to manage stuff.",
+ "version": "0.0.1",
+ "homepage": "https://github.com/DanBUK/npm-wrapper",
+ "repository": "git://github.com/DanBUK/npm-wrapper.git",
+ "author": "Daniel Bartlett <dan@f-box.org> (https://github.com/DanBUK)",
+ "main": "./npm-wrapper",
+ "directories": {
+ "lib": ""
+ },
+ "engines": {
+ "node": "*"
+ }
+}
@@ -0,0 +1,12 @@
+npm-wrapper
+
+A very dump module to make using npm from scripts a little eaiser.
+
+Please see example.js for how to use.
+
+npmwrapper methods:
+ setup - Setup the job you want to run
+ run - Run the job with a callback with one argument with the output
+
+Installation
+> npm install npm-wrapper

0 comments on commit e09c5a5

Please sign in to comment.