You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qmk_firmware/flasher/util.js

43 lines
1.2 KiB

const Chalk = require('chalk');
module.exports.IdentifyKeyboard = function IdentifyKeyboard (name = 'Kiibohd DFU', path, limit = true) {
const boards = execSync(`dfu-util --list`).toString()
.split('\n')
.filter(line => line.match(/(\[\w+\:\w+\])/g) != null)
.map(line => ({
name: /name="([\w\s]+)"/g.exec(line)[1],
id: /(\[\w+\:\w+\])/g.exec(line)[1]
}))
.filter(device => device.name === name && path != null ? device.path === path : true);
if (limit) {
return boards[0];
} else {
return boards;
}
}
module.exports.Exec = function Exec (command) {
return new Promise((resolve, reject) => {
console.log(command);
const proc = exec(command, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
const line_start = Chalk.blue(']\t');
proc.stdout.on('data', data => console.log(line_start + data.replace(/\n$/, '').replace(/\n/g, `\n${line_start}`)));
});
}
module.exports.Echo = function Echo (...logs) {
for(const log of logs) {
if (typeof log === 'string') {
console.log(log);
} else {
console.log(log.toString ? log.toString() : log);
}
}
}