Skip to content

Commit

Permalink
feat: enhanced store log
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse484 committed Oct 23, 2022
1 parent ed9c047 commit 5252d41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/lib/store/EventStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
23 changes: 16 additions & 7 deletions src/lib/store/StoreBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,33 @@ export class StoreBase<
T extends keyof Structures,
X extends Structures[T] | Structures[T][] = Structures[T]
> extends Map<string, X> {
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);
}
}
}

0 comments on commit 5252d41

Please sign in to comment.