UNPKG

hdw2

Version:

鸿蒙 hdc 调试工具

64 lines (57 loc) 1.34 kB
import os from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const TAG = '[hdw]'; export function debug(...args) { console.log(TAG, ...args); } /** * 操作系统映射 */ const OS_MAP = { win32: 'win', darwin: 'mac', linux: 'linux', }; /** * 架构映射 */ const ARCH_MAP = { x64: 'x86', ia32: 'x86', arm64: 'arm', arm: 'arm', }; /** * 获取配置文件路径 */ export function getPlatformArch() { const platform = os.platform(); const arch = os.arch(); const osPart = OS_MAP[platform] || platform; const archPart = ARCH_MAP[arch] || arch; return osPart && archPart ? `${osPart}-${archPart}` : ''; } /** * 获取hdc * @returns */ export function getHdc() { const platformArch = getPlatformArch(); debug('当前平台:', platformArch); if (platformArch === 'win-x86') { return path.join(__dirname, '../toolchains/win-x86/hdc'); } if (platformArch === 'mac-x86') { return path.join(__dirname, '../toolchains/mac-x86/hdc'); } if (platformArch === 'mac-arm') { return path.join(__dirname, '../toolchains/mac-arm/hdc'); } if (platformArch === 'linux-x86') { return path.join(__dirname, '../toolchains/linux-x86/hdc'); } return ''; }