alemonjs 2.0.0-rc.2 → 2.0.0-rc.3

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.
@@ -1,64 +1,65 @@
1
- import { join, dirname } from 'node:path';
2
- import fs from 'node:fs';
1
+ import { join, dirname } from 'node:path'
2
+ import fs from 'node:fs'
3
3
 
4
- const _dir = './src/apps';
4
+ const _dir = './src/apps'
5
5
  /**
6
6
  *
7
7
  */
8
- const values = [];
8
+ const values = []
9
9
  /**
10
10
  *
11
11
  * @returns
12
12
  */
13
- const getFilesValues = () => values;
13
+ const getFilesValues = () => values
14
14
  /**
15
15
  * 递归获取所有文件名以 res 开头的文件
16
16
  * @param dir 目录路径
17
17
  * @returns 文件路径数组
18
18
  */
19
- const getFiles = (dir) => {
20
- let results = [];
21
- const list = fs.readdirSync(dir, { withFileTypes: true });
22
- list.forEach(item => {
23
- const fullPath = join(dir, item.name);
24
- if (item.isDirectory()) {
25
- results = results.concat(getFiles(fullPath));
26
- }
27
- else if (item.isFile() && item.name.startsWith('res')) {
28
- if (item.name.endsWith('.ts') ||
29
- item.name.endsWith('.js') ||
30
- item.name.endsWith('.jsx') ||
31
- item.name.endsWith('.tsx')) {
32
- results.push(fullPath);
33
- }
34
- }
35
- });
36
- return results;
37
- };
19
+ const getFiles = dir => {
20
+ let results = []
21
+ const list = fs.readdirSync(dir, { withFileTypes: true })
22
+ list.forEach(item => {
23
+ const fullPath = join(dir, item.name)
24
+ if (item.isDirectory()) {
25
+ results = results.concat(getFiles(fullPath))
26
+ } else if (item.isFile() && item.name.startsWith('res')) {
27
+ if (
28
+ item.name.endsWith('.ts') ||
29
+ item.name.endsWith('.js') ||
30
+ item.name.endsWith('.jsx') ||
31
+ item.name.endsWith('.tsx')
32
+ ) {
33
+ results.push(fullPath)
34
+ }
35
+ }
36
+ })
37
+ return results
38
+ }
38
39
  /**
39
40
  * 加载文件
40
41
  */
41
42
  const loadFiles = async () => {
42
- const dir = join(process.cwd(), _dir);
43
- const files = getFiles(dir);
44
- // 读取config ,根据config对目录进行分类
45
- for (const item of files) {
46
- // 暂时不使用 config.js
47
- // const dir = dirname(item)
48
- let v = {};
49
- // try {
50
- // const obj = await import(`file://${dir}/config.js`)
51
- // v = obj?.default
52
- // } catch (e) {
53
- // // console.error(e)
54
- // }
55
- // 保存目录地址和文件地址
56
- values.push({
57
- ...v,
58
- dir: dirname(item),
59
- path: item
60
- });
61
- }
62
- };
43
+ const dir = join(process.cwd(), _dir)
44
+ const files = getFiles(dir)
45
+ // 读取config ,根据config对目录进行分类
46
+ for (const item of files) {
47
+ // 暂时不使用 config.js
48
+ // const dir = dirname(item)
49
+ let v = {}
50
+ // try {
51
+ // const obj = await import(`file://${dir}/config.js`)
52
+ // v = obj?.default
53
+ // } catch (e) {
54
+ // // console.error(e)
55
+ // }
56
+ // 保存目录地址和文件地址
57
+ values.push({
58
+ ...v,
59
+ dir: dirname(item),
60
+ path: item
61
+ })
62
+ }
63
+ }
63
64
 
64
- export { getFilesValues, loadFiles };
65
+ export { getFilesValues, loadFiles }
@@ -97,19 +97,34 @@ const onMessageCreate = async (e) => {
97
97
  next();
98
98
  return;
99
99
  }
100
+ //
101
+ n++;
100
102
  // 发现订阅
101
- const item = global.storeoberver['message.create'][n];
103
+ const item = global.storeoberver['message.create'][n - 1];
104
+ if (!item) {
105
+ // 继续 next
106
+ nextOberver();
107
+ return;
108
+ }
102
109
  for (const key in item.event) {
103
110
  // 只要发现不符合的,就继续
104
111
  if (item.event[key] !== e[key]) {
105
112
  // 不符合。继续 next。
106
- n++;
107
113
  nextOberver();
108
114
  return;
109
115
  }
110
116
  }
111
- // 符合。调用
112
- item.callback(e, { next });
117
+ // 设置为undefined
118
+ global.storeoberver['message.create'][n - 1] = undefined;
119
+ // 放回来
120
+ const Continue = () => {
121
+ global.storeoberver['message.create'][n - 1] = item;
122
+ // 直接结束才对
123
+ };
124
+ // 没有调用下一步。应该删除当前的 n ?
125
+ // 有没有可能。按key来分。
126
+ item.callback(e, { next: Continue });
127
+ //
113
128
  };
114
129
  const calli = async () => {
115
130
  // 调用完了
@@ -68,8 +68,24 @@ const useOberver = (event, option) => {
68
68
  global.storeoberver = {};
69
69
  if (!global.storeoberver[option])
70
70
  global.storeoberver[option] = [];
71
- // 如果不存在。则创建
72
- global.storeoberver[option].push({ event: v, callback });
71
+ let i = 0;
72
+ const next = () => {
73
+ if (i >= global.storeoberver[option].length) {
74
+ // 如果不存在。则创建
75
+ global.storeoberver[option][i] = { event: v, callback };
76
+ return;
77
+ }
78
+ i++;
79
+ // 是空的。占据位置。
80
+ if (!global.storeoberver[option][i]) {
81
+ global.storeoberver[option][i] = { event: v, callback };
82
+ }
83
+ else {
84
+ // 不是空的。继续
85
+ next();
86
+ }
87
+ };
88
+ next();
73
89
  return;
74
90
  };
75
91
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.0.0-rc.2",
3
+ "version": "2.0.0-rc.3",
4
4
  "description": "啊柠檬脚本",
5
5
  "author": "ningmengchongshui",
6
6
  "license": "MIT",