node-karin 0.6.21 → 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.
Files changed (48) hide show
  1. package/lib/adapter/input/index.js +5 -5
  2. package/lib/adapter/kritor/grpc.js +59 -59
  3. package/lib/adapter/onebot/11/convert.js +16 -17
  4. package/lib/adapter/onebot/11/event.js +21 -21
  5. package/lib/adapter/onebot/11/index.js +50 -52
  6. package/lib/cli/init.js +1 -20
  7. package/lib/cli/restart.js +10 -0
  8. package/lib/cli/start.d.ts +2 -0
  9. package/lib/cli/start.js +10 -0
  10. package/lib/cli/stop.d.ts +2 -0
  11. package/lib/cli/stop.js +10 -0
  12. package/lib/cli/up.d.ts +0 -0
  13. package/lib/cli/up.js +1 -0
  14. package/lib/core/init.js +8 -0
  15. package/lib/core/karin.js +2 -3
  16. package/lib/core/plugin.app.js +1 -2
  17. package/lib/core/plugin.js +1 -2
  18. package/lib/core/plugin.loader.d.ts +7 -16
  19. package/lib/core/plugin.loader.js +100 -146
  20. package/lib/core/process.js +3 -3
  21. package/lib/core/server.js +2 -5
  22. package/lib/event/notice.handler.js +16 -17
  23. package/lib/event/request.handler.js +3 -4
  24. package/lib/types/event/contact.d.ts +1 -1
  25. package/lib/types/event/contact.js +1 -13
  26. package/lib/types/event/event.d.ts +5 -5
  27. package/lib/types/event/event.js +1 -234
  28. package/lib/types/event/notice.js +1 -2
  29. package/lib/types/event/request.js +1 -2
  30. package/lib/types/event/sender.d.ts +2 -2
  31. package/lib/types/event/sender.js +1 -22
  32. package/lib/types/onebot11/api.d.ts +1 -1
  33. package/lib/types/onebot11/api.js +1 -54
  34. package/lib/types/onebot11/event.d.ts +5 -5
  35. package/lib/types/onebot11/event.js +1 -55
  36. package/lib/types/onebot11/params.d.ts +1 -1
  37. package/lib/types/onebot11/params.js +1 -7
  38. package/lib/types/onebot11/response.js +1 -1
  39. package/lib/types/onebot11/segment.d.ts +1 -1
  40. package/lib/types/onebot11/segment.js +1 -30
  41. package/lib/utils/common.d.ts +2 -3
  42. package/lib/utils/common.js +6 -6
  43. package/lib/utils/init.d.ts +1 -1
  44. package/lib/utils/init.js +25 -20
  45. package/package.json +11 -22
  46. package/lib/cli/postinstall.js +0 -25
  47. package/pnpm-workspace.yaml +0 -2
  48. /package/lib/cli/{postinstall.d.ts → restart.d.ts} +0 -0
package/lib/utils/init.js CHANGED
@@ -76,7 +76,7 @@ export class KarinInit {
76
76
  })
77
77
  })
78
78
  /** 创建pnpm工作区配置 */
79
- fs.copyFileSync(path.join(karinDir, 'pnpm-workspace.yaml'), './pnpm-workspace.yaml')
79
+ fs.writeFileSync('./pnpm-workspace.yaml', `packages:\n - 'plugins/**'\n`)
80
80
  /** 为每个插件包创建统一存储的文件夹 */
81
81
  const plugins = this.getPlugins()
82
82
  const DataList = [
@@ -98,13 +98,23 @@ export class KarinInit {
98
98
  modifyPackage () {
99
99
  const pkg = this.readJson(path.join(karinDir, 'package.json'))
100
100
  const projPkg = this.readJson('./package.json')
101
+ const main = 'node_modules/node-karin/lib/index.js'
101
102
  delete pkg.bin
102
- pkg.main = './node_modules/node-karin/lib/index.js'
103
- pkg.dependencies['node-karin'] = 'latest'
104
- pkg.dependencies['kritor-proto'] = 'latest'
103
+ pkg.main = `./${main}`
104
+ pkg.types = `./${main.replace('.js', '.d.ts')}`
105
105
  pkg.dependencies = { ...projPkg.dependencies, ...pkg.dependencies }
106
106
  pkg.devDependencies = { ...projPkg.devDependencies, ...pkg.devDependencies }
107
- fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2))
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))
108
118
  }
109
119
 
110
120
  /**
@@ -132,7 +142,7 @@ export class KarinInit {
132
142
  */
133
143
  async install (type) {
134
144
  /** 检查是否已经安装对应的包管理器 */
135
- if (!this.shell(`${type} -v`)) {
145
+ if (!(await this.shell(`${type} -v`))) {
136
146
  console.log(`检测到未安装${type},开始安装...`)
137
147
  if (!await this.shell(`npm install -g ${type}`)) {
138
148
  console.log(`${type}安装失败,请手动安装${type}!`)
@@ -145,7 +155,7 @@ export class KarinInit {
145
155
  console.log('检测到已安装pnpm,开始安装依赖...')
146
156
  }
147
157
  /** 安装依赖 */
148
- if (!this.shell(`${type} install -P`)) {
158
+ if (!(await this.shell(`${type} -P --force`))) {
149
159
  console.log('安装依赖失败,请手动安装依赖!')
150
160
  console.log(`可尝试手动执行 【 ${type} install -P 】 安装依赖~`)
151
161
  console.log('如中国大陆用户安装失败,请尝试执行换源 【 npm config set registry https://registry.npmmirror.com 】后再安装依赖~')
@@ -153,9 +163,9 @@ export class KarinInit {
153
163
  console.log('依赖安装完成~')
154
164
  }
155
165
  /** 检查安装pm2 */
156
- if (!this.shell('pm2 -v')) {
166
+ if (!(await this.shell('pm2 -v'))) {
157
167
  console.log('检测到未安装pm2,开始安装pm2...')
158
- if (!this.shell(`${type} install -g pm2`)) {
168
+ if (!(await this.shell(`${type} install -g pm2`))) {
159
169
  console.log('安装pm2失败,请手动安装pm2!')
160
170
  console.log('可尝试手动执行 【 npm install -g pm2 】 安装pm2~')
161
171
  } else {
@@ -188,18 +198,13 @@ export class KarinInit {
188
198
  }
189
199
 
190
200
  /**
191
- * 获取当前的包管理器
201
+ * 获取当前的包管理器 根据锁文件判断
192
202
  */
193
203
  getRegistry () {
194
- const { npm_config_user_agent: agent, npm_config_userconfig: userconfig } = process.env
195
- if (agent && agent.includes('pnpm')) {
196
- return 'pnpm'
197
- } else if (userconfig && userconfig.includes('cnpm')) {
198
- return 'cnpm'
199
- } else if (agent && agent.includes('yarn')) {
200
- return 'yarn'
201
- } else {
202
- return 'npm'
203
- }
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'
204
209
  }
205
210
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-karin",
3
- "version": "0.6.21",
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
+ "app": "lib/index.js",
21
+ "debug": "lib/index.js",
22
+ "dev": "lib/index.js",
20
23
  "init": "lib/cli/init.js",
21
- "log": "lib/cli/log.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,28 +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
- "log": "node lib/cli/log.js",
48
- "monit": "pm2 monit",
47
+ "fix:all": "eslint lib/**/*.js --fix && eslint lib/**/*.d.ts --fix",
49
48
  "pub": "npm publish --access public",
50
- "restart": "pm2 restart ./config/config/pm2.yaml",
51
- "sort:pack": "npx sort-package-json",
52
- "start": "pm2 start ./config/config/pm2.yaml && pm2 monit",
53
- "stop": "pm2 delete ./config/config/pm2.yaml"
49
+ "sort": "npx sort-package-json"
54
50
  },
55
51
  "dependencies": {
56
52
  "@grpc/grpc-js": "1.10.10",
@@ -84,13 +80,6 @@
84
80
  "tsx": "latest",
85
81
  "typescript": "latest"
86
82
  },
87
- "bundledDependencies": [
88
- "@types/express",
89
- "@types/lodash",
90
- "@types/node",
91
- "@types/node-schedule",
92
- "@types/ws"
93
- ],
94
83
  "engines": {
95
84
  "node": ">=18"
96
85
  },
@@ -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))
@@ -1,2 +0,0 @@
1
- packages:
2
- - 'plugins/**'
File without changes