11import { readFile } from 'node:fs/promises' ;
2- import { EVENT_FILES_DIR , pullEventFiles } from './git.ts' ;
2+ import { pull } from './git.ts' ;
33import { typedEntries } from './javascript-helper.ts' ;
4- import type { EventDirectory , EventId } from './types.ts' ;
4+ import type { EventDirectory , EventEntry , EventId } from './types.ts' ;
5+
6+ const DIRECTORY = 'eventfiles' ;
57
68let directory : EventDirectory = { } ;
79let namesOfEvents : Readonly < Record < EventId , string > > = { } ;
@@ -11,11 +13,8 @@ await update();
1113console . log ( new Date ( ) , 'eventfiles loaded' ) ;
1214
1315async function update ( ) {
14- await pullEventFiles ( ) ;
15- const directoryString = await readFile (
16- `${ EVENT_FILES_DIR } /directory.json` ,
17- 'utf8' ,
18- ) ;
16+ await pull ( DIRECTORY , 'https://github.com/HAWHHCalendarBot/eventfiles.git' ) ;
17+ const directoryString = await readFile ( `${ DIRECTORY } /directory.json` , 'utf8' ) ;
1918 directory = JSON . parse ( directoryString ) as EventDirectory ;
2019 namesOfEvents = await generateMapping ( ) ;
2120}
@@ -106,3 +105,8 @@ export function find(
106105 events : Object . fromEntries ( typedEntries ( accumulator ) . sort ( ( a , b ) => a [ 1 ] . localeCompare ( b [ 1 ] ) ) ) ,
107106 } ;
108107}
108+
109+ export async function loadEvents ( eventId : EventId ) : Promise < EventEntry [ ] > {
110+ const content = await readFile ( `${ DIRECTORY } /events/${ eventId } .json` , 'utf8' ) ;
111+ return JSON . parse ( content ) as EventEntry [ ] ;
112+ }
0 commit comments