Skip to content

Commit

Permalink
docs - more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 11, 2014
1 parent 112a3e0 commit 54197db
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 80 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<a href="http://gulpjs.com">
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png"/>
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
</a>
</p>

Expand All @@ -19,9 +19,8 @@ For a Getting started guide, API docs, recipes, making a plugin, etc. see the [d

This file is just a quick sample to give you a taste of what gulp does.

```javascript
```js
var gulp = require('gulp');

var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
Expand Down Expand Up @@ -69,7 +68,6 @@ gulp.task('watch', function() {

// The default task (called when you run `gulp` from cli)
gulp.task('default', ['watch', 'scripts', 'images']);

```

## Incremental Builds
Expand Down
50 changes: 23 additions & 27 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

### gulp.src(globs[, options])

Takes a glob and represents a file structure. Can be piped to plugins.
Takes a glob and represents a file structure. Can be piped to plugins.

```javascript
gulp.src('./client/templates/*.jade')
.pipe(jade())
.pipe(minify())
.pipe(gulp.dest('./build/minified_templates'));
```js
gulp.src('client/templates/*.jade')
.pipe(jade())
.pipe(minify())
.pipe(gulp.dest('build/minified_templates'));
```

`glob` refers to [node-glob syntax](https://github.com/isaacs/node-glob) or it can be a direct file path.
Expand Down Expand Up @@ -37,7 +37,6 @@ Default: `true`

Setting this to `false` will return `file.contents` as null and not read the file at all.


### gulp.dest(path)

Can be piped to and it will write files. Re-emits all data passed to it so you can pipe to multiple folders. Folders that don't exist will be created.
Expand All @@ -55,12 +54,11 @@ Type: `String`

The path (folder) to write files to.


### gulp.task(name[, deps], fn)

Define a task using [Orchestrator].

```javascript
```js
gulp.task('somename', function() {
// Do stuff
});
Expand All @@ -75,14 +73,13 @@ Type: `Array`

An array of tasks to be executed and completed before your task will run.

```javascript
```js
gulp.task('mytask', ['array', 'of', 'task', 'names'], function() {
// Do stuff
});
```

**Note:** Are your tasks running before the dependencies are complete? Make sure your dependency tasks
are correctly using the async run hints: take in a callback or return a promise or event stream.
**Note:** Are your tasks running before the dependencies are complete? Make sure your dependency tasks are correctly using the async run hints: take in a callback or return a promise or event stream.

#### fn

Expand All @@ -95,24 +92,24 @@ Tasks can be made asynchronous if its `fn` does one of the following:
##### Accept a callback

```javascript
// Run a command in a shell
// run a command in a shell
var exec = require('child_process').exec;
gulp.task('jekyll', function(cb) {
// Build Jekyl
exec('jekyll build', function(err) {
if (err) return cb(err); //return error
// build Jekyll
exec('jekyll build', function(err) {
if (err) return cb(err); // return error
cb(); // finished task
});
});
```

##### Return a stream

```javascript
```js
gulp.task('somename', function() {
var stream = gulp.src('./client/**/*.js')
var stream = gulp.src('client/**/*.js')
.pipe(minify())
.pipe(gulp.dest('/build'));
.pipe(gulp.dest('build'));
return stream;
});
```
Expand All @@ -125,7 +122,7 @@ var Q = require('q');
gulp.task('somename', function() {
var deferred = Q.defer();

// Do async stuff
// do async stuff
setTimeout(function() {
deferred.resolve();
}, 1);
Expand All @@ -134,8 +131,7 @@ gulp.task('somename', function() {
});
```

**Note:** By default, tasks run with maximum concurrency -- e.g. it launches all the tasks at once and waits for nothing.
If you want to create a series where tasks run in a particular order, you need to do two things:
**Note:** By default, tasks run with maximum concurrency -- e.g. it launches all the tasks at once and waits for nothing. If you want to create a series where tasks run in a particular order, you need to do two things:

- give it a hint to tell it when the task is done,
- and give it a hint that a task depends on completion of another.
Expand All @@ -149,7 +145,7 @@ done or return a promise or stream that the engine should wait to resolve or end

So this example would look like this:

```javascript
```js
var gulp = require('gulp');

// takes in a callback so the engine knows when it'll be done
Expand Down Expand Up @@ -188,10 +184,10 @@ Type: `Array`

Names of task(s) to run when a file changes, added with `gulp.task()`

```javascript
```js
var watcher = gulp.watch('js/**/*.js', ['uglify','reload']);
watcher.on('change', function(event) {
console.log('File '+event.path+' was '+event.type+', running tasks...');
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
```

Expand All @@ -212,9 +208,9 @@ Type: `Function`

Callback to be called on each change.

```javascript
```js
gulp.watch('js/**/*.js', function(event) {
console.log('File '+event.path+' was '+event.type+', running tasks...');
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
```

Expand Down
2 changes: 1 addition & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ gulp has very few flags to know about. All other flags are for tasks to use if n
- `--no-color` will force gulp and gulp plugins to not display colors even when color support is detected
- `--silent` will disable all gulp logging

The CLI adds process.env.INIT_CWD which is the original cwd it was launched from
The CLI adds process.env.INIT_CWD which is the original cwd it was launched from.

### Tasks

Expand Down
9 changes: 7 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
* [CLI documentation](CLI.md) - Learn how to call tasks and use compilers
* [Writing a Plugin](writing-a-plugin/README.md) - So you're writing a gulp plugin? Go here for the essential dos and don'ts.


## FAQ

See [the FAQ](FAQ.md) for the answers to commonly asked questions.
See the [FAQ](FAQ.md) for the answers to commonly asked questions.


## Recipes

The community has compiled guides on how to use gulp for common use cases. Check out the [recipes folder](recipes) for a full list.
The community has written [recipes](recipes) common gulp use-cases.


## Still got questions?

Post on [StackOverflow with a #gulp tag](http://stackoverflow.com/questions/tagged/gulp), or come chat with us in [#gulpjs](http://webchat.freenode.net/?channels=gulpjs) on [Freenode](http://freenode.net/).


## Articles
* [Tagtree intro to gulp video](http://tagtree.tv/gulp)
* [Introduction to node.js streams](https://github.com/substack/stream-handbook)
Expand All @@ -29,6 +33,7 @@ Post on [StackOverflow with a #gulp tag](http://stackoverflow.com/questions/tagg
* [Gulp - The Basics (screencast)](https://www.youtube.com/watch?v=dwSLFai8ovQ)
* [Get started with gulp (video series)](http://www.youtube.com/playlist?list=PLRk95HPmOM6PN-G1xyKj9q6ap_dc9Yckm)


## License

All the documentation is covered by the CC0 license *(do whatever you want with it - public domain)*.
Expand Down
26 changes: 13 additions & 13 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
## Getting Started
# Getting Started

### 1. Install gulp globally:
#### 1. Install gulp globally:

```
npm install -g gulp
```sh
$ npm install --global gulp
```

### 2. Install gulp in your project devDependencies:
#### 2. Install gulp in your project devDependencies:

```
npm install --save-dev gulp
```sh
$ npm install --save-dev gulp
```

### 3. Create a `gulpfile.js` at the root of your project:
#### 3. Create a `gulpfile.js` at the root of your project:

```javascript
```js
var gulp = require('gulp');

gulp.task('default', function() {
// place code for your default task here
});
```

### 4. Run gulp:
#### 4. Run gulp:

```
gulp
```sh
$ gulp
```

The default task will run and do nothing.
Expand All @@ -34,7 +34,7 @@ To run individual tasks, use `gulp <task> <othertask>`.

## Where do I go now?

You have an empty gulpfile and everything is installed. How do you REALLY get started? Check out the [recipes and articles section](README.md#articles-and-recipes) for more information.
You have an empty gulpfile and everything is installed. How do you REALLY get started? Check out the [recipes](recipes) and the [list of articles](README.md#articles) for more information.

## .src, .watch, .dest, CLI args - How do I use these things?

Expand Down
22 changes: 11 additions & 11 deletions docs/writing-a-plugin/dealing-with-streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;

// Consts
// consts
const PLUGIN_NAME = 'gulp-prefixer';

function prefixStream(prefixText) {
Expand All @@ -24,19 +24,19 @@ function prefixStream(prefixText) {
return stream;
}

// Plugin level function(dealing with files)
// plugin level function (dealing with files)
function gulpPrefixer(prefixText) {

if (!prefixText) {
throw new PluginError(PLUGIN_NAME, "Missing prefix text!");
throw new PluginError(PLUGIN_NAME, 'Missing prefix text!');
}

prefixText = new Buffer(prefixText); // allocate ahead of time

// Creating a stream through which each file will pass
var stream = through.obj(function(file, enc, callback) {
// creating a stream through which each file will pass
var stream = through.obj(function(file, enc, cb) {
if (file.isBuffer()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Buffers not supported!'));
return callback();
return cb();
}

if (file.isStream()) {
Expand All @@ -51,14 +51,14 @@ function gulpPrefixer(prefixText) {
// make sure the file goes through the next gulp plugin
this.push(file);
// tell the stream engine that we are done with this file
callback();
cb();
});

// returning the file stream
return stream;
};

// Exporting the plugin main function
// exporting the plugin main function
module.exports = gulpPrefixer;
```

Expand All @@ -70,10 +70,10 @@ var gulpPrefixer = require('gulp-prefixer');

gulp.src('files/**/*.js', { buffer: false })
.pipe(gulpPrefixer('prepended string'))
.pipe(gulp.dest('/modified-files/'));
.pipe(gulp.dest('modified-files'));
```

## Some plugins using streams

* [gulp-svgicons2svgfont](https://github.com/nfroidure/gulp-svgiconstosvgfont)
* gulp-browserify (Soon)

19 changes: 10 additions & 9 deletions docs/writing-a-plugin/guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;

// Consts
// consts
const PLUGIN_NAME = 'gulp-prefixer';

function prefixStream(prefixText) {
Expand All @@ -65,19 +65,20 @@ function prefixStream(prefixText) {
return stream;
}

// Plugin level function(dealing with files)
// plugin level function (dealing with files)
function gulpPrefixer(prefixText) {

if (!prefixText) {
throw new PluginError(PLUGIN_NAME, "Missing prefix text!");
throw new PluginError(PLUGIN_NAME, 'Missing prefix text!');
}

prefixText = new Buffer(prefixText); // allocate ahead of time

// Creating a stream through which each file will pass
var stream = through.obj(function(file, enc, callback) {
// creating a stream through which each file will pass
var stream = through.obj(function(file, enc, cb) {
if (file.isNull()) {
// Do nothing if no contents
// do nothing if no contents
}

if (file.isBuffer()) {
file.contents = Buffer.concat([prefixText, file.contents]);
}
Expand All @@ -87,14 +88,14 @@ function gulpPrefixer(prefixText) {
}

this.push(file);
return callback();

return cb();
});

// returning the file stream
return stream;
};

// Exporting the plugin main function
// exporting the plugin main function
module.exports = gulpPrefixer;
```
3 changes: 1 addition & 2 deletions docs/writing-a-plugin/recommended-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ Use [chalk](https://github.com/sindresorhus/chalk)

Use [dateformat](https://github.com/felixge/node-dateformat)


Display as `HH:MM:ss`
Display as `HH:MM:ss`
Loading

0 comments on commit 54197db

Please sign in to comment.