You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thats it! If no arguments are given after the gulpfile the `default` task will run instead.
46
+
Thats it! When no arguments are given after `gulpfile` the `default` task will run instead.
42
47
43
-
4. What about the CLI? Can I run `gulp` from the terminal?
48
+
3. What about the CLI? Can I run `gulp` from the terminal?
44
49
45
-
Yes. Just add an alias to your `.bashrc`/`.zshrc`
50
+
Yes. Just add an alias line to your `.bashrc`/`.zshrc`
46
51
47
52
```sh
48
53
alias gulp-runtime='node $(find . -name "gulpfile.js" -not -path "./node_modules/*" | head -n1)'
49
54
```
50
55
51
-
(or change it to your preferences). With that you can use
56
+
which will run the first `gulpfile.js` found excluding `node_moduldes`. Open a new terminal tab and then you can do
52
57
53
58
`gulp-runtime --tasks default watch serve`
54
59
55
-
directly from the terminal.
56
-
57
-
5. And what about CLI commands like `--tasks`, `--version`, etc.?
58
-
59
-
Each of the [gulp cli](https://github.com/gulpjs/gulp/blob/master/docs/CLI.md) commands is defined as a task for the instance. So you can use these as you would with normal tasks.
60
-
61
-
Example:
62
-
63
-
```js
64
-
var gulp =require('gulp-runtime').create();
65
-
66
-
gulp.task('info', ['--tasks', '--version']);
67
-
// other tasks...
68
-
gulp.task('default', ['info']);
69
-
```
70
-
71
60
## API
72
61
73
62
The module comes with the same [gulp API][gulp-api] methods we know and love
@@ -80,43 +69,47 @@ The module comes with the same [gulp API][gulp-api] methods we know and love
80
69
and 4 more
81
70
82
71
[gulp.start](#gulpstart) -
83
-
[gulp.stack](#async-composers) -
84
-
[gulp.series](#async-composers) -
85
-
[gulp.parallel](#async-composers)
72
+
[gulp.stack](#gulpstack) -
73
+
[gulp.series](#gulpseries) -
74
+
[gulp.parallel](#gulpparallel)
75
+
76
+
### Static methods
86
77
87
78
When you require the module
88
79
89
80
```js
90
81
var Gulp =require('gulp-runtime');
91
82
```
92
83
93
-
you get a constructor
94
-
95
-
### Static methods
84
+
you get a constructor with two methods `Gulp.create` and `Gulp.createClass`.
96
85
97
86
#### Gulp.create
98
87
99
88
```js
100
89
functioncreate(Objectoptions)
101
90
```
102
91
103
-
`Gulp.create` creates a new `gulp` instance with the given `options`. These options default to:
92
+
`Gulp.create` creates a new instance with the given `options`. These options default to:
104
93
105
94
- `options.log = true` if `false` the instance will have no logging
106
95
- `options.repl = false` no REPL by default
107
-
- `options.wait = false` tasks run in __parallel__ by default. Pass `wait: true` to run tasks in __series__
96
+
- `options.wait = false` tasks run in __parallel__ by default. Pass `wait: true` to run tasks in __series__ by default
108
97
109
98
#### Gulp.createClass
110
99
111
100
```js
112
101
function createClass(Object mixin)
113
102
```
114
103
115
-
`Gulp.createClass` creates a new `Gulp` class with the given `mixin` mixed in with its parent prototype. If `mixin.create` is given it will be used as constructor.
104
+
`Gulp.createClass` creates a new class. `mixin` is mixed in with its parent prototype. If `mixin.create` is given it will be used as constructor.
116
105
117
106
Example:
118
107
108
+
Say we always want to create instances that log and have a REPL.
109
+
119
110
```js
111
+
// myGulpConstructor.js
112
+
120
113
var Gulp = require('gulp-runtime').createClass({
121
114
create:functionGulp (options) {
122
115
options = options || {};
@@ -125,17 +118,19 @@ var Gulp = require('gulp-runtime').createClass({
125
118
Gulp.super_.call(this, options);
126
119
}
127
120
})
121
+
122
+
module.exports= Gulp;
128
123
```
129
124
130
125
### Instance methods
131
126
132
-
Exactly, instances. You can split builds into instances within the same process and run them separately.
127
+
You can split builds into instances within the same process and run them separately.
133
128
134
129
#### gulp.task
135
130
136
-
`gulp.src`, `gulp.dest`, `gulp.watch` and `gulp.task`behave the same as described in the [`gulp` API documentation][gulp-api].
131
+
`gulp.src`, `gulp.dest`, `gulp.watch` and `gulp.task`behaves the same as described in the [`gulp` API documentation][gulp-api].
137
132
138
-
In addition `gulp.task`task names can also have `:parameters` (like expressjs routes).
133
+
In addition `gulp.task` names can also have `:parameters` (like expressjs routes).
139
134
140
135
Example:
141
136
@@ -148,7 +143,9 @@ gulp.task('build:mode', function (done) {
148
143
});
149
144
```
150
145
151
-
or even have regular expression right after the parameter
146
+
`done` will be always passed as first argument to the task. It should be used if the task does not return a stream, promise or [RxJS][RxJS] observable.
147
+
148
+
Tasks parameters can also contain use regular expressions
152
149
153
150
```js
154
151
var gulp =require('gulp-runtime').create();
@@ -158,7 +155,7 @@ gulp.task('build:mode(-dev|-prod)', function (done){
158
155
});
159
156
```
160
157
161
-
The parameters are defined using [parth][parth]. There you will find more information about what qualifies as parameter and what not.
158
+
Task names are set using [parth][parth]. If you want to know more there you will find more information about how far these can go.
162
159
163
160
#### gulp.start
164
161
@@ -168,7 +165,7 @@ The parameters are defined using [parth][parth]. There you will find more inform
168
165
functionstart(tasks...)
169
166
```
170
167
171
-
Runs any number of `tasks...` given in __parallel__.
168
+
Runs any number of `tasks...` given. They will run __parallel__ by default. If the gulp instance was created with `wait: true` they will in __series__ instead.
172
169
173
170
`tasks...` can be either a `string` (matching one of the tasks registered) or a `function`.
174
171
@@ -182,18 +179,19 @@ function build(done){
182
179
}
183
180
184
181
gulp.task('thing', function (done){
185
-
setTimeout(done, 100);
182
+
setTimeout(done, Math.random()*10);
186
183
});
187
184
188
185
gulp.start(build, 'thing');
189
186
```
190
-
Or, in order to give arguments to the tasks, you can use
187
+
188
+
Which is good, but still limits `gulp.start` to the way the tasks were defined. For this reason you can also pass arguments in a more functional way.
191
189
192
190
```js
193
191
functionstart(Arraytasks, args...[, onStackEnd])
194
192
```
195
193
196
-
If `tasks` is an array it will be taken as the tasks to run and the rest of arguments are passed down. If the last argument is a function it will be called when all of the given `tasks` are finished.
194
+
If `tasks` is an array, these will run with the given `args...`. The last argument may not be a function. If the last argument is a function it will be called when all of the given `tasks` are finished.
197
195
198
196
```js
199
197
var gulp = require('gulp-runtime').create();
@@ -222,9 +220,9 @@ gulp.task('default', function (done) {
222
220
223
221
### async composers
224
222
225
-
`gulp.start` is not enough when you need to compose tasks since it runs them. If you want to compose tasks, you need another function that will run a set of tasks.
223
+
`gulp.start`just runs tasks which is not enough when you only need to compose them. For this reason we need another function that will bundle and run a set of tasks only when called.
226
224
227
-
So, just as tasks dependencies bundle in one task others, we have 3 async composer functions to help with this (in fact there is only one function and two others are sugar on top).
225
+
Just as tasks dependencies bundles into one task others, we have 3 async composer functions to help with this (in fact there is only one function and two others are sugar on top).
228
226
229
227
#### gulp.series
230
228
@@ -263,21 +261,43 @@ function stack(tasks...[, Object options])
263
261
- `options.onHandleError` if given, will run when a task errors
264
262
- `options.onStackEnd` if given, will run when all of the stacked functions have ended (including error)
265
263
264
+
## CLI
265
+
266
+
The initial aim of this project was to be able to run gulp tasks directly from a REPL. But when that was then possible, one also wants to be able to run the CLI while using the REPL, right?
267
+
268
+
For this reason each of the [gulp cli](https://github.com/gulpjs/gulp/blob/master/docs/CLI.md) commands is defined as a task for the instance. This way you can use these as you would with normal tasks.
269
+
270
+
Example:
271
+
272
+
```js
273
+
var gulp = require('gulp-runtime').create();
274
+
275
+
gulp.task('info', ['--tasks', '--version']);
276
+
// other tasks...
277
+
gulp.task('default', ['info']);
278
+
```
279
+
266
280
## REPL
267
281
268
282
```js
269
283
var gulp = require('gulp-runtime').create({repl:true});
270
284
```
271
285
272
-
When an instance passes `repl: true` the process running will not stop but wait and have a REPL listening on `stdin`. This way you can run tasks in the same way you run commands on the terminal.
286
+
When an instance passes `repl: true` the process running will not exit when all tasks are done, instead it will wait and have a REPL listening on `stdin`. This way you can run tasks in the same way you run commands on the terminal.
273
287
274
-
```js
275
-
node gulpfile.js
276
-
# some task logging here...
277
-
# when done press enter
288
+
```sh
289
+
$ node gulpfile.js
290
+
```
291
+
292
+
press enter and you will see a prompt `>` that will run the tasks defined in the gulpfile
293
+
294
+
```sh
295
+
>
278
296
> build less compress png
279
297
```
280
298
299
+
How will tasks run with the REPL?
300
+
281
301
- If those tasks are defined they will run in __parallel__
282
302
- If there is more than one instance with `repl: true` the REPL will go through them and run the first task that matched one of those tasks
283
303
- If one or more of those tasks is not defined there will be a warning and none of the tasks will run for that instance of any of the other ones.
0 commit comments