Skip to content
Snippets Groups Projects
Unverified Commit df7f4aa3 authored by trivernis's avatar trivernis
Browse files

Add support for glob syntax to config file env variables

This change allows loading config files using glob syntax, for
exakple `production-*.yml` to load all config files prefixed with
*production*. With this change the config file can also be configured
using two additional env variables `SHARKEY_CONFIG_YML`
and `SHARKEY_CONFIG_FILE`.
parent 8b31c126
No related branches found
No related tags found
No related merge requests found
......@@ -183,14 +183,27 @@ const _dirname = dirname(_filename);
*/
const dir = `${_dirname}/../../../.config`;
function buildPath() {
const envVars = ['MISSKEY_CONFIG_YML', 'SHARKEY_CONFIG_YML', 'SHARKEY_CONFIG_FILE'];
const envCfgFile = envVars
.map(v => process.env[v])
.map(v => v ? resolve(dir, v) : undefined)
.find(v => !!v);
if (envCfgFile) {
return envCfgFile;
}
if (process.env.NODE_ENV === 'test') {
return resolve(dir, 'test.yml');
}
return resolve(dir, 'default.yml');
}
/**
* Path of configuration file
* Path of configuration file. Supports loading multiple files using glob syntax
*/
const cfgDir = process.env.MISSKEY_CONFIG_DIR
? resolve(dir, process.env.MISSKEY_CONFIG_DIR)
: process.env.NODE_ENV === 'test'
? resolve(dir, './test/')
: dir;
const path = buildPath();
export function loadConfig(): Config {
const meta = JSON.parse(fs.readFileSync(`${_dirname}/../../../built/meta.json`, 'utf-8'));
......@@ -199,7 +212,7 @@ export function loadConfig(): Config {
? JSON.parse(fs.readFileSync(`${_dirname}/../../../built/_vite_/manifest.json`, 'utf-8'))
: { 'src/_boot_.ts': { file: 'src/_boot_.ts' } };
const config = globSync(`${cfgDir}/*.{yaml,yml}`)
const config = globSync(path)
.map(path => fs.readFileSync(path, 'utf-8'))
.map(contents => yaml.load(contents) as Source)
.reduce(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment