* 从启用的插件列表构建插件指令、正则匹配指令和 mainPush 功能列表。
(
enabledPlugins: any[],
commandAliases: CommandAliasStore
)
| 726 | * 从启用的插件列表构建插件指令、正则匹配指令和 mainPush 功能列表。 |
| 727 | */ |
| 728 | function buildPluginCommandItems( |
| 729 | enabledPlugins: any[], |
| 730 | commandAliases: CommandAliasStore |
| 731 | ): { pluginItems: Command[]; regexItems: Command[]; mainPushItems: MainPushFeature[] } { |
| 732 | const pluginItems: Command[] = [] |
| 733 | const regexItems: Command[] = [] |
| 734 | const mainPushItems: MainPushFeature[] = [] |
| 735 | |
| 736 | for (const plugin of enabledPlugins) { |
| 737 | if (!plugin.features || !Array.isArray(plugin.features) || plugin.features.length === 0) { |
| 738 | continue |
| 739 | } |
| 740 | |
| 741 | const hasPluginNameCmd = plugin.features.some((feature: any) => |
| 742 | feature.cmds?.some( |
| 743 | (cmd: any) => |
| 744 | (typeof cmd === 'string' ? cmd : cmd.label) === (plugin.title ?? plugin.name) |
| 745 | ) |
| 746 | ) |
| 747 | |
| 748 | if (!hasPluginNameCmd) { |
| 749 | let defaultFeatureCode: string | undefined = undefined |
| 750 | let defaultFeatureExplain: string | undefined = undefined |
| 751 | if (!plugin.main && plugin.features) { |
| 752 | for (const feature of plugin.features) { |
| 753 | if (feature.cmds && Array.isArray(feature.cmds)) { |
| 754 | const hasTextCmd = feature.cmds.some((cmd: any) => typeof cmd === 'string') |
| 755 | if (hasTextCmd) { |
| 756 | defaultFeatureCode = feature.code |
| 757 | defaultFeatureExplain = feature.explain |
| 758 | break |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | pluginItems.push({ |
| 765 | name: plugin.title ?? plugin.name, |
| 766 | path: plugin.path, |
| 767 | icon: plugin.logo, |
| 768 | type: 'plugin', |
| 769 | featureCode: defaultFeatureCode, |
| 770 | pluginName: plugin.name, |
| 771 | pluginTitle: plugin.title, |
| 772 | pluginExplain: defaultFeatureExplain || plugin.description, |
| 773 | pinyin: pinyin(plugin.name, { toneType: 'none', type: 'string' }) |
| 774 | .replace(/\s+/g, '') |
| 775 | .toLowerCase(), |
| 776 | pinyinAbbr: pinyin(plugin.name, { |
| 777 | pattern: 'first', |
| 778 | toneType: 'none', |
| 779 | type: 'string' |
| 780 | }) |
| 781 | .replace(/\s+/g, '') |
| 782 | .toLowerCase() |
| 783 | }) |
| 784 | } |
| 785 |
no test coverage detected