RTB

Quick Example

Th example will copy *.txt files, showing the file names using 'gulp-debug'.

const tron = require('gulp-tron');
const copy = {
name: 'my-copy',
builder: rtb => rtb.src().debug({title: rtb.name + '::'}).dest(),
src: ['src/**/*.txt'],
dest: '_build'
}
tron.createProject({copy}).addWatcher();

RTB API

setBuildOptions()

setBuildOptions(opts: Options): void;

Merge opts to rtb.buildOptions. This is shallow copy using Object.assign().

setModuleOptions()

setModuleOptions(opts: Options): void;

Merge opts to rtb.moduleOptions. This is shallow copy using Object.assign().

src()

src(src?: string | string[]) => this;

Creates internal gulp stream with files specified in BuildConf.src. sourceMap is automatically handled if it is enabled in BuildConfig.

dest()

dest(path?: string) => this;

Calls gulp.dest() on internal gulp stream with BuildConf.dest. sourceMap is automatically handled if is enabled in BuildConfig.

pipe()

pipe(destination: any, options?: { end?: boolean; }) => this;

Calls gulp pipe() on internal gulp stream.

chain()

chain(action: BuildFunction) => this;

Calls plugin action with this RTB innstance. If promise is returned from the plugin, then it is handled in sync or async depending on current sync mode.

promise()

type PromiseExecutor = () => void | Promise<unknown>;
promise(promise?: Promise<unknown> | void | PromiseExecutor, sync: boolean = false) => this;

If 'promise' argument is an instance of Promise, then it is added to sync or async promise queue depending on current sync mode (default is async).

If promise is a function, then it is added to sync promise queue in sync mode, or it is executed immediately in async mode. if it returns promise, then it is added to sync or async queue depending on current sync mode.

The last argument, 'sync' will override current sync mode.

Current sync mode is determined by conf.sync property initially, but it can be changed by RTB functions, sync() or async().

Note that all the promise objects, sync or async, are waited before finishing the build process. If no sync mode specified, all the build operations are executed in async mode by default for better performance.

sync()

sync() => this;

Turns on sync mode. Once enabled, all the build operations are executed in sequence.

async()

async() => this;

Turns off sync mode. In async mode, all the build operations are executed in parallel.

wait()

wait(msec: number = 0, sync: boolean = false) => this;

Add a promise waiting for msec. In sync mode, this will suspend build operations in sync promise queue for msec. In async mode, this wait will be independent of other build operations, and it will only delays the finishig of whole build process up to msec.

The last argument, 'sync' will override current sync state for this operation.

pushStream()

pushStream() => this;

Save current gulp stream into internal stream queue. Multiple pushes are allowed.

popStream()

popStream() => this;

If internal promise queue is not empty, then current stream is added to promise execution sequence to be flushed, and the latest stream pushed to the internal stream queue is restored as current stream. Multiple pops are allowed.

debug()

debug(options: Options = {}) => this;

Loads 'gulp-debug' module and pipe it to internal gulp stream with opts as argument.

filter()

filter(pattern: string | string[] | filter.FileFunction = ["**", "!**/*.map"],
options: filter.Options = {}) => this;

Loads 'gulp-filter' module and pipe it to internal gulp stream with pattern and options as argument.

rename()

rename(options: Options = {}) => this;

Loads 'gulp-rename' module and pipe it to internal gulp stream with options as argument. Refer to gulp-rename documents for option details.

copy()

copy(param?: CopyParam | CopyParam[], options: Options = {}) => this;

In sync mode, all the copy operations specified in 'param' are added to sync promise queue, and will be executed in sequence. In async mode, all the copy operations executed immediately, and the returned promise is added to sync or async queue depending on current sync state.

The last argument, 'sync' will override current sync state for this operation.

del()

del(patterns: string | string[], options: Options = {}) => this;

In sync mode, delete operation is added to sync promise queue, and will be executed in sequence. In async mode, delete operation executed immediately, and the returned promise is added to sync or async queue depending on current sync state.

For this operation, 'del' module is loaded and called with pattern and options as arguments.

options

options argument accepts all the properties available from node 'del' module.

In addition, options.sync can be specified to override current sync state for this operation.

exec()

exec(cmd: string | ExternalCommand, args: string[] = [], options: SpawnOptions = {}) => this;

Executes external commands with cmd, args, and options. In sync mode, the command execution is added to sync promise queue, and will be executed in sequence. In async mode, the command is executed immediately, and the returned promise is added to sync or async queue depending on current sync state.

The last argument, 'sync' will override current sync state for this operation.

clean()

clean(options: CleanOptions = {}): this

Triggers delete operations for the patterns specified in BuildConfig.clean and options.clean. For this operation, 'del' module is loaded and called with options as arguments.

In sync mode, the clean operation is added to sync promise queue, and will be executed in sequence. In async mode, it is executed immediately, and the returned promise is added to sync or async queue depending on current sync state.

options

clean() internally use del(). So, options argument accepts all the properties available for del() including options.sync.

concat()

concat(options: Options = {}) => this;

Loads 'gulp-concat' module and pipe it to internal gulp stream with BuildConfig.outFile and options.concat as arguments. if BuildConfig.outFile is not specified, the operation will be skipped with a warning message. In this operation, *.map files in current gulp stream will be filtered out. If BuildConfig.sourceMaps is set to true, map files will be generated.

minifyCss()

minifyCss(options: Options = {}) => this;

Minify css files in the current stream. This operation will filter out .map files. Output files will have '.min.css' extension names. If BuildConfig.sourceMaps is set to true, map files will be grnerated.

minifyJs()

minifyJs(options: Options = {}) => this;

Minify javascript files in the current stream. This operation will filter out .map files. Output files will have '.min.js' extion names. If BuildConfig.sourceMaps is set to true, map files will be grnerated.


Properties

conf

BuildConfig object this RTB is attached to.

name

Name of the build configuration, and the name of gulp task created for the build process.

buildOptions

Shortcut to conf.buildOptions

moduleOptions

Shortcut to conf.moduleOptions

stream

Internal file stream, typically opened by gulp.src() when conf.src is valid.