Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d4da57d7aa | |||
| 3f1de332fd | |||
| 25a8f35f28 | |||
| fc31824aa4 | |||
| bb154474b1 | |||
| a5d831aa0b | |||
| e61b0aeb17 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,4 +1,9 @@
|
|||||||
|
.rollup.cache
|
||||||
.yarn*
|
.yarn*
|
||||||
.vscode
|
.vscode
|
||||||
|
.theia
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
|
package-lock.json
|
||||||
|
packages/nashorn/docs
|
||||||
|
!packages/types/dist
|
||||||
|
|||||||
26
.npmignore
Normal file
26
.npmignore
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
src
|
||||||
|
test
|
||||||
|
typings
|
||||||
|
bundled
|
||||||
|
build
|
||||||
|
coverage
|
||||||
|
docs
|
||||||
|
wiki
|
||||||
|
gulpfile.js
|
||||||
|
bower.json
|
||||||
|
karma.conf.js
|
||||||
|
tsconfig.json
|
||||||
|
typings.json
|
||||||
|
CONTRIBUTING.md
|
||||||
|
ISSUE_TEMPLATE.md
|
||||||
|
PULL_REQUEST_TEMPLATE.md
|
||||||
|
tslint.json
|
||||||
|
wallaby.js
|
||||||
|
.travis.yml
|
||||||
|
.gitignore
|
||||||
|
.vscode
|
||||||
|
.theia
|
||||||
|
type_definitions
|
||||||
|
tsconfig.tsbuildinfo
|
||||||
|
*.tsbuildinfo
|
||||||
|
.rollup.cache
|
||||||
47
README.MD
47
README.MD
@@ -8,28 +8,27 @@
|
|||||||
|
|
||||||
```txt
|
```txt
|
||||||
└─packages
|
└─packages
|
||||||
├─api 全平台兼容的接口
|
├─api 全平台兼容的接口
|
||||||
├─core 核心代码 用于引导加载
|
├─core 核心代码 用于引导加载
|
||||||
├─common 公共类库代码 例如 http reflect 模块
|
├─common 公共类库代码 例如 http reflect 模块
|
||||||
├─compile 编译器相关功能
|
├─client NodeJS的Minecraft客户端 用于调试插件
|
||||||
├─client NodeJS 的 Minecraft 客户端 已迁移至 ms-client
|
├─container IOC容器 用于注入具体实现
|
||||||
├─container IOC容器 用于注入具体实现
|
├─ployfill Nashorn 的一些自定义增强
|
||||||
├─database 数据库相关功能
|
├─nashorn Nashorn 的类型定义
|
||||||
├─protocol 协议处理相关功能
|
├─bungee BungeeCordAPI内部实现
|
||||||
├─service 服务相关功能
|
├─bukkit BukkitAPI内部实现
|
||||||
├─i18n 多语言环境相关支持
|
├─sponge SpongeAPI内部实现
|
||||||
├─polyfill Nashorn 的一些自定义增强
|
├─nukkit NukkitAPI内部实现
|
||||||
├─nashorn Nashorn 的类型定义
|
├─plugin 插件管理器
|
||||||
├─nodejs NodeJS 的部分 Java 实现
|
├─websocket Netty的WebSocket注入
|
||||||
├─bungee BungeeCordAPI 内部实现
|
├─type Java的类型定义
|
||||||
├─bukkit BukkitAPI 内部实现
|
| ├─bungee BungeeCord类型定义
|
||||||
├─sponge SpongeAPI 内部实现
|
| ├─bukkit Bukkit类型定义
|
||||||
├─nukkit NukkitAPI 内部实现
|
| ├─sponge Sponge类型定义
|
||||||
├─molang MoLang 解析库
|
| └─nukkit Nukkit类型定义
|
||||||
├─qrcode 二维码相关类库
|
└─plugins 这里当然是插件啦
|
||||||
├─plugin 插件管理器
|
├─bungee 只兼容BungeeCord的插件
|
||||||
├─websocket WebSocket 相关实现
|
├─bukkit 只兼容Bukkit的插件
|
||||||
| ├─client 基于 Netty 的 WebSocket 客户端
|
├─sponge 只兼容Sponge的插件
|
||||||
| └─server 基于 Netty 的 WebSocket 服务端
|
└─nukkit 只兼容Nukkit的插件
|
||||||
└─type 类型定义 已迁移到 @javatypes
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
{
|
{
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"npmClient": "pnpm",
|
"npmClient": "yarn",
|
||||||
|
"packages": [
|
||||||
|
"packages/*"
|
||||||
|
],
|
||||||
"command": {
|
"command": {
|
||||||
"run": {
|
"run": {
|
||||||
"stream": true
|
"stream": true
|
||||||
|
|||||||
31
package.json
31
package.json
@@ -6,30 +6,23 @@
|
|||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"bs": "pnpm install",
|
"bs": "lerna bootstrap",
|
||||||
"clean": "lerna run clean",
|
"clean": "lerna run clean",
|
||||||
"watch": "lerna run watch --parallel",
|
"watch": "lerna run watch --parallel",
|
||||||
"build": "lerna run build",
|
"build": "lerna run build",
|
||||||
"ug": "pnpm up -r -i",
|
"ug": "yarn upgrade-interactive",
|
||||||
"np": "./script/push.sh",
|
"np": "./script/push.sh",
|
||||||
"lsp": "npm login -scope=@ccms",
|
"lsp": "npm login -scope=@ccms",
|
||||||
"lp": "lerna publish --force-publish",
|
"lp": "lerna publish --verify-access --force-publish",
|
||||||
"lpb": "lerna publish prerelease --preid beta --dist-tag beta --force-publish",
|
"lpb": "lerna publish --preid beta --dist-tag beta --verify-access --force-publish",
|
||||||
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --force-publish",
|
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --verify-access --force-publish",
|
||||||
"lpf": "lerna publish from-package --dist-tag beta --yes",
|
"lpf": "lerna publish from-package --yes",
|
||||||
"sync": "./script/sync.sh",
|
"sync": "./script/sync.sh"
|
||||||
"postpublish": "pnpm sync"
|
|
||||||
},
|
},
|
||||||
|
"workspaces": [
|
||||||
|
"packages/*"
|
||||||
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "workspace:*",
|
"lerna": "^7.1.4"
|
||||||
"@javatypes/jdk": "^0.0.3",
|
|
||||||
"@lerna-lite/cli": "^2.6.0",
|
|
||||||
"@lerna-lite/publish": "^2.6.0",
|
|
||||||
"@lerna-lite/run": "^2.6.0",
|
|
||||||
"@types/node": "^20.8.8",
|
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^5.0.5",
|
|
||||||
"tslib": "^2.6.2",
|
|
||||||
"typescript": "^5.2.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/amqp/.npmignore
Symbolic link
1
packages/amqp/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
35
packages/amqp/package.json
Normal file
35
packages/amqp/package.json
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "@ccms/amqp",
|
||||||
|
"version": "0.27.4",
|
||||||
|
"description": "MiaoScript amqp package",
|
||||||
|
"keywords": [
|
||||||
|
"miaoscript",
|
||||||
|
"minecraft",
|
||||||
|
"bukkit",
|
||||||
|
"sponge"
|
||||||
|
],
|
||||||
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
|
"license": "ISC",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"clean": "rimraf dist",
|
||||||
|
"watch": "tsc --watch",
|
||||||
|
"build": "yarn clean && tsc",
|
||||||
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@ccms/api": "^0.27.4",
|
||||||
|
"@ccms/common": "^0.27.4",
|
||||||
|
"@ccms/container": "^0.27.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@ccms/nashorn": "^0.27.4",
|
||||||
|
"@javatypes/amqp-client": "^0.0.3",
|
||||||
|
"@javatypes/spring-amqp": "^0.0.3",
|
||||||
|
"@javatypes/spring-rabbit": "^0.0.3",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
17
packages/amqp/src/adapter/admin.ts
Normal file
17
packages/amqp/src/adapter/admin.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { ConnectionFactoryAdapter } from "./connection"
|
||||||
|
import { RabbitTemplateAdapter } from "./template"
|
||||||
|
import { JSClass } from "@ccms/container"
|
||||||
|
|
||||||
|
export const RabbitAdmin = Java.type('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||||
|
|
||||||
|
export class RabbitAdminAdapter {
|
||||||
|
@JSClass('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||||
|
private RabbitAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||||
|
private _Handler: org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||||
|
constructor(config: RabbitTemplateAdapter | org.springframework.amqp.rabbit.core.RabbitTemplate | ConnectionFactoryAdapter | org.springframework.amqp.rabbit.connection.ConnectionFactory) {
|
||||||
|
this._Handler = new RabbitAdmin((config instanceof RabbitTemplateAdapter || config instanceof ConnectionFactoryAdapter) ? config.getHandler() : config)
|
||||||
|
}
|
||||||
|
getHandler(): org.springframework.amqp.rabbit.core.RabbitAdmin {
|
||||||
|
return this._Handler
|
||||||
|
}
|
||||||
|
}
|
||||||
30
packages/amqp/src/adapter/callback.ts
Normal file
30
packages/amqp/src/adapter/callback.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
export const ConfirmCallback = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback')
|
||||||
|
export const ReturnCallback = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnCallback')
|
||||||
|
|
||||||
|
export abstract class ConfirmCallbackAdapter {
|
||||||
|
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback
|
||||||
|
constructor() {
|
||||||
|
let ConfirmCallbackImpl = Java.extend(ReturnCallback, {
|
||||||
|
confirm: (correlationData: org.springframework.amqp.rabbit.connection.CorrelationData, ack: boolean, cause: string) => this.confirm(correlationData, ack, cause)
|
||||||
|
})
|
||||||
|
this._Handler = new ConfirmCallbackImpl()
|
||||||
|
}
|
||||||
|
abstract confirm(correlationData: org.springframework.amqp.rabbit.connection.CorrelationData, ack: boolean, cause: string)
|
||||||
|
getHandler() {
|
||||||
|
return this._Handler
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class ReturnCallbackAdapter {
|
||||||
|
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnCallback
|
||||||
|
constructor() {
|
||||||
|
let ReturnCallbackImpl = Java.extend(ReturnCallback, {
|
||||||
|
returnedMessage: (message: org.springframework.amqp.core.Message, replyCode: number, replyText: string, exchange: string, routingKey: string) => this.returnedMessage(message, replyCode, replyText, exchange, routingKey)
|
||||||
|
})
|
||||||
|
this._Handler = new ReturnCallbackImpl()
|
||||||
|
}
|
||||||
|
abstract returnedMessage(message: org.springframework.amqp.core.Message, replyCode: number, replyText: string, exchange: string, routingKey: string)
|
||||||
|
getHandler() {
|
||||||
|
return this._Handler
|
||||||
|
}
|
||||||
|
}
|
||||||
31
packages/amqp/src/adapter/connection.ts
Normal file
31
packages/amqp/src/adapter/connection.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import threadPool from '@ccms/common/dist/thread-pool'
|
||||||
|
|
||||||
|
export const ConnectionFactory = Java.type('org.springframework.amqp.rabbit.connection.ConnectionFactory')
|
||||||
|
const CachingConnectionFactory = Java.type('org.springframework.amqp.rabbit.connection.CachingConnectionFactory')
|
||||||
|
interface ConnectionConfig {
|
||||||
|
url: string,
|
||||||
|
username?: string,
|
||||||
|
password?: string,
|
||||||
|
publisherConfirms?: boolean
|
||||||
|
cacheSize?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ConnectionFactoryAdapter {
|
||||||
|
private _Handler: org.springframework.amqp.rabbit.connection.CachingConnectionFactory
|
||||||
|
|
||||||
|
constructor(config: ConnectionConfig) {
|
||||||
|
if (!config.url) { throw new Error('Connection UrI Can\'t be undefiend!') }
|
||||||
|
config = { publisherConfirms: true, cacheSize: 50, ...config }
|
||||||
|
this._Handler = new CachingConnectionFactory(new java.net.URI(config.url))
|
||||||
|
config.username && this._Handler.setUsername(config.username)
|
||||||
|
config.password && this._Handler.setPassword(config.password)
|
||||||
|
this._Handler.setPublisherConfirms(config.publisherConfirms)
|
||||||
|
this._Handler.setExecutor(threadPool.create({
|
||||||
|
groupName: '@ccms/amqp-rabbit'
|
||||||
|
}))
|
||||||
|
this._Handler.setChannelCacheSize(config.cacheSize)
|
||||||
|
}
|
||||||
|
getHandler() {
|
||||||
|
return this._Handler
|
||||||
|
}
|
||||||
|
}
|
||||||
30
packages/amqp/src/adapter/container.ts
Normal file
30
packages/amqp/src/adapter/container.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { ConnectionFactoryAdapter, ConnectionFactory } from "./connection"
|
||||||
|
import { ChannelAwareMessageListenerAdapter, ChannelAwareMessageListener } from "./listener"
|
||||||
|
|
||||||
|
export const SimpleMessageListenerContainer = org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
|
||||||
|
export const AcknowledgeMode = org.springframework.amqp.core.AcknowledgeMode
|
||||||
|
interface ContainerConfig {
|
||||||
|
connectionFactory: ConnectionFactoryAdapter | typeof ConnectionFactory
|
||||||
|
queueNames: string[]
|
||||||
|
messageListener: ChannelAwareMessageListenerAdapter | typeof ChannelAwareMessageListener
|
||||||
|
maxConcurrentConsumers?: number
|
||||||
|
concurrentConsumers?: number
|
||||||
|
acknowledgeMode?: org.springframework.amqp.core.AcknowledgeMode
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MessageListenerContainerAdapter {
|
||||||
|
private _Handler: org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
|
||||||
|
constructor(config: ContainerConfig) {
|
||||||
|
config = { concurrentConsumers: 5, maxConcurrentConsumers: 10, acknowledgeMode: AcknowledgeMode.AUTO, ...config }
|
||||||
|
this._Handler = new SimpleMessageListenerContainer(config.connectionFactory instanceof ConnectionFactoryAdapter ? config.connectionFactory.getHandler() : config.connectionFactory)
|
||||||
|
//@ts-ignore
|
||||||
|
this._Handler.setQueueNames(config.queueNames)
|
||||||
|
this._Handler.setMaxConcurrentConsumers(config.maxConcurrentConsumers)
|
||||||
|
this._Handler.setConcurrentConsumers(config.concurrentConsumers)
|
||||||
|
this._Handler.setAcknowledgeMode(config.acknowledgeMode)
|
||||||
|
this._Handler.setMessageListener(config.messageListener instanceof ChannelAwareMessageListenerAdapter ? config.messageListener.getHandler() : config.messageListener)
|
||||||
|
}
|
||||||
|
getHandler() {
|
||||||
|
return this._Handler
|
||||||
|
}
|
||||||
|
}
|
||||||
37
packages/amqp/src/adapter/converter.ts
Normal file
37
packages/amqp/src/adapter/converter.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
const JavaString = Java.type('java.lang.String')
|
||||||
|
const MessageProperties = org.springframework.amqp.core.MessageProperties
|
||||||
|
const Message = org.springframework.amqp.core.Message
|
||||||
|
|
||||||
|
export const MessageConverter = Java.type('org.springframework.amqp.support.converter.MessageConverter')
|
||||||
|
|
||||||
|
export class MessageConverterAdapter {
|
||||||
|
private _Handler: org.springframework.amqp.support.converter.MessageConverter
|
||||||
|
constructor() {
|
||||||
|
var MessageConverterImpl = Java.extend(MessageConverter, {
|
||||||
|
toMessage: (object: any, messageProperties: org.springframework.amqp.core.MessageProperties) => this.toMessage(object, messageProperties),
|
||||||
|
fromMessage: (message: org.springframework.amqp.core.Message) => this.fromMessage(message)
|
||||||
|
})
|
||||||
|
this._Handler = new MessageConverterImpl()
|
||||||
|
}
|
||||||
|
toMessage(object: any, messageProperties: org.springframework.amqp.core.MessageProperties) {
|
||||||
|
if (typeof object == "string") {
|
||||||
|
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)
|
||||||
|
return new Message(new JavaString(object).getBytes(), messageProperties)
|
||||||
|
} else {
|
||||||
|
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON)
|
||||||
|
return new Message(new JavaString(JSON.stringify(object)).getBytes(), messageProperties)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fromMessage(message: org.springframework.amqp.core.Message) {
|
||||||
|
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_TEXT_PLAIN) {
|
||||||
|
return new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding())
|
||||||
|
}
|
||||||
|
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_JSON) {
|
||||||
|
return JSON.parse(new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding()))
|
||||||
|
}
|
||||||
|
return message
|
||||||
|
}
|
||||||
|
getHandler() {
|
||||||
|
return this._Handler
|
||||||
|
}
|
||||||
|
}
|
||||||
7
packages/amqp/src/adapter/index.ts
Normal file
7
packages/amqp/src/adapter/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export * from './admin'
|
||||||
|
export * from './callback'
|
||||||
|
export * from './connection'
|
||||||
|
export * from './container'
|
||||||
|
export * from './converter'
|
||||||
|
export * from './listener'
|
||||||
|
export * from './template'
|
||||||
49
packages/amqp/src/adapter/listener.ts
Normal file
49
packages/amqp/src/adapter/listener.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
const JavaString = Java.type('java.lang.String')
|
||||||
|
export const MessageProperties = org.springframework.amqp.core.MessageProperties
|
||||||
|
export const ChannelAwareMessageListener = Java.type('org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener')
|
||||||
|
export const AmqpRejectAndDontRequeueException = org.springframework.amqp.AmqpRejectAndDontRequeueException
|
||||||
|
export const Channel: com.rabbitmq.client.Channel = Java.type('com.rabbitmq.client.Channel')
|
||||||
|
export const Message = org.springframework.amqp.core.Message
|
||||||
|
export type MessageHandler<T> = (content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) => any
|
||||||
|
export abstract class ChannelAwareMessageListenerAdapter<T = any> {
|
||||||
|
private _Handler: org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener
|
||||||
|
constructor(manual: boolean = false) {
|
||||||
|
let ChannelAwareMessageListenerImpl = Java.extend(ChannelAwareMessageListener, {
|
||||||
|
onMessage: (message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) => {
|
||||||
|
let content = new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding() || "UTF-8")
|
||||||
|
try {
|
||||||
|
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_JSON) {
|
||||||
|
content = JSON.parse(content)
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
if (manual) {
|
||||||
|
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true)
|
||||||
|
} else {
|
||||||
|
throw new AmqpRejectAndDontRequeueException(`${error}`, error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
manual ? this.manualOnMessage(content, message, channel) : this.onMessage(content, message, channel)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this._Handler = new ChannelAwareMessageListenerImpl()
|
||||||
|
}
|
||||||
|
abstract onMessage(content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel): any
|
||||||
|
onError(error: Error, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel): any { }
|
||||||
|
getHandler() {
|
||||||
|
return this._Handler
|
||||||
|
}
|
||||||
|
private manualOnMessage(content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) {
|
||||||
|
let deliveryTag = message.getMessageProperties().getDeliveryTag()
|
||||||
|
try {
|
||||||
|
if (this.onMessage(content, message, channel)) {
|
||||||
|
channel.basicAck(deliveryTag, false)
|
||||||
|
} else if (message.getMessageProperties().getRedelivered()) {
|
||||||
|
channel.basicReject(deliveryTag, true)
|
||||||
|
} else {
|
||||||
|
channel.basicNack(deliveryTag, false, true)
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
channel.basicReject(deliveryTag, this.onError(error, message, channel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
27
packages/amqp/src/adapter/template.ts
Normal file
27
packages/amqp/src/adapter/template.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { MessageConverterAdapter } from "./converter"
|
||||||
|
import { ConnectionFactoryAdapter } from "./connection"
|
||||||
|
import { ConfirmCallbackAdapter, ReturnCallbackAdapter } from "./callback"
|
||||||
|
|
||||||
|
export const RabbitTemplate = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate')
|
||||||
|
|
||||||
|
interface TemplateConfig {
|
||||||
|
connectionFactory: ConnectionFactoryAdapter | org.springframework.amqp.rabbit.connection.ConnectionFactory
|
||||||
|
confirmCallback?: ConfirmCallbackAdapter
|
||||||
|
returnCallback?: ReturnCallbackAdapter
|
||||||
|
messageConverter?: MessageConverterAdapter
|
||||||
|
}
|
||||||
|
export class RabbitTemplateAdapter {
|
||||||
|
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate
|
||||||
|
constructor(config: TemplateConfig) {
|
||||||
|
config = { messageConverter: new MessageConverterAdapter(), ...config }
|
||||||
|
console.debug(JSON.stringify(config))
|
||||||
|
this._Handler = new RabbitTemplate(config.connectionFactory instanceof ConnectionFactoryAdapter ? config.connectionFactory.getHandler() : config.connectionFactory)
|
||||||
|
config.returnCallback && this._Handler.setReturnCallback(config.returnCallback.getHandler())
|
||||||
|
config.confirmCallback && this._Handler.setConfirmCallback(config.confirmCallback.getHandler())
|
||||||
|
config.messageConverter && this._Handler.setMessageConverter(config.messageConverter.getHandler())
|
||||||
|
}
|
||||||
|
|
||||||
|
getHandler() {
|
||||||
|
return this._Handler
|
||||||
|
}
|
||||||
|
}
|
||||||
89
packages/amqp/src/admin.ts
Normal file
89
packages/amqp/src/admin.ts
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
import { JSClass } from "@ccms/container"
|
||||||
|
import { RabbitAdminAdapter, MessageListenerContainerAdapter, AcknowledgeMode, MessageHandler, ChannelAwareMessageListenerAdapter } from "./adapter"
|
||||||
|
|
||||||
|
export class AmqpAdmin {
|
||||||
|
@JSClass('org.springframework.amqp.core.TopicExchange')
|
||||||
|
private TopicExchange: typeof org.springframework.amqp.core.TopicExchange
|
||||||
|
@JSClass('org.springframework.amqp.core.Queue')
|
||||||
|
private Queue: typeof org.springframework.amqp.core.Queue
|
||||||
|
@JSClass('org.springframework.amqp.core.Binding')
|
||||||
|
private Binding: typeof org.springframework.amqp.core.Binding
|
||||||
|
@JSClass('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||||
|
private RabbitAdmin: typeof org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||||
|
@JSClass('org.springframework.amqp.core.Binding.DestinationType')
|
||||||
|
private DestinationType: org.springframework.amqp.core.Binding.DestinationType
|
||||||
|
|
||||||
|
private amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||||
|
|
||||||
|
constructor(amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin | any) {
|
||||||
|
if (amqpAdmin instanceof this.RabbitAdmin) {
|
||||||
|
this.amqpAdmin = amqpAdmin
|
||||||
|
} else if (amqpAdmin instanceof RabbitAdminAdapter) {
|
||||||
|
this.amqpAdmin = amqpAdmin.getHandler()
|
||||||
|
} else {
|
||||||
|
this.amqpAdmin = new RabbitAdminAdapter(amqpAdmin).getHandler()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getHandler() {
|
||||||
|
return this.amqpAdmin
|
||||||
|
}
|
||||||
|
|
||||||
|
getQueueProperties(name: string) {
|
||||||
|
return this.amqpAdmin.getQueueProperties(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
declareExchange(name: string) {
|
||||||
|
let exchange = new this.TopicExchange(name, true, false)
|
||||||
|
this.amqpAdmin.declareExchange(exchange)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
declareQueue(name: string) {
|
||||||
|
let queue = new this.Queue(name, true)
|
||||||
|
this.amqpAdmin.declareQueue(queue)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
declareBinding(queue: string, exchange: string, routerKey: string, argument: any = null) {
|
||||||
|
let binding = new this.Binding(queue, org.springframework.amqp.core.Binding.DestinationType.QUEUE, exchange, routerKey, argument)
|
||||||
|
this.amqpAdmin.declareBinding(binding)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
declareQueueAndBindExchange(queue: string, exchange: string, routerKey: string) {
|
||||||
|
return this.declareQueue(queue).declareExchange(exchange).declareBinding(queue, exchange, routerKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
createContainer<T>(queue: string, listener: MessageHandler<T>, acknowledgeMode = AcknowledgeMode.AUTO) {
|
||||||
|
let connection = this.amqpAdmin.getRabbitTemplate().getConnectionFactory()
|
||||||
|
return new MessageListenerContainerAdapter({
|
||||||
|
connectionFactory: connection,
|
||||||
|
queueNames: [queue],
|
||||||
|
messageListener: new SimpleMessageHandler(listener),
|
||||||
|
acknowledgeMode: acknowledgeMode
|
||||||
|
}).getHandler()
|
||||||
|
}
|
||||||
|
|
||||||
|
send()
|
||||||
|
send() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
getTemplate() {
|
||||||
|
return this.amqpAdmin.getRabbitTemplate()
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.getTemplate().stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SimpleMessageHandler extends ChannelAwareMessageListenerAdapter {
|
||||||
|
constructor(private handler: MessageHandler<any>) {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
onMessage(content: any, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) {
|
||||||
|
return this.handler(content, message, channel)
|
||||||
|
}
|
||||||
|
}
|
||||||
3
packages/amqp/src/constants.ts
Normal file
3
packages/amqp/src/constants.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const METADATA_KEY = {
|
||||||
|
|
||||||
|
}
|
||||||
34
packages/amqp/src/index.ts
Normal file
34
packages/amqp/src/index.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/// <reference types="@ccms/nashorn" />
|
||||||
|
/// <reference types="@javatypes/jdk" />
|
||||||
|
/// <reference types="@javatypes/spring-amqp" />
|
||||||
|
/// <reference types="@javatypes/spring-rabbit" />
|
||||||
|
/// <reference types="@javatypes/amqp-client" />
|
||||||
|
|
||||||
|
import { amqp } from '@ccms/api'
|
||||||
|
import { getContainer, reduceMetadata } from '@ccms/container'
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
const beanFactory = base.getInstance().getAutowireCapableBeanFactory()
|
||||||
|
getContainer().bind(amqp.rabbit.Template).toDynamicValue((ctx) => {
|
||||||
|
let metadata = reduceMetadata(ctx)
|
||||||
|
if (!metadata.named) {
|
||||||
|
return beanFactory.getBean('rabbitTemplate')
|
||||||
|
} else {
|
||||||
|
return beanFactory.getBean(`${metadata.named}-rabbitTemplate`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
getContainer().bind(amqp.rabbit.Admin).toDynamicValue((ctx) => {
|
||||||
|
let metadata = reduceMetadata(ctx)
|
||||||
|
if (!metadata.named) {
|
||||||
|
return beanFactory.getBean('rabbitAdmin')
|
||||||
|
} else {
|
||||||
|
return beanFactory.getBean(`${metadata.named}-rabbitAdmin`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
init()
|
||||||
|
|
||||||
|
export * from './admin'
|
||||||
|
export * from './adapter'
|
||||||
|
export * from './manager'
|
||||||
|
export * from './constants'
|
||||||
5
packages/amqp/src/listener.ts
Normal file
5
packages/amqp/src/listener.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export class AmqpListener {
|
||||||
|
constructor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
18
packages/amqp/src/manager.ts
Normal file
18
packages/amqp/src/manager.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { amqp } from "@ccms/api"
|
||||||
|
import { provideSingleton } from "@ccms/container"
|
||||||
|
|
||||||
|
import { ConnectionFactoryAdapter, RabbitTemplateAdapter, RabbitAdminAdapter } from "./adapter"
|
||||||
|
import { AmqpAdmin } from "./admin"
|
||||||
|
|
||||||
|
@provideSingleton(amqp.Manager)
|
||||||
|
export class AmqpManager {
|
||||||
|
createConnection(url: string, username: string, password: string) {
|
||||||
|
return new ConnectionFactoryAdapter({ url, username, password })
|
||||||
|
}
|
||||||
|
createTemplate(adapter: ConnectionFactoryAdapter) {
|
||||||
|
return new RabbitTemplateAdapter({ connectionFactory: adapter })
|
||||||
|
}
|
||||||
|
createAdmin(adapter: RabbitTemplateAdapter | ConnectionFactoryAdapter) {
|
||||||
|
return new AmqpAdmin(new RabbitAdminAdapter(adapter))
|
||||||
|
}
|
||||||
|
}
|
||||||
1
packages/api/.npmignore
Symbolic link
1
packages/api/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/api",
|
"name": "@ccms/api",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,26 +12,23 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/common": "workspace:*",
|
"@ccms/common": "^0.27.4",
|
||||||
"@ccms/container": "workspace:*",
|
"@ccms/container": "^0.27.4",
|
||||||
"@ccms/i18n": "workspace:*",
|
"@ccms/polyfill": "^0.27.4",
|
||||||
"@ccms/polyfill": "workspace:*",
|
|
||||||
"base64-js": "^1.5.1",
|
"base64-js": "^1.5.1",
|
||||||
"source-map-builder": "^0.0.7"
|
"source-map-builder": "^0.0.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/base64-js": "^1.5.0"
|
"@types/base64-js": "^1.3.0",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
packages/api/src/amqp.ts
Normal file
7
packages/api/src/amqp.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export namespace amqp {
|
||||||
|
export const Manager = Symbol('AmqpManager')
|
||||||
|
export namespace rabbit {
|
||||||
|
export const Admin = Symbol('RabbitAdmin')
|
||||||
|
export const Template = Symbol('RabbitTemplate')
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,12 +5,6 @@ import { plugin } from './plugin'
|
|||||||
export namespace command {
|
export namespace command {
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class Command {
|
export abstract class Command {
|
||||||
/**
|
|
||||||
* first time script engine need optimize jit code
|
|
||||||
* so ignore first slow exec notify
|
|
||||||
*/
|
|
||||||
private cacheSlowKeys = {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册插件命令
|
* 注册插件命令
|
||||||
* @param plugin 插件
|
* @param plugin 插件
|
||||||
@@ -52,13 +46,36 @@ export namespace command {
|
|||||||
try {
|
try {
|
||||||
let time = Date.now()
|
let time = Date.now()
|
||||||
let result = executor(sender, command, Java.from(args))
|
let result = executor(sender, command, Java.from(args))
|
||||||
this.checkSlow(Date.now() - time,
|
let cost = Date.now() - time
|
||||||
"ms.api.command.execute.slow",
|
if (cost > global.ScriptSlowExecuteTime) {
|
||||||
plugin, command, sender, args)
|
console.i18n("ms.api.command.execute.slow", {
|
||||||
|
player: sender.name,
|
||||||
|
plugin: plugin.description.name,
|
||||||
|
command,
|
||||||
|
args: Java.from(args).join(' '),
|
||||||
|
cost
|
||||||
|
})
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
this.printError(ex, "ms.api.command.execute.error",
|
console.i18n("ms.api.command.execute.error", {
|
||||||
plugin, command, sender, args)
|
player: sender.name,
|
||||||
|
plugin: plugin.description.name,
|
||||||
|
command,
|
||||||
|
args: Java.from(args).join(' '),
|
||||||
|
ex
|
||||||
|
})
|
||||||
|
console.ex(ex)
|
||||||
|
if (sender.name != 'CONSOLE') {
|
||||||
|
console.sender(sender, [i18n.translate("ms.api.command.execute.error", {
|
||||||
|
player: sender.name,
|
||||||
|
plugin: plugin.description.name,
|
||||||
|
command,
|
||||||
|
args: Java.from(args).join(' '),
|
||||||
|
ex
|
||||||
|
}),
|
||||||
|
...console.stack(ex)])
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,18 +87,42 @@ export namespace command {
|
|||||||
var token = args[args.length - 1]
|
var token = args[args.length - 1]
|
||||||
var complete = tabCompleter(sender, command, Java.from(args)) || []
|
var complete = tabCompleter(sender, command, Java.from(args)) || []
|
||||||
let result = this.copyPartialMatches(complete, token)
|
let result = this.copyPartialMatches(complete, token)
|
||||||
this.checkSlow(Date.now() - time,
|
let cost = Date.now() - time
|
||||||
"ms.api.command.tab.completer.slow",
|
if (cost > global.ScriptSlowExecuteTime) {
|
||||||
plugin, command, sender, args)
|
console.i18n("ms.api.command.tab.completer.slow", {
|
||||||
|
player: sender.name,
|
||||||
|
plugin: plugin.description.name,
|
||||||
|
command,
|
||||||
|
args: Java.from(args).join(' '),
|
||||||
|
cost
|
||||||
|
})
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
this.printError(ex, "ms.api.command.tab.completer.error",
|
console.i18n("ms.api.command.tab.completer.error", {
|
||||||
plugin, command, sender, args)
|
player: sender.name,
|
||||||
|
plugin: plugin.description.name,
|
||||||
|
command,
|
||||||
|
args: Java.from(args).join(' '),
|
||||||
|
ex
|
||||||
|
})
|
||||||
|
console.ex(ex)
|
||||||
|
if (sender.name != 'CONSOLE') {
|
||||||
|
console.sender(sender, [
|
||||||
|
i18n.translate("ms.api.command.tab.completer.error", {
|
||||||
|
player: sender.name,
|
||||||
|
plugin: plugin.description.name,
|
||||||
|
command,
|
||||||
|
args: Java.from(args).join(' '),
|
||||||
|
ex
|
||||||
|
}),
|
||||||
|
...console.stack(ex)
|
||||||
|
])
|
||||||
|
}
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
|
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
|
||||||
if (!token) { return complete }
|
if (!token) { return complete }
|
||||||
complete.forEach(function (e) {
|
complete.forEach(function (e) {
|
||||||
@@ -91,35 +132,5 @@ export namespace command {
|
|||||||
})
|
})
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkSlow(cost: number, key: string, plugin: plugin.Plugin, command: string, sender: any, args: any[]) {
|
|
||||||
if (cost > global.ScriptSlowExecuteTime) {
|
|
||||||
let completerKey = `${plugin.description.name}-${key}-${command}-${sender.name}`
|
|
||||||
if (!this.cacheSlowKeys[completerKey]) {
|
|
||||||
return this.cacheSlowKeys[completerKey] = cost
|
|
||||||
}
|
|
||||||
console.i18n(key, {
|
|
||||||
player: sender.name,
|
|
||||||
plugin: plugin.description.name,
|
|
||||||
command,
|
|
||||||
args: Java.from(args).join(' '),
|
|
||||||
cost
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private printError(error: Error, key: string, plugin: plugin.Plugin, command: string, sender: any, args: any[]) {
|
|
||||||
let message = i18n.translate(key, {
|
|
||||||
player: sender.name,
|
|
||||||
plugin: plugin.description.name,
|
|
||||||
command,
|
|
||||||
args: Java.from(args).join(' '),
|
|
||||||
error
|
|
||||||
})
|
|
||||||
console.console(message)
|
|
||||||
console.ex(error)
|
|
||||||
if (sender.name != 'CONSOLE') {
|
|
||||||
console.sender(sender, [message, ...console.stack(error)])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ global.setGlobal('MiaoScriptSourceFileMaps', sourceFileMaps)
|
|||||||
|
|
||||||
export namespace jsconsole {
|
export namespace jsconsole {
|
||||||
export function readSourceMap(fileName: string, lineNumber: any) {
|
export function readSourceMap(fileName: string, lineNumber: any) {
|
||||||
if (lineNumber == 1) return { fileName, lineNumber }
|
|
||||||
try {
|
try {
|
||||||
if (fileName.endsWith('js') || fileName.endsWith('ms')) {
|
if (fileName.endsWith('js') || fileName.endsWith('ms')) {
|
||||||
if (sourceMaps[fileName] === undefined) {
|
if (sourceMaps[fileName] === undefined) {
|
||||||
@@ -69,7 +68,10 @@ export namespace jsconsole {
|
|||||||
console.ex(error)
|
console.ex(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { fileName, lineNumber }
|
return {
|
||||||
|
fileName,
|
||||||
|
lineNumber
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getStackTrace(ex: Error, color: boolean = true): string[] {
|
export function getStackTrace(ex: Error, color: boolean = true): string[] {
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export namespace event {
|
|||||||
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError(i18n.translate("ms.api.event.listen.plugin.name.empty"))
|
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError(i18n.translate("ms.api.event.listen.plugin.name.empty"))
|
||||||
var name = plugin.description.name
|
var name = plugin.description.name
|
||||||
var eventCls = this.name2Class(name, event)
|
var eventCls = this.name2Class(name, event)
|
||||||
if (!eventCls) { return () => { console.warn('event ' + event + ' not found ignore off listener.') } }
|
if (!eventCls) { return }
|
||||||
if (typeof priority === 'boolean') {
|
if (typeof priority === 'boolean') {
|
||||||
ignoreCancel = priority
|
ignoreCancel = priority
|
||||||
priority = EventPriority.NORMAL
|
priority = EventPriority.NORMAL
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import "@ccms/nashorn"
|
import "@ccms/nashorn"
|
||||||
|
|
||||||
|
export * from './web'
|
||||||
|
export * from './amqp'
|
||||||
export * from './chat'
|
export * from './chat'
|
||||||
export * from './task'
|
export * from './task'
|
||||||
export * from './item'
|
export * from './item'
|
||||||
|
|||||||
@@ -19,23 +19,14 @@ export namespace plugin {
|
|||||||
@injectable()
|
@injectable()
|
||||||
export abstract class PluginManager {
|
export abstract class PluginManager {
|
||||||
abstract scan(folder: string): void
|
abstract scan(folder: string): void
|
||||||
|
abstract build(): void
|
||||||
abstract loadFromFile(file: string, ext?: any): Plugin
|
abstract loadFromFile(file: string, ext?: any): Plugin
|
||||||
abstract require(loadMetadata: PluginLoadMetadata): PluginMetadata
|
abstract load(...args: any[]): void
|
||||||
abstract build(metadata: PluginMetadata): Plugin
|
abstract enable(...args: any[]): void
|
||||||
abstract rebuild(plugin: plugin.Plugin): void
|
abstract disable(...args: any[]): void
|
||||||
abstract load(plugin: plugin.Plugin): void
|
abstract reload(...args: any[]): void
|
||||||
abstract enable(plugin: plugin.Plugin): void
|
|
||||||
abstract disable(plugin: plugin.Plugin): void
|
|
||||||
abstract reload(plugin: plugin.Plugin): void
|
|
||||||
abstract has(name: string): boolean
|
|
||||||
abstract get(name: string): plugin.Plugin
|
|
||||||
abstract getPlugin(name: string): plugin.Plugin
|
abstract getPlugin(name: string): plugin.Plugin
|
||||||
abstract getPlugins(): Map<string, plugin.Plugin>
|
abstract getPlugins(): Map<string, plugin.Plugin>
|
||||||
abstract buildPlugins(): void
|
|
||||||
abstract rebuildPlugins(): void
|
|
||||||
abstract loadPlugins(): void
|
|
||||||
abstract enablePlugins(): void
|
|
||||||
abstract disablePlugins(): void
|
|
||||||
}
|
}
|
||||||
export const PluginScanner = Symbol("PluginScanner")
|
export const PluginScanner = Symbol("PluginScanner")
|
||||||
/**
|
/**
|
||||||
@@ -47,13 +38,9 @@ export namespace plugin {
|
|||||||
*/
|
*/
|
||||||
type: string
|
type: string
|
||||||
/**
|
/**
|
||||||
* 插件文件(java.io.File)
|
* 插件文件
|
||||||
*/
|
*/
|
||||||
file?: any
|
file?: string
|
||||||
/**
|
|
||||||
* 插件规范路径 canonicalPath
|
|
||||||
*/
|
|
||||||
path?: string
|
|
||||||
/**
|
/**
|
||||||
* 插件实例
|
* 插件实例
|
||||||
*/
|
*/
|
||||||
@@ -135,6 +122,11 @@ export namespace plugin {
|
|||||||
* @param plugin 插件
|
* @param plugin 插件
|
||||||
*/
|
*/
|
||||||
disable?(plugin: Plugin): void
|
disable?(plugin: Plugin): void
|
||||||
|
/**
|
||||||
|
* Reload 阶段
|
||||||
|
* @param plugin 插件
|
||||||
|
*/
|
||||||
|
reload?(plugin: Plugin): void
|
||||||
}
|
}
|
||||||
export interface Plugin {
|
export interface Plugin {
|
||||||
description: PluginMetadata
|
description: PluginMetadata
|
||||||
|
|||||||
5
packages/api/src/service.ts
Normal file
5
packages/api/src/service.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export namespace service {
|
||||||
|
export class ServiceManager {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,6 @@ export namespace task {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.taskId = new AtomicInteger(0)
|
this.taskId = new AtomicInteger(0)
|
||||||
process.on('core.disable', () => { this.disable() })
|
|
||||||
process.on('task.finish', (task: task.Task) => {
|
process.on('task.finish', (task: task.Task) => {
|
||||||
let taskId = task.getTaskId()
|
let taskId = task.getTaskId()
|
||||||
this.cacheTasks.delete(taskId)
|
this.cacheTasks.delete(taskId)
|
||||||
@@ -25,6 +24,30 @@ export namespace task {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected pluginCreate(plugin: plugin.Plugin, task: task.Task) {
|
||||||
|
if (!this.pluginCacheTasks.has(plugin.description.name)) {
|
||||||
|
this.pluginCacheTasks.set(plugin.description.name, new Map())
|
||||||
|
}
|
||||||
|
this.pluginCacheTasks.get(plugin.description.name).set(task.getTaskId(), task)
|
||||||
|
return task
|
||||||
|
}
|
||||||
|
|
||||||
|
protected pluginDisable(plugin: plugin.Plugin) {
|
||||||
|
if (this.pluginCacheTasks.has(plugin.description.name)) {
|
||||||
|
this.pluginCacheTasks.get(plugin.description.name).forEach((task) => {
|
||||||
|
task.cancel()
|
||||||
|
})
|
||||||
|
this.pluginCacheTasks.delete(plugin.description.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得自增的任务ID
|
||||||
|
*/
|
||||||
|
protected nextId() {
|
||||||
|
return this.taskId.incrementAndGet()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建任务
|
* 创建任务
|
||||||
* @param func 任务内容
|
* @param func 任务内容
|
||||||
@@ -52,28 +75,6 @@ export namespace task {
|
|||||||
if (plugin) { return this.pluginDisable(plugin) }
|
if (plugin) { return this.pluginDisable(plugin) }
|
||||||
this.disable0()
|
this.disable0()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected pluginCreate(plugin: plugin.Plugin, task: task.Task) {
|
|
||||||
if (!this.pluginCacheTasks.has(plugin.description.name)) {
|
|
||||||
this.pluginCacheTasks.set(plugin.description.name, new Map())
|
|
||||||
}
|
|
||||||
this.pluginCacheTasks.get(plugin.description.name).set(task.getTaskId(), task)
|
|
||||||
return task
|
|
||||||
}
|
|
||||||
|
|
||||||
protected pluginDisable(plugin: plugin.Plugin) {
|
|
||||||
if (this.pluginCacheTasks.has(plugin.description.name)) {
|
|
||||||
this.pluginCacheTasks.get(plugin.description.name).forEach((task) => task.cancel())
|
|
||||||
this.pluginCacheTasks.delete(plugin.description.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得自增的任务ID
|
|
||||||
*/
|
|
||||||
protected nextId() {
|
|
||||||
return this.taskId.incrementAndGet()
|
|
||||||
}
|
|
||||||
protected abstract create0(owner: plugin.Plugin, func: Function, id: number): task.Task
|
protected abstract create0(owner: plugin.Plugin, func: Function, id: number): task.Task
|
||||||
protected abstract disable0()
|
protected abstract disable0()
|
||||||
}
|
}
|
||||||
@@ -96,9 +97,6 @@ export namespace task {
|
|||||||
this.owner = owner
|
this.owner = owner
|
||||||
this.func = func
|
this.func = func
|
||||||
this.taskId = id
|
this.taskId = id
|
||||||
this.on('finish', () => {
|
|
||||||
process.emit('task.finish', this)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getOwner() {
|
getOwner() {
|
||||||
@@ -153,9 +151,8 @@ export namespace task {
|
|||||||
this.func(...args)
|
this.func(...args)
|
||||||
this.emit('after', this)
|
this.emit('after', this)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
try {
|
this.emit('error', error)
|
||||||
this.emit('error', error)
|
if (!error.processed) {
|
||||||
} catch (ignore) {
|
|
||||||
console.console('§4插件执行任务时发生错误', error)
|
console.console('§4插件执行任务时发生错误', error)
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
this.cancel()
|
this.cancel()
|
||||||
@@ -167,6 +164,7 @@ export namespace task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected finish() {
|
protected finish() {
|
||||||
|
process.emit('task.finish', this)
|
||||||
this.emit('finish', this)
|
this.emit('finish', this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +181,7 @@ export namespace task {
|
|||||||
* 提交任务
|
* 提交任务
|
||||||
* @param args 任务参数
|
* @param args 任务参数
|
||||||
*/
|
*/
|
||||||
protected abstract submit0(...args: any[]): Cancelable
|
protected abstract submit0(...args: any[]): any
|
||||||
/**
|
/**
|
||||||
* 取消任务
|
* 取消任务
|
||||||
*/
|
*/
|
||||||
|
|||||||
3
packages/api/src/web.ts
Normal file
3
packages/api/src/web.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export namespace web {
|
||||||
|
export const Server = Symbol('Server')
|
||||||
|
}
|
||||||
1
packages/bukkit/.npmignore
Symbolic link
1
packages/bukkit/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bukkit",
|
"name": "@ccms/bukkit",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript bukkit package",
|
"description": "MiaoScript bukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,23 +12,21 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/spigot-api": "^0.0.3"
|
"@javatypes/spigot-api": "^0.0.3",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "workspace:*",
|
"@ccms/api": "^0.27.4",
|
||||||
"@ccms/common": "workspace:*",
|
"@ccms/common": "^0.27.4",
|
||||||
"@ccms/container": "workspace:*"
|
"@ccms/container": "^0.27.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,32 +65,28 @@ abstract class BukkitChatInvoke {
|
|||||||
return base.getClass(['net.minecraft.server', this.nmsVersion, name].join('.'))
|
return base.getClass(['net.minecraft.server', this.nmsVersion, name].join('.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
remapMethod(clazz: any, methods: string[], params: any) {
|
remapMethod(clazz: any, origin: string, test: string, params: any) {
|
||||||
for (const method of methods) {
|
try {
|
||||||
try {
|
return clazz.getMethod(origin, params)
|
||||||
if (this.RemapUtils) {
|
} catch (ex: any) {
|
||||||
return clazz.getMethod(this.RemapUtils.mapMethod(clazz, method, params), params)
|
if (this.RemapUtils) {
|
||||||
} else {
|
return clazz.getMethod(this.RemapUtils.mapMethod(clazz, origin, params), params)
|
||||||
return clazz.getMethod(method, params)
|
} else {
|
||||||
}
|
return clazz.getMethod(test, params)
|
||||||
} catch (error) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error(`Class ${clazz} not found method ${methods}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
remapFieldName(clazz: any, fields: string[]) {
|
remapFieldName(clazz: any, origin: string, test: string) {
|
||||||
for (const field of fields) {
|
try {
|
||||||
try {
|
return clazz.getField(origin)
|
||||||
if (this.RemapUtils) {
|
} catch (ex: any) {
|
||||||
return clazz.getField(this.RemapUtils.mapFieldName(clazz, field))
|
if (this.RemapUtils) {
|
||||||
} else {
|
return clazz.getField(this.RemapUtils.mapFieldName(clazz, origin))
|
||||||
return clazz.getField(field)
|
} else {
|
||||||
}
|
return clazz.getField(test)
|
||||||
} catch (ex: any) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Error(`Class ${clazz} not found field ${fields}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json(sender: any, json: string) {
|
json(sender: any, json: string) {
|
||||||
@@ -111,10 +107,10 @@ abstract class BukkitChatInvoke {
|
|||||||
|
|
||||||
class BukkitChatInvokeBase extends BukkitChatInvoke {
|
class BukkitChatInvokeBase extends BukkitChatInvoke {
|
||||||
getSendPacketMethodName(playerConnectionClass: any) {
|
getSendPacketMethodName(playerConnectionClass: any) {
|
||||||
return this.remapMethod(playerConnectionClass, ['sendPacket', 'a', 'func_179290_a'], this.getPacketClass()).getName()
|
return this.remapMethod(playerConnectionClass, 'sendPacket', 'func_179290_a', this.getPacketClass()).getName()
|
||||||
}
|
}
|
||||||
getNmsChatSerializerMethodName(nmsChatSerializerClass: any) {
|
getNmsChatSerializerMethodName(nmsChatSerializerClass: any) {
|
||||||
let nmsChatSerializerMethod = this.remapMethod(nmsChatSerializerClass, ['serialize', 'a', 'func_150699_a'], base.getClass('java.lang.String'))
|
let nmsChatSerializerMethod = this.remapMethod(nmsChatSerializerClass, 'a', 'func_150699_a', base.getClass('java.lang.String'))
|
||||||
return nmsChatSerializerMethod.getName()
|
return nmsChatSerializerMethod.getName()
|
||||||
}
|
}
|
||||||
getPacketPlayOutChat(sender: any, json: any, type: number) {
|
getPacketPlayOutChat(sender: any, json: any, type: number) {
|
||||||
@@ -127,7 +123,7 @@ class BukkitChatInvokeBase extends BukkitChatInvoke {
|
|||||||
return this.nmsCls("PacketPlayOutChat")
|
return this.nmsCls("PacketPlayOutChat")
|
||||||
}
|
}
|
||||||
getPlayerConnectionField() {
|
getPlayerConnectionField() {
|
||||||
return this.remapFieldName(this.nmsCls('EntityPlayer'), ['playerConnection', 'field_71135_a'])
|
return this.remapFieldName(this.nmsCls('EntityPlayer'), 'playerConnection', 'field_71135_a')
|
||||||
}
|
}
|
||||||
getPacketClass() {
|
getPacketClass() {
|
||||||
return this.nmsCls('Packet')
|
return this.nmsCls('Packet')
|
||||||
@@ -178,27 +174,13 @@ class BukkitChatInvoke_1_19 extends BukkitChatInvoke_1_18_2 {
|
|||||||
return new this.PacketPlayOutChat(this.ChatSerializer[this.nmsChatSerializerMethodName](json), type)
|
return new this.PacketPlayOutChat(this.ChatSerializer[this.nmsChatSerializerMethodName](json), type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class BukkitChatInvoke_1_20 extends BukkitChatInvoke_1_19 {
|
|
||||||
getNmsChatSerializerClass() {
|
|
||||||
return base.getClass('net.minecraft.network.chat.IChatBaseComponent')
|
|
||||||
}
|
|
||||||
getNmsChatSerializerMethodName(nmsChatSerializerClass: any) {
|
|
||||||
let nmsChatSerializerMethod = this.remapMethod(nmsChatSerializerClass, ['literal', 'a'], base.getClass('java.lang.String'))
|
|
||||||
return nmsChatSerializerMethod.getName()
|
|
||||||
}
|
|
||||||
getPlayerConnectionField() {
|
|
||||||
return base.getClass('net.minecraft.server.level.EntityPlayer').getField('f')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let Bukkit: typeof org.bukkit.Bukkit = Java.type('org.bukkit.Bukkit')
|
let Bukkit: typeof org.bukkit.Bukkit = Java.type('org.bukkit.Bukkit')
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let nmsVersion = Bukkit.getServer().class.name.split('.')[3]
|
let nmsVersion = Bukkit.getServer().class.name.split('.')[3]
|
||||||
let nmsSubVersion = nmsVersion.split("_")[1]
|
let nmsSubVersion = nmsVersion.split("_")[1]
|
||||||
if (nmsSubVersion >= 20) {
|
if (nmsSubVersion >= 19) {
|
||||||
bukkitChatInvoke = new BukkitChatInvoke_1_20(nmsVersion)
|
|
||||||
} else if (nmsSubVersion >= 19) {
|
|
||||||
bukkitChatInvoke = new BukkitChatInvoke_1_19(nmsVersion)
|
bukkitChatInvoke = new BukkitChatInvoke_1_19(nmsVersion)
|
||||||
} else if (nmsSubVersion >= 18) {
|
} else if (nmsSubVersion >= 18) {
|
||||||
bukkitChatInvoke = new BukkitChatInvoke_1_18_2(nmsVersion)
|
bukkitChatInvoke = new BukkitChatInvoke_1_18_2(nmsVersion)
|
||||||
|
|||||||
1
packages/bungee/.npmignore
Symbolic link
1
packages/bungee/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bungee",
|
"name": "@ccms/bungee",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript bungee package",
|
"description": "MiaoScript bungee package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,23 +12,21 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/bungee-api": "^0.0.3"
|
"@javatypes/bungee-api": "^0.0.3",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "workspace:*",
|
"@ccms/api": "^0.27.4",
|
||||||
"@ccms/common": "workspace:*",
|
"@ccms/common": "^0.27.4",
|
||||||
"@ccms/container": "workspace:*"
|
"@ccms/container": "^0.27.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/common/.npmignore
Symbolic link
1
packages/common/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/common",
|
"name": "@ccms/common",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript common package",
|
"description": "MiaoScript common package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,20 +12,18 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "workspace:*",
|
"@ccms/nashorn": "^0.27.4",
|
||||||
"@javatypes/jdk": "^0.0.3"
|
"@javatypes/jdk": "^0.0.3",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ function declaredField(clazz: java.lang.Class<any>, name: string | java.lang.Str
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (target === undefined) { break }
|
if (target === undefined) { break }
|
||||||
target = target.getSuperclass()
|
target = target.getSuperclass()
|
||||||
console.debug(`switch to super class: ${target.getName()}`)
|
console.debug(`切换到超类: ${target.getName()}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (field === null) {
|
if (field === null) {
|
||||||
@@ -174,7 +174,7 @@ function declaredMethod(clazz: java.lang.Class<any>, nameOrIndex: string | numbe
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (target === undefined) { break }
|
if (target === undefined) { break }
|
||||||
target = target.getSuperclass()
|
target = target.getSuperclass()
|
||||||
console.debug(`switch to super class: ${target.getName()}`)
|
console.debug(`切换到超类: ${target.getName()}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,7 +187,7 @@ function declaredMethods(clazz: java.lang.Class<any>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mapToObject(javaObj) {
|
function mapToObject(javaObj) {
|
||||||
if (!Java.isJavaObject(javaObj)) { throw new TypeError(`argument ${javaObj} is not a java object.`) }
|
if (!Java.isJavaObject(javaObj)) { throw new TypeError(`参数 ${javaObj} 不是一个Java对象!`) }
|
||||||
let target = Proxy.newProxy(javaObj, {
|
let target = Proxy.newProxy(javaObj, {
|
||||||
apply: (target, name, args) => { return args ? javaObj[name](args) : javaObj[name]() }
|
apply: (target, name, args) => { return args ? javaObj[name](args) : javaObj[name]() }
|
||||||
})
|
})
|
||||||
|
|||||||
1
packages/compile/.npmignore
Symbolic link
1
packages/compile/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/compile",
|
"name": "@ccms/compile",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript compile package",
|
"description": "MiaoScript compile package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,15 +12,15 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/container/.npmignore
Symbolic link
1
packages/container/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/container",
|
"name": "@ccms/container",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript container package",
|
"description": "MiaoScript container package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,22 +12,20 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@ccms/nashorn": "^0.27.4",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"inversify": "^6.0.1",
|
"inversify": "^6.0.1",
|
||||||
"inversify-binding-decorators": "^4.0.0"
|
"inversify-binding-decorators": "^4.0.0"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@ccms/nashorn": "workspace:*"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,28 +32,18 @@ export const provideSingletonNamed = (identifier: interfaces.ServiceIdentifier<a
|
|||||||
return fluentProvide(identifier).inSingletonScope().whenTargetNamed(name).done()
|
return fluentProvide(identifier).inSingletonScope().whenTargetNamed(name).done()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getJavaClass(className: string) {
|
|
||||||
try { return Java.type(className).class; return } catch (error: any) { }
|
|
||||||
try { return base.getClass(className); return } catch (error: any) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得一个 java.lang.Class
|
* 获得一个 java.lang.Class
|
||||||
* @param className Java全类名
|
* @param className Java全类名
|
||||||
*/
|
*/
|
||||||
export const JavaClass = (className: string) => {
|
export const JavaClass = (className: string) => {
|
||||||
return function (target: object, propertyKey: string, index?: number) {
|
return function (target: object, propertyKey: string, index?: number) {
|
||||||
_proxyGetter(target, propertyKey, () => {
|
try { target[propertyKey] = Java.type(className).class; return } catch (error: any) { }
|
||||||
return getJavaClass(className) || console.warn('JavaClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
try { target[propertyKey] = base.getClass(className); return } catch (error: any) { }
|
||||||
}, true)
|
console.warn('JavaClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getJSClass(className: string) {
|
|
||||||
try { return Java.type(className) } catch (error: any) { }
|
|
||||||
try { return base.getClass(className).static } catch (error: any) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得一个JS的Java类
|
* 获得一个JS的Java类
|
||||||
* @param className Java 全类名
|
* @param className Java 全类名
|
||||||
@@ -61,7 +51,9 @@ export function getJSClass(className: string) {
|
|||||||
export const JSClass = (className: string) => {
|
export const JSClass = (className: string) => {
|
||||||
return function (target: object, propertyKey: string, index?: number) {
|
return function (target: object, propertyKey: string, index?: number) {
|
||||||
_proxyGetter(target, propertyKey, () => {
|
_proxyGetter(target, propertyKey, () => {
|
||||||
return getJSClass(className) || console.warn('JSClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
try { return Java.type(className) } catch (error: any) { }
|
||||||
|
try { return base.getClass(className).static } catch (error: any) { }
|
||||||
|
console.warn('JSClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
||||||
}, true)
|
}, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,8 +156,7 @@ function initAutowired(container: Container) {
|
|||||||
var metadata: any = reduceMetadata(ctx)
|
var metadata: any = reduceMetadata(ctx)
|
||||||
let key = Object.prototype.toString.call(metadata.named)
|
let key = Object.prototype.toString.call(metadata.named)
|
||||||
if (key === "[object Function]" || key === "[object Symbol]") { return container.get(metadata.named) }
|
if (key === "[object Function]" || key === "[object Symbol]") { return container.get(metadata.named) }
|
||||||
console.warn('container Autowired', metadata.named, 'failed. Error: illegal serviceIdentifier type', key)
|
console.warn('container autowired', metadata.named, 'failed. Error: illegal serviceIdentifier type', key)
|
||||||
console.debug(metadata.named, 'metadata', JSON.stringify(metadata))
|
|
||||||
return undefined
|
return undefined
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/core/.npmignore
Symbolic link
1
packages/core/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/core",
|
"name": "@ccms/core",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript core package",
|
"description": "MiaoScript core package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,28 +12,20 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "pnpm rollup -c rollup.config.js --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && pnpm rollup -c rollup.config.js",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-typescript": "^11.1.6",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rollup": "^2.79.2",
|
"rimraf": "^4.1.2",
|
||||||
"rollup-obfuscator": "^3.0.2",
|
"typescript": "^4.9.5"
|
||||||
"rollup-plugin-peer-deps-external": "^2.2.4"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "workspace:*",
|
"@ccms/api": "^0.27.4",
|
||||||
"@ccms/common": "workspace:*",
|
"@ccms/container": "^0.27.4"
|
||||||
"@ccms/container": "workspace:*",
|
|
||||||
"js-yaml": "^4.1.0"
|
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
import typescript from '@rollup/plugin-typescript'
|
|
||||||
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
|
|
||||||
import { obfuscator } from 'rollup-obfuscator'
|
|
||||||
|
|
||||||
import pkg from './package.json'
|
|
||||||
|
|
||||||
const external = ['path', 'fs', 'typescript', 'tslib']
|
|
||||||
/**
|
|
||||||
* @type {import('rollup').RollupOptions}
|
|
||||||
*/
|
|
||||||
export default {
|
|
||||||
input: 'src/index.ts',
|
|
||||||
plugins: [
|
|
||||||
peerDepsExternal(),
|
|
||||||
typescript(),
|
|
||||||
obfuscator({
|
|
||||||
compact: true,
|
|
||||||
deadCodeInjection: true,
|
|
||||||
deadCodeInjectionThreshold: 1,
|
|
||||||
identifierNamesGenerator: 'mangled-shuffled',
|
|
||||||
numbersToExpressions: true,
|
|
||||||
simplify: true,
|
|
||||||
stringArray: true,
|
|
||||||
stringArrayThreshold: 1,
|
|
||||||
stringArrayEncoding: ['rc4'],
|
|
||||||
stringArrayCallsTransform: true,
|
|
||||||
stringArrayCallsTransformThreshold: 1,
|
|
||||||
stringArrayWrappersChainedCalls: true,
|
|
||||||
stringArrayWrappersParametersMaxCount: 3,
|
|
||||||
sourceMap: true,
|
|
||||||
sourceMapSourcesMode: 'sources',
|
|
||||||
inputFileName: `${pkg.name}.ts`,
|
|
||||||
transformObjectKeys: true,
|
|
||||||
unicodeEscapeSequence: true,
|
|
||||||
target: 'browser-no-eval'
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
external,
|
|
||||||
treeshake: false,
|
|
||||||
output: [
|
|
||||||
{
|
|
||||||
format: 'cjs',
|
|
||||||
interop: "auto",
|
|
||||||
exports: "named",
|
|
||||||
sourcemap: true,
|
|
||||||
file: pkg.main || `dist/${pkg.name}.js`
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@ console.i18n("ms.core.ioc.completed", { scope: global.scope, time: (Date.now() -
|
|||||||
import * as yaml from 'js-yaml'
|
import * as yaml from 'js-yaml'
|
||||||
import http from '@ccms/common/dist/http'
|
import http from '@ccms/common/dist/http'
|
||||||
import * as fs from '@ccms/common/dist/fs'
|
import * as fs from '@ccms/common/dist/fs'
|
||||||
|
import { VersionUtils } from '@ccms/common/dist/version'
|
||||||
|
|
||||||
const UUID = Java.type('java.util.UUID')
|
const UUID = Java.type('java.util.UUID')
|
||||||
const MiaoScriptAPI = Java.type('pw.yumc.MiaoScript.api.MiaoScriptAPI')
|
const MiaoScriptAPI = Java.type('pw.yumc.MiaoScript.api.MiaoScriptAPI')
|
||||||
@@ -14,18 +15,22 @@ const MiaoScriptAPI = Java.type('pw.yumc.MiaoScript.api.MiaoScriptAPI')
|
|||||||
class MiaoScriptCore {
|
class MiaoScriptCore {
|
||||||
@Autowired(server.Console)
|
@Autowired(server.Console)
|
||||||
private Console: Console
|
private Console: Console
|
||||||
|
@Autowired(plugin.PluginFolder)
|
||||||
|
private pluginFolder: string
|
||||||
|
@Autowired()
|
||||||
|
private taskManager: task.TaskManager
|
||||||
@Autowired()
|
@Autowired()
|
||||||
private pluginManager: plugin.PluginManager
|
private pluginManager: plugin.PluginManager
|
||||||
|
|
||||||
enable() {
|
enable() {
|
||||||
process.emit('core.before.enable', this)
|
process.emit('core.before.enable')
|
||||||
this.loadServerConsole()
|
this.loadServerConsole()
|
||||||
try {
|
try {
|
||||||
MiaoScriptAPI.setPluginManager(this.pluginManager)
|
MiaoScriptAPI.setPluginManager(this.pluginManager)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
}
|
}
|
||||||
process.emit('core.enable', this)
|
this.loadPlugins()
|
||||||
process.emit('core.after.enable', this)
|
process.emit('core.after.enable')
|
||||||
console.i18n("ms.core.engine.completed", {
|
console.i18n("ms.core.engine.completed", {
|
||||||
loader: base.version,
|
loader: base.version,
|
||||||
version: 'v' + global.ScriptEngineVersion,
|
version: 'v' + global.ScriptEngineVersion,
|
||||||
@@ -35,28 +40,40 @@ class MiaoScriptCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadServerConsole() {
|
loadServerConsole() {
|
||||||
process.emit('core.before.load.console', this)
|
process.emit('core.before.load.console')
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
global.setGlobal('console', new this.Console(), { writable: false, configurable: false })
|
global.setGlobal('console', new this.Console(), { writable: false, configurable: false })
|
||||||
process.emit('core.after.load.console', this)
|
process.emit('core.after.load.console')
|
||||||
|
}
|
||||||
|
|
||||||
|
loadPlugins() {
|
||||||
|
process.emit('core.before.load.plugins')
|
||||||
|
let loadPluginStartTime = new Date().getTime()
|
||||||
|
console.i18n("ms.core.plugin.initialize")
|
||||||
|
this.pluginManager.scan(this.pluginFolder)
|
||||||
|
this.pluginManager.build()
|
||||||
|
this.pluginManager.load(this.pluginManager.getPlugins())
|
||||||
|
this.pluginManager.enable(this.pluginManager.getPlugins())
|
||||||
|
console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 })
|
||||||
|
process.emit('core.after.load.plugins')
|
||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
process.emit('core.before.disable', this)
|
process.emit('core.before.disable')
|
||||||
let disableStartTime = Date.now()
|
let disableStartTime = Date.now()
|
||||||
console.i18n("ms.core.engine.disable")
|
console.i18n("ms.core.engine.disable")
|
||||||
process.emit('core.disable', this)
|
this.pluginManager.disable(this.pluginManager.getPlugins())
|
||||||
process.emit('core.after.disable', this)
|
this.taskManager.disable()
|
||||||
|
process.emit('core.after.disable')
|
||||||
loadCoreScript('exit')
|
loadCoreScript('exit')
|
||||||
process.emit('core.before.exit', this)
|
process.emit('core.before.exit')
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
process.emit('core.exit', this)
|
|
||||||
console.i18n("ms.core.engine.disable.finish", {
|
console.i18n("ms.core.engine.disable.finish", {
|
||||||
loader: base.version,
|
loader: base.version,
|
||||||
version: 'v' + global.ScriptEngineVersion,
|
version: 'v' + global.ScriptEngineVersion,
|
||||||
time: (new Date().getTime() - disableStartTime) / 1000
|
time: (new Date().getTime() - disableStartTime) / 1000
|
||||||
})
|
})
|
||||||
process.emit('core.after.exit', this)
|
process.emit('core.after.exit')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,12 +166,14 @@ function initialize() {
|
|||||||
global.setGlobal('loadCoreScript', loadCoreScript)
|
global.setGlobal('loadCoreScript', loadCoreScript)
|
||||||
loadCoreScript('initialize')
|
loadCoreScript('initialize')
|
||||||
try {
|
try {
|
||||||
return createCore()
|
let core = createCore()
|
||||||
|
return VersionUtils.isGreaterOrEqual(base.version, '0.22.0') ? core : core.enable()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
let core = { enable: () => () => console.i18n('ms.core.engine.disable.abnormal') }
|
||||||
console.i18n("core.initialize.error", { error })
|
console.i18n("core.initialize.error", { error })
|
||||||
jsconsole.getStackTrace(error, false).forEach(line => console.log(line))
|
jsconsole.getStackTrace(error, false).forEach(line => console.log(line))
|
||||||
process.emit('core.initialize.error')
|
process.emit('core.initialize.error')
|
||||||
return { enable: () => () => console.i18n('ms.core.engine.disable.abnormal') }
|
return VersionUtils.isGreaterOrEqual(base.version, '0.22.0') ? core : core.enable()
|
||||||
} finally {
|
} finally {
|
||||||
process.emit('core.after.initialize')
|
process.emit('core.after.initialize')
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/database/.npmignore
Symbolic link
1
packages/database/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/database",
|
"name": "@ccms/database",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript database package",
|
"description": "MiaoScript database package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,22 +12,20 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/spring-jdbc": "^0.0.3"
|
"@javatypes/spring-jdbc": "^0.0.3",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "workspace:*",
|
"@ccms/api": "^0.27.4",
|
||||||
"@ccms/container": "workspace:*"
|
"@ccms/container": "^0.27.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/i18n/.npmignore
Symbolic link
1
packages/i18n/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/i18n",
|
"name": "@ccms/i18n",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript i18n package",
|
"description": "MiaoScript i18n package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,24 +12,21 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map",
|
|
||||||
"languages"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@ccms/nashorn": "^0.27.4",
|
||||||
|
"@types/js-yaml": "^4.0.5",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"js-yaml": "^4.1.0"
|
"js-yaml": "^4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
|
||||||
"@ccms/nashorn": "workspace:*",
|
|
||||||
"@types/js-yaml": "^4.0.9"
|
|
||||||
},
|
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/keyvalue/.npmignore
Symbolic link
1
packages/keyvalue/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
36
packages/keyvalue/package.json
Normal file
36
packages/keyvalue/package.json
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"name": "@ccms/keyvalue",
|
||||||
|
"version": "0.27.4",
|
||||||
|
"description": "MiaoScript keyvalue package",
|
||||||
|
"keywords": [
|
||||||
|
"miaoscript",
|
||||||
|
"minecraft",
|
||||||
|
"bukkit",
|
||||||
|
"sponge"
|
||||||
|
],
|
||||||
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
|
"license": "ISC",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"clean": "rimraf dist",
|
||||||
|
"watch": "tsc --watch",
|
||||||
|
"build": "yarn clean && tsc",
|
||||||
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@ccms/api": "^0.27.4",
|
||||||
|
"@ccms/common": "^0.27.4",
|
||||||
|
"@ccms/container": "^0.27.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@ccms/nashorn": "^0.27.4",
|
||||||
|
"@javatypes/amqp-client": "^0.0.3",
|
||||||
|
"@javatypes/spring-amqp": "^0.0.3",
|
||||||
|
"@javatypes/spring-rabbit": "^0.0.3",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
|
},
|
||||||
|
"gitHead": "2589633069d24f646ac09261b1b2304c21d4ea75"
|
||||||
|
}
|
||||||
3
packages/keyvalue/src/index.ts
Normal file
3
packages/keyvalue/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/// <reference types="@ccms/nashorn" />
|
||||||
|
/// <reference types="@javatypes/jdk" />
|
||||||
|
export { }
|
||||||
7
packages/keyvalue/tsconfig.json
Normal file
7
packages/keyvalue/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "src",
|
||||||
|
"outDir": "dist"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/molang",
|
"name": "@ccms/molang",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "A fast parser for Minecraft's MoLang",
|
"description": "A fast parser for Minecraft's MoLang",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -26,6 +21,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/solvedDev/MoLang#readme",
|
"homepage": "https://github.com/solvedDev/MoLang#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.19.118"
|
"@types/node": "^18.13.0",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"tslib": "^2.5.0",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/nashorn/.npmignore
Symbolic link
1
packages/nashorn/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nashorn",
|
"name": "@ccms/nashorn",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript nashorn package",
|
"description": "MiaoScript nashorn package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -13,15 +13,15 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/nodejs/.npmignore
Symbolic link
1
packages/nodejs/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nodejs",
|
"name": "@ccms/nodejs",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript nodejs package",
|
"description": "MiaoScript nodejs package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,19 +12,18 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "workspace:*"
|
"@ccms/nashorn": "^0.27.4",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"tslib": "^2.5.0",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
var Throwable = Java.type('java.lang.Throwable')
|
|
||||||
var R = typeof Reflect === 'object' ? Reflect : null
|
var R = typeof Reflect === 'object' ? Reflect : null
|
||||||
var ReflectApply = R && typeof R.apply === 'function'
|
var ReflectApply = R && typeof R.apply === 'function'
|
||||||
? R.apply
|
? R.apply
|
||||||
@@ -137,19 +136,13 @@ EventEmitter.prototype.emit = function emit(type) {
|
|||||||
var er;
|
var er;
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
er = args[0];
|
er = args[0];
|
||||||
if (er instanceof Error || er instanceof Throwable) {
|
if (er instanceof Error) {
|
||||||
// Note: The comments on the `throw` lines are intentional, they show
|
// Note: The comments on the `throw` lines are intentional, they show
|
||||||
// up in Node's output if this results in an unhandled exception.
|
// up in Node's output if this results in an unhandled exception.
|
||||||
throw er; // Unhandled 'error' event
|
throw er; // Unhandled 'error' event
|
||||||
}
|
}
|
||||||
if (er.error instanceof Error || er.error instanceof Throwable) {
|
|
||||||
throw er.error; // Unhandled 'error' event
|
|
||||||
}
|
|
||||||
if (er.cause instanceof Error || er.cause instanceof Throwable) {
|
|
||||||
throw er.cause; // Unhandled 'error' event
|
|
||||||
}
|
|
||||||
// At least give some kind of context to the user
|
// At least give some kind of context to the user
|
||||||
var err = new Error('Unhandled error.' + (er ? ' (' + (er.message || er.error || er.cause || er) + ')' : ''));
|
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
err.context = er;
|
err.context = er;
|
||||||
throw err; // Unhandled 'error' event
|
throw err; // Unhandled 'error' event
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ const Path = Java.type("java.nio.file.Path");
|
|||||||
const JavaString = Java.type("java.lang.String");
|
const JavaString = Java.type("java.lang.String");
|
||||||
const File = Java.type("java.io.File");
|
const File = Java.type("java.io.File");
|
||||||
const Files = Java.type("java.nio.file.Files");
|
const Files = Java.type("java.nio.file.Files");
|
||||||
const Paths = Java.type("java.nio.file.Paths");
|
|
||||||
const Collector = Java.type("java.util.stream.Collector")
|
const Collector = Java.type("java.util.stream.Collector")
|
||||||
const separatorChar = File.separatorChar;
|
const separatorChar = File.separatorChar;
|
||||||
const StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
const StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
||||||
@@ -38,7 +37,7 @@ function javaFile(...opts: any[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function renameSync(oldPath: PathLike, newPath: PathLike): void {
|
export function renameSync(oldPath: PathLike, newPath: PathLike): void {
|
||||||
Files.move(Paths.get(oldPath), Paths.get(oldPath), StandardCopyOption['ATOMIC_MOVE'])
|
|
||||||
}
|
}
|
||||||
export function truncateSync() {
|
export function truncateSync() {
|
||||||
|
|
||||||
|
|||||||
@@ -715,7 +715,6 @@ function callbackify(original) {
|
|||||||
// implications (stack, `uncaughtException`, `async_hooks`)
|
// implications (stack, `uncaughtException`, `async_hooks`)
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
original.apply(this, args)
|
original.apply(this, args)
|
||||||
// @ts-ignore
|
|
||||||
.then(function (ret) { process.nextTick(cb.bind(null, null, ret)) },
|
.then(function (ret) { process.nextTick(cb.bind(null, null, ret)) },
|
||||||
function (rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) });
|
function (rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) });
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/nukkit/.npmignore
Symbolic link
1
packages/nukkit/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nukkit",
|
"name": "@ccms/nukkit",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript nukkit package",
|
"description": "MiaoScript nukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,23 +12,21 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/nukkit-api": "^0.0.3"
|
"@javatypes/nukkit-api": "^0.0.3",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "workspace:*",
|
"@ccms/api": "^0.27.4",
|
||||||
"@ccms/common": "workspace:*",
|
"@ccms/common": "^0.27.4",
|
||||||
"@ccms/container": "workspace:*"
|
"@ccms/container": "^0.27.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/plugin/.npmignore
Symbolic link
1
packages/plugin/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/plugin",
|
"name": "@ccms/plugin",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript plugin package",
|
"description": "MiaoScript plugin package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,28 +12,26 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/crypto-js": "^4.2.2",
|
"@types/crypto-js": "^4.1.1",
|
||||||
"@types/js-yaml": "^4.0.9"
|
"@types/js-yaml": "^4.0.5",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "workspace:*",
|
"@ccms/api": "^0.27.4",
|
||||||
"@ccms/common": "workspace:*",
|
"@ccms/common": "^0.27.4",
|
||||||
"@ccms/container": "workspace:*",
|
"@ccms/container": "^0.27.4",
|
||||||
"@ccms/i18n": "workspace:*",
|
"@ccms/i18n": "^0.27.4",
|
||||||
"@ccms/verify": "^0.26.1",
|
"@ccms/verify": "^0.25.1",
|
||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.1.1",
|
||||||
"js-yaml": "^4.1.0"
|
"js-yaml": "^4.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import './config/loader'
|
|||||||
export class PluginConfigManager {
|
export class PluginConfigManager {
|
||||||
@Autowired(ContainerInstance)
|
@Autowired(ContainerInstance)
|
||||||
private container: Container
|
private container: Container
|
||||||
@Autowired(plugin.PluginFolder)
|
|
||||||
private pluginFolder: string
|
|
||||||
|
|
||||||
private configLoaderMap = new Map<string, PluginConfigLoader>()
|
private configLoaderMap = new Map<string, PluginConfigLoader>()
|
||||||
|
|
||||||
@@ -33,7 +31,7 @@ export class PluginConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getConfigLoader(format: string) {
|
getConfigLoader(format: string) {
|
||||||
if (!this.configLoaderMap.has(format)) { throw new Error(`unsupport config format ${format} !`) }
|
if (!this.configLoaderMap.has(format)) { throw new Error(`Unsupport config format ${format} !`) }
|
||||||
return this.configLoaderMap.get(format)
|
return this.configLoaderMap.get(format)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +68,7 @@ export class PluginConfigManager {
|
|||||||
try {
|
try {
|
||||||
let defaultValue = metadata.default ?? plugin[metadata.variable]
|
let defaultValue = metadata.default ?? plugin[metadata.variable]
|
||||||
metadata.file = fs.concat(
|
metadata.file = fs.concat(
|
||||||
root,
|
fs.file(plugin.description.loadMetadata.file).parent,
|
||||||
this.pluginFolder,
|
|
||||||
plugin.description.name,
|
plugin.description.name,
|
||||||
metadata.filename
|
metadata.filename
|
||||||
)
|
)
|
||||||
@@ -88,7 +85,7 @@ export class PluginConfigManager {
|
|||||||
if (metadata.migrate && defaultValue && this.setDefaultValue(configValue, defaultValue, !!metadata.default)) {
|
if (metadata.migrate && defaultValue && this.setDefaultValue(configValue, defaultValue, !!metadata.default)) {
|
||||||
base.save(metadata.file, configLoader.dump(configValue))
|
base.save(metadata.file, configLoader.dump(configValue))
|
||||||
}
|
}
|
||||||
console.debug(`[${plugin.description.name}] load config ${metadata.variable} from file ${metadata.file}`)
|
console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file}`)
|
||||||
this.defienConfigProp(plugin, metadata, configValue)
|
this.defienConfigProp(plugin, metadata, configValue)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.i18n("ms.plugin.manager.config.load.error", {
|
console.i18n("ms.plugin.manager.config.load.error", {
|
||||||
@@ -121,7 +118,7 @@ export class PluginConfigManager {
|
|||||||
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)
|
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)
|
||||||
let result = this.getConfigLoader(metadata.format).dump(plugin[metadata.variable])
|
let result = this.getConfigLoader(metadata.format).dump(plugin[metadata.variable])
|
||||||
base.save(metadata.file, result)
|
base.save(metadata.file, result)
|
||||||
console.debug(`[${plugin.description.name}] save config ${metadata.variable} to file ${metadata.file} =>
|
console.debug(`[${plugin.description.name}] Save Config ${metadata.variable} to file ${metadata.file} =>
|
||||||
${result.substring(0, 500)}`)
|
${result.substring(0, 500)}`)
|
||||||
return true
|
return true
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ export class PluginEventManager {
|
|||||||
let off = () => {
|
let off = () => {
|
||||||
if (off['offed']) return
|
if (off['offed']) return
|
||||||
off['offed'] = true
|
off['offed'] = true
|
||||||
execes.forEach((exec: { off: () => void }) => exec.off())
|
execes.forEach((off: () => any) => off())
|
||||||
}
|
}
|
||||||
listener.off = off
|
listener.off = off
|
||||||
}
|
}
|
||||||
|
|
||||||
public unregistryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
|
private unregistryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
|
||||||
if (listener && listener.off) {
|
if (listener && listener.off) {
|
||||||
listener.off()
|
listener.off()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { server, MiaoScriptConsole, event, plugin, task, command } from "@ccms/api"
|
import { server, MiaoScriptConsole, event, plugin } from "@ccms/api"
|
||||||
import { injectable, inject, postConstruct, Autowired } from "@ccms/container"
|
import { injectable, inject, postConstruct } from "@ccms/container"
|
||||||
import { getPluginMetadata } from "./utils"
|
import { getPluginMetadata } from "./utils"
|
||||||
import { PluginEventManager } from "./event"
|
|
||||||
import { PluginCommandManager } from "./command"
|
|
||||||
|
|
||||||
const File = Java.type('java.io.File')
|
const File = Java.type('java.io.File')
|
||||||
|
|
||||||
@@ -13,12 +11,6 @@ export namespace interfaces {
|
|||||||
public logger: MiaoScriptConsole
|
public logger: MiaoScriptConsole
|
||||||
@inject(server.Console)
|
@inject(server.Console)
|
||||||
private Console: MiaoScriptConsole
|
private Console: MiaoScriptConsole
|
||||||
@Autowired()
|
|
||||||
private taskManager: task.TaskManager
|
|
||||||
@Autowired()
|
|
||||||
private eventManager: PluginEventManager
|
|
||||||
@Autowired()
|
|
||||||
private commandManager: PluginCommandManager
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.description = getPluginMetadata(this)
|
this.description = getPluginMetadata(this)
|
||||||
@@ -36,42 +28,10 @@ export namespace interfaces {
|
|||||||
return dataFolder.getAbsolutePath()
|
return dataFolder.getAbsolutePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public registryCommand(executor: any) { }
|
||||||
* 注册命令
|
public unregistryCommand(executor: any) { }
|
||||||
* @param executor 命令执行器
|
public registryListener(listener: any) { }
|
||||||
*/
|
public unregistryListener(listener: any) { }
|
||||||
public registryCommand(executor: any) {
|
|
||||||
this.commandManager.registryCommand(this, executor)
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 注销命令
|
|
||||||
* @param executor 命令执行器
|
|
||||||
*/
|
|
||||||
public unregistryCommand(executor: any) {
|
|
||||||
this.commandManager.unregistryCommand(this, executor)
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 注册事件
|
|
||||||
* @param listener 事件监听器
|
|
||||||
*/
|
|
||||||
public registryListener(listener: any) {
|
|
||||||
this.eventManager.registryListener(this, listener)
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 注销事件
|
|
||||||
* @param listener 事件监听器
|
|
||||||
*/
|
|
||||||
public unregistryListener(listener: any) {
|
|
||||||
this.eventManager.unregistryListener(this, listener)
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 创建任务
|
|
||||||
* @param func 任务内容
|
|
||||||
* @returns 任务
|
|
||||||
*/
|
|
||||||
public createTask(func: Function) {
|
|
||||||
return this.taskManager.create(func, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
public load() { }
|
public load() { }
|
||||||
public enable() { }
|
public enable() { }
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ export class BasicLoader implements plugin.PluginLoader {
|
|||||||
if (metadata?.type == this.type) {
|
if (metadata?.type == this.type) {
|
||||||
loadMetadata.metadata = metadata
|
loadMetadata.metadata = metadata
|
||||||
loadMetadata.loaded = true
|
loadMetadata.loaded = true
|
||||||
this.pluginRequireMap.set(loadMetadata.path, loadMetadata.instance)
|
this.pluginRequireMap.set(metadata.source.toString(), loadMetadata.instance)
|
||||||
}
|
}
|
||||||
return loadMetadata
|
return loadMetadata
|
||||||
}
|
}
|
||||||
build(metadata: plugin.PluginMetadata) {
|
build(metadata: plugin.PluginMetadata) {
|
||||||
return this.pluginRequireMap.get(metadata.loadMetadata.path)
|
return this.pluginRequireMap.get(metadata.source.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ export class IocLoader implements plugin.PluginLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require(loadMetadata: plugin.PluginLoadMetadata) {
|
require(loadMetadata: plugin.PluginLoadMetadata) {
|
||||||
let metadata = this.pluginMetadataMap.get(loadMetadata.path)
|
let metadata = this.pluginMetadataMap.get(loadMetadata.file.toString())
|
||||||
if (metadata?.type == this.type) {
|
if (metadata && metadata.type == this.type) {
|
||||||
loadMetadata.metadata = metadata
|
loadMetadata.metadata = metadata
|
||||||
loadMetadata.loaded = true
|
loadMetadata.loaded = true
|
||||||
}
|
}
|
||||||
@@ -54,6 +54,13 @@ export class IocLoader implements plugin.PluginLoader {
|
|||||||
disable(plugin: plugin.Plugin): void {
|
disable(plugin: plugin.Plugin): void {
|
||||||
this.stage(plugin, 'disable')
|
this.stage(plugin, 'disable')
|
||||||
}
|
}
|
||||||
|
reload(plugin: plugin.Plugin): void {
|
||||||
|
this.disable(plugin)
|
||||||
|
//@ts-ignore
|
||||||
|
require(plugin.description.source, { cache: false })
|
||||||
|
this.load(plugin)
|
||||||
|
this.enable(plugin)
|
||||||
|
}
|
||||||
|
|
||||||
private bindPlugin(metadata: plugin.PluginMetadata) {
|
private bindPlugin(metadata: plugin.PluginMetadata) {
|
||||||
if (this.container.isBoundNamed(plugin.Plugin, metadata.name)) {
|
if (this.container.isBoundNamed(plugin.Plugin, metadata.name)) {
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
private pluginInstance: any
|
private pluginInstance: any
|
||||||
@Autowired(server.ServerType)
|
@Autowired(server.ServerType)
|
||||||
private serverType: string
|
private serverType: string
|
||||||
@Autowired(plugin.PluginFolder)
|
|
||||||
private pluginFolder: string
|
|
||||||
|
|
||||||
@Autowired()
|
@Autowired()
|
||||||
private serverChecker: server.ServerChecker
|
private serverChecker: server.ServerChecker
|
||||||
@@ -60,21 +58,6 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
this.eventManager
|
this.eventManager
|
||||||
this.configManager
|
this.configManager
|
||||||
this.commandManager
|
this.commandManager
|
||||||
process.on('core.enable', (core) => {
|
|
||||||
process.emit('core.before.load.plugins')
|
|
||||||
let loadPluginStartTime = new Date().getTime()
|
|
||||||
console.i18n("ms.core.plugin.initialize")
|
|
||||||
process.emit('core.load.plugins', this.pluginFolder)
|
|
||||||
console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 })
|
|
||||||
process.emit('core.after.load.plugins')
|
|
||||||
})
|
|
||||||
process.on('core.load.plugins', (pluginFolder) => {
|
|
||||||
this.scan(pluginFolder)
|
|
||||||
this.buildPlugins()
|
|
||||||
this.loadPlugins()
|
|
||||||
this.enablePlugins()
|
|
||||||
})
|
|
||||||
process.on('core.disable', () => { this.disablePlugins() })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
@@ -103,7 +86,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scan(folder: string): void {
|
scan(folder: string): void {
|
||||||
if (!folder) { throw new Error("plugin scan folder can't be undefiend.") }
|
if (!folder) { throw new Error('plugin scan folder can\'t be empty!') }
|
||||||
this.initialize()
|
this.initialize()
|
||||||
process.emit('plugin.manager.before.scan', folder, this)
|
process.emit('plugin.manager.before.scan', folder, this)
|
||||||
for (const [, scanner] of this.sacnnerMap) {
|
for (const [, scanner] of this.sacnnerMap) {
|
||||||
@@ -113,7 +96,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
console.i18n('ms.plugin.manager.scan.finish', { scanner: scanner.type, folder, size: loadMetadatas.length })
|
console.i18n('ms.plugin.manager.scan.finish', { scanner: scanner.type, folder, size: loadMetadatas.length })
|
||||||
for (const loadMetadata of loadMetadatas) {
|
for (const loadMetadata of loadMetadatas) {
|
||||||
try {
|
try {
|
||||||
this.require(loadMetadata)
|
this.loadAndRequirePlugin(loadMetadata)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.console(`§c扫描器 §4${scanner.type} §c文件 §4${loadMetadata.file.toString().replace(root, '')} §c编译失败 请提供下列错误给开发者`)
|
console.console(`§c扫描器 §4${scanner.type} §c文件 §4${loadMetadata.file.toString().replace(root, '')} §c编译失败 请提供下列错误给开发者`)
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
@@ -126,6 +109,12 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
process.emit('plugin.manager.after.scan', folder, this)
|
process.emit('plugin.manager.after.scan', folder, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
build(): void {
|
||||||
|
process.emit('plugin.manager.before.build', this)
|
||||||
|
this.buildPlugins()
|
||||||
|
process.emit('plugin.manager.after.build', this)
|
||||||
|
}
|
||||||
|
|
||||||
private logStage(plugin: plugin.Plugin, stage: string) {
|
private logStage(plugin: plugin.Plugin, stage: string) {
|
||||||
console.i18n("ms.plugin.manager.stage", { stage, plugin: plugin.description.name, version: plugin.description.version, author: plugin.description.author })
|
console.i18n("ms.plugin.manager.stage", { stage, plugin: plugin.description.name, version: plugin.description.version, author: plugin.description.author })
|
||||||
}
|
}
|
||||||
@@ -145,9 +134,9 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadPlugin(loadMetadata: plugin.PluginLoadMetadata): plugin.PluginMetadata {
|
private loadPlugin(loadMetadata: plugin.PluginLoadMetadata) {
|
||||||
if (!loadMetadata) { throw new Error("loadMetadata can't be undefiend when loadPlugin.") }
|
if (!loadMetadata) { throw new Error('loadMetadata can\'t be undefiend when loadPlugin!') }
|
||||||
if (loadMetadata.loaded) { throw new Error(`plugin file ${loadMetadata.file} is already loaded by ${loadMetadata.loader?.type}.`) }
|
if (loadMetadata.loaded) { throw new Error(`Plugin file ${loadMetadata.file} is already loaded by ${loadMetadata.loader?.type}!`) }
|
||||||
process.emit(`plugin.before.require`, loadMetadata)
|
process.emit(`plugin.before.require`, loadMetadata)
|
||||||
try {
|
try {
|
||||||
for (const [, loader] of this.loaderMap) {
|
for (const [, loader] of this.loaderMap) {
|
||||||
@@ -156,8 +145,6 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.i18n("ms.plugin.manager.initialize.error", { name: loadMetadata.file, ex: error })
|
console.i18n("ms.plugin.manager.initialize.error", { name: loadMetadata.file, ex: error })
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
} finally {
|
|
||||||
process.emit(`plugin.after.require`, loadMetadata)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,18 +155,19 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
let metadata = loadMetadata.metadata
|
let metadata = loadMetadata.metadata
|
||||||
if (this.metadataMap.has(metadata.name) && this.instanceMap.has(metadata.name)) {
|
if (this.metadataMap.has(metadata.name) && this.instanceMap.has(metadata.name)) {
|
||||||
let oldMetadata = this.metadataMap.get(metadata.name)
|
let oldMetadata = this.metadataMap.get(metadata.name)
|
||||||
throw new Error(`plugin ${oldMetadata.name} is already load from ${oldMetadata.source}.`)
|
throw new Error(`Plugin ${oldMetadata.name} is already load from ${oldMetadata.source}...`)
|
||||||
}
|
}
|
||||||
this.metadataMap.set(metadata.name, metadata)
|
this.metadataMap.set(metadata.name, metadata)
|
||||||
metadata.loadMetadata = loadMetadata
|
metadata.loadMetadata = loadMetadata
|
||||||
|
process.emit(`plugin.after.require`, loadMetadata)
|
||||||
}
|
}
|
||||||
return loadMetadata
|
return loadMetadata
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (global.debug) {
|
if (global.debug) {
|
||||||
console.console(`§6loader §b${loader.type} §6load §a${loadMetadata.file} §cerror. §4Err: §c${error}`)
|
console.console(`§6Loader §b${loader.type} §6load §a${loadMetadata.file} §cerror. §4Err: §c${error}`)
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
} else {
|
} else {
|
||||||
console.warn(`loader ${loader.type} load ${loadMetadata.file} error. Err: ${error}`)
|
console.warn(`Loader ${loader.type} load ${loadMetadata.file} error. Err: ${error}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,10 +175,10 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
private loadAndRequirePlugin(loadMetadata: plugin.PluginLoadMetadata) {
|
private loadAndRequirePlugin(loadMetadata: plugin.PluginLoadMetadata) {
|
||||||
let startTime = Date.now()
|
let startTime = Date.now()
|
||||||
let metadata = this.loadPlugin(loadMetadata.scanner.load(loadMetadata))
|
let metadata = this.loadPlugin(loadMetadata.scanner.load(loadMetadata))
|
||||||
if (!metadata) { throw new Error(`can't load plugin from metadata: ${JSON.stringify(loadMetadata)}`) }
|
if (!metadata) { throw new Error('load plugin metadata failed.') }
|
||||||
console.i18n('ms.plugin.manager.build', {
|
console.i18n('ms.plugin.manager.build', {
|
||||||
name: metadata.name,
|
name: loadMetadata.metadata.name,
|
||||||
version: metadata.version,
|
version: loadMetadata.metadata.version,
|
||||||
file: loadMetadata.file.toString().replace(root, ''),
|
file: loadMetadata.file.toString().replace(root, ''),
|
||||||
scanner: loadMetadata.scanner.type,
|
scanner: loadMetadata.scanner.type,
|
||||||
loader: loadMetadata.loader.type,
|
loader: loadMetadata.loader.type,
|
||||||
@@ -204,54 +192,39 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
* @param file java.io.File
|
* @param file java.io.File
|
||||||
*/
|
*/
|
||||||
loadFromFile(file: string, ext: any = 'js'): plugin.Plugin {
|
loadFromFile(file: string, ext: any = 'js'): plugin.Plugin {
|
||||||
if (!file) { throw new Error("plugin file can't be undefiend.") }
|
if (!file) { throw new Error('plugin file can\'t be undefiend.') }
|
||||||
let scanner = this.sacnnerMap.get(ext)
|
let scanner = this.sacnnerMap.get(ext)
|
||||||
if (!scanner) { throw new Error(`scanner ${ext} can't found in sacnnerMap.`) }
|
if (!scanner) { throw new Error(`plugin scanner ${ext} can't found in sacnnerMap.`) }
|
||||||
let metadata = this.loadAndRequirePlugin(scanner.read(file))
|
let metadata = this.loadAndRequirePlugin(scanner.read(file))
|
||||||
this.buildPlugin(metadata)
|
this.buildPlugin(metadata)
|
||||||
let plugin = metadata.target
|
let plugin = metadata.target
|
||||||
if (!plugin) { throw new Error(`loader ${metadata.loadMetadata.loader.type} build plugin ${metadata.name} failed.`) }
|
if (!plugin) { throw new Error(`plugin scanner ${ext} can't found in sacnnerMap.`) }
|
||||||
this.load(plugin)
|
this.load(plugin)
|
||||||
this.enable(plugin)
|
this.enable(plugin)
|
||||||
return plugin
|
return plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
load(plugin: plugin.Plugin): void {
|
load(...args: any[]): void {
|
||||||
this.runPluginStage(plugin, 'load')
|
this.checkAndGet(args[0]).forEach((plugin: plugin.Plugin) => this.runPluginStage(plugin, 'load'))
|
||||||
}
|
}
|
||||||
|
|
||||||
enable(plugin: plugin.Plugin): void {
|
enable(...args: any[]): void {
|
||||||
this.runPluginStage(plugin, 'enable')
|
this.checkAndGet(args[0]).forEach((plugin: plugin.Plugin) => this.runPluginStage(plugin, 'enable'))
|
||||||
}
|
}
|
||||||
|
|
||||||
disable(plugin: plugin.Plugin): void {
|
disable(...args: any[]): void {
|
||||||
this.runPluginStage(plugin, 'disable')
|
this.checkAndGet(args[0]).forEach((plugin: plugin.Plugin) => {
|
||||||
this.metadataMap.delete(plugin.description.name)
|
this.runPluginStage(plugin, 'disable')
|
||||||
this.instanceMap.delete(plugin.description.name)
|
this.metadataMap.delete(plugin.description.name)
|
||||||
|
this.instanceMap.delete(plugin.description.name)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
reload(plugin: plugin.Plugin): void {
|
reload(...args: any[]): void {
|
||||||
this.rebuild(plugin)
|
this.checkAndGet(args[0]).forEach((pl: plugin.Plugin) => {
|
||||||
}
|
this.disable(pl)
|
||||||
|
this.loadFromFile(pl.description.loadMetadata.file, pl.description.loadMetadata.scanner.type)
|
||||||
require(loadMetadata: plugin.PluginLoadMetadata): plugin.PluginMetadata {
|
})
|
||||||
return this.loadAndRequirePlugin(loadMetadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
build(metadata: plugin.PluginMetadata): plugin.Plugin {
|
|
||||||
try {
|
|
||||||
return this.buildPlugin(metadata)
|
|
||||||
} catch (error: any) {
|
|
||||||
console.ex(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rebuild(plugin: plugin.Plugin): void {
|
|
||||||
if (!plugin) { throw new Error(`can't run reload plugin because plugin is ${plugin}`) }
|
|
||||||
this.disable(plugin)
|
|
||||||
let loadMetadata = plugin.description.loadMetadata
|
|
||||||
delete require.cache[loadMetadata.path]
|
|
||||||
this.loadFromFile(loadMetadata.file)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
has(name: string) {
|
has(name: string) {
|
||||||
@@ -259,65 +232,46 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get(name: string) {
|
get(name: string) {
|
||||||
return this.instanceMap.get(name)
|
return this.instanceMap.get(name) || null
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlugin(name: string) {
|
getPlugin(name: string) {
|
||||||
return this.instanceMap.get(name)
|
return this.instanceMap.get(name) || null
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlugins() {
|
getPlugins() {
|
||||||
return this.instanceMap
|
return this.instanceMap
|
||||||
}
|
}
|
||||||
|
|
||||||
buildPlugins() {
|
private runCatch(pl: any, func: string) {
|
||||||
process.emit('plugin.manager.before.build', this)
|
|
||||||
for (const [key, metadata] of this.metadataMap) {
|
|
||||||
if (metadata.depends?.length) {
|
|
||||||
this.lazyMetadataMap.set(key, metadata)
|
|
||||||
} else {
|
|
||||||
this.build(metadata)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const metadata of this.lazyMetadataMap.values()) {
|
|
||||||
this.build(metadata)
|
|
||||||
}
|
|
||||||
process.emit('plugin.manager.after.build', this)
|
|
||||||
}
|
|
||||||
|
|
||||||
rebuildPlugins() {
|
|
||||||
for (const plugin of this.instanceMap.values()) {
|
|
||||||
this.rebuild(plugin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadPlugins() {
|
|
||||||
for (const plugin of this.instanceMap.values()) {
|
|
||||||
this.load(plugin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enablePlugins() {
|
|
||||||
for (const plugin of this.instanceMap.values()) {
|
|
||||||
this.enable(plugin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
disablePlugins() {
|
|
||||||
for (const plugin of this.instanceMap.values()) {
|
|
||||||
this.disable(plugin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private runCatch(plugin: any, fn: string) {
|
|
||||||
try {
|
try {
|
||||||
if (plugin[fn]) plugin[fn].call(plugin)
|
if (pl[func]) pl[func].call(pl)
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
console.i18n("ms.plugin.manager.stage.exec.error", { plugin: plugin.description.name, executor: fn, error: ex })
|
console.i18n("ms.plugin.manager.stage.exec.error", { plugin: pl.description.name, executor: func, error: ex })
|
||||||
console.ex(ex)
|
console.ex(ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private checkAndGet(name: string | plugin.Plugin | undefined | any): Map<string, plugin.Plugin> | plugin.Plugin[] {
|
||||||
|
if (name === undefined) throw new Error(`checkAndGet Plugin can't be undefiend.`)
|
||||||
|
if (name == this.instanceMap) { return this.instanceMap }
|
||||||
|
if (typeof name == 'string' && this.instanceMap.has(name)) { return [this.instanceMap.get(name)] }
|
||||||
|
if (name instanceof interfaces.Plugin) { return [name as plugin.Plugin] }
|
||||||
|
if (name.description?.name) { return [name as plugin.Plugin] }
|
||||||
|
throw new Error(`Plugin ${JSON.stringify(name)} not exist.`)
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildPlugins() {
|
||||||
|
this.metadataMap.forEach((metadata, key) => {
|
||||||
|
if (metadata?.depends?.length) {
|
||||||
|
this.lazyMetadataMap.set(key, metadata)
|
||||||
|
} else {
|
||||||
|
this.tryBuildPlugin(metadata)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.lazyMetadataMap.forEach((metadata, key) => this.tryBuildPlugin(metadata))
|
||||||
|
}
|
||||||
|
|
||||||
private checkDepends(depends: string | string[]) {
|
private checkDepends(depends: string | string[]) {
|
||||||
if (!depends) return []
|
if (!depends) return []
|
||||||
let loseDepends = []
|
let loseDepends = []
|
||||||
@@ -326,11 +280,18 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
}
|
}
|
||||||
private checkNativeDepends(depends: string | string[]) {
|
private checkNativeDepends(depends: string | string[]) {
|
||||||
if (!depends) return []
|
if (!depends) return []
|
||||||
let loseNativeDepends = []
|
let loseDepends = []
|
||||||
for (const depend of depends) { if (!this.nativePluginManager.has(depend)) loseNativeDepends.push(depend) }
|
for (const depend of depends) { if (!this.nativePluginManager.has(depend)) loseDepends.push(depend) }
|
||||||
return loseNativeDepends
|
return loseDepends
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private tryBuildPlugin(metadata: plugin.PluginMetadata) {
|
||||||
|
try {
|
||||||
|
return this.buildPlugin(metadata)
|
||||||
|
} catch (error: any) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private buildPlugin(metadata: plugin.PluginMetadata) {
|
private buildPlugin(metadata: plugin.PluginMetadata) {
|
||||||
process.emit(`plugin.before.build`, metadata)
|
process.emit(`plugin.before.build`, metadata)
|
||||||
@@ -343,7 +304,6 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
if (loseNativeDepends.length) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查插件依赖 §3[${loseNativeDepends.join(',')}] §4是否安装完整!`) }
|
if (loseNativeDepends.length) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查插件依赖 §3[${loseNativeDepends.join(',')}] §4是否安装完整!`) }
|
||||||
let pluginInstance = this.loaderMap.get(metadata.type).build(metadata)
|
let pluginInstance = this.loaderMap.get(metadata.type).build(metadata)
|
||||||
if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) }
|
if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) }
|
||||||
process.emit(`plugin.build`, pluginInstance)
|
|
||||||
metadata.target = pluginInstance
|
metadata.target = pluginInstance
|
||||||
this.instanceMap.set(metadata.name, pluginInstance)
|
this.instanceMap.set(metadata.name, pluginInstance)
|
||||||
process.emit(`plugin.after.build`, metadata, pluginInstance)
|
process.emit(`plugin.after.build`, metadata, pluginInstance)
|
||||||
|
|||||||
@@ -13,21 +13,15 @@ export class JSFileScanner implements plugin.PluginScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
read(file: any): plugin.PluginLoadMetadata {
|
read(file: any): plugin.PluginLoadMetadata {
|
||||||
return {
|
return { file, type: this.type, scanner: this, loaded: false }
|
||||||
file,
|
|
||||||
path: file.canonicalPath || file.toString(),
|
|
||||||
type: this.type,
|
|
||||||
scanner: this,
|
|
||||||
loaded: false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
load(loadMetadata: plugin.PluginLoadMetadata): plugin.PluginLoadMetadata {
|
load(metadata: plugin.PluginLoadMetadata): plugin.PluginLoadMetadata {
|
||||||
if (loadMetadata.type !== this.type) { return }
|
if (metadata.type !== this.type) { return }
|
||||||
this.updatePlugin(loadMetadata.file)
|
this.updatePlugin(metadata.file)
|
||||||
delete require.cache[loadMetadata.path]
|
//@ts-ignore load plugin not use cache
|
||||||
loadMetadata.instance = require(loadMetadata.path)
|
metadata.instance = require(metadata.file.toString(), { cache: false })
|
||||||
return loadMetadata
|
return metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
private scanFolder(folder: any): string[] {
|
private scanFolder(folder: any): string[] {
|
||||||
@@ -51,7 +45,7 @@ export class JSFileScanner implements plugin.PluginScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updatePlugin(file: any) {
|
private updatePlugin(file: any) {
|
||||||
var update = fs.file(fs.concat(file.parentFile, 'update', file.name))
|
var update = fs.file(fs.file(fs.file(file).parentFile, 'update'), file.name)
|
||||||
if (update.exists()) {
|
if (update.exists()) {
|
||||||
console.i18n("ms.plugin.manager.build.update", { name: file.name })
|
console.i18n("ms.plugin.manager.build.update", { name: file.name })
|
||||||
fs.move(update, file, true)
|
fs.move(update, file, true)
|
||||||
|
|||||||
1
packages/polyfill/.npmignore
Symbolic link
1
packages/polyfill/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,26 +1,27 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/polyfill",
|
"name": "@ccms/polyfill",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript polyfill package",
|
"description": "MiaoScript polyfill package",
|
||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/i18n": "workspace:*",
|
"@ccms/i18n": "^0.27.4",
|
||||||
"@ccms/nodejs": "workspace:*",
|
"@ccms/nodejs": "^0.27.4",
|
||||||
"core-js": "^3.44.0"
|
"core-js": "^3.27.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@ccms/nashorn": "^0.27.4",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,241 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
// @ts-ignore
|
|
||||||
require.internal.versionLockModules['core-js'] = '3.32.2'
|
|
||||||
import 'core-js/modules/es.symbol';
|
|
||||||
import 'core-js/modules/es.symbol.description';
|
|
||||||
import 'core-js/modules/es.symbol.async-iterator';
|
|
||||||
import 'core-js/modules/es.symbol.has-instance';
|
|
||||||
import 'core-js/modules/es.symbol.is-concat-spreadable';
|
|
||||||
import 'core-js/modules/es.symbol.iterator';
|
|
||||||
import 'core-js/modules/es.symbol.match';
|
|
||||||
import 'core-js/modules/es.symbol.match-all';
|
|
||||||
import 'core-js/modules/es.symbol.replace';
|
|
||||||
import 'core-js/modules/es.symbol.search';
|
|
||||||
import 'core-js/modules/es.symbol.species';
|
|
||||||
import 'core-js/modules/es.symbol.split';
|
|
||||||
import 'core-js/modules/es.symbol.to-primitive';
|
|
||||||
import 'core-js/modules/es.symbol.to-string-tag';
|
|
||||||
import 'core-js/modules/es.symbol.unscopables';
|
|
||||||
import 'core-js/modules/es.array.at';
|
|
||||||
import 'core-js/modules/es.array.concat';
|
|
||||||
import 'core-js/modules/es.array.copy-within';
|
|
||||||
import 'core-js/modules/es.array.every';
|
|
||||||
import 'core-js/modules/es.array.fill';
|
|
||||||
import 'core-js/modules/es.array.filter';
|
|
||||||
import 'core-js/modules/es.array.find';
|
|
||||||
import 'core-js/modules/es.array.find-index';
|
|
||||||
import 'core-js/modules/es.array.find-last';
|
|
||||||
import 'core-js/modules/es.array.find-last-index';
|
|
||||||
import 'core-js/modules/es.array.flat';
|
|
||||||
import 'core-js/modules/es.array.flat-map';
|
|
||||||
import 'core-js/modules/es.array.for-each';
|
|
||||||
import 'core-js/modules/es.array.from';
|
|
||||||
import 'core-js/modules/es.array.includes';
|
|
||||||
import 'core-js/modules/es.array.index-of';
|
|
||||||
import 'core-js/modules/es.array.is-array';
|
|
||||||
import 'core-js/modules/es.array.iterator';
|
|
||||||
import 'core-js/modules/es.array.join';
|
|
||||||
import 'core-js/modules/es.array.last-index-of';
|
|
||||||
import 'core-js/modules/es.array.map';
|
|
||||||
import 'core-js/modules/es.array.of';
|
|
||||||
import 'core-js/modules/es.array.push';
|
|
||||||
import 'core-js/modules/es.array.reduce';
|
|
||||||
import 'core-js/modules/es.array.reduce-right';
|
|
||||||
import 'core-js/modules/es.array.reverse';
|
|
||||||
import 'core-js/modules/es.array.slice';
|
|
||||||
import 'core-js/modules/es.array.some';
|
|
||||||
import 'core-js/modules/es.array.sort';
|
|
||||||
import 'core-js/modules/es.array.species';
|
|
||||||
import 'core-js/modules/es.array.splice';
|
|
||||||
import 'core-js/modules/es.array.to-reversed';
|
|
||||||
import 'core-js/modules/es.array.to-sorted';
|
|
||||||
import 'core-js/modules/es.array.to-spliced';
|
|
||||||
import 'core-js/modules/es.array.unscopables.flat';
|
|
||||||
import 'core-js/modules/es.array.unscopables.flat-map';
|
|
||||||
import 'core-js/modules/es.array.unshift';
|
|
||||||
import 'core-js/modules/es.array.with';
|
|
||||||
import 'core-js/modules/es.array-buffer.constructor';
|
|
||||||
import 'core-js/modules/es.array-buffer.is-view';
|
|
||||||
import 'core-js/modules/es.array-buffer.slice';
|
|
||||||
import 'core-js/modules/es.data-view';
|
|
||||||
import 'core-js/modules/es.date.get-year';
|
|
||||||
import 'core-js/modules/es.date.now';
|
|
||||||
import 'core-js/modules/es.date.set-year';
|
|
||||||
import 'core-js/modules/es.date.to-gmt-string';
|
|
||||||
import 'core-js/modules/es.date.to-iso-string';
|
|
||||||
import 'core-js/modules/es.date.to-json';
|
|
||||||
import 'core-js/modules/es.date.to-primitive';
|
|
||||||
import 'core-js/modules/es.date.to-string';
|
|
||||||
import 'core-js/modules/es.escape';
|
|
||||||
import 'core-js/modules/es.function.bind';
|
|
||||||
import 'core-js/modules/es.function.has-instance';
|
|
||||||
import 'core-js/modules/es.function.name';
|
|
||||||
import 'core-js/modules/es.global-this';
|
|
||||||
import 'core-js/modules/es.json.stringify';
|
|
||||||
import 'core-js/modules/es.json.to-string-tag';
|
|
||||||
import 'core-js/modules/es.map';
|
|
||||||
import 'core-js/modules/es.math.acosh';
|
|
||||||
import 'core-js/modules/es.math.asinh';
|
|
||||||
import 'core-js/modules/es.math.atanh';
|
|
||||||
import 'core-js/modules/es.math.cbrt';
|
|
||||||
import 'core-js/modules/es.math.clz32';
|
|
||||||
import 'core-js/modules/es.math.cosh';
|
|
||||||
import 'core-js/modules/es.math.expm1';
|
|
||||||
import 'core-js/modules/es.math.fround';
|
|
||||||
import 'core-js/modules/es.math.hypot';
|
|
||||||
import 'core-js/modules/es.math.imul';
|
|
||||||
import 'core-js/modules/es.math.log10';
|
|
||||||
import 'core-js/modules/es.math.log1p';
|
|
||||||
import 'core-js/modules/es.math.log2';
|
|
||||||
import 'core-js/modules/es.math.sign';
|
|
||||||
import 'core-js/modules/es.math.sinh';
|
|
||||||
import 'core-js/modules/es.math.tanh';
|
|
||||||
import 'core-js/modules/es.math.to-string-tag';
|
|
||||||
import 'core-js/modules/es.math.trunc';
|
|
||||||
import 'core-js/modules/es.number.constructor';
|
|
||||||
import 'core-js/modules/es.number.epsilon';
|
|
||||||
import 'core-js/modules/es.number.is-finite';
|
|
||||||
import 'core-js/modules/es.number.is-integer';
|
|
||||||
import 'core-js/modules/es.number.is-nan';
|
|
||||||
import 'core-js/modules/es.number.is-safe-integer';
|
|
||||||
import 'core-js/modules/es.number.max-safe-integer';
|
|
||||||
import 'core-js/modules/es.number.min-safe-integer';
|
|
||||||
import 'core-js/modules/es.number.parse-float';
|
|
||||||
import 'core-js/modules/es.number.parse-int';
|
|
||||||
import 'core-js/modules/es.number.to-exponential';
|
|
||||||
import 'core-js/modules/es.number.to-fixed';
|
|
||||||
import 'core-js/modules/es.number.to-precision';
|
|
||||||
import 'core-js/modules/es.object.assign';
|
|
||||||
import 'core-js/modules/es.object.create';
|
|
||||||
import 'core-js/modules/es.object.define-getter';
|
|
||||||
import 'core-js/modules/es.object.define-properties';
|
|
||||||
import 'core-js/modules/es.object.define-property';
|
|
||||||
import 'core-js/modules/es.object.define-setter';
|
|
||||||
import 'core-js/modules/es.object.entries';
|
|
||||||
import 'core-js/modules/es.object.freeze';
|
|
||||||
import 'core-js/modules/es.object.from-entries';
|
|
||||||
import 'core-js/modules/es.object.get-own-property-descriptor';
|
|
||||||
import 'core-js/modules/es.object.get-own-property-descriptors';
|
|
||||||
import 'core-js/modules/es.object.get-own-property-names';
|
|
||||||
import 'core-js/modules/es.object.get-prototype-of';
|
|
||||||
import 'core-js/modules/es.object.has-own';
|
|
||||||
import 'core-js/modules/es.object.is';
|
|
||||||
import 'core-js/modules/es.object.is-extensible';
|
|
||||||
import 'core-js/modules/es.object.is-frozen';
|
|
||||||
import 'core-js/modules/es.object.is-sealed';
|
|
||||||
import 'core-js/modules/es.object.keys';
|
|
||||||
import 'core-js/modules/es.object.lookup-getter';
|
|
||||||
import 'core-js/modules/es.object.lookup-setter';
|
|
||||||
import 'core-js/modules/es.object.prevent-extensions';
|
|
||||||
import 'core-js/modules/es.object.proto';
|
|
||||||
import 'core-js/modules/es.object.seal';
|
|
||||||
import 'core-js/modules/es.object.values';
|
|
||||||
import 'core-js/modules/es.parse-float';
|
|
||||||
import 'core-js/modules/es.parse-int';
|
|
||||||
import 'core-js/modules/es.promise';
|
|
||||||
import 'core-js/modules/es.promise.all-settled';
|
|
||||||
import 'core-js/modules/es.promise.any';
|
|
||||||
import 'core-js/modules/es.promise.finally';
|
|
||||||
import 'core-js/modules/es.reflect.apply';
|
|
||||||
import 'core-js/modules/es.reflect.construct';
|
|
||||||
import 'core-js/modules/es.reflect.define-property';
|
|
||||||
import 'core-js/modules/es.reflect.delete-property';
|
|
||||||
import 'core-js/modules/es.reflect.get';
|
|
||||||
import 'core-js/modules/es.reflect.get-own-property-descriptor';
|
|
||||||
import 'core-js/modules/es.reflect.get-prototype-of';
|
|
||||||
import 'core-js/modules/es.reflect.has';
|
|
||||||
import 'core-js/modules/es.reflect.is-extensible';
|
|
||||||
import 'core-js/modules/es.reflect.own-keys';
|
|
||||||
import 'core-js/modules/es.reflect.prevent-extensions';
|
|
||||||
import 'core-js/modules/es.reflect.set';
|
|
||||||
import 'core-js/modules/es.reflect.set-prototype-of';
|
|
||||||
import 'core-js/modules/es.reflect.to-string-tag';
|
|
||||||
import 'core-js/modules/es.regexp.constructor';
|
|
||||||
import 'core-js/modules/es.regexp.dot-all';
|
|
||||||
import 'core-js/modules/es.regexp.exec';
|
|
||||||
import 'core-js/modules/es.regexp.flags';
|
|
||||||
import 'core-js/modules/es.regexp.sticky';
|
|
||||||
import 'core-js/modules/es.regexp.test';
|
|
||||||
import 'core-js/modules/es.regexp.to-string';
|
|
||||||
import 'core-js/modules/es.set';
|
|
||||||
import 'core-js/modules/es.string.at-alternative';
|
|
||||||
import 'core-js/modules/es.string.code-point-at';
|
|
||||||
import 'core-js/modules/es.string.ends-with';
|
|
||||||
import 'core-js/modules/es.string.from-code-point';
|
|
||||||
import 'core-js/modules/es.string.includes';
|
|
||||||
import 'core-js/modules/es.string.is-well-formed';
|
|
||||||
import 'core-js/modules/es.string.iterator';
|
|
||||||
import 'core-js/modules/es.string.match';
|
|
||||||
import 'core-js/modules/es.string.match-all';
|
|
||||||
import 'core-js/modules/es.string.pad-end';
|
|
||||||
import 'core-js/modules/es.string.pad-start';
|
|
||||||
import 'core-js/modules/es.string.raw';
|
|
||||||
import 'core-js/modules/es.string.repeat';
|
|
||||||
import 'core-js/modules/es.string.replace';
|
|
||||||
import 'core-js/modules/es.string.replace-all';
|
|
||||||
import 'core-js/modules/es.string.search';
|
|
||||||
import 'core-js/modules/es.string.split';
|
|
||||||
import 'core-js/modules/es.string.starts-with';
|
|
||||||
import 'core-js/modules/es.string.substr';
|
|
||||||
import 'core-js/modules/es.string.to-well-formed';
|
|
||||||
import 'core-js/modules/es.string.trim';
|
|
||||||
import 'core-js/modules/es.string.trim-end';
|
|
||||||
import 'core-js/modules/es.string.trim-start';
|
|
||||||
import 'core-js/modules/es.string.anchor';
|
|
||||||
import 'core-js/modules/es.string.big';
|
|
||||||
import 'core-js/modules/es.string.blink';
|
|
||||||
import 'core-js/modules/es.string.bold';
|
|
||||||
import 'core-js/modules/es.string.fixed';
|
|
||||||
import 'core-js/modules/es.string.fontcolor';
|
|
||||||
import 'core-js/modules/es.string.fontsize';
|
|
||||||
import 'core-js/modules/es.string.italics';
|
|
||||||
import 'core-js/modules/es.string.link';
|
|
||||||
import 'core-js/modules/es.string.small';
|
|
||||||
import 'core-js/modules/es.string.strike';
|
|
||||||
import 'core-js/modules/es.string.sub';
|
|
||||||
import 'core-js/modules/es.string.sup';
|
|
||||||
import 'core-js/modules/es.typed-array.float32-array';
|
|
||||||
import 'core-js/modules/es.typed-array.float64-array';
|
|
||||||
import 'core-js/modules/es.typed-array.int8-array';
|
|
||||||
import 'core-js/modules/es.typed-array.int16-array';
|
|
||||||
import 'core-js/modules/es.typed-array.int32-array';
|
|
||||||
import 'core-js/modules/es.typed-array.uint8-array';
|
|
||||||
import 'core-js/modules/es.typed-array.uint8-clamped-array';
|
|
||||||
import 'core-js/modules/es.typed-array.uint16-array';
|
|
||||||
import 'core-js/modules/es.typed-array.uint32-array';
|
|
||||||
import 'core-js/modules/es.typed-array.at';
|
|
||||||
import 'core-js/modules/es.typed-array.copy-within';
|
|
||||||
import 'core-js/modules/es.typed-array.every';
|
|
||||||
import 'core-js/modules/es.typed-array.fill';
|
|
||||||
import 'core-js/modules/es.typed-array.filter';
|
|
||||||
import 'core-js/modules/es.typed-array.find';
|
|
||||||
import 'core-js/modules/es.typed-array.find-index';
|
|
||||||
import 'core-js/modules/es.typed-array.find-last';
|
|
||||||
import 'core-js/modules/es.typed-array.find-last-index';
|
|
||||||
import 'core-js/modules/es.typed-array.for-each';
|
|
||||||
import 'core-js/modules/es.typed-array.from';
|
|
||||||
import 'core-js/modules/es.typed-array.includes';
|
|
||||||
import 'core-js/modules/es.typed-array.index-of';
|
|
||||||
import 'core-js/modules/es.typed-array.iterator';
|
|
||||||
import 'core-js/modules/es.typed-array.join';
|
|
||||||
import 'core-js/modules/es.typed-array.last-index-of';
|
|
||||||
import 'core-js/modules/es.typed-array.map';
|
|
||||||
import 'core-js/modules/es.typed-array.of';
|
|
||||||
import 'core-js/modules/es.typed-array.reduce';
|
|
||||||
import 'core-js/modules/es.typed-array.reduce-right';
|
|
||||||
import 'core-js/modules/es.typed-array.reverse';
|
|
||||||
import 'core-js/modules/es.typed-array.set';
|
|
||||||
import 'core-js/modules/es.typed-array.slice';
|
|
||||||
import 'core-js/modules/es.typed-array.some';
|
|
||||||
import 'core-js/modules/es.typed-array.sort';
|
|
||||||
import 'core-js/modules/es.typed-array.subarray';
|
|
||||||
import 'core-js/modules/es.typed-array.to-locale-string';
|
|
||||||
import 'core-js/modules/es.typed-array.to-reversed';
|
|
||||||
import 'core-js/modules/es.typed-array.to-sorted';
|
|
||||||
import 'core-js/modules/es.typed-array.to-string';
|
|
||||||
import 'core-js/modules/es.typed-array.with';
|
|
||||||
import 'core-js/modules/es.unescape';
|
|
||||||
import 'core-js/modules/es.weak-map';
|
|
||||||
import 'core-js/modules/es.weak-set';
|
|
||||||
|
|
||||||
module.exports = require('core-js/internals/path');
|
|
||||||
@@ -7,7 +7,7 @@ console.i18n("ms.polyfill.initialize")
|
|||||||
import './openjdk-nashorn-shim'
|
import './openjdk-nashorn-shim'
|
||||||
import './es5-ext'
|
import './es5-ext'
|
||||||
import './node-shim'
|
import './node-shim'
|
||||||
import './core-js'
|
import 'core-js'
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
process.on('exit', () => require.disable())
|
process.on('exit', () => require.disable())
|
||||||
global.setGlobal('Proxy', require('./proxy').Proxy)
|
global.setGlobal('Proxy', require('./proxy').Proxy)
|
||||||
|
|||||||
@@ -18,17 +18,10 @@ const JavaScriptTask = Java.type(base.getJavaScriptTaskClass().name)
|
|||||||
const threadCount = new AtomicInteger(0)
|
const threadCount = new AtomicInteger(0)
|
||||||
const threadGroup = new ThreadGroup("@ccms/micro-task")
|
const threadGroup = new ThreadGroup("@ccms/micro-task")
|
||||||
const microTaskPool = new ThreadPoolExecutor(
|
const microTaskPool = new ThreadPoolExecutor(
|
||||||
16, 32, 64, TimeUnit.SECONDS,
|
100, 200, 60, TimeUnit.SECONDS,
|
||||||
new LinkedBlockingQueue(64),
|
new LinkedBlockingQueue(1024),
|
||||||
new ThreadFactory((run: any) => new Thread(threadGroup, run, "@ccms/micro-task-" + threadCount.incrementAndGet()))
|
new ThreadFactory((run: any) => new Thread(threadGroup, run, "@ccms/micro-task-" + threadCount.incrementAndGet()))
|
||||||
)
|
)
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface Function {
|
|
||||||
thread: any;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Process extends EventEmitter {
|
class Process extends EventEmitter {
|
||||||
readonly version = base.version
|
readonly version = base.version
|
||||||
readonly versions = []
|
readonly versions = []
|
||||||
@@ -52,13 +45,11 @@ class Process extends EventEmitter {
|
|||||||
execArgv = ''
|
execArgv = ''
|
||||||
execPath = ''
|
execPath = ''
|
||||||
|
|
||||||
private queueMicrotaskExecuteTimeout = 5000
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.on('exit', () => {
|
this.on('exit', () => {
|
||||||
console.log(`await microTaskPool termination! queueTask: ${microTaskPool.shutdownNow().size()} remainTask: ${threadGroup.activeCount()}`)
|
console.log(`await microTaskPool termination! queueTask: ${microTaskPool.shutdownNow().size()} remainTask: ${threadGroup.activeCount()}`)
|
||||||
microTaskPool.awaitTermination(this.queueMicrotaskExecuteTimeout, TimeUnit.MILLISECONDS)
|
microTaskPool.awaitTermination(3000, TimeUnit.MILLISECONDS)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
on(event: string | symbol, listener: (...args: any[]) => void) {
|
on(event: string | symbol, listener: (...args: any[]) => void) {
|
||||||
@@ -76,34 +67,18 @@ class Process extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
nextTick(callback: Function, ...args: any[]): void {
|
nextTick(callback: Function, ...args: any[]): void {
|
||||||
try {
|
microTaskPool.execute(() => {
|
||||||
microTaskPool.submit(new Callable({
|
try {
|
||||||
call: () => {
|
callback(args)
|
||||||
callback.thread = Thread.currentThread();
|
} catch (origin: any) {
|
||||||
try {
|
try {
|
||||||
callback(args)
|
super.emit('error', origin)
|
||||||
} catch (origin: any) {
|
} catch (error: any) {
|
||||||
try {
|
console.ex(origin)
|
||||||
super.emit('error', origin)
|
console.ex(error)
|
||||||
} catch (error: any) {
|
|
||||||
console.ex(origin)
|
|
||||||
console.ex(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})).get(this.queueMicrotaskExecuteTimeout, TimeUnit.MILLISECONDS)
|
|
||||||
} catch (error: any) {
|
|
||||||
if (error instanceof InterruptedException) {
|
|
||||||
return console.warn(`FixedThreadPool isInterrupted exit! Task ${callback.name || '<anonymous>'} exec exit!`)
|
|
||||||
}
|
}
|
||||||
if (error instanceof TimeoutException) {
|
})
|
||||||
if (callback.thread instanceof Thread) {
|
|
||||||
console.debug(console.stack(callback.thread as any))
|
|
||||||
}
|
|
||||||
return console.warn(`Task ${callback.name || '<anonymous>'} => ${callback} exec time greater than ${this.queueMicrotaskExecuteTimeout}ms!`)
|
|
||||||
}
|
|
||||||
throw error.getCause && error.getCause() || error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exit(code: number) {
|
exit(code: number) {
|
||||||
console.log(`process exit by code ${code}!`)
|
console.log(`process exit by code ${code}!`)
|
||||||
@@ -145,10 +120,12 @@ class Process extends EventEmitter {
|
|||||||
throw new Error('MiaoScript unsupport kill.')
|
throw new Error('MiaoScript unsupport kill.')
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
toString() {
|
||||||
|
return "[object process]"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EventLoop {
|
class EventLoop {
|
||||||
private threadCount = new AtomicInteger(0)
|
|
||||||
private eventLoopMainThread = undefined
|
private eventLoopMainThread = undefined
|
||||||
private eventLoopTaskQueue = new DelayQueue()
|
private eventLoopTaskQueue = new DelayQueue()
|
||||||
private taskExecuteTimeout = 3000
|
private taskExecuteTimeout = 3000
|
||||||
@@ -157,10 +134,10 @@ class EventLoop {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.taskExecuteTimeout = parseInt(process.env.MS_TASK_EXECUTE_TIMEOUT) || 3000
|
this.taskExecuteTimeout = parseInt(process.env.MS_TASK_EXECUTE_TIMEOUT) || 3000
|
||||||
this.fixedThreadPool = new ThreadPoolExecutor(
|
this.fixedThreadPool = new ThreadPoolExecutor(
|
||||||
4, 16, 32, TimeUnit.SECONDS,
|
1, 1, 0, TimeUnit.SECONDS,
|
||||||
new LinkedBlockingQueue(32),
|
new LinkedBlockingQueue(1024),
|
||||||
new ThreadFactory((run: any) => {
|
new ThreadFactory((run: any) => {
|
||||||
let thread = new Thread(run, "@ccms/event-loop-" + this.threadCount.incrementAndGet())
|
let thread = new Thread(run, "@ccms/event-loop")
|
||||||
thread.setDaemon(true)
|
thread.setDaemon(true)
|
||||||
return thread
|
return thread
|
||||||
}))
|
}))
|
||||||
@@ -196,7 +173,7 @@ class EventLoop {
|
|||||||
this.eventLoopMainThread.interrupt()
|
this.eventLoopMainThread.interrupt()
|
||||||
this.fixedThreadPool.shutdownNow()
|
this.fixedThreadPool.shutdownNow()
|
||||||
console.log(`await fixedThreadPool termination!`)
|
console.log(`await fixedThreadPool termination!`)
|
||||||
this.fixedThreadPool.awaitTermination(this.taskExecuteTimeout, TimeUnit.MILLISECONDS)
|
this.fixedThreadPool.awaitTermination(3000, TimeUnit.MILLISECONDS)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,11 +195,10 @@ class EventLoop {
|
|||||||
try {
|
try {
|
||||||
this.fixedThreadPool.submit(new Callable({
|
this.fixedThreadPool.submit(new Callable({
|
||||||
call: () => {
|
call: () => {
|
||||||
callback.thread = Thread.currentThread();
|
|
||||||
try {
|
try {
|
||||||
callback.apply(undefined, args)
|
callback.apply(undefined, args)
|
||||||
} catch (cause: any) {
|
} catch (cause: any) {
|
||||||
cause = cause.getCause ? cause.getCause() : cause
|
cause = cause.getCause && cause.getCause() || cause
|
||||||
try {
|
try {
|
||||||
process.emit('error', cause)
|
process.emit('error', cause)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -237,10 +213,7 @@ class EventLoop {
|
|||||||
return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`)
|
return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`)
|
||||||
}
|
}
|
||||||
if (error instanceof TimeoutException) {
|
if (error instanceof TimeoutException) {
|
||||||
if (callback.thread instanceof Thread) {
|
return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecuteTimeout}s!`)
|
||||||
console.debug(console.stack(callback.thread as any).join('\n'))
|
|
||||||
}
|
|
||||||
return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecuteTimeout}ms!`)
|
|
||||||
}
|
}
|
||||||
throw error.getCause && error.getCause() || error
|
throw error.getCause && error.getCause() || error
|
||||||
}
|
}
|
||||||
@@ -287,7 +260,7 @@ class EventLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
global.setGlobal('process', new Process(), {})
|
global.setGlobal('process', new Process(), {})
|
||||||
Object.defineProperty(process, require('core-js/es/symbol/to-string-tag'), { value: 'process' })
|
Object.defineProperty(process, require('core-js/es/symbol/to-string-tag'), { value: '[object process]' })
|
||||||
const eventLoop = new EventLoop()
|
const eventLoop = new EventLoop()
|
||||||
Object.defineProperty(process, 'eventLoop', { value: eventLoop })
|
Object.defineProperty(process, 'eventLoop', { value: eventLoop })
|
||||||
eventLoop.startEventLoop()
|
eventLoop.startEventLoop()
|
||||||
|
|||||||
1
packages/protocol/.npmignore
Symbolic link
1
packages/protocol/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/protocol",
|
"name": "@ccms/protocol",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript protocol package",
|
"description": "MiaoScript protocol package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -13,15 +13,15 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/qrcode/.npmignore
Symbolic link
1
packages/qrcode/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/qrcode",
|
"name": "@ccms/qrcode",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript qrcode package",
|
"description": "MiaoScript qrcode package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,15 +12,15 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
{
|
|
||||||
"private": true,
|
|
||||||
"name": "@ccms/runtime",
|
|
||||||
"version": "0.28.0-beta.11",
|
|
||||||
"description": "development runtime",
|
|
||||||
"keywords": [
|
|
||||||
"miaoscript",
|
|
||||||
"minecraft",
|
|
||||||
"bukkit",
|
|
||||||
"sponge"
|
|
||||||
],
|
|
||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
|
||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
|
||||||
"license": "ISC",
|
|
||||||
"main": "dist/index.js",
|
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
|
||||||
"clean": "rimraf dist",
|
|
||||||
"watch": "tsc --watch",
|
|
||||||
"build": "pnpm clean && tsc",
|
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@ccms/api": "workspace:*",
|
|
||||||
"@ccms/bukkit": "workspace:*",
|
|
||||||
"@ccms/bungee": "workspace:*",
|
|
||||||
"@ccms/common": "workspace:*",
|
|
||||||
"@ccms/container": "workspace:*",
|
|
||||||
"@ccms/core": "workspace:*",
|
|
||||||
"@ccms/database": "workspace:*",
|
|
||||||
"@ccms/i18n": "workspace:*",
|
|
||||||
"@ccms/molang": "workspace:*",
|
|
||||||
"@ccms/nashorn": "workspace:*",
|
|
||||||
"@ccms/nodejs": "workspace:*",
|
|
||||||
"@ccms/nukkit": "workspace:*",
|
|
||||||
"@ccms/plugin": "workspace:*",
|
|
||||||
"@ccms/polyfill": "workspace:*",
|
|
||||||
"@ccms/protocol": "workspace:*",
|
|
||||||
"@ccms/qrcode": "workspace:*",
|
|
||||||
"@ccms/sponge": "workspace:*",
|
|
||||||
"@ccms/websocket": "workspace:*"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1
packages/sponge/.npmignore
Symbolic link
1
packages/sponge/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/sponge",
|
"name": "@ccms/sponge",
|
||||||
"version": "0.28.0-beta.11",
|
"version": "0.27.4",
|
||||||
"description": "MiaoScript sponge package",
|
"description": "MiaoScript sponge package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,23 +12,21 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
|
||||||
"dist/**/*.js",
|
|
||||||
"dist/**/*.ts",
|
|
||||||
"dist/**/*.map"
|
|
||||||
],
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "pnpm clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/sponge-api": "^0.0.3"
|
"@javatypes/sponge-api": "^0.0.3",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "workspace:*",
|
"@ccms/api": "^0.27.4",
|
||||||
"@ccms/common": "workspace:*",
|
"@ccms/common": "^0.27.4",
|
||||||
"@ccms/container": "workspace:*"
|
"@ccms/container": "^0.27.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/spring/.npmignore
Symbolic link
1
packages/spring/.npmignore
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../.npmignore
|
||||||
32
packages/spring/package.json
Normal file
32
packages/spring/package.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"name": "@ccms/spring",
|
||||||
|
"version": "0.27.4",
|
||||||
|
"description": "MiaoScript spring package",
|
||||||
|
"keywords": [
|
||||||
|
"miaoscript",
|
||||||
|
"minecraft",
|
||||||
|
"bukkit",
|
||||||
|
"sponge"
|
||||||
|
],
|
||||||
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
|
"license": "ISC",
|
||||||
|
"main": "dist/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"clean": "rimraf dist",
|
||||||
|
"watch": "tsc --watch",
|
||||||
|
"build": "yarn clean && tsc",
|
||||||
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^4.1.2",
|
||||||
|
"typescript": "^4.9.5"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@ccms/api": "^0.27.4",
|
||||||
|
"@ccms/common": "^0.27.4",
|
||||||
|
"@ccms/container": "^0.27.4",
|
||||||
|
"@ccms/database": "^0.27.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
28
packages/spring/src/command.ts
Normal file
28
packages/spring/src/command.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import '@ccms/nashorn'
|
||||||
|
|
||||||
|
import { command, plugin } from '@ccms/api'
|
||||||
|
import { inject, provideSingleton, postConstruct } from '@ccms/container'
|
||||||
|
|
||||||
|
import { CommandMap } from './internal/command'
|
||||||
|
|
||||||
|
@provideSingleton(command.Command)
|
||||||
|
export class SpringCommand extends command.Command {
|
||||||
|
@inject(CommandMap)
|
||||||
|
private commandMap: CommandMap
|
||||||
|
|
||||||
|
protected create(plugin: any, command: string) {
|
||||||
|
return this.commandMap.register(plugin, command)
|
||||||
|
}
|
||||||
|
public tabComplete(sender: any, input: string, index?: number): string[] {
|
||||||
|
return this.commandMap.tabComplate(sender, input, index)
|
||||||
|
}
|
||||||
|
protected remove(plugin: any, command: string) {
|
||||||
|
this.commandMap.unregister(plugin, command)
|
||||||
|
}
|
||||||
|
protected onCommand(plugin: any, command: any, executor: Function) {
|
||||||
|
command.setExecutor(super.setExecutor(plugin, command, executor))
|
||||||
|
}
|
||||||
|
protected onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
||||||
|
command.setTabCompleter(super.setTabCompleter(plugin, command, tabCompleter))
|
||||||
|
}
|
||||||
|
}
|
||||||
58
packages/spring/src/console.ts
Normal file
58
packages/spring/src/console.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { MiaoScriptConsole } from '@ccms/api'
|
||||||
|
|
||||||
|
var colorMap = []
|
||||||
|
colorMap['0'] = '38;5;0'
|
||||||
|
colorMap['1'] = '38;5;4'
|
||||||
|
colorMap['2'] = '38;5;2'
|
||||||
|
colorMap['3'] = '38;5;6'
|
||||||
|
colorMap['4'] = '38;5;1'
|
||||||
|
colorMap['5'] = '38;5;5'
|
||||||
|
colorMap['6'] = '38;5;3'
|
||||||
|
colorMap['7'] = '38;5;7'
|
||||||
|
colorMap['8'] = '38;5;8'
|
||||||
|
colorMap['9'] = '38;5;12'
|
||||||
|
colorMap['a'] = '38;5;10'
|
||||||
|
colorMap['b'] = '38;5;14'
|
||||||
|
colorMap['c'] = '38;5;9'
|
||||||
|
colorMap['d'] = '38;5;13'
|
||||||
|
colorMap['e'] = '38;5;11'
|
||||||
|
colorMap['f'] = '38;5;15'
|
||||||
|
colorMap['r'] = '0'
|
||||||
|
colorMap['l'] = '1'
|
||||||
|
colorMap['n'] = '4'
|
||||||
|
var regexMap = []
|
||||||
|
for (const c in colorMap) {
|
||||||
|
regexMap[colorMap[c]] = new RegExp(`§${c}`, "g")
|
||||||
|
}
|
||||||
|
function mcColor2ANSI(str: string) {
|
||||||
|
for (const regex in regexMap) {
|
||||||
|
str = str.replace(regexMap[regex], `\u001b[${regex}m`)
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SpringConsole extends MiaoScriptConsole {
|
||||||
|
error(...args: any[]) {
|
||||||
|
this.logger.error(args.join(' '))
|
||||||
|
}
|
||||||
|
warn(...args: any[]) {
|
||||||
|
this.logger.warn(args.join(' '))
|
||||||
|
}
|
||||||
|
sender(sender: any, ...args: any[]) {
|
||||||
|
sender = sender || {
|
||||||
|
sendMessage: (message: string) => console.console(message)
|
||||||
|
}
|
||||||
|
if (!sender.sendMessage) {
|
||||||
|
this.error('第一个参数未实现 sendMessage 无法发送消息!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (Object.prototype.toString.call(args[0]) === '[object Array]') {
|
||||||
|
args[0].forEach(line => sender.sendMessage(this.prefix + line))
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(this.prefix + args.join(' '))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console(...args: string[]): void {
|
||||||
|
this.logger.info(mcColor2ANSI(args.join(' ') + '§r'))
|
||||||
|
}
|
||||||
|
}
|
||||||
24
packages/spring/src/event.ts
Normal file
24
packages/spring/src/event.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { event, plugin } from '@ccms/api'
|
||||||
|
import { inject, provideSingleton } from '@ccms/container'
|
||||||
|
|
||||||
|
@provideSingleton(event.Event)
|
||||||
|
export class SpringEvent extends event.Event {
|
||||||
|
@inject(plugin.PluginInstance)
|
||||||
|
private pluginInstance: any
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super('');
|
||||||
|
}
|
||||||
|
mapEventName() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
isValidEvent(clazz: any): boolean {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
register(eventCls: any, exec: Function, priority: any, ignoreCancel: boolean) {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
unregister(event: any, listener: any): void {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
}
|
||||||
30
packages/spring/src/index.ts
Normal file
30
packages/spring/src/index.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { server } from '@ccms/api'
|
||||||
|
import { ioc, Container, reduceMetadata } from '@ccms/container'
|
||||||
|
|
||||||
|
import { SpringConsole } from './console'
|
||||||
|
import './event'
|
||||||
|
import './server'
|
||||||
|
import './command'
|
||||||
|
import './task'
|
||||||
|
|
||||||
|
const toString = {}.toString
|
||||||
|
|
||||||
|
export default function SpringImpl(container: Container) {
|
||||||
|
try {
|
||||||
|
require('@ccms/web')
|
||||||
|
require('@ccms/amqp')
|
||||||
|
require('@ccms/database')
|
||||||
|
require('./internal/scanner/mysql-scanner')
|
||||||
|
} catch (error: any) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
const beanFactory = base.getInstance().getAutowireCapableBeanFactory()
|
||||||
|
container.bind(server.Console).toConstantValue(SpringConsole)
|
||||||
|
container.rebind(ioc.Autowired).toDynamicValue((ctx) => {
|
||||||
|
var metadata: any = reduceMetadata(ctx)
|
||||||
|
let key = toString.call(metadata.named)
|
||||||
|
if (key === "[object Function]" || key === "[object Symbol]") { return container.get(metadata.named) }
|
||||||
|
if (key === '[object jdk.internal.dynalink.beans.StaticClass]') { metadata.named = metadata.named.class }
|
||||||
|
return beanFactory.getBean(metadata.named)
|
||||||
|
})
|
||||||
|
}
|
||||||
79
packages/spring/src/internal/command.ts
Normal file
79
packages/spring/src/internal/command.ts
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import { provideSingleton } from "@ccms/container"
|
||||||
|
import { plugin } from "@ccms/api"
|
||||||
|
|
||||||
|
type CommandExec = (sender: any, _: any, command: string, args: string[]) => boolean
|
||||||
|
type TabCompleter = (sender: any, _: any, command: string, args: string[]) => string[]
|
||||||
|
type CommandStore = { [key: string]: SpringCommand }
|
||||||
|
|
||||||
|
@provideSingleton(CommandMap)
|
||||||
|
export class CommandMap {
|
||||||
|
private commands: CommandStore = {}
|
||||||
|
private pluginCommands: { [key: string]: CommandStore } = {}
|
||||||
|
|
||||||
|
register(plugin: plugin.Plugin, command: string) {
|
||||||
|
let springCommand = new SpringCommand(plugin, command)
|
||||||
|
this.commands[command] = springCommand
|
||||||
|
if (!this.pluginCommands[plugin.description.name]) { this.pluginCommands[plugin.description.name] = {} }
|
||||||
|
this.pluginCommands[plugin.description.name][command] = springCommand
|
||||||
|
return springCommand
|
||||||
|
}
|
||||||
|
|
||||||
|
unregister(plugin: plugin.Plugin, command: string) {
|
||||||
|
delete this.commands[command]
|
||||||
|
delete this.pluginCommands[plugin.description.name][command]
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(sender: any, command: string, args: string[]): boolean {
|
||||||
|
if (command === "help") {
|
||||||
|
sender.sendMessage('§e--------- §rHelp: Index §e---------------------------')
|
||||||
|
sender.sendMessage('Use /help [n] to get page n of help.')
|
||||||
|
for (const cmdName of Object.getOwnPropertyNames(this.commands)) {
|
||||||
|
sender.sendMessage(`§6/${cmdName}: §rA command provided by plugin §b${this.commands[cmdName].plugin.description.name}§r.`)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let exists = this.commands[command]
|
||||||
|
if (exists) {
|
||||||
|
try {
|
||||||
|
return exists.executor(sender, '', command, Java.to(args))
|
||||||
|
} catch (error: any) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
sender.sendMessage && sender.sendMessage(`Unknown command. Type "/help" for help.`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tabComplate(sender: any, input: string, index?: number): string[] {
|
||||||
|
if (index == 0) { return Object.keys(this.commands).concat('help') }
|
||||||
|
let [command, ...args] = input.split(' ')
|
||||||
|
let exists = this.commands[command]
|
||||||
|
if (exists && exists.tabCompleter) {
|
||||||
|
try {
|
||||||
|
if (args.length !== index) { args.push('') }
|
||||||
|
return exists.tabCompleter(sender, '', command, Java.to(args))
|
||||||
|
} catch (error: any) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SpringCommand {
|
||||||
|
public plugin: plugin.Plugin
|
||||||
|
public name: string
|
||||||
|
public executor: CommandExec
|
||||||
|
public tabCompleter: TabCompleter
|
||||||
|
|
||||||
|
constructor(plugin: plugin.Plugin, command: string, description: string = '暂无描述!') {
|
||||||
|
this.plugin = plugin
|
||||||
|
this.name = command
|
||||||
|
}
|
||||||
|
|
||||||
|
setExecutor = (executor: CommandExec) => this.executor = executor
|
||||||
|
setTabCompleter = (tabCompleter: TabCompleter) => this.tabCompleter = tabCompleter
|
||||||
|
toString = () => `SpringCommand(${this.name})`
|
||||||
|
}
|
||||||
48
packages/spring/src/internal/scanner/mysql-scanner.ts
Normal file
48
packages/spring/src/internal/scanner/mysql-scanner.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { plugin, database } from '@ccms/api'
|
||||||
|
import { DataBaseManager } from '@ccms/database'
|
||||||
|
import { provideSingleton, inject } from '@ccms/container'
|
||||||
|
|
||||||
|
import * as fs from '@ccms/common/dist/fs'
|
||||||
|
|
||||||
|
interface MySQLPlugin {
|
||||||
|
name: string
|
||||||
|
source: string
|
||||||
|
}
|
||||||
|
|
||||||
|
@provideSingleton(plugin.PluginScanner)
|
||||||
|
export class MySQLScanner implements plugin.PluginScanner {
|
||||||
|
type: string = "mysql"
|
||||||
|
|
||||||
|
private cacheDir = 'mysql-plugin-cache'
|
||||||
|
private cacheFileMap: Map<string, MySQLPlugin> = new Map()
|
||||||
|
private target: string
|
||||||
|
|
||||||
|
@inject(database.DataBaseManager)
|
||||||
|
private databaseManager: DataBaseManager
|
||||||
|
|
||||||
|
scan(target: any): plugin.PluginLoadMetadata[] {
|
||||||
|
this.target = target
|
||||||
|
let plugins = this.databaseManager.getMainDatabase().query<MySQLPlugin>(`SELECT name FROM ${this.target} WHERE LENGTH(source) != 0 AND deleted = 0`)
|
||||||
|
return plugins.map(p => this.read(p))
|
||||||
|
}
|
||||||
|
read(mysqlPlugin: MySQLPlugin): plugin.PluginLoadMetadata {
|
||||||
|
// if invoke this function from loadFromFile mysqlPlugin is a string need read from cache
|
||||||
|
if (typeof mysqlPlugin == "string") {
|
||||||
|
if (!this.cacheFileMap.has(mysqlPlugin)) { throw new Error(`this file ${mysqlPlugin} is not read from mysql-scanner. can't reload from this scanner!`) }
|
||||||
|
mysqlPlugin = this.cacheFileMap.get(mysqlPlugin)
|
||||||
|
}
|
||||||
|
let cacheFile = fs.concat(root, this.cacheDir, `${mysqlPlugin.name}.js`)
|
||||||
|
this.cacheFileMap.set(cacheFile, mysqlPlugin)
|
||||||
|
return { name: mysqlPlugin.name, file: cacheFile, type: this.type, mysqlPlugin, scanner: this }
|
||||||
|
}
|
||||||
|
load(metadata: plugin.PluginLoadMetadata) {
|
||||||
|
if (metadata.type !== this.type) { return }
|
||||||
|
var plugin: any = this.databaseManager.getMainDatabase().query<MySQLPlugin>(`SELECT source FROM ${this.target} WHERE name = ? AND deleted = 0`, metadata.name)
|
||||||
|
if (plugin.length == 0) { throw new Error(`[MySQLScanner] plugin ${metadata.name} not found at mysql database...`) }; plugin = plugin[0]
|
||||||
|
if (!plugin.source) { throw new Error(`[MySQLScanner] plugin ${metadata.name} source can\'t be undefiend or empty...`) }
|
||||||
|
base.save(metadata.file, plugin.source)
|
||||||
|
//@ts-ignore
|
||||||
|
metadata.instance = require(metadata.file, { cache: false })
|
||||||
|
return metadata
|
||||||
|
}
|
||||||
|
}
|
||||||
43
packages/spring/src/server.ts
Normal file
43
packages/spring/src/server.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { constants, server } from '@ccms/api'
|
||||||
|
import { provideSingleton, postConstruct, Autowired, Container, ContainerInstance } from '@ccms/container'
|
||||||
|
import { CommandMap } from './internal/command'
|
||||||
|
|
||||||
|
@provideSingleton(server.Server)
|
||||||
|
export class SpringServer extends server.Server {
|
||||||
|
@Autowired(ContainerInstance)
|
||||||
|
private container: Container
|
||||||
|
@Autowired()
|
||||||
|
private commandMap: CommandMap
|
||||||
|
|
||||||
|
private nettyPipeline = base.getInstance().getAutowireCapableBeanFactory()
|
||||||
|
private rootLogger = Packages.org.slf4j.LoggerFactory.getLogger("root") || global.logger
|
||||||
|
|
||||||
|
@postConstruct()
|
||||||
|
initialize() {
|
||||||
|
this.container.bind(constants.ServiceIdentifier.NettyPipeline).toConstantValue(this.nettyPipeline)
|
||||||
|
this.container.bind(constants.ServiceIdentifier.RootLogger).toConstantValue(this.rootLogger)
|
||||||
|
}
|
||||||
|
|
||||||
|
getVersion(): string {
|
||||||
|
return "SpringFramework"
|
||||||
|
}
|
||||||
|
getConsoleSender() {
|
||||||
|
return {
|
||||||
|
name: 'CONSOLE',
|
||||||
|
sendMessage: (message: string) => console.console(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dispatchCommand(sender: any, command: string): boolean {
|
||||||
|
let cmd_args = command.split(" ")
|
||||||
|
return this.commandMap.dispatch(sender, cmd_args.shift(), cmd_args || [])
|
||||||
|
}
|
||||||
|
dispatchConsoleCommand(command: string): boolean {
|
||||||
|
return this.dispatchCommand(this.getConsoleSender(), command)
|
||||||
|
}
|
||||||
|
getNettyPipeline() {
|
||||||
|
return this.nettyPipeline
|
||||||
|
}
|
||||||
|
getRootLogger() {
|
||||||
|
return this.rootLogger
|
||||||
|
}
|
||||||
|
}
|
||||||
95
packages/spring/src/task.ts
Normal file
95
packages/spring/src/task.ts
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
import { task, plugin } from '@ccms/api'
|
||||||
|
import { inject, provideSingleton } from '@ccms/container'
|
||||||
|
import thread_pool from '@ccms/common/dist/thread-pool'
|
||||||
|
|
||||||
|
const AtomicBoolean = Java.type("java.util.concurrent.atomic.AtomicBoolean")
|
||||||
|
const Thread = Java.type('java.lang.Thread')
|
||||||
|
|
||||||
|
@provideSingleton(task.TaskManager)
|
||||||
|
export class SpringTaskManager extends task.TaskManager {
|
||||||
|
@inject(plugin.PluginInstance)
|
||||||
|
private pluginInstance: any
|
||||||
|
|
||||||
|
private tasks: { [s: string]: task.Cancelable }
|
||||||
|
private executor: java.util.concurrent.ThreadPoolExecutor
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.tasks = {}
|
||||||
|
this.executor = thread_pool.create({
|
||||||
|
groupName: '@ccms/spring'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
create0(owner: plugin.Plugin, func: Function, id: number): task.Task {
|
||||||
|
return new SpringTask(owner, func, id, this)
|
||||||
|
}
|
||||||
|
callSyncMethod(func: Function): any {
|
||||||
|
return func()
|
||||||
|
}
|
||||||
|
disable0() {
|
||||||
|
Object.values(this.tasks).forEach((task) => task?.cancel())
|
||||||
|
this.executor.shutdown()
|
||||||
|
}
|
||||||
|
nextId() {
|
||||||
|
return this.taskId.incrementAndGet()
|
||||||
|
}
|
||||||
|
submit(id: number, task: SpringTask, func: Function) {
|
||||||
|
this.tasks[id] = task
|
||||||
|
this.executor.execute(func as any)
|
||||||
|
}
|
||||||
|
cancel(id: number) {
|
||||||
|
delete this.tasks[id]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SpringTask extends task.Task {
|
||||||
|
private id: number
|
||||||
|
private taskManager: SpringTaskManager
|
||||||
|
private running = new AtomicBoolean(true)
|
||||||
|
|
||||||
|
constructor(owner: plugin.Plugin, func: Function, id: number, taskManager: SpringTaskManager) {
|
||||||
|
super(owner, func, id)
|
||||||
|
this.id = taskManager.nextId()
|
||||||
|
this.taskManager = taskManager
|
||||||
|
}
|
||||||
|
|
||||||
|
run(...args: any[]) {
|
||||||
|
if (this.laterTime > 0) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(this.laterTime)
|
||||||
|
} catch (ex: any) {
|
||||||
|
Thread.currentThread().interrupt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (this.running.get()) {
|
||||||
|
try {
|
||||||
|
this.func(...args)
|
||||||
|
} catch (ex: any) {
|
||||||
|
console.error("Task exec error:", ex)
|
||||||
|
console.ex(ex)
|
||||||
|
}
|
||||||
|
// If we have a interval of 0 or less, only run once
|
||||||
|
if (this.interval <= 0) { break }
|
||||||
|
try {
|
||||||
|
Thread.sleep(this.interval)
|
||||||
|
} catch (ex: any) {
|
||||||
|
Thread.currentThread().interrupt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel0() {
|
||||||
|
var wasRunning = this.running.getAndSet(false)
|
||||||
|
if (wasRunning) {
|
||||||
|
this.taskManager.cancel(this.id)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
submit0(...args: any[]) {
|
||||||
|
this.taskManager.submit(this.id, this, () => this.run(...args))
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user