Register a new plugin
Overview
The registerPlugin function adds a new plugin to Scully. This function has 5 parameters:
type: string
- Indicates the plugin's type.
- The existing types are:
router,render,fileHandler,allDone, orrouteDiscoveryDone.
name: string
- The plugin's name.
- This must be unique for the type of plugin.
- To replace an existing plugin, set the
replaceExistingPluginoption.
plugin: any
- The plugin's function.
- Contains the plugin's logic.
- Plugin types are described in their own type descriptions
validator?: function (optional)
- A validation function.
- It should return an array of errors.
- If there are no errors, it should return a
falsevalue. - If it returns a
string<array>, those strings are displayed as errors, and the process is aborted.
Tip: Add color to the validator errors by using the colors exported from Scully.
Validator Example:
import { yellow } from '@scullyio/scully';
// Omitted code ...
const validator = async options => {
const errors = [];
if (options.numberOfPages && typeof options.numberOfPages !== 'number') {
errors.push(
`my-custom-plugin numberOfPages should be a number, not a ${yellow(
typeof options.numberOfPages
)}`
);
}
return errors;
};
options?: <..> (optional)
The options object can be used to set the plugin options.
At the moment, the only available option is replaceExistingPlugin.