Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
exec vs spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleyg committed Nov 29, 2011
1 parent c38d95e commit bf72223
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions bin/nserv
Expand Up @@ -7,7 +7,8 @@ var commander = require('commander'),
exec = require('child_process').exec,
http = require('http'),
colors = require('colors'),
path = require('path');
path = require('path'),
spawn = require('child_process').spawn;

// vars
var choice = process.argv[2];
Expand Down Expand Up @@ -166,8 +167,7 @@ function addApp(domain, cb){
error(err, "Could not make base application directory.");
fs.mkdir(repo, '755', function(err){
error(err, "Could not make git repo directory.");
exec("cd " + repo + " && exec git init --bare", function(err, stdout, stderr){
error(err, "Could create application git repo.");
createRepo(repo, function(){
fs.readFile(placeholders + 'post-receive', function(err, data){
error(err, "Could not read post-receive hook.");
fs.writeFile(repo + 'hooks/post-receive', data, function(err){
Expand Down Expand Up @@ -257,6 +257,22 @@ function getPort(cb){
});
}

function createRepo(repo, cb){
var ps = spawn('git', [ 'init', '--bare', repo ]);
var err = '';
ps.stderr.on('data', function (data) {
err += data;
});
ps.on('exit', function (code) {
if(code !== null){
cb();
}
else {
error(err, "Could create application git repo.");
}
});
}

String.prototype.trim = function () {
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -19,4 +19,4 @@
"engines": {
"node": "0.4.12"
}
}
}

0 comments on commit bf72223

Please sign in to comment.