UNPKG

magnus-cli

Version:

Command line tool to pull and push source code files from a Rock RMS server

51 lines 1.55 kB
import Conf from 'conf'; import dotenv from 'dotenv'; dotenv.config(); // Conf uses the following paths: // macOS: ~/Library/Preferences/MyApp-nodejs // Windows: %APPDATA%\MyApp-nodejs\Config (for example, C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config) // Linux: ~/.config/MyApp-nodejs (or $XDG_CONFIG_HOME/MyApp-nodejs) // Create a new instance of Conf const config = new Conf({ projectName: 'magnus-cli', defaults: { serverUrl: '', username: '', password: '', cookie: '', token: '', }, }); /** * Get a configuration value * @param {keyof Config} key - Configuration key * @returns {any} Configuration value */ export function getConfig(key) { // Check if the key exists in environment variables first const envKey = `MAGNUS_${key.toUpperCase()}`; if (process.env[envKey] !== undefined) { return process.env[envKey]; } return config.get(key); } /** * Set a configuration value * @param {keyof Config} key - Configuration key * @param {Config[K]} value - Configuration value */ export function setConfig(key, value) { config.set(key, value); } /** * Check if the user is authenticated * @returns {boolean} True if authenticated */ export function isAuthenticated() { const serverUrl = getConfig('serverUrl'); const username = getConfig('username'); const password = getConfig('password'); const token = getConfig('token'); return Boolean(serverUrl && ((username && password) || token)); } //# sourceMappingURL=config.js.map