UNPKG

@nexex/cli

Version:
56 lines 2.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const cosmiconfig_1 = __importDefault(require("cosmiconfig")); const fs_1 = __importDefault(require("fs")); const os_1 = __importDefault(require("os")); const moduleName = 'nexex'; class Base extends command_1.Command { initDir() { if (!fs_1.default.existsSync(this.homeDir)) { fs_1.default.mkdirSync(this.homeDir); } if (!fs_1.default.existsSync(this.defaultConfig)) { fs_1.default.copyFileSync(require.resolve('../config/user.yaml'), this.defaultConfig); } } async readConfig() { const explorer = cosmiconfig_1.default(moduleName, { searchPlaces: [`.${moduleName}rc.yaml`, '.nexex/config.yaml'] }); const searchRes = await explorer.search(); return searchRes; } async saveConfig(newConfig) { const { filepath } = await this.readConfig(); fs_1.default.writeFileSync(filepath, newConfig, { encoding: 'utf-8' }); } get homeDir() { return `${os_1.default.homedir()}/.nexex`; } get defaultConfig() { return `${this.homeDir}/config.yaml`; } async getDexConfig() { const { config: { network, provider } } = await this.readConfig(); return { network, provider }; } } Base.flags = { help: command_1.flags.help({ char: 'h' }), endpoint: command_1.flags.string({ char: 'e', default: 'https://kovan-ob.nexex.info' }), showAddr: command_1.flags.boolean({ char: 'a', default: false }) }; exports.default = Base; function initDir(target, propertyKey, descriptor) { const origin = descriptor.value; descriptor.value = function (...args) { this.initDir(); return origin.apply(this, args); }; } exports.initDir = initDir; //# sourceMappingURL=Base.js.map