var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
var spawner = {};

spawner.parse = function(dir, callback) {
	file = fs.readFile(path.normalize(dir+"/package.json"));
	if(!file) {
		callback(new Error("package.json in "+dir+" was not found!"), null);
		return;
	}
	package = JSON.parse(file);
}

spawner.run = function() {
	var logfile = "~/"+random()+".log";
	var out = fs.openSync(logfile, 'a');
	var err = fs.openSync(logfile, 'a');
	var child = spawn('prg', [], {
		detached: true,
		stdio: [ 'ignore', out, err ]
	});

	child.unref();
}

spawner.apps = {};

spawner.random = function() {
	var text = "";
	var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

	for( var i=0; i < 5; i++ ) {
		text += possible.charAt(Math.floor(Math.random() * possible.length));
	}

	return text;
}

module.exports = spawner;
@@ -305,16 +305,24 @@
 urn;%0A%09%7D%0A
+%09try %7B%0A%09
 %09package
@@ -346,43 +346,147 @@
 e);%0A
-%7D%0A%0Aspawner.run = function() %7B%0A%09var 
+%09%09callback(null, package);%0A%09%7D catch(exception e) %7B%0A%09%09callback(e, null);%0A%09%7D%0A%7D%0A%0Aspawner.run = function(repo, callback) %7B%0A%09var app = %7B%7D;%0A%09app.
 logf
@@ -494,16 +494,22 @@
 le = %22~/
+.hype/
 %22+random
@@ -520,20 +520,20 @@
 .log%22;%0A%09
-var 
+app.
 out = fs
@@ -562,50 +562,130 @@
 );%0A%09
-var err = fs.openSync(logfile, 'a');%0A%09var 
+app.package = spawner.parse(repo.cloneDir, function(err, pack) %7B%0A%09%09if(err) %7B%0A%09%09%09callback(err, null);%0A%09%09%09return;%0A%09%09%7D%0A%09%09app.
 chil
@@ -698,13 +698,8 @@
 awn(
-'prg'
 , %5B%5D
@@ -704,16 +704,17 @@
 %5B%5D, %7B%0A%09%09
+%09
 detached
@@ -721,16 +721,17 @@
 : true,%0A
+%09
 %09%09stdio:
@@ -752,21 +752,27 @@
 ut, 
-err
+out
  %5D%0A
+%09
 %09%7D);%0A%0A%09
+%09app.
 chil
@@ -782,16 +782,47 @@
 nref();%0A
+%09%09spawner.apps.push(app);%0A%09%7D);%0A
 %7D%0A%0Aspawn

add more OO to spawner.js