@kotori-bot/loader
Advanced tools
Comparing version 1.4.2 to 1.5.0
@@ -1,3 +0,4 @@ | ||
export * from './loader'; | ||
export * from './consts'; | ||
export * from './class/loader'; | ||
export * from './constants'; | ||
export * from './decorators'; | ||
export * from '@kotori-bot/logger'; |
@@ -7,3 +7,3 @@ "use strict"; | ||
* @LastEditors: Hotaru biyuehuya@gmail.com | ||
* @LastEditTime: 2024-02-20 20:20:54 | ||
* @LastEditTime: 2024-05-02 10:44:55 | ||
*/ | ||
@@ -25,4 +25,5 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./loader"), exports); | ||
__exportStar(require("./consts"), exports); | ||
__exportStar(require("./class/loader"), exports); | ||
__exportStar(require("./constants"), exports); | ||
__exportStar(require("./decorators"), exports); | ||
__exportStar(require("@kotori-bot/logger"), exports); |
@@ -35,3 +35,3 @@ "use strict"; | ||
* @LastEditors: Hotaru biyuehuya@gmail.com | ||
* @LastEditTime: 2024-02-24 19:11:35 | ||
* @LastEditTime: 2024-05-01 22:06:58 | ||
*/ | ||
@@ -44,3 +44,3 @@ const core_1 = require("@kotori-bot/core"); | ||
const log_1 = __importDefault(require("./log")); | ||
const consts_1 = require("./consts"); | ||
const constants_1 = require("./constants"); | ||
const server_1 = __importDefault(require("./service/server")); | ||
@@ -63,3 +63,3 @@ const file_1 = __importDefault(require("./service/file")); | ||
const options = { | ||
mode: file === consts_1.DEV_CONFIG_NAME ? 'dev' : 'build' | ||
mode: file === constants_1.DEV_CONFIG_NAME ? 'dev' : 'build' | ||
}; | ||
@@ -121,3 +121,3 @@ if (dir) | ||
super(); | ||
const file = options && options.mode === 'dev' ? consts_1.DEV_CONFIG_NAME : consts_1.BUILD_CONFIG_NAME; | ||
const file = options && options.mode === 'dev' ? constants_1.DEV_CONFIG_NAME : constants_1.BUILD_CONFIG_NAME; | ||
const runnerConfig = getRunnerConfig(file, options?.dir); | ||
@@ -209,4 +209,4 @@ const ctx = new core_1.Core(getCoreConfig(file, runnerConfig.baseDir)); | ||
if (!requiredVersion.includes('workspace') && | ||
(!consts_1.SUPPORTS_VERSION.exec(requiredVersion) || requiredVersion !== this.ctx.pkg.version)) { | ||
if (consts_1.SUPPORTS_HALF_VERSION.exec(requiredVersion)) { | ||
(!constants_1.SUPPORTS_VERSION.exec(requiredVersion) || requiredVersion !== this.ctx.pkg.version)) { | ||
if (constants_1.SUPPORTS_HALF_VERSION.exec(requiredVersion)) { | ||
this.ctx.logger.warn(`incomplete supported module version: ${requiredVersion}`); | ||
@@ -251,3 +251,3 @@ } | ||
const res = await this.ctx.http | ||
.get("https://hotaru.icu/api/agent/?url=https://raw.githubusercontent.com/kotorijs/kotori/master/packages/kotori/package.json" /* GLOBAL.UPDATE */) | ||
.get("https://hotaru.icu/api/agent/?url=https://raw.githubusercontent.com/kotorijs/kotori/master/packages/core/package.json" /* GLOBAL.UPDATE */) | ||
.catch(() => this.ctx.logger.error('get update failed, please check your network')); | ||
@@ -254,0 +254,0 @@ if (!res || !core_1.Tsu.Object({ version: core_1.Tsu.String() }).check(res)) { |
@@ -34,3 +34,3 @@ "use strict"; | ||
const logger_1 = require("@kotori-bot/logger"); | ||
const consts_1 = require("./consts"); | ||
const constants_1 = require("./constants"); | ||
const logger_2 = __importDefault(require("./utils/logger")); | ||
@@ -105,3 +105,3 @@ exports.localeTypeSchema = core_1.Tsu.Union([ | ||
} | ||
if (path_1.default.parse(file).ext !== (this.isDev ? consts_1.DEV_FILE : consts_1.BUILD_FILE)) | ||
if (path_1.default.parse(file).ext !== (this.isDev ? constants_1.DEV_FILE : constants_1.BUILD_FILE)) | ||
return; | ||
@@ -147,7 +147,7 @@ list.push(path_1.default.resolve(file)); | ||
pkg = result.data; | ||
const devMode = this.isDev && (0, fs_1.existsSync)(path_1.default.resolve(dir, consts_1.DEV_IMPORT)); | ||
const main = path_1.default.resolve(dir, devMode ? consts_1.DEV_IMPORT : pkg.main); | ||
const devMode = this.isDev && (0, fs_1.existsSync)(path_1.default.resolve(dir, constants_1.DEV_IMPORT)); | ||
const main = path_1.default.resolve(dir, devMode ? constants_1.DEV_IMPORT : pkg.main); | ||
if (!fs_1.default.existsSync(main)) | ||
throw new core_1.DevError(`cannot find ${main}`); | ||
const dirs = path_1.default.join(dir, devMode ? consts_1.DEV_CODE_DIRS : path_1.default.dirname(pkg.main)); | ||
const dirs = path_1.default.join(dir, devMode ? constants_1.DEV_CODE_DIRS : path_1.default.dirname(pkg.main)); | ||
const files = fs_1.default.statSync(dirs).isDirectory() ? this.getDirFiles(dirs) : []; | ||
@@ -154,0 +154,0 @@ this[core_1.Symbols.modules].set(pkg.name, [ |
@@ -6,3 +6,3 @@ import { Context, Service, createConfig, loadConfig, saveConfig } from '@kotori-bot/core'; | ||
getFile(filename: string): string; | ||
load(filename: string, type?: Parameters<typeof loadConfig>[1], init?: Parameters<typeof loadConfig>[2]): string | object | unknown[] | null; | ||
load<T = Parameters<typeof saveConfig>[1]>(filename: string, type?: Parameters<typeof loadConfig>[1], init?: Parameters<typeof loadConfig>[2]): T; | ||
save(filename: string, data: Parameters<typeof saveConfig>[1], type?: Parameters<typeof saveConfig>[2]): void; | ||
@@ -9,0 +9,0 @@ create(filename: string, data?: Parameters<typeof createConfig>[1], type?: Parameters<typeof createConfig>[2]): void; |
@@ -16,2 +16,3 @@ "use strict"; | ||
} | ||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ | ||
load(filename, type, init) { | ||
@@ -18,0 +19,0 @@ return (0, core_1.loadConfig)(this.getFile(filename), type, init); |
/// <reference types="body-parser" /> | ||
/// <reference types="connect" /> | ||
/// <reference types="serve-static" /> | ||
/// <reference types="node" /> | ||
import { Context, Service } from '@kotori-bot/core'; | ||
import express from 'express'; | ||
import { IncomingMessage } from 'http'; | ||
import ws from 'ws'; | ||
interface ServerConfig { | ||
@@ -12,2 +15,3 @@ port: number; | ||
private server?; | ||
private wsServer?; | ||
constructor(ctx: Context, config: ServerConfig); | ||
@@ -26,3 +30,4 @@ start(): void; | ||
static: import("serve-static").RequestHandlerConstructor<express.Response<any, Record<string, any>>>; | ||
wss(path?: string): ws.Server<typeof ws, typeof IncomingMessage> | undefined; | ||
} | ||
export default Server; |
@@ -9,5 +9,7 @@ "use strict"; | ||
const express_1 = __importDefault(require("express")); | ||
const ws_1 = __importDefault(require("ws")); | ||
class Server extends core_1.Service { | ||
app; | ||
server; | ||
wsServer; | ||
constructor(ctx, config) { | ||
@@ -39,11 +41,17 @@ super(ctx, config, 'server'); | ||
start() { | ||
if (this.server) | ||
return; | ||
this.server = this.app.listen(this.config.port); | ||
this.ctx.logger.label('server').info(`server start at http://127.0.0.1:${this.config.port}`); | ||
if (!this.server) { | ||
this.server = this.app.listen(this.config.port); | ||
this.ctx.logger.label('server').info(`http server start at http://127.0.0.1:${this.config.port}`); | ||
} | ||
if (!this.wsServer) { | ||
const port = this.config.port + 1; | ||
this.wsServer = new ws_1.default.Server({ port }); | ||
this.ctx.logger.label('server').info(`websocket server start at ws://127.0.0.1:${port}`); | ||
} | ||
} | ||
stop() { | ||
if (!this.server) | ||
return; | ||
this.server.close(); | ||
if (this.server) | ||
this.server.close(); | ||
if (this.wsServer) | ||
this.wsServer.close(); | ||
} | ||
@@ -60,4 +68,30 @@ get; | ||
static = express_1.default.static; | ||
wss(path) { | ||
if (!this.wsServer) | ||
return undefined; | ||
if (!path) | ||
return this.wsServer; | ||
const eventEmiter = new Proxy(this.wsServer.on, { | ||
apply: (target, thisArg, argArray) => { | ||
const [event, callback] = argArray; | ||
if (event !== 'connection') | ||
return Reflect.apply(target, thisArg, argArray); | ||
return this.wsServer.on(event, (ws, req) => { | ||
if (req.url !== path && path) | ||
return; | ||
callback(ws, req); | ||
this.ctx.logger.label('server').info(`websocket connection from ${req.url}`); | ||
}); | ||
} | ||
}); | ||
return new Proxy(this.wsServer, { | ||
get: (target, p, receiver) => { | ||
if (p !== 'on') | ||
return Reflect.get(target, p, receiver); | ||
return eventEmiter; | ||
} | ||
}); | ||
} | ||
} | ||
exports.Server = Server; | ||
exports.default = Server; |
{ | ||
"name": "@kotori-bot/loader", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "Loader For KotoriBot", | ||
@@ -27,5 +27,7 @@ "license": "GPL-3.0", | ||
"dependencies": { | ||
"@types/ws": "^8.5.8", | ||
"express": "^4.18.2", | ||
"knex": "^3.1.0", | ||
"@kotori-bot/core": "^1.3.0", | ||
"ws": "^8.14.2", | ||
"@kotori-bot/core": "^1.4.0", | ||
"@kotori-bot/logger": "^1.2.0" | ||
@@ -32,0 +34,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105200
33
1676
6
9
+ Added@types/ws@^8.5.8
+ Addedws@^8.14.2
+ Added@types/node@22.9.3(transitive)
+ Added@types/ws@8.5.13(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedws@8.18.0(transitive)
Updated@kotori-bot/core@^1.4.0