Permalink
Browse files

emitting stdout data

  • Loading branch information...
1 parent c395b23 commit bfa568c3e61ea7532dcaa19cd1fdf80bc3b5415d @crcn crcn committed Dec 4, 2011
Showing with 75 additions and 36 deletions.
  1. +1 −0 gittyup
  2. +29 −14 lib/app.js
  3. +22 −7 lib/checkout/git.js
  4. +1 −1 lib/checkout/index.js
  5. +1 −2 lib/factory.js
  6. +1 −1 lib/link/index.js
  7. +10 −5 lib/link/javascript.js
  8. +1 −0 node_modules/.bin/beet
  9. +1 −0 node_modules/.bin/beet-install
  10. +1 −0 node_modules/beet
  11. +1 −0 node_modules/gumbo
  12. +6 −6 package.json
View
View
@@ -5,7 +5,8 @@ nodefs = require('node-fs'),
exec = require('child_process').exec,
fs = require('fs'),
Process = require('./process'),
-slug = require('./slug');
+slug = require('./slug'),
+EventEmitter = require('events').EventEmitter;
var App = Structr({
@@ -75,7 +76,7 @@ var App = Structr({
'checkout': function(ops, callback)
{
- var source, start;
+ var source, start, em = new EventEmitter();
if(typeof ops == 'string')
{
@@ -96,7 +97,7 @@ var App = Structr({
function onCheckout(err, result)
{
- console.log('done: ' + source);
+ em.emit('data','done: ' + source);
callback(err, result);
}
@@ -116,7 +117,7 @@ var App = Structr({
//checkout the source which could be from a number of sources
var ret = checkout({ source: source, app: self, output: appDir }, function(err, response)
{
- console.log('checked out: ' + source);
+ em.emit('data', 'checked out: ' + source);
if(err) return callback(err, response ? response.result : undefined);
@@ -169,13 +170,10 @@ var App = Structr({
self.remove(items.pop()._id);
}
});
-
-
- console.log('linking new app: ' + source);
-
+ em.emit('data', 'linking new app: ' + source);
- var linked = linkApp ? link(item, function(err, result)
+ var listener = linkApp ? link(item, function(err, result)
{
if(err)
{
@@ -189,16 +187,33 @@ var App = Structr({
//not linked? no prob
- if(!linked)
- {
+ if(!listener) {
onCheckout(err, item);
- }
+ } else {
+ listener.addListener('data', function(data) {
+ em.emit('data', data);
+ });
+ listener.addListener('error', function(data) {
+ em.emit('error', data);
+ })
+ }
});
});
- });
+ });
if(!ret) return callback('Cannot handle repo: '+ source);
- })
+
+ if(typeof ret == 'object') {
+ ret.addListener('data', function(data) {
+ em.emit('data', data);
+ });
+ ret.addListener('error', function(data) {
+ em.emit('error', data);
+ })
+ }
+ });
+
+ return em;
},
View
@@ -1,5 +1,7 @@
var child_process = require('child_process'),
-exec = child_process.exec;
+exec = child_process.exec,
+spawn = child_process.spawn,
+EventEmitter = require('events').EventEmitter;
exports.test = function(ops)
{
@@ -9,12 +11,25 @@ exports.test = function(ops)
exports.checkout = function(ops, callback)
{
console.log('using git to check out ' + ops.source);
+
+ var git = spawn('git',[ 'clone',ops.source,ops.output], { cwd: __dirname }),
+ em = new EventEmitter(),
+ err = false;
- exec('git clone ' + ops.source + ' ' + ops.output, { cwd: __dirname }, function(err, result)
- {
- callback(err, {
- result: result,
- link: true
- });
+
+ git.stdout.on('data', function(data) {
+ em.emit('data', data.toString());
});
+
+ git.stderr.on('data', function(data) {
+ em.emit('error', data.toString());
+ err = true;
+ })
+
+ git.on('exit', function() {
+
+ callback(err, { result: true, link: true });
+ });
+
+ return em;
}
View
@@ -1,6 +1,6 @@
module.exports = require('../factory')(__dirname, function(ops, module, callback)
{
- module.checkout(ops, callback);
+ return module.checkout(ops, callback);
});
View
@@ -20,8 +20,7 @@ module.exports = function(directory, factory)
if(m.test(ops))
{
- factory(ops, m, callback);
- return true;
+ return factory(ops, m, callback) || true;
}
}
View
@@ -1,6 +1,6 @@
module.exports = require('../factory')(__dirname, function(ops, module, callback)
{
- module.link(ops, callback);
+ return module.link(ops, callback);
})
View
@@ -1,5 +1,6 @@
var fs = require('fs'),
-spawn = require('child_process').spawn;
+spawn = require('child_process').spawn,
+EventEmitter = require('events').EventEmitter;
exports.test = function(ops)
{
@@ -33,22 +34,26 @@ exports.test = function(ops)
exports.link = function(ops, callback)
{
- console.log("Linking with npm: " + ops.appDir);
- var npm = spawn('sudo',['npm','install','--unsafe-perm'], { cwd: ops.appDir });
+ var npm = spawn('sudo',['npm','install','--unsafe-perm'], { cwd: ops.appDir }),
+ em = new EventEmitter();
+
+ em.emit('data', "Linking with npm: " + ops.appDir);
npm.stdout.on('data', function(data)
{
- console.log(data.toString());
+ em.emit('data', data.toString());
});
npm.stderr.on('data', function(data)
{
- console.error(data.toString());
+ em.emit('error', data.toString());
});
npm.on('exit', callback);
// exec('sudo npm install --unsafe-perm', { cwd: ops.appDir }, callback);
+ return em;
+
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,21 +1,21 @@
{
- "name":"gittyup",
+ "name": "gittyup",
"descriptions": "easy git deployment for node.js apps",
- "version": "0.0.21",
+ "version": "0.0.22",
"author": "Craig Condon <craig@crcn.com>",
"repository": {
"type": "git",
"url": "http://github.com/crcn/gittyup.git"
},
"main": "./lib/index.js",
"dependencies": {
- "structr":"*",
- "node-fs":"*",
- "gumbo":"*"
+ "structr": "*",
+ "node-fs": "*",
+ "gumbo": "*"
},
"os": [
"linux",
"darwin",
"freebsd"
]
-}
+}

0 comments on commit bfa568c

Please sign in to comment.