@skweb/types
v1.1.0
Published
Shared types and interfaces for skweb packages.
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.db / ctx.redis are present when the framework was constructed with
// db/redis options; read-only access also available via ctx.framework.
},
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), exposing read-onlydbInstance/redisInstance/modelsgettersdb?/redis?— optional, present when the framework was constructed with db/redis optionsapp?— the runtime adapter instance (web only)
The package also exports VERSION (the running @skweb/plugin version) which
is useful for diagnostics.
License
MIT
