diff --git a/src/lib/store/EventStore.ts b/src/lib/store/EventStore.ts index 7c72713..d29c636 100644 --- a/src/lib/store/EventStore.ts +++ b/src/lib/store/EventStore.ts @@ -5,11 +5,11 @@ export class EventStore extends StoreBase<'event', Structures['event'][]> { constructor() { super('events'); } - async update(path: string) { + async update(path: string, isCore?: boolean) { const { default: file }: { default: Structures['event'] } = await import( path ); const current = this.get(file.name); - this.add(file.name, current ? [file, ...current] : [file]); + this.add(file.name, current ? [file, ...current] : [file], path, isCore); } } diff --git a/src/lib/store/StoreBase.ts b/src/lib/store/StoreBase.ts index a66c808..948b18a 100644 --- a/src/lib/store/StoreBase.ts +++ b/src/lib/store/StoreBase.ts @@ -14,24 +14,33 @@ export class StoreBase< T extends keyof Structures, X extends Structures[T] | Structures[T][] = Structures[T] > extends Map { - constructor(private storeDirectryName: string) { + constructor(storeDirectryName: string) { super(); const directorypath = getDirectoryPath(storeDirectryName); if (!directorypath) return; - watch([directorypath, path.resolve(__dirname, '../../core/')]).on( + watch(directorypath).on('add', (path) => this.update(path)); + + watch(path.resolve(__dirname, '../../core/', storeDirectryName)).on( 'add', - (path) => this.update(path) + (path) => this.update(path, true) ); } - add(name: string, file: X): this { - Client.log.info('[Store]', `/${this.storeDirectryName} - ${name}`); + public add(name: string, file: X, filePath: string, isCore?: boolean): this { + Client.log.info( + `[Store] `, + isCore ? '(core)' : ' ', + ' ', + name.padEnd(20, ' '), + '`' + filePath.split('/').slice(-2).join('/') + '`' + ); return this.set(name, file); } - async update(path: string) { + async update(path: string, isCore?: boolean) { const { default: file }: { default: X } = await import(path); + if ('name' in file) { - this.add(file.name, file); + this.add(file.name, file, path, isCore); } } }