Skip to content

Commit ad627e6

Browse files
dinoboffphated
authored andcommitted
Docs: Mention .description property & add usage examples
1 parent 1abb5ed commit ad627e6

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

docs/API.md

+53-18
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,16 @@ Define a task exposed to gulp-cli, `gulp.series`, `gulp.parallel` and
211211
`gulp.lastRun`; inherited from [undertaker].
212212

213213
```js
214-
gulp.task('somename', function() {
214+
gulp.task(function someTask() {
215215
// Do stuff
216216
});
217217
```
218218

219219
Or get a task that has been registered.
220220

221221
```js
222-
// somenameTask will be the registered task function
223-
var somenameTask = gulp.task('somename');
222+
// someTask will be the registered task function
223+
var someTask = gulp.task('someTask');
224224
```
225225

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

236+
#### fn
237+
238+
The function that performs the task's operations. Generally it takes this form:
239+
240+
```js
241+
function someTask() {
242+
return gulp.src(['some/glob/**/*.ext']).pipe(someplugin());
243+
}
244+
someTask.description = 'Does something';
245+
246+
gulp.task(someTask)
247+
```
248+
249+
Gulp tasks are asynchronous and Gulp uses [async-done] to wait for the task's
250+
completion. Tasks are called with a callback parameter to call to signal
251+
completion. Alternatively, Task can return a stream, a promise, a child process
252+
or a RxJS observable to signal the end of the task.
253+
254+
**Warning:** Sync tasks are not supported and your function will never complete
255+
if the one of the above strategies is not used to signal completion. However,
256+
thrown errors will be caught by Gulp.
257+
258+
#### fn properties
259+
260+
##### fn.name
261+
262+
`gulp.task` names the task after the function `name` property
263+
if the optional `name` parameter of `gulp.task` is not provided.
264+
236265
**Note:** [Function.name] is not writable; it cannot be set or edited. If
237266
you need to assign a function name or use characters that aren't allowed
238267
in function names, use the `displayName` property.
@@ -249,24 +278,30 @@ bar.name = 'bar'
249278
bar.name === '' // true
250279
```
251280

252-
#### fn
253-
Type: `Function`
281+
##### fn.displayName
254282

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

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

267-
**Warning:** Sync tasks are not supported and your function will never complete
268-
if the one of the above strategies is not used to signal completion. However,
269-
thrown errors will be caught by Gulp.
289+
gulp-cli prints this description alongside the task name when listing tasks:
290+
```js
291+
var gulp = require('gulp');
292+
293+
function test(done){
294+
done();
295+
}
296+
test.description = 'I do nothing';
297+
298+
gulp.task(test);
299+
```
300+
```shell
301+
$> gulp --tasks
302+
[12:00:02] Tasks for ~/Documents/some-project/gulpfile.js
303+
[12:00:02] └── test I do nothing
304+
```
270305

271306
#### Async support
272307

docs/CLI.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ gulp has very few flags to know about. All other flags are for tasks to use if n
88
- `--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
99
- `--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
1010
- `--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
11-
- `-T` or `--tasks` will display the task dependency tree for the loaded gulpfile
11+
- `-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).
1212
- `--tasks-simple` will display a plaintext list of tasks for the loaded gulpfile
1313
- `--verify` will verify plugins referenced in project's package.json against the plugins blacklist
1414
- `--color` will force gulp and gulp plugins to display colors even when no color support is detected

0 commit comments

Comments
 (0)