node-karin 0.12.1 → 0.12.2-5.pr.206.02ba956

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 (256) 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 +45 -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/cli/index.cjs +526 -0
  17. package/{lib/cli/init.d.ts → dist/cli/index.d.ts} +0 -1
  18. package/dist/cli/index.js +517 -0
  19. package/dist/index.d.ts +9869 -0
  20. package/dist/index.js +12651 -0
  21. package/dist/module/art-template.cjs +11 -0
  22. package/dist/module/art-template.d.ts +1 -0
  23. package/dist/module/axios.cjs +22 -0
  24. package/dist/module/axios.d.ts +2 -0
  25. package/dist/module/chalk.cjs +22 -0
  26. package/dist/module/chalk.d.ts +2 -0
  27. package/dist/module/chokidar.cjs +22 -0
  28. package/dist/module/chokidar.d.ts +2 -0
  29. package/dist/module/commander.cjs +35 -0
  30. package/dist/module/commander.d.ts +3 -0
  31. package/dist/module/commander.js +3 -0
  32. package/dist/module/dotenv.cjs +22 -0
  33. package/dist/module/dotenv.d.ts +2 -0
  34. package/dist/module/dotenv.js +2 -0
  35. package/dist/module/express.cjs +32 -0
  36. package/dist/module/express.d.ts +1 -0
  37. package/dist/module/express.js +1 -0
  38. package/dist/module/level.cjs +22 -0
  39. package/dist/module/level.d.ts +2 -0
  40. package/dist/module/lodash.cjs +11 -0
  41. package/dist/module/lodash.d.ts +1 -0
  42. package/dist/module/log4js.cjs +22 -0
  43. package/dist/module/log4js.d.ts +2 -0
  44. package/dist/module/moment.cjs +11 -0
  45. package/dist/module/moment.d.ts +1 -0
  46. package/dist/module/node-schedule.cjs +22 -0
  47. package/dist/module/node-schedule.d.ts +2 -0
  48. package/dist/module/redis.cjs +22 -0
  49. package/dist/module/redis.d.ts +2 -0
  50. package/dist/module/ws.cjs +28 -0
  51. package/dist/module/ws.d.ts +1 -0
  52. package/dist/module/ws.js +1 -0
  53. package/dist/module/yaml.cjs +22 -0
  54. package/dist/module/yaml.d.ts +2 -0
  55. package/dist/root.d.ts +40 -0
  56. package/dist/root.js +44 -0
  57. package/package.json +150 -129
  58. package/LICENSE +0 -674
  59. package/README.md +0 -56
  60. package/config/defSet/App.yaml +0 -42
  61. package/config/defSet/config.yaml +0 -65
  62. package/config/defSet/group.yaml +0 -56
  63. package/config/defSet/pm2.yaml +0 -21
  64. package/config/defSet/redis.yaml +0 -18
  65. package/config/defSet/server.yaml +0 -42
  66. package/config/view/group.yaml +0 -92
  67. package/lib/adapter/index.d.ts +0 -2
  68. package/lib/adapter/index.js +0 -2
  69. package/lib/adapter/input/index.d.ts +0 -78
  70. package/lib/adapter/input/index.js +0 -205
  71. package/lib/adapter/onebot/11/convert.d.ts +0 -12
  72. package/lib/adapter/onebot/11/convert.js +0 -167
  73. package/lib/adapter/onebot/11/event.d.ts +0 -25
  74. package/lib/adapter/onebot/11/event.js +0 -442
  75. package/lib/adapter/onebot/11/index.d.ts +0 -508
  76. package/lib/adapter/onebot/11/index.js +0 -1047
  77. package/lib/cli/index.d.ts +0 -92
  78. package/lib/cli/index.js +0 -307
  79. package/lib/cli/init.js +0 -22
  80. package/lib/cli/karin.d.ts +0 -2
  81. package/lib/cli/karin.js +0 -16
  82. package/lib/cli/pkg.d.ts +0 -4
  83. package/lib/cli/pkg.js +0 -14
  84. package/lib/cli/start.d.ts +0 -1
  85. package/lib/cli/start.js +0 -8
  86. package/lib/core/index.d.ts +0 -10
  87. package/lib/core/index.js +0 -10
  88. package/lib/core/init/config.d.ts +0 -43
  89. package/lib/core/init/config.js +0 -201
  90. package/lib/core/init/dir.d.ts +0 -4
  91. package/lib/core/init/dir.js +0 -7
  92. package/lib/core/init/init.d.ts +0 -1
  93. package/lib/core/init/init.js +0 -47
  94. package/lib/core/karin/karin.d.ts +0 -198
  95. package/lib/core/karin/karin.js +0 -226
  96. package/lib/core/listener/listener.d.ts +0 -145
  97. package/lib/core/listener/listener.js +0 -235
  98. package/lib/core/plugin/base.d.ts +0 -156
  99. package/lib/core/plugin/base.js +0 -131
  100. package/lib/core/plugin/loader.d.ts +0 -141
  101. package/lib/core/plugin/loader.js +0 -618
  102. package/lib/core/process/process.d.ts +0 -18
  103. package/lib/core/process/process.js +0 -96
  104. package/lib/core/server/server.d.ts +0 -25
  105. package/lib/core/server/server.js +0 -295
  106. package/lib/db/index.d.ts +0 -2
  107. package/lib/db/index.js +0 -2
  108. package/lib/db/level/level.d.ts +0 -19
  109. package/lib/db/level/level.js +0 -36
  110. package/lib/db/redis/redis.d.ts +0 -2
  111. package/lib/db/redis/redis.js +0 -135
  112. package/lib/db/redis/redis_level.d.ts +0 -112
  113. package/lib/db/redis/redis_level.js +0 -281
  114. package/lib/event/handler/base.d.ts +0 -42
  115. package/lib/event/handler/base.js +0 -200
  116. package/lib/event/handler/message.d.ts +0 -25
  117. package/lib/event/handler/message.js +0 -302
  118. package/lib/event/handler/notice.d.ts +0 -18
  119. package/lib/event/handler/notice.js +0 -214
  120. package/lib/event/handler/request.d.ts +0 -18
  121. package/lib/event/handler/request.js +0 -115
  122. package/lib/event/handler/review.d.ts +0 -55
  123. package/lib/event/handler/review.js +0 -386
  124. package/lib/event/index.d.ts +0 -5
  125. package/lib/event/index.js +0 -5
  126. package/lib/index.d.ts +0 -8
  127. package/lib/index.js +0 -8
  128. package/lib/modules/art-template.d.ts +0 -1
  129. package/lib/modules/axios.d.ts +0 -2
  130. package/lib/modules/chalk.d.ts +0 -2
  131. package/lib/modules/chokidar.d.ts +0 -2
  132. package/lib/modules/commander.d.ts +0 -2
  133. package/lib/modules/commander.js +0 -2
  134. package/lib/modules/express.d.ts +0 -3
  135. package/lib/modules/express.js +0 -3
  136. package/lib/modules/level.d.ts +0 -2
  137. package/lib/modules/lodash.d.ts +0 -1
  138. package/lib/modules/log4js.d.ts +0 -2
  139. package/lib/modules/moment.d.ts +0 -1
  140. package/lib/modules/node-schedule.d.ts +0 -2
  141. package/lib/modules/redis.d.ts +0 -2
  142. package/lib/modules/ws.d.ts +0 -3
  143. package/lib/modules/ws.js +0 -3
  144. package/lib/modules/yaml.d.ts +0 -2
  145. package/lib/modules.d.ts +0 -15
  146. package/lib/modules.js +0 -15
  147. package/lib/render/app.d.ts +0 -56
  148. package/lib/render/app.js +0 -120
  149. package/lib/render/base.d.ts +0 -30
  150. package/lib/render/base.js +0 -69
  151. package/lib/render/client.d.ts +0 -41
  152. package/lib/render/client.js +0 -238
  153. package/lib/render/http.d.ts +0 -19
  154. package/lib/render/http.js +0 -50
  155. package/lib/render/index.d.ts +0 -6
  156. package/lib/render/index.js +0 -6
  157. package/lib/render/server.d.ts +0 -25
  158. package/lib/render/server.js +0 -101
  159. package/lib/render/wormhole.d.ts +0 -1
  160. package/lib/render/wormhole.js +0 -156
  161. package/lib/types/adapter/api.d.ts +0 -399
  162. package/lib/types/adapter/api.js +0 -1
  163. package/lib/types/adapter/base.d.ts +0 -560
  164. package/lib/types/adapter/base.js +0 -1
  165. package/lib/types/config/config.d.ts +0 -379
  166. package/lib/types/config/config.js +0 -1
  167. package/lib/types/element/element.d.ts +0 -565
  168. package/lib/types/element/element.js +0 -1
  169. package/lib/types/element/qqbot.d.ts +0 -123
  170. package/lib/types/element/qqbot.js +0 -1
  171. package/lib/types/event/contact.d.ts +0 -28
  172. package/lib/types/event/contact.js +0 -1
  173. package/lib/types/event/event.d.ts +0 -305
  174. package/lib/types/event/event.js +0 -1
  175. package/lib/types/event/index.d.ts +0 -12
  176. package/lib/types/event/index.js +0 -7
  177. package/lib/types/event/message.d.ts +0 -109
  178. package/lib/types/event/message.js +0 -74
  179. package/lib/types/event/notice.d.ts +0 -513
  180. package/lib/types/event/notice.js +0 -52
  181. package/lib/types/event/reply.d.ts +0 -50
  182. package/lib/types/event/reply.js +0 -1
  183. package/lib/types/event/request.d.ts +0 -126
  184. package/lib/types/event/request.js +0 -52
  185. package/lib/types/event/sender.d.ts +0 -44
  186. package/lib/types/event/sender.js +0 -1
  187. package/lib/types/index.d.ts +0 -13
  188. package/lib/types/index.js +0 -13
  189. package/lib/types/logger/logger.d.ts +0 -110
  190. package/lib/types/logger/logger.js +0 -1
  191. package/lib/types/onebot11/api.d.ts +0 -53
  192. package/lib/types/onebot11/api.js +0 -1
  193. package/lib/types/onebot11/event.d.ts +0 -619
  194. package/lib/types/onebot11/event.js +0 -2
  195. package/lib/types/onebot11/index.d.ts +0 -6
  196. package/lib/types/onebot11/index.js +0 -6
  197. package/lib/types/onebot11/params.d.ts +0 -609
  198. package/lib/types/onebot11/params.js +0 -1
  199. package/lib/types/onebot11/response.d.ts +0 -516
  200. package/lib/types/onebot11/response.js +0 -1
  201. package/lib/types/onebot11/segment.d.ts +0 -269
  202. package/lib/types/onebot11/segment.js +0 -1
  203. package/lib/types/onebot11/sender.d.ts +0 -59
  204. package/lib/types/onebot11/sender.js +0 -1
  205. package/lib/types/plugin/app.d.ts +0 -71
  206. package/lib/types/plugin/app.js +0 -1
  207. package/lib/types/plugin/plugin.d.ts +0 -473
  208. package/lib/types/plugin/plugin.js +0 -1
  209. package/lib/types/render/render.d.ts +0 -118
  210. package/lib/types/render/render.js +0 -1
  211. package/lib/types/type/global.d.ts +0 -25
  212. package/lib/types/type/global.js +0 -1
  213. package/lib/utils/common/common.d.ts +0 -236
  214. package/lib/utils/common/common.js +0 -708
  215. package/lib/utils/config/config.d.ts +0 -193
  216. package/lib/utils/config/config.js +0 -328
  217. package/lib/utils/config/updateVersion.d.ts +0 -33
  218. package/lib/utils/config/updateVersion.js +0 -145
  219. package/lib/utils/config/yamlEditor.d.ts +0 -101
  220. package/lib/utils/config/yamlEditor.js +0 -330
  221. package/lib/utils/core/handler.d.ts +0 -18
  222. package/lib/utils/core/handler.js +0 -46
  223. package/lib/utils/core/logger.d.ts +0 -3
  224. package/lib/utils/core/logger.js +0 -105
  225. package/lib/utils/core/segment.d.ts +0 -279
  226. package/lib/utils/core/segment.js +0 -451
  227. package/lib/utils/index.d.ts +0 -13
  228. package/lib/utils/index.js +0 -13
  229. package/lib/utils/tools/button.d.ts +0 -2
  230. package/lib/utils/tools/button.js +0 -27
  231. package/lib/utils/tools/exec.d.ts +0 -20
  232. package/lib/utils/tools/exec.js +0 -54
  233. package/lib/utils/tools/ffmpeg.d.ts +0 -12
  234. package/lib/utils/tools/ffmpeg.js +0 -25
  235. package/lib/utils/tools/restart.d.ts +0 -15
  236. package/lib/utils/tools/restart.js +0 -39
  237. package/lib/utils/tools/stop.d.ts +0 -7
  238. package/lib/utils/tools/stop.js +0 -13
  239. package/lib/utils/tools/update.d.ts +0 -67
  240. package/lib/utils/tools/update.js +0 -151
  241. /package/{config → default}/view/App.yaml +0 -0
  242. /package/{config → default}/view/config.yaml +0 -0
  243. /package/{config → default}/view/pm2.yaml +0 -0
  244. /package/{config → default}/view/redis.yaml +0 -0
  245. /package/{config → default}/view/server.yaml +0 -0
  246. /package/{lib/modules → dist/module}/art-template.js +0 -0
  247. /package/{lib/modules → dist/module}/axios.js +0 -0
  248. /package/{lib/modules → dist/module}/chalk.js +0 -0
  249. /package/{lib/modules → dist/module}/chokidar.js +0 -0
  250. /package/{lib/modules → dist/module}/level.js +0 -0
  251. /package/{lib/modules → dist/module}/lodash.js +0 -0
  252. /package/{lib/modules → dist/module}/log4js.js +0 -0
  253. /package/{lib/modules → dist/module}/moment.js +0 -0
  254. /package/{lib/modules → dist/module}/node-schedule.js +0 -0
  255. /package/{lib/modules → dist/module}/redis.js +0 -0
  256. /package/{lib/modules → dist/module}/yaml.js +0 -0
@@ -0,0 +1,517 @@
1
+ #!/usr/bin/env node
2
+ import fs2 from 'node:fs';
3
+ import { fileURLToPath, URL as URL$1, pathToFileURL } from 'node:url';
4
+ import path2, { join } from 'node:path';
5
+ import { fork, spawn, execSync as execSync$1, exec as exec$1 } from 'node:child_process';
6
+ import dotenv from 'dotenv';
7
+ import { program } from 'commander';
8
+
9
+ var execSync = (cmd, options = {}) => {
10
+ try {
11
+ const result = execSync$1(cmd, options);
12
+ return { status: true, error: null, stdout: result.toString(), stderr: "" };
13
+ } catch (error) {
14
+ return { status: false, error, stdout: "", stderr: "" };
15
+ }
16
+ };
17
+ var exec = (cmd, options = {}) => {
18
+ return new Promise((resolve) => {
19
+ exec$1(cmd, options, (error, stdout, stderr) => {
20
+ const status = !error;
21
+ resolve({ status, error, stdout, stderr });
22
+ });
23
+ });
24
+ };
25
+ var pm2Dir = path2.join(process.cwd(), "./@karinjs/config/pm2.json");
26
+ var start = () => {
27
+ if (!fs2.existsSync(pm2Dir)) {
28
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
29
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
30
+ process.exit(1);
31
+ }
32
+ console.log("[pm2] \u542F\u52A8\u4E2D...");
33
+ const { error } = execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
34
+ if (error) {
35
+ console.log("[pm2] \u542F\u52A8\u5931\u8D25");
36
+ console.log(error);
37
+ process.exit(1);
38
+ }
39
+ console.log("[pm2] \u542F\u52A8\u6210\u529F");
40
+ console.log("[pm2] \u91CD\u542F\u670D\u52A1: pnpm rs");
41
+ console.log("[pm2] \u67E5\u770B\u65E5\u5FD7: pnpm log");
42
+ console.log("[pm2] \u505C\u6B62\u670D\u52A1: pnpm stop");
43
+ console.log("[pm2] \u67E5\u770B\u76D1\u63A7: pm2 monit");
44
+ console.log("[pm2] \u67E5\u770B\u5217\u8868: pm2 list");
45
+ process.exit(0);
46
+ };
47
+ var log = () => {
48
+ if (!fs2.existsSync(pm2Dir)) {
49
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
50
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
51
+ process.exit(1);
52
+ }
53
+ const data = JSON.parse(fs2.readFileSync(pm2Dir, "utf-8"));
54
+ try {
55
+ const prefix = process.platform === "win32" ? "pm2.cmd" : "pm2";
56
+ spawn(prefix, ["logs", data.name, "--lines", data.lines || 1e3], { stdio: "inherit", shell: true });
57
+ } catch (error) {
58
+ console.error("[pm2] \u53D1\u751F\u672A\u77E5\u9519\u8BEF: \u8BF7\u68C0\u67E5pm2\u662F\u5426\u5B89\u88C5 \u3010npm install -g pm2\u3011");
59
+ console.error(error);
60
+ process.exit(1);
61
+ }
62
+ };
63
+ var stop = () => {
64
+ if (!fs2.existsSync(pm2Dir)) {
65
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
66
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
67
+ process.exit(1);
68
+ }
69
+ const data = JSON.parse(fs2.readFileSync(pm2Dir, "utf-8"));
70
+ execSync(`pm2 stop ${data.name}`, { cwd: process.cwd() });
71
+ console.log("[pm2] \u505C\u6B62\u6210\u529F");
72
+ process.exit(0);
73
+ };
74
+ var restart = () => {
75
+ if (!fs2.existsSync(pm2Dir)) {
76
+ console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
77
+ console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
78
+ process.exit(1);
79
+ }
80
+ };
81
+ var pm2 = {
82
+ start,
83
+ log,
84
+ stop,
85
+ restart
86
+ };
87
+ var dir = process.env.INIT_CWD || process.cwd();
88
+ var pkgDir = fileURLToPath(new URL$1("../..", import.meta.url));
89
+ var createDir = () => {
90
+ const list = [
91
+ path2.join(dir, "logs"),
92
+ path2.join(dir, "plugins", "karin-plugin-example"),
93
+ path2.join(dir, "@karinjs", "config"),
94
+ path2.join(dir, "@karinjs", "data"),
95
+ path2.join(dir, "@karinjs", "temp", "console"),
96
+ path2.join(dir, "@karinjs", "temp", "html"),
97
+ path2.join(dir, "@karinjs", "resource")
98
+ ];
99
+ list.forEach((item) => {
100
+ if (!fs2.existsSync(item)) fs2.mkdirSync(item, { recursive: true });
101
+ });
102
+ };
103
+ var createPnpmFile = (dir2) => {
104
+ const pnpmfile = path2.join(dir2, ".pnpmfile.cjs");
105
+ if (fs2.existsSync(pnpmfile)) return;
106
+ const content = [
107
+ "// \u6E05\u7A7A\u5BF9\u7B49\u4F9D\u8D56\u4E2D\u7684node-karin",
108
+ "function readPackage (pkg, context) {",
109
+ " if (pkg?.['peerDependencies']?.['node-karin'] && pkg['peerDependencies']['node-karin'] !== 'file:./lib') {",
110
+ " delete pkg['peerDependencies']['node-karin']",
111
+ " }",
112
+ " return pkg",
113
+ "}",
114
+ "module.exports = {",
115
+ " hooks: {",
116
+ " readPackage",
117
+ " },",
118
+ "}"
119
+ ].join("\n");
120
+ fs2.writeFileSync(pnpmfile, content);
121
+ };
122
+ var shouldSkipNpmrc = () => {
123
+ const { stdout } = execSync("npm config get registry");
124
+ if (stdout.includes("registry.npmjs.org")) return true;
125
+ const { stdout: proxy } = execSync("npm config get proxy");
126
+ return !!proxy;
127
+ };
128
+ var createOrUpdateNpmrc = (dir2) => {
129
+ const list = [
130
+ "node_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/sqlite3",
131
+ "better_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3",
132
+ "sass_binary_site=https://registry.npmmirror.com/-/binary/node-sass",
133
+ "sharp_binary_host=https://registry.npmmirror.com/-/binary/sharp",
134
+ "sharp_libvips_binary_host=https://registry.npmmirror.com/-/binary/sharp-libvips",
135
+ "canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas",
136
+ "# 19\u4EE5\u4E0B\u7248\u672C",
137
+ "puppeteer_download_host=https://registry.npmmirror.com/mirrors",
138
+ "# 20\u4EE5\u4E0A\u7248\u672C",
139
+ "PUPPETEER_DOWNLOAD_BASE_URL = https://registry.npmmirror.com/binaries/chrome-for-testing"
140
+ ];
141
+ const npmrc = path2.join(dir2, ".npmrc");
142
+ if (!fs2.existsSync(npmrc)) {
143
+ fs2.writeFileSync(npmrc, list.join("\n"));
144
+ return;
145
+ }
146
+ const data = fs2.readFileSync(npmrc, "utf-8");
147
+ const newEntries = list.filter((item) => {
148
+ const key = item.split("=")[0];
149
+ return !data.includes(key);
150
+ });
151
+ if (newEntries.length > 0) {
152
+ fs2.appendFileSync(npmrc, "\n" + newEntries.join("\n"));
153
+ }
154
+ };
155
+ var createOrUpdateEnv = (dir2) => {
156
+ const generateRandomKey = () => {
157
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
158
+ return Array.from({ length: 6 }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join("");
159
+ };
160
+ const envData = [
161
+ "# \u662F\u5426\u542F\u7528HTTP",
162
+ "HTTP_ENABLE=true",
163
+ "# HTTP\u76D1\u542C\u7AEF\u53E3",
164
+ "HTTP_PORT=7777",
165
+ "# HTTP\u76D1\u542C\u5730\u5740",
166
+ "HTTP_HOST=0.0.0.0",
167
+ "# HTTP\u9274\u6743\u79D8\u94A5 \u4EC5\u7528\u4E8Ekarin\u81EA\u8EABApi",
168
+ `HTTP_AUTH_KEY=${generateRandomKey()}`,
169
+ "# ws_server\u9274\u6743\u79D8\u94A5",
170
+ `WS_SERVER_AUTH_KEY=${generateRandomKey()}`,
171
+ "\n",
172
+ "# \u662F\u5426\u542F\u7528Redis \u5173\u95ED\u540E\u5C06\u4F7F\u7528\u5185\u90E8\u865A\u62DFRedis",
173
+ "REDIS_ENABLE=true",
174
+ "# \u91CD\u542F\u662F\u5426\u8C03\u7528pm2 \u5982\u679C\u4E0D\u8C03\u7528\u5219\u4F1A\u76F4\u63A5\u5173\u673A \u6B64\u914D\u7F6E\u9002\u5408\u6709\u8FDB\u7A0B\u5B88\u62A4\u7684\u7A0B\u5E8F",
175
+ "PM2_RESTART=true",
176
+ "\n",
177
+ "# \u65E5\u5FD7\u7B49\u7EA7",
178
+ "LOG_LEVEL=info",
179
+ "# \u65E5\u5FD7\u4FDD\u7559\u5929\u6570",
180
+ "LOG_DAYS_TO_KEEP=7",
181
+ "# \u65E5\u5FD7\u6587\u4EF6\u6700\u5927\u5927\u5C0F \u5982\u679C\u6B64\u9879\u5927\u4E8E0\u5219\u542F\u7528\u65E5\u5FD7\u5206\u5272",
182
+ "LOG_MAX_LOG_SIZE=0",
183
+ "# logger.fnc\u989C\u8272",
184
+ 'LOG_FNC_COLOR="#E1D919"',
185
+ "\n",
186
+ "# ffmpeg",
187
+ "FFMPEG_PATH=",
188
+ "# ffprobe",
189
+ "FFPROBE_PATH=",
190
+ "# ffplay",
191
+ "FFPLAY_PATH=",
192
+ "\n",
193
+ "# \u8FD9\u91CC\u8BF7\u52FF\u4FEE\u6539",
194
+ "RUNTIME=node"
195
+ ];
196
+ const env = path2.join(dir2, ".env");
197
+ if (!fs2.existsSync(env)) {
198
+ fs2.writeFileSync(env, envData.join("\n"));
199
+ return;
200
+ }
201
+ const value = fs2.readFileSync(env, "utf-8");
202
+ const newEntries = envData.filter((item) => {
203
+ if (item.includes("#")) return false;
204
+ const key = item.split("=")[0];
205
+ return !value.includes(key);
206
+ });
207
+ if (newEntries.length > 0) {
208
+ fs2.appendFileSync(env, "\n" + newEntries.join("\n"));
209
+ }
210
+ };
211
+ var createWorkspace = (dir2) => {
212
+ const workspace = path2.join(dir2, "pnpm-workspace.yaml");
213
+ if (fs2.existsSync(workspace)) return;
214
+ const content = "packages:\n - 'plugins/**'\n";
215
+ fs2.writeFileSync(workspace, content);
216
+ };
217
+ var createOtherFile = async () => {
218
+ createPnpmFile(dir);
219
+ createWorkspace(dir);
220
+ if (!shouldSkipNpmrc()) {
221
+ createOrUpdateNpmrc(dir);
222
+ }
223
+ createOrUpdateEnv(dir);
224
+ };
225
+ var createConfig = () => {
226
+ const defCfg = path2.join(pkgDir, "default", "config");
227
+ const files = fs2.readdirSync(defCfg);
228
+ files.forEach((file) => {
229
+ if (!file.endsWith(".json")) return;
230
+ const filePath = path2.join(defCfg, file);
231
+ const targetPath = path2.join(dir, "@karinjs", "config");
232
+ const targetFile = path2.join(targetPath, file);
233
+ if (!fs2.existsSync(targetFile)) {
234
+ fs2.copyFileSync(filePath, targetFile);
235
+ return;
236
+ }
237
+ const defData = fs2.readFileSync(filePath, "utf-8");
238
+ const targetData = fs2.readFileSync(targetFile, "utf-8");
239
+ const mergedData = { ...JSON.parse(defData), ...JSON.parse(targetData) };
240
+ fs2.writeFileSync(targetFile, JSON.stringify(mergedData, null, 2));
241
+ });
242
+ };
243
+ var modifyPackageJson = () => {
244
+ const pkg = fs2.readFileSync(path2.join(dir, "package.json"), "utf-8");
245
+ const data = JSON.parse(pkg);
246
+ data.type = "module";
247
+ data.scripts.karin = "karin";
248
+ const list = [
249
+ "app",
250
+ "start",
251
+ "pm2",
252
+ "stop",
253
+ "rs",
254
+ "log",
255
+ "up",
256
+ "init",
257
+ "dev",
258
+ "ts",
259
+ "watch"
260
+ ];
261
+ list.forEach((v) => {
262
+ data.scripts[v] = `karin ${v}`;
263
+ });
264
+ fs2.writeFileSync(path2.join(dir, "package.json"), JSON.stringify(data, null, 2));
265
+ return data;
266
+ };
267
+ var init = async () => {
268
+ createDir();
269
+ await createOtherFile();
270
+ createConfig();
271
+ modifyPackageJson();
272
+ process.exit(0);
273
+ };
274
+ var parseEnvFiles = (env) => {
275
+ if (!env) return [".env"];
276
+ return env.split(",").map((file) => file.trim());
277
+ };
278
+ var loadEnv = (env) => {
279
+ const dir2 = process.cwd();
280
+ const files = parseEnvFiles(env);
281
+ if (!files.includes(".env")) {
282
+ files.unshift(".env");
283
+ }
284
+ files.forEach((file) => {
285
+ if (!fs2.existsSync(`${dir2}/${file}`)) {
286
+ if (file === ".env") {
287
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 pnpm init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
288
+ } else {
289
+ console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
290
+ }
291
+ process.exit(1);
292
+ }
293
+ });
294
+ const paths = files.map((file) => `${dir2}/${file}`);
295
+ dotenv.config({ path: paths, override: true });
296
+ };
297
+ var start2 = async (env) => {
298
+ loadEnv(env);
299
+ const index = "../root.js";
300
+ const { karinMain } = await import(index);
301
+ const child = fork(karinMain);
302
+ child.on("message", (message) => {
303
+ if (message === "restart") {
304
+ child.kill();
305
+ child.removeAllListeners();
306
+ start2(env);
307
+ }
308
+ });
309
+ child.on("exit", (code) => process.exit(code));
310
+ };
311
+ var dev = async (env) => {
312
+ loadEnv(env);
313
+ const index = "../root.js";
314
+ process.env.NODE_ENV = "development";
315
+ const { karinMain } = await import(index);
316
+ await import(pathToFileURL(karinMain).toString());
317
+ };
318
+ var tsStart = async (env) => {
319
+ loadEnv(env);
320
+ process.env.NODE_ENV = "development";
321
+ const index = "../root.js";
322
+ const { karinMain } = await import(index);
323
+ const child = spawn("npx", ["tsx", karinMain], {
324
+ env: {
325
+ ...process.env,
326
+ RUNTIME: "tsx"
327
+ },
328
+ stdio: "inherit",
329
+ shell: true
330
+ });
331
+ child.on("exit", (code) => process.exit(code ?? 0));
332
+ };
333
+ var tsWatch = async (options) => {
334
+ loadEnv(options.env);
335
+ process.env.NODE_ENV = "development";
336
+ const index = "../root.js";
337
+ const { karinMain } = await import(index);
338
+ const args = ["tsx", "watch"];
339
+ if (options.include) {
340
+ options.include.split(",").forEach((pattern) => {
341
+ args.push("--include", pattern.trim());
342
+ });
343
+ }
344
+ if (options.exclude) {
345
+ options.exclude.split(",").forEach((pattern) => {
346
+ args.push("--exclude", pattern.trim());
347
+ });
348
+ }
349
+ if (!options.clearScreen) {
350
+ args.push("--clear-screen=false");
351
+ }
352
+ args.push(karinMain);
353
+ const child = spawn("npx", args, {
354
+ env: {
355
+ ...process.env,
356
+ RUNTIME: "tsx",
357
+ TSX_WATCH: "true"
358
+ },
359
+ stdio: "inherit",
360
+ shell: true
361
+ });
362
+ child.on("exit", (code) => process.exit(code ?? 0));
363
+ };
364
+ var checkGitInstalled = async () => {
365
+ try {
366
+ const { status } = await exec("git --version");
367
+ return status;
368
+ } catch {
369
+ return false;
370
+ }
371
+ };
372
+ var updateDependencies = async (packagePath) => {
373
+ try {
374
+ const packageJson = JSON.parse(fs2.readFileSync(packagePath, "utf-8"));
375
+ const dependencies = packageJson.dependencies || {};
376
+ const packagesToUpdate = [];
377
+ const checkVersionTasks = Object.entries(dependencies).map(async ([pkg, version]) => {
378
+ if (pkg.startsWith("@types/")) {
379
+ return;
380
+ }
381
+ try {
382
+ const { stdout: pkgInfoStr } = await exec(`pnpm view ${pkg} --json`);
383
+ const pkgInfo = JSON.parse(pkgInfoStr.trim());
384
+ if (!pkgInfo.karin) return;
385
+ const currentVersion = version.replace(/[\^~]/g, "");
386
+ const { stdout: distTagsStr } = await exec(`pnpm view ${pkg} dist-tags --json`);
387
+ const distTags = JSON.parse(distTagsStr.trim());
388
+ const isPreRelease = /[-+]/.test(currentVersion);
389
+ const latestVersion = distTags.latest;
390
+ console.log(`[npm] ${pkg}:`);
391
+ console.log(` \u5F53\u524D\u7248\u672C: ${currentVersion}${isPreRelease ? " (\u9884\u53D1\u5E03\u7248\u672C)" : ""}`);
392
+ console.log(` \u6700\u65B0\u7248\u672C: ${latestVersion}`);
393
+ if (isPreRelease || currentVersion !== latestVersion) {
394
+ console.log(`[npm] \u53D1\u73B0\u65B0\u7248\u672C ${pkg}: ${currentVersion} -> ${latestVersion}`);
395
+ packagesToUpdate.push(`${pkg}@latest`);
396
+ } else {
397
+ console.log(`[npm] ${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
398
+ }
399
+ } catch (error) {
400
+ console.error(`[npm] \u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
401
+ }
402
+ });
403
+ await Promise.all(checkVersionTasks);
404
+ if (packagesToUpdate.length > 0) {
405
+ console.log("[npm] \u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
406
+ try {
407
+ const { status, error } = await exec(`pnpm update ${packagesToUpdate.join(" ")}`);
408
+ if (status) {
409
+ console.log("[npm] \u6240\u6709\u63D2\u4EF6\u66F4\u65B0\u5B8C\u6210");
410
+ } else {
411
+ console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
412
+ }
413
+ } catch (error) {
414
+ console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
415
+ }
416
+ } else {
417
+ console.log("[npm] \u6240\u6709\u63D2\u4EF6\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
418
+ }
419
+ } catch (error) {
420
+ console.error("[npm] \u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
421
+ }
422
+ };
423
+ var updatePlugins = async (pluginsPath) => {
424
+ if (!await checkGitInstalled()) {
425
+ console.error("[git] \u8BF7\u5148\u5B89\u88C5git");
426
+ return;
427
+ }
428
+ if (!fs2.existsSync(pluginsPath)) {
429
+ console.error("[git] plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
430
+ return;
431
+ }
432
+ const isDirectory = (await fs2.promises.stat(pluginsPath)).isDirectory();
433
+ if (!isDirectory) {
434
+ console.error("[git] plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
435
+ return;
436
+ }
437
+ const dirs = await fs2.promises.readdir(pluginsPath);
438
+ const updateTasks = dirs.map(async (dir2) => {
439
+ const pluginPath = join(pluginsPath, dir2);
440
+ const gitPath = join(pluginPath, ".git");
441
+ const packageJsonPath = join(pluginPath, "package.json");
442
+ if (!dir2.startsWith("karin-plugin-") || !(await fs2.promises.stat(pluginPath)).isDirectory()) {
443
+ return;
444
+ }
445
+ if (!fs2.existsSync(gitPath)) {
446
+ console.log(`[git] ${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
447
+ return;
448
+ }
449
+ try {
450
+ const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8"));
451
+ if (!packageJson.karin) {
452
+ console.log(`[git] ${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
453
+ return;
454
+ }
455
+ console.log(`[git] \u6B63\u5728\u66F4\u65B0 ${dir2}...`);
456
+ const { status, error } = await exec("git pull", { cwd: pluginPath });
457
+ if (!status) {
458
+ console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
459
+ }
460
+ } catch (error) {
461
+ console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
462
+ }
463
+ });
464
+ await Promise.all(updateTasks);
465
+ };
466
+ var updateAll = async () => {
467
+ try {
468
+ console.log("[all] \u5F00\u59CB\u6267\u884C\u66F4\u65B0\u4EFB\u52A1\n");
469
+ await Promise.all([updateDependencies("./package.json"), updatePlugins("./plugins")]);
470
+ console.log("\n[all] \u66F4\u65B0\u4EFB\u52A1\u6267\u884C\u5B8C\u6210");
471
+ } finally {
472
+ process.exit(0);
473
+ }
474
+ };
475
+ var _a;
476
+ if (!((_a = process.argv) == null ? undefined : _a[2])) process.argv.push("-h");
477
+ var addEnvOption = (command) => {
478
+ return command.option("-e, --env <files>", "\u6307\u5B9A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\uFF0C\u591A\u4E2A\u6587\u4EF6\u7528\u9017\u53F7\u5206\u9694");
479
+ };
480
+ var getVersion = () => {
481
+ try {
482
+ const file = fileURLToPath(new URL("../../package.json", import.meta.url));
483
+ const packageJson = JSON.parse(fs2.readFileSync(file, "utf-8"));
484
+ return packageJson.version;
485
+ } catch {
486
+ return "unknown";
487
+ }
488
+ };
489
+ program.version(getVersion(), "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
490
+ program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
491
+ program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
492
+ program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
493
+ program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
494
+ program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
495
+ program.command("init").description("\u521D\u59CB\u5316\u9879\u76EE").action(init);
496
+ addEnvOption(program.command(".").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
497
+ addEnvOption(program.command("app").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
498
+ addEnvOption(program.command("start").description("\u524D\u53F0\u542F\u52A8")).action((options) => start2(options.env));
499
+ addEnvOption(program.command("dev").description("JavaScript\u5F00\u53D1\u6A21\u5F0F")).action((options) => dev(options.env));
500
+ addEnvOption(
501
+ program.command("ts").description("TypeScript\u5F00\u53D1\u6A21\u5F0F").addHelpText("after", `
502
+ \u793A\u4F8B:
503
+ $ karin ts # \u4F7F\u7528\u9ED8\u8BA4 .env \u6587\u4EF6\u542F\u52A8
504
+ $ karin ts -e .env.dev # \u4F7F\u7528\u6307\u5B9A\u7684\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
505
+ $ karin ts -e .env.dev,.env.local # \u4F7F\u7528\u591A\u4E2A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\u542F\u52A8
506
+ `)
507
+ ).action((options) => tsStart(options.env));
508
+ addEnvOption(
509
+ program.command("watch").description("TypeScript\u76D1\u89C6\u6A21\u5F0F").option("--include <patterns>", "\u6DFB\u52A0\u8981\u76D1\u89C6\u7684\u6587\u4EF6/\u76EE\u5F55\uFF0C\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694").option("--exclude <patterns>", "\u6392\u9664\u8981\u76D1\u89C6\u7684\u6587\u4EF6/\u76EE\u5F55\uFF0C\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694").option("--clear-screen", "\u91CD\u65B0\u8FD0\u884C\u65F6\u662F\u5426\u6E05\u5C4F", true).addHelpText("after", `
510
+ \u793A\u4F8B:
511
+ $ karin watch # \u9ED8\u8BA4\u76D1\u89C6\u6A21\u5F0F
512
+ $ karin watch --include src # \u76D1\u89C6 src \u76EE\u5F55
513
+ $ karin watch --exclude node_modules,dist # \u6392\u9664\u6307\u5B9A\u76EE\u5F55
514
+ $ karin watch --no-clear-screen # \u7981\u7528\u6E05\u5C4F
515
+ `)
516
+ ).action((options) => tsWatch(options));
517
+ program.parse(process.argv);