node-karin 0.6.20 → 0.6.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapter/input/index.js +5 -5
- package/lib/adapter/kritor/grpc.js +59 -59
- package/lib/adapter/onebot/11/convert.js +16 -17
- package/lib/adapter/onebot/11/event.js +21 -21
- package/lib/adapter/onebot/11/index.js +50 -52
- package/lib/cli/init.js +1 -20
- package/lib/cli/restart.js +10 -0
- package/lib/cli/start.d.ts +2 -0
- package/lib/cli/start.js +10 -0
- package/lib/cli/stop.d.ts +2 -0
- package/lib/cli/stop.js +10 -0
- package/lib/cli/up.d.ts +0 -0
- package/lib/cli/up.js +1 -0
- package/lib/core/init.js +8 -0
- package/lib/core/karin.js +2 -3
- package/lib/core/plugin.app.js +1 -2
- package/lib/core/plugin.js +1 -2
- package/lib/core/plugin.loader.d.ts +7 -16
- package/lib/core/plugin.loader.js +100 -146
- package/lib/core/process.js +3 -3
- package/lib/core/server.js +2 -5
- package/lib/event/notice.handler.js +16 -17
- package/lib/event/request.handler.js +3 -4
- package/lib/types/event/contact.d.ts +1 -1
- package/lib/types/event/contact.js +1 -13
- package/lib/types/event/event.d.ts +5 -5
- package/lib/types/event/event.js +1 -234
- package/lib/types/event/notice.js +1 -2
- package/lib/types/event/request.js +1 -2
- package/lib/types/event/sender.d.ts +2 -2
- package/lib/types/event/sender.js +1 -22
- package/lib/types/onebot11/api.d.ts +1 -1
- package/lib/types/onebot11/api.js +1 -54
- package/lib/types/onebot11/event.d.ts +5 -5
- package/lib/types/onebot11/event.js +1 -55
- package/lib/types/onebot11/params.d.ts +1 -1
- package/lib/types/onebot11/params.js +1 -7
- package/lib/types/onebot11/response.js +1 -1
- package/lib/types/onebot11/segment.d.ts +1 -1
- package/lib/types/onebot11/segment.js +1 -30
- package/lib/utils/common.d.ts +2 -3
- package/lib/utils/common.js +6 -6
- package/lib/utils/init.d.ts +1 -2
- package/lib/utils/init.js +25 -21
- package/package.json +12 -26
- package/lib/cli/postinstall.js +0 -25
- package/pnpm-workspace.yaml +0 -2
- /package/lib/cli/{postinstall.d.ts → restart.d.ts} +0 -0
package/lib/utils/init.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
import fs from 'fs'
|
|
3
2
|
import path from 'path'
|
|
4
3
|
import { exec } from 'child_process'
|
|
@@ -77,7 +76,7 @@ export class KarinInit {
|
|
|
77
76
|
})
|
|
78
77
|
})
|
|
79
78
|
/** 创建pnpm工作区配置 */
|
|
80
|
-
fs.
|
|
79
|
+
fs.writeFileSync('./pnpm-workspace.yaml', `packages:\n - 'plugins/**'\n`)
|
|
81
80
|
/** 为每个插件包创建统一存储的文件夹 */
|
|
82
81
|
const plugins = this.getPlugins()
|
|
83
82
|
const DataList = [
|
|
@@ -99,13 +98,23 @@ export class KarinInit {
|
|
|
99
98
|
modifyPackage () {
|
|
100
99
|
const pkg = this.readJson(path.join(karinDir, 'package.json'))
|
|
101
100
|
const projPkg = this.readJson('./package.json')
|
|
101
|
+
const main = 'node_modules/node-karin/lib/index.js'
|
|
102
102
|
delete pkg.bin
|
|
103
|
-
pkg.main =
|
|
104
|
-
pkg.
|
|
105
|
-
pkg.dependencies['kritor-proto'] = 'latest'
|
|
103
|
+
pkg.main = `./${main}`
|
|
104
|
+
pkg.types = `./${main.replace('.js', '.d.ts')}`
|
|
106
105
|
pkg.dependencies = { ...projPkg.dependencies, ...pkg.dependencies }
|
|
107
106
|
pkg.devDependencies = { ...projPkg.devDependencies, ...pkg.devDependencies }
|
|
108
|
-
|
|
107
|
+
projPkg.type = 'module'
|
|
108
|
+
projPkg.private = true
|
|
109
|
+
projPkg.main = `./${main}`
|
|
110
|
+
projPkg.dependencies = { ...projPkg.dependencies, ...pkg.dependencies }
|
|
111
|
+
projPkg.dependencies['node-karin'] = 'latest'
|
|
112
|
+
projPkg.dependencies['kritor-proto'] = 'latest'
|
|
113
|
+
if (!projPkg.scripts) { projPkg.scripts = {} }
|
|
114
|
+
if (!projPkg.devDependencies) { projPkg.devDependencies = {} }
|
|
115
|
+
projPkg.scripts.debug = `node --watch ${main}`
|
|
116
|
+
projPkg.scripts.dev = `tsx --watch ${main}`
|
|
117
|
+
fs.writeFileSync('./package.json', JSON.stringify(projPkg, null, 2))
|
|
109
118
|
}
|
|
110
119
|
|
|
111
120
|
/**
|
|
@@ -133,7 +142,7 @@ export class KarinInit {
|
|
|
133
142
|
*/
|
|
134
143
|
async install (type) {
|
|
135
144
|
/** 检查是否已经安装对应的包管理器 */
|
|
136
|
-
if (!this.shell(`${type} -v`)) {
|
|
145
|
+
if (!(await this.shell(`${type} -v`))) {
|
|
137
146
|
console.log(`检测到未安装${type},开始安装...`)
|
|
138
147
|
if (!await this.shell(`npm install -g ${type}`)) {
|
|
139
148
|
console.log(`${type}安装失败,请手动安装${type}!`)
|
|
@@ -146,7 +155,7 @@ export class KarinInit {
|
|
|
146
155
|
console.log('检测到已安装pnpm,开始安装依赖...')
|
|
147
156
|
}
|
|
148
157
|
/** 安装依赖 */
|
|
149
|
-
if (!this.shell(`${type}
|
|
158
|
+
if (!(await this.shell(`${type} -P --force`))) {
|
|
150
159
|
console.log('安装依赖失败,请手动安装依赖!')
|
|
151
160
|
console.log(`可尝试手动执行 【 ${type} install -P 】 安装依赖~`)
|
|
152
161
|
console.log('如中国大陆用户安装失败,请尝试执行换源 【 npm config set registry https://registry.npmmirror.com 】后再安装依赖~')
|
|
@@ -154,9 +163,9 @@ export class KarinInit {
|
|
|
154
163
|
console.log('依赖安装完成~')
|
|
155
164
|
}
|
|
156
165
|
/** 检查安装pm2 */
|
|
157
|
-
if (!this.shell('pm2 -v')) {
|
|
166
|
+
if (!(await this.shell('pm2 -v'))) {
|
|
158
167
|
console.log('检测到未安装pm2,开始安装pm2...')
|
|
159
|
-
if (!this.shell(`${type} install -g pm2`)) {
|
|
168
|
+
if (!(await this.shell(`${type} install -g pm2`))) {
|
|
160
169
|
console.log('安装pm2失败,请手动安装pm2!')
|
|
161
170
|
console.log('可尝试手动执行 【 npm install -g pm2 】 安装pm2~')
|
|
162
171
|
} else {
|
|
@@ -189,18 +198,13 @@ export class KarinInit {
|
|
|
189
198
|
}
|
|
190
199
|
|
|
191
200
|
/**
|
|
192
|
-
* 获取当前的包管理器
|
|
201
|
+
* 获取当前的包管理器 根据锁文件判断
|
|
193
202
|
*/
|
|
194
203
|
getRegistry () {
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
} else if (agent && agent.includes('yarn')) {
|
|
201
|
-
return 'yarn'
|
|
202
|
-
} else {
|
|
203
|
-
return 'npm'
|
|
204
|
-
}
|
|
204
|
+
if (fs.existsSync('./pnpm-lock')) { return 'pnpm' }
|
|
205
|
+
if (fs.existsSync('./yarn.lock')) { return 'yarn' }
|
|
206
|
+
if (fs.existsSync('./package-lock.json')) { return 'npm' }
|
|
207
|
+
// cnpm 没有锁文件
|
|
208
|
+
return 'cnpm'
|
|
205
209
|
}
|
|
206
210
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-karin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.22",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "基于 Kritor 进行开发的nodejs机器人框架",
|
|
6
6
|
"homepage": "https://github.com/KarinJS/Karin",
|
|
@@ -17,8 +17,14 @@
|
|
|
17
17
|
"main": "./lib/index.js",
|
|
18
18
|
"types": "./lib/index.d.ts",
|
|
19
19
|
"bin": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"app": "lib/index.js",
|
|
21
|
+
"debug": "lib/index.js",
|
|
22
|
+
"dev": "lib/index.js",
|
|
23
|
+
"init": "lib/cli/init.js",
|
|
24
|
+
"log": "lib/cli/log.js",
|
|
25
|
+
"rs": "lib/cli/restart.js",
|
|
26
|
+
"start": "lib/cli/start.js",
|
|
27
|
+
"stop": "lib/cli/stop.js"
|
|
22
28
|
},
|
|
23
29
|
"files": [
|
|
24
30
|
"/lib/**/*.js",
|
|
@@ -29,31 +35,18 @@
|
|
|
29
35
|
"modules.d.ts",
|
|
30
36
|
"LICENSE",
|
|
31
37
|
"package.json",
|
|
32
|
-
"README.md"
|
|
33
|
-
"pnpm-workspace.yaml"
|
|
38
|
+
"README.md"
|
|
34
39
|
],
|
|
35
40
|
"workspaces": [
|
|
36
41
|
"plugins/**"
|
|
37
42
|
],
|
|
38
43
|
"scripts": {
|
|
39
|
-
"app": "node .",
|
|
40
44
|
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && npm run cp && npm run fix",
|
|
41
45
|
"cp": "cp ./lib/modules.d.ts ./modules.d.ts && cp ./lib/modules.js ./modules.js",
|
|
42
|
-
"debug": "node . --dev",
|
|
43
|
-
"delete": "pm2 delete ./config/config/pm2.yaml",
|
|
44
|
-
"dev": "tsx ./lib/index.js --dev",
|
|
45
46
|
"fix": "eslint lib/**/*.js --fix",
|
|
46
|
-
"fix:all": "eslint lib/**/*.js --fix && eslint lib/**/*.ts --fix",
|
|
47
|
-
"hook": "node lib/cli/hook.js",
|
|
48
|
-
"init": "node lib/cli/install.js",
|
|
49
|
-
"postinstall": "node lib/cli/postinstall.js",
|
|
50
|
-
"log": "node lib/cli/log.js",
|
|
51
|
-
"monit": "pm2 monit",
|
|
47
|
+
"fix:all": "eslint lib/**/*.js --fix && eslint lib/**/*.d.ts --fix",
|
|
52
48
|
"pub": "npm publish --access public",
|
|
53
|
-
"
|
|
54
|
-
"sort:pack": "npx sort-package-json",
|
|
55
|
-
"start": "pm2 start ./config/config/pm2.yaml && pm2 monit",
|
|
56
|
-
"stop": "pm2 delete ./config/config/pm2.yaml"
|
|
49
|
+
"sort": "npx sort-package-json"
|
|
57
50
|
},
|
|
58
51
|
"dependencies": {
|
|
59
52
|
"@grpc/grpc-js": "1.10.10",
|
|
@@ -87,13 +80,6 @@
|
|
|
87
80
|
"tsx": "latest",
|
|
88
81
|
"typescript": "latest"
|
|
89
82
|
},
|
|
90
|
-
"bundledDependencies": [
|
|
91
|
-
"@types/express",
|
|
92
|
-
"@types/lodash",
|
|
93
|
-
"@types/node",
|
|
94
|
-
"@types/node-schedule",
|
|
95
|
-
"@types/ws"
|
|
96
|
-
],
|
|
97
83
|
"engines": {
|
|
98
84
|
"node": ">=18"
|
|
99
85
|
},
|
package/lib/cli/postinstall.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'fs'
|
|
3
|
-
import { KarinInit } from '../utils/init.js'
|
|
4
|
-
async function main () {
|
|
5
|
-
/** 捕获错误 打印日志 */
|
|
6
|
-
process.on('uncaughtException', err => console.error(err))
|
|
7
|
-
process.on('unhandledRejection', err => console.error(err))
|
|
8
|
-
/** 在src目录说明为开发环境 不执行任何初始化操作 */
|
|
9
|
-
if (fs.existsSync('./src')) { return }
|
|
10
|
-
const init = new KarinInit()
|
|
11
|
-
init.init()
|
|
12
|
-
/** 判断锁文件 优先度: pnpm > yarn > cnpm > npm */
|
|
13
|
-
let pkg
|
|
14
|
-
if (fs.existsSync('pnpm-lock.yaml')) {
|
|
15
|
-
pkg = 'pnpm'
|
|
16
|
-
} else if (fs.existsSync('yarn.lock')) {
|
|
17
|
-
pkg = 'yarn'
|
|
18
|
-
} else if (fs.existsSync('cnpm-lock.yaml')) {
|
|
19
|
-
pkg = 'cnpm'
|
|
20
|
-
} else {
|
|
21
|
-
pkg = 'npm'
|
|
22
|
-
}
|
|
23
|
-
await init.install(pkg)
|
|
24
|
-
}
|
|
25
|
-
main().then(() => process.exit(0)).catch(() => process.exit(0))
|
package/pnpm-workspace.yaml
DELETED
|
File without changes
|