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.
- package/CHANGELOG.md +1029 -0
- package/default/comment/config.json +34 -0
- package/default/comment/friendDirect.json +10 -0
- package/default/comment/groupGuild.json +11 -0
- package/default/comment/server.json +17 -0
- package/default/config/adapter.json +28 -0
- package/default/config/config.json +47 -0
- package/default/config/groups.json +47 -0
- package/default/config/groups.yaml +70 -0
- package/default/config/pm2.json +16 -0
- package/default/config/privates.json +23 -0
- package/default/config/privates.yaml +31 -0
- package/default/config/redis.json +10 -0
- package/default/config/render.json +19 -0
- package/default/view/group.yaml +73 -0
- package/dist/index.d.ts +9869 -0
- package/dist/index.js +12643 -0
- package/dist/module/art-template.cjs +11 -0
- package/dist/module/art-template.d.ts +1 -0
- package/dist/module/axios.cjs +22 -0
- package/dist/module/axios.d.ts +2 -0
- package/dist/module/chalk.cjs +22 -0
- package/dist/module/chalk.d.ts +2 -0
- package/dist/module/chokidar.cjs +22 -0
- package/dist/module/chokidar.d.ts +2 -0
- package/dist/module/commander.cjs +35 -0
- package/dist/module/commander.d.ts +3 -0
- package/dist/module/commander.js +3 -0
- package/dist/module/dotenv.cjs +22 -0
- package/dist/module/dotenv.d.ts +2 -0
- package/dist/module/dotenv.js +2 -0
- package/dist/module/express.cjs +112 -0
- package/dist/module/express.d.ts +1 -0
- package/dist/module/express.js +1 -0
- package/dist/module/level.cjs +22 -0
- package/dist/module/level.d.ts +2 -0
- package/dist/module/lodash.cjs +11 -0
- package/dist/module/lodash.d.ts +1 -0
- package/dist/module/log4js.cjs +22 -0
- package/dist/module/log4js.d.ts +2 -0
- package/dist/module/moment.cjs +11 -0
- package/dist/module/moment.d.ts +1 -0
- package/dist/module/node-schedule.cjs +22 -0
- package/dist/module/node-schedule.d.ts +2 -0
- package/dist/module/redis.cjs +22 -0
- package/dist/module/redis.d.ts +2 -0
- package/dist/module/ws.cjs +28 -0
- package/dist/module/ws.d.ts +1 -0
- package/dist/module/ws.js +1 -0
- package/dist/module/yaml.cjs +22 -0
- package/dist/module/yaml.d.ts +2 -0
- package/dist/root.d.ts +40 -0
- package/dist/root.js +44 -0
- package/package.json +142 -128
- package/LICENSE +0 -674
- package/README.md +0 -56
- package/config/defSet/App.yaml +0 -42
- package/config/defSet/config.yaml +0 -65
- package/config/defSet/group.yaml +0 -56
- package/config/defSet/pm2.yaml +0 -21
- package/config/defSet/redis.yaml +0 -18
- package/config/defSet/server.yaml +0 -42
- package/config/view/group.yaml +0 -92
- package/lib/adapter/index.d.ts +0 -2
- package/lib/adapter/index.js +0 -2
- package/lib/adapter/input/index.d.ts +0 -78
- package/lib/adapter/input/index.js +0 -205
- package/lib/adapter/onebot/11/convert.d.ts +0 -12
- package/lib/adapter/onebot/11/convert.js +0 -167
- package/lib/adapter/onebot/11/event.d.ts +0 -25
- package/lib/adapter/onebot/11/event.js +0 -442
- package/lib/adapter/onebot/11/index.d.ts +0 -508
- package/lib/adapter/onebot/11/index.js +0 -1047
- package/lib/cli/index.d.ts +0 -92
- package/lib/cli/index.js +0 -307
- package/lib/cli/init.d.ts +0 -2
- package/lib/cli/init.js +0 -22
- package/lib/cli/karin.d.ts +0 -2
- package/lib/cli/karin.js +0 -16
- package/lib/cli/pkg.d.ts +0 -4
- package/lib/cli/pkg.js +0 -14
- package/lib/cli/start.d.ts +0 -1
- package/lib/cli/start.js +0 -8
- package/lib/core/index.d.ts +0 -10
- package/lib/core/index.js +0 -10
- package/lib/core/init/config.d.ts +0 -43
- package/lib/core/init/config.js +0 -201
- package/lib/core/init/dir.d.ts +0 -4
- package/lib/core/init/dir.js +0 -7
- package/lib/core/init/init.d.ts +0 -1
- package/lib/core/init/init.js +0 -47
- package/lib/core/karin/karin.d.ts +0 -198
- package/lib/core/karin/karin.js +0 -226
- package/lib/core/listener/listener.d.ts +0 -145
- package/lib/core/listener/listener.js +0 -235
- package/lib/core/plugin/base.d.ts +0 -156
- package/lib/core/plugin/base.js +0 -131
- package/lib/core/plugin/loader.d.ts +0 -141
- package/lib/core/plugin/loader.js +0 -618
- package/lib/core/process/process.d.ts +0 -18
- package/lib/core/process/process.js +0 -96
- package/lib/core/server/server.d.ts +0 -25
- package/lib/core/server/server.js +0 -295
- package/lib/db/index.d.ts +0 -2
- package/lib/db/index.js +0 -2
- package/lib/db/level/level.d.ts +0 -19
- package/lib/db/level/level.js +0 -36
- package/lib/db/redis/redis.d.ts +0 -2
- package/lib/db/redis/redis.js +0 -135
- package/lib/db/redis/redis_level.d.ts +0 -112
- package/lib/db/redis/redis_level.js +0 -281
- package/lib/event/handler/base.d.ts +0 -42
- package/lib/event/handler/base.js +0 -200
- package/lib/event/handler/message.d.ts +0 -29
- package/lib/event/handler/message.js +0 -307
- package/lib/event/handler/notice.d.ts +0 -18
- package/lib/event/handler/notice.js +0 -214
- package/lib/event/handler/request.d.ts +0 -18
- package/lib/event/handler/request.js +0 -115
- package/lib/event/handler/review.d.ts +0 -55
- package/lib/event/handler/review.js +0 -386
- package/lib/event/index.d.ts +0 -5
- package/lib/event/index.js +0 -5
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -8
- package/lib/modules/art-template.d.ts +0 -1
- package/lib/modules/axios.d.ts +0 -2
- package/lib/modules/chalk.d.ts +0 -2
- package/lib/modules/chokidar.d.ts +0 -2
- package/lib/modules/commander.d.ts +0 -2
- package/lib/modules/commander.js +0 -2
- package/lib/modules/express.d.ts +0 -3
- package/lib/modules/express.js +0 -3
- package/lib/modules/level.d.ts +0 -2
- package/lib/modules/lodash.d.ts +0 -1
- package/lib/modules/log4js.d.ts +0 -2
- package/lib/modules/moment.d.ts +0 -1
- package/lib/modules/node-schedule.d.ts +0 -2
- package/lib/modules/redis.d.ts +0 -2
- package/lib/modules/ws.d.ts +0 -3
- package/lib/modules/ws.js +0 -3
- package/lib/modules/yaml.d.ts +0 -2
- package/lib/modules.d.ts +0 -15
- package/lib/modules.js +0 -15
- package/lib/render/app.d.ts +0 -56
- package/lib/render/app.js +0 -120
- package/lib/render/base.d.ts +0 -30
- package/lib/render/base.js +0 -69
- package/lib/render/client.d.ts +0 -41
- package/lib/render/client.js +0 -238
- package/lib/render/http.d.ts +0 -19
- package/lib/render/http.js +0 -50
- package/lib/render/index.d.ts +0 -6
- package/lib/render/index.js +0 -6
- package/lib/render/server.d.ts +0 -25
- package/lib/render/server.js +0 -101
- package/lib/render/wormhole.d.ts +0 -1
- package/lib/render/wormhole.js +0 -156
- package/lib/types/adapter/api.d.ts +0 -399
- package/lib/types/adapter/api.js +0 -1
- package/lib/types/adapter/base.d.ts +0 -560
- package/lib/types/adapter/base.js +0 -1
- package/lib/types/config/config.d.ts +0 -379
- package/lib/types/config/config.js +0 -1
- package/lib/types/element/element.d.ts +0 -565
- package/lib/types/element/element.js +0 -1
- package/lib/types/element/qqbot.d.ts +0 -123
- package/lib/types/element/qqbot.js +0 -1
- package/lib/types/event/contact.d.ts +0 -28
- package/lib/types/event/contact.js +0 -1
- package/lib/types/event/event.d.ts +0 -305
- package/lib/types/event/event.js +0 -1
- package/lib/types/event/index.d.ts +0 -12
- package/lib/types/event/index.js +0 -7
- package/lib/types/event/message.d.ts +0 -109
- package/lib/types/event/message.js +0 -74
- package/lib/types/event/notice.d.ts +0 -513
- package/lib/types/event/notice.js +0 -52
- package/lib/types/event/reply.d.ts +0 -50
- package/lib/types/event/reply.js +0 -1
- package/lib/types/event/request.d.ts +0 -126
- package/lib/types/event/request.js +0 -52
- package/lib/types/event/sender.d.ts +0 -44
- package/lib/types/event/sender.js +0 -1
- package/lib/types/index.d.ts +0 -13
- package/lib/types/index.js +0 -13
- package/lib/types/logger/logger.d.ts +0 -110
- package/lib/types/logger/logger.js +0 -1
- package/lib/types/onebot11/api.d.ts +0 -53
- package/lib/types/onebot11/api.js +0 -1
- package/lib/types/onebot11/event.d.ts +0 -619
- package/lib/types/onebot11/event.js +0 -2
- package/lib/types/onebot11/index.d.ts +0 -6
- package/lib/types/onebot11/index.js +0 -6
- package/lib/types/onebot11/params.d.ts +0 -609
- package/lib/types/onebot11/params.js +0 -1
- package/lib/types/onebot11/response.d.ts +0 -516
- package/lib/types/onebot11/response.js +0 -1
- package/lib/types/onebot11/segment.d.ts +0 -269
- package/lib/types/onebot11/segment.js +0 -1
- package/lib/types/onebot11/sender.d.ts +0 -59
- package/lib/types/onebot11/sender.js +0 -1
- package/lib/types/plugin/app.d.ts +0 -71
- package/lib/types/plugin/app.js +0 -1
- package/lib/types/plugin/plugin.d.ts +0 -473
- package/lib/types/plugin/plugin.js +0 -1
- package/lib/types/render/render.d.ts +0 -118
- package/lib/types/render/render.js +0 -1
- package/lib/types/type/global.d.ts +0 -25
- package/lib/types/type/global.js +0 -1
- package/lib/utils/common/common.d.ts +0 -236
- package/lib/utils/common/common.js +0 -708
- package/lib/utils/config/config.d.ts +0 -193
- package/lib/utils/config/config.js +0 -328
- package/lib/utils/config/updateVersion.d.ts +0 -33
- package/lib/utils/config/updateVersion.js +0 -145
- package/lib/utils/config/yamlEditor.d.ts +0 -101
- package/lib/utils/config/yamlEditor.js +0 -330
- package/lib/utils/core/handler.d.ts +0 -18
- package/lib/utils/core/handler.js +0 -46
- package/lib/utils/core/logger.d.ts +0 -3
- package/lib/utils/core/logger.js +0 -105
- package/lib/utils/core/segment.d.ts +0 -279
- package/lib/utils/core/segment.js +0 -451
- package/lib/utils/index.d.ts +0 -13
- package/lib/utils/index.js +0 -13
- package/lib/utils/tools/button.d.ts +0 -2
- package/lib/utils/tools/button.js +0 -27
- package/lib/utils/tools/exec.d.ts +0 -20
- package/lib/utils/tools/exec.js +0 -54
- package/lib/utils/tools/ffmpeg.d.ts +0 -12
- package/lib/utils/tools/ffmpeg.js +0 -25
- package/lib/utils/tools/restart.d.ts +0 -15
- package/lib/utils/tools/restart.js +0 -39
- package/lib/utils/tools/stop.d.ts +0 -7
- package/lib/utils/tools/stop.js +0 -13
- package/lib/utils/tools/update.d.ts +0 -67
- package/lib/utils/tools/update.js +0 -151
- /package/{config → default}/view/App.yaml +0 -0
- /package/{config → default}/view/config.yaml +0 -0
- /package/{config → default}/view/pm2.yaml +0 -0
- /package/{config → default}/view/redis.yaml +0 -0
- /package/{config → default}/view/server.yaml +0 -0
- /package/{lib/modules → dist/module}/art-template.js +0 -0
- /package/{lib/modules → dist/module}/axios.js +0 -0
- /package/{lib/modules → dist/module}/chalk.js +0 -0
- /package/{lib/modules → dist/module}/chokidar.js +0 -0
- /package/{lib/modules → dist/module}/level.js +0 -0
- /package/{lib/modules → dist/module}/lodash.js +0 -0
- /package/{lib/modules → dist/module}/log4js.js +0 -0
- /package/{lib/modules → dist/module}/moment.js +0 -0
- /package/{lib/modules → dist/module}/node-schedule.js +0 -0
- /package/{lib/modules → dist/module}/redis.js +0 -0
- /package/{lib/modules → dist/module}/yaml.js +0 -0
package/lib/cli/index.d.ts
DELETED
|
@@ -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
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));
|
package/lib/cli/karin.d.ts
DELETED
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
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
|
-
};
|
package/lib/cli/start.d.ts
DELETED
|
@@ -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);
|
package/lib/core/index.d.ts
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';
|
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
|
-
}
|