wangyj
Version:
wangyj 个人常用命令库
52 lines (51 loc) • 2.15 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.wssRemove = 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 registries_json_1 = __importDefault(require("../registries.json"));
const formatOutput_1 = require("../../../utils/formatOutput");
const wssRemove = async () => {
const defaultList = ["npm", "yarn", "cnpm", "taobao"];
const keys = Object.keys(registries_json_1.default);
if (keys.length === defaultList.length) {
(0, formatOutput_1.formatOutput)("提示信息", "当前无自定义镜像源", "warning");
return;
}
else {
const customList = keys.filter((key) => !defaultList.includes(key));
const { select, confirm } = await inquirer_1.default.prompt([
{
type: "list",
loop: false,
name: "select",
message: "请选择自定义镜像源",
choices: customList,
},
{
type: "confirm",
name: "confirm",
message: "是否删除自定义镜像源",
default: false,
},
]);
if (!confirm) {
(0, formatOutput_1.formatOutput)("镜像源删除", "取消", "warning");
return;
}
Reflect.deleteProperty(registries_json_1.default, select);
try {
node_fs_1.default.writeFileSync(node_path_1.default.join(__dirname, "../registries.json"), JSON.stringify(registries_json_1.default, null, 4));
(0, formatOutput_1.formatOutput)("镜像源删除", "成功", "success");
}
catch (error) {
(0, formatOutput_1.formatOutput)("镜像源删除", "失败", "error");
(0, formatOutput_1.formatOutput)("错误信息", `${error}`, "error");
}
}
};
exports.wssRemove = wssRemove;