# Module: chiefPlugin

Contains all of the functions to manage the loading, unloading, reloading, registering, unregistering of plugins and plugin metaData.

Author:
  - Seth Hollingsead
Copyright:
  - Copyright © 2022-… by Seth Hollingsead. All rights reserved
Source:
  - controllers/chiefPlugin.js, line 1

### Requires

- module:pluginBroker
- module:loggers
- module:stack
- @haystacks/constants
- path

### Methods

#### (inner) clearPluginRegistry() → {boolean}

This is a wrapper function for pluginBroker.unregisterAllPlugins.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 221

##### Returns:

True or False to indicate if the plugin registry data hive was cleared successfully or not.

Type
  boolean

#### (inner) countAllPluginsInRegistry() → {integer}

This is a wrapper function for pluginBroker.countPluginsInRegistry.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 122

##### Returns:

The count of the number of plugins listed in the plugin registry data hive.

Type
  integer

#### (inner) countAllPluginsInRegistryPath() → {integer}

This is a wrapper function for pluginBroker.countPluginsInRegistryPath.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 139

##### Returns:

The count of the number of plugin sub-folders in the plugins path listed in the plugin registry data hive.

Type
  integer

#### (inner) getAllPluginsInRegistry() → {array.<string>}

This is a wrapper function for pluginBroker.listPluginsInRegistry.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 69

##### Returns:

A list array of the names of the plugins in the plugin registry.

Type
  array.<string>

#### (inner) getAllPluginsInRegistryPath() → {array.<string>}

This is a wrapper function for pluginBroker.listPluginsInRegistryPath.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 104

##### Returns:

A list array of the names of the plugins located at the specified path on the local system from the plugins registry data hive.

Type
  array.<string>

#### (inner) getAllPluginsPathsInRegistry() → {array.<string>}

This is a wrapper function for pluginBroker.listPluginsPathsInRegistry The purpose is to get the array of paths for all of the plugins that must be loaded.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 86

##### Returns:

A list array of all the paths of all the plugins in the plugin registry.

Type
  array.<string>

#### (inner) loadAllPlugins(pluginsExecutionPaths, pluginsMetaData) → {object}

This is a wrapper function that iterates over the list of plugin URI paths to import and calls the loadPlugin function on the pluginBroker to actually load the plugin data, metaData, business rules, commands, constants, constants validation, command aliases, configuration settings, debug settings and workflows.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginsExecutionPaths` | array.<string> | An array of fully qualified path URI's to be imported and executed for each plugin.
`pluginsMetaData` | array.<object> | An array of JSON objects that contain all of the package.json data loaded for each plugin that should be imported, we are passing this along here, to have access to the name of each plugin as it is loaded.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 344

##### Returns:

An object containing objects that contain all of the data and functions from each plugin, these will need to be decomposed and merged with the D-data structure as appropriate.

Type
  object

#### (inner) loadAllPluginsExecutionPaths(pluginsMetaData, pluginsPaths) → {array.<string>}

Extracts the path to the main entry point for each plugin and does a path join to form a fully qualified path, then converts the fully qualified path to a file URI so it can be imported.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginsMetaData` | array.<object> | An array of JSON objects that contain all of the package.json data loaded for each plugin that should be imported.
`pluginsPaths` | array.<string> | An array of fully qualified paths where each plugin was loaded from, used to path.join with the execution path entry point file for each plugin.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 297

##### Returns:

An array of fully qualified path URI's for each of the main entry points for all of the plugins that should be loaded.

Type
  array.<string>

#### (inner) loadAllPluginsMetaData(pluginsPaths) → {array.<object>}

Loads the plugin meta data for all of the plugins in the input plugins path array.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginsPaths` | array.<string> |

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 255

##### Returns:

An array that contains all of the meta-data, for each of the plugins in the input pluginsPaths array.

Type
  array.<object>

#### (inner) loadPluginRegistryData(pluginRegistryPath) → {object}

Loads the plugin registry meta data which includes paths to plugins.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginRegistryPath` | string |

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 29

##### Returns:

A JSON object loaded from the specified path with the plugin paths and plugin metaData.

Type
  object

#### (inner) persistPluginRegistryToDataStructure(pluginRegistryData) → {boolean}

Saves the plugin registry data to the D-data structure.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginRegistryData` | object |

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 49

##### Returns:

True or False to indicate if the persistense was successful or not.

Type
  boolean

#### (inner) registerNamedPlugin(pluginName, pluginPath) → {boolean}

This is a wrapper function for pluginBroker.registerPlugin.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginName` | string | The name of the plugin that should be registered.
`pluginPath` | string | The path to the plugin, to be added to the plugin registry. This should be the path to the plugin/package.json file, but not including the package.json as part of the path URI.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 156

##### Returns:

True or False to indicate if the plugin was added to the plugin registry successfully or not.

Type
  boolean

#### (inner) savePluginRegistryDisk() → {boolean}

This is a wrapper function for pluginBroker.savePluginRegistry.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 238

##### Returns:

True or False to indicate if the plugin registry was successfully saved to the disk or not.

Type
  boolean

#### (inner) synchronizePluginRegistryWithPath() → {boolean}

This is a wrapper function for pluginBroker.syncPluginRegistryWithPluginRegistryPath.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 200

##### Returns:

True or False to indicate if the synchronization was performed successfully or not.

Type
  boolean

#### (inner) unregisterNamedPlugin(pluginName) → {boolean}

This is a wrapper function for pluginBroker.unregisterPlugin.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginName` | string | The name of the plugin that should be removed from the plugin registry.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 180

##### Returns:

True or False to indicate if the plugin was removed from the plugin registry successfully or not.

Type
  boolean

#### (inner) verifyAllPluginsLoaded() → {boolean}

Examins the pluginsLoaded stack to confirm that none of the plugins which were supposed to have been loaded failed to load.

Author:
  - Seth Hollingsead
Source:
  - controllers/chiefPlugin.js, line 409

##### Returns:

True or False to indicate if all of the plugins were loaded successfully or not.

Type
  boolean