UNPKG

hdw2

Version:

鸿蒙前端hdc调试工具

63 lines (57 loc) 2.12 kB
/* * @Author: tankunpeng * @Date: 2024-06-26 19:47:35 * @LastEditTime: 2024-09-16 14:35:10 * @LastEditors: tankunpeng * @Description: 获取hdc命令路径 * Come on, worker! */ const shell = require('shelljs'); const chalk = require('chalk'); const { getHdc } = require('./util'); function printTitle(text = '') { shell.echo(chalk.italic(chalk.bold(chalk.blue(text)))); } function getHdcPath() { const hdc = getHdc(); printTitle('=====>获取hdc命令路径开始<====='); shell.echo(''); shell.echo(`${chalk.cyan('hdc命令路径: ')}${chalk.green(hdc)}`); shell.echo(''); printTitle('=====>获取hdc命令路径结束<====='); } function getUdid() { const hdc = getHdc(); printTitle('=====>获取手机udid开始<====='); const udiDCmd = `${hdc} shell bm get --udid`; const udiDExec = shell.exec(udiDCmd, { silent: true }); if (udiDExec.code !== 0) { shell.echo(`${chalk.cyan('获取手机udid结果: ')}${chalk.red('失败')}`); shell.echo(`${chalk.cyan('处理建议: ')}${chalk.yellow('请手动执行命令尝试\n命令:' + chalk.green(udiDCmd))}`); printTitle('=====>获取手机udid结束<====='); shell.exit(1); } const udid = udiDExec.stdout.split(/[\r\n]/).find((item) => /^[a-zA-z0-9]{64,}$/.test(item)); if (!udid) { shell.echo(`${chalk.cyan('获取手机udid结果: ')}${chalk.red('失败')}`); shell.echo(`${chalk.cyan('处理建议: ')}${chalk.yellow('请手动执行命令尝试\n命令:' + chalk.green(udiDCmd))}`); shell.echo(`${chalk.cyan('失败输出: \n')}${chalk.yellow(udiDExec.stdout)}`); printTitle('=====>获取手机udid结束<====='); shell.exit(1); } shell.echo(''); shell.echo(`${chalk.cyan('手机udid: ')}${chalk.green(udid)}`); shell.echo(''); printTitle('=====>获取手机udid结束<====='); } function get(arg0, arg1, args = [], options = {}, command = {}) { if (arg0 === 'hdc') { getHdcPath(); return; } if (arg0 === 'udid') { getUdid(); return; } } exports.get = get;