wangyj
Version:
wangyj 个人常用命令库
66 lines (65 loc) • 2.7 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.wdtEdit = void 0;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const inquirer_1 = __importDefault(require("inquirer"));
const templates_json_1 = __importDefault(require("../templates.json"));
const formatOutput_1 = require("../../../utils/formatOutput");
const wdtEdit = async () => {
const keys = Object.keys(templates_json_1.default);
if (keys.length === 0) {
(0, formatOutput_1.formatOutput)("提示信息", "当前无项目模板", "warning");
return;
}
else {
const { name, newname, newurl } = await inquirer_1.default.prompt([
{
type: "list",
loop: false,
name: "name",
message: "请选择要修改的模板",
choices: keys,
},
{
type: "input",
name: "newname",
message: "请输入新名称 (不填视为不修改)",
validate(valid) {
if (keys.includes(valid)) {
return `模板${valid}已存在`;
}
return true;
},
},
{
type: "input",
name: "newurl",
message: "请输入新模板地址 (不填视为不修改)",
},
]);
if (newname == "" && newurl !== "") {
Reflect.set(templates_json_1.default, name, { url: newurl });
}
else if (newname !== "" && newurl == "") {
Reflect.set(templates_json_1.default, newname, Reflect.get(templates_json_1.default, name));
Reflect.deleteProperty(templates_json_1.default, name);
}
else if (newname !== "" && newurl !== "") {
Reflect.set(templates_json_1.default, newname, { url: newurl });
Reflect.deleteProperty(templates_json_1.default, name);
}
try {
node_fs_1.default.writeFileSync(node_path_1.default.join(__dirname, "../templates.json"), JSON.stringify(templates_json_1.default, null, 4));
(0, formatOutput_1.formatOutput)("模板修改", "成功", "success");
}
catch (error) {
(0, formatOutput_1.formatOutput)("模板修改", "失败", "error");
(0, formatOutput_1.formatOutput)("错误信息", `${error}`, "error");
}
}
};
exports.wdtEdit = wdtEdit;