This guide explains how to prepare your Open MCT plugin for use mct - the Open MCT Build Tool.
mct allows developers to build an Open MCT deployment and install and manage Open MCT plugins through a command-line interface. To make your plugin compatible with mct, you need to follow a few key conventions.
- Open MCT plugins are npm packages
- Your plugin needs to have a
package.jsonfile, per the npm standard - Your package.json should define a
mainfield that points to the entry point of your plugin. This should be a file that exports an Open MCT install function. - Your package.json should define a
typefield that is either "commonjs" or "module" depending on whether you are using CommonJS or ES6 modules respectively. - Your package.json should define a
peerDependenciesfield that lists the version(s) of Open MCT your plugin is compatible with. - Your plugin should export an install function that takes an Open MCT instance and, optionally, an options object as arguments.
Your plugin should be published as an npm package with a clear entry point that exports an install function. It is also good practice to include a peerDependencies field in your package.json to specify the version(s) of Open MCT your plugin is compatible with.
mct is compatible with UMD and ES6 modules. To specify that your plugin is an ES6 module, include a "type": "module" field in your package.json. The default type is "commonjs", but this can also be specified manually.
{
"name": "@myorg/openmct-my-plugin",
"version": "1.0.0",
"description": "My awesome Open MCT plugin",
"main": "dist/index.js",
"type": "module",
"peerDependencies": {
"openmct": "^3.0.0"
}
}Your scripts's main entry point must export a function that, when executed, will return an install function. The outer function may optionall accept an options object as an argument. The options object will be populated from one of three sources, in descending order of priority:
- Any options specified on the command line
- Any options specified in a provided recipe
- Any options specified in the YAML configuration file
The returned install function takes an Open MCT instance as an argument.
Example plugins are available from recipes/examples/
Once your plugin is published to npm, users can install it using mct:
# Install to default instance
mct plugins add @myorg/my-openmct-plugin
# Install plugin to a specific instance
mct plugins add @myorg/openmct-my-plugin -i my-instance
The above is shorthand for:
# Install to default instance
mct plugins add my-openmct-plugin --source npm --npmPackage @myorg/my-openmct-plugin
# Install plugin to a specific instance
mct -i my-instance plugins add my-openmct-plugin --source npm --npmPackage @myorg/my-openmct-plugin# Install to default instance
mct plugins add file:../path/to/your/plugin
# Install plugin to a specific instance
mct -i my-instance plugins add file:../path/to/your/pluginThe above is shorthand for:
# Install to default instance
mct plugins add my-local-plugin --npmPackage ../path/to/your/plugin
# Install plugin to a specific instance
mct -i my-instance plugins add my-local-plugin --npmPackage ../path/to/your/pluginNote that when removing a plugin, you must specify the package name, not the source or npm package. Plugin names are normalized during installation.
# Remove plugin from default instance
mct plugins remove my-openmct-plugin
# Remove plugin from specific instance
mct -i my-instance plugins remove my-openmct-pluginPlugins can be configured through mct by specifying options in the YAML configuration file or via the command line.
When a plugin is installed, it's added to the instance's configuration YAML:
openmct:
version: stable
plugins:
- akhenry/openmct-yamcs:
options:
customSetting: "my-value"Each plugin in the configuration can have the following properties:
- enabled (boolean): Whether the plugin is enabled (default: true). This can be used to override plugins that are enabled by default.
- options (object): Configuration options passed to the plugin at install time (optional). These will be converted to a JavaScript object and passed into the object install function as a second argument.
Options can be specified in the YAML configuration file or via the command line.
openmct:
version: stable
plugins:
- akhenry/openmct-yamcs:
options:
customSetting: "my-value"mct plugins configure openmct-my-plugin --options '{"customMessage": "value"}'Note: An options object with named properties is the preferred approach for reasons of user friendliness, but for legacy support an array of JavaScript primitives and / or objects may also be specified here.
openmct:
version: stable
plugins:
- akhenry/openmct-yamcs:
options:
- true
- "my-value"
- 1234
-
- An Array
- Of Valuesmct plugins configure openmct-my-plugin --options '[true, "my-value", 1234, ["An Array", "Of Values"]]'- Update your
package.jsonwith correct version information. Npm uses semver, more information is available here - https://docs.npmjs.com/about-semantic-versioning -
- Best practice: Update your
package.jsonwith apeerDependenciesentry for Open MCT, specifying the version of Open MCT that this version of your plugin has been tested with. This allows the Open MCT build tool to identify version incompatibilities. We strongly recommend specifying an npm version of Open MCT, and not a GitHub version as this avoids the need to compile from source.
- Best practice: Update your
- Build your plugin
- Publish to npm:
npm publish - Users can now install it with the Open MCT build tool
mct