2024-07-15 00:30:33 +08:00
|
|
|
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
2024-07-21 02:26:03 +08:00
|
|
|
import { pluginGroups, pluginRegistry } from '@certd/pipeline';
|
2024-12-03 00:35:34 +08:00
|
|
|
import { cloneDeep } from 'lodash-es';
|
2024-10-13 01:27:08 +08:00
|
|
|
|
2023-01-29 13:44:19 +08:00
|
|
|
@Provide()
|
2024-12-23 00:24:31 +08:00
|
|
|
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
2024-10-13 01:27:08 +08:00
|
|
|
export class BuiltInPluginService {
|
2023-01-29 13:44:19 +08:00
|
|
|
getList() {
|
|
|
|
|
const collection = pluginRegistry.storage;
|
2025-04-03 00:19:54 +08:00
|
|
|
let list = [];
|
2023-01-29 13:44:19 +08:00
|
|
|
for (const key in collection) {
|
|
|
|
|
const Plugin = collection[key];
|
2024-09-30 12:25:44 +08:00
|
|
|
if (Plugin?.define?.deprecated) {
|
2024-09-29 14:57:20 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
2023-01-29 13:44:19 +08:00
|
|
|
list.push({ ...Plugin.define, key });
|
|
|
|
|
}
|
2025-04-03 00:19:54 +08:00
|
|
|
list = list.sort((a, b) => {
|
|
|
|
|
return (a.order ?? 10 )- (b.order ?? 10);
|
|
|
|
|
});
|
2023-01-29 13:44:19 +08:00
|
|
|
return list;
|
|
|
|
|
}
|
2024-07-21 02:26:03 +08:00
|
|
|
|
|
|
|
|
getGroups() {
|
2025-04-03 00:19:54 +08:00
|
|
|
const groups:any = cloneDeep(pluginGroups);
|
|
|
|
|
for (const key in groups) {
|
|
|
|
|
const group = groups[key];
|
|
|
|
|
group.plugins = group.plugins.sort((a, b) => {
|
|
|
|
|
return (a.order ?? 10 )- (b.order ?? 10);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return groups;
|
2024-07-21 02:26:03 +08:00
|
|
|
}
|
2024-12-03 00:55:37 +08:00
|
|
|
|
|
|
|
|
getByType(type: string) {
|
|
|
|
|
return pluginRegistry.getDefine(type);
|
|
|
|
|
}
|
2023-01-29 13:44:19 +08:00
|
|
|
}
|