UNPKG

@eightshone/sshman

Version:
38 lines 2.02 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 { CONFIG_DIR } from "./consts.js"; import findServerIndex from "./findServerIndex.js"; import saveFile from "./saveFile.js"; import { formattedTime } from "./time.js"; import updateRecentServers from "./updateRecentServer.js"; function updateConfigs(initialConfig_1, initialLogs_1, sshConfig_1) { return __awaiter(this, arguments, void 0, function* (initialConfig, initialLogs, sshConfig, saveConfig = false) { const config = Object.assign({}, initialConfig); let logs = [...initialLogs]; if (saveConfig) { if (findServerIndex(config.servers, sshConfig) === -1) { config.servers = [...config.servers, sshConfig]; } else { console.info("\n⚠️ This server config exists in your list of servers!\n It will not be added to the list to avoid duplicate entries.\n"); } } config.recentServers = updateRecentServers(config.recentServers, sshConfig); logs = [ { time: formattedTime, server: sshConfig.id, serverName: sshConfig.name }, ...logs, ]; yield saveFile(`${CONFIG_DIR}/config.json`, config); yield saveFile(`${CONFIG_DIR}/logs.json`, logs); return [config, logs]; }); } export default updateConfigs; //# sourceMappingURL=updateConfigs.js.map