You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/packages/hydrooj/src/options.ts

28 lines
811 B
TypeScript

import fs from 'fs';
import os from 'os';
import path from 'path';
import { findFileSync } from '@hydrooj/utils/lib/utils';
import { Logger } from './logger';
const logger = new Logger('options');
export = function load() {
const envFile = path.resolve(os.homedir(), '.hydro', 'env');
if (fs.existsSync(envFile)) {
const content = fs.readFileSync(envFile).toString();
for (const line of content.split('\n')) {
process.env[line.split('=')[0]] = line.split('=')[1];
}
}
const f = findFileSync('config.json', false);
if (!f) return null;
let result: any = {};
try {
result = JSON.parse(fs.readFileSync(f).toString());
} catch (e) {
logger.error('Cannot read config file %o', e);
result = {};
}
return result;
};