UNPKG

@zambelz/zhc

Version:
66 lines 2.65 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeProfile = exports.createProfile = void 0; const node_path_1 = __importDefault(require("node:path")); const node_fs_1 = __importDefault(require("node:fs")); const global_1 = require("./global"); const fileOperation_1 = require("./fileOperation"); const createProfile = (name) => { const profilePath = node_path_1.default.join(global_1.PROFILES_PATH, name); if (node_fs_1.default.existsSync(profilePath)) { throw new Error(`"${profilePath}" is exists`); } (0, fileOperation_1.createDirectory)({ path: profilePath, recursive: true }); (0, fileOperation_1.createFile)({ path: node_path_1.default.join(profilePath, "config.jsonc"), content: JSON.stringify({ "defaultEnv": "default", }, null, 2) }); const envPath = node_path_1.default.join(profilePath, "env"); (0, fileOperation_1.createDirectory)({ path: envPath, recursive: true }); (0, fileOperation_1.createFile)({ path: node_path_1.default.join(envPath, "default.jsonc"), content: JSON.stringify({ "protocol": "https", "baseURL": "dummyjson.com" }, null, 2) }); const endpointsPath = node_path_1.default.join(profilePath, "endpoints"); (0, fileOperation_1.createDirectory)({ path: endpointsPath, recursive: true }); (0, fileOperation_1.createFile)({ path: node_path_1.default.join(endpointsPath, "default.jsonc"), content: JSON.stringify({ "sample_get_all": { "path": "/posts", "method": "GET", "headers": { "Content-Type": "application/json" }, "params": {} }, "sample_get_single": { "path": "/posts/1", "method": "GET", "headers": { "Content-Type": "application/json" }, "params": {} } }, null, 2) }); return profilePath; }; exports.createProfile = createProfile; const removeProfile = (name) => { const profilePath = node_path_1.default.join(global_1.PROFILES_PATH, name); if (!node_fs_1.default.existsSync(profilePath)) { throw new Error(`"${profilePath}" is not exists`); } node_fs_1.default.rmdirSync(profilePath, { recursive: true }); }; exports.removeProfile = removeProfile; //# sourceMappingURL=profile.js.map