1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| import { keys, orderBy } from "lodash-es";
| import { module } from "../module";
|
| export async function createModules() {
| // 加载 uni_modules 插件
| const files: any = import.meta.glob("/uni_modules/cool-*/config.ts", {
| eager: true,
| });
|
| const modules = orderBy(
| keys(files).map((k) => {
| const [, , name] = k.split("/");
|
| return {
| name,
| value: files[k]?.default,
| };
| }),
| "order",
| "desc",
| );
|
| for (let i in modules) {
| const { name, value } = modules[i];
| const data = value ? value() : undefined;
|
| // 添加模块
| module.add({
| name,
| ...data,
| });
|
| // 触发加载事件
| if (data) {
| await data.onLoad?.(data.options);
| }
| }
| }
|
|