RTB Extension

Extension to RTB API

RTB Extension is a module that can be added to RTB API. Actually it is a function returning BuildFunction.

type RTBExtension = (...args: any[]) => BuildFunction;

It receives arbitrary number of arguments and returns a BuildFunction object. With this RTB instance, users can do necessary operations during the build process. Once the extension is ready, it can be registered to RTB extension set using tron.registerExtension() function.

If the Extension returns promise, then it handled according to the promise processing mechanism involving syncMode state. Otherwise, it runs asynchronously. If synchronous actions are required, you can also use rtb.promise() function instead of returning a promise.

Registering extensions

RTB extensions can be registered to RTB API using tron.registerExtension() function.

extensions/ext-custom.js
const tron = require('gulp-tron');
tron.registerExtension('customExt1', (...args) => (rtb) => {
console.log(`CustomExt1 called. buildName=${rtb.name} args= ${args}`);
});
tron.registerExtension('customExt2', (...args) => (rtb) => {
console.log(`CustomExt2 called. buildName=${rtb.name} args= ${args}`);
});

Using extensions

If the extension are in single or multiple files, it can be loaded using tron.loadExtension() function. Once loaded, it's avaiable in RTB API.

gulpfile.js
tron.loadExtension('./extensions/*.js'));
//--- custom extension
const customExt = {
name: 'custom-ext',
builder: rtb => rtb.customExt1('a', 'b').customExt2('c', 'd')
};

Built-in extensions