Permalink
Browse files

more npm friendliness + getting ready to publish to npm registry

  • Loading branch information...
pdeschen committed Jun 17, 2011
1 parent 21a830b commit cf1fe2b44fec3b614bd07d443917a6b5e11aa2de
Showing with 120 additions and 57 deletions.
  1. +1 −0 .gitignore
  2. +0 −3 bin/nodast.initd
  3. +12 −1 lib/index.js
  4. +48 −0 lib/installer.js
  5. +2 −2 lib/proxy.js
  6. +41 −44 package.json
  7. +8 −2 readme.textile
  8. +0 −5 scripts/install.js
  9. +8 −0 scripts/nodast.initd
View
@@ -0,0 +1 @@
+/npm-debug.log
View
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-node nodast --daemon $@
View
@@ -14,13 +14,24 @@ exports.parse = function () {
cli.setApp($proxy.name, $proxy.version);
var options = cli.parse( {
- test : [ 't', 'Test location', 'string' ]
+ test : [ 't', 'Test location', 'string' ],
+ install : [ 'i', 'Install config file and init.d script' ]
});
if (options.test) {
var destination = require('./processor.js').test(options.test);
console.log(color('\t' + destination.hostname + ":" + destination.port, "green"));
+ } else if (options.install) {
+ console.log(color('\tinstalling...', "green"));
+ var installer = require('./installer.js');
+ installer.install(function (error) {
+ if (error) {
+ console.log(color('\t' + error, "red"));
+ }
+ console.log(color('\tdone', "green"));
+ });
} else {
+
cli.main(function (args, options) {
$proxy.start();
});
View
@@ -0,0 +1,48 @@
+var path = require('path'), fs = require('fs'), util = require('util'), spawn = require('child_process').spawn;
+
+var install = function (callback) {
+
+ var done = false;
+
+ process.on('uncaughtException', function (err) {
+ console.log('Caught exception: ' + err);
+ callback(err);
+ });
+
+ var handleError = function (error) {
+ if (error) {
+ callback(error);
+ }
+ };
+ var etc = process.env.npm_package_config_etc || '/etc/nodast/';
+ var initd = process.env.npm_package_config_initd || '/etc/init.d/';
+ path.exists(etc, function (exists) {
+ if (!exists) {
+ fs.mkdirSync(etc, 755);
+ }
+ var inStream = fs.createReadStream('./etc/nodast.js');
+ var outStream = fs.createWriteStream(etc + 'nodast.js', {
+ flags : 'w',
+ encoding : null,
+ mode : 644
+ });
+ util.pump(inStream, outStream, function (error) {
+ handleError(error);
+
+ var initdInStream = fs.createReadStream('./scripts/nodast.initd');
+ var initdOutStream = fs.createWriteStream(initd + 'nodast', {
+ flags : 'w',
+ encoding : null,
+ mode : 744
+ });
+ util.pump(initdInStream, initdOutStream, function (error) {
+ handleError(error);
+ var chkconfig = spawn('chkconfig', [ '--add', 'nodast' ]);
+ chkconfig.on('exit', function (code) {
+ callback();
+ });
+ });
+ });
+ });
+};
+exports.install = install;
View
@@ -1,5 +1,5 @@
var sys = require("sys"), net = require("net"), color = require("ansi-color").set, syslog =
- require('node-syslog').Syslog;
+ require('node-syslog');
var dir = process.env.npm_package_config_location || './../etc/';
var config = {
@@ -10,7 +10,7 @@ var config = {
syslog.init("nodast", syslog.LOG_PID | syslog.LOG_ODELAY, syslog.LOG_INFO);
process.on('uncaughtException', function (error) {
- syslog.log(syslog.LOG_ERROR, error);
+ syslog.Syslog.log(syslog.LOG_ERROR, error);
});
var proxy = function () {
View
@@ -1,45 +1,42 @@
{
- "name": "nodast",
- "description": "Asterisk FastAgi Proxy",
- "version": "0.0.1",
- "author": "Pascal Deschenes <pdeschen@rassemblr.com> (http://blog.rassemblr.com)",
- "homepage": "http://github.com/pdeschen/nodast",
- "preferGlobal": true,
- "keywords": ["telephony", "asterisk", "proxy", "fastagi"],
- "directories": {
- "lib": "./lib",
- "bin": "./bin",
- "etc": "./etc"
- },
- "main": "nodeast",
- "config": {
- "location": '/etc/nodast/'
- },
- "bin": {
- "nodast": "./bin/nodast"
- },
- "repository": {
- "type": "git",
- "url": "http://github.com/pdeschen/nodast.git"
- },
- "scripts": {
- "install": "./scripts/install.js"
- },
- "bugs": {
- "email": "pdeschen+nodast@gmail.com",
- "url": "http://github.com/pdeschen/nodast/issues"
- },
- "dependencies": {
- "cli": "1",
- "ansi-color": "1",
- "node-syslog": "1"
- },
- "engines": {
- "node": "0.4 || 0.5",
- "npm": "1"
- },
- "licenses": [{
- "type": "MIT",
- "url": "http://github.com/pdeschen/nodast/raw/master/LICENSE"
- }]
-}
+ "author": "Pascal Deschenes <pdeschen@rassemblr.com> (http://blog.rassemblr.com/)",
+ "name": "nodast",
+ "description": "Asterisk FastAgi Proxy",
+ "version": "0.0.1",
+ "homepage": "http://github.com/pdeschen/nodast",
+ "preferGlobal": true,
+ "keywords": ["telephony", "asterisk", "proxy", "fastagi"],
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/pdeschen/nodast.git"
+ },
+ "main": "nodast",
+ "directories": {
+ "lib": "./lib",
+ "bin": "./bin",
+ "etc": "./etc"
+ },
+ "config": {
+ "etc": "/etc/nodast/",
+ "initd": "/etc/init.d/"
+ },
+ "bin": {
+ "nodast": "./bin/nodast"
+ },
+ "bugs": {
+ "email": "pdeschen+nodast@gmail.com",
+ "url": "http://github.com/pdeschen/nodast/issues"
+ },
+ "engines": {
+ "node": "v0.4.5"
+ },
+ "dependencies": {
+ "cli": "0.3.x",
+ "daemon": "0.3.x",
+ "ansi-color": "0.2.x",
+ "node-syslog": "1.0.x",
+ "mime": "1.2.x"
+ },
+ "devDependencies": {}
+}
+
View
@@ -73,9 +73,15 @@ h2. Installation
h3. Git Clone
-h3. Install from npm:
+@$ git clone git://github.com/pdeschen/nodast.git@
-@$ npm install nodast@
+h3. Install from npm
+
+@$ sudo npm install nodast -g@
+
+h3. Install the /etc/nodast config and /etc/init.d/nodast daemon script
+
+@$ sudo nodast --install@
h2. Todo
View
@@ -1,5 +0,0 @@
-// create config location dir
-// copy default config to config location
-// create init.d dir
-// copy init.d script
-// run chkconfig
View
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# nodast This shell script takes care of starting and stopping nodast server.
+#
+# chkconfig: 2345 65 35
+# description: nodast Asterisk FastAgi Proxy Server
+
+nodast --daemon $@

0 comments on commit cf1fe2b

Please sign in to comment.