@tuzki/cli
Version:
🐇 lowcode-cli is an efficient cli tool for Rabbitpre plugin component secondary development. ❤️
52 lines (51 loc) • 1.94 kB
JavaScript
/*
* Config Command
*
* @Author: xu.jin
* @Date: 2023-08-15 19:21:16
*
* Copyright © 2014-2023 Rabbitpre.com. All Rights Reserved.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import Logger from '@tuzki/scaffold-logger';
import { getCliConfig, getConfigByName, getLocalConfig, setLocalConfig, setLocalConfigByName, } from '../utils/config.js';
const logger = Logger.get('cli:commands:config');
export const config = (commandArgs) => __awaiter(void 0, void 0, void 0, function* () {
const { get: getName, set, list, unset } = commandArgs;
// 无参数配置
if (!getName && !set && !list && !unset) {
logger.error('缺失配置参数');
return;
}
// 获取名称
if (getName) {
console.log(getConfigByName(getName));
}
// 显示配置列表
if (list) {
console.log(getCliConfig());
}
// 设置配置属性
if (set) {
if (set.length > 2) {
logger.error('config set 参数数量错误');
}
yield setLocalConfigByName(set[0], set[1]);
}
// 删除配置属性
if (unset) {
const curConfig = getLocalConfig();
unset.forEach(config => {
delete curConfig[config];
});
yield setLocalConfig(Object.assign({}, curConfig));
}
});