Skip to content

Plugins

Player supports methods to alter how DSL Content gets compiled into JSON that Player ingests. Any method of manipulating the DSL or Schema is referred to as a “DSL Plugin” (e.g. cli-plugin, using the DSL hooks directly, etc.). A “DSL Plugin” is not any particular code construct.

Below are some examples of how you might use DSL Plugins to augment the DSL compilation process.

These examples assume access to a DSLCompiler instance, which we will call compiler. You generally will not instantiate your own DSLCompiler. Instead, you will access one that has been made available to you, e.g. via PlayerCLIPlugin.onCreateDSLCompiler.

Example 1: Pre-Processing Flow Enhancement

Section titled “Example 1: Pre-Processing Flow Enhancement”

The preProcessFlow hook is generally useful for adding information that will affect the compilation process later on. This example adds a function to the flow that will be used later on in the compilation process.

compiler.hooks.preProcessFlow.tap('VersionInjector', (flow) => {
// Add version and timestamp to the flow
return {
...flow,
// Simple function example
hello: () => console.log('Hello, world!')
};
});

Example 2: Post-Processing Metadata Injection

Section titled “Example 2: Post-Processing Metadata Injection”

This example demonstrates how to add metadata to the compiled flow after compilation is complete. This is useful for adding information that doesn’t affect the compilation process itself.

compiler.hooks.postProcessFlow.tap('MetadataInjector', (compiledFlow) => {
return {
...compiledFlow,
compilationInfo: {
timestamp: new Date().toISOString(),
version: '1.0.0',
customProcessed: true
}
};
});

This example shows how to tap into the schema generation process to add custom validation rules to schema nodes. It adds a custom validation node to required a minimum length of 1.

compiler.hooks.schemaGenerator.tap('SchemaValidator', (schemaGenerator) => {
schemaGenerator.hooks.createSchemaNode.tap('CustomSchemaValidation', (node, originalProperty) => {
// Add custom validation rules to string schema nodes
if (node.type === 'string') {
return {
...node,
// Add minimum length validation for string fields
validation: {
...node.validation,
minLength: 1,
customRule: 'no-empty-strings'
}
};
}
return node;
});
});