UNPKG

hdw2

Version:

鸿蒙前端hdc调试工具

57 lines (51 loc) 2.06 kB
/* * @Author: tankunpeng * @Date: 2024-09-02 11:16:22 * @LastEditTime: 2025-08-06 16:35:30 * @LastEditors: tankunpeng * @Description: 删除手机端指定目录下文件 * Come on, worker! */ const shell = require('shelljs'); const chalk = require('chalk'); const { getHdc, printTitle, shellLog } = require('./util'); const path = require('path'); function rm(options = {}, command = {}, logOps = {}) { const args = command.args || []; const hdc = getHdc(); const remoteArg = args[0]; let remotePath = options.remote || remoteArg || '*'; if (!/^\//.test(remotePath)) { if (options.download) { remotePath = path.posix.resolve('/storage/media/100/local/files/Docs/Download/', remotePath); } else { remotePath = path.posix.resolve('/data/local/tmp/', remotePath); } } if (/\/$/.test(remotePath)) { remotePath += '*'; } shellLog(`${chalk.cyan('手机删除路径: ')}${chalk.yellow(remotePath)}`, logOps); printTitle('=====>删除文件<=====', logOps, { beforeLine: true, afterLine: true }); const lsCmd = `${hdc} shell rm -r ${remotePath}`; 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.cyan('删除文件结果: ')}${chalk.red('失败')}`, logOps, { hideLog: false }); shellLog(`${chalk.cyan('失败原因: \n')}${chalk.yellow(lsStdout)}`, logOps, { hideLog: false }); shell.exit(1); } shellLog(`${chalk.cyan('删除文件结果: ')}${chalk.green('成功')}`, logOps); } exports.rm = rm;