UNPKG

@eightshone/sshman

Version:
44 lines 2.18 kB
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 dayjs from "dayjs"; import normalizeServerName from "../../utils/normalizeServerName.js"; import init from "../functions/init.js"; import { existsSync } from "fs"; import saveFile from "../../utils/saveFile.js"; function exportServers() { return __awaiter(this, arguments, void 0, function* (servers = [], options) { var _a; // get or generate output filename const fileName = ((_a = options.name) === null || _a === void 0 ? void 0 : _a.length) ? options.name : `config-export-${dayjs().format("YYYY-MM-DD---HH-mm-ss")}.cfg`; const { config } = yield init({ silent: true }); // normalize selected servers' names const normalizedServerNames = servers.map((serverName) => normalizeServerName(serverName)); let serverConfigs = []; // check if the user wants to export all or not, the all option will ignore any if (options.all) { serverConfigs = config.servers; } else { serverConfigs = config.servers.filter((server) => normalizedServerNames.includes(normalizeServerName(server.name))); } // check if the output file should be replaced or not if (!options.force && existsSync(fileName)) { throw new Error("File exists!"); } else { yield saveFile(fileName, serverConfigs); } process.exit(); }); } export default exportServers; //# sourceMappingURL=exportServers.js.map