From 99c02534e799d7b43366a3df9f15f1e7b60fc83c Mon Sep 17 00:00:00 2001 From: Sander Elias Date: Thu, 23 Jan 2020 14:15:21 +0100 Subject: [PATCH] fix(registerplugin): better error on type (#225) * fix(registerplugin): better error on type When given the wrong type for a plugin, throw a proper explaination. closes #219 * fix(typo): fix typo in errormessage --- scully/pluginManagement/pluginRepository.ts | 9 ++++++--- scully/pluginManagement/systemPlugins.ts | 1 + scully/routerPlugins/ignoredRoutePlugin.ts | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 scully/routerPlugins/ignoredRoutePlugin.ts diff --git a/scully/pluginManagement/pluginRepository.ts b/scully/pluginManagement/pluginRepository.ts index f7b433c3e..8183e2932 100644 --- a/scully/pluginManagement/pluginRepository.ts +++ b/scully/pluginManagement/pluginRepository.ts @@ -39,9 +39,12 @@ export const registerPlugin = ( {replaceExistingPlugin = false} = {} ) => { if (!['router', 'render', 'fileHandler'].includes(type)) { - throw new Error( - `Type "${yellow(type)}" is not a known plugin type for registering plugin "${yellow(name)}"` - ); + throw new Error(` +-------------- + Type "${yellow(type)}" is not a known plugin type for registering plugin "${yellow(name)}". + The first parameter of registerPlugin needs to be one of: 'fileHandler', 'router', 'render' +-------------- +`); } if (replaceExistingPlugin === false && plugins[type][name]) { throw new Error(`Plugin ${name} already exists`); diff --git a/scully/pluginManagement/systemPlugins.ts b/scully/pluginManagement/systemPlugins.ts index fe51c9480..c35a43ba5 100644 --- a/scully/pluginManagement/systemPlugins.ts +++ b/scully/pluginManagement/systemPlugins.ts @@ -3,3 +3,4 @@ import '../fileHanderPlugins/asciidoc'; import '../renderPlugins/contentRenderPlugin'; import '../routerPlugins/jsonRoutePlugin'; import '../routerPlugins/contentFolderPlugin'; +import '../routerPlugins/ignoredRoutePlugin'; diff --git a/scully/routerPlugins/ignoredRoutePlugin.ts b/scully/routerPlugins/ignoredRoutePlugin.ts new file mode 100644 index 000000000..a654344bf --- /dev/null +++ b/scully/routerPlugins/ignoredRoutePlugin.ts @@ -0,0 +1,7 @@ +import {registerPlugin} from '../pluginManagement/pluginRepository'; + +/** + * The ignoredPlugin helps to take routes out. + * when you use this plugin, the route will never be rendered. + */ +registerPlugin('router', 'ignored', () => []);