| 172 | } |
| 173 | |
| 174 | async init() { |
| 175 | const pluginNames: string[] = [] |
| 176 | const pluginObj: Record<string, PluginRuntime> = {} |
| 177 | this.plugins.forEach(plugin => { |
| 178 | pluginNames.push(plugin.name) |
| 179 | pluginObj[plugin.name] = plugin |
| 180 | }) |
| 181 | |
| 182 | // check plugin dependency |
| 183 | const { missingTasks, sequence } = sequencify(pluginObj, pluginNames) |
| 184 | if (missingTasks.length) { |
| 185 | logger.error('plugin dependency missing', missingTasks) |
| 186 | return |
| 187 | } |
| 188 | logger.log('load plugin sequence:', sequence) |
| 189 | |
| 190 | for (const pluginName of sequence) { |
| 191 | try { |
| 192 | await this.pluginsMap.get(pluginName)!.init() |
| 193 | } catch (e) { |
| 194 | logger.error(`Failed to init plugin:${pluginName}, it maybe affect those plugins which depend on this.`) |
| 195 | logger.error(e) |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * destroy all plugins |