@@ -60,7 +60,7 @@ export const CatPlugin = Object.freeze({
60
60
* @param fn The function to execute when the event is triggered.
61
61
* @returns the event instance
62
62
*/
63
- on : < T extends EventNames > ( event : T , fn : PluginEvents [ T ] ) => ( { name : event , fn } as PluginEvent < T > ) ,
63
+ on : < T extends EventNames > ( event : T , fn : PluginEvents [ T ] ) : PluginEvent < T > => ( { name : event , fn } ) ,
64
64
} )
65
65
66
66
export class Plugin <
@@ -142,7 +142,7 @@ export class Plugin<
142
142
id : this . id ,
143
143
active : this . active ,
144
144
manifest : this . manifest ,
145
- upgradable : false ,
145
+ upgradable : false , // TODO: Add registry support for upgrading
146
146
forms : this . forms . map ( ( { name, description, active } ) => ( { name, description, active } ) ) ,
147
147
tools : this . tools . map ( ( { name, description, active } ) => ( { name, description, active } ) ) ,
148
148
hooks : this . hooks . map ( ( { name, priority } ) => ( { name, priority } ) ) ,
@@ -161,7 +161,7 @@ export class Plugin<
161
161
return this . _settings
162
162
}
163
163
164
- set settings ( settings : Record < string , any > ) {
164
+ set settings ( settings : S ) {
165
165
this . _settings = this . schema . parse ( settings ) as S
166
166
const settingsPath = join ( this . path , 'settings.json' )
167
167
Bun . write ( settingsPath , JSON . stringify ( this . _settings , null , 2 ) )
@@ -172,17 +172,16 @@ export class Plugin<
172
172
* @param event The name of the event to trigger.
173
173
*/
174
174
triggerEvent ( event : EventNames ) {
175
- const callback = this . events [ event ]
175
+ const callback = this . events [ event ] as ( value : Record < string , any > ) => void
176
176
if ( callback ) {
177
177
const timeStart = performance . now ( )
178
- // TODO: Improve this check
179
178
if ( event === 'installed' || event === 'removed' ) callback ( this . manifest )
180
- else callback ( this . settings as TODO )
179
+ else if ( event === 'enabled' || event === 'disabled' ) callback ( this . settings )
181
180
const timeEnd = performance . now ( )
182
181
const eventTime = ( timeEnd - timeStart ) . toFixed ( 2 )
183
182
log . tag ( 'bgCyanBright' , 'PLUGIN' , event , `event of ${ this . id } executed in ${ eventTime } ms` )
184
183
}
185
- else log . info ( `Plugin ${ this . id } ${ event } ` )
184
+ else log . debug ( `Plugin ${ this . id } ${ event } ` )
186
185
}
187
186
188
187
private async loadManifest ( ) {
@@ -206,7 +205,7 @@ export class Plugin<
206
205
const settingsPath = join ( this . path , 'settings.json' )
207
206
if ( existsSync ( settingsPath ) ) {
208
207
try {
209
- const json = destr < Record < string , any > > ( await Bun . file ( settingsPath ) . text ( ) )
208
+ const json = destr ( await Bun . file ( settingsPath ) . text ( ) )
210
209
this . _settings = this . schema . parse ( json ) as S
211
210
}
212
211
catch ( err ) {
@@ -233,7 +232,6 @@ export class Plugin<
233
232
234
233
private async importAll ( files : Dirent [ ] ) {
235
234
log . debug ( `Importing plugin features...` )
236
- // TODO: Improve plugin methods import (maybe with the Function class (?), ECMAScript parser or AST parser)
237
235
for ( const file of files ) {
238
236
const normalizedPath = relative ( process . cwd ( ) , file . path )
239
237
const content = await Bun . file ( normalizedPath ) . text ( )
0 commit comments