Skip to content

Commit 28d6438

Browse files
committed
docs: WIP better structrure and table of contents
1 parent 24deec7 commit 28d6438

File tree

1 file changed

+82
-61
lines changed

1 file changed

+82
-61
lines changed

docs/README.md

Lines changed: 82 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
> Find something missing? [Open an issue](open-an-issue)
22
3-
#### index
4-
5-
create: [Gulp.create](#gulpcreate) - [Gulp.createClass](#gulpcreateclass) <br>
6-
definition: [gulp.task](#gulptask) -
7-
[gulp.src](#gulptask) -
8-
[gulp.dest](#gulptask) -
9-
[gulp.watch](#gulptask) <br>
10-
composition: [gulp.start](#gulpstart) -
11-
[gulp.stack](#async-composers) -
12-
[gulp.series](#async-composers) -
13-
[gulp.parallel](#async-composers)
14-
153
# documentation
164

17-
## Setup
5+
<!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:0 orderedList:0 -->
6+
7+
- [Setup](#setup)
8+
- [API](#api)
9+
- [Static methods](#static-methods)
10+
- [Gulp.create](#gulpcreate)
11+
- [Gulp.createClass](#gulpcreateclass)
12+
- [Instance methods](#instance-methods)
13+
- [gulp.task](#gulptask)
14+
- [gulp.start](#gulpstart)
15+
- [async composers](#async-composers)
16+
- [gulp.series](#gulpseries)
17+
- [gulp.parallel](#gulpparallel)
18+
- [gulp.stack](#gulpstack)
19+
- [CLI](#cli)
20+
- [REPL](#repl)
21+
22+
<!-- /TOC -->
1823

19-
1. You don't know gulp? [First go here][gulp-what-is]
24+
## Setup
2025

21-
2. Install `npm install --save-dev gulp-runtime`
26+
1. Install `npm install --save-dev gulp-runtime`
2227

23-
3. Open a `gulpfile` (or [create one][example-gulpfile]) and change this line
28+
2. Open a `gulpfile`, or [create one][example-gulpfile], and change this line
2429

2530
```js
2631
var gulp = require('gulp');
@@ -38,36 +43,20 @@ composition: [gulp.start](#gulpstart) -
3843
node gulpfile.js default watch serve
3944
```
4045

41-
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.
4247

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?
4449

45-
Yes. Just add an alias to your `.bashrc`/`.zshrc`
50+
Yes. Just add an alias line to your `.bashrc`/`.zshrc`
4651

4752
```sh
4853
alias gulp-runtime='node $(find . -name "gulpfile.js" -not -path "./node_modules/*" | head -n1)'
4954
```
5055

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
5257

5358
`gulp-runtime --tasks default watch serve`
5459

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-
7160
## API
7261

7362
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
8069
and 4 more
8170

8271
[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
8677

8778
When you require the module
8879

8980
```js
9081
var Gulp = require('gulp-runtime');
9182
```
9283

93-
you get a constructor
94-
95-
### Static methods
84+
you get a constructor with two methods `Gulp.create` and `Gulp.createClass`.
9685

9786
#### Gulp.create
9887

9988
```js
10089
function create(Object options)
10190
```
10291

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:
10493

10594
- `options.log = true` if `false` the instance will have no logging
10695
- `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
10897

10998
#### Gulp.createClass
11099

111100
```js
112101
function createClass(Object mixin)
113102
```
114103

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.
116105

117106
Example:
118107

108+
Say we always want to create instances that log and have a REPL.
109+
119110
```js
111+
// myGulpConstructor.js
112+
120113
var Gulp = require('gulp-runtime').createClass({
121114
create: function Gulp (options) {
122115
options = options || {};
@@ -125,17 +118,19 @@ var Gulp = require('gulp-runtime').createClass({
125118
Gulp.super_.call(this, options);
126119
}
127120
})
121+
122+
module.exports = Gulp;
128123
```
129124

130125
### Instance methods
131126

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.
133128

134129
#### gulp.task
135130

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].
137132

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).
139134

140135
Example:
141136

@@ -148,7 +143,9 @@ gulp.task('build:mode', function (done) {
148143
});
149144
```
150145

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
152149

153150
```js
154151
var gulp = require('gulp-runtime').create();
@@ -158,7 +155,7 @@ gulp.task('build:mode(-dev|-prod)', function (done){
158155
});
159156
```
160157

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.
162159

163160
#### gulp.start
164161

@@ -168,7 +165,7 @@ The parameters are defined using [parth][parth]. There you will find more inform
168165
function start(tasks...)
169166
```
170167

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.
172169

173170
`tasks...` can be either a `string` (matching one of the tasks registered) or a `function`.
174171

@@ -182,18 +179,19 @@ function build(done){
182179
}
183180

184181
gulp.task('thing', function (done){
185-
setTimeout(done, 100);
182+
setTimeout(done, Math.random()*10);
186183
});
187184

188185
gulp.start(build, 'thing');
189186
```
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.
191189

192190
```js
193191
function start(Array tasks, args...[, onStackEnd])
194192
```
195193

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.
197195

198196
```js
199197
var gulp = require('gulp-runtime').create();
@@ -222,9 +220,9 @@ gulp.task('default', function (done) {
222220

223221
### async composers
224222

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.
226224

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).
228226

229227
#### gulp.series
230228

@@ -263,21 +261,43 @@ function stack(tasks...[, Object options])
263261
- `options.onHandleError` if given, will run when a task errors
264262
- `options.onStackEnd` if given, will run when all of the stacked functions have ended (including error)
265263

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+
266280
## REPL
267281

268282
```js
269283
var gulp = require('gulp-runtime').create({repl: true});
270284
```
271285

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.
273287

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+
>
278296
> build less compress png
279297
```
280298

299+
How will tasks run with the REPL?
300+
281301
- If those tasks are defined they will run in __parallel__
282302
- 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
283303
- 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.
@@ -286,6 +306,7 @@ node gulpfile.js
286306

287307
[npm]: https://npmjs.com/gulp-runtime
288308
[gulp]: https://github.com/gulpjs/gulp
309+
[RxJs]: https://github.com/Reactive-Extensions/RxJS
289310
[parth]: https://github.com/stringparser/parth
290311
[license]: http://opensource.org/licenses/MIT
291312
[runtime]: https://github.com/stringparser/runtime

0 commit comments

Comments
 (0)