@athenna/config
Advanced tools
Comparing version 3.6.0 to 3.7.0
{ | ||
"name": "@athenna/config", | ||
"version": "3.6.0", | ||
"version": "3.7.0", | ||
"description": "Cache and handle environment variables and config files of Athenna.", | ||
@@ -84,2 +84,3 @@ "license": "MIT", | ||
"text-summary", | ||
"lcovonly", | ||
"html" | ||
@@ -86,0 +87,0 @@ ], |
@@ -57,2 +57,7 @@ /** | ||
/** | ||
* Push a value to a configuration key that is a valid array. | ||
* If configuration is not an array, an exception will be thrown. | ||
*/ | ||
static push(key: string, value: any | any[]): typeof Config; | ||
/** | ||
* Delete the configuration key. | ||
@@ -59,0 +64,0 @@ */ |
@@ -9,7 +9,8 @@ /** | ||
*/ | ||
import { sep, parse } from 'node:path'; | ||
import { File, Json, Path, Exec, Module, Is, } from '@athenna/common'; | ||
import { loadFile, writeFile } from 'magicast'; | ||
import { File, Json, Path, Exec, Module } from '@athenna/common'; | ||
import { sep, parse, extname } from 'node:path'; | ||
import { RecursiveConfigException } from '#src/Exceptions/RecursiveConfigException'; | ||
import { NotSupportedKeyException } from '#src/Exceptions/NotSupportedKeyException'; | ||
import { NotValidArrayConfigException } from '#src/Exceptions/NotValidArrayConfigException'; | ||
class Config { | ||
@@ -98,2 +99,20 @@ /** | ||
/** | ||
* Push a value to a configuration key that is a valid array. | ||
* If configuration is not an array, an exception will be thrown. | ||
*/ | ||
static push(key, value) { | ||
const config = this.configs.get(key, []); | ||
if (!Is.Array(config)) { | ||
throw new NotValidArrayConfigException(key); | ||
} | ||
if (Is.Array(value)) { | ||
config.push(...value); | ||
} | ||
else { | ||
config.push(value); | ||
} | ||
this.configs.set(key, config); | ||
return this; | ||
} | ||
/** | ||
* Delete the configuration key. | ||
@@ -144,2 +163,6 @@ */ | ||
static async loadAll(path = Path.config(), safe = false) { | ||
if (extname(path)) { | ||
safe ? this.safeLoad(path) : this.load(path); | ||
return; | ||
} | ||
const files = await Module.getAllJSFilesFrom(path); | ||
@@ -146,0 +169,0 @@ this.fatherConfigPath = path; |
38424
29
1006