hdw2
Version:
鸿蒙前端hdc调试工具
49 lines (44 loc) • 1.79 kB
JavaScript
/*
* @Author: tankunpeng
* @Date: 2024-06-26 19:47:35
* @LastEditTime: 2024-09-02 12:04:09
* @LastEditors: tankunpeng
* @Description: 查询映射列表
* 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 list(options = {}, command = {}) {
const commandName = command._name || '';
const isList = commandName === 'list';
const isClean = commandName === 'clean';
const hdc = getHdc();
isList && printTitle('=====>查询调试端口映射开始<=====');
shell.echo();
const fportLsCmd = `${hdc} fport ls`;
const fportLsExec = shell.exec(fportLsCmd, { silent: true });
if (fportLsExec.code !== 0) {
isList && shell.echo(`${chalk.cyan('查询调试端口映射结果: ')}${chalk.red('失败')}`);
shell.echo(`${chalk.cyan('处理建议: ')}${chalk.yellow('查询端口映射列表命令执行失败,请手动执行命令尝试\n命令:' + chalk.green(fportLsCmd))}`);
isList && printTitle();
shell.exit(1);
}
const fportLsStdout = fportLsExec.stdout;
const isEmpty = fportLsStdout.includes('[Empty]');
if (isEmpty) {
shell.echo();
shell.echo(chalk.yellow('当前无调试端口映射'));
shell.echo();
isClean && shell.exit(0);
} else {
isList && shell.echo(`${chalk.cyan('调试端口映射列表: \n')}${chalk.green(fportLsStdout)}`);
}
isList && shell.echo(`${chalk.cyan('查询调试端口映射结果: ')}${chalk.green('成功')}`);
isList && printTitle();
return isEmpty ? '' : fportLsStdout;
}
exports.list = list;