UNPKG

alfred-chrono-notes

Version:

Alfred Workflow for easy access to your Obsidian Periodic Notes

44 lines (43 loc) 1.88 kB
import { isEnvVarSet } from '../../CommonUtils.js'; import { MissingConfigurationException } from '../../../Exceptions/MissingConfigurationException.js'; /** * @description The default Env ConfigDriver that uses process.env. */ export class EnvConfigDriver { get(key) { return process.env[key]; } /** * Method to get interval configurations, assuming intervals are known. * @param interval - The interval to get the config for. * @returns - The interval config for the given interval. */ getIntervalConfig(interval) { const fileFormatVar = `${interval.toUpperCase()}_FILE_FORMAT`; const folderPathVar = `${interval.toUpperCase()}_PATH`; const templatePathVar = `${interval.toUpperCase()}_TEMPLATE_PATH`; console.log(`File Format: ${this.get(fileFormatVar)}`); console.log(`Folder path: ${this.get(folderPathVar)}`); console.log(`Template path: ${this.get(templatePathVar)}`); return { FILE_FORMAT: this.get(fileFormatVar) ?? '', FOLDER_PATH: this.get(folderPathVar) ?? '', TEMPLATE_PATH: this.get(templatePathVar) ?? '', }; } /** * Check that the required interval config variables are set * Specifically checking 3 variables in {@link IntervalConfig} * If it's not set then throw {@link MissingConfigurationException}. * @param intervalVars - The interval config variables to check. * @throws {MissingConfigurationException} - If any of the required variables are not set. */ validateIntervalConfig(intervalVars) { Object.keys(intervalVars).forEach((key) => { const typedKey = key; if (!isEnvVarSet(intervalVars[typedKey])) { throw new MissingConfigurationException(`Missing environment variable: ${typedKey}`); } }); } }