UNPKG

hdw2

Version:

鸿蒙前端hdc调试工具

59 lines (52 loc) 1.91 kB
/* * @Author: tankunpeng * @Date: 2024-09-02 09:33:05 * @LastEditTime: 2024-09-16 17:11:23 * @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 fileList(options = {}, command = {}) { const args = command.args || []; const hdc = getHdc(); if (!options.remote) { if (args.length) { options.remote = args[0]; } else if (options.download) { options.remote = '/storage/media/100/local/files/Docs/Download'; } else { options.remote = '/data/local/tmp'; } } shell.echo(); shell.echo(`${chalk.cyan('手机路径: ')}${chalk.yellow(options.remote)}`); shell.echo(); printTitle('=====>获取文件列表开始<====='); shell.echo(); const lsCmd = `${hdc} shell ls ${options.remote}`; const lsExec = shell.exec(lsCmd, { silent: true }); if (lsExec.code !== 0) { shell.echo(`${chalk.cyan('获取文件列表结果: ')}${chalk.red('失败')}`); shell.echo(`${chalk.cyan('处理建议: ')}${chalk.yellow('查询端口映射列表命令执行失败,请手动执行命令尝试\n命令:' + chalk.green(lsCmd))}`); printTitle(); shell.exit(1); } const lsStdout = lsExec.stdout; if (!lsStdout) { shell.echo(); shell.echo(chalk.yellow('当前文件夹为空')); shell.echo(); printTitle(); shell.exit(0); } shell.echo(`${chalk.cyan('文件列表: \n')}${chalk.green(lsStdout)}`); shell.echo(`${chalk.cyan('获取文件列表结果: ')}${chalk.green('成功')}`); printTitle(); } exports.fileList = fileList;