tree-wide: make sources more bundler friendly

This commit is contained in:
liushuyu 2022-12-31 02:02:40 -07:00
parent e46432ac22
commit 4f8bf4574f
No known key found for this signature in database
GPG key ID: 23D1CE4534419437
3 changed files with 20 additions and 10 deletions

View file

@ -1,6 +1,12 @@
import * as fs from 'fs';
import state from './state';
import logger from './logging';
import { IResponses } from './models/interfaces';
const responses: { [index: string]: IResponses } = {
citra: require('./responses/citra.json'),
yuzu: require('./responses/yuzu.json')
};
export function readWarnings () {
// Load the warnings file into the application state.
@ -32,13 +38,15 @@ export function readBans () {
export function readCustomResponses () {
// Load the responses file into the responses variable.
try {
state.responses = require(`./responses/${process.env.TENANT}.json`);
if (process.env.TENANT) {
state.responses = responses[process.env.TENANT];
if (state.responses) {
logger.debug(`Loaded responses file for ${process.env.TENANT} from external source.`);
} catch (e) {
logger.error(`Failed to load ${process.env.TENANT}.json! Custom responses are disabled.`);
return;
}
}
logger.error(`Failed to load ${process.env.TENANT}.json! Custom responses are disabled.`);
}
export function flushWarnings () {
const warningsJson = JSON.stringify(state.warnings, null, 4);

View file

@ -1,6 +1,7 @@
import * as winston from 'winston';
import * as ip from 'ip';
import * as os from 'os';
import LogdnaWinston from 'logdna-winston';
const logger = winston.createLogger({
level: 'debug',
@ -18,10 +19,9 @@ const logger = winston.createLogger({
// Setup logging for LogDNA cloud logging.
if (process.env.LOGDNA_API_KEY) {
const logdnaWinston = require('logdna-winston');
const logLevel = process.env.LOGDNA_LEVEL || 'info';
logger.add(new logdnaWinston({
logger.add(new LogdnaWinston({
level: logLevel,
app: process.env.LOGDNA_APPNAME,
index_meta: true,

View file

@ -9,7 +9,9 @@ import triggers from './triggers/_';
// Check for environmental variables.
import * as checkenv from 'checkenv';
checkenv.setConfig(require('../env.json'));
import envConfig from '../env.json';
checkenv.setConfig(envConfig);
checkenv.check();
interface IModuleMap {