Skip to content

Commit

Permalink
fix(core): ensure modules have unique names (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
potb committed Jan 5, 2024
1 parent d258ce2 commit 9a4a57a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
Empty file.
11 changes: 7 additions & 4 deletions src/core/createEnvForModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ const createEnvForModule = (constantName: string) =>
return acc;
}, {});

export const createAllModules = async (
modules: Record<string, ModuleCreator>,
): Promise<CreatedModule[]> => {
export const createAllModules = async (modules: ModuleCreator[]): Promise<CreatedModule[]> => {
const uniqueModuleNames = new Set(modules.map((module) => module.name));
if (uniqueModuleNames.size !== modules.length) {
throw new Error('Found duplicate module names');
}

const createdModules: CreatedModule[] = [];

for (const { name, factory } of Object.values(modules)) {
for (const { name, factory } of modules) {
const moduleConstantName = constantCase(name);
const env = createEnvForModule(moduleConstantName);
const module = await factory({ env });
Expand Down
16 changes: 15 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ import { createAllModules } from './core/createEnvForModule';
import { env } from './core/env';
import { getIntentsFromModules } from './core/getIntentsFromModules';
import { loadModules } from './core/loadModules';
import { modules } from './modules/modules';
import { coolLinksManagement } from './modules/coolLinksManagement/coolLinksManagement.module';
import { fart } from './modules/fart/fart.module';
import { fixEmbedTwitterVideo } from './modules/fixEmbedTwitterVideo/fixEmbedTwitterVideo.module';
import { quoiFeur } from './modules/quoiFeur/quoiFeur.module';
import { recurringMessage } from './modules/recurringMessage/recurringMessage.module';
import { voiceOnDemand } from './modules/voiceOnDemand/voiceOnDemand.module';

const modules = [
fart,
voiceOnDemand,
coolLinksManagement,
quoiFeur,
recurringMessage,
fixEmbedTwitterVideo,
];

const createdModules = await createAllModules(modules);

Expand Down
15 changes: 0 additions & 15 deletions src/modules/modules.ts

This file was deleted.

0 comments on commit 9a4a57a

Please sign in to comment.