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.
@@ -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 app) {
229
+ for await (const appname of apps) {
228
230
  if (existsSync(`${dir}/${appname}/index.ts`)) {
229
231
  /**
230
232
  * 优先考虑ts
@@ -10,6 +10,5 @@ export default {
10
10
  '--no-zygote',
11
11
  '--single-process'
12
12
  ],
13
- skipDownload: true,
14
- executablePath: 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'
13
+ skipDownload: true
15
14
  };
@@ -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
- else {
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
- const ars = process.argv.slice(2);
193
- if (!ars.includes('off')) {
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;
@@ -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
- * assets
14
- * pages
15
- * plugins
16
- * server
17
- */
18
- /**
19
- * publick/.AppName/assets
20
- * publick/.AppName/pages
21
- * publick/.AppName/plugins
22
- * publick/.AppName/server
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "阿柠檬框架",
5
5
  "author": "ningmengchongshui",
6
6
  "main": "lib/index.js",
@@ -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'
@@ -1,4 +1,5 @@
1
1
  /**
2
2
  * 同步挂载文件
3
+ * @param dir 插件目录
3
4
  */
4
- export declare function copyAppsFile(): void;
5
+ export declare function copyAppsFile(dir: any): void;