UNPKG

hdw2

Version:

鸿蒙前端hdc调试工具

55 lines (49 loc) 1.9 kB
/* * @Author: tankunpeng * @Date: 2024-09-02 09:33:05 * @LastEditTime: 2025-08-28 10:39:10 * @LastEditors: tankunpeng * @Description: 获取手机端指定目录文件列表 * Come on, worker! */ const shell = require('shelljs'); const chalk = require('chalk'); const { getHdc, printTitle, shellLog, REMOTE_PATH_MAP } = require('./util'); function fileList(options = {}, command = {}, logOps = {}) { const args = command.args || []; const hdc = getHdc(); if (!options.remote) { if (args.length) { options.remote = args[0]; } else if (options.download) { options.remote = REMOTE_PATH_MAP.download; } else if (options.share) { options.remote = REMOTE_PATH_MAP.share; } else { options.remote = REMOTE_PATH_MAP.temp; } } shellLog(`${chalk.cyan('手机路径: ')}${chalk.yellow(options.remote)}`, logOps, { beforeLine: true }); printTitle('=====>获取文件列表<=====', logOps, { beforeLine: true, afterLine: true }); const lsCmd = `${hdc} shell ls "${options.remote}"`; const lsExec = shell.exec(lsCmd, { silent: true }); if (lsExec.code !== 0) { shellLog(`${chalk.cyan('获取文件列表结果: ')}${chalk.red('失败')}`, logOps, { hideLog: false }); shellLog( `${chalk.cyan('处理建议: ')}${chalk.yellow( '查询端口映射列表命令执行失败,请手动执行命令尝试\n命令:' + chalk.green(lsCmd) )}`, logOps, { hideLog: false } ); shell.exit(1); } const lsStdout = lsExec.stdout; if (!lsStdout) { shellLog(chalk.yellow('当前文件夹为空'), logOps, { hideLog: false }); shell.exit(0); } shellLog(`${chalk.cyan('文件列表: \n')}${chalk.green(lsStdout)}`, logOps); shellLog(`${chalk.cyan('获取文件列表结果: ')}${chalk.green('成功')}`, logOps); } exports.fileList = fileList;