wangyj
Version:
wangyj 个人常用命令库
52 lines (51 loc) • 2.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTargetPath = void 0;
const node_child_process_1 = require("node:child_process");
const formatOutput_1 = require("../../../utils/formatOutput");
const node_path_1 = require("node:path");
const node_process_1 = require("node:process");
// 获取VSCode的安装路径
function getVSCodeAppRoot() {
try {
let codePath;
if (node_process_1.platform === "win32") {
// Windows:通过where查找code.cmd路径
codePath = (0, node_child_process_1.execSync)("where code", { stdio: ["pipe", "pipe", "ignore"] })
.toString()
.trim()
.split("\r\n")[0];
if (!codePath)
throw new Error("未找到code命令");
// 安装目录为bin的上级目录
const installDir = (0, node_path_1.dirname)((0, node_path_1.dirname)(codePath));
return (0, node_path_1.join)(installDir, "resources", "app");
}
else {
// macOS/Linux:通过which查找code路径并解析符号链接
codePath = (0, node_child_process_1.execSync)("which code", { stdio: ["pipe", "pipe", "ignore"] })
.toString()
.trim();
if (!codePath)
throw new Error("未找到code命令");
const realPath = (0, node_child_process_1.execSync)(`readlink -f "${codePath}"`).toString().trim();
// 推导app目录(假设路径结构为.../app/bin/code)
const appRoot = (0, node_path_1.resolve)(realPath, "../../..");
return appRoot;
}
}
catch (err) {
(0, formatOutput_1.formatOutput)("错误:", err.message, 'error');
return null;
}
}
const getTargetPath = () => {
const vsCodeAppRoot = getVSCodeAppRoot();
if (vsCodeAppRoot) {
return (0, node_path_1.join)(vsCodeAppRoot, "out", "vs", "workbench", "workbench.desktop.main.css");
}
else {
return null;
}
};
exports.getTargetPath = getTargetPath;