Skip to content

Commit

Permalink
Initial import, published to npm already.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanBUK committed Jan 24, 2011
0 parents commit e09c5a5
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
14 changes: 14 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -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);
});
51 changes: 51 additions & 0 deletions npm-wrapper.js
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": "*"
}
}
12 changes: 12 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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.