File loading fixes for prod.

This commit is contained in:
Dennis Postma 2024-09-30 23:18:27 +02:00
parent da8ef9fa65
commit 7b3c4b92a5
2 changed files with 8 additions and 4 deletions

View File

@ -61,14 +61,17 @@ class CommandManager {
} }
private async loadCommands() { private async loadCommands() {
const commandsDir = path.join(process.cwd(), 'src', 'commands'); const baseDir = config.ENV === 'production' ? path.join(__dirname, '..') : process.cwd();
const commandsDir = path.join(baseDir, config.ENV === 'production' ? 'commands' : 'src', 'commands');
const extension = config.ENV === 'production' ? '.js' : '.ts';
commandLogger.info(`Loading commands from: ${commandsDir}`); commandLogger.info(`Loading commands from: ${commandsDir}`);
try { try {
const files = await fs.promises.readdir(commandsDir, { withFileTypes: true }); const files = await fs.promises.readdir(commandsDir, { withFileTypes: true });
for (const file of files) { for (const file of files) {
if (!file.isFile() || (!file.name.endsWith('.ts') && !file.name.endsWith('.js'))) { if (!file.isFile() || !file.name.endsWith(extension)) {
continue; continue;
} }

View File

@ -50,8 +50,9 @@ class QueueManager {
private async processJob(job: Job) { private async processJob(job: Job) {
const { jobName, params, socketId } = job.data; const { jobName, params, socketId } = job.data;
const jobsDir = path.join(process.cwd(), 'src', 'jobs'); const baseDir = config.ENV === 'production' ? path.join(__dirname, '..') : process.cwd();
const extension = config.ENV === 'development' ? '.ts' : '.js'; const jobsDir = path.join(baseDir, config.ENV === 'production' ? 'jobs' : 'src', 'jobs');
const extension = config.ENV === 'production' ? '.js' : '.ts';
const jobPath = path.join(jobsDir, `${jobName}${extension}`); const jobPath = path.join(jobsDir, `${jobName}${extension}`);
queueLogger.info(`Processing job: ${jobName}`); queueLogger.info(`Processing job: ${jobName}`);