alemonjs 1.1.10 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/dealmsg.js +1 -1
- package/lib/define/main.js +13 -14
- package/lib/log/index.js +30 -0
- package/lib/ntqq/alemon/group/controller.js +6 -3
- package/lib/ntqq/alemon/group/direct.js +13 -6
- package/lib/ntqq/alemon/group/reply.js +8 -4
- package/lib/ntqq/alemon/guild/controller.js +1 -0
- package/lib/ntqq/index.js +0 -2
- package/lib/ntqq/sdk/api/group.js +16 -2
- package/lib/ntqq/sdk/config.js +0 -2
- package/lib/villa/villa.js +1 -5
- package/package.json +6 -26
- package/types/define/types.d.ts +3 -20
- package/types/log/index.d.ts +7 -0
- package/types/ntqq/alemon/guild/controller.d.ts +1 -0
- package/types/ntqq/sdk/api/group.d.ts +1 -0
- package/types/villa/villa.d.ts +0 -20
- package/logs.d.ts +0 -6
- package/logs.js +0 -23
- package/run.d.ts +0 -5
- package/run.js +0 -29
package/lib/core/dealmsg.js
CHANGED
package/lib/define/main.js
CHANGED
|
@@ -2,11 +2,13 @@ import PupOptions from '../default/pup.js';
|
|
|
2
2
|
import { rebotMap } from './map.js';
|
|
3
3
|
import { nodeScripts } from './child_process.js';
|
|
4
4
|
import { command } from './command.js';
|
|
5
|
-
import {
|
|
5
|
+
import { AppNameError } from '../log/index.js';
|
|
6
|
+
import { setLanchConfig, loadInit, appsInit, setAppProCoinfg, startChrom, getPublicIP } from '../core/index.js';
|
|
6
7
|
import { getPupPath, setBotConfigByKey, getBotConfigByKey } from '../config/index.js';
|
|
7
8
|
import { createWeb } from '../koa/index.js';
|
|
8
9
|
import { autoClearFiles } from '../koa/file.js';
|
|
9
10
|
import { AvailableIntentsEventsEnum } from 'qq-guild-bot';
|
|
11
|
+
import { join } from 'path';
|
|
10
12
|
let OptionsCache;
|
|
11
13
|
/**
|
|
12
14
|
* 得到初始化配置
|
|
@@ -229,19 +231,19 @@ export async function defineAlemonConfig(Options) {
|
|
|
229
231
|
* ************
|
|
230
232
|
*/
|
|
231
233
|
if (Options?.login && Options?.app?.init !== false) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
setAppProCoinfg('regex', Options?.app?.regJSon?.create);
|
|
234
|
+
if (Options?.app?.regJSON?.create === false) {
|
|
235
|
+
setAppProCoinfg('regex', Options?.app?.regJSON?.create);
|
|
235
236
|
}
|
|
236
|
-
if (Options?.app?.
|
|
237
|
-
setAppProCoinfg('route', Options?.app?.
|
|
237
|
+
if (Options?.app?.regJSON?.address) {
|
|
238
|
+
setAppProCoinfg('route', Options?.app?.regJSON?.address);
|
|
238
239
|
}
|
|
239
|
-
if (Options?.app?.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
if (Options?.app?.scripts && typeof Options?.app?.scripts == 'string') {
|
|
241
|
+
const dir = join(process.cwd(), Options?.app?.scripts);
|
|
242
|
+
await import(`file://${dir}`).catch(err => {
|
|
243
|
+
console.error(`file://${dir}`);
|
|
244
|
+
AppNameError('local dev', err);
|
|
245
|
+
});
|
|
243
246
|
}
|
|
244
|
-
app.mount();
|
|
245
247
|
}
|
|
246
248
|
/**
|
|
247
249
|
* ************
|
|
@@ -300,9 +302,6 @@ export async function defineAlemonConfig(Options) {
|
|
|
300
302
|
* ************
|
|
301
303
|
*/
|
|
302
304
|
if (Options?.mount !== false) {
|
|
303
|
-
if (Options?.regex) {
|
|
304
|
-
setAppProCoinfg('regex', Options?.regex);
|
|
305
|
-
}
|
|
306
305
|
await appsInit();
|
|
307
306
|
}
|
|
308
307
|
/**
|
package/lib/log/index.js
CHANGED
|
@@ -4,3 +4,33 @@ export const everyoneError = (err) => {
|
|
|
4
4
|
console.error(err);
|
|
5
5
|
return err;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* 捕捉插件错误
|
|
9
|
+
* @param appname
|
|
10
|
+
* @param err
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export const AppNameError = (appname, err) => {
|
|
14
|
+
// 属于依赖缺失
|
|
15
|
+
const match = /Cannot find package '(.+)' imported from/.exec(err.message);
|
|
16
|
+
if (match && match[1]) {
|
|
17
|
+
const packageName = match[1];
|
|
18
|
+
console.error(`[APP] [${appname}] 缺失 ${packageName} 包`);
|
|
19
|
+
// 发送消息
|
|
20
|
+
process.send?.({
|
|
21
|
+
type: 'lack-of-package',
|
|
22
|
+
message: {
|
|
23
|
+
packageName
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// 其他错误
|
|
30
|
+
console.error(`[APP] [${appname}]`, err);
|
|
31
|
+
process.send?.({
|
|
32
|
+
type: 'error',
|
|
33
|
+
message: err
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -52,7 +52,8 @@ export const Controller = {
|
|
|
52
52
|
}).then(res => res.file_info)
|
|
53
53
|
},
|
|
54
54
|
msg_id,
|
|
55
|
-
msg_type: 7
|
|
55
|
+
msg_type: 7,
|
|
56
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
return false;
|
|
@@ -69,7 +70,8 @@ export const Controller = {
|
|
|
69
70
|
}).then(res => res.file_info)
|
|
70
71
|
},
|
|
71
72
|
msg_id,
|
|
72
|
-
msg_type: 7
|
|
73
|
+
msg_type: 7,
|
|
74
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
77
|
return false;
|
|
@@ -82,7 +84,8 @@ export const Controller = {
|
|
|
82
84
|
for (const item of msg) {
|
|
83
85
|
arr.push(ClientNTQQ.groupOpenMessages(guild_id, {
|
|
84
86
|
msg_id,
|
|
85
|
-
...item
|
|
87
|
+
...item,
|
|
88
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
86
89
|
}));
|
|
87
90
|
}
|
|
88
91
|
return arr;
|
|
@@ -84,7 +84,8 @@ const Controller = {
|
|
|
84
84
|
}).then(res => res.file_info)
|
|
85
85
|
},
|
|
86
86
|
msg_id,
|
|
87
|
-
msg_type: 7
|
|
87
|
+
msg_type: 7,
|
|
88
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
88
89
|
}).catch(everyoneError);
|
|
89
90
|
}
|
|
90
91
|
return false;
|
|
@@ -106,7 +107,8 @@ const Controller = {
|
|
|
106
107
|
}).then(res => res.file_info)
|
|
107
108
|
},
|
|
108
109
|
msg_id,
|
|
109
|
-
msg_type: 7
|
|
110
|
+
msg_type: 7,
|
|
111
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
110
112
|
}).catch(everyoneError);
|
|
111
113
|
}
|
|
112
114
|
return;
|
|
@@ -116,6 +118,7 @@ const Controller = {
|
|
|
116
118
|
for (const item of msg) {
|
|
117
119
|
arr.push(ClientNTQQ.usersOpenMessages(open_id, {
|
|
118
120
|
msg_id,
|
|
121
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id),
|
|
119
122
|
...item
|
|
120
123
|
}));
|
|
121
124
|
}
|
|
@@ -179,7 +182,8 @@ export async function directController(msg, open_id, msg_id) {
|
|
|
179
182
|
}).then(res => res.file_info)
|
|
180
183
|
},
|
|
181
184
|
msg_id,
|
|
182
|
-
msg_type: 7
|
|
185
|
+
msg_type: 7,
|
|
186
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
183
187
|
}).catch(everyoneError);
|
|
184
188
|
}
|
|
185
189
|
catch (err) {
|
|
@@ -214,7 +218,8 @@ export async function directController(msg, open_id, msg_id) {
|
|
|
214
218
|
}).then(res => res.file_info)
|
|
215
219
|
},
|
|
216
220
|
msg_id,
|
|
217
|
-
msg_type: 7
|
|
221
|
+
msg_type: 7,
|
|
222
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
218
223
|
}).catch(everyoneError);
|
|
219
224
|
}
|
|
220
225
|
catch (err) {
|
|
@@ -252,13 +257,15 @@ export async function directController(msg, open_id, msg_id) {
|
|
|
252
257
|
}).then(res => res.file_info)
|
|
253
258
|
},
|
|
254
259
|
msg_id,
|
|
255
|
-
msg_type: 7
|
|
260
|
+
msg_type: 7,
|
|
261
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
256
262
|
}).catch(everyoneError);
|
|
257
263
|
}
|
|
258
264
|
}
|
|
259
265
|
return await ClientNTQQ.usersOpenMessages(open_id, {
|
|
260
266
|
content,
|
|
261
267
|
msg_id,
|
|
262
|
-
msg_type: 0
|
|
268
|
+
msg_type: 0,
|
|
269
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
263
270
|
}).catch(everyoneError);
|
|
264
271
|
}
|
|
@@ -25,7 +25,8 @@ export async function replyController(msg, guild_id, msg_id) {
|
|
|
25
25
|
}).then(res => res.file_info)
|
|
26
26
|
},
|
|
27
27
|
msg_id,
|
|
28
|
-
msg_type: 7
|
|
28
|
+
msg_type: 7,
|
|
29
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
29
30
|
}).catch(everyoneError);
|
|
30
31
|
}
|
|
31
32
|
catch (err) {
|
|
@@ -57,7 +58,8 @@ export async function replyController(msg, guild_id, msg_id) {
|
|
|
57
58
|
}).then(res => res.file_info)
|
|
58
59
|
},
|
|
59
60
|
msg_id,
|
|
60
|
-
msg_type: 7
|
|
61
|
+
msg_type: 7,
|
|
62
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
61
63
|
}).catch(everyoneError);
|
|
62
64
|
}
|
|
63
65
|
catch (err) {
|
|
@@ -87,12 +89,14 @@ export async function replyController(msg, guild_id, msg_id) {
|
|
|
87
89
|
}).then(res => res.file_info)
|
|
88
90
|
},
|
|
89
91
|
msg_id,
|
|
90
|
-
msg_type: 7
|
|
92
|
+
msg_type: 7,
|
|
93
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
91
94
|
}).catch(everyoneError);
|
|
92
95
|
}
|
|
93
96
|
return await ClientNTQQ.groupOpenMessages(guild_id, {
|
|
94
97
|
content,
|
|
95
98
|
msg_id,
|
|
96
|
-
msg_type: 0
|
|
99
|
+
msg_type: 0,
|
|
100
|
+
msg_seq: ClientNTQQ.getMsgSeq(msg_id)
|
|
97
101
|
}).catch(everyoneError);
|
|
98
102
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/ntqq/index.js
CHANGED
|
@@ -14,9 +14,7 @@ export async function createAlemonByNtqq() {
|
|
|
14
14
|
* 读取配置
|
|
15
15
|
*/
|
|
16
16
|
const cfg = getBotConfigByKey('ntqq');
|
|
17
|
-
console.log('cfg', cfg);
|
|
18
17
|
const intents = getIntentsMask(cfg.intents);
|
|
19
|
-
console.log('intents', intents);
|
|
20
18
|
if (cfg.mode == 'qq-guild') {
|
|
21
19
|
setBotConfig({
|
|
22
20
|
appID: cfg.appID,
|
|
@@ -8,7 +8,6 @@ import { API_SGROUP } from './config.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export async function GroupService(config) {
|
|
10
10
|
const { token, appID } = getBotConfig();
|
|
11
|
-
console.log('token', token);
|
|
12
11
|
const service = await axios.create({
|
|
13
12
|
baseURL: API_SGROUP,
|
|
14
13
|
timeout: 20000,
|
|
@@ -29,7 +28,6 @@ export async function gateway() {
|
|
|
29
28
|
})
|
|
30
29
|
.then(res => res.data)
|
|
31
30
|
.then(data => {
|
|
32
|
-
console.log('data', data);
|
|
33
31
|
const { url } = data;
|
|
34
32
|
if (url) {
|
|
35
33
|
return url;
|
|
@@ -58,6 +56,22 @@ export async function usersOpenMessages(openid, data, msg_id) {
|
|
|
58
56
|
}).then(res => res.data);
|
|
59
57
|
}
|
|
60
58
|
// /\[🔗[^\]]+\]\([^)]+\)|@everyone/.test(content)
|
|
59
|
+
// map会越来越大,应该自动delte第一个key
|
|
60
|
+
const map = {};
|
|
61
|
+
export function getMsgSeq(MsgId) {
|
|
62
|
+
if (Object.prototype.hasOwnProperty.call(map, MsgId)) {
|
|
63
|
+
map[MsgId] = map[MsgId] + 1;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
map[MsgId] = 1;
|
|
67
|
+
}
|
|
68
|
+
const arr = Object.keys(map);
|
|
69
|
+
if (arr.length > 15) {
|
|
70
|
+
const firstKey = arr[0];
|
|
71
|
+
delete map[firstKey];
|
|
72
|
+
}
|
|
73
|
+
return map[MsgId];
|
|
74
|
+
}
|
|
61
75
|
/**
|
|
62
76
|
* 发送群聊消息
|
|
63
77
|
* @param group_openid
|
package/lib/ntqq/sdk/config.js
CHANGED
|
@@ -34,7 +34,6 @@ export async function setTimeoutBotConfig(cfg) {
|
|
|
34
34
|
* 发送请求
|
|
35
35
|
*/
|
|
36
36
|
const data = await getAuthentication(cfg.appID, cfg.secret).then(res => res.data);
|
|
37
|
-
console.log('data.access_token', data.access_token);
|
|
38
37
|
const g = {
|
|
39
38
|
appID: cfg.appID,
|
|
40
39
|
token: data.access_token,
|
|
@@ -52,7 +51,6 @@ export async function setTimeoutBotConfig(cfg) {
|
|
|
52
51
|
* 发送请求
|
|
53
52
|
*/
|
|
54
53
|
const data = await getAuthentication(cfg.appID, cfg.secret).then(res => res.data);
|
|
55
|
-
console.log('data.access_token', data.access_token);
|
|
56
54
|
g.token = data.access_token;
|
|
57
55
|
/**
|
|
58
56
|
* 设置配置
|
package/lib/villa/villa.js
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alemonjs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "DOCS https://alemonjs.com/",
|
|
5
|
-
"author": "ningmengchongshui",
|
|
6
|
-
"license": "GPL-2.0",
|
|
7
|
-
"type": "module",
|
|
8
5
|
"scripts": {
|
|
9
6
|
"app": "ts-node alemon.config.ts",
|
|
10
|
-
"build": "npm run tsc && npm run tsc:logs && npm run tsc:run ",
|
|
11
7
|
"tsc": "tsc",
|
|
12
|
-
"tsc:logs": "tsc --module NodeNext --declaration ./logs.ts",
|
|
13
|
-
"tsc:run": "tsc --module NodeNext --declaration ./run.ts",
|
|
14
8
|
"doc": "typedoc --options typedoc.json",
|
|
15
9
|
"format": "prettier --write .",
|
|
16
10
|
"lint": "eslint . --ext .js,.ts --fix --ignore-path .gitignore"
|
|
@@ -46,39 +40,25 @@
|
|
|
46
40
|
"@types/ws": "^8.5.5",
|
|
47
41
|
"@typescript-eslint/eslint-plugin": "^5.60.0",
|
|
48
42
|
"@typescript-eslint/parser": "^5.60.0",
|
|
49
|
-
"alemon-rollup": "^1.0.4",
|
|
50
|
-
"art-template": "^4.13.2",
|
|
51
43
|
"eslint": "^8.43.0",
|
|
52
44
|
"eslint-config-prettier": "^8.8.0",
|
|
53
45
|
"eslint-plugin-prettier": "^4.2.1",
|
|
54
46
|
"prettier": "^2.8.8",
|
|
55
|
-
"
|
|
56
|
-
"typedoc": "^0.25.2",
|
|
57
|
-
"typescript": ">=5.0.4 <5.1.0"
|
|
47
|
+
"typedoc": "^0.25.2"
|
|
58
48
|
},
|
|
49
|
+
"author": "ningmengchongshui",
|
|
50
|
+
"license": "GPL-2.0",
|
|
51
|
+
"type": "module",
|
|
59
52
|
"types": "types",
|
|
60
53
|
"main": "lib/index.js",
|
|
61
54
|
"files": [
|
|
62
|
-
"bin",
|
|
63
55
|
"lib",
|
|
64
|
-
"types"
|
|
65
|
-
"run.js",
|
|
66
|
-
"run.d.ts",
|
|
67
|
-
"logs.js",
|
|
68
|
-
"logs.d.ts"
|
|
56
|
+
"types"
|
|
69
57
|
],
|
|
70
58
|
"exports": {
|
|
71
59
|
".": {
|
|
72
60
|
"import": "./lib/index.js",
|
|
73
61
|
"types": "./types/index.d.ts"
|
|
74
|
-
},
|
|
75
|
-
"./run": {
|
|
76
|
-
"import": "./run.js",
|
|
77
|
-
"types": "./run.d.ts"
|
|
78
|
-
},
|
|
79
|
-
"./logs": {
|
|
80
|
-
"import": "./logs.js",
|
|
81
|
-
"types": "./logs.d.ts"
|
|
82
62
|
}
|
|
83
63
|
},
|
|
84
64
|
"publishConfig": {
|
package/types/define/types.d.ts
CHANGED
|
@@ -16,10 +16,6 @@ export interface AlemonOptions {
|
|
|
16
16
|
* 事件屏蔽
|
|
17
17
|
*/
|
|
18
18
|
shieldEvent?: string[];
|
|
19
|
-
/**
|
|
20
|
-
* 是否生成json
|
|
21
|
-
*/
|
|
22
|
-
regex?: boolean;
|
|
23
19
|
/**
|
|
24
20
|
* 自定义起始符规则
|
|
25
21
|
*/
|
|
@@ -33,21 +29,13 @@ export interface AlemonOptions {
|
|
|
33
29
|
*/
|
|
34
30
|
app?: {
|
|
35
31
|
/**
|
|
36
|
-
*
|
|
32
|
+
* 是否执行
|
|
37
33
|
*/
|
|
38
34
|
init?: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* 应用名称
|
|
41
|
-
*/
|
|
42
|
-
name?: string;
|
|
43
|
-
/**
|
|
44
|
-
* 可执行的包
|
|
45
|
-
*/
|
|
46
|
-
component?: any[];
|
|
47
35
|
/**
|
|
48
36
|
* 指令预览
|
|
49
37
|
*/
|
|
50
|
-
|
|
38
|
+
regJSON?: {
|
|
51
39
|
/**
|
|
52
40
|
* 是否生成
|
|
53
41
|
* defaukt true
|
|
@@ -59,12 +47,7 @@ export interface AlemonOptions {
|
|
|
59
47
|
*/
|
|
60
48
|
address?: string;
|
|
61
49
|
};
|
|
62
|
-
|
|
63
|
-
* 重定义消息对象
|
|
64
|
-
* @param args
|
|
65
|
-
* @returns
|
|
66
|
-
*/
|
|
67
|
-
redefineMessage?: (...args: any[]) => any;
|
|
50
|
+
scripts?: string;
|
|
68
51
|
};
|
|
69
52
|
/**
|
|
70
53
|
* 插件配置
|
package/types/log/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/villa/villa.d.ts
CHANGED
|
@@ -28,32 +28,12 @@ export interface VILLAOptions {
|
|
|
28
28
|
* 端口
|
|
29
29
|
*/
|
|
30
30
|
port?: number;
|
|
31
|
-
/**
|
|
32
|
-
* 随机数大小
|
|
33
|
-
*/
|
|
34
|
-
size?: number;
|
|
35
|
-
/**
|
|
36
|
-
* 图片路由
|
|
37
|
-
*/
|
|
38
|
-
img_url?: string;
|
|
39
|
-
/**
|
|
40
|
-
* 本地缓存图地址
|
|
41
|
-
*/
|
|
42
|
-
IMAGE_DIR?: string;
|
|
43
|
-
/**
|
|
44
|
-
* 头模式
|
|
45
|
-
*/
|
|
46
|
-
http?: string;
|
|
47
31
|
}
|
|
48
32
|
export declare const defineVILLA: {
|
|
49
33
|
bot_id: string;
|
|
50
34
|
secret: string;
|
|
51
35
|
pub_key: string;
|
|
52
36
|
masterID: string;
|
|
53
|
-
http: string;
|
|
54
37
|
url: string;
|
|
55
38
|
port: number;
|
|
56
|
-
size: number;
|
|
57
|
-
img_url: string;
|
|
58
|
-
IMAGE_DIR: string;
|
|
59
39
|
};
|
package/logs.d.ts
DELETED
package/logs.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 重定义log
|
|
3
|
-
* @param fun 中间值
|
|
4
|
-
* @param prefix 前缀
|
|
5
|
-
*/
|
|
6
|
-
export function setLog(fun) {
|
|
7
|
-
const log = console.log
|
|
8
|
-
global.console.log = (...argv) => {
|
|
9
|
-
log(fun(), ...argv)
|
|
10
|
-
}
|
|
11
|
-
const info = console.info
|
|
12
|
-
global.console.info = (...argv) => {
|
|
13
|
-
info(fun(), ...argv)
|
|
14
|
-
}
|
|
15
|
-
const error = console.error
|
|
16
|
-
global.console.error = (...argv) => {
|
|
17
|
-
error(fun(), ...argv)
|
|
18
|
-
}
|
|
19
|
-
const debug = console.debug
|
|
20
|
-
global.console.debug = (...argv) => {
|
|
21
|
-
debug(fun(), ...argv)
|
|
22
|
-
}
|
|
23
|
-
}
|
package/run.d.ts
DELETED
package/run.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'child_process'
|
|
2
|
-
import { existsSync } from 'fs'
|
|
3
|
-
import { join } from 'path'
|
|
4
|
-
/**
|
|
5
|
-
* 指令运行队则
|
|
6
|
-
* @param ars 指令参数数组
|
|
7
|
-
*/
|
|
8
|
-
export function commandRun(ars) {
|
|
9
|
-
const msg = ars.join(' ')
|
|
10
|
-
const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.config.ts']
|
|
11
|
-
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '')
|
|
12
|
-
for (const item of files) {
|
|
13
|
-
if (!existsSync(join(process.cwd(), item))) {
|
|
14
|
-
console.info('no file', item)
|
|
15
|
-
continue
|
|
16
|
-
}
|
|
17
|
-
const isTypeScript = item.endsWith('.ts')
|
|
18
|
-
const command = isTypeScript ? 'ts-node' : 'node'
|
|
19
|
-
const cmd = `${command} ${item} ${argsWithoutFiles}`
|
|
20
|
-
console.info(cmd)
|
|
21
|
-
const childProcess = spawn(cmd, { shell: true })
|
|
22
|
-
childProcess.stdout.on('data', data => {
|
|
23
|
-
process.stdout.write(data.toString())
|
|
24
|
-
})
|
|
25
|
-
childProcess.stderr.on('data', data => {
|
|
26
|
-
process.stderr.write(data.toString())
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
}
|