Permalink
Browse files

add .use(), document methods

  • Loading branch information...
1 parent 80530ee commit afd39e7601c4fbbf0df5716d51319a6a1a0cb333 @substack committed Feb 27, 2012
Showing with 47 additions and 10 deletions.
  1. +28 −0 README.markdown
  2. +18 −9 index.js
  3. +1 −1 package.json
View
28 README.markdown
@@ -75,6 +75,34 @@ Usage:
List all the running processes on all the drones.
```
+methods
+=======
+
+var propagit = require('propagit')
+
+var p = propagit(opts)
+----------------------
+
+Create a new propagit object with `opts`:
+
+* secret - authenticate with this passphrase
+* hub - if specified, connect to this hub
+
+p.drone()
+---------
+
+Register with the connected hub as a drone.
+
+propagit.listen(controlPort, gitPort)
+-------------------------------------
+
+Create a new hub on `controlPort` and start a git http server on `gitPort`.
+
+propagit.use(fn)
+----------------
+
+Modify the dnode server or client service with `fn(service)`.
+
install
=======
View
27 index.js
@@ -31,6 +31,7 @@ function Propagit (opts) {
this.readable = true;
this.secret = opts.secret;
+ this.middleware = [];
var base = opts.basedir || process.cwd();
this.repodir = path.resolve(opts.repodir || base + '/repos');
@@ -69,6 +70,10 @@ Propagit.prototype.connect = function (hub) {
return self;
};
+Propagit.prototype.use = function (fn) {
+ this.middleware.push(fn);
+};
+
Propagit.prototype.listen = function (controlPort, gitPort) {
var self = this;
mkdirp(self.repodir);
@@ -189,6 +194,10 @@ Propagit.prototype.createService = function (remote, conn) {
}
};
+ self.middleware.forEach(function (m) {
+ m(service);
+ });
+
return service;
};
@@ -273,7 +282,7 @@ Propagit.prototype.drone = function (fn) {
}, {}));
};
- actions.spawn = function (opts, emit) {
+ actions.spawn = function (opts) {
var repo = opts.repo;
var commit = opts.commit;
var dir = path.join(self.deploydir, repo + '.' + commit);
@@ -297,32 +306,32 @@ Propagit.prototype.drone = function (fn) {
};
ps.stdout.on('data', function (buf) {
- if (emit) emit('data', buf.toString());
self.emit('stdout', buf, opts);
});
ps.stderr.on('data', function (buf) {
- if (emit) emit('data', buf.toString());
self.emit('stderr', buf, opts);
});
ps.once('exit', function (code, sig) {
- if (emit) emit('exit', code, sig);
self.emit('exit', code, sig, opts);
if (proc.status !== 'stopped') {
proc.status = 'respawning';
setTimeout(respawn, 1000);
}
});
- if (emit) emit('spawn', id, opts);
self.emit('spawn', id, opts);
})();
};
actions.id = (Math.random() * Math.pow(16,8)).toString(16);
if (typeof fn === 'function') fn.call(self, actions);
+ self.middleware.forEach(function (m) {
+ m(actions);
+ });
+
function onup (remote) {
remote.register('drone', actions);
}
@@ -334,22 +343,21 @@ Propagit.prototype.drone = function (fn) {
return self;
};
-Propagit.prototype.stop = function (opts, id) {
+Propagit.prototype.stop = function (opts, id, cb) {
var self = this;
if (typeof opts === 'string') {
id = opts;
opts = undefined;
}
- var stream = new Stream;
stream.readable = true;
(opts ? self.getDrones(opts) : self.drones).forEach(function (drone) {
- drone.stop(id, stream.emit.bind(stream));
+ drone.stop(id, cb);
});
- return stream;
+ return self;
};
Propagit.prototype.spawn = function (opts) {
@@ -370,6 +378,7 @@ Propagit.prototype.deploy = function (opts, cb) {
self.hub(function (hub) {
hub.deploy(opts, function () {
self.emit('deploy');
+ if (cb) cb();
});
});
View
2 package.json
@@ -1,7 +1,7 @@
{
"name" : "propagit",
"description" : "cascading multi-server git deployment",
- "version" : "0.3.0",
+ "version" : "0.4.0",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/propagit.git"

0 comments on commit afd39e7

Please sign in to comment.