Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use NodeDomain instead of NodeConnection
We switched from a HTTP server responding with a EventSource body to Brackets' built-in RPC functionality. This removed some boilderplate code and allows us to send output without waiting for a line terminator. Fixes #43
- Loading branch information
Showing
8 changed files
with
128 additions
and
189 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
(function () { | ||
"use strict"; | ||
|
||
var treekill = require("treekill"), | ||
exec = require("child_process").exec, | ||
domain = null, | ||
child = null, | ||
DOMAIN_NAME = "brackets-nodejs"; | ||
|
||
function cmdStartProcess(command, cwd, cb) { | ||
if(child !== null) { | ||
treekill(child.pid); | ||
} | ||
|
||
child = exec(command, { | ||
cwd: cwd, | ||
silent: true | ||
}); | ||
|
||
// Send data to the client | ||
var send = function(data) { | ||
|
||
// Support for ansi colors and text decorations | ||
data = data.toString().replace(/\x1B\[/g, "\\x1B["); | ||
|
||
domain.emitEvent(DOMAIN_NAME, "output", data); | ||
}; | ||
|
||
child.stdout.on("data", send); | ||
child.stderr.on("data", send); | ||
|
||
child.on("exit", function(code) { | ||
cb(null, code); | ||
}); | ||
|
||
child.on("error", function(err) { | ||
cb(err); | ||
}); | ||
} | ||
|
||
function cmdStopProcess() { | ||
if(child !== null) { | ||
treekill(child.pid); | ||
} | ||
} | ||
|
||
function init(domainManager) { | ||
domain = domainManager; | ||
|
||
if(!domainManager.hasDomain(DOMAIN_NAME)) { | ||
domainManager.registerDomain(DOMAIN_NAME, { | ||
major: 0, | ||
minor: 0 | ||
}); | ||
} | ||
|
||
domainManager.registerCommand( | ||
DOMAIN_NAME, | ||
"startProcess", | ||
cmdStartProcess, | ||
true, | ||
"Starts the process using the supplied command", | ||
[ | ||
{ | ||
name: "command", | ||
type: "string" | ||
}, | ||
{ | ||
name: "cwd", | ||
type: "string" | ||
} | ||
] | ||
); | ||
|
||
domainManager.registerCommand( | ||
DOMAIN_NAME, | ||
"stopProcess", | ||
cmdStopProcess, | ||
false, | ||
"Stops the process if one is already started", | ||
[] | ||
); | ||
|
||
domainManager.registerEvent( | ||
DOMAIN_NAME, | ||
"output", | ||
[ | ||
{ | ||
name: "output", | ||
type: "string" | ||
} | ||
] | ||
); | ||
} | ||
|
||
exports.init = init; | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(process.env); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
for(var i = 0; i < 5; i++) { | ||
setTimeout(function() { | ||
process.stdout.write(". "); | ||
}, i * 1000); | ||
} |