UNPKG

cli-stash

Version:

CLI application to manage and work with Atlassian Stash. Work with your Stash project and repositories from Command lines.

47 lines (46 loc) 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Config = void 0; const fileSystem_1 = require("../fileSystem"); const INSTANCES_FILE = 'instances.json'; class Config { constructor(folderPath, load) { this.folderPath = ''; this.instances = {}; this.folderPath = folderPath; if (load) { this.load(); } } getConnectorOptions(alias) { const instance = this.instances[alias]; const data = atob(instance.token); const splits = data.split(':'); return { host: instance.host, user: splits[0], password: splits[1], }; } load() { const filePath = this.folderPath + '/' + INSTANCES_FILE; if (!fileSystem_1.FileChecker.isExists(this.folderPath)) { fileSystem_1.FileWriter.createFolderSync(this.folderPath); } if (!fileSystem_1.FileChecker.isExists(filePath)) { fileSystem_1.FileWriter.createFileSync(filePath, JSON.stringify({})); } this.instances = JSON.parse(fileSystem_1.FileReader.readFileSync(filePath)); } save() { const filePath = this.folderPath + '/' + INSTANCES_FILE; if (!fileSystem_1.FileChecker.isExists(this.folderPath)) { fileSystem_1.FileWriter.createFolderSync(this.folderPath); } if (!fileSystem_1.FileChecker.isExists(filePath)) { fileSystem_1.FileWriter.createFileSync(filePath, JSON.stringify({})); } fileSystem_1.FileWriter.createFileSync(filePath, JSON.stringify(this.instances, null, 2)); } } exports.Config = Config;