Commit 774aef24 authored by nanahira's avatar nanahira

catchup

parent 589953bb
...@@ -16,17 +16,6 @@ build: ...@@ -16,17 +16,6 @@ build:
paths: paths:
- dist/ - dist/
upload_to_minio:
stage: deploy
dependencies:
- build
tags:
- linux
script:
- aws s3 --endpoint=https://minio.mycard.moe:9000 sync --delete dist/ s3://nanahira/koishi-plugin/ygocard
only:
- master
deploy_npm: deploy_npm:
stage: deploy stage: deploy
dependencies: dependencies:
......
This diff is collapsed.
import { DefineSchema, UseSchema } from 'koishi-utils-schemagen'; import { DefineSchema, RegisterSchema } from 'schemastery-gen';
import { Schema } from 'koishi'; import { Schema } from 'koishi';
import { YGOProCardLike } from './YGOProCard'; import { YGOProCardLike } from './YGOProCard';
import _ from 'lodash'; import _ from 'lodash';
import { renderTemplate } from './utility'; import { renderTemplate } from './utility';
@RegisterSchema()
export class YGOCardConfig { export class YGOCardConfig {
@DefineSchema({ type: 'string', desc: '命令名', default: 'card' }) @DefineSchema({ type: 'string', desc: '命令名', default: 'card' })
commandName: string; commandName: string;
...@@ -19,7 +20,9 @@ export class YGOCardConfig { ...@@ -19,7 +20,9 @@ export class YGOCardConfig {
@DefineSchema({ type: 'number', default: 100, desc: '查询最多显示的数量' }) @DefineSchema({ type: 'number', default: 100, desc: '查询最多显示的数量' })
matchCount: number; matchCount: number;
@UseSchema(Schema.select(['cn', 'en'], '显示语言').default('cn')) @DefineSchema({
schema: Schema.select(['cn', 'en'], '显示语言').default('cn'),
})
lang: 'cn' | 'en'; lang: 'cn' | 'en';
@DefineSchema({ type: 'boolean', desc: '是否展示卡图', default: true }) @DefineSchema({ type: 'boolean', desc: '是否展示卡图', default: true })
......
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 { YGOCardConfig } from './config';
export * from './plugin';
export * from './config';
export const name = 'ygocard'; export const name = 'ygocard';
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: YGOCardConfig) {
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 } from 'koishi';
import { YGOCardConfig } from './config'; import { YGOCardConfig } from './config';
import { schemaFromClass, schemaTransform } from 'koishi-utils-schemagen';
import sqlite, { Database } from 'better-sqlite3'; import sqlite, { Database } from 'better-sqlite3';
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import _ from 'lodash'; import _ from 'lodash';
...@@ -16,7 +15,7 @@ export class MyPlugin { ...@@ -16,7 +15,7 @@ export class MyPlugin {
private ctx: Context; private ctx: Context;
private dbs: Database[] = []; private dbs: Database[] = [];
name = 'ygocard-main'; name = 'ygocard-main';
schema: Schema<Config> = schemaFromClass(YGOCardConfig); schema = YGOCardConfig;
private queryInDB(value: string, db: Database) { private queryInDB(value: string, db: Database) {
const possibleValueNumber = parseInt(value) || 0; const possibleValueNumber = parseInt(value) || 0;
const statement = db.prepare<[number, string, string]>( const statement = db.prepare<[number, string, string]>(
...@@ -55,9 +54,9 @@ export class MyPlugin { ...@@ -55,9 +54,9 @@ export class MyPlugin {
}), }),
); );
} }
async apply(ctx: Context, config: Config) { async apply(ctx: Context, config: YGOCardConfig) {
this.ctx = ctx; this.ctx = ctx;
this.config = schemaTransform(YGOCardConfig, config); this.config = config;
await this.loadDBs(); await this.loadDBs();
ctx.on('connect', () => this.loadDBs()); ctx.on('connect', () => this.loadDBs());
ctx.on('disconnect', () => { ctx.on('disconnect', () => {
......
const path = require('path'); const path = require('path');
const packgeInfo = require('./package.json');
function externalsFromDep() {
return Object.fromEntries(
[
...Object.keys(packgeInfo.dependencies || {}),
...Object.keys(packgeInfo.peerDependencies || {}),
]
.filter((dep) => dep !== 'source-map-support')
.map((dep) => [dep, dep]),
);
}
const packAll = !!process.env.PACK_ALL;
module.exports = { module.exports = {
entry: './src/index.ts', entry: './src/index.ts',
...@@ -23,10 +37,10 @@ module.exports = { ...@@ -23,10 +37,10 @@ module.exports = {
library: { library: {
type: 'commonjs', type: 'commonjs',
}, },
path: path.resolve(__dirname, 'dist'), path: path.resolve(__dirname, packAll ? 'dist/full' : 'dist'),
}, },
externals: { externals: {
koishi: 'koishi', koishi: 'koishi',
'better-sqlite3': 'better-sqlite3', ...(packAll ? {} : externalsFromDep()),
}, },
}; };
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