node-karin 0.12.0 → 0.12.2-5.pr.206.027f2f2

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 (254) hide show
  1. package/CHANGELOG.md +1029 -0
  2. package/default/comment/config.json +34 -0
  3. package/default/comment/friendDirect.json +10 -0
  4. package/default/comment/groupGuild.json +11 -0
  5. package/default/comment/server.json +17 -0
  6. package/default/config/adapter.json +28 -0
  7. package/default/config/config.json +47 -0
  8. package/default/config/groups.json +47 -0
  9. package/default/config/groups.yaml +70 -0
  10. package/default/config/pm2.json +16 -0
  11. package/default/config/privates.json +23 -0
  12. package/default/config/privates.yaml +31 -0
  13. package/default/config/redis.json +10 -0
  14. package/default/config/render.json +19 -0
  15. package/default/view/group.yaml +73 -0
  16. package/dist/index.d.ts +9869 -0
  17. package/dist/index.js +12643 -0
  18. package/dist/module/art-template.cjs +11 -0
  19. package/dist/module/art-template.d.ts +1 -0
  20. package/dist/module/axios.cjs +22 -0
  21. package/dist/module/axios.d.ts +2 -0
  22. package/dist/module/chalk.cjs +22 -0
  23. package/dist/module/chalk.d.ts +2 -0
  24. package/dist/module/chokidar.cjs +22 -0
  25. package/dist/module/chokidar.d.ts +2 -0
  26. package/dist/module/commander.cjs +35 -0
  27. package/dist/module/commander.d.ts +3 -0
  28. package/dist/module/commander.js +3 -0
  29. package/dist/module/dotenv.cjs +22 -0
  30. package/dist/module/dotenv.d.ts +2 -0
  31. package/dist/module/dotenv.js +2 -0
  32. package/dist/module/express.cjs +112 -0
  33. package/dist/module/express.d.ts +1 -0
  34. package/dist/module/express.js +1 -0
  35. package/dist/module/level.cjs +22 -0
  36. package/dist/module/level.d.ts +2 -0
  37. package/dist/module/lodash.cjs +11 -0
  38. package/dist/module/lodash.d.ts +1 -0
  39. package/dist/module/log4js.cjs +22 -0
  40. package/dist/module/log4js.d.ts +2 -0
  41. package/dist/module/moment.cjs +11 -0
  42. package/dist/module/moment.d.ts +1 -0
  43. package/dist/module/node-schedule.cjs +22 -0
  44. package/dist/module/node-schedule.d.ts +2 -0
  45. package/dist/module/redis.cjs +22 -0
  46. package/dist/module/redis.d.ts +2 -0
  47. package/dist/module/ws.cjs +28 -0
  48. package/dist/module/ws.d.ts +1 -0
  49. package/dist/module/ws.js +1 -0
  50. package/dist/module/yaml.cjs +22 -0
  51. package/dist/module/yaml.d.ts +2 -0
  52. package/dist/root.d.ts +40 -0
  53. package/dist/root.js +44 -0
  54. package/package.json +142 -128
  55. package/LICENSE +0 -674
  56. package/README.md +0 -56
  57. package/config/defSet/App.yaml +0 -42
  58. package/config/defSet/config.yaml +0 -65
  59. package/config/defSet/group.yaml +0 -56
  60. package/config/defSet/pm2.yaml +0 -21
  61. package/config/defSet/redis.yaml +0 -18
  62. package/config/defSet/server.yaml +0 -42
  63. package/config/view/group.yaml +0 -92
  64. package/lib/adapter/index.d.ts +0 -2
  65. package/lib/adapter/index.js +0 -2
  66. package/lib/adapter/input/index.d.ts +0 -78
  67. package/lib/adapter/input/index.js +0 -205
  68. package/lib/adapter/onebot/11/convert.d.ts +0 -12
  69. package/lib/adapter/onebot/11/convert.js +0 -167
  70. package/lib/adapter/onebot/11/event.d.ts +0 -25
  71. package/lib/adapter/onebot/11/event.js +0 -442
  72. package/lib/adapter/onebot/11/index.d.ts +0 -508
  73. package/lib/adapter/onebot/11/index.js +0 -1047
  74. package/lib/cli/index.d.ts +0 -92
  75. package/lib/cli/index.js +0 -307
  76. package/lib/cli/init.d.ts +0 -2
  77. package/lib/cli/init.js +0 -22
  78. package/lib/cli/karin.d.ts +0 -2
  79. package/lib/cli/karin.js +0 -16
  80. package/lib/cli/pkg.d.ts +0 -4
  81. package/lib/cli/pkg.js +0 -14
  82. package/lib/cli/start.d.ts +0 -1
  83. package/lib/cli/start.js +0 -8
  84. package/lib/core/index.d.ts +0 -10
  85. package/lib/core/index.js +0 -10
  86. package/lib/core/init/config.d.ts +0 -43
  87. package/lib/core/init/config.js +0 -201
  88. package/lib/core/init/dir.d.ts +0 -4
  89. package/lib/core/init/dir.js +0 -7
  90. package/lib/core/init/init.d.ts +0 -1
  91. package/lib/core/init/init.js +0 -47
  92. package/lib/core/karin/karin.d.ts +0 -198
  93. package/lib/core/karin/karin.js +0 -226
  94. package/lib/core/listener/listener.d.ts +0 -145
  95. package/lib/core/listener/listener.js +0 -235
  96. package/lib/core/plugin/base.d.ts +0 -156
  97. package/lib/core/plugin/base.js +0 -131
  98. package/lib/core/plugin/loader.d.ts +0 -141
  99. package/lib/core/plugin/loader.js +0 -618
  100. package/lib/core/process/process.d.ts +0 -18
  101. package/lib/core/process/process.js +0 -96
  102. package/lib/core/server/server.d.ts +0 -25
  103. package/lib/core/server/server.js +0 -295
  104. package/lib/db/index.d.ts +0 -2
  105. package/lib/db/index.js +0 -2
  106. package/lib/db/level/level.d.ts +0 -19
  107. package/lib/db/level/level.js +0 -36
  108. package/lib/db/redis/redis.d.ts +0 -2
  109. package/lib/db/redis/redis.js +0 -135
  110. package/lib/db/redis/redis_level.d.ts +0 -112
  111. package/lib/db/redis/redis_level.js +0 -281
  112. package/lib/event/handler/base.d.ts +0 -42
  113. package/lib/event/handler/base.js +0 -200
  114. package/lib/event/handler/message.d.ts +0 -29
  115. package/lib/event/handler/message.js +0 -307
  116. package/lib/event/handler/notice.d.ts +0 -18
  117. package/lib/event/handler/notice.js +0 -214
  118. package/lib/event/handler/request.d.ts +0 -18
  119. package/lib/event/handler/request.js +0 -115
  120. package/lib/event/handler/review.d.ts +0 -55
  121. package/lib/event/handler/review.js +0 -386
  122. package/lib/event/index.d.ts +0 -5
  123. package/lib/event/index.js +0 -5
  124. package/lib/index.d.ts +0 -8
  125. package/lib/index.js +0 -8
  126. package/lib/modules/art-template.d.ts +0 -1
  127. package/lib/modules/axios.d.ts +0 -2
  128. package/lib/modules/chalk.d.ts +0 -2
  129. package/lib/modules/chokidar.d.ts +0 -2
  130. package/lib/modules/commander.d.ts +0 -2
  131. package/lib/modules/commander.js +0 -2
  132. package/lib/modules/express.d.ts +0 -3
  133. package/lib/modules/express.js +0 -3
  134. package/lib/modules/level.d.ts +0 -2
  135. package/lib/modules/lodash.d.ts +0 -1
  136. package/lib/modules/log4js.d.ts +0 -2
  137. package/lib/modules/moment.d.ts +0 -1
  138. package/lib/modules/node-schedule.d.ts +0 -2
  139. package/lib/modules/redis.d.ts +0 -2
  140. package/lib/modules/ws.d.ts +0 -3
  141. package/lib/modules/ws.js +0 -3
  142. package/lib/modules/yaml.d.ts +0 -2
  143. package/lib/modules.d.ts +0 -15
  144. package/lib/modules.js +0 -15
  145. package/lib/render/app.d.ts +0 -56
  146. package/lib/render/app.js +0 -120
  147. package/lib/render/base.d.ts +0 -30
  148. package/lib/render/base.js +0 -69
  149. package/lib/render/client.d.ts +0 -41
  150. package/lib/render/client.js +0 -238
  151. package/lib/render/http.d.ts +0 -19
  152. package/lib/render/http.js +0 -50
  153. package/lib/render/index.d.ts +0 -6
  154. package/lib/render/index.js +0 -6
  155. package/lib/render/server.d.ts +0 -25
  156. package/lib/render/server.js +0 -101
  157. package/lib/render/wormhole.d.ts +0 -1
  158. package/lib/render/wormhole.js +0 -156
  159. package/lib/types/adapter/api.d.ts +0 -399
  160. package/lib/types/adapter/api.js +0 -1
  161. package/lib/types/adapter/base.d.ts +0 -560
  162. package/lib/types/adapter/base.js +0 -1
  163. package/lib/types/config/config.d.ts +0 -379
  164. package/lib/types/config/config.js +0 -1
  165. package/lib/types/element/element.d.ts +0 -565
  166. package/lib/types/element/element.js +0 -1
  167. package/lib/types/element/qqbot.d.ts +0 -123
  168. package/lib/types/element/qqbot.js +0 -1
  169. package/lib/types/event/contact.d.ts +0 -28
  170. package/lib/types/event/contact.js +0 -1
  171. package/lib/types/event/event.d.ts +0 -305
  172. package/lib/types/event/event.js +0 -1
  173. package/lib/types/event/index.d.ts +0 -12
  174. package/lib/types/event/index.js +0 -7
  175. package/lib/types/event/message.d.ts +0 -109
  176. package/lib/types/event/message.js +0 -74
  177. package/lib/types/event/notice.d.ts +0 -513
  178. package/lib/types/event/notice.js +0 -52
  179. package/lib/types/event/reply.d.ts +0 -50
  180. package/lib/types/event/reply.js +0 -1
  181. package/lib/types/event/request.d.ts +0 -126
  182. package/lib/types/event/request.js +0 -52
  183. package/lib/types/event/sender.d.ts +0 -44
  184. package/lib/types/event/sender.js +0 -1
  185. package/lib/types/index.d.ts +0 -13
  186. package/lib/types/index.js +0 -13
  187. package/lib/types/logger/logger.d.ts +0 -110
  188. package/lib/types/logger/logger.js +0 -1
  189. package/lib/types/onebot11/api.d.ts +0 -53
  190. package/lib/types/onebot11/api.js +0 -1
  191. package/lib/types/onebot11/event.d.ts +0 -619
  192. package/lib/types/onebot11/event.js +0 -2
  193. package/lib/types/onebot11/index.d.ts +0 -6
  194. package/lib/types/onebot11/index.js +0 -6
  195. package/lib/types/onebot11/params.d.ts +0 -609
  196. package/lib/types/onebot11/params.js +0 -1
  197. package/lib/types/onebot11/response.d.ts +0 -516
  198. package/lib/types/onebot11/response.js +0 -1
  199. package/lib/types/onebot11/segment.d.ts +0 -269
  200. package/lib/types/onebot11/segment.js +0 -1
  201. package/lib/types/onebot11/sender.d.ts +0 -59
  202. package/lib/types/onebot11/sender.js +0 -1
  203. package/lib/types/plugin/app.d.ts +0 -71
  204. package/lib/types/plugin/app.js +0 -1
  205. package/lib/types/plugin/plugin.d.ts +0 -473
  206. package/lib/types/plugin/plugin.js +0 -1
  207. package/lib/types/render/render.d.ts +0 -118
  208. package/lib/types/render/render.js +0 -1
  209. package/lib/types/type/global.d.ts +0 -25
  210. package/lib/types/type/global.js +0 -1
  211. package/lib/utils/common/common.d.ts +0 -236
  212. package/lib/utils/common/common.js +0 -708
  213. package/lib/utils/config/config.d.ts +0 -193
  214. package/lib/utils/config/config.js +0 -328
  215. package/lib/utils/config/updateVersion.d.ts +0 -33
  216. package/lib/utils/config/updateVersion.js +0 -145
  217. package/lib/utils/config/yamlEditor.d.ts +0 -101
  218. package/lib/utils/config/yamlEditor.js +0 -330
  219. package/lib/utils/core/handler.d.ts +0 -18
  220. package/lib/utils/core/handler.js +0 -46
  221. package/lib/utils/core/logger.d.ts +0 -3
  222. package/lib/utils/core/logger.js +0 -105
  223. package/lib/utils/core/segment.d.ts +0 -279
  224. package/lib/utils/core/segment.js +0 -451
  225. package/lib/utils/index.d.ts +0 -13
  226. package/lib/utils/index.js +0 -13
  227. package/lib/utils/tools/button.d.ts +0 -2
  228. package/lib/utils/tools/button.js +0 -27
  229. package/lib/utils/tools/exec.d.ts +0 -20
  230. package/lib/utils/tools/exec.js +0 -54
  231. package/lib/utils/tools/ffmpeg.d.ts +0 -12
  232. package/lib/utils/tools/ffmpeg.js +0 -25
  233. package/lib/utils/tools/restart.d.ts +0 -15
  234. package/lib/utils/tools/restart.js +0 -39
  235. package/lib/utils/tools/stop.d.ts +0 -7
  236. package/lib/utils/tools/stop.js +0 -13
  237. package/lib/utils/tools/update.d.ts +0 -67
  238. package/lib/utils/tools/update.js +0 -151
  239. /package/{config → default}/view/App.yaml +0 -0
  240. /package/{config → default}/view/config.yaml +0 -0
  241. /package/{config → default}/view/pm2.yaml +0 -0
  242. /package/{config → default}/view/redis.yaml +0 -0
  243. /package/{config → default}/view/server.yaml +0 -0
  244. /package/{lib/modules → dist/module}/art-template.js +0 -0
  245. /package/{lib/modules → dist/module}/axios.js +0 -0
  246. /package/{lib/modules → dist/module}/chalk.js +0 -0
  247. /package/{lib/modules → dist/module}/chokidar.js +0 -0
  248. /package/{lib/modules → dist/module}/level.js +0 -0
  249. /package/{lib/modules → dist/module}/lodash.js +0 -0
  250. /package/{lib/modules → dist/module}/log4js.js +0 -0
  251. /package/{lib/modules → dist/module}/moment.js +0 -0
  252. /package/{lib/modules → dist/module}/node-schedule.js +0 -0
  253. /package/{lib/modules → dist/module}/redis.js +0 -0
  254. /package/{lib/modules → dist/module}/yaml.js +0 -0
@@ -1,92 +0,0 @@
1
- import { ChildProcess, ExecOptions } from 'child_process';
2
- export declare const enum Runner {
3
- Node = "node",
4
- Tsx = "tsx",
5
- Pm2 = "pm2"
6
- }
7
- export declare const enum Mode {
8
- Dev = "dev",
9
- Prod = "prod"
10
- }
11
- export declare const enum Lang {
12
- Js = "js",
13
- Ts = "ts"
14
- }
15
- export declare class KarinCli {
16
- child: ChildProcess;
17
- filename: string;
18
- karinDir: string;
19
- file: string;
20
- constructor();
21
- /**
22
- * 获取pkg配置
23
- * @param isNpm - 是否是npm包
24
- */
25
- pkg(isNpm: boolean): any;
26
- /**
27
- * 获取配置文件路径
28
- * @param name - 配置文件名
29
- */
30
- getConfigPath(name: 'pm2' | 'server'): string;
31
- /**
32
- * 获取pm2配置
33
- * @param name - 配置文件名
34
- */
35
- getConfigData(name: 'pm2' | 'server'): any;
36
- /**
37
- * 启动
38
- * @param mode - 模式
39
- * @param lang - 语言环境
40
- * @param runner - 运行器
41
- */
42
- start(mode: Mode, lang: Lang, runner: Runner): void;
43
- /**
44
- * pm2重启
45
- */
46
- restart(): Promise<void>;
47
- /**
48
- * pm2启动
49
- */
50
- pm2(): Promise<void>;
51
- /**
52
- * pm2结束进程
53
- */
54
- stop(): Promise<void>;
55
- /**
56
- * pm2查看日志
57
- */
58
- log(): Promise<void>;
59
- /**
60
- * 更新依赖
61
- */
62
- update(): Promise<void>;
63
- /**
64
- * 获取指定包的本地版本
65
- * @param name - 包名
66
- * @param pkg - 包管理器
67
- * @returns - 版本号
68
- */
69
- getLocalVersion(name: string, pkg: 'pnpm' | 'cnpm' | 'yarn' | 'npm'): Promise<string>;
70
- /**
71
- * 获取指定包的最新版本
72
- * @param name - 包名
73
- * @param pkg - 包管理器
74
- */
75
- getRemoteVersion(name: string, pkg: 'pnpm' | 'cnpm' | 'yarn' | 'npm'): Promise<string>;
76
- /**
77
- * 获取git插件列表
78
- */
79
- getGitPlugins(): Array<string>;
80
- /**
81
- * 封装exec
82
- * @param cmd - 命令
83
- */
84
- exec(cmd: string, options?: ExecOptions): Promise<string>;
85
- /**
86
- * 封装axios 超时返回false
87
- * @param url - 请求地址
88
- * @param timeout - 超时时间
89
- * @returns - 请求结果
90
- */
91
- Axios(url: string, timeout: number): Promise<any>;
92
- }
package/lib/cli/index.js DELETED
@@ -1,307 +0,0 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import yaml from 'yaml';
4
- import axios from 'axios';
5
- import { fileURLToPath } from 'url';
6
- import { getRegistry } from './pkg.js';
7
- import { exec as execCmd, spawn } from 'child_process';
8
- export class KarinCli {
9
- child;
10
- filename;
11
- karinDir;
12
- file;
13
- constructor() {
14
- process.env.karin_app_start_count = '0';
15
- process.env.karin_app_watch = 'no';
16
- /** 当前文件绝对路径 */
17
- this.filename = fileURLToPath(import.meta.url);
18
- /** karin目录 */
19
- this.karinDir = path.join(path.dirname(this.filename), '../..');
20
- /** 入口文件(注意后缀) */
21
- this.file = path.join(path.dirname(this.filename), '../index.js');
22
- this.child = null;
23
- process.env.karin_app_pkg = getRegistry();
24
- process.env.karin_app_version = this.pkg(true).version;
25
- }
26
- /**
27
- * 获取pkg配置
28
- * @param isNpm - 是否是npm包
29
- */
30
- pkg(isNpm) {
31
- const filePath = isNpm ? path.join(this.karinDir, 'package.json') : path.join(process.cwd(), 'package.json');
32
- const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
33
- return data;
34
- }
35
- /**
36
- * 获取配置文件路径
37
- * @param name - 配置文件名
38
- */
39
- getConfigPath(name) {
40
- const filePath = `./config/config/${name}.yaml`;
41
- if (!fs.existsSync(filePath))
42
- return `${this.karinDir}/config/config/${name}.yaml`;
43
- return filePath;
44
- }
45
- /**
46
- * 获取pm2配置
47
- * @param name - 配置文件名
48
- */
49
- getConfigData(name) {
50
- const _path = this.getConfigPath(name);
51
- const data = yaml.parse(fs.readFileSync(_path, 'utf-8'));
52
- return data;
53
- }
54
- /**
55
- * 启动
56
- * @param mode - 模式
57
- * @param lang - 语言环境
58
- * @param runner - 运行器
59
- */
60
- start(mode, lang, runner) {
61
- process.env.karin_app_mode = mode;
62
- process.env.karin_app_lang = lang;
63
- process.env.karin_app_runner = runner;
64
- let cmd;
65
- switch (runner) {
66
- case "node" /* Runner.Node */:
67
- cmd = [this.file];
68
- break;
69
- case "tsx" /* Runner.Tsx */:
70
- cmd = [this.file];
71
- break;
72
- case "pm2" /* Runner.Pm2 */: {
73
- this.pm2();
74
- return;
75
- }
76
- }
77
- /** 启动 */
78
- this.child = spawn(runner, cmd, { stdio: ['inherit', 'inherit', 'inherit', 'ipc'], cwd: process.cwd(), env: process.env, shell: runner === "tsx" /* Runner.Tsx */ });
79
- /** 监听退出 */
80
- this.child.once('exit', (code) => process.exit(code));
81
- /** 监听子进程消息 */
82
- this.child.on('message', (data) => {
83
- /** pm2重启 */
84
- if (data.env.pm_id)
85
- return this.restart();
86
- try {
87
- /** 先结束进程 */
88
- this.child.kill('SIGINT');
89
- /** 停止监听 */
90
- this.child.removeAllListeners();
91
- /** 重启次数+1 */
92
- const count = Number(process.env.karin_app_start_count) || 0;
93
- process.env.karin_app_start_count = String(count + 1);
94
- }
95
- catch { }
96
- return this.start(mode, lang, runner);
97
- });
98
- }
99
- /**
100
- * pm2重启
101
- */
102
- async restart() {
103
- const pm2Cfg = this.getConfigData('pm2');
104
- const serverCfg = this.getConfigData('server');
105
- /** 尝试获取pm2的进程id */
106
- const port = serverCfg?.http?.port || 7000;
107
- const res = await this.Axios(`http://127.0.0.1:${port}/api/ping`, 1000);
108
- if (res) {
109
- await this.exec(`pm2 restart ${res.pm2_id}`);
110
- }
111
- else {
112
- await this.exec(`pm2 restart ${pm2Cfg?.apps[0]?.name || 'Karin'}`);
113
- }
114
- console.log('pm2服务已重启');
115
- process.exit(0);
116
- }
117
- /**
118
- * pm2启动
119
- */
120
- async pm2() {
121
- console.log('pm2启动中...');
122
- const filePath = this.getConfigPath('pm2');
123
- const data = this.getConfigData('pm2');
124
- /** 修正入口文件路径 兼容0.6.28以前的版本 */
125
- if (!fs.existsSync('./src') && filePath === './config/config/pm2.yaml') {
126
- const script = './node_modules/node-karin/lib/index.js';
127
- if (data.apps[0].script !== script) {
128
- data.apps[0].script = script;
129
- fs.writeFileSync(filePath, yaml.stringify(data));
130
- }
131
- }
132
- const cmd = `pm2 start ${filePath} --env ${JSON.stringify(process.env)}`;
133
- await this.exec(cmd);
134
- console.log('pm2服务已启动 可执行 【npx karin log】 查看日志');
135
- process.exit(0);
136
- }
137
- /**
138
- * pm2结束进程
139
- */
140
- async stop() {
141
- console.log('pm2服务停止中...');
142
- const pm2Cfg = this.getConfigData('pm2');
143
- const serverCfg = this.getConfigData('server');
144
- const port = serverCfg?.http?.port || 7000;
145
- const res = await this.Axios(`http://127.0.0.1:${port}/api/ping`, 1000);
146
- if (res) {
147
- await this.exec(`pm2 delete ${res.pm2_id}`);
148
- }
149
- else {
150
- await this.exec(`pm2 delete ${pm2Cfg?.apps[0]?.name || 'Karin'}`);
151
- }
152
- console.log('pm2服务已停止');
153
- process.exit(0);
154
- }
155
- /**
156
- * pm2查看日志
157
- */
158
- async log() {
159
- const pm2Cfg = this.getConfigData('pm2');
160
- const serverCfg = this.getConfigData('server');
161
- const port = serverCfg?.http?.port || 7000;
162
- const res = await this.Axios(`http://127.0.0.1:${port}/api/ping`, 1000);
163
- const lines = pm2Cfg?.lines || 1000;
164
- const cmd = process.platform === 'win32' ? 'pm2.cmd' : 'pm2';
165
- const type = res ? res.pm_id : pm2Cfg?.apps[0]?.name || 'Karin';
166
- spawn(cmd, ['logs', type, '--lines', lines], { stdio: 'inherit', shell: true, cwd: process.cwd() });
167
- }
168
- /**
169
- * 更新依赖
170
- */
171
- async update() {
172
- /** 屏蔽的依赖包列表 */
173
- const pkgdependencies = [
174
- 'art-template',
175
- 'axios',
176
- 'chalk',
177
- 'chokidar',
178
- 'commander',
179
- 'express',
180
- 'level',
181
- 'lodash',
182
- 'log4js',
183
- 'moment',
184
- 'node-schedule',
185
- 'redis',
186
- 'ws',
187
- 'yaml',
188
- ];
189
- const list = Object.keys(this.pkg(false).dependencies).filter(key => !pkgdependencies.includes(key));
190
- /** 获取包管理器 */
191
- const pkg = getRegistry();
192
- const cmd = pkg === 'yarn' ? 'yarn upgrade' : `${pkg} update`;
193
- await Promise.all(list.map(async (item) => {
194
- try {
195
- /** 检查是否已经是最新版本 */
196
- const local = await this.getLocalVersion(item, pkg);
197
- const remote = await this.getRemoteVersion(item, pkg);
198
- if (local === remote) {
199
- console.log(`[依赖更新] ${item} 已经是最新~`);
200
- return;
201
- }
202
- console.log(`[依赖更新] ${item} 当前版本: ${local} 最新版本: ${remote}`);
203
- await this.exec(`${cmd} ${item}@latest`);
204
- console.log(`[依赖更新] ${item} 更新完成~`);
205
- }
206
- catch (error) {
207
- console.error(`[依赖更新] ${item} 更新失败:`);
208
- console.error(error.stack || error.message || error);
209
- }
210
- }));
211
- console.log('[依赖更新] 所有npm依赖已更新完成~');
212
- console.log('[依赖更新] 开始更新git插件...');
213
- const gitList = this.getGitPlugins();
214
- if (!gitList.length)
215
- return console.log('[依赖更新] 没有git插件需要更新~');
216
- await Promise.all(gitList.map(async (item) => {
217
- const dir = path.resolve(process.cwd(), 'plugins', item);
218
- try {
219
- await this.exec('git pull', { cwd: dir });
220
- console.log(`[依赖更新] ${item} 更新完成~`);
221
- }
222
- catch (error) {
223
- console.error(`[依赖更新] ${item} 更新失败`);
224
- console.error(error.stack || error.message || error);
225
- }
226
- }));
227
- console.log('[依赖更新] 所有git插件已更新完成~');
228
- }
229
- /**
230
- * 获取指定包的本地版本
231
- * @param name - 包名
232
- * @param pkg - 包管理器
233
- * @returns - 版本号
234
- */
235
- async getLocalVersion(name, pkg) {
236
- const cmd = pkg === 'yarn' ? `yarn list --pattern ${name}` : `${pkg} list ${name} --depth=0`;
237
- const text = await this.exec(cmd);
238
- /** pnpm特殊处理 */
239
- if (pkg === 'pnpm') {
240
- const reg = new RegExp(`${name}\\s+([\\d.]+)`, 'gm');
241
- const res = reg.exec(text);
242
- return res?.[1] || '0.0.0';
243
- }
244
- const reg = new RegExp(`${name}@(\\d+\\.\\d+\\.\\d+)`, 'gm');
245
- const res = reg.exec(text);
246
- return res?.[1] || '0.0.0';
247
- }
248
- /**
249
- * 获取指定包的最新版本
250
- * @param name - 包名
251
- * @param pkg - 包管理器
252
- */
253
- async getRemoteVersion(name, pkg) {
254
- const cmd = `${pkg} info ${name} version`;
255
- const text = await this.exec(cmd);
256
- /** yarn特殊处理 */
257
- if (pkg === 'yarn') {
258
- const lines = text.split('\n').map(line => line.trim());
259
- const ver = lines.find(line => /^\d+\.\d+\.\d+$/.test(line));
260
- return ver || '';
261
- }
262
- return text.trim();
263
- }
264
- /**
265
- * 获取git插件列表
266
- */
267
- getGitPlugins() {
268
- const dir = path.resolve(process.cwd(), 'plugins');
269
- let list = fs.readdirSync(dir, { withFileTypes: true });
270
- /** 忽略非文件夹、非 karin-plugin-开头的文件夹 */
271
- list = list.filter(v => v.isDirectory() && v.name.startsWith('karin-plugin-'));
272
- list = list.filter(v => fs.existsSync(`${dir}/${v.name}/package.json`));
273
- const arr = [];
274
- list.map(v => arr.push(v.name));
275
- return arr;
276
- }
277
- /**
278
- * 封装exec
279
- * @param cmd - 命令
280
- */
281
- exec(cmd, options) {
282
- return new Promise((resolve, reject) => {
283
- execCmd(cmd, options, (error, stdout, stderr) => {
284
- if (stdout)
285
- return resolve(stdout.toString().trim());
286
- if (error)
287
- return reject(error);
288
- return reject(stderr);
289
- });
290
- });
291
- }
292
- /**
293
- * 封装axios 超时返回false
294
- * @param url - 请求地址
295
- * @param timeout - 超时时间
296
- * @returns - 请求结果
297
- */
298
- async Axios(url, timeout) {
299
- try {
300
- const res = await axios.get(url, { timeout });
301
- return res.data;
302
- }
303
- catch {
304
- return false;
305
- }
306
- }
307
- }
package/lib/cli/init.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/lib/cli/init.js DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
- import { getRegistry } from './pkg.js';
3
- import { KarinCfgInit } from '../core/init/config.js';
4
- /**
5
- * 休眠函数
6
- * @param ms 毫秒
7
- */
8
- function sleep(ms) {
9
- return new Promise(resolve => setTimeout(resolve, ms));
10
- }
11
- async function main() {
12
- /** 捕获错误 打印日志 */
13
- process.on('uncaughtException', err => console.error(err));
14
- process.on('unhandledRejection', err => console.error(err));
15
- const init = new KarinCfgInit();
16
- init.init();
17
- await sleep(1000);
18
- const pkg = getRegistry();
19
- /** 结果 */
20
- await init.install(pkg);
21
- }
22
- main().then(() => process.exit(0)).catch(() => process.exit(0));
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/lib/cli/karin.js DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
- import { program } from 'commander';
3
- import { KarinCli } from './index.js';
4
- const cli = new KarinCli();
5
- program.version(cli.pkg(true).version, '-v, --version', '显示版本号');
6
- program.command('.').description('启动karin').action(() => cli.start("prod" /* Mode.Prod */, "js" /* Lang.Js */, "node" /* Runner.Node */));
7
- program.command('start').description('启动karin').action(() => cli.start("prod" /* Mode.Prod */, "js" /* Lang.Js */, "node" /* Runner.Node */));
8
- program.command('pm2').description('后台运行karin').action(() => cli.start("prod" /* Mode.Prod */, "js" /* Lang.Js */, "pm2" /* Runner.Pm2 */));
9
- program.command('stop').description('停止后台运行').action(() => cli.stop());
10
- program.command('rs').description('重启pm2服务').action(() => cli.restart());
11
- program.command('dev').description('JavaScript开发模式').action(() => cli.start("dev" /* Mode.Dev */, "js" /* Lang.Js */, "node" /* Runner.Node */));
12
- program.command('ts').description('TypeScript开发模式').action(() => cli.start("dev" /* Mode.Dev */, "ts" /* Lang.Ts */, "tsx" /* Runner.Tsx */));
13
- program.command('log').description('查看日志').action(() => cli.log());
14
- program.command('up').description('更新依赖').action(() => cli.update());
15
- program.command('init').description('初始化karin').action(() => { import('./init.js'); });
16
- program.parse(process.argv);
package/lib/cli/pkg.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * 获取当前的包管理器 根据锁文件判断 优先级 pnpm > yarn > npm > cnpm
3
- */
4
- export declare const getRegistry: () => "pnpm" | "cnpm" | "yarn" | "npm";
package/lib/cli/pkg.js DELETED
@@ -1,14 +0,0 @@
1
- import fs from 'fs';
2
- /**
3
- * 获取当前的包管理器 根据锁文件判断 优先级 pnpm > yarn > npm > cnpm
4
- */
5
- export const getRegistry = () => {
6
- if (fs.existsSync('./pnpm-lock.yaml'))
7
- return 'pnpm';
8
- if (fs.existsSync('./yarn.lock'))
9
- return 'yarn';
10
- if (fs.existsSync('./package-lock.json'))
11
- return 'npm';
12
- // cnpm 没有锁文件
13
- return 'cnpm';
14
- };
@@ -1 +0,0 @@
1
- export {};
package/lib/cli/start.js DELETED
@@ -1,8 +0,0 @@
1
- import { program } from 'commander';
2
- import { KarinCli } from './index.js';
3
- const karin = new KarinCli();
4
- program.version(karin.pkg(true).version, '-v, --version', '显示版本号');
5
- program.command('.').description('启动karin').action(() => karin.start("prod" /* Mode.Prod */, "js" /* Lang.Js */, "node" /* Runner.Node */));
6
- program.command('start').description('启动karin').action(() => karin.start("prod" /* Mode.Prod */, "js" /* Lang.Js */, "node" /* Runner.Node */));
7
- program.command('dev').description('dev开发模式').action(() => karin.start("dev" /* Mode.Dev */, "js" /* Lang.Js */, "node" /* Runner.Node */));
8
- program.parse(process.argv);
@@ -1,10 +0,0 @@
1
- export * from './karin/karin.js';
2
- export * from './init/dir.js';
3
- export * from './init/init.js';
4
- export * from './listener/listener.js';
5
- export * from './plugin/base.js';
6
- export * from '../types/plugin/app.js';
7
- export * from './plugin/loader.js';
8
- export * from './process/process.js';
9
- export * from './server/server.js';
10
- import '../adapter/input/index.js';
package/lib/core/index.js DELETED
@@ -1,10 +0,0 @@
1
- export * from './karin/karin.js';
2
- export * from './init/dir.js';
3
- export * from './init/init.js';
4
- export * from './listener/listener.js';
5
- export * from './plugin/base.js';
6
- export * from '../types/plugin/app.js';
7
- export * from './plugin/loader.js';
8
- export * from './process/process.js';
9
- export * from './server/server.js';
10
- import '../adapter/input/index.js';
@@ -1,43 +0,0 @@
1
- export declare class KarinCfgInit {
2
- /**
3
- * 基础目录
4
- */
5
- baseDir: string[];
6
- constructor();
7
- init(): void;
8
- /**
9
- * 递归创建目录
10
- * @param dirname - 路径
11
- */
12
- mkdir(dirname: string): boolean;
13
- /**
14
- * 解析json
15
- */
16
- readJson(file: string): any;
17
- /**
18
- * 获取插件列表
19
- */
20
- getPlugins(): string[];
21
- /**
22
- * 从npm包内复制默认配置出来
23
- */
24
- copyFile(): void;
25
- /**
26
- * 修改package.json以支持运行
27
- */
28
- modifyPackage(): void;
29
- /**
30
- * 更换镜像源为淘宝源
31
- */
32
- changeRegistry(host: string): Promise<void>;
33
- /**
34
- * 安装pnpm或者yarn
35
- * @param type - 包管理器名称
36
- */
37
- install(type: 'pnpm' | 'yarn' | 'cnpm' | 'npm'): Promise<void>;
38
- /**
39
- * 执行命令
40
- * @param cmd - 命令
41
- */
42
- shell(cmd: string): Promise<unknown>;
43
- }