alemonjs 2.1.0-alpha.37 → 2.1.0-alpha.39

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/bin/alemonc.js CHANGED
@@ -1,66 +1,66 @@
1
1
  #!/usr/bin/env node
2
- import { updateConfig } from './updateConfig.js'
3
- import { run } from './run.js'
4
- import { start } from './start.js'
5
- import { Command } from 'commander'
6
- const program = new Command()
2
+ import { updateConfig } from './updateConfig.js';
3
+ import { run } from './run.js';
4
+ import { start } from './start.js';
5
+ import { Command } from 'commander';
6
+ const program = new Command();
7
7
 
8
- program.name('alemonc').description('CLI to some alemonc actions and scripts').version('1.0.0')
8
+ program.name('alemonc').description('CLI to some alemonc actions and scripts').version('1.0.0');
9
9
 
10
10
  program
11
11
  .command('add <key> [values...]')
12
12
  .description('给key为数据的值添加元素')
13
13
  .action((key, values) => {
14
- updateConfig('add', key, values)
15
- })
14
+ updateConfig('add', key, values);
15
+ });
16
16
 
17
17
  program
18
18
  .command('remove <key> [values...]')
19
19
  .description('给key为数据的值移除元素')
20
20
  .action((key, values) => {
21
- updateConfig('remove', key, values)
22
- })
21
+ updateConfig('remove', key, values);
22
+ });
23
23
 
24
24
  program
25
25
  .command('set <key> [values...]')
26
26
  .description('给某个key设置值')
27
27
  .action((key, values) => {
28
- updateConfig('set', key, values)
29
- })
28
+ updateConfig('set', key, values);
29
+ });
30
30
 
31
31
  program
32
32
  .command('del <key>')
33
33
  .description('删除指定配置')
34
34
  .action(key => {
35
- updateConfig('del', key)
36
- })
35
+ updateConfig('del', key);
36
+ });
37
37
 
38
38
  program
39
39
  .command('get <key>')
40
40
  .description('获取指定配置')
41
41
  .action(key => {
42
- updateConfig('get', key)
43
- })
42
+ updateConfig('get', key);
43
+ });
44
44
 
45
45
  program
46
46
  .command('run [script]')
47
47
  .description('运行指定脚本')
48
48
  .action(script => {
49
- run(script)
50
- })
49
+ run(script);
50
+ });
51
51
 
52
52
  program
53
53
  .command('start')
54
54
  .description('启动 package.json 中的 main 入口')
55
55
  .action(() => {
56
- start()
57
- })
56
+ start();
57
+ });
58
58
 
59
59
  program
60
60
  .command('help')
61
61
  .description('获取帮助')
62
62
  .action(() => {
63
- program.help()
64
- })
63
+ program.help();
64
+ });
65
65
 
66
- program.parse(process.argv)
66
+ program.parse(process.argv);
package/bin/run.js CHANGED
@@ -6,6 +6,6 @@
6
6
  */
7
7
  export const run = dir => {
8
8
  import('../lib/index.js').then(res => {
9
- res.start(dir)
10
- })
11
- }
9
+ res.start(dir);
10
+ });
11
+ };
package/bin/start.js CHANGED
@@ -1,30 +1,30 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import path from 'path'
4
- import fs from 'fs'
5
- import { createRequire } from 'module'
6
- const require = createRequire(import.meta.url)
3
+ import path from 'path';
4
+ import fs from 'fs';
5
+ import { createRequire } from 'module';
6
+ const require = createRequire(import.meta.url);
7
7
 
8
8
  const createExports = packageJson => {
9
9
  if (packageJson?.exports) {
10
10
  if (typeof packageJson.exports === 'string') {
11
- return packageJson.exports
11
+ return packageJson.exports;
12
12
  } else if (typeof packageJson.exports === 'object') {
13
- return packageJson.exports['.'] || packageJson.exports['./index.js']
13
+ return packageJson.exports['.'] || packageJson.exports['./index.js'];
14
14
  }
15
15
  }
16
- }
16
+ };
17
17
 
18
18
  const getInputExportPath = input => {
19
- const packageJsonPath = path.join(input ?? process.cwd(), 'package.json')
19
+ const packageJsonPath = path.join(input ?? process.cwd(), 'package.json');
20
20
  if (fs.existsSync(packageJsonPath)) {
21
- const packageJson = require(packageJsonPath)
22
- const main = packageJson?.main || createExports(packageJson)
21
+ const packageJson = require(packageJsonPath);
22
+ const main = packageJson?.main || createExports(packageJson);
23
23
  if (main) {
24
- return main
24
+ return main;
25
25
  }
26
26
  }
27
- }
27
+ };
28
28
 
29
29
  /**
30
30
  *
@@ -32,8 +32,8 @@ const getInputExportPath = input => {
32
32
  */
33
33
  export const start = () => {
34
34
  // 读取配置文件
35
- const main = getInputExportPath()
35
+ const main = getInputExportPath();
36
36
  import('../lib/index.js').then(res => {
37
- res.start(main)
38
- })
39
- }
37
+ res.start(main);
38
+ });
39
+ };
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { join } from 'path'
3
- import fs from 'fs'
4
- import YAML from 'yaml'
5
- const configPath = join(process.cwd(), 'alemon.config.yaml')
2
+ import { join } from 'path';
3
+ import fs from 'fs';
4
+ import YAML from 'yaml';
5
+ const configPath = join(process.cwd(), 'alemon.config.yaml');
6
6
 
7
7
  /**
8
8
  * 更新配置
@@ -12,72 +12,72 @@ const configPath = join(process.cwd(), 'alemon.config.yaml')
12
12
  * @returns
13
13
  */
14
14
  export function updateConfig(action, key, value = []) {
15
- let config = {}
15
+ let config = {};
16
16
  if (fs.existsSync(configPath)) {
17
- const data = fs.readFileSync(configPath, 'utf8')
18
- config = YAML.parse(data) ?? {}
17
+ const data = fs.readFileSync(configPath, 'utf8');
18
+ config = YAML.parse(data) ?? {};
19
19
  }
20
- const keys = key.split('.')
21
- let current = config
20
+ const keys = key.split('.');
21
+ let current = config;
22
22
  if (action === 'add') {
23
23
  for (let i = 0; i < keys.length - 1; i++) {
24
- const currentKey = keys[i]
24
+ const currentKey = keys[i];
25
25
  if (current[currentKey] === null || typeof current[currentKey] !== 'object') {
26
- current[currentKey] = {} // 确保当前键的值是一个对象
26
+ current[currentKey] = {}; // 确保当前键的值是一个对象
27
27
  }
28
- current = current[currentKey]
28
+ current = current[currentKey];
29
29
  }
30
- const finalKey = keys[keys.length - 1]
30
+ const finalKey = keys[keys.length - 1];
31
31
  if (!Array.isArray(current[finalKey])) {
32
- current[finalKey] = [] // 如果最终键的值不是数组,则初始化为空数组
32
+ current[finalKey] = []; // 如果最终键的值不是数组,则初始化为空数组
33
33
  }
34
- current[finalKey] = [...new Set([...current[finalKey], ...value])] // 去重并添加新值
34
+ current[finalKey] = [...new Set([...current[finalKey], ...value])]; // 去重并添加新值
35
35
  } else if (action === 'remove') {
36
36
  for (let i = 0; i < keys.length - 1; i++) {
37
- const currentKey = keys[i]
37
+ const currentKey = keys[i];
38
38
  if (current[currentKey] === null || typeof current[currentKey] !== 'object') {
39
- return // 如果路径不存在,直接返回
39
+ return; // 如果路径不存在,直接返回
40
40
  }
41
- current = current[currentKey]
41
+ current = current[currentKey];
42
42
  }
43
- const finalKey = keys[keys.length - 1]
43
+ const finalKey = keys[keys.length - 1];
44
44
  if (Array.isArray(current[finalKey])) {
45
- current[finalKey] = current[finalKey].filter(item => !value.includes(item)) // 过滤掉要删除的值
45
+ current[finalKey] = current[finalKey].filter(item => !value.includes(item)); // 过滤掉要删除的值
46
46
  }
47
47
  } else if (action === 'set') {
48
48
  for (let i = 0; i < keys.length - 1; i++) {
49
- const currentKey = keys[i]
49
+ const currentKey = keys[i];
50
50
  if (current[currentKey] === null || typeof current[currentKey] !== 'object') {
51
- current[currentKey] = {} // 确保当前键的值是一个对象
51
+ current[currentKey] = {}; // 确保当前键的值是一个对象
52
52
  }
53
- current = current[currentKey]
53
+ current = current[currentKey];
54
54
  }
55
- current[keys[keys.length - 1]] = value[0]
55
+ current[keys[keys.length - 1]] = value[0];
56
56
  } else if (action === 'del') {
57
57
  for (let i = 0; i < keys.length - 1; i++) {
58
- const currentKey = keys[i]
58
+ const currentKey = keys[i];
59
59
  if (current[currentKey] === null || typeof current[currentKey] !== 'object') {
60
- return // 如果路径不存在,直接返回
60
+ return; // 如果路径不存在,直接返回
61
61
  }
62
- current = current[currentKey]
62
+ current = current[currentKey];
63
63
  }
64
- delete current[keys[keys.length - 1]]
64
+ delete current[keys[keys.length - 1]];
65
65
  } else if (action === 'get') {
66
66
  for (let i = 0; i < keys.length; i++) {
67
- const currentKey = keys[i]
67
+ const currentKey = keys[i];
68
68
  if (current[currentKey] === null || typeof current[currentKey] !== 'object') {
69
69
  if (i === keys.length - 1) {
70
- console.log(current[currentKey]) // 输出最终值
70
+ console.log(current[currentKey]); // 输出最终值
71
71
  } else {
72
- console.log(undefined) // 路径不存在
72
+ console.log(undefined); // 路径不存在
73
73
  }
74
- return
74
+ return;
75
75
  }
76
- current = current[currentKey]
76
+ current = current[currentKey];
77
77
  }
78
- console.log(current) // 输出最终值
79
- return
78
+ console.log(current); // 输出最终值
79
+ return;
80
80
  }
81
81
 
82
- fs.writeFileSync(configPath, YAML.stringify(config))
82
+ fs.writeFileSync(configPath, YAML.stringify(config));
83
83
  }
@@ -0,0 +1,19 @@
1
+ import { EventKeys, Events } from '../typing/event/map.js';
2
+ import '../global.js';
3
+
4
+ /**
5
+ * @fileoverview 消息处理快
6
+ * 登录模块向核心模块发送数据
7
+ * 核心模块调用模块索引
8
+ * @module processor
9
+ * @author ningmengchongshui
10
+ */
11
+
12
+ /**
13
+ * 消息体处理机制
14
+ * @param event
15
+ * @param key
16
+ */
17
+ declare const expendCycle: <T extends EventKeys>(valueEvent: Events[T], select: T) => Promise<void>;
18
+
19
+ export { expendCycle };
@@ -50,17 +50,15 @@ const showLog = (event, select) => {
50
50
  * @param event
51
51
  * @param key
52
52
  */
53
- const expendCycle = async (valueEvent, select) => {
54
- const nextEnd = () => {
55
- return;
56
- };
53
+ const expendCycle = (valueEvent, select) => {
54
+ const nextEnd = () => { };
57
55
  // unmount
58
56
  const nextUnMount = (cn, ...cns) => {
59
57
  if (cn) {
60
58
  nextEnd(...cns);
61
59
  return;
62
60
  }
63
- expendSubscribeUnmount(valueEvent, select, nextEnd);
61
+ void expendSubscribeUnmount(valueEvent, select, nextEnd);
64
62
  };
65
63
  // event
66
64
  const nextEvent = (cn, ...cns) => {
@@ -68,7 +66,7 @@ const expendCycle = async (valueEvent, select) => {
68
66
  nextUnMount(...cns);
69
67
  return;
70
68
  }
71
- expendEvent(valueEvent, select, nextUnMount);
69
+ void expendEvent(valueEvent, select, nextUnMount);
72
70
  };
73
71
  // mount
74
72
  const nextMount = (cn, ...cns) => {
@@ -76,7 +74,7 @@ const expendCycle = async (valueEvent, select) => {
76
74
  nextEvent(...cns);
77
75
  return;
78
76
  }
79
- expendSubscribeMount(valueEvent, select, nextEvent);
77
+ void expendSubscribeMount(valueEvent, select, nextEvent);
80
78
  };
81
79
  // middleware
82
80
  const nextCreate = (cn, ...cns) => {
@@ -84,7 +82,7 @@ const expendCycle = async (valueEvent, select) => {
84
82
  nextMount(...cns);
85
83
  return;
86
84
  }
87
- expendMiddleware(valueEvent, select, nextMount);
85
+ void expendMiddleware(valueEvent, select, nextMount);
88
86
  };
89
87
  const value = getConfigValue() ?? {};
90
88
  if (Array.isArray(value?.logs?.channel_id)) {
@@ -97,7 +95,7 @@ const expendCycle = async (valueEvent, select) => {
97
95
  showLog(valueEvent, select);
98
96
  }
99
97
  // create
100
- expendSubscribeCreate(valueEvent, select, nextCreate);
98
+ void expendSubscribeCreate(valueEvent, select, nextCreate);
101
99
  };
102
100
 
103
101
  export { expendCycle };
@@ -0,0 +1,11 @@
1
+ import { EventKeys, Events } from '../typing/event/map.js';
2
+ import '../global.js';
3
+
4
+ /**
5
+ * 消息体处理机制
6
+ * @param event
7
+ * @param key
8
+ */
9
+ declare const expendEvent: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function) => Promise<void>;
10
+
11
+ export { expendEvent };
@@ -17,7 +17,7 @@ import { EventMessageText } from '../core/variable.js';
17
17
  * @param event
18
18
  * @param key
19
19
  */
20
- const expendEvent = async (valueEvent, select, next) => {
20
+ const expendEvent = (valueEvent, select, next) => {
21
21
  const res = new Response();
22
22
  const [message] = useMessage(valueEvent);
23
23
  // 得到所有 res
@@ -38,7 +38,7 @@ const expendEvent = async (valueEvent, select, next) => {
38
38
  return;
39
39
  }
40
40
  // 检查所有
41
- calli();
41
+ void calli();
42
42
  };
43
43
  /**
44
44
  * 执行 i
@@ -61,7 +61,7 @@ const expendEvent = async (valueEvent, select, next) => {
61
61
  //
62
62
  try {
63
63
  const app = await import(`file://${file.path}`);
64
- if (!app?.default || !app?.default?.current || !app?.default?.select) {
64
+ if (!app?.default?.current || !app?.default?.select) {
65
65
  // 继续
66
66
  nextEvent();
67
67
  return;
@@ -69,7 +69,7 @@ const expendEvent = async (valueEvent, select, next) => {
69
69
  // 检查状态
70
70
  if (file?.stateKey) {
71
71
  const [state] = useState(file?.stateKey);
72
- if (state == false) {
72
+ if (state === false) {
73
73
  // 继续
74
74
  nextEvent();
75
75
  return;
@@ -93,9 +93,7 @@ const expendEvent = async (valueEvent, select, next) => {
93
93
  }
94
94
  }
95
95
  }
96
- const currents = Array.isArray(app.default.current)
97
- ? app.default.current
98
- : [app.default.current];
96
+ const currents = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
99
97
  let index = 0;
100
98
  let isClose = false;
101
99
  let isNext = false;
@@ -107,14 +105,14 @@ const expendEvent = async (valueEvent, select, next) => {
107
105
  if (Array.isArray(res)) {
108
106
  if (res.length > 0) {
109
107
  // 发送数据
110
- message.send(res);
108
+ void message.send(res);
111
109
  }
112
110
  isClose = true;
113
111
  }
114
112
  else if (typeof res === 'object') {
115
113
  if (Array.isArray(res.data)) {
116
114
  // 发送数据
117
- message.send(res.data);
115
+ void message.send(res.data);
118
116
  }
119
117
  if (!res.allowGrouping) {
120
118
  isClose = true;
@@ -122,12 +120,15 @@ const expendEvent = async (valueEvent, select, next) => {
122
120
  }
123
121
  };
124
122
  const start = async () => {
125
- if (index >= currents.length)
123
+ if (index >= currents.length) {
126
124
  return;
127
- if (isNext)
125
+ }
126
+ if (isNext) {
128
127
  return;
129
- if (isClose)
128
+ }
129
+ if (isClose) {
130
130
  return;
131
+ }
131
132
  if (isAsyncFunction(currents[index])) {
132
133
  const res = await currents[index](valueEvent, (...cns) => {
133
134
  isNext = true;
@@ -143,9 +144,9 @@ const expendEvent = async (valueEvent, select, next) => {
143
144
  onRes(res);
144
145
  }
145
146
  ++index;
146
- start();
147
+ void start();
147
148
  };
148
- start();
149
+ void start();
149
150
  }
150
151
  catch (err) {
151
152
  showErrorModule(err);
@@ -0,0 +1,11 @@
1
+ import { EventKeys, Events } from '../typing/event/map.js';
2
+ import '../global.js';
3
+
4
+ /**
5
+ * 处理中间件
6
+ * @param event
7
+ * @param select
8
+ */
9
+ declare const expendMiddleware: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function) => Promise<void>;
10
+
11
+ export { expendMiddleware };
@@ -17,7 +17,7 @@ import { EventMessageText } from '../core/variable.js';
17
17
  * @param event
18
18
  * @param select
19
19
  */
20
- const expendMiddleware = async (valueEvent, select, next) => {
20
+ const expendMiddleware = (valueEvent, select, next) => {
21
21
  const mw = new Middleware();
22
22
  const [message] = useMessage(valueEvent);
23
23
  // 得到所有 mws
@@ -28,7 +28,7 @@ const expendMiddleware = async (valueEvent, select, next) => {
28
28
  * 下一步
29
29
  * @returns
30
30
  */
31
- const nextMiddleware = async (cn, ...cns) => {
31
+ const nextMiddleware = (cn, ...cns) => {
32
32
  if (cn) {
33
33
  next(...cns);
34
34
  return;
@@ -39,7 +39,7 @@ const expendMiddleware = async (valueEvent, select, next) => {
39
39
  return;
40
40
  }
41
41
  // 检查所有
42
- calli();
42
+ void calli();
43
43
  };
44
44
  /**
45
45
  * 执行 i
@@ -61,7 +61,7 @@ const expendMiddleware = async (valueEvent, select, next) => {
61
61
  }
62
62
  try {
63
63
  const app = await import(`file://${file.path}`);
64
- if (!app?.default || !app?.default?.current || !app?.default?.select) {
64
+ if (!app?.default?.current || !app?.default?.select) {
65
65
  // 继续
66
66
  nextMiddleware();
67
67
  return;
@@ -69,7 +69,7 @@ const expendMiddleware = async (valueEvent, select, next) => {
69
69
  // 检查状态
70
70
  if (file?.stateKey) {
71
71
  const [state] = useState(file?.stateKey);
72
- if (state == false) {
72
+ if (state === false) {
73
73
  // 继续
74
74
  nextMiddleware();
75
75
  return;
@@ -91,9 +91,7 @@ const expendMiddleware = async (valueEvent, select, next) => {
91
91
  nextMiddleware();
92
92
  return;
93
93
  }
94
- const currents = Array.isArray(app.default.current)
95
- ? app.default.current
96
- : [app.default.current];
94
+ const currents = Array.isArray(app.default.current) ? app.default.current : [app.default.current];
97
95
  let index = 0;
98
96
  let isClose = false;
99
97
  let isNext = false;
@@ -109,14 +107,14 @@ const expendMiddleware = async (valueEvent, select, next) => {
109
107
  else if (Array.isArray(res)) {
110
108
  if (res.length > 0) {
111
109
  // 发送数据
112
- message.send(res);
110
+ void message.send(res);
113
111
  }
114
112
  isClose = true;
115
113
  }
116
114
  else if (typeof res === 'object') {
117
115
  if (Array.isArray(res.data)) {
118
116
  // 发送数据
119
- message.send(res.data);
117
+ void message.send(res.data);
120
118
  }
121
119
  if (!res.allowGrouping) {
122
120
  isClose = true;
@@ -124,12 +122,15 @@ const expendMiddleware = async (valueEvent, select, next) => {
124
122
  }
125
123
  };
126
124
  const start = async () => {
127
- if (index >= currents.length)
125
+ if (index >= currents.length) {
128
126
  return;
129
- if (isNext)
127
+ }
128
+ if (isNext) {
130
129
  return;
131
- if (isClose)
130
+ }
131
+ if (isClose) {
132
132
  return;
133
+ }
133
134
  if (isAsyncFunction(currents[index])) {
134
135
  const res = await currents[index](valueEvent, (...cns) => {
135
136
  isNext = true;
@@ -145,9 +146,9 @@ const expendMiddleware = async (valueEvent, select, next) => {
145
146
  onRes(res);
146
147
  }
147
148
  ++index;
148
- start();
149
+ void start();
149
150
  };
150
- start();
151
+ void start();
151
152
  }
152
153
  catch (err) {
153
154
  showErrorModule(err);
@@ -0,0 +1,41 @@
1
+ import { EventCycleEnum } from '../typing/cycle/index.js';
2
+ import '../global.js';
3
+ import { EventKeys, Events } from '../typing/event/map.js';
4
+
5
+ /**
6
+ * @fileoverview 观察者
7
+ * @module processor
8
+ * @author ningmengchongshui
9
+ */
10
+
11
+ /**
12
+ * 处理订阅
13
+ * @param valueEvent
14
+ * @param select
15
+ * @param next
16
+ * @param chioce
17
+ */
18
+ declare const expendSubscribe: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function, chioce: EventCycleEnum) => Promise<void>;
19
+ /**
20
+ *
21
+ * @param valueEvent
22
+ * @param select
23
+ * @param next
24
+ */
25
+ declare const expendSubscribeCreate: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function) => Promise<void>;
26
+ /**
27
+ *
28
+ * @param valueEvent
29
+ * @param select
30
+ * @param next
31
+ */
32
+ declare const expendSubscribeMount: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function) => Promise<void>;
33
+ /**
34
+ *
35
+ * @param valueEvent
36
+ * @param select
37
+ * @param next
38
+ */
39
+ declare const expendSubscribeUnmount: <T extends EventKeys>(valueEvent: Events[T], select: T, next: Function) => Promise<void>;
40
+
41
+ export { expendSubscribe, expendSubscribeCreate, expendSubscribeMount, expendSubscribeUnmount };
@@ -7,7 +7,7 @@ import { SubscribeList } from './store.js';
7
7
  * @param next
8
8
  * @param chioce
9
9
  */
10
- const expendSubscribe = async (valueEvent, select, next, chioce) => {
10
+ const expendSubscribe = (valueEvent, select, next, chioce) => {
11
11
  const subList = new SubscribeList(chioce, select);
12
12
  /**
13
13
  * 观察者下一步
@@ -45,7 +45,6 @@ const expendSubscribe = async (valueEvent, select, next, chioce) => {
45
45
  return;
46
46
  }
47
47
  subList.value.removeCurrent(); // 移除当前节点
48
- return;
49
48
  };
50
49
  remove();
51
50
  }
@@ -73,7 +72,6 @@ const expendSubscribe = async (valueEvent, select, next, chioce) => {
73
72
  if (typeof cn === 'boolean') {
74
73
  clear();
75
74
  nextObserver(...cns);
76
- return;
77
75
  }
78
76
  };
79
77
  item.data.current(valueEvent, Continue);
@@ -87,7 +85,7 @@ const expendSubscribe = async (valueEvent, select, next, chioce) => {
87
85
  * @param select
88
86
  * @param next
89
87
  */
90
- const expendSubscribeCreate = async (valueEvent, select, next) => {
88
+ const expendSubscribeCreate = (valueEvent, select, next) => {
91
89
  expendSubscribe(valueEvent, select, next, 'create');
92
90
  };
93
91
  /**
@@ -96,7 +94,7 @@ const expendSubscribeCreate = async (valueEvent, select, next) => {
96
94
  * @param select
97
95
  * @param next
98
96
  */
99
- const expendSubscribeMount = async (valueEvent, select, next) => {
97
+ const expendSubscribeMount = (valueEvent, select, next) => {
100
98
  expendSubscribe(valueEvent, select, next, 'mount');
101
99
  };
102
100
  /**
@@ -105,7 +103,7 @@ const expendSubscribeMount = async (valueEvent, select, next) => {
105
103
  * @param select
106
104
  * @param next
107
105
  */
108
- const expendSubscribeUnmount = async (valueEvent, select, next) => {
106
+ const expendSubscribeUnmount = (valueEvent, select, next) => {
109
107
  expendSubscribe(valueEvent, select, next, 'unmount');
110
108
  };
111
109
 
@@ -50,9 +50,7 @@ const callback = () => {
50
50
  // 下一次清理的时间,应该随着长度的增加而减少
51
51
  const length = ProcessorEventAutoClearMap.size + ProcessorEventUserAudoClearMap.size;
52
52
  // 长度控制在37个以内
53
- const time = length > processor_repeated_clear_size
54
- ? processor_repeated_clear_time_min
55
- : processor_repeated_clear_time_max;
53
+ const time = length > processor_repeated_clear_size ? processor_repeated_clear_time_min : processor_repeated_clear_time_max;
56
54
  setTimeout(callback, time);
57
55
  };
58
56
  setTimeout(callback, processor_repeated_clear_time_min);
@@ -94,7 +92,6 @@ const onProcessor = (name, event, data) => {
94
92
  }
95
93
  event['name'] = name;
96
94
  expendCycle(event, name);
97
- return;
98
95
  };
99
96
  /**
100
97
  * 消息处理器
@@ -105,7 +102,6 @@ const onProcessor = (name, event, data) => {
105
102
  */
106
103
  const OnProcessor = (event, name) => {
107
104
  onProcessor(name, event);
108
- return;
109
105
  };
110
106
 
111
107
  export { OnProcessor, onProcessor };
@@ -134,9 +134,7 @@ const useMessage = (event) => {
134
134
  */
135
135
  const send = async (val) => {
136
136
  if (!val || val.length === 0) {
137
- return [
138
- createResult(ResultCode.FailParams, 'Invalid val: val must be a non-empty array', null)
139
- ];
137
+ return [createResult(ResultCode.FailParams, 'Invalid val: val must be a non-empty array', null)];
140
138
  }
141
139
  const result = await sendAction({
142
140
  action: 'message.send',
@@ -40,15 +40,13 @@ const useSubscribe = (event, selects) => {
40
40
  for (const select of curSelects) {
41
41
  const subList = new SubscribeList(choose, select);
42
42
  // 没有选择
43
- if (keys.length === 0)
43
+ if (keys.length === 0) {
44
44
  return;
45
+ }
45
46
  // 只能选择基础数据类型的key
46
47
  const values = {};
47
48
  for (const key of keys) {
48
- if (typeof key === 'string' &&
49
- (typeof event[key] == 'string' ||
50
- typeof event[key] == 'number' ||
51
- typeof event[key] == 'boolean')) {
49
+ if (typeof key === 'string' && (typeof event[key] === 'string' || typeof event[key] === 'number' || typeof event[key] === 'boolean')) {
52
50
  values[key] = event[key];
53
51
  }
54
52
  else {
@@ -113,7 +111,6 @@ const useSubscribe = (event, selects) => {
113
111
  return;
114
112
  }
115
113
  subList.value.removeCurrent(); // 移除当前节点
116
- return;
117
114
  };
118
115
  remove();
119
116
  }
package/lib/app/load.js CHANGED
@@ -121,7 +121,6 @@ const loadChildren = async (mainPath, appName) => {
121
121
  }
122
122
  catch (e) {
123
123
  unMounted(e);
124
- return;
125
124
  }
126
125
  }
127
126
  catch (e) {
@@ -13,7 +13,7 @@ type BaseMap = {
13
13
  */
14
14
  declare const createEventValue: <T extends keyof R, R extends BaseMap>(event: {
15
15
  value: R[T];
16
- }) => R[T] | undefined;
16
+ }) => R[T];
17
17
  /**
18
18
  * 创建数据格式。
19
19
  * @param {...DataEnums[]} data - 要格式化的数据。
package/lib/app/store.js CHANGED
@@ -21,16 +21,16 @@ const createLogger = () => {
21
21
  const hideLevel = process.env.LOGGER_LEVEL === 'false' ? true : false;
22
22
  let pattern = '';
23
23
  if (hideTime && hideLevel) {
24
- pattern = `%m`;
24
+ pattern = '%m';
25
25
  }
26
26
  else if (hideTime && !hideLevel) {
27
- pattern = `[%p] %m`;
27
+ pattern = '[%p] %m';
28
28
  }
29
29
  else if (!hideTime && hideLevel) {
30
- pattern = `[%d{yyyy-MM-dd hh:mm:ss}] %m`;
30
+ pattern = '[%d{yyyy-MM-dd hh:mm:ss}] %m';
31
31
  }
32
32
  else {
33
- pattern = `[%d{yyyy-MM-dd hh:mm:ss}][%p] %m`;
33
+ pattern = '[%d{yyyy-MM-dd hh:mm:ss}][%p] %m';
34
34
  }
35
35
  log4js.configure({
36
36
  appenders: {
@@ -28,7 +28,7 @@ const useHeartbeat = ({ ping, isConnected, terminate }) => {
28
28
  ping();
29
29
  logger.debug({
30
30
  code: ResultCode.Ok,
31
- message: `发送 ping`,
31
+ message: '发送 ping',
32
32
  data: null
33
33
  });
34
34
  heartbeatTimer = setTimeout(callback, HEARTBEAT_INTERVAL);
@@ -51,7 +51,7 @@ const useHeartbeat = ({ ping, isConnected, terminate }) => {
51
51
  lastPong = Date.now();
52
52
  logger.debug({
53
53
  code: ResultCode.Ok,
54
- message: `收到 pong`,
54
+ message: '收到 pong',
55
55
  data: null
56
56
  });
57
57
  }
package/lib/cbp/router.js CHANGED
@@ -120,7 +120,7 @@ router.all('app/{*path}', async (ctx) => {
120
120
  ctx.status = 500;
121
121
  ctx.body = {
122
122
  code: 500,
123
- message: `处理 API 请求时发生错误。`,
123
+ message: '处理 API 请求时发生错误。',
124
124
  error: err.message
125
125
  };
126
126
  }
@@ -146,9 +146,7 @@ router.all('app/{*path}', async (ctx) => {
146
146
  };
147
147
  return;
148
148
  }
149
- const fullPath = root
150
- ? path.join(rootPath, root, resourcePath)
151
- : path.join(rootPath, resourcePath);
149
+ const fullPath = root ? path.join(rootPath, root, resourcePath) : path.join(rootPath, resourcePath);
152
150
  try {
153
151
  // 返回文件
154
152
  const file = await fs.promises.readFile(fullPath);
@@ -162,7 +160,7 @@ router.all('app/{*path}', async (ctx) => {
162
160
  ctx.status = 404;
163
161
  ctx.body = {
164
162
  code: 404,
165
- message: `资源中未找到。`,
163
+ message: '资源中未找到。',
166
164
  data: null
167
165
  };
168
166
  }
@@ -170,7 +168,7 @@ router.all('app/{*path}', async (ctx) => {
170
168
  ctx.status = 500;
171
169
  ctx.body = {
172
170
  code: 500,
173
- message: `加载资源时发生服务器错误。`,
171
+ message: '加载资源时发生服务器错误。',
174
172
  error: err.message
175
173
  };
176
174
  }
@@ -234,7 +232,7 @@ router.all('apps/:app/{*path}', async (ctx) => {
234
232
  ctx.status = 500;
235
233
  ctx.body = {
236
234
  code: 500,
237
- message: `处理 API 请求时发生错误。`,
235
+ message: '处理 API 请求时发生错误。',
238
236
  error: err.message
239
237
  };
240
238
  }
@@ -262,9 +260,7 @@ router.all('apps/:app/{*path}', async (ctx) => {
262
260
  };
263
261
  return;
264
262
  }
265
- const fullPath = root
266
- ? path.join(rootPath, root, resourcePath)
267
- : path.join(rootPath, resourcePath);
263
+ const fullPath = root ? path.join(rootPath, root, resourcePath) : path.join(rootPath, resourcePath);
268
264
  try {
269
265
  // 返回文件
270
266
  const file = await fs.promises.readFile(fullPath);
package/lib/cbp/server.js CHANGED
@@ -250,7 +250,6 @@ const cbpServer = (port, listeningListener) => {
250
250
  message: '服务端解析平台消息失败',
251
251
  data: error
252
252
  });
253
- return;
254
253
  }
255
254
  });
256
255
  // 处理关闭事件
@@ -442,7 +441,6 @@ const cbpServer = (port, listeningListener) => {
442
441
  message: '创建 CBP 服务器失败',
443
442
  data: error
444
443
  });
445
- return;
446
444
  }
447
445
  };
448
446
  createServer();
@@ -24,8 +24,9 @@ const connectionTestOne = (ws, _request) => {
24
24
  }
25
25
  // 监听整个目录,捕获新文件创建
26
26
  const dirWatcher = watch(testonePath, { persistent: true }, (eventType, filename) => {
27
- if (!filename)
27
+ if (!filename) {
28
28
  return;
29
+ }
29
30
  // 如果是新创建的文件,开始监听它
30
31
  if (eventType === 'change') {
31
32
  if (filename === 'commands.json') {
@@ -47,8 +48,9 @@ const connectionTestOne = (ws, _request) => {
47
48
  });
48
49
  const commandsPath = join(testonePath, 'commands.json');
49
50
  const onCommands = _.debounce(() => {
50
- if (!existsSync(commandsPath))
51
+ if (!existsSync(commandsPath)) {
51
52
  return;
53
+ }
52
54
  readFile(commandsPath, 'utf-8')
53
55
  .then(data => {
54
56
  const commands = JSON.parse(data);
@@ -63,8 +65,9 @@ const connectionTestOne = (ws, _request) => {
63
65
  }, 1000);
64
66
  const usersPath = join(testonePath, 'users.json');
65
67
  const onUsers = _.debounce(() => {
66
- if (!existsSync(usersPath))
68
+ if (!existsSync(usersPath)) {
67
69
  return;
70
+ }
68
71
  readFile(usersPath, 'utf-8')
69
72
  .then(data => {
70
73
  const users = JSON.parse(data);
@@ -79,8 +82,9 @@ const connectionTestOne = (ws, _request) => {
79
82
  }, 1000);
80
83
  const channelsPath = join(testonePath, 'channels.json');
81
84
  const onChannels = _.debounce(() => {
82
- if (!existsSync(channelsPath))
85
+ if (!existsSync(channelsPath)) {
83
86
  return;
87
+ }
84
88
  readFile(channelsPath, 'utf-8')
85
89
  .then(data => {
86
90
  const channels = JSON.parse(data);
@@ -95,8 +99,9 @@ const connectionTestOne = (ws, _request) => {
95
99
  }, 1000);
96
100
  const userPath = join(testonePath, 'user.json');
97
101
  const onUser = _.debounce(() => {
98
- if (!existsSync(userPath))
102
+ if (!existsSync(userPath)) {
99
103
  return;
104
+ }
100
105
  readFile(userPath, 'utf-8')
101
106
  .then(data => {
102
107
  const user = JSON.parse(data);
@@ -111,8 +116,9 @@ const connectionTestOne = (ws, _request) => {
111
116
  }, 1000);
112
117
  const botPath = join(testonePath, 'bot.json');
113
118
  const onBot = _.debounce(() => {
114
- if (!existsSync(botPath))
119
+ if (!existsSync(botPath)) {
115
120
  return;
121
+ }
116
122
  readFile(botPath, 'utf-8')
117
123
  .then(data => {
118
124
  const bot = JSON.parse(data);
@@ -131,21 +137,13 @@ const connectionTestOne = (ws, _request) => {
131
137
  mkdirSync(cacheDir, { recursive: true });
132
138
  const initData = () => {
133
139
  try {
134
- const commandsData = existsSync(commandsPath)
135
- ? JSON.parse(readFileSync(commandsPath, 'utf-8'))
136
- : [];
140
+ const commandsData = existsSync(commandsPath) ? JSON.parse(readFileSync(commandsPath, 'utf-8')) : [];
137
141
  const usersData = existsSync(usersPath) ? JSON.parse(readFileSync(usersPath, 'utf-8')) : [];
138
- const channelsData = existsSync(channelsPath)
139
- ? JSON.parse(readFileSync(channelsPath, 'utf-8'))
140
- : [];
142
+ const channelsData = existsSync(channelsPath) ? JSON.parse(readFileSync(channelsPath, 'utf-8')) : [];
141
143
  const userData = existsSync(userPath) ? JSON.parse(readFileSync(userPath, 'utf-8')) : null;
142
144
  const botData = existsSync(botPath) ? JSON.parse(readFileSync(botPath, 'utf-8')) : null;
143
- const privateMessage = existsSync(privateMessagePath)
144
- ? JSON.parse(readFileSync(privateMessagePath, 'utf-8'))
145
- : [];
146
- const publicMessage = existsSync(publicMessagePath)
147
- ? JSON.parse(readFileSync(publicMessagePath, 'utf-8'))
148
- : [];
145
+ const privateMessage = existsSync(privateMessagePath) ? JSON.parse(readFileSync(privateMessagePath, 'utf-8')) : [];
146
+ const publicMessage = existsSync(publicMessagePath) ? JSON.parse(readFileSync(publicMessagePath, 'utf-8')) : [];
149
147
  global.testoneClient?.send(flattedJSON.stringify({
150
148
  type: 'init.data',
151
149
  payload: {
@@ -28,8 +28,9 @@ class ConfigCore {
28
28
  * @returns
29
29
  */
30
30
  #update() {
31
- if (!this.#dir)
31
+ if (!this.#dir) {
32
32
  return this.#value;
33
+ }
33
34
  // 读取配置文件
34
35
  const dir = join(process.cwd(), this.#dir);
35
36
  // 如果文件不存在
@@ -82,8 +83,9 @@ class ConfigCore {
82
83
  */
83
84
  saveValue(value) {
84
85
  // 立即保存当前配置
85
- if (!this.#dir)
86
+ if (!this.#dir) {
86
87
  return;
88
+ }
87
89
  // 读取配置文件
88
90
  const dir = join(process.cwd(), this.#dir);
89
91
  if (!existsSync(dir)) {
@@ -97,8 +99,9 @@ class ConfigCore {
97
99
  * package.json
98
100
  */
99
101
  get package() {
100
- if (this.#package)
102
+ if (this.#package) {
101
103
  return this.#package;
104
+ }
102
105
  const dir = process.env.PKG_PATH || join(process.cwd(), 'package.json');
103
106
  if (!existsSync(dir)) {
104
107
  logger.warn({
@@ -133,14 +136,15 @@ class ConfigCore {
133
136
  const argv = {};
134
137
  return new Proxy(argv, {
135
138
  get(_target, key) {
136
- if (typeof key === 'symbol')
139
+ if (typeof key === 'symbol') {
137
140
  return undefined;
141
+ }
138
142
  const index$0 = process.argv.indexOf(key);
139
- if (index$0 != -1) {
143
+ if (index$0 !== -1) {
140
144
  return process.argv[index$0 + 1];
141
145
  }
142
146
  const index = process.argv.indexOf(`--${key}`);
143
- if (index != -1) {
147
+ if (index !== -1) {
144
148
  return process.argv[index + 1];
145
149
  }
146
150
  return null;
@@ -153,9 +157,11 @@ class ConfigCore {
153
157
  * @returns
154
158
  */
155
159
  const getConfig = () => {
156
- if (global?.config)
160
+ if (global?.config) {
157
161
  return global.config;
158
- global.config = new ConfigCore('alemon.config.yaml');
162
+ }
163
+ const configDir = process.env.CFG_PATH || 'alemon.config.yaml';
164
+ global.config = new ConfigCore(configDir);
159
165
  return global.config;
160
166
  };
161
167
  /**
@@ -61,7 +61,7 @@ declare const getInputExportPath: (input?: string) => any;
61
61
  */
62
62
  type Result<T = any> = {
63
63
  code: ResultCode;
64
- message: string | Object;
64
+ message: string | object;
65
65
  data: T;
66
66
  };
67
67
  /**
@@ -70,7 +70,7 @@ type Result<T = any> = {
70
70
  * @param message
71
71
  * @returns
72
72
  */
73
- declare const createResult: <T>(code: ResultCode, message: string | Object, data?: T) => Result<T>;
73
+ declare const createResult: <T>(code: ResultCode, message: string | object, data?: T) => Result<T>;
74
74
 
75
75
  export { createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey };
76
76
  export type { Result };
package/lib/core/utils.js CHANGED
@@ -56,7 +56,7 @@ const stringToNumber = (str, size = 33) => {
56
56
  while (i) {
57
57
  hash = (hash * size) ^ str.charCodeAt(--i);
58
58
  }
59
- /*JavaScript对32位签名执行逐位操作(如上面的XOR)
59
+ /* JavaScript对32位签名执行逐位操作(如上面的XOR)
60
60
  *整数。由于我们希望结果始终为正,因此转换
61
61
  *通过执行无符号位移,将带符号的int转换为无符号*/
62
62
  return hash >>> 0;
@@ -70,8 +70,9 @@ const stringToNumber = (str, size = 33) => {
70
70
  const getRecursiveDirFiles = (dir, condition = item => file_suffix_response.test(item.name)) => {
71
71
  //
72
72
  let results = [];
73
- if (!existsSync(dir))
73
+ if (!existsSync(dir)) {
74
74
  return results;
75
+ }
75
76
  const list = readdirSync(dir, { withFileTypes: true });
76
77
  list.forEach(item => {
77
78
  const fullPath = join(dir, item.name);
@@ -93,8 +94,9 @@ const getRecursiveDirFiles = (dir, condition = item => file_suffix_response.test
93
94
  * @returns
94
95
  */
95
96
  const showErrorModule = (e) => {
96
- if (!e)
97
+ if (!e) {
97
98
  return;
99
+ }
98
100
  const moduleNotFoundRegex = /Cannot find (module|package)/;
99
101
  // 处理模块未找到的错误
100
102
  if (moduleNotFoundRegex.test(e?.message)) {
@@ -28,11 +28,6 @@ const FailParams = 4001;
28
28
  const FailAuth = 4002;
29
29
  // 授权错误
30
30
  const FailInternal = 5000; // 内部错误
31
- const EventMessageText = [
32
- 'message.create',
33
- 'private.message.create',
34
- 'interaction.create',
35
- 'private.interaction.create'
36
- ];
31
+ const EventMessageText = ['message.create', 'private.message.create', 'interaction.create', 'private.interaction.create'];
37
32
 
38
33
  export { EventMessageText, Fail, FailAuth, FailInternal, FailParams, Ok, Warn, default_platform_common_prefix, default_port, file_prefix_common, file_suffix_middleware, file_suffix_response, processor_repeated_clear_size, processor_repeated_clear_time_max, processor_repeated_clear_time_min, processor_repeated_event_time, processor_repeated_user_time };
@@ -45,8 +45,9 @@ class SinglyLinkedList {
45
45
  }
46
46
  // 删除当前节点
47
47
  removeCurrent() {
48
- if (!this.head)
48
+ if (!this.head) {
49
49
  return;
50
+ }
50
51
  if (this.current === this.head) {
51
52
  this.head = this.head.next; // 移除头节点
52
53
  this.current = null; // 重置当前节点
package/lib/main.d.ts CHANGED
@@ -37,6 +37,6 @@ declare const run: (input: string) => void;
37
37
  /**
38
38
  * @param input
39
39
  */
40
- declare const start: (options?: StartOptions | string) => Promise<void>;
40
+ declare const start: (options?: StartOptions | string) => void;
41
41
 
42
42
  export { run, start };
package/lib/main.js CHANGED
@@ -31,10 +31,8 @@ const loadState = () => {
31
31
  };
32
32
  const loadApps = () => {
33
33
  const cfg = getConfig();
34
- if (cfg.value && cfg.value?.apps && Array.isArray(cfg.value.apps)) {
35
- Promise.all(cfg.value.apps.map(async (app) => {
36
- loadChildrenFile(app);
37
- }));
34
+ if (cfg.value?.apps && Array.isArray(cfg.value.apps)) {
35
+ void Promise.all(cfg.value.apps.map(app => loadChildrenFile(app)));
38
36
  }
39
37
  };
40
38
  /**
@@ -43,9 +41,10 @@ const loadApps = () => {
43
41
  * @returns
44
42
  */
45
43
  const run = (input) => {
46
- if (!input || input == '')
44
+ if (!input) {
47
45
  return;
48
- let mainPath = join(process.cwd(), input);
46
+ }
47
+ const mainPath = join(process.cwd(), input);
49
48
  // 路径
50
49
  if (!existsSync(input)) {
51
50
  logger.warn({
@@ -56,12 +55,12 @@ const run = (input) => {
56
55
  return;
57
56
  }
58
57
  // 指定运行的,name识别为 'main:res:xxx'
59
- loadChildren(mainPath, 'main');
58
+ void loadChildren(mainPath, 'main');
60
59
  };
61
60
  /**
62
61
  * @param input
63
62
  */
64
- const start = async (options = {}) => {
63
+ const start = (options = {}) => {
65
64
  if (typeof options === 'string') {
66
65
  // 如果是字符串,则认为是入口文件路径
67
66
  options = { input: options };
@@ -77,10 +76,10 @@ const start = async (options = {}) => {
77
76
  }
78
77
  else {
79
78
  // 创建 cbp 服务器
80
- const port = options?.port || cfg.argv?.port || cfg.value?.port || default_port;
79
+ const port = options?.port ?? cfg.argv?.port ?? cfg.value?.port ?? default_port;
81
80
  // 设置环境变量
82
81
  process.env.port = port;
83
- cbpServer(port, async () => {
82
+ cbpServer(port, () => {
84
83
  const httpURL = `http://127.0.0.1:${port}`;
85
84
  const wsURL = `ws://127.0.0.1:${port}`;
86
85
  logger.info(`[CBP server started at ${httpURL}]`);
@@ -119,7 +118,7 @@ const start = async (options = {}) => {
119
118
  if (login) {
120
119
  process.env.login = login;
121
120
  }
122
- import(process.env.platform).then(res => res?.default());
121
+ void import(process.env.platform).then(res => res?.default());
123
122
  });
124
123
  }
125
124
  // 获取入口文件
package/lib/utils.js CHANGED
@@ -43,8 +43,9 @@ const createQRCode = async (text, targetPath) => {
43
43
  const bufferData = Buffer.from(qrDataURL.split(',')[1], 'base64');
44
44
  if (targetPath) {
45
45
  writeFile(targetPath, bufferData, (err) => {
46
- if (err)
46
+ if (err) {
47
47
  throw err;
48
+ }
48
49
  console.info(targetPath);
49
50
  });
50
51
  }
@@ -116,10 +117,12 @@ async function createPicFrom(options) {
116
117
  picData.push(null);
117
118
  };
118
119
  if (url) {
119
- if (!existsSync(url))
120
+ if (!existsSync(url)) {
120
121
  return;
121
- if (!name)
122
+ }
123
+ if (!name) {
122
124
  name = basename(url.toString());
125
+ }
123
126
  picData = createReadStream(url);
124
127
  }
125
128
  else if (typeof image === 'string') {
@@ -133,8 +136,9 @@ async function createPicFrom(options) {
133
136
  }
134
137
  // file path
135
138
  else if (existsSync(image)) {
136
- if (!name)
139
+ if (!name) {
137
140
  name = basename(image);
141
+ }
138
142
  picData = createReadStream(image);
139
143
  }
140
144
  // invalid string
@@ -169,8 +173,9 @@ async function createPicFrom(options) {
169
173
  */
170
174
  const getPublicIP = async (options = {}) => {
171
175
  const { force, ...config } = options;
172
- if (global.publicip && !force)
176
+ if (global.publicip && !force) {
173
177
  return global.publicip;
178
+ }
174
179
  return await publicIp({
175
180
  onlyHttps: true,
176
181
  ...config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.0-alpha.37",
3
+ "version": "2.1.0-alpha.39",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",