Change loadConfig to load all yaml files in the config directory

This commit is contained in:
trivernis 2023-12-24 17:16:24 +01:00
parent fd57c7e24c
commit 64d34f595c
No known key found for this signature in database
GPG key ID: DFFFCC2C7A02DB45
4 changed files with 38 additions and 104 deletions

View file

@ -109,6 +109,7 @@
"file-type": "18.7.0",
"fluent-ffmpeg": "2.1.2",
"form-data": "4.0.0",
"glob": "^10.3.10",
"got": "14.0.0",
"happy-dom": "10.0.3",
"hpagent": "1.2.0",
@ -122,8 +123,8 @@
"json5": "2.2.3",
"jsonld": "8.3.2",
"jsrsasign": "10.9.0",
"meilisearch": "0.36.0",
"megalodon": "workspace:*",
"meilisearch": "0.36.0",
"microformats-parser": "2.0.2",
"mime-types": "2.1.35",
"misskey-js": "workspace:*",

View file

@ -8,6 +8,7 @@ import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import * as yaml from 'js-yaml';
import type { RedisOptions } from 'ioredis';
import { globSync } from 'glob';
type RedisOptionsSource = Partial<RedisOptions> & {
host: string;
@ -185,19 +186,26 @@ const dir = `${_dirname}/../../../.config`;
/**
* Path of configuration file
*/
const path = process.env.MISSKEY_CONFIG_YML
? resolve(dir, process.env.MISSKEY_CONFIG_YML)
const cfgDir = process.env.MISSKEY_CONFIG_DIR
? resolve(dir, process.env.MISSKEY_CONFIG_DIR)
: process.env.NODE_ENV === 'test'
? resolve(dir, 'test.yml')
: resolve(dir, 'default.yml');
? resolve(dir, './test/')
: dir;
export function loadConfig(): Config {
const meta = JSON.parse(fs.readFileSync(`${_dirname}/../../../built/meta.json`, 'utf-8'));
const clientManifestExists = fs.existsSync(_dirname + '/../../../built/_vite_/manifest.json');
const clientManifest = clientManifestExists ?
JSON.parse(fs.readFileSync(`${_dirname}/../../../built/_vite_/manifest.json`, 'utf-8'))
const clientManifestExists = fs.existsSync(`${_dirname}/../../../built/_vite_/manifest.json`);
const clientManifest = clientManifestExists
? JSON.parse(fs.readFileSync(`${_dirname}/../../../built/_vite_/manifest.json`, 'utf-8'))
: { 'src/_boot_.ts': { file: 'src/_boot_.ts' } };
const config = yaml.load(fs.readFileSync(path, 'utf-8')) as Source;
const config = globSync(`${cfgDir}/*.{yaml,yml}`)
.map(path => fs.readFileSync(path, 'utf-8'))
.map(contents => yaml.load(contents) as Source)
.reduce(
(acc: Source, cur: Source) => Object.assign(acc, cur),
{} as Source,
) as Source;
const url = tryCreateUrl(config.url);
const version = meta.version;