-
Notifications
You must be signed in to change notification settings - Fork 6
/
ideTools.js
109 lines (89 loc) · 3.14 KB
/
ideTools.js
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
var exec = require('child_process').exec;
var stopPressed = false;
$(document).ready(function(){
$('#compileBtn').on('click', function(){ compile(); });
$('#runBtn').on('click', function(){ run(); });
$('#stopBtn').on('click', function(){
if(!stopPressed) {
stopPressed = true;
stop();
}
});
});
function compile() {
var fileAbsolutePath = `"${curFile.path}"`,
fileContainerPath = `"${getDirectoryParentPath(curFile.path)}"`,
fileName = `"${curFile.name.substr(0, curFile.name.indexOf("."))}"`;
// Save current file
curFile.data = getData();
saveFile(curFile);
setLanguage( getExtensionFromName(curFile.path) );
//Status Update
$('#outputTab').val('Compiling...');
//Show IO Panel
showIOPanel(true);
//Execute compile code from "buildFilePath"
const command = eval('`' + curLang.compileCommand + '`');
execute(command, function(error, stderr, stdout) {
displayCompileResults(error, stderr, stdout);
});
}
function run() {
var fileAbsolutePath = `"${curFile.path}"`,
fileContainerPath = `"${getDirectoryParentPath(curFile.path)}"`,
fileName = `"${curFile.name.substr(0, curFile.name.indexOf("."))}"`;
//Save input file
inputFile.data = $('#inputTab').val();
saveFile(inputFile);
console.log('>'+curFile.path)
setLanguage( getExtensionFromName(curFile.path) );
console.log(">RUN")
//Status Update
$('#outputTab').val('Executing...');
//Show IO Panel
showIOPanel(true);
const command = eval('`' + curLang.runCommand + '`');
outputFile.data = '';
saveFile(outputFile);
execute(command, function(error, stderr, stdout) {
displayRunResults(error, stderr, stdout);
});
}
function stop() {
var fileAbsolutePath = `"${curFile.path}"`,
fileContainerPath = `"${getDirectoryParentPath(curFile.path)}"`,
fileName = `"${curFile.name.substr(0, curFile.name.indexOf("."))}"`;
setLanguage( getExtensionFromName(curFile.path) );
const command = eval('`' + curLang.stopCommand + '`');
execute(command, function(error, stderr, stdout) {
displayCompileResults(error, stderr, stdout);
$('#outputTab').val('Process Stopped!');
stopPressed = false;
});
}
function displayCompileResults(error, stderr, stdout) {
var out = '';
if(stderr.length>0)
out = out+stderr+'\n';
if(stdout.length>0)
out = out+stdout+'\n';
if(out.length == 0 || out.indexOf("1 file(s) moved.")!=-1) out='Compiled Successfully!';
$('#outputTab').val(out);
}
function displayRunResults(error, stderr, stdout) {
var out = '';
if(stderr.length>0)
out = out+stderr+'\n';
if(stdout.length>0)
out = out+stdout+'\n';
if(stopPressed)
$('#outputTab').val('Execution Interrupted!');
else
fileRead(outputFile, function(data){
out = out+data+'Execution Completed!';
$('#outputTab').val(out);
});
}
function execute(command, callback){
exec(command, function(error, stdout, stderr){ callback(error, stderr, stdout); });
};