Builders

Builder is a property of BuildConfig defining entry point of the gulp task to be created. Curently, following builder types are available.

  • BuilderClassName
  • BuildFunction
  • ExternalCommand
  • GBuilder
  • 'cleaner'
  • 'watcher'

BuilderClassName

Class name, in string type, of built-in builders or user defined class derived from GBuilder.

Example:

const sass = {
name: 'sass',
builder: 'GCSSBuilder',
// ...
}

If BuilderClassName is used, the class definition file with the name is searched in the custom directory locations specified by ProjectOptions.customBuildDirs first. If no file found, then built-in builders are searched for the mathing. This sequence gives a chance to override built-in builder classes with the same name. If no builder is specified, default function which does nothing is assigned. Refer to ProjectOptions for more information on customBuildDirs option.

BuildFunction

type BuildFunction = (rtb: RTB, ...args: any[]) => void | Promise<unknown>;

This is a function to be executed for build process. RTB instance is passed as its first argument. If it returns promise, build task is not finished until the promise is fullfilled. Optional arguments(args) are delivered if available. Refer to Extension for example of using optional arguments.

Example:

const customFunction = {
name: 'customFunction',
builder: (rtb) => console.log('Custom builder using function(): Hello!!!', rtb.name)
};

ExternalCommand

Builder can be an external command object with following data type:

interface ExternalCommand {
command: string,
args?: string[];
options?: SpawnOptions;
}
propertydescription
commandcommand name that can be executed by process.spawn() function
argscommand line argument list
optionsAccepts all the options for process.spawn() function and the followings
options.silentSuppress all the output messages
options.verbosePrint excessive messages
options.syncExcutes the command in sequence by calling order of other build routines in sync mode. Refer to [RTB] section for more information.

Example:

const cmd1 = {
name: 'node-version',
builder: { command: 'node', args: ['-v'] },
}

GBuilder

GBuilder is a built-in class that copies files listed in conf.src to conf.dest. This is a base class that all the built-in classes are derivatived from. It has a member function build() which is executed by gulp task. Custom classes can also defined by extending GBuilder and defining its own build function. If the build function returns promise, build task is not finished until the promise is fullfilled.

GBuilder interface:

class GBuilder {
protected build() => void | Promise<unknown>;
}

Built-in Builders

Currently, following built-in builders are available:

Built-in builders are available from tron.builders property. Typically in BuildConfig, BuilderClassName is used rather than directly creating GBuilder class instances.

Example

const tron = require('gulp-build-manafer');
// using GBuilder as copy builder: copy src to dest
const copy1 = {
name: 'copy',
builder: new tron.builders.GBuilder,
src: 'www/**/*.html',
dest: 'www',
}
// using BuilderClass
const copy2 = {
name: 'copy',
builder: 'GBuilder', // same as 'new tron.builders.GBuilder'
src: 'www/**/*.html',
dest: 'www2',
}

Custom Builders

Custom builder class can be defined by extending tron.builders.GBuilder and redefining builder() function.

Example

const tron = require('gulp-build-manafer');
//--- custom builder with new build process
class CustomBuilder extends tron.builders.GBuilder {
constructor() { super() }
build() {
console.log(`CustomBuilder is building '${this.name}'`);
}
}
const customBuilder = {
name: 'custom-builder',
builder: new CustomBuilder(),
};
//--- custom builder extending built-in builder
class CustomCSSBuilder extends tron.builders.GCSSBuilder {
// redefine src() function to add debug call
src() {
// print input files by overloading src() function
return super.src().debug({ title: 'MyCSSBuilder:' })
}
}
const customCSSBuilder = {
name: 'custom-css-builder',
builder: new CustomCSSBuilder(),
src: upath.join(basePath, '*.scss'),
dest: (file) => file.base,
clean: [upath.join(basePath, "sample.css")]
};

cleaner

Predefined built-in builder, Cleaner. Refer to CleanerConfig for more information.

watcher

Predefined built-in builder, Watcher. Refer to WatcherConfig for more information.