UNPKG

hdw2

Version:

鸿蒙前端hdc调试工具

61 lines (54 loc) 2.03 kB
/* * @Author: tankunpeng * @Date: 2024-09-02 11:16:22 * @LastEditTime: 2025-03-27 09:54:51 * @LastEditors: tankunpeng * @Description: 删除手机端指定目录下文件 * Come on, worker! */ const shell = require('shelljs'); const chalk = require('chalk'); const { getHdc } = require('./util'); const path = require('path'); function printTitle(text = '=====>删除文件结束<=====') { shell.echo(chalk.italic(chalk.bold(chalk.blue(text)))); } function rm(options = {}, command = {}) { 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 += '*'; } shell.echo(); shell.echo(`${chalk.cyan('手机删除路径: ')}${chalk.yellow(remotePath)}`); shell.echo(); printTitle('=====>删除文件开始<====='); shell.echo(); const lsCmd = `${hdc} shell rm -r ${remotePath}`; 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(`${chalk.cyan('删除文件结果: ')}${chalk.red('失败')}`); shell.echo(`${chalk.cyan('失败原因: \n')}${chalk.yellow(lsStdout)}`); } else { shell.echo(`${chalk.cyan('删除文件结果: ')}${chalk.green('成功')}`); shell.echo(); } printTitle(); } exports.rm = rm;