70 lines
2.2 KiB
JavaScript
Executable File
70 lines
2.2 KiB
JavaScript
Executable File
import _ from 'lodash';
|
||
import Shell from './shell.js';
|
||
import { ARDUINO } from './config.js';
|
||
|
||
|
||
export default class ShellArduino extends Shell {
|
||
constructor() {
|
||
super();
|
||
}
|
||
|
||
async compile(config) {
|
||
let arduino = _.merge({}, ARDUINO);
|
||
arduino = _.merge(arduino, config);
|
||
|
||
// 构建参数数组,避免 shell 解析引号问题
|
||
const args = [
|
||
'compile',
|
||
'-b', arduino.key,
|
||
'--config-file', arduino.path.config,
|
||
'--verbose'
|
||
];
|
||
|
||
// 为每个 library 路径添加参数
|
||
// 注意:config.json 中的路径是指向包含多个库的集合目录,所以必须用 --libraries
|
||
// 如果用 --library,arduino-cli 会尝试把该目录当作单个库处理,导致找不到头文件报错
|
||
for (const lib of arduino.path.libraries) {
|
||
args.push('--libraries', lib);
|
||
}
|
||
|
||
args.push(
|
||
'--build-path', arduino.path.build,
|
||
'--output-dir', arduino.path.output,
|
||
arduino.path.code,
|
||
'--no-color'
|
||
);
|
||
|
||
return this.execFileUntilClosed(arduino.path.cli, args, { maxBuffer: 4096 * 1000000 });
|
||
}
|
||
|
||
async upload(config) {
|
||
let arduino = _.merge({}, ARDUINO);
|
||
arduino = _.merge(arduino, config);
|
||
|
||
// 构建参数数组,避免 shell 解析引号问题
|
||
const args = [
|
||
'compile',
|
||
'--upload',
|
||
'-p', arduino.port,
|
||
'-b', arduino.key,
|
||
'--config-file', arduino.path.config,
|
||
'--verbose'
|
||
];
|
||
|
||
// 为每个 library 路径添加参数
|
||
// 注意:config.json 中的路径是指向包含多个库的集合目录,所以必须用 --libraries
|
||
// 如果用 --library,arduino-cli 会尝试把该目录当作单个库处理,导致找不到头文件报错
|
||
for (const lib of arduino.path.libraries) {
|
||
args.push('--libraries', lib);
|
||
}
|
||
|
||
args.push(
|
||
'--build-path', arduino.path.build,
|
||
'--output-dir', arduino.path.output,
|
||
arduino.path.code,
|
||
'--no-color'
|
||
);
|
||
|
||
return this.execFileUntilClosed(arduino.path.cli, args, { maxBuffer: 4096 * 1000000 });
|
||
}
|
||
} |