alemonjs 1.0.4 → 1.0.6
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/alemon/dealmsg.js +14 -12
- package/lib/default/pup.js +1 -2
- package/lib/define/main.js +31 -23
- package/lib/define/plugin.js +61 -21
- package/package.json +1 -1
- package/types/alemon/dealmsg.d.ts +8 -0
- package/types/define/plugin.d.ts +2 -1
package/lib/alemon/dealmsg.js
CHANGED
|
@@ -49,6 +49,16 @@ export function setAppRegex(val) {
|
|
|
49
49
|
appRegexClose = RegexClose;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* 得到插件名匹配模式
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
export function getAppRegex() {
|
|
57
|
+
return {
|
|
58
|
+
RegexOpen: appRegex,
|
|
59
|
+
RegexClose: appRegexClose
|
|
60
|
+
};
|
|
61
|
+
}
|
|
52
62
|
/**
|
|
53
63
|
* 设置指令json地址
|
|
54
64
|
* @param rt '/public/defset'
|
|
@@ -197,22 +207,14 @@ async function synthesis(AppsObj, appname, belong) {
|
|
|
197
207
|
* @param dir
|
|
198
208
|
*/
|
|
199
209
|
async function loadPlugins(dir) {
|
|
200
|
-
|
|
201
|
-
* ********************
|
|
202
|
-
* 没有该文件夹直接返回
|
|
203
|
-
* *******************
|
|
204
|
-
*/
|
|
205
|
-
if (!existsSync(dir)) {
|
|
210
|
+
if (!existsSync(dir))
|
|
206
211
|
return;
|
|
207
|
-
}
|
|
208
212
|
const flies = readdirSync(dir);
|
|
209
|
-
if (flies.length == 0)
|
|
213
|
+
if (flies.length == 0)
|
|
210
214
|
return;
|
|
211
|
-
|
|
212
|
-
const app = flies
|
|
215
|
+
const apps = flies
|
|
213
216
|
.filter(item => appRegex.test(item))
|
|
214
217
|
.filter(item => {
|
|
215
|
-
// 关闭符合条件的
|
|
216
218
|
if (!appRegexClose) {
|
|
217
219
|
return true;
|
|
218
220
|
}
|
|
@@ -224,7 +226,7 @@ async function loadPlugins(dir) {
|
|
|
224
226
|
/**
|
|
225
227
|
* 识别并执行插件
|
|
226
228
|
*/
|
|
227
|
-
for await (const appname of
|
|
229
|
+
for await (const appname of apps) {
|
|
228
230
|
if (existsSync(`${dir}/${appname}/index.ts`)) {
|
|
229
231
|
/**
|
|
230
232
|
* 优先考虑ts
|
package/lib/default/pup.js
CHANGED
package/lib/define/main.js
CHANGED
|
@@ -5,6 +5,8 @@ import { nodeScripts } from './child_process.js';
|
|
|
5
5
|
import { ClientAPIByQQ as ClientByNTQQ } from '../ntqq/sdk/index.js';
|
|
6
6
|
import { createApp, loadInit, setBotConfigByKey, setLanchConfig, getPupPath, getBotConfigByKey, setAppRegex } from '../index.js';
|
|
7
7
|
import { command } from './command.js';
|
|
8
|
+
import { copyAppsFile } from './plugin.js';
|
|
9
|
+
import { join } from 'path';
|
|
8
10
|
// 设置ntqq独立鉴权路径
|
|
9
11
|
export const setAuthenticationByNtqq = ClientByNTQQ.setAuthentication;
|
|
10
12
|
let appDir = 'application';
|
|
@@ -36,16 +38,6 @@ export async function defineAlemonConfig(Options) {
|
|
|
36
38
|
if (!Options)
|
|
37
39
|
return;
|
|
38
40
|
OptionsCache = Options;
|
|
39
|
-
/**
|
|
40
|
-
* **********
|
|
41
|
-
* 运行前执行
|
|
42
|
-
* **********
|
|
43
|
-
*/
|
|
44
|
-
if (Options?.command) {
|
|
45
|
-
for await (const item of Options.command) {
|
|
46
|
-
await command(item);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
41
|
/**
|
|
50
42
|
* *******
|
|
51
43
|
* pup配置
|
|
@@ -125,7 +117,12 @@ export async function defineAlemonConfig(Options) {
|
|
|
125
117
|
await rebotMap[item]();
|
|
126
118
|
}
|
|
127
119
|
}
|
|
128
|
-
|
|
120
|
+
/**
|
|
121
|
+
* ********
|
|
122
|
+
* 登录提示
|
|
123
|
+
* ********
|
|
124
|
+
*/
|
|
125
|
+
if (!Options?.login || Object.keys(Options?.login ?? {}).length == 0) {
|
|
129
126
|
console.info('[LOGIN] 无登录配置');
|
|
130
127
|
}
|
|
131
128
|
/**
|
|
@@ -150,6 +147,14 @@ export async function defineAlemonConfig(Options) {
|
|
|
150
147
|
RegexClose: Options?.plugin?.RegexClose
|
|
151
148
|
});
|
|
152
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* ***************
|
|
152
|
+
* 是否同步文件
|
|
153
|
+
* ***************
|
|
154
|
+
*/
|
|
155
|
+
if (Options?.plugin?.mountFile) {
|
|
156
|
+
copyAppsFile(join(process.cwd(), `/${address}`));
|
|
157
|
+
}
|
|
153
158
|
/**
|
|
154
159
|
* ************
|
|
155
160
|
* 扫描插件
|
|
@@ -183,22 +188,25 @@ export async function defineAlemonConfig(Options) {
|
|
|
183
188
|
}
|
|
184
189
|
app.mount('#app');
|
|
185
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* **********
|
|
193
|
+
* 附加执行
|
|
194
|
+
* **********
|
|
195
|
+
*/
|
|
196
|
+
if (Options?.command) {
|
|
197
|
+
for await (const item of Options.command) {
|
|
198
|
+
await command(item);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
186
201
|
/**
|
|
187
202
|
* ***************
|
|
188
|
-
*
|
|
189
|
-
* 不会执行附加脚本
|
|
203
|
+
* 附加脚本
|
|
190
204
|
* ***************
|
|
191
205
|
*/
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
*/
|
|
197
|
-
if (Options?.scripts) {
|
|
198
|
-
for await (const item of Options.scripts) {
|
|
199
|
-
const name = item?.name ?? 'node';
|
|
200
|
-
nodeScripts(name, item?.file, item?.ars ?? []);
|
|
201
|
-
}
|
|
206
|
+
if (Options?.scripts) {
|
|
207
|
+
for await (const item of Options.scripts) {
|
|
208
|
+
const name = item?.name ?? 'node';
|
|
209
|
+
nodeScripts(name, item?.file, item?.ars ?? []);
|
|
202
210
|
}
|
|
203
211
|
}
|
|
204
212
|
return;
|
package/lib/define/plugin.js
CHANGED
|
@@ -1,25 +1,65 @@
|
|
|
1
|
+
import { existsSync, readdirSync, copyFileSync, mkdirSync } from 'fs';
|
|
2
|
+
import { getAppRegex } from '../alemon/index.js';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* 遍历复制方法
|
|
6
|
+
*/
|
|
7
|
+
const copyFiles = (source, destination) => {
|
|
8
|
+
if (!existsSync(destination)) {
|
|
9
|
+
mkdirSync(destination, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
const files = readdirSync(source);
|
|
12
|
+
for (const file of files) {
|
|
13
|
+
const sourcePath = join(source, file);
|
|
14
|
+
const destinationPath = join(destination, file);
|
|
15
|
+
copyFileSync(sourcePath, destinationPath);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
1
18
|
/**
|
|
2
19
|
* 同步挂载文件
|
|
20
|
+
* @param dir 插件目录
|
|
3
21
|
*/
|
|
4
|
-
export function copyAppsFile() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
export function copyAppsFile(dir) {
|
|
23
|
+
if (!existsSync(dir))
|
|
24
|
+
return;
|
|
25
|
+
const flies = readdirSync(dir);
|
|
26
|
+
if (flies.length === 0)
|
|
27
|
+
return;
|
|
28
|
+
const { RegexOpen, RegexClose } = getAppRegex();
|
|
29
|
+
// 插件名
|
|
30
|
+
const apps = flies
|
|
31
|
+
.filter(item => RegexOpen.test(item))
|
|
32
|
+
.filter(item => {
|
|
33
|
+
// 关闭符合条件的
|
|
34
|
+
if (!RegexClose) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (RegexClose.test(item)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
for (const appname of apps) {
|
|
43
|
+
const appPath = join(dir, appname);
|
|
44
|
+
if (existsSync(`${appPath}/assets`)) {
|
|
45
|
+
const originalAddress = `${appPath}/assets`;
|
|
46
|
+
const destinationAddress = join(process.cwd(), `/public/.${appname}/assets`);
|
|
47
|
+
copyFiles(originalAddress, destinationAddress);
|
|
48
|
+
}
|
|
49
|
+
if (existsSync(`${appPath}/pages`)) {
|
|
50
|
+
const originalAddress = `${appPath}/pages`;
|
|
51
|
+
const destinationAddress = join(process.cwd(), `/public/.${appname}/pages`);
|
|
52
|
+
copyFiles(originalAddress, destinationAddress);
|
|
53
|
+
}
|
|
54
|
+
if (existsSync(`${appPath}/plugins`)) {
|
|
55
|
+
const originalAddress = `${appPath}/plugins`;
|
|
56
|
+
const destinationAddress = join(process.cwd(), `/public/.${appname}/plugins`);
|
|
57
|
+
copyFiles(originalAddress, destinationAddress);
|
|
58
|
+
}
|
|
59
|
+
if (existsSync(`${appPath}/server`)) {
|
|
60
|
+
const originalAddress = `${appPath}/server`;
|
|
61
|
+
const destinationAddress = join(process.cwd(), `/public/.${appname}/server`);
|
|
62
|
+
copyFiles(originalAddress, destinationAddress);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
25
65
|
}
|
package/package.json
CHANGED
|
@@ -8,6 +8,14 @@ interface RegexControl {
|
|
|
8
8
|
* @param val
|
|
9
9
|
*/
|
|
10
10
|
export declare function setAppRegex(val: RegexControl): void;
|
|
11
|
+
/**
|
|
12
|
+
* 得到插件名匹配模式
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAppRegex(): {
|
|
16
|
+
RegexOpen: RegExp;
|
|
17
|
+
RegexClose: RegExp;
|
|
18
|
+
};
|
|
11
19
|
/**
|
|
12
20
|
* 设置指令json地址
|
|
13
21
|
* @param rt '/public/defset'
|
package/types/define/plugin.d.ts
CHANGED