Skip to content

Commit

Permalink
feat: logging for experimental json loading
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed Jan 31, 2024
1 parent ba06f97 commit 598241c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/core/module-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createRequire } from 'node:module';
import type { ImportPayload, Wrapper } from '../types/core';
import type { Module } from '../types/core-modules';
import { existsSync } from 'fs';
import type { Logging } from './contracts/logging';

export const shouldHandle = (path: string, fpath: string) => {
const file_name = fpath+extname(path);
Expand Down Expand Up @@ -107,26 +108,26 @@ async function* readPaths(dir: string): AsyncGenerator<string> {

export const requir = createRequire(import.meta.url);

export function loadConfig(wrapper: Wrapper | 'file'): Wrapper {
export function loadConfig(wrapper: Wrapper | 'file', log: Logging | undefined): Wrapper {
if (wrapper !== 'file') {
return wrapper;
}
console.log('Experimental loading of sern.config.json');
log?.info({ message: 'Experimental loading of sern.config.json'});
const config = requir(resolve('sern.config.json'));

const makePath = (dir: PropertyKey) =>
config.language === 'typescript'
? join('dist', config.paths[dir]!)
: join(config.paths[dir]!);

console.log('Loading config: ', config);
log?.info({ message: 'Loading config: ' + JSON.stringify(config, null, 4) });
const commandsPath = makePath('commands');

console.log('Commands path is set to', commandsPath);
log?.info({ message: `Commands path is set to ${commandsPath}` });
let eventsPath: string | undefined;
if (config.paths.events) {
eventsPath = makePath('events');
console.log('Events path is set to', eventsPath);
log?.info({ message: `Events path is set to ${eventsPath} `});
}

return { defaultPrefix: config.defaultPrefix,
Expand Down
2 changes: 1 addition & 1 deletion src/sern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { Client } from 'discord.js';
*/
export function init(maybeWrapper: Wrapper | 'file') {
const startTime = performance.now();
const wrapper = Files.loadConfig(maybeWrapper);
const dependencies = Services('@sern/emitter',
'@sern/errors',
'@sern/logger',
Expand All @@ -34,6 +33,7 @@ export function init(maybeWrapper: Wrapper | 'file') {
const logger = dependencies[2],
errorHandler = dependencies[1];

const wrapper = Files.loadConfig(maybeWrapper, logger);
if (wrapper.events !== undefined) {
eventsHandler(dependencies, Files.getFullPathTree(wrapper.events));
}
Expand Down

0 comments on commit 598241c

Please sign in to comment.