Commit e33ea961 authored by nanahira's avatar nanahira

use schemagen as default

parent 6a881169
Pipeline #6277 passed with stages
in 1 minute and 33 seconds
...@@ -15,4 +15,5 @@ npm install --save-dev \ ...@@ -15,4 +15,5 @@ npm install --save-dev \
ts-loader \ ts-loader \
webpack \ webpack \
webpack-cli \ webpack-cli \
koishi@^4.0.0-alpha.9 koishi@^4.0.0-alpha.9 \
koishi-utils-schemagen
import 'source-map-support/register';
import { DefineSchema, UseSchema } from 'koishi-utils-schemagen';
import { Schema } from 'koishi';
export class Config {
@DefineSchema({ type: 'string', desc: '命令名', default: 'cmd' })
commandName: string;
}
import 'source-map-support/register'; import 'source-map-support/register';
import { Context } from 'koishi'; import { Context } from 'koishi';
import { Config, MyPlugin } from './plugin'; import { MyPlugin } from './plugin';
export { Config } from './plugin'; import { Config } from './config';
export { Config } from './config';
export const name = 'my-plugin'; export const name = 'my-plugin';
const plugin = new MyPlugin(); const plugin = new MyPlugin();
export const schema = plugin.schema; export const schema = plugin.schema;
export function apply(ctx: Context, config: Config) { export function apply(ctx: Context, config: Partial<Config>) {
ctx.plugin(plugin, config); ctx.plugin(plugin, config);
} }
import 'source-map-support/register'; import 'source-map-support/register';
import { Context, Schema } from 'koishi'; import { Context, Schema } from 'koishi';
import { Config } from './config';
export interface Config { import { schemaFromClass, schemaTransform } from 'koishi-utils-schemagen';
prefix: string;
}
export class MyPlugin { export class MyPlugin {
config: Config private config: Config;
ctx: Context; private ctx: Context;
name = 'my-plugin-main'; name = 'my-plugin-main';
schema: Schema<Config> = Schema.object({ schema: Schema<Config> = schemaFromClass(Config);
prefix: Schema.string('desc') apply(ctx: Context, config: Partial<Config>) {
});
apply(ctx: Context, config: Config) {
this.ctx = ctx; this.ctx = ctx;
this.config = Schema.validate(config, this.schema);; this.config = schemaTransform(Config, config);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment