alemonjs 1.0.19 → 1.0.21
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/build.d.ts +1 -0
- package/{bin/build.js → build.js} +20 -22
- package/lib/build.js +20 -0
- package/lib/config/index.js +5 -4
- package/lib/config/login.js +6 -4
- package/lib/core/apps.js +13 -5
- package/lib/core/configs.js +2 -6
- package/lib/core/dealmsg.js +9 -13
- package/lib/core/index.js +2 -3
- package/lib/core/plugin.js +5 -5
- package/lib/core/screenshot.js +80 -2
- package/lib/default/typings.js +1 -0
- package/lib/define/child_process.js +6 -0
- package/lib/define/command.js +6 -0
- package/lib/define/index.js +3 -1
- package/lib/index.js +15 -13
- package/lib/run.js +25 -0
- package/package.json +13 -8
- package/run.js +6 -0
- package/types/build.d.ts +1 -0
- package/types/config/index.d.ts +5 -4
- package/types/config/login.d.ts +3 -3
- package/types/config/types.d.ts +2 -1
- package/types/core/apps.d.ts +24 -1
- package/types/core/configs.d.ts +22 -0
- package/types/core/index.d.ts +2 -3
- package/types/core/plugin.d.ts +4 -4
- package/types/core/screenshot.d.ts +17 -11
- package/types/default/types.d.ts +0 -50
- package/types/default/typings.d.ts +50 -0
- package/types/define/child_process.d.ts +6 -0
- package/types/define/command.d.ts +6 -0
- package/types/define/index.d.ts +3 -1
- package/types/define/types.d.ts +2 -1
- package/types/index.d.ts +12 -10
- package/types/login.d.ts +2 -0
- package/types/run.d.ts +1 -0
- package/bin/dev.js +0 -25
- package/bin/start.js +0 -25
package/build.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function commandBuild(): Promise<void>
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})
|
|
22
|
-
})()
|
|
1
|
+
import { compilationTools } from 'alemon-rollup'
|
|
2
|
+
export async function commandBuild() {
|
|
3
|
+
const ars = process.argv.slice(2)
|
|
4
|
+
const Options = {
|
|
5
|
+
input: 'apps/**/*.ts',
|
|
6
|
+
output: 'alemon.app.js'
|
|
7
|
+
}
|
|
8
|
+
const i = ars.indexOf('--i')
|
|
9
|
+
if (i != -1) {
|
|
10
|
+
Options.input = ars[i + 1]
|
|
11
|
+
}
|
|
12
|
+
const o = ars.indexOf('--o')
|
|
13
|
+
if (ars.indexOf('--o') != -1) {
|
|
14
|
+
Options.output = ars[o + 1]
|
|
15
|
+
}
|
|
16
|
+
await compilationTools({
|
|
17
|
+
aInput: Options.input,
|
|
18
|
+
aOutput: Options.output
|
|
19
|
+
})
|
|
20
|
+
}
|
package/lib/build.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { compilationTools } from 'alemon-rollup';
|
|
2
|
+
export async function commandBuild() {
|
|
3
|
+
const ars = process.argv.slice(2);
|
|
4
|
+
const Options = {
|
|
5
|
+
input: 'apps/**/*.ts',
|
|
6
|
+
output: 'alemon.app.js'
|
|
7
|
+
};
|
|
8
|
+
const i = ars.indexOf('--i');
|
|
9
|
+
if (i != -1) {
|
|
10
|
+
Options.input = ars[i + 1];
|
|
11
|
+
}
|
|
12
|
+
const o = ars.indexOf('--o');
|
|
13
|
+
if (ars.indexOf('--o') != -1) {
|
|
14
|
+
Options.output = ars[o + 1];
|
|
15
|
+
}
|
|
16
|
+
await compilationTools({
|
|
17
|
+
aInput: Options.input,
|
|
18
|
+
aOutput: Options.output
|
|
19
|
+
});
|
|
20
|
+
}
|
package/lib/config/index.js
CHANGED
package/lib/config/login.js
CHANGED
|
@@ -8,7 +8,9 @@ import villa from '../default/login/villa.js';
|
|
|
8
8
|
import qq from '../default/login/qq.js';
|
|
9
9
|
import ntqq from '../default/login/ntqq.js';
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* *************
|
|
12
|
+
* defset-config
|
|
13
|
+
* *************
|
|
12
14
|
*/
|
|
13
15
|
const config = {
|
|
14
16
|
redis,
|
|
@@ -22,7 +24,7 @@ const config = {
|
|
|
22
24
|
puppeteer
|
|
23
25
|
};
|
|
24
26
|
/**
|
|
25
|
-
*
|
|
27
|
+
* init config
|
|
26
28
|
* @param val
|
|
27
29
|
*/
|
|
28
30
|
export function setBotConfig(val) {
|
|
@@ -54,7 +56,7 @@ export function setBotConfig(val) {
|
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
/**
|
|
57
|
-
*
|
|
59
|
+
* set
|
|
58
60
|
* @param key
|
|
59
61
|
* @param val
|
|
60
62
|
*/
|
|
@@ -78,7 +80,7 @@ export function setBotConfigByKey(key, val) {
|
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
/**
|
|
81
|
-
*
|
|
83
|
+
* get
|
|
82
84
|
* @param key
|
|
83
85
|
* @returns
|
|
84
86
|
*/
|
package/lib/core/apps.js
CHANGED
|
@@ -18,6 +18,14 @@ export function getAppPath(url) {
|
|
|
18
18
|
export function getAppName(url) {
|
|
19
19
|
return basename(getAppPath(url));
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* 创建应用对象
|
|
23
|
+
* @param url import.meta.url
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export function createApps(url) {
|
|
27
|
+
return createApp(getAppPath(url));
|
|
28
|
+
}
|
|
21
29
|
/**
|
|
22
30
|
* 创建应用对象
|
|
23
31
|
* @param AppName
|
|
@@ -52,18 +60,18 @@ export function createApp(AppName) {
|
|
|
52
60
|
* 创建应用
|
|
53
61
|
* @param app 应用对象
|
|
54
62
|
*/
|
|
55
|
-
component: (
|
|
63
|
+
component: (urlObject = {}) => {
|
|
56
64
|
try {
|
|
57
|
-
for (const item in
|
|
65
|
+
for (const item in urlObject) {
|
|
58
66
|
/**
|
|
59
67
|
* 如果该导出是class
|
|
60
68
|
*/
|
|
61
|
-
if (
|
|
69
|
+
if (urlObject[item].prototype) {
|
|
62
70
|
if (!Object.prototype.hasOwnProperty.call(apps, item)) {
|
|
63
71
|
/**
|
|
64
72
|
* 不重名
|
|
65
73
|
*/
|
|
66
|
-
apps[item] =
|
|
74
|
+
apps[item] = urlObject[item];
|
|
67
75
|
continue;
|
|
68
76
|
}
|
|
69
77
|
const T = true;
|
|
@@ -73,7 +81,7 @@ export function createApp(AppName) {
|
|
|
73
81
|
/**
|
|
74
82
|
* 不重名
|
|
75
83
|
*/
|
|
76
|
-
apps[keyName] =
|
|
84
|
+
apps[keyName] = urlObject[item];
|
|
77
85
|
/**
|
|
78
86
|
* 重置为0
|
|
79
87
|
*/
|
package/lib/core/configs.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
const ApplicationProcessingConfiguration = {
|
|
2
|
-
// 根目录
|
|
3
2
|
dir: '/application',
|
|
4
|
-
// 主函数
|
|
5
3
|
main: '/index',
|
|
6
4
|
type: 'ts',
|
|
7
|
-
// 打开正则
|
|
8
5
|
openRegex: /./,
|
|
9
|
-
// 屏蔽正则
|
|
10
6
|
closeRegex: undefined,
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
route: '/public/defset',
|
|
8
|
+
regex: true
|
|
13
9
|
};
|
|
14
10
|
export function setAppProCoinfg(key, val) {
|
|
15
11
|
// 当前仅当同属性名的时候才会覆盖默认配置
|
package/lib/core/dealmsg.js
CHANGED
|
@@ -8,7 +8,7 @@ import { EventEnum } from './typings.js';
|
|
|
8
8
|
import { conversationHandlers, getConversationState } from './dialogue.js';
|
|
9
9
|
import { getAppProCoinfg } from './configs.js';
|
|
10
10
|
const Command = {};
|
|
11
|
-
const
|
|
11
|
+
const CommandNotMessage = {};
|
|
12
12
|
/**
|
|
13
13
|
* 机器人统计
|
|
14
14
|
*/
|
|
@@ -129,7 +129,7 @@ async function synthesis(AppsObj, appname) {
|
|
|
129
129
|
priority
|
|
130
130
|
});
|
|
131
131
|
// 保存
|
|
132
|
-
|
|
132
|
+
CommandNotMessage[event].push({
|
|
133
133
|
event: event,
|
|
134
134
|
eventType: eventType,
|
|
135
135
|
priority,
|
|
@@ -159,13 +159,9 @@ async function loadPlugins(dir) {
|
|
|
159
159
|
const apps = flies
|
|
160
160
|
.filter(item => open.test(item))
|
|
161
161
|
.filter(item => {
|
|
162
|
-
if (!close)
|
|
162
|
+
if (!close)
|
|
163
163
|
return true;
|
|
164
|
-
|
|
165
|
-
if (close.test(item)) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
return true;
|
|
164
|
+
return !close.test(item);
|
|
169
165
|
});
|
|
170
166
|
/**
|
|
171
167
|
* 动态扫描
|
|
@@ -190,7 +186,7 @@ function dataInit() {
|
|
|
190
186
|
for (const item of EventEnum) {
|
|
191
187
|
if (isNaN(Number(item))) {
|
|
192
188
|
Command[item] = [];
|
|
193
|
-
|
|
189
|
+
CommandNotMessage[item] = [];
|
|
194
190
|
}
|
|
195
191
|
}
|
|
196
192
|
return;
|
|
@@ -218,8 +214,8 @@ export async function appsInit() {
|
|
|
218
214
|
Command[val] = lodash.orderBy(Command[val], ['priority'], ['asc']);
|
|
219
215
|
}
|
|
220
216
|
// 排序
|
|
221
|
-
for (const val in
|
|
222
|
-
|
|
217
|
+
for (const val in CommandNotMessage) {
|
|
218
|
+
CommandNotMessage[val] = lodash.orderBy(CommandNotMessage[val], ['priority'], ['asc']);
|
|
223
219
|
}
|
|
224
220
|
// 排序之后把所有正则变成一条正则
|
|
225
221
|
const mergedRegexArr = [];
|
|
@@ -323,10 +319,10 @@ export async function InstructionMatching(e) {
|
|
|
323
319
|
* @returns
|
|
324
320
|
*/
|
|
325
321
|
export async function typeMessage(e) {
|
|
326
|
-
if (!
|
|
322
|
+
if (!CommandNotMessage[e.event])
|
|
327
323
|
return true;
|
|
328
324
|
// 循环查找
|
|
329
|
-
for (const data of
|
|
325
|
+
for (const data of CommandNotMessage[e.event]) {
|
|
330
326
|
if (e.eventType != data.eventType)
|
|
331
327
|
continue;
|
|
332
328
|
try {
|
package/lib/core/index.js
CHANGED
package/lib/core/plugin.js
CHANGED
|
@@ -27,17 +27,17 @@ export class plugin {
|
|
|
27
27
|
*/
|
|
28
28
|
rule;
|
|
29
29
|
/**
|
|
30
|
-
* @param name 类名标记
|
|
31
|
-
* @param event 事件类型
|
|
32
|
-
* @param eventType 消息类型
|
|
33
|
-
* @param priority 优先级
|
|
30
|
+
* @param name 类名标记 default app-name
|
|
31
|
+
* @param event 事件类型 default MESSAGES
|
|
32
|
+
* @param eventType 消息类型 default CREATE
|
|
33
|
+
* @param priority 优先级 越小优越高 default 9000
|
|
34
34
|
* @param rule.reg 命令正则 RegExp | string
|
|
35
35
|
* @param rule.fnc 命令函数 function
|
|
36
36
|
* @param rule.dsc 指令示范 sdc
|
|
37
37
|
* @param rule.doc 指令文档 doc
|
|
38
38
|
* @param rule.priority 优先级 数字越小优先级越高
|
|
39
39
|
*/
|
|
40
|
-
constructor({ name = '
|
|
40
|
+
constructor({ name = 'app-name', event = 'MESSAGES', eventType = 'CREATE', priority = 9000, rule = [] }) {
|
|
41
41
|
this.name = name;
|
|
42
42
|
this.event = event;
|
|
43
43
|
this.eventType = eventType;
|
package/lib/core/screenshot.js
CHANGED
|
@@ -48,8 +48,86 @@ function watchCT(tplFile) {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* 如果control
|
|
52
|
-
* @param
|
|
51
|
+
* 如果control为真则需重新重新渲染
|
|
52
|
+
* @param AppName
|
|
53
|
+
* @param tplFile
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
export function createHtml(AppName, tplFile) {
|
|
57
|
+
const appDir = getAppProCoinfg('dir');
|
|
58
|
+
/**
|
|
59
|
+
* 插件路径
|
|
60
|
+
*/
|
|
61
|
+
const basePath = join(process.cwd(), appDir, AppName);
|
|
62
|
+
/**
|
|
63
|
+
* 数据路径
|
|
64
|
+
*/
|
|
65
|
+
const dataPath = join(process.cwd(), '.data', AppName);
|
|
66
|
+
/**
|
|
67
|
+
* 写入地址
|
|
68
|
+
*/
|
|
69
|
+
const AdressHtml = join(dataPath, basename(tplFile));
|
|
70
|
+
/**
|
|
71
|
+
* 确保写入目录存在
|
|
72
|
+
*/
|
|
73
|
+
mkdirSync(dataPath, { recursive: true });
|
|
74
|
+
/**
|
|
75
|
+
* 判断初始模板是否改变
|
|
76
|
+
*/
|
|
77
|
+
let control = false;
|
|
78
|
+
/**
|
|
79
|
+
* 缓存不存在
|
|
80
|
+
*/
|
|
81
|
+
if (!html[tplFile]) {
|
|
82
|
+
/**
|
|
83
|
+
* 读取文件
|
|
84
|
+
*/
|
|
85
|
+
html[tplFile] = readFileSync(tplFile, 'utf8');
|
|
86
|
+
/**
|
|
87
|
+
* 读取后监听文件
|
|
88
|
+
*/
|
|
89
|
+
watchCT(tplFile);
|
|
90
|
+
control = true;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 模板更改和数据更改都会生成生成html
|
|
94
|
+
*/
|
|
95
|
+
if (control) {
|
|
96
|
+
const reg = /url\(['"](@[^'"]+)['"]\)|href=['"](@[^'"]+)['"]|src=['"](@[^'"]+)['"]/g;
|
|
97
|
+
absolutePathTemplateCache[tplFile] = html[tplFile].replace(reg, (match, urlPath, hrefPath, srcPath) => {
|
|
98
|
+
const relativePath = urlPath ?? hrefPath ?? srcPath;
|
|
99
|
+
/**
|
|
100
|
+
* 去掉路径开头的 @ 符号
|
|
101
|
+
* 转义\/
|
|
102
|
+
*/
|
|
103
|
+
const absolutePath = join(basePath, relativePath.substr(1)).replace(/\\/g, '/');
|
|
104
|
+
if (urlPath)
|
|
105
|
+
return `url('${absolutePath}')`;
|
|
106
|
+
if (hrefPath)
|
|
107
|
+
return `href='${absolutePath}'`;
|
|
108
|
+
if (srcPath)
|
|
109
|
+
return `src='${absolutePath}'`;
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* 打印反馈生成后的地址
|
|
113
|
+
*/
|
|
114
|
+
console.info('[HTML][CREATE]', AdressHtml);
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
control,
|
|
118
|
+
// 模板地址
|
|
119
|
+
AdressHtml,
|
|
120
|
+
// 模板字符
|
|
121
|
+
template: absolutePathTemplateCache[tplFile]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 如果control为真则需重新渲染
|
|
126
|
+
* 如果key不变而数组元素改变请勿使用缓存
|
|
127
|
+
* @param Options AppName 应用名
|
|
128
|
+
* @param Options tplFile 模板地址模板地址
|
|
129
|
+
* @param Options data 任意数据对象
|
|
130
|
+
* @deprecated 已废弃,建议使用createHtml
|
|
53
131
|
* @returns
|
|
54
132
|
*/
|
|
55
133
|
export function createStr(Options) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param name
|
|
5
|
+
* @param file
|
|
6
|
+
* @param ars
|
|
7
|
+
*/
|
|
2
8
|
export function nodeScripts(name = 'node', file = '', ars = []) {
|
|
3
9
|
const command = spawn(`${name} ${file} ${ars.join(' ')}`, { shell: true });
|
|
4
10
|
command.stdout.on('data', data => {
|
package/lib/define/command.js
CHANGED
package/lib/define/index.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -3,31 +3,33 @@ if (process.argv.slice(2).includes('discord') &&
|
|
|
3
3
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* *************
|
|
7
|
+
* core
|
|
8
|
+
* *************
|
|
9
9
|
*/
|
|
10
10
|
export * from './core/index.js';
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* *************
|
|
13
|
+
* define
|
|
14
|
+
* *************
|
|
15
15
|
*/
|
|
16
16
|
export * from './define/index.js';
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* *************
|
|
19
|
+
* config system
|
|
20
|
+
* *************
|
|
21
21
|
*/
|
|
22
22
|
export * from './config/index.js';
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* *************
|
|
25
|
+
* login
|
|
26
|
+
* *************
|
|
25
27
|
*/
|
|
26
28
|
export * from './login.js';
|
|
27
29
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
30
|
+
* *************
|
|
31
|
+
* exit
|
|
32
|
+
* *************
|
|
31
33
|
*/
|
|
32
34
|
process.on('SIGINT', signals => {
|
|
33
35
|
console.info(signals);
|
package/lib/run.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
export function commandRun(ars) {
|
|
5
|
+
const msg = ars.join(' ');
|
|
6
|
+
const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.config.ts'];
|
|
7
|
+
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '');
|
|
8
|
+
for (const item of files) {
|
|
9
|
+
if (!existsSync(join(process.cwd(), item))) {
|
|
10
|
+
console.log('[NO FILE]', item);
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const isTypeScript = item.endsWith('.ts');
|
|
14
|
+
const command = isTypeScript ? 'npx ts-node' : 'node';
|
|
15
|
+
const cmd = `${command} ${item} ${argsWithoutFiles}`;
|
|
16
|
+
console.log('[alemonjs]', cmd);
|
|
17
|
+
const childProcess = spawn(cmd, { shell: true });
|
|
18
|
+
childProcess.stdout.on('data', data => {
|
|
19
|
+
process.stdout.write(data.toString());
|
|
20
|
+
});
|
|
21
|
+
childProcess.stderr.on('data', data => {
|
|
22
|
+
process.stderr.write(data.toString());
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alemonjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"description": "阿柠檬框架",
|
|
5
5
|
"author": "ningmengchongshui",
|
|
6
6
|
"license": "GPL-2.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"app": "alemonjs",
|
|
10
|
-
"dev": "alemonjs dev",
|
|
11
9
|
"tsc": "npx tsc",
|
|
12
10
|
"format": "prettier --write .",
|
|
13
11
|
"lint": "eslint . --ext .js,.ts --fix --ignore-path .gitignore"
|
|
@@ -50,20 +48,27 @@
|
|
|
50
48
|
"lib",
|
|
51
49
|
"types",
|
|
52
50
|
"run.js",
|
|
53
|
-
"run.d.ts"
|
|
51
|
+
"run.d.ts",
|
|
52
|
+
"build.js",
|
|
53
|
+
"build.d.ts"
|
|
54
54
|
],
|
|
55
55
|
"exports": {
|
|
56
56
|
".": "./lib/index.js",
|
|
57
57
|
"./run": {
|
|
58
58
|
"import": "./run.js",
|
|
59
59
|
"types": "./run.d.ts"
|
|
60
|
+
},
|
|
61
|
+
"./build": {
|
|
62
|
+
"import": "./build.js",
|
|
63
|
+
"types": "./build.d.ts"
|
|
64
|
+
},
|
|
65
|
+
"./core": {
|
|
66
|
+
"import": "./core.js",
|
|
67
|
+
"types": "./core.d.ts"
|
|
60
68
|
}
|
|
61
69
|
},
|
|
62
70
|
"bin": {
|
|
63
|
-
"alemonjs": "bin/main.js"
|
|
64
|
-
"alemonjs-start": "bin/start.js",
|
|
65
|
-
"alemonjs-build": "bin/build.js",
|
|
66
|
-
"alemonjs-dev": "bin/dev.js"
|
|
71
|
+
"alemonjs": "bin/main.js"
|
|
67
72
|
},
|
|
68
73
|
"publishConfig": {
|
|
69
74
|
"registry": "https://registry.npmjs.org"
|
package/run.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { spawn } from 'child_process'
|
|
2
|
+
import { existsSync } from 'fs'
|
|
3
|
+
import { join } from 'path'
|
|
2
4
|
export function commandRun(ars) {
|
|
3
5
|
const msg = ars.join(' ')
|
|
4
6
|
const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.config.ts']
|
|
5
7
|
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '')
|
|
6
8
|
for (const item of files) {
|
|
9
|
+
if (!existsSync(join(process.cwd(), item))) {
|
|
10
|
+
console.log('[NO FILE]', item)
|
|
11
|
+
continue
|
|
12
|
+
}
|
|
7
13
|
const isTypeScript = item.endsWith('.ts')
|
|
8
14
|
const command = isTypeScript ? 'npx ts-node' : 'node'
|
|
9
15
|
const cmd = `${command} ${item} ${argsWithoutFiles}`
|
package/types/build.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function commandBuild(): Promise<void>;
|
package/types/config/index.d.ts
CHANGED
package/types/config/login.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { ConfigType } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* init config
|
|
4
4
|
* @param val
|
|
5
5
|
*/
|
|
6
6
|
export declare function setBotConfig(val: ConfigType): void;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* set
|
|
9
9
|
* @param key
|
|
10
10
|
* @param val
|
|
11
11
|
*/
|
|
12
12
|
export declare function setBotConfigByKey<T extends keyof ConfigType>(key: T, val: ConfigType[T]): void;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* get
|
|
15
15
|
* @param key
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
package/types/config/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PuppeteerLaunchOptions } from 'puppeteer';
|
|
2
|
-
import { DiscordOptions, KookOptionsg,
|
|
2
|
+
import { DiscordOptions, KookOptionsg, NtQQOptions, QqGuildOptions, VillaOptions, ServerOptions } from '../default/types.js';
|
|
3
|
+
import { MysqlOptions, RedisOptions } from '../default/typings.js';
|
|
3
4
|
/**
|
|
4
5
|
* ******
|
|
5
6
|
* config
|
package/types/core/apps.d.ts
CHANGED
|
@@ -10,6 +10,29 @@ export declare function getAppPath(url: string | URL): string;
|
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
12
|
export declare function getAppName(url: string | URL): string;
|
|
13
|
+
/**
|
|
14
|
+
* 创建应用对象
|
|
15
|
+
* @param url import.meta.url
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare function createApps(url: string): {
|
|
19
|
+
/**
|
|
20
|
+
* 重定义消息
|
|
21
|
+
* @param fnc
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
setMessage: (fnc: (...args: any[]) => any) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 创建应用
|
|
27
|
+
* @param app 应用对象
|
|
28
|
+
*/
|
|
29
|
+
component: (urlObject?: object) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* 挂起应用
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
mount: () => void;
|
|
35
|
+
};
|
|
13
36
|
/**
|
|
14
37
|
* 创建应用对象
|
|
15
38
|
* @param AppName
|
|
@@ -26,7 +49,7 @@ export declare function createApp(AppName: string): {
|
|
|
26
49
|
* 创建应用
|
|
27
50
|
* @param app 应用对象
|
|
28
51
|
*/
|
|
29
|
-
component: (
|
|
52
|
+
component: (urlObject?: object) => boolean;
|
|
30
53
|
/**
|
|
31
54
|
* 挂起应用
|
|
32
55
|
* @returns
|
package/types/core/configs.d.ts
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
interface ApplicationProcessingOpsion {
|
|
2
|
+
/**
|
|
3
|
+
* 根目录
|
|
4
|
+
*/
|
|
2
5
|
dir: string;
|
|
6
|
+
/**
|
|
7
|
+
* 主文件
|
|
8
|
+
*/
|
|
3
9
|
main: string;
|
|
10
|
+
/**
|
|
11
|
+
* 主文件类型
|
|
12
|
+
*/
|
|
4
13
|
type: 'ts' | 'js';
|
|
14
|
+
/**
|
|
15
|
+
* 匹配正则
|
|
16
|
+
*/
|
|
5
17
|
openRegex: RegExp;
|
|
18
|
+
/**
|
|
19
|
+
* 不匹配正则
|
|
20
|
+
*/
|
|
6
21
|
closeRegex: RegExp | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* 指令json路由
|
|
24
|
+
*/
|
|
7
25
|
route: string;
|
|
26
|
+
/**
|
|
27
|
+
* 是否生成json
|
|
28
|
+
*/
|
|
29
|
+
regex: boolean;
|
|
8
30
|
}
|
|
9
31
|
export declare function setAppProCoinfg<T extends keyof ApplicationProcessingOpsion>(key: T, val: ApplicationProcessingOpsion[T]): void;
|
|
10
32
|
export declare function getAppProCoinfg<T extends keyof ApplicationProcessingOpsion>(key: T): ApplicationProcessingOpsion[T];
|
package/types/core/index.d.ts
CHANGED
package/types/core/plugin.d.ts
CHANGED
|
@@ -64,10 +64,10 @@ export declare class plugin {
|
|
|
64
64
|
*/
|
|
65
65
|
rule?: PluginRuleType[];
|
|
66
66
|
/**
|
|
67
|
-
* @param name 类名标记
|
|
68
|
-
* @param event 事件类型
|
|
69
|
-
* @param eventType 消息类型
|
|
70
|
-
* @param priority 优先级
|
|
67
|
+
* @param name 类名标记 default app-name
|
|
68
|
+
* @param event 事件类型 default MESSAGES
|
|
69
|
+
* @param eventType 消息类型 default CREATE
|
|
70
|
+
* @param priority 优先级 越小优越高 default 9000
|
|
71
71
|
* @param rule.reg 命令正则 RegExp | string
|
|
72
72
|
* @param rule.fnc 命令函数 function
|
|
73
73
|
* @param rule.dsc 指令示范 sdc
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 如果control
|
|
3
|
-
* @param
|
|
2
|
+
* 如果control为真则需重新重新渲染
|
|
3
|
+
* @param AppName
|
|
4
|
+
* @param tplFile
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function createHtml(AppName: string, tplFile: string): {
|
|
8
|
+
control: boolean;
|
|
9
|
+
AdressHtml: string;
|
|
10
|
+
template: any;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 如果control为真则需重新渲染
|
|
14
|
+
* 如果key不变而数组元素改变请勿使用缓存
|
|
15
|
+
* @param Options AppName 应用名
|
|
16
|
+
* @param Options tplFile 模板地址模板地址
|
|
17
|
+
* @param Options data 任意数据对象
|
|
18
|
+
* @deprecated 已废弃,建议使用createHtml
|
|
4
19
|
* @returns
|
|
5
20
|
*/
|
|
6
21
|
export declare function createStr(Options: {
|
|
7
|
-
/**
|
|
8
|
-
* 插件名
|
|
9
|
-
*/
|
|
10
22
|
AppName: string;
|
|
11
|
-
/**
|
|
12
|
-
* 模板地址模板地址
|
|
13
|
-
*/
|
|
14
23
|
tplFile: string;
|
|
15
|
-
/**
|
|
16
|
-
* 任意数据对象
|
|
17
|
-
*/
|
|
18
24
|
data?: any;
|
|
19
25
|
}): {
|
|
20
26
|
control: boolean;
|
package/types/default/types.d.ts
CHANGED
|
@@ -27,56 +27,6 @@ export interface LoginOptions {
|
|
|
27
27
|
*/
|
|
28
28
|
ntqq?: NtQQOptions;
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
31
|
-
* ****
|
|
32
|
-
* redis
|
|
33
|
-
* *****
|
|
34
|
-
*/
|
|
35
|
-
export interface RedisOptions {
|
|
36
|
-
/**
|
|
37
|
-
* 地址
|
|
38
|
-
*/
|
|
39
|
-
host?: string;
|
|
40
|
-
/**
|
|
41
|
-
* 端口
|
|
42
|
-
*/
|
|
43
|
-
port?: number;
|
|
44
|
-
/**
|
|
45
|
-
* 密码
|
|
46
|
-
*/
|
|
47
|
-
password?: string;
|
|
48
|
-
/**
|
|
49
|
-
* 数据库名
|
|
50
|
-
*/
|
|
51
|
-
db?: number;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* ***
|
|
55
|
-
* mysql
|
|
56
|
-
* **
|
|
57
|
-
*/
|
|
58
|
-
export interface MysqlOptions {
|
|
59
|
-
/**
|
|
60
|
-
* 地址
|
|
61
|
-
*/
|
|
62
|
-
host?: string;
|
|
63
|
-
/**
|
|
64
|
-
* 端口
|
|
65
|
-
*/
|
|
66
|
-
port?: number;
|
|
67
|
-
/**
|
|
68
|
-
* 用户名
|
|
69
|
-
*/
|
|
70
|
-
user?: string;
|
|
71
|
-
/**
|
|
72
|
-
* 密码
|
|
73
|
-
*/
|
|
74
|
-
password?: string;
|
|
75
|
-
/**
|
|
76
|
-
* 数据库名
|
|
77
|
-
*/
|
|
78
|
-
database?: string;
|
|
79
|
-
}
|
|
80
30
|
/**
|
|
81
31
|
* **
|
|
82
32
|
* discord
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ****
|
|
3
|
+
* redis
|
|
4
|
+
* *****
|
|
5
|
+
*/
|
|
6
|
+
export interface RedisOptions {
|
|
7
|
+
/**
|
|
8
|
+
* 地址
|
|
9
|
+
*/
|
|
10
|
+
host?: string;
|
|
11
|
+
/**
|
|
12
|
+
* 端口
|
|
13
|
+
*/
|
|
14
|
+
port?: number;
|
|
15
|
+
/**
|
|
16
|
+
* 密码
|
|
17
|
+
*/
|
|
18
|
+
password?: string;
|
|
19
|
+
/**
|
|
20
|
+
* 数据库名
|
|
21
|
+
*/
|
|
22
|
+
db?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* ***
|
|
26
|
+
* mysql
|
|
27
|
+
* **
|
|
28
|
+
*/
|
|
29
|
+
export interface MysqlOptions {
|
|
30
|
+
/**
|
|
31
|
+
* 地址
|
|
32
|
+
*/
|
|
33
|
+
host?: string;
|
|
34
|
+
/**
|
|
35
|
+
* 端口
|
|
36
|
+
*/
|
|
37
|
+
port?: number;
|
|
38
|
+
/**
|
|
39
|
+
* 用户名
|
|
40
|
+
*/
|
|
41
|
+
user?: string;
|
|
42
|
+
/**
|
|
43
|
+
* 密码
|
|
44
|
+
*/
|
|
45
|
+
password?: string;
|
|
46
|
+
/**
|
|
47
|
+
* 数据库名
|
|
48
|
+
*/
|
|
49
|
+
database?: string;
|
|
50
|
+
}
|
package/types/define/index.d.ts
CHANGED
package/types/define/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PuppeteerLaunchOptions } from 'puppeteer';
|
|
2
|
-
import { LoginOptions,
|
|
2
|
+
import { LoginOptions, ServerOptions } from '../default/types.js';
|
|
3
|
+
import { MysqlOptions, RedisOptions } from '../default/typings.js';
|
|
3
4
|
/**
|
|
4
5
|
* ******
|
|
5
6
|
* config
|
package/types/index.d.ts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* *************
|
|
3
|
+
* core
|
|
4
|
+
* *************
|
|
5
5
|
*/
|
|
6
6
|
export * from './core/index.js';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* *************
|
|
9
|
+
* define
|
|
10
|
+
* *************
|
|
11
11
|
*/
|
|
12
12
|
export * from './define/index.js';
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* *************
|
|
15
|
+
* config system
|
|
16
|
+
* *************
|
|
17
17
|
*/
|
|
18
18
|
export * from './config/index.js';
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* *************
|
|
21
|
+
* login
|
|
22
|
+
* *************
|
|
21
23
|
*/
|
|
22
24
|
export * from './login.js';
|
package/types/login.d.ts
CHANGED
package/types/run.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function commandRun(ars: string[]): void;
|
package/bin/dev.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { spawn } from 'child_process'
|
|
4
|
-
import { existsSync } from 'fs'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
const ars = process.argv.slice(2).push('dev')
|
|
7
|
-
const msg = ars.join(' ')
|
|
8
|
-
const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['alemon.config.ts']
|
|
9
|
-
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '')
|
|
10
|
-
for (const item of files) {
|
|
11
|
-
if (!existsSync(join(process.cwd(), item))) {
|
|
12
|
-
console.log('[NO FILE]', item)
|
|
13
|
-
continue
|
|
14
|
-
}
|
|
15
|
-
// nodemon alemon.config.ts dev
|
|
16
|
-
const cmd = `nodemon ${item} ${argsWithoutFiles}`
|
|
17
|
-
console.log('[alemonjs]', cmd)
|
|
18
|
-
const childProcess = spawn(cmd, { shell: true })
|
|
19
|
-
childProcess.stdout.on('data', data => {
|
|
20
|
-
process.stdout.write(data.toString())
|
|
21
|
-
})
|
|
22
|
-
childProcess.stderr.on('data', data => {
|
|
23
|
-
process.stderr.write(data.toString())
|
|
24
|
-
})
|
|
25
|
-
}
|
package/bin/start.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { spawn } from 'child_process'
|
|
4
|
-
import { existsSync } from 'fs'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
const ars = process.argv.slice(2)
|
|
7
|
-
const msg = ars.join(' ')
|
|
8
|
-
const files = msg.match(/(\S+\.js|\S+\.ts)/g) ?? ['pm2.config.cjs']
|
|
9
|
-
const argsWithoutFiles = msg.replace(/(\S+\.js|\S+\.ts)/g, '')
|
|
10
|
-
for (const item of files) {
|
|
11
|
-
if (!existsSync(join(process.cwd(), item))) {
|
|
12
|
-
console.log('[NO FILE]', item)
|
|
13
|
-
continue
|
|
14
|
-
}
|
|
15
|
-
// pm2 startOrRestart pm2.config.cjs
|
|
16
|
-
const cmd = `pm2 startOrRestart ${item} ${argsWithoutFiles}`
|
|
17
|
-
console.log('[alemonjs]', cmd)
|
|
18
|
-
const childProcess = spawn(cmd, { shell: true })
|
|
19
|
-
childProcess.stdout.on('data', data => {
|
|
20
|
-
process.stdout.write(data.toString())
|
|
21
|
-
})
|
|
22
|
-
childProcess.stderr.on('data', data => {
|
|
23
|
-
process.stderr.write(data.toString())
|
|
24
|
-
})
|
|
25
|
-
}
|