Skip to content

Latest commit

 

History

History
226 lines (154 loc) · 5.74 KB

API.md

File metadata and controls

226 lines (154 loc) · 5.74 KB

docs - API - CLI - REPL - logging - arguments

API

The module has 2 static methods

Gulp.create - Gulp.createClass

the same gulp API methods we know and love

gulp.src - gulp.dest - gulp.task - gulp.watch

and 3 more to bundle/run tasks

gulp.series - gulp.parallel - gulp.stack

## Static methods

The module exports a constructor function

var Gulp = require('gulp-runtime');

which has two static methods: Gulp.create and Gulp.createClass.

Gulp.create

function create([Object props])

Gulp.create returns a new instance with the given props.

Defaults are:

  • props.log = true task logging is enabled, pass false to disable it

  • props.repl = false the REPL is disabled, pass true to enable it

  • props.wait = false tasks will run in parallel by default. Pass wait: true to make series the default when running tasks

  • props.onStackEnd called when a stack has ended, defaults to empty function

  • props.onHandleEnd called after a task has ended, defaults to empty function

  • props.onHandleStart called before a task starts, defaults to empty function

  • props.onHandleError called when a task throws, defaults to empty function

These callbacks can be overridden in gulp.series, gulp.parallel and gulp.stack passing an object as a last argument.

Gulp.createClass

function createClass([Object mixin])

Gulp.createClass returns a new constructor function that inherits from its parent prototype.

  • When mixin is given it overrides its parent prototype.
  • When mixin.create is given it will be used as the instance constructor.

Example:

Say we always want to make instances that log and have a REPL.

var Gulp = require('gulp-runtime').createClass({
  create: function Gulp (props) {
    props = props || {};
    props.log = props.repl = true;
    Gulp.super_.call(this, props);
  }
});

exports = module.exports = Gulp;

Instance methods

gulp.task

gulp.src, gulp.dest, gulp.watch and gulp.task behave the same as described in the gulp API documentation.

In addition task names can use :parameters (like expressjs routes) and have arguments passed from other task or task runner.

:parameters example:

var gulp = require('gulp-runtime').create();

gulp.task('build:mode', function (done) {
  console.log(this.params.mode);
  done(); // or do async things
});

done will be always passed as first argument to the task. It should be used if the task does not return a stream, promise or RxJS observable.

Tasks parameters can also use regular expressions using parens right after the parameter

var gulp = require('gulp-runtime').create();

gulp.task('build:mode(-dev|-prod)', function (done){
  done(); // or do async things
});

To know more about how this tasks names can be set see parth.

arguments example:

var gulp = require('gulp-runtime').create();

gulp.task('build', function (done, sources, dest) {
  var stream = gulp.src(sources)
    // some build steps here

  stream.on('end', function () {
    // pass stream to next task
    done(stream);
  });
});

gulp.task('minify', function (done, stream) {
  return stream
    // minify
    .pipe(gulp.dest(dest));
});

gulp.task('build and min', function (done) {
  gulp.series('build', 'minify')('src/**/*.js', 'dest/source.min.js', done);
});

gulp.start

Can be used in two ways

function start(tasks...)

Runs any number of tasks... given with the defaults of the instance.

Each of the tasks... can be either a string or a function.

Example:

var gulp = require('gulp-runtime').create({ wait: true });

function build(done){
  done(); // or do async things
}

gulp.task('thing', function (done){
 setTimeout(done, Math.random()*10);
});

gulp.start(build, 'thing');
// ^ will run in series since the instance was created with `{wait: true}`
function start(Array tasks, args...)

Same as start(tasks...) but passing the args... down to each of the tasks run.

gulp.series

function series(tasks...[, Object options])

series bundles the given tasks... into one async function and returns it. This function will always run the tasks... in series.

Its sugar on top of [gulp.stack][#gulpstack]. See [gulp.stack][#gulpstack] for more information about options.

gulp.parallel

function parallel(tasks...[, Object options])

parallel bundles the given tasks... into one async function and returns it. This function will always run the tasks... in parallel.

Its sugar on top of [gulp.stack][#gulpstack]. See [gulp.stack][#gulpstack] for more information about options.

gulp.stack

function stack(tasks...[, Object options])

stack bundles the given tasks... into one async function and returns it.

Each tasks... can be either a string or a function.

If given, options will override the instance props for this stack.


Back to top ↑