-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgulp.javascript.txt
132 lines (107 loc) · 7.14 KB
/
gulp.javascript.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
┏━━━━━━━━━━┓
┃ GULP ┃
┗━━━━━━━━━━┛
ALTERNATIVES ==> # - grunt: more declarative
# - gulp (prefered): more imperative. Use streams
VERSION ==> #Node module (5.0.0)
#gulp-cli (3.0.0)
┌─────────┐
│ RUN │
└─────────┘
CONF ==> #Either:
# - ~/.gulp.EXT
# - ./.gulp.EXT
#Where EXT can be js|cjs|mjs|ts|cts|mts|jsx|tsx
CONF.flags #Like CLI flags, OBJ: continue, compactTasks, tasksDepth, gulpfile, silent, series, logLevel, sortTasks,
#require, nodeFlags
CONF.message|timestamp(...) #Customize Gulp output
#Not documented yet
SHELL COMPLETION ==> #See online doc
DEBUGGING ==> #Can either use:
# - node --inspect[-brk] $(which gulp) [TASK...]
# - NODE_OPTIONS=--inspect[-brk] gulp [TASK...]
gulp [TASK...] #Run TASK... (def: 'default')
#If a GULP.watch() is present, doesn't exit
#Can only pass arguments as CLI --flags, then using process.argv
--gulpfile FILE #Def: ./gulpfile.js
-f FILE #Can be in the following formats (providing the related library is installed):
# - gulpfile.babel.js
# - gulpfile.coffee
# - gulpfile.ts
--cwd DIR #Used to search and launch gulpfile.js
--preload FILE #import FILE before reading gulpfile.js
--node-flags STR #Node CLI flags
--series #If several top-level TASK... run with GULP.series() not GULP.parallel()
--continue #Sets UNDERTAKER_SETTLE 'true', i.e. finish all parallel tasks on error (but still error whole task)
--[no-]color #
--log-level
-L #Set several times to set NUM. Can be 1 (error), 2 (warn), 3 (info, def), 4 (debug)
--silent
-S #
--tasks-simple #Only prints all 'TASK' names
--tasks #Only prints all TASK as a tree
-T #Prefixed with CONF.description (def: 'Tasks for GULPFILE_PATH')
#Also shows (if set) for each TASK's FUNC (wrapped or not):
# - FUNC.description STR
# - FUNC.flags { 'OPT': STR, ... } (CLI flags, e.g. parsed with yargs)
--tasks-json #Same but as JSON
--sort-tasks #Sort tasks with --tasks[-json] (def: false)
--tasks-depth NUM #Max depth with --tasks[-json] (def: none)
--compact-tasks #Less depth with --tasks[-json]
┌───────────┐
│ TASKS │
└───────────┘
GULP.Gulp #Inherits from Undertaker (see its doc)
GULP #Instance of GULP.Gulp
GULP.task('TASK', FUNC)
GULP.task(FUNC)
GULP.task('TASK')->FUNC2
GULP.series|parallel
(TASK[_ARR],...)->FUNC2
GULP.tree([OPTS])->OBJ
GULP.lastRun(TASK[, NUM])
->DATE_NUM|undefined
GULP.on
('start|stop|error', FUNC(OBJ)) #Like UNDERTAKER.* (see its doc)
module.exports = {TASK: FUNC, ...}#Same as calling GULP.task('TASK', FUNC)
GULP.src('GLOB'[_ARR][, OPTS])
->IOSTREAM
GULP.dest('DIR'[(VINYL)][, OPTS])
->IOSTREAM
GULP.symlink('DIR'[(VINL)][,OPTS])
->IOSTREAM #Like VINYL-FS.* (see its doc)
GULP.watch #Like GLOB-WATCHER(...) (see its doc)
('GLOB'[_ARR][, OPTS], FUNC) #WATCHER is an EVENTEMITTER, i.e. can be returned in tasks.
->WATCHER #FUNC can e.g. be GULP.series|parallel()
#To only fire tasks for the files that changed:
# - GULP.src(..., { since: GULP.lastRun(FUNC) }):
# - modified since last run of this task
# - only works for watch mode
# - GULP.src(...).pipe(GULP-CHANGED(...)) (see its doc):
# - modified since last write of dest folder of this task
# - does not work for in-place modifications
# - for linting tasks:
# - they should trigger for newly modified files, but also for non-modified files that
# haven't triggered linting errors in previous runs
# - none of the above solves this
# - eslint --cache solves this
┌────────────────────┐
│ BEST PRACTICES │
└────────────────────┘
BEST PATTERN ==> #Instead of GULP.task(), use module.exports = { TASK, ... }
#This implies using GULP.series|parallel(FUNC,...) instead of GULP.series|parallel('TASK',...)
#FUNC should either be async or return a STREAM, not both (because of error handling, see Vinyl doc)
PLUGINS BEST PRACTICES ==> # - exports a FUNC(...)->IOSTREAM
# - use through2 (see its doc)
# - test whether VINYL.isNull|Stream|Buffer()
# - and do not change VINYL.contents type
# - if STREAM|BUFFER not supported, emit an 'error' event
# - inside the IOSTREAM, emit errors with this.emit('error', new PluginError(...)) (see Vinyl doc)
# then call callback()
# - outside, throw ERROR
# - only write plugins if operation is file-based
# - do not add gulp as dependencies|peerDependencies
# - gulpplugin in keyword of package.json
# - prefix project name with 'gulp-'
HELPERS ==> #Most are in Vinyl doc
GRUNT ==> #See https://github.com/gulpjs/gulp/blob/master/docs/recipes/run-grunt-tasks-from-gulp.md