1
1
'use strict' ;
2
- /*jshint -W089 */
3
2
4
3
module . exports = function HelpTask ( gulp ) {
5
-
6
4
/**
7
5
* Modifies the gulp.task() function and builds a list of all tasks.
8
6
*
@@ -32,7 +30,6 @@ module.exports = function HelpTask (gulp) {
32
30
let log = this . byId ( 'log' , true ) || console . log . bind ( console ) ;
33
31
34
32
const parseFn = require ( 'parse-function' ) ;
35
- const util = require ( 'util' ) ;
36
33
const extractComments = require ( 'extract-comments' ) ;
37
34
const _task = gulp . task ;
38
35
const taskInfo = { } ;
@@ -69,10 +66,10 @@ module.exports = function HelpTask (gulp) {
69
66
if ( typeof fn === 'function' ) {
70
67
let info = parseFn ( fn . toString ( ) ) ;
71
68
entry = {
72
- name : id
69
+ name : id
73
70
} ;
74
- entry . description = util . format ( ' Runs the %s task (no description)' , id ) ;
75
- let comments = extractComments ( info . body , { first : true } ) ;
71
+ entry . description = ` Runs the ${ id } task (no description)` ;
72
+ let comments = extractComments ( info . body , { first : true } ) ;
76
73
if ( comments . length ) {
77
74
let comment = comments [ 0 ] ;
78
75
let lines = comment . raw
@@ -84,17 +81,17 @@ module.exports = function HelpTask (gulp) {
84
81
}
85
82
} else if ( id === 'default' ) {
86
83
entry = {
87
- name : 'default' ,
88
- description : 'Runs the default tasks: ' + deps . join ( ' ' )
84
+ name : 'default' ,
85
+ description : 'Runs the default tasks: ' + deps . join ( ' ' )
89
86
} ;
90
87
}
91
88
92
89
if ( entry ) {
93
90
entry . deps = deps ;
94
91
if ( DEBUG ) {
95
- let line = [ ' Adding' , chalk . cyan ( entry . name ) , ' task' ] ;
92
+ let line = [ ` Adding ${ chalk . cyan ( entry . name ) } task` ] ;
96
93
if ( deps . length ) {
97
- line . push ( ' - depending on ' , chalk . magenta ( deps . join ( ' ' ) ) ) ;
94
+ line . push ( ` - depending on ${ chalk . magenta ( deps . join ( ' ' ) ) } ` ) ;
98
95
}
99
96
log . apply ( chalk , line ) ;
100
97
}
@@ -109,7 +106,6 @@ module.exports = function HelpTask (gulp) {
109
106
gulp . task ( 'help' , function ( ) {
110
107
/* Prints an overview over all available Gulp tasks. */
111
108
112
- let util = require ( 'util' ) ;
113
109
let pad = require ( 'pad' ) ;
114
110
let lines = [ '' ] ;
115
111
let padding = 5 ;
@@ -124,12 +120,14 @@ module.exports = function HelpTask (gulp) {
124
120
let taskIds = Object . keys ( taskInfo ) ;
125
121
let taskLengths = taskIds . map ( function ( id ) { return id . length ; } ) ;
126
122
let maxLength = Math . max . apply ( Math , taskLengths ) ;
127
-
128
- for ( let key in taskInfo ) {
123
+ let keys = Object . keys ( taskInfo ) ;
124
+ keys . sort ( ) ;
125
+ for ( var i = 0 ; i < keys . length ; i ++ ) {
126
+ let key = keys [ i ] ;
129
127
let entry = taskInfo [ key ] ;
130
128
let paddingLength = maxLength ;
131
- let str = new Array ( paddingLength + 2 ) . join ( ' ' ) ;
132
- let descriptionLine = util . format ( ' Runs the %s task.' , key ) ;
129
+ let str = new Array ( paddingLength + 2 ) . join ( ' ' ) ;
130
+ let descriptionLine = ` Runs the ${ key } task.` ;
133
131
if ( entry . description ) descriptionLine = mapDescription ( str , entry . description ) ;
134
132
lines . push ( ' ' + pad ( entry . name , maxLength ) + paddingStr + descriptionLine . join ( '\n' ) . trim ( ) ) ;
135
133
lines . push ( '' ) ;
@@ -147,13 +145,12 @@ module.exports = function HelpTask (gulp) {
147
145
* @private
148
146
*/
149
147
150
- function mapDescription ( str , lines ) {
148
+ function mapDescription ( str , lines ) {
151
149
if ( typeof lines === 'string' ) lines = [ lines ] ;
152
150
return lines . map ( function ( line , index ) {
153
151
line = line . trim ( ) ;
154
152
return index ? str + paddingStr + line : line ;
155
153
} ) ;
156
154
}
157
155
} ) ;
158
-
159
156
} ;
0 commit comments