forked from c9/cloud9
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoderunner.js
More file actions
173 lines (141 loc) · 5.15 KB
/
Copy pathnoderunner.js
File metadata and controls
173 lines (141 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* Node Runner Module for the Cloud9 IDE
*
* @copyright 2010, Ajax.org B.V.
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
*/
define(function(require, exports, module) {
var ide = require("core/ide");
var ext = require("core/ext");
var util = require("core/util");
var markup = require("text!ext/noderunner/noderunner.xml");
return ext.register("ext/noderunner/noderunner", {
name : "Node Runner",
dev : "Ajax.org",
type : ext.GENERAL,
alone : true,
offline : false,
markup : markup,
commands: {
"run": {
"hint": "run a node program on the server",
"commands": {
"[PATH]": {"hint": "path pointing to an executable. Autocomplete with [TAB]"}
}
}
},
init : function(amlNode){
ide.addEventListener("socketDisconnect", this.onDisconnect.bind(this));
ide.addEventListener("socketMessage", this.onMessage.bind(this));
dbgNode.addEventListener("onsocketfind", function() {
return ide.socket;
});
stDebugProcessRunning.addEventListener("activate", this.$onDebugProcessActivate.bind(this));
stDebugProcessRunning.addEventListener("deactivate", this.$onDebugProcessDeactivate.bind(this));
ide.addEventListener("consolecommand.run", function(e) {
ide.socket.send(JSON.stringify({
command: "internal-isfile",
argv: e.data.argv,
cwd: e.data.cwd,
sender: "noderunner"
}));
return false;
});
},
$onDebugProcessActivate : function() {
dbg.attach(dbgNode, 0);
},
$onDebugProcessDeactivate : function() {
dbg.detach();
},
onMessage : function(e) {
var message = e.message;
// console.log("MSG", message)
switch(message.type) {
case "node-debug-ready":
ide.dispatchEvent("debugready");
break;
case "chrome-debug-ready":
winTab.show();
dbgChrome.loadTabs();
ide.dispatchEvent("debugready");
break;
case "node-exit":
stProcessRunning.deactivate();
stDebugProcessRunning.deactivate();
break;
case "state":
stDebugProcessRunning.setProperty("active", message.debugClient);
dbgNode.setProperty("strip", message.workspaceDir + "/");
ide.dispatchEvent("noderunnerready");
break;
case "error":
/*
6:
401: Authorization Required
*/
if (message.code !== 6 && message.code != 401) {
//util.alert("Server Error", "Server Error "
// + (message.code || ""), message.message);
txtConsole.addValue("<div class='item console_log' style='font-weight:bold;color:#ff0000'>[C9 Server Exception "
+ (message.code || "") + "] " + message.message.message + "</div>");
apf.ajax("/debug", {
method : "POST",
contentType : "application/json",
data : apf.serialize({
agent : navigator.userAgent,
type : "C9 SERVER EXCEPTION",
code : e.code,
message : e.message
// log : apf.console.debugInfo.join("\n")
})
});
}
ide.socket.send('{"command": "state"}');
break;
}
},
onDisconnect : function() {
stDebugProcessRunning.deactivate();
},
debugChrome : function() {
var command = {
"command" : "RunDebugChrome",
"file" : ""
};
ide.socket.send(JSON.stringify(command));
},
debug : function() {
this.$run(true);
},
run : function(path, args, debug) {
if (stProcessRunning.active || !stServerConnected.active || !path || typeof path != "string")
return false;
var page = ide.getActivePageModel();
var command = {
"command" : debug ? "RunDebugBrk" : "Run",
"file" : path.replace(/^\/+/, ""),
"runner" : ddRunnerSelector.value, // Explicit addition; trying to affect as less logic as possible for now...
"args" : args || "",
"env" : {
"C9_SELECTED_FILE": page ? page.getAttribute("path").slice(ide.davPrefix.length) : ""
}
};
ide.socket.send(JSON.stringify(command));
if (debug)
stDebugProcessRunning.activate();
stProcessRunning.activate();
},
stop : function() {
if (!stProcessRunning.active)
return
ide.socket.send(JSON.stringify({"command": "kill"}));
},
enable : function(){
},
disable : function(){
},
destroy : function(){
}
});
});