UNPKG

wangyj

Version:

wangyj 个人常用命令库

55 lines (54 loc) 2.05 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.wssAdd = 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 wssAdd = async () => { const { name, registry } = await inquirer_1.default.prompt([ { type: "input", name: "name", message: "请输入镜像源名称", validate(valid) { const keys = Object.keys(registries_json_1.default); if (keys.includes(valid)) { return `镜像源名称${valid}已存在`; } if (!valid.trim()) { return "镜像源名称不能为空"; } return true; }, }, { type: "input", name: "registry", message: "请输入镜像源地址", validate(valid) { if (!valid.trim()) { return `镜像源地址不能为空`; } return true; }, }, ]); const value = { registry: registry.trim(), }; Reflect.set(registries_json_1.default, name, value); 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.wssAdd = wssAdd;