-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·59 lines (45 loc) · 1.45 KB
/
Copy pathbuild
File metadata and controls
executable file
·59 lines (45 loc) · 1.45 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
#!/usr/bin/env node
const exec = require('child_process').exec;
const FQBN = "adafruit:samd:adafruit_pygamer_m4";
var PORT = "";
// execute a command and get output
const execute = (command, callback) => {
exec(command, function(error, stdout, stderr) { callback(stdout, stderr); });
};
// abort program
const abort = (msg) => {
console.log(msg);
process.exitCode = -1;
process.exit();
};
const log = (msg) => {
console.log("\x1b[32m" + msg + "\x1b[0m");
}
if (require.main === module) {
// get port
execute("arduino-cli board list", (output, stderr) => {
if (stderr.length !== 0)
abort("Failed to locate device.");
var devices = output.split('\n');
devices.forEach((str, i) => {
if (str.includes(FQBN)) {
PORT = str.split(' ', 1)[0];
}
});
if (PORT.length === 0)
abort("Failed to locate device.");
log("\t[✔] Port Found");
// compile
execute("arduino-cli compile --fqbn " + FQBN + " .", (output, stderr) => {
if (stderr.length !== 0)
abort(stderr);
log("\t[✔] Compilation Successful");
// upload
execute("arduino-cli upload --fqbn " + FQBN + " --port " + PORT, (output, stderr) => {
if (stderr.length !== 0)
abort(stderr);
log("\t[✔] Upload Successful");
});
});
});
}