debug(shell-micropython): 添加详细调试日志以定位引号错误

This commit is contained in:
yczpf2019
2026-01-24 20:02:11 +08:00
parent cc550ec5cc
commit c32583e3f4

View File

@@ -25,6 +25,13 @@ export default class ShellMicroPython extends Shell {
}
async upload(config) {
// 调试:打印接收到的原始配置
console.log('=== UPLOAD DEBUG START ===');
console.log('Received config.command:', JSON.stringify(config.command));
console.log('Received config.reset:', JSON.stringify(config.reset));
console.log('Received config.port:', config.port);
console.log('Received config.boardDirPath:', config.boardDirPath);
// 正确处理 reset 参数:如果是数组则序列化为 JSON 字符串
let resetValue = config.reset;
if (Array.isArray(resetValue)) {
@@ -32,6 +39,7 @@ export default class ShellMicroPython extends Shell {
} else if (resetValue === undefined || resetValue === null) {
resetValue = '[]';
}
console.log('Processed resetValue:', resetValue);
const info = {
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
@@ -39,11 +47,18 @@ export default class ShellMicroPython extends Shell {
com: config.port,
reset: resetValue
};
console.log('Info object:', JSON.stringify(info));
// 兼容性处理:移除模板中可能存在的冗余引号
let cmdTemplate = config.command || "";
console.log('Original cmdTemplate:', cmdTemplate);
cmdTemplate = cmdTemplate.replace(/"{ampy}"/g, '{ampy}');
console.log('After quote cleanup:', cmdTemplate);
const command = MString.tpl(cmdTemplate, info);
console.log('DEBUG CMD UPLOAD:', command);
console.log('Final command:', command);
console.log('=== UPLOAD DEBUG END ===');
return this.execUntilClosed(command);
}
}