Skip to content

Commit

Permalink
More docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboy committed Mar 19, 2012
1 parent 6812b29 commit dbaee9c
Showing 1 changed file with 112 additions and 12 deletions.
124 changes: 112 additions & 12 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,123 @@

# The grunt API

In an effort to make development easier, grunt exposes a lot of its functionality as globals.
Grunt exposes a lot of its functionality on the `grunt` object passed into a [config.js gruntfile](configuring.md) or [tasks file](tasks_creating.md).

In a [gruntfile](configuring.md):

```javascript
exports.config = function(grunt) {
// Tons o' stuff is available on the grunt object.
};
```

In a [custom tasks file](tasks_creating.md):

```javascript
exports.tasks = function(grunt) {
// Tons o' stuff is available on the grunt object.
};
```

## Methods

### Config

#### grunt.initConfig
This method is a convenient shortcut for the [config.init](api_config.md) method.

Usage:

```javascript
grunt.initConfig(configObject);
```

### Tasks: Creating

#### grunt.registerTask
This method is a convenient shortcut for the [task.registerTask](api_task.md) method.

Usage:

```javascript
grunt.registerTask(taskName, taskList);
grunt.registerTask(taskName, description, taskFunction);
```

#### grunt.registerMultiTask
This method is a convenient shortcut for the [task.registerMultiTask](api_task.md) method.

Usage:

```javascript
grunt.registerMultiTask(taskName, description, taskFunction);
```

#### grunt.registerInitTask
This method is a convenient shortcut for the [task.registerInitTask](api_task.md) method.

Usage:

```javascript
grunt.registerInitTask(taskName, description, taskFunction);
```

### Tasks: Loading

#### grunt.loadTasks
This method is a convenient shortcut for the [task.loadTasks](api_task.md) method.

Usage:

```javascript
grunt.loadTasks();
```

#### grunt.loadNpmTasks
This method is a convenient shortcut for the [task.loadNpmTasks](api_task.md) method.

Usage:

```javascript
grunt.loadNpmTasks();
```

### Helpers

#### grunt.registerHelper
This method is a convenient shortcut for the [task.registerHelper](api_task.md) method.

Usage:

```javascript
grunt.registerHelper(helperName, helperFunction);
```

#### grunt.helper
This method is a convenient shortcut for the [task.helper](api_task.md) method.

Usage:

```javascript
grunt.helper(helperName [, arguments...]);
```

## Internals

* `utils` - miscellaneous utilities
* `task` - the entire task interface
* `file` - glob expansion, file reading, writing, directory traversing
* `fail` - more serious than error logging, `fail.warn` and `fail.fatal` will halt everything
* `config` - reading values from the grunt configuration
* `option` - reading values from the command-line options
* `log` - don't use `console.log`, use `log.writeln` instead! [More info on log](api_log.md).
* `verbose` - just like `log`, but only logs if `--verbose` was specified. [More info on verbose](api_log.md).
* [grunt.utils](api_utils.md) - miscellaneous utilities
* [grunt.template](api_template.md) - template methods
* [grunt.task](api_task.md) - the entire task interface
* [grunt.file](api_file.md) - glob expansion, file reading, writing, directory traversing
* [grunt.fail](api_fail.md) - more serious than error logging, `fail.warn` and `fail.fatal` will halt everything
* [grunt.config](api_config.md) - reading values from the grunt configuration
* [grunt.option](api_option.md) - reading values from the command-line options
* [grunt.log](api_log.md) - don't use `console.log`, use `log.writeln` instead!
* [grunt.verbose](api_verbose.md) - just like `log`, but only logs if `--verbose` was specified.

## External libraries, exposed

* `utils.async` - [Async utilities](https://github.com/caolan/async)
* `utils._` - [Underscore.js](http://underscorejs.org/), including [Underscore.string](https://github.com/epeli/underscore.string)
* `utils.hooker` - [JavaScript hooker](https://github.com/cowboy/javascript-hooker)
* [utils.async](api_utils.md) - [Async utilities](https://github.com/caolan/async)
* [utils._](api_utils.md) - [Underscore.js](http://underscorejs.org/), including [Underscore.string](https://github.com/epeli/underscore.string)
* [utils.hooker](api_utils.md) - [JavaScript hooker](https://github.com/cowboy/javascript-hooker)

Unfortunately, I haven't documented everything yet. Fortunately, the source is open and browsable. Have fun!

0 comments on commit dbaee9c

Please sign in to comment.