@skweb/plugin
v1.3.0
Published
Plugin interface and types for skweb framework.
Readme
@skweb/plugin
Plugin system for skweb framework. A plugin is a module that implements the
PluginModule interface; the framework discovers and orchestrates it.
Installation
npm install @skweb/pluginUsage
import type { PluginModule, PluginContext } from '@skweb/plugin'
import { VERSION } from '@skweb/plugin'
const myPlugin: PluginModule = {
name: 'my-plugin',
version: '1.0.0',
description: 'Does something useful',
async beforeSetup(ctx: PluginContext) {
// Run before the framework finishes setup.
// ctx.framework is available to inject db/redis via setDb/setRedis.
// ctx.db / ctx.redis are optional — only present if a prior plugin injected them.
},
async afterSetup(ctx: PluginContext) {
// Run after the framework finishes setup.
// ctx.app is available here (web only).
},
async initData(ctx: PluginContext) {
// Seed initial data.
}
}
export default myPluginA plugin module is a plain object — no base class required. All hooks are optional; implement only the ones you need.
PluginContext provides:
framework— the framework instance (implementsFrameworkLike), used to injectdb/redisviactx.framework.setDb(db)/ctx.framework.setRedis(redis)db?/redis?— optional, only present if a prior plugin injected themapp?— the runtime adapter instance (web only)
The package also exports VERSION (the running @skweb/plugin version) which
is useful for diagnostics.
License
MIT
