UNPKG

hdw2

Version:

鸿蒙前端hdc调试工具

80 lines (75 loc) 2.84 kB
/* * @Author: tankunpeng * @Date: 2024-09-16 13:57:36 * @LastEditTime: 2024-11-19 17:55:07 * @LastEditors: tankunpeng * @Description: hdc常用配置 * Come on, worker! */ const shell = require('shelljs'); const chalk = require('chalk'); const { getHdwConfig, setHdwConfig, getConfigPath, hasConfigKey, getConfigKeyMap } = require('./util'); function printTitle(text = '') { shell.echo(chalk.italic(chalk.bold(chalk.blue(text)))); } function congigTrack(key, value) { if (!key && !value) { return; } if (key === 'list') { shell.echo(); shell.echo(`${chalk.cyan('配置列表: \n')}${chalk.green(JSON.stringify(getHdwConfig(), null, 1))}\n`); process.exit(0); } if (key === 'delete') { const config = getHdwConfig(); if (!value) { shell.echo(); shell.echo(`${chalk.yellow(`请传入需要删除的key,配置列表:`)}\n`); shell.echo(`${chalk.green(JSON.stringify(config, null, 1))}\n`); process.exit(1); } delete config[value]; setHdwConfig(config, true); shell.echo(); shell.echo(`${chalk.cyan('删除结果: ')}${chalk.green('成功')}\n`); shell.echo(`${chalk.cyan('配置文件路径: ')}${chalk.green(getConfigPath())}\n`); shell.echo(`${chalk.cyan('配置列表: \n')}${chalk.green(JSON.stringify(config, null, 1))}\n`); process.exit(0); } const hasKey = hasConfigKey(key); if (!hasKey) { const keyMap = getConfigKeyMap(); shell.echo(); shell.echo(`${chalk.yellow(`${key} config不支持, 支持列表如下: `)}\n`); shell.echo(`${chalk.green(JSON.stringify(keyMap, null, 2))}\n`); process.exit(1); } printTitle('=====>hdw配置开始<====='); // 设置配置 if (key && value) { const config = {}; config[key] = value; setHdwConfig(config); shell.echo(); shell.echo(`${chalk.cyan('配置结果: ')}${chalk.green('成功')}\n`); shell.echo(`${chalk.cyan('配置文件路径: ')}${chalk.green(getConfigPath())}\n`); shell.echo(`${chalk.cyan('配置列表: \n')}${chalk.green(JSON.stringify(getHdwConfig(), null, 1))}\n`); process.exit(0); } // 获取配置 const configValue = getHdwConfig(key); if (!configValue) { shell.echo(); shell.echo(`${chalk.cyan(`${key}: `)}${chalk.green('当前未设置,使用默认配置')}\n`); printTitle('=====>hdw配置结束<====='); process.exit(0); } shell.echo(); shell.echo(`${chalk.cyan(`${key}: `)}${chalk.green(configValue)}\n`); printTitle('=====>hdw配置结束<====='); } function config(arg0, args = [], options = {}, command = {}) { congigTrack(arg0, ...args); } exports.config = config;