Commit fa614711 authored by nanahira's avatar nanahira

catchup

parent cb53fbf2
...@@ -23,7 +23,7 @@ upload_to_minio: ...@@ -23,7 +23,7 @@ upload_to_minio:
tags: tags:
- linux - linux
script: script:
- aws s3 --endpoint=https://minio.mycard.moe:9000 sync --delete dist/ s3://nanahira/koishi-plugin/cache-memcached - aws s3 --endpoint=https://minio.mycard.moe:9000 sync --delete dist/full/ s3://nanahira/koishi-plugin/cache-memcached
only: only:
- master - master
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"scripts": { "scripts": {
"lint": "eslint --fix .", "lint": "eslint --fix .",
"build": "webpack" "build": "webpack && env PACK_ALL=1 webpack"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
...@@ -31,24 +31,24 @@ ...@@ -31,24 +31,24 @@
"homepage": "https://github.com/koishijs/koishi-plugin-cache-memcached", "homepage": "https://github.com/koishijs/koishi-plugin-cache-memcached",
"dependencies": { "dependencies": {
"@types/memjs": "^1.2.3", "@types/memjs": "^1.2.3",
"source-map-support": "^0.5.20" "schemastery-gen": "^1.0.3",
"source-map-support": "^0.5.20",
"memjs": "^1.3.0",
"moment": "^2.29.1",
"encoded-buffer": "^0.2.6"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.0.0-alpha.10" "koishi": "^4.0.0-beta-2"
}, },
"devDependencies": { "devDependencies": {
"@types/moment": "^2.13.0", "@types/moment": "^2.13.0",
"@types/node": "^16.11.1", "@types/node": "^16.11.1",
"@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0", "@typescript-eslint/parser": "^4.33.0",
"encoded-buffer": "^0.2.6",
"eslint": "^7.32.0", "eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1", "eslint-plugin-prettier": "^3.4.1",
"koishi": "^4.0.0-alpha.10", "koishi": "^4.0.0-beta.2",
"koishi-utils-schemagen": "^1.1.7",
"memjs": "^1.3.0",
"moment": "^2.29.1",
"prettier": "^2.4.1", "prettier": "^2.4.1",
"raw-loader": "^4.0.2", "raw-loader": "^4.0.2",
"ts-loader": "^9.2.6", "ts-loader": "^9.2.6",
......
import 'source-map-support/register'; import 'source-map-support/register';
import { DefineSchema } from 'koishi-utils-schemagen';
import { ClientOptions } from 'memjs'; import { ClientOptions } from 'memjs';
import { RegisterSchema, DefineSchema } from 'schemastery-gen';
@RegisterSchema()
export class MemcachedCachePluginConfig { export class MemcachedCachePluginConfig {
@DefineSchema({ desc: 'Memcached 服务器地址', default: 'localhost:11211' }) @DefineSchema({ desc: 'Memcached 服务器地址', default: 'localhost:11211' })
endpoint: string; endpoint: string;
......
import 'source-map-support/register'; import 'source-map-support/register';
import { Context } from 'koishi'; import { Context } from 'koishi';
import { MemcachedCache, MemcachedCachePlugin } from './plugin'; import { MemcachedCache, MemcachedCachePlugin } from './plugin';
import { MemcachedCachePluginConfigLike } from './config'; import { MemcachedCachePluginConfig } from './config';
export * from './config'; export * from './config';
export * from './plugin'; export * from './plugin';
export const name = 'memcached'; export const name = 'memcached';
const plugin = new MemcachedCachePlugin(); const plugin = new MemcachedCachePlugin();
export const schema = plugin.schema; export const schema = plugin.schema;
export function apply( export function apply(ctx: Context, config: MemcachedCachePluginConfig) {
ctx: Context,
config: Partial<MemcachedCachePluginConfigLike>,
) {
ctx.plugin(plugin, config); ctx.plugin(plugin, config);
} }
...@@ -4,13 +4,14 @@ import { ...@@ -4,13 +4,14 @@ import {
MemcachedCachePluginConfig, MemcachedCachePluginConfig,
MemcachedCachePluginConfigLike, MemcachedCachePluginConfigLike,
} from './config'; } from './config';
import { schemaFromClass, schemaTransform } from 'koishi-utils-schemagen';
import { Client } from 'memjs'; import { Client } from 'memjs';
import { Moment } from 'moment'; import { Moment } from 'moment';
import moment from 'moment'; import moment from 'moment';
import * as EncodeBuffer from 'encoded-buffer'; import * as EncodeBuffer from 'encoded-buffer';
export class MemcachedCache extends Cache { export class MemcachedCache extends Cache {
protected start(): void | Promise<void> {}
protected stop(): void | Promise<void> {}
private logger = new Logger('memcached'); private logger = new Logger('memcached');
private mem: Client; private mem: Client;
constructor(ctx: Context, private config: MemcachedCachePluginConfig) { constructor(ctx: Context, private config: MemcachedCachePluginConfig) {
...@@ -148,12 +149,10 @@ export class MemcachedCachePlugin { ...@@ -148,12 +149,10 @@ export class MemcachedCachePlugin {
private config: MemcachedCachePluginConfig; private config: MemcachedCachePluginConfig;
private ctx: Context; private ctx: Context;
name = 'memcached-main'; name = 'memcached-main';
schema: Schema<MemcachedCachePluginConfigLike> = schemaFromClass( schema = MemcachedCachePluginConfig;
MemcachedCachePluginConfig, apply(ctx: Context, config: MemcachedCachePluginConfig) {
);
apply(ctx: Context, config: MemcachedCachePluginConfigLike) {
this.ctx = ctx; this.ctx = ctx;
this.config = schemaTransform(MemcachedCachePluginConfig, config); this.config = config;
ctx.cache = new MemcachedCache(ctx, this.config); ctx.cache = new MemcachedCache(ctx, this.config);
} }
} }
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',
mode: "production", mode: 'production',
target: "node", target: 'node',
devtool: "source-map", devtool: 'source-map',
module: { module: {
rules: [ rules: [
{ {
test: /\.tsx?$/, test: /\.tsx?$/,
use: "ts-loader", use: 'ts-loader',
exclude: /node_modules/, exclude: /node_modules/,
}, },
{ test: /\.mustache$/, use: "raw-loader" }, { test: /\.mustache$/, use: 'raw-loader' },
], ],
}, },
resolve: { resolve: {
extensions: [".tsx", ".ts", ".js"], extensions: ['.tsx', '.ts', '.js'],
}, },
output: { output: {
filename: "index.js", filename: 'index.js',
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',
} ...(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