Skip to content

Commit

Permalink
Docs: Mention .description property & add usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dinoboff authored and phated committed Dec 31, 2017
1 parent 1abb5ed commit ad627e6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
71 changes: 53 additions & 18 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,16 @@ Define a task exposed to gulp-cli, `gulp.series`, `gulp.parallel` and
`gulp.lastRun`; inherited from [undertaker].

```js
gulp.task('somename', function() {
gulp.task(function someTask() {
// Do stuff
});
```

Or get a task that has been registered.

```js
// somenameTask will be the registered task function
var somenameTask = gulp.task('somename');
// someTask will be the registered task function
var someTask = gulp.task('someTask');
```

#### name
Expand All @@ -233,6 +233,35 @@ If the name is not provided, the task will be named after the function
Since the task can be run from the command line, you should avoid using
spaces in task names.

#### fn

The function that performs the task's operations. Generally it takes this form:

```js
function someTask() {
return gulp.src(['some/glob/**/*.ext']).pipe(someplugin());
}
someTask.description = 'Does something';

gulp.task(someTask)
```

Gulp tasks are asynchronous and Gulp uses [async-done] to wait for the task's
completion. Tasks are called with a callback parameter to call to signal
completion. Alternatively, Task can return a stream, a promise, a child process
or a RxJS observable to signal the end of the task.

**Warning:** Sync tasks are not supported and your function will never complete
if the one of the above strategies is not used to signal completion. However,
thrown errors will be caught by Gulp.

#### fn properties

##### fn.name

`gulp.task` names the task after the function `name` property
if the optional `name` parameter of `gulp.task` is not provided.

**Note:** [Function.name] is not writable; it cannot be set or edited. If
you need to assign a function name or use characters that aren't allowed
in function names, use the `displayName` property.
Expand All @@ -249,24 +278,30 @@ bar.name = 'bar'
bar.name === '' // true
```

#### fn
Type: `Function`
##### fn.displayName

The function that performs the task's operations. Generally it takes this form:
```
gulp.task('somename', function() {
return gulp.src(['some/glob/**/*.ext']).pipe(someplugin());
})
```
`gulp.task` names the task after the function `displayName` property
if function is anonymous and the optional `name` parameter of `gulp.task`
is not provided.

Gulp tasks are asynchronous and Gulp uses [async-done] to wait for the tasks'
completion. Tasks are called with a callback parameter to call to signal
completion. Alternatively, Task can return a stream, a promise, a child process
or a RxJS observable to signal the end of the task.
##### fn.description

**Warning:** Sync tasks are not supported and your function will never complete
if the one of the above strategies is not used to signal completion. However,
thrown errors will be caught by Gulp.
gulp-cli prints this description alongside the task name when listing tasks:
```js
var gulp = require('gulp');

function test(done){
done();
}
test.description = 'I do nothing';

gulp.task(test);
```
```shell
$> gulp --tasks
[12:00:02] Tasks for ~/Documents/some-project/gulpfile.js
[12:00:02] └── test I do nothing
```

#### Async support

Expand Down
2 changes: 1 addition & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gulp has very few flags to know about. All other flags are for tasks to use if n
- `--require <module path>` will require a module before running the gulpfile. This is useful for transpilers but also has other applications. You can use multiple `--require` flags
- `--gulpfile <gulpfile path>` will manually set path of gulpfile. Useful if you have multiple gulpfiles. This will set the CWD to the gulpfile directory as well
- `--cwd <dir path>` will manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here
- `-T` or `--tasks` will display the task dependency tree for the loaded gulpfile
- `-T` or `--tasks` will display the task dependency tree for the loaded gulpfile. It will include the task names and their [description](./API.md#fndescription).
- `--tasks-simple` will display a plaintext list of tasks for the loaded gulpfile
- `--verify` will verify plugins referenced in project's package.json against the plugins blacklist
- `--color` will force gulp and gulp plugins to display colors even when no color support is detected
Expand Down

0 comments on commit ad627e6

Please # to comment.