* Gets all plugins installed on the local system
()
| 360 | * Gets all plugins installed on the local system |
| 361 | */ |
| 362 | private loadInstalledPlugins(): void { |
| 363 | this.loadDefaultPaths() |
| 364 | |
| 365 | this.searchPaths.forEach((searchPath) => { // search for plugins among all known paths |
| 366 | if (!existsSync(searchPath)) { // just because this path is in require.main.paths doesn't mean it necessarily exists! |
| 367 | return |
| 368 | } |
| 369 | |
| 370 | if (existsSync(join(searchPath, 'package.json'))) { // does this path point inside a single plugin and not a directory containing plugins? |
| 371 | try { |
| 372 | this.loadPlugin(searchPath) |
| 373 | } catch (error: any) { |
| 374 | log.warn(error.message) |
| 375 | } |
| 376 | } else { // read through each directory in this node_modules folder |
| 377 | let relativePluginPaths = readdirSync(searchPath) // search for directories only |
| 378 | .filter((relativePath) => { |
| 379 | try { |
| 380 | return statSync(resolve(searchPath, relativePath)).isDirectory() |
| 381 | } catch (error: any) { |
| 382 | log.debug(`Ignoring path ${resolve(searchPath, relativePath)} - ${error.message}`) |
| 383 | return false |
| 384 | } |
| 385 | }) |
| 386 | |
| 387 | // expand out @scoped plugins |
| 388 | const scopeDirectories = relativePluginPaths.filter(path => path.startsWith('@')) |
| 389 | relativePluginPaths = relativePluginPaths.filter(path => !path.startsWith('@')) |
| 390 | |
| 391 | for (const scopeDirectory of scopeDirectories) { |
| 392 | const absolutePath = join(searchPath, scopeDirectory) |
| 393 | readdirSync(absolutePath) |
| 394 | .filter(name => PluginManager.isQualifiedPluginIdentifier(name)) |
| 395 | .filter((name) => { |
| 396 | try { |
| 397 | return statSync(resolve(absolutePath, name)).isDirectory() |
| 398 | } catch (error: any) { |
| 399 | log.debug(`Ignoring path ${resolve(absolutePath, name)} - ${error.message}`) |
| 400 | return false |
| 401 | } |
| 402 | }) |
| 403 | .forEach(name => relativePluginPaths.push(`${scopeDirectory}/${name}`)) |
| 404 | } |
| 405 | |
| 406 | relativePluginPaths |
| 407 | .filter((pluginIdentifier) => { |
| 408 | return PluginManager.isQualifiedPluginIdentifier(pluginIdentifier) // needs to be a valid homebridge plugin name |
| 409 | && (!this.activePlugins || this.activePlugins.includes(pluginIdentifier)) // check if activePlugins is restricted and if so is the plugin is contained |
| 410 | }) |
| 411 | .forEach((pluginIdentifier) => { |
| 412 | try { |
| 413 | const absolutePath = resolve(searchPath, pluginIdentifier) |
| 414 | this.loadPlugin(absolutePath) |
| 415 | } catch (error: any) { |
| 416 | log.warn(error.message) |
| 417 | } |
| 418 | }) |
| 419 | } |
no test coverage detected