UNPKG

multi-automator

Version:
77 lines (76 loc) 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAppList = exports.uninstallApp = exports.installApp = exports.devices = void 0; /** * @desc: iOS Device Operation * @author: john_chen * @date: 2025.01.12 */ const child_process_1 = require("child_process"); async function devices() { let { stdout, stderr, status } = (0, child_process_1.spawnSync)('idevice_id -l', { shell: true, timeout: 20000, }); if (0 !== status) { throw new Error(`未正确安装 idevice_id: ${stderr.toString()},请执行命令 'brew install libimobiledevice' 进行安装`); } let deviceConnectMap = {}; for (let uuid of stdout.toString().split('\n')) { const trimUuid = uuid.trim(); if (trimUuid) { deviceConnectMap[trimUuid] = { status: 0 }; } } return deviceConnectMap; } exports.devices = devices; async function installApp(uuid, appPath) { let { stderr, status } = (0, child_process_1.spawnSync)(`ideviceinstaller --install ${appPath} -u ${uuid}`, { shell: true, timeout: 20000, }); if (0 !== status) { throw new Error(`未正确安装 ideviceinstaller: ${stderr.toString()},请执行命令 'brew install ideviceinstaller' 进行安装`); } } exports.installApp = installApp; async function uninstallApp(uuid, packageName) { let { stderr, status } = (0, child_process_1.spawnSync)(`ideviceinstaller --uninstall ${packageName} -u ${uuid}`, { shell: true, timeout: 20000, }); if (0 !== status) { throw new Error(`未正确安装 ideviceinstaller: ${stderr.toString()},请执行命令 'brew install ideviceinstaller' 进行安装`); } } exports.uninstallApp = uninstallApp; async function getAppList(uuid) { try { const { stdout, stderr, status } = (0, child_process_1.spawnSync)(`ideviceinstaller --list-apps -u ${uuid}`, { shell: true, timeout: 20000, encoding: 'utf8' }); if (status !== 0) { throw new Error(`未正确安装 ideviceinstaller: ${stderr},请执行命令 'brew install ideviceinstaller' 进行安装`); } return stdout .split('\n') .filter(line => line.trim()) .slice(1) .map(line => { const [appId = '', version = '', name = ''] = line.split(',').map(item => item.trim()); return { appId, version, name }; }); } catch (error) { if (error instanceof Error) { throw new Error(`获取应用列表失败: ${error.message}`); } throw new Error('获取应用列表失败'); } } exports.getAppList = getAppList;