Skip to content

Commit 72d3ae4

Browse files
SanderEliasVillanuevand
authored andcommitted
feat(pluginrpository.ts): refactor registerplugin to take validator
* feat(pluginrpository.ts): refactor registerplugin to take validator To make writing plugins easier, the validator is now a parameter to the registerPlugin function. Also the resiterPlugin functin now checks its types. * fix(pluginrepsitory .ts): user the correct validator * fix(pluginrepository): check type of valdidator is funciton
1 parent 73cfa2b commit 72d3ae4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

scully/pluginManagement/pluginRepository.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,25 @@ export const registerPlugin = (
3535
type: PluginTypes,
3636
name: string,
3737
plugin: any,
38+
validator = async () => [],
3839
{replaceExistingPlugin = false} = {}
3940
) => {
41+
if (!['router', 'render', 'fileHandler'].includes(type)) {
42+
throw new Error(
43+
`Type "${yellow(type)}" is not a known plugin type for registering plugin "${yellow(name)}"`
44+
);
45+
}
4046
if (replaceExistingPlugin === false && plugins[type][name]) {
4147
throw new Error(`Plugin ${name} already exists`);
4248
}
43-
if (type === 'router' && plugin[configValidator] === undefined) {
49+
if (type === 'router' && typeof validator !== 'function') {
4450
logError(`
4551
---------------
46-
Route plugin "${yellow(name)}" should have an config validator attached to '${
47-
plugin.name
48-
}[configValidator]'
52+
Route plugin "${yellow(name)}" should have an config validator attached to '${plugin.name}'
4953
---------------
5054
`);
5155
plugin[configValidator] = async () => [];
5256
}
57+
plugin[configValidator] = validator;
5358
plugins[type][name] = plugin;
5459
};

0 commit comments

Comments
 (0)