# 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:chiefConstant
- module:chiefTheme
- 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 262

##### 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 143

##### 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 160

##### 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 90

##### 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 125

##### 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 107

##### Returns:

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

Type
  array.<string>

#### (inner) getPluginsRegistryPath() → {string}

This is a wrapper function for the pluginBroker.getPluginsRegistryPath.

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

##### Returns:

The path to the plugins listed in the plugin registry as meta-data.

Type
  string

#### (inner) integrateAllPluginsData(allPluginsData) → {boolean}

Integrates all plugin data for each plugin with the haystacks data structures, this is the final step if the loading of the plugins and basically ensures that all runtime operations of all of the loaded plugins are fully integrated and activated within the haystacks execution environment.

##### Parameters:

Name | Type | Description
--- | --- | ---
`allPluginsData` | object | All of the plugins data for each plugin all combined together into a single JSON data object.

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

##### Returns:

True or False to indicate if all of the data integration was successful or not.

Type
  boolean

#### (inner) integratePluginData(pluginName, pluginData) → {boolean}

Integrates a single plugin data set with the haystacks data structures.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginName` | string | The name of the plugin that should have its data integrated with the haystacks data structure.
`pluginData` | object | The data for the named plugin that should be integrated wtih the haystacks data structure.

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

##### Returns:

True or False to indicate if all the plugin data was integrated successfully with the haystacks data structures.

Type
  boolean

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

This is a wrapper function for pluginBroker.listAllLoadedPlugins.

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

##### Returns:

A list array of the names of the plugins that are currently loaded.

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 388

##### 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 341

##### 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> | Should be the entry-point to the plugin, but it could also be the name of the folder in the plugin registry path that is the entry-point to the plugin. If its the later than we will need to compose the fully qualified path.

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

##### 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 33

##### 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 53

##### 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 177

##### 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 279

##### 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 241

##### Returns:

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

Type
  boolean

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

Unloads a plugin by removing all of the plugin data and meta-data from all of the appropriate data structures in the D-data structure. This is a wrapper function for calling the pluginBroker to get the work done.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginName` | string | The name of the plugin that should have all its data unloaded from the D-data structure.

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

##### Returns:

True or False to indicate if the plugin was unloaded 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 201

##### Returns:

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

Type
  boolean

#### (inner) unregisterPlugins(pluginListArray) → {boolean}

This is a wrapper function for pluginBroker.unregisterPlugins.

##### Parameters:

Name | Type | Description
--- | --- | ---
`pluginListArray` | array.<string> | A list array of plugin names that should be removed from the plugin registry.

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

##### Returns:

True or False to indicate if all the plugins were removed from the plugin registry successfully or not.

Type
  boolean

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

Examines 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 592

##### Returns:

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

Type
  boolean