-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
57 lines (54 loc) · 1.6 KB
/
main.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
function run_cmd(cmd, args, cb, end) {
var spawn = require('child_process').spawn,
child = spawn(cmd, args),
me = this;
child.stdout.on('data', function (buffer) { cb(me, buffer) });
child.stdout.on('end', end);
}
var foo = new run_cmd(
'force', [
'login',
'-u=<put_username_here>',
'-p=<put_password_here>'
],
function (me, buffer) { me.stdout += buffer.toString() },
function () { console.log(foo.stdout) }
);
document.getElementById('test-soql').addEventListener('click', function (e) {
var textArea = document.querySelector('#editor');
var outputDiv = document.querySelector('#output');
if(textArea.value.trim() !== '') {
var args1 = ['query', textArea.value];
var foo = new run_cmd(
'force', args1,
function (me, buffer) { me.stdout += buffer.toString() },
function () {
var outputStr = foo.stdout;
if(outputStr !== undefined)
{
outputStr = outputStr.replace(/(?:\r\n|\r|\n)/g, '<br />');
if(outputStr.indexOf('undefined') > -1){
outputStr = outputStr.replace('undefined', '');
}
outputDiv.innerHTML = outputStr;
outputDiv.style.display = 'block';
} else {
outputDiv.innerHTML = 'No Data';
outputDiv.style.display = 'block';
}
}
);
}
});
var gui = require('nw.gui');
var win = gui.Window.get();
win.on('closed', function() {
foo = new run_cmd(
'force', [
'logout',
'-u=<put_username_here>'
],
function (me, buffer) { me.stdout += buffer.toString() },
function () { console.log(foo.stdout) }
);
});