70 lines
No EOL
2.6 KiB
TypeScript
70 lines
No EOL
2.6 KiB
TypeScript
import {Environment} from "../Environment";
|
|
import {Container} from "./Container";
|
|
import {DatabaseConnection} from "../Database/DatabaseConnection";
|
|
import {getLogger, configure, Logger} from "log4js";
|
|
import path from "node:path";
|
|
import {GroupRepository} from "../Repositories/GroupRepository";
|
|
import {PlaydateRepository} from "../Repositories/PlaydateRepository";
|
|
import {GuildEmojiRoleManager} from "discord.js";
|
|
import {GroupConfigurationRepository} from "../Repositories/GroupConfigurationRepository";
|
|
import {DiscordClient} from "../Discord/DiscordClient";
|
|
import {IconCache} from "../Icons/IconCache";
|
|
|
|
export enum ServiceHint {
|
|
App,
|
|
Deploy
|
|
}
|
|
|
|
export class Services {
|
|
public static setup(container: Container, hint: ServiceHint) {
|
|
const env = new Environment();
|
|
env.setup();
|
|
container.set<Environment>(env);
|
|
|
|
const database = new DatabaseConnection(env.database);
|
|
container.set<DatabaseConnection>(database);
|
|
|
|
const discordClient = new DiscordClient(env.discord.clientId);
|
|
container.set<DiscordClient>(discordClient);
|
|
|
|
const iconCache = new IconCache(discordClient);
|
|
container.set<IconCache>(iconCache);
|
|
|
|
// @ts-ignore
|
|
configure({
|
|
appenders: {
|
|
out: { type: "stdout" },
|
|
appLogFile: { type: "file", filename: path.resolve("logs/run.log")},
|
|
deployLogFile: { type: "file", filename: path.resolve("logs/deploy.log")},
|
|
},
|
|
categories: {
|
|
default: { appenders: ['out'], level: 'debug' },
|
|
app: { appenders: ["out", "appLogFile"], level: "debug" },
|
|
deploy: { appenders: ["out", "deployLogFile"], level: "debug" },
|
|
}
|
|
})
|
|
|
|
let loggername = '';
|
|
switch (hint) {
|
|
case ServiceHint.App:
|
|
loggername = "app";
|
|
break;
|
|
case ServiceHint.Deploy:
|
|
loggername = "deploy";
|
|
break;
|
|
|
|
}
|
|
const logger = getLogger(loggername);
|
|
|
|
container.set<Logger>(logger, 'logger');
|
|
|
|
this.setupRepositories(container);
|
|
}
|
|
|
|
private static setupRepositories(container: Container) {
|
|
const db = container.get<DatabaseConnection>(DatabaseConnection.name);
|
|
container.set<GroupRepository>(new GroupRepository(db));
|
|
container.set<PlaydateRepository>(new PlaydateRepository(db, container.get<GroupRepository>(GroupRepository.name)))
|
|
container.set<GroupConfigurationRepository>(new GroupConfigurationRepository(db, container.get<GroupRepository>(GroupRepository.name)))
|
|
}
|
|
} |