-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
CLI_functions.js
125 lines (121 loc) · 6.26 KB
/
CLI_functions.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* @license
* Copyright 2020 Sébastien CANET
* SPDX-License-Identifier: GPL-3.0
*/
/**
* @fileoverview Arduino CLI control.
* @author [email protected] (Sébastien CANET)
*/
const {ipcRenderer} = require('electron');
const {exec} = require('child_process');
const fs = require('fs-extra');
window.addEventListener('load', function load(event) {
document.getElementById('coreUpdateButton').onclick = function (event) {
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = MSG['coreUpdateButton_msg'];
var cmd = 'arduino-cli.exe core update-index';
exec(cmd, {
cwd: './compiler'
}, (error, stdout, stderr) => {
if (error) {
document.getElementById('content_serial').style.color = '#FF0000';
document.getElementById('content_serial').innerHTML = stderr;
return;
}
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = stdout;
});
};
document.getElementById('cleanCLIcacheButton').onclick = function (event) {
var file_path = '.\\tmp';
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = MSG['cleanCLIcacheButton_msg'];
fs.remove(file_path, err => {
recursive: true;
if (err) {
return console.log(err);
document.getElementById('content_serial').style.color = '#FF0000';
document.getElementById('content_serial').innerHTML = MSG['cleanCLIcacheButton_error_msg'];
} else {
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = MSG['cleanCLIcacheButton_success_msg'];
}
});
};
document.getElementById('listBoardsButton').onclick = function (event) {
var cmd = 'arduino-cli.exe board list';
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = MSG['listBoardsButton_msg'];
exec(cmd, {
cwd: './compiler'
}, (error, stdout, stderr) => {
if (error) {
document.getElementById('content_serial').style.color = '#FF0000';
document.getElementById('content_serial').innerHTML = stderr;
document.getElementById('content_serial').scrollTop = stderr.offsetHeight + stderr.offsetTop;
return;
}
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = stdout;
document.getElementById('content_serial').scrollTop = stdout.offsetHeight + stdout.offsetTop;
});
};
document.getElementById('installBoardsButton').onclick = function (event) {
var cmd = 'arduino-cli.exe core install "' + document.getElementById("installBoardsInput").value + '"';
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = MSG['installBoardsButton_msg'];
exec(cmd, {
cwd: './compiler'
}, (error, stdout, stderr) => {
if (error) {
document.getElementById('content_serial').style.color = '#FF0000';
document.getElementById('content_serial').innerHTML = stderr;
document.getElementById('content_serial').scrollTop = stderr.offsetHeight + stderr.offsetTop;
return;
}
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = stdout;
document.getElementById('content_serial').scrollTop = stdout.offsetHeight + stdout.offsetTop;
});
};
document.getElementById('searchlLibButton').onclick = function (event) {
var cmd = 'arduino-cli.exe lib search "' + document.getElementById("searchlLibInput").value + '"';
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = MSG['searchlLibButton_msg'];
exec(cmd, {
cwd: './compiler'
}, (error, stdout, stderr) => {
if (error) {
document.getElementById('content_serial').style.color = '#FF0000';
document.getElementById('content_serial').innerHTML = stderr;
document.getElementById('content_serial').scrollTop = stderr.offsetHeight + stderr.offsetTop;
return;
}
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = stdout;
document.getElementById('content_serial').scrollTop = stdout.offsetHeight + stdout.offsetTop;
});
};
document.getElementById('installLibButton').onclick = function (event) {
var cmd = 'arduino-cli.exe lib install "' + document.getElementById("installLibInput").value + '"';
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = MSG['installLibButton_msg'];
exec(cmd, {
cwd: './compiler'
}, (error, stdout, stderr) => {
if (error) {
document.getElementById('content_serial').style.color = '#FF0000';
document.getElementById('content_serial').innerHTML = stderr;
document.getElementById('content_serial').scrollTop = stderr.offsetHeight + stderr.offsetTop;
return;
}
document.getElementById('content_serial').style.color = '#00FF00';
document.getElementById('content_serial').innerHTML = stdout;
document.getElementById('content_serial').scrollTop = stdout.offsetHeight + stdout.offsetTop;
//error sent without 'error' in function, need to double instruction
// document.getElementById('content_serial').style.color = '#FF0000';
// document.getElementById('content_serial').innerHTML += stderr;
});
};
});