feat: 优化跨平台路径解析并修复引号拼接 Bug

This commit is contained in:
yczpf2019
2026-01-24 16:02:28 +08:00
parent 0bdd6b4dc6
commit d5aa1c6c8c
4 changed files with 28 additions and 32 deletions

View File

@@ -4,18 +4,34 @@ import fsExtra from 'fs-extra';
function processConfig(data) {
const resolvePath = (p) => {
if (!p || typeof p !== 'string') {
return p;
}
// 如果是系统命令(不含路径斜杠),不作为路径处理,直接返回原名
if (!p.includes('/') && !p.includes('\\')) {
return p;
}
// 如果已经是绝对路径,则直接返回
if (path.isAbsolute(p)) {
return p;
}
// 否则解析为相对于当前工作目录的路径
return path.resolve(process.cwd(), p);
};
for (let i in data.path) {
if (!data.path[i]) {
continue;
}
if (typeof data.path[i] === 'string') {
data.path[i] = path.resolve(process.cwd(), data.path[i]);
data.path[i] = resolvePath(data.path[i]);
} else if (typeof data.path[i] === 'object') {
for (let j in data.path[i]) {
if (typeof data.path[i][j] !== 'string') {
continue;
}
data.path[i][j] = path.resolve(process.cwd(), data.path[i][j]);
data.path[i][j] = resolvePath(data.path[i][j]);
}
}
}

View File

@@ -12,7 +12,7 @@ export default class ShellMicroPython extends Shell {
async burn(config) {
const info = {
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
esptool: `${PYTHON.path.cli}" "${MICROPYTHON.path.esptool}`,
esptool: `"${PYTHON.path.cli}" "${MICROPYTHON.path.esptool}`,
com: config.port
};
const command = MString.tpl(config.command, info);
@@ -22,7 +22,7 @@ export default class ShellMicroPython extends Shell {
async upload(config) {
const info = {
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
ampy: `${PYTHON.path.cli}" "${MICROPYTHON.path.ampy}`,
ampy: `"${PYTHON.path.cli}" "${MICROPYTHON.path.ampy}`,
com: config.port
};
const command = MString.tpl(config.command, info);