UNPKG

adr-cli

Version:

Architecture Decision Records (ADR) command cli

82 lines 2.68 kB
import { accessSync, constants, readFileSync, writeFileSync } from 'fs'; import { ModulesPath } from './managePath.js'; import Table from 'cli-table3'; import { Locale } from './locale.js'; import chalk from 'chalk'; export class Configuration { jsonFile = {}; pathFile = `${ModulesPath.getInstalledPathSync('adr-cli')}\\dist\\config\\default.json`; path = `${ModulesPath.getInstalledPathSync('adr-cli')}\\dist\\config`; _locale; constructor() { this._locale = Locale.getInstance().getLocale(); } setDefaultValues(object) { for (let key in object) { let value = object[key]; this.jsonFile[key] = value; } let newData = JSON.stringify(this.jsonFile); writeFileSync(this.pathFile, newData); } checkConfigFileExistsSync() { let flag = true; try { accessSync(this.pathFile, constants.F_OK); } catch (e) { flag = false; } return flag; } file(path) { if (path !== undefined) { this.pathFile = path; } const data = readFileSync(this.pathFile, { encoding: 'utf8', flag: 'r' }); this.jsonFile = JSON.parse(data); } set(key, value) { this.file(); this.jsonFile[key] = value; this.saveFile(); } get(key) { const file = readFileSync(this.pathFile, { encoding: 'utf8', flag: 'r' }); const data = JSON.parse(file); return data[key]; } getShow() { const file = readFileSync(this.pathFile, { encoding: 'utf8', flag: 'r' }); const data = JSON.parse(file); return data; } displayPropertiesValues() { const tableFiles = new Table({ head: this._locale.command.config.show.table.columnName, }); const config = this.getShow(); const keys = Object.keys(config); for (const key of keys) { const localeKey = this._locale.command.config.show.table.rows[key]; tableFiles.push([ key, config[key], localeKey ]); } console.log(tableFiles.toString()); } saveFile() { const newData = JSON.stringify(this.jsonFile); writeFileSync(this.pathFile, newData, { mode: 0o777 }); } resetConfig() { console.log(`Configurations file reset successfully in this folder: ${chalk.cyan.bold(this.path)}`); } getCurrentPath() { console.log(`Configuration file create in this folder: ${chalk.cyan.bold(this.path)}`); } } export default Configuration; //# sourceMappingURL=configurations.js.map