MrFusion42 / gulp-help

Adds a default help task to gulp and provides the ability to add custom help messages to your gulp tasks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gulp-help NPM version Build Status

Adds a default help task to gulp and provides the ability to add custom help messages to your gulp tasks

Install

$ npm install --save-dev gulp-help

Usage

Before defining any tasks, add gulp help to your gulp instance

// gulpfile.js
var gulp = require('gulp-help')(require('gulp'));

Next, define help text for each custom task

// gulpfile.js
gulp.task('lint', 'Lints all server side js', function () {
    gulp.src('./lib/**/*.js')
      .pipe(jshint());
});

Now show that help via gulp help

$ gulp help
[gulp] Running 'help'...

Usage
  gulp [task]

Available tasks
  help Display this help text.
  lint Lints all server side js

[gulp] Finished 'help' in 607 μs

New task API

gulp.task(name[, help, deps, fn, taskOptions])

Type: string

help

Type: string | boolean

Custom help message as a string. If you want to hide the task from the help menu, supply false.

Type: Array

Type: function

taskOptions.aliases

Type: Array

List of aliases for this task.

Hide Tasks

You can optionally hide a target from showing up in the help menu by passing false as the help argument, e.g.

gulp.task('task-hidden-from-help', false, function () {
  // ...
});

However, if the --all flag is provided, even these tasks will be shown. (i.e. gulp help --all)

Aliases

You can optionally add aliases to your targets by supplying an object with an aliases array, e.g.

gulp.task('version', 'prints the version.', [], function() {
  // ...
}, {
  aliases: ['v', 'V']
});

which results in

[gulp] Starting 'help'...

Usage
  gulp [task]

Available tasks
  help     Display this help text.
  version  prints the version. Aliases: v, V

[gulp] Finished 'help' after 928 μs

Options

You can optionally pass options to your targets by supplying an object with an options object, e.g.

gulp.task('version', 'prints the version.', [], function () {
  // ...
}, {
  options: {
    'env=prod': 'description of env, perhaps with available values',
    'key=val': 'description of key & val',
    'key': 'description of key'
  }
});

which results in

[gulp] Starting 'help'...

Usage
  gulp [task]

Available tasks
  help          Display this help text.
  version       prints the version.
    --env=prod  description of env, perhaps with available values
    --key=val   description of key & val
    --key       description of key

[gulp] Finished 'help' after 928 μs

Override default help message

require('gulp-help')(gulp, { description: 'you are looking at it.', aliases: ['h', '?'] });

Then, calling

$ gulp      #or
$ gulp help #or
$ gulp h    #or
$ gulp ?

will now result in

[gulp] Starting 'help'...

Usage:
  gulp [task]

Available tasks:
  help     you are looking at it. Aliases: h, ?

[gulp] Finished 'help' after 1.05 ms

Post-help callback

You can define a function to run after the default help task runs.

require('gulp-help')(gulp, {
  afterPrintCallback: function(tasks) {
    console.log(tasks);
  }
});

License

MIT © Chris Montgomery

About

Adds a default help task to gulp and provides the ability to add custom help messages to your gulp tasks


Languages

Language:JavaScript 100.0%