Permalink
Browse files

reverted - breaks some commands such as sublimes subl

  • Loading branch information...
1 parent 1cf6a9a commit 3d0a96a44cbbdaf6e8dcbbc1b619c51320ac7b35 @crcn crcn committed Mar 5, 2012
Showing with 120 additions and 67 deletions.
  1. +2 −3 .cupboard
  2. BIN lib/beans/.DS_Store
  3. +6 −0 lib/beans/cbd.projects/execute
  4. +60 −47 lib/beans/cbd.projects/processor.js
  5. +52 −17 project.sublime-workspace
View
@@ -1,6 +1,5 @@
[commands]
-proj = subl --project project.sublime-project
-
+proj = subl -b --project project.sublime-project
[ignore]
-project.sublime-\w+
+project.sublime-\w+
View
Binary file not shown.
@@ -0,0 +1,6 @@
+#!/bin/bash -e
+
+eval "$@ &"
+
+# this gets parsed out
+echo "CHILD-PID:$!"
@@ -8,12 +8,12 @@ exec = require('child_process').exec;
*/
var Script = Structr({
-
+
/**
*/
-
+
'__construct': function(processor, script, ops) {
-
+
this._processor = processor;
this._script = script;
this._em = new EventEmitter();
@@ -22,89 +22,102 @@ var Script = Structr({
this.coloredName = (this._project.name()+':')[Processor.nextTermColor()].bold;
},
-
+
/**
*/
-
+
'_log': function(data) {
data = data.toString();
-
- var self = this;
-
+
+ var pid = data.match(/CHILD-PID\:(\d+)/),
+ self = this;
+
+ if(pid) {
+ self._cpid = Number(pid[1]);
+ return;
+ }
+
+
data.replace(/[\s\r\n]+$/,'').split(/[\r\n]+/g).forEach(function(msg) {
-
+
console.log('%s %s', self.coloredName, msg);
});
},
-
+
/**
*/
-
+
'execute': function(ops, callback) {
-
+
this._em.addListener('complete', callback);
//already running, skip
if(!!this._proc) return;
-
-
+
+
var self = this,
script = this._script.replace(/,/g,';').replace(/\$@/g, ops.args.join(' ')),
project = this._project;
-
-
+
+
//replace "script with passed args"
for(var param in ops.data) {
var search = new RegExp('\\\$\{'+param+'\}');
script = script.replace(search, ops.data[param]);
}
- var proc = this._proc = exec(script, { cwd: project.path() });
-
+ var proc = this._proc = spawn(__dirname + '/execute', [script], { cwd: project.path() });
+
+
function log(data) {
self._log(data);
}
-
+
log(script.bold);
-
-
+
+
+ //send user notification if installed ~ growl
+ // this._router.push('user/notification', { message: ops.command + " " + this._project.name() });
+
+
proc.stdout.on('data', log);
proc.stderr.on('data', log);
proc.on('exit', function(code, signal) {
self._proc = null;
-
+
// log('done');
-
+
var killed = code !== 0;
-
+
self._em.emit('complete', killed ? new Error('killed') : null, !killed ? 1 : null);
self._em.removeAllListeners('complete');
});
-
-
+
+
return this;
},
-
+
/**
*/
-
+
'kill': function(onKilled) {
-
+
var self = this;
-
+
if(!this._proc) return onKilled(this);
-
+
//self._log('killing: '+ this._script.bold);
-
+
this._em.addListener('complete', function() {
onKilled(self);
});
-
- this._proc.kill();
+
+
+ process.kill(this._cpid, 'SIGKILL');
this._proc = null;
}
-
+
});
@@ -113,20 +126,20 @@ var Processor = module.exports = Structr({
/**
*/
-
+
'__construct': function(project) {
this.project = project;
this._scripts = {};
this.termColor = Processor.nextTermColor();
},
-
+
/**
*/
-
+
'execute': function(script, ops, callback) {
var scr = this._scripts[script],
self = this;
-
+
function onReady(scr) {
scr.execute(ops, callback);
}
@@ -138,30 +151,30 @@ var Processor = module.exports = Structr({
onReady(this._scripts[script] = new Script(self, script, ops));
}
},
-
+
/**
*/
-
+
'static nextTermColor': function() {
-
+
if(!this._colors) {
-
+
this._colors = ['green','blue','yellow','magenta','cyan','grey'];
this._curColor = 0;
}
-
+
return this._colors[this._curColor++ % this._colors.length ];
},
-
+
/**
* singleton is used because the project model is instantiated each time find is called.
*/
-
+
'static getInstance': function(project) {
if(!this._processors) {
this._processors = {};
}
-
+
return this._processors[project.name()] || (this._processors[project.name()] = new module.exports(project));
}
});
Oops, something went wrong.

0 comments on commit 3d0a96a

Please sign in to comment.