Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 161 lines (103 sloc) 5.108 kb
7ee61b69 »
2012-02-04 Docs reorganization.
1 [Grunt homepage](https://github.com/cowboy/grunt) | [Documentation table of contents](toc.md)
2
3 # The grunt API
4
dbaee9c8 »
2012-03-19 More docs.
5 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).
6
7 In a [gruntfile](configuring.md):
8
9 ```javascript
10 exports.config = function(grunt) {
11 // Tons o' stuff is available on the grunt object.
12 };
13 ```
14
15 In a [custom tasks file](tasks_creating.md):
16
17 ```javascript
18 exports.tasks = function(grunt) {
19 // Tons o' stuff is available on the grunt object.
20 };
21 ```
22
48bcd441 »
2012-03-19 More docs.
23 ## Config
dbaee9c8 »
2012-03-19 More docs.
24
80581c20 »
2012-03-19 More docs.
25
48bcd441 »
2012-03-19 More docs.
26 ### grunt.initConfig
80581c20 »
2012-03-19 More docs.
27 Initialize a configuration object for the current project. The specified `configObject` is used by tasks and helpers and can also be accessed using the [grunt.config](api_config.md) method. Nearly every project's [config.js gruntfile](configuring.md) will need this.
dbaee9c8 »
2012-03-19 More docs.
28
29 ```javascript
34274e30 »
2012-03-19 More docs.
30 grunt.initConfig(configObject)
31 ```
32
33 *Example*
34
35 ```javascript
36 grunt.initConfig({
37 lint: {
38 all: ['lib/*.js', 'test/*.js', 'grunt.js']
39 }
40 });
dbaee9c8 »
2012-03-19 More docs.
41 ```
42
29b12b96 »
2012-03-19 More docs.
43 See the [configuring grunt](configuring.md) documentation for more information and examples.
44
fbc09866 »
2012-03-19 More docs.
45 _This method is an alias for the [config.init](api_config.md) method._
dbaee9c8 »
2012-03-19 More docs.
46
48bcd441 »
2012-03-19 More docs.
47
0e2160ef »
2012-03-19 More docs.
48 ## Creating Tasks
48bcd441 »
2012-03-19 More docs.
49
80581c20 »
2012-03-19 More docs.
50
48bcd441 »
2012-03-19 More docs.
51 ### grunt.registerTask
80581c20 »
2012-03-19 More docs.
52 Register a task or an "alias task." This method supports the following two signatures:
dbaee9c8 »
2012-03-19 More docs.
53
80581c20 »
2012-03-19 More docs.
54 If a string `taskList` is specified, the new task will be an alias for one or more other tasks. Whenever this "alias task" is run, every specified task in `taskList` will be run, in the order specified.
dbaee9c8 »
2012-03-19 More docs.
55
56 ```javascript
34274e30 »
2012-03-19 More docs.
57 grunt.registerTask(taskName, taskList)
f5311130 »
2012-03-19 More docs.
58 ```
59
80581c20 »
2012-03-19 More docs.
60 If a `description` and `taskFunction` are passed, the specified function will be executed whenever the task is run. In addition, the specified description will be shown when `grunt --help` is run. Task-specific properties and methods are available inside the task function as properties of the `this` object.
61
62 Note that the `grunt.registerMultiTask` method, explained below, can be used to define a special type of task known as a "multi task."
f5311130 »
2012-03-19 More docs.
63
64 ```javascript
34274e30 »
2012-03-19 More docs.
65 grunt.registerTask(taskName, description, taskFunction)
dbaee9c8 »
2012-03-19 More docs.
66 ```
67
80581c20 »
2012-03-19 More docs.
68 See the [creating tasks](tasks_creating.md) documentation for examples of tasks and alias tasks.
f5311130 »
2012-03-19 More docs.
69
fbc09866 »
2012-03-19 More docs.
70 _This method is an alias for the [task.registerTask](api_task.md) method._
f5311130 »
2012-03-19 More docs.
71
72
48bcd441 »
2012-03-19 More docs.
73 ### grunt.registerMultiTask
80581c20 »
2012-03-19 More docs.
74 Register a "multi task." A multi task is a task that implicitly iterates over all of its named sub-properties (AKA targets) if none was specified. In addition to the default properties and methods, extra multi task-specific properties are available inside the task function as properties of the `this` object.
dbaee9c8 »
2012-03-19 More docs.
75
80581c20 »
2012-03-19 More docs.
76 Many of the built-in tasks, including the [lint](task_lint.md), [concat](task_concat.md) and [min](task_min.md) are multi tasks.
dbaee9c8 »
2012-03-19 More docs.
77
78 ```javascript
34274e30 »
2012-03-19 More docs.
79 grunt.registerMultiTask(taskName, description, taskFunction)
dbaee9c8 »
2012-03-19 More docs.
80 ```
81
80581c20 »
2012-03-19 More docs.
82 See the [creating tasks](tasks_creating.md) documentation for examples of multi tasks.
83
84 _This method is an alias for the [task.registerMultiTask](api_task.md) method._
85
86
48bcd441 »
2012-03-19 More docs.
87 ### grunt.registerInitTask
fbc09866 »
2012-03-19 More docs.
88 This method is an alias for the [task.registerInitTask](api_task.md) method.
dbaee9c8 »
2012-03-19 More docs.
89
90 Usage:
91
92 ```javascript
34274e30 »
2012-03-19 More docs.
93 grunt.registerInitTask(taskName, description, taskFunction)
dbaee9c8 »
2012-03-19 More docs.
94 ```
95
0e2160ef »
2012-03-19 More docs.
96 ## Loading Externally-Defined Tasks
dbaee9c8 »
2012-03-19 More docs.
97
48bcd441 »
2012-03-19 More docs.
98 ### grunt.loadTasks
fbc09866 »
2012-03-19 More docs.
99 This method is an alias for the [task.loadTasks](api_task.md) method.
dbaee9c8 »
2012-03-19 More docs.
100
101 Usage:
102
103 ```javascript
34274e30 »
2012-03-19 More docs.
104 grunt.loadTasks()
dbaee9c8 »
2012-03-19 More docs.
105 ```
106
48bcd441 »
2012-03-19 More docs.
107 ### grunt.loadNpmTasks
fbc09866 »
2012-03-19 More docs.
108 This method is an alias for the [task.loadNpmTasks](api_task.md) method.
dbaee9c8 »
2012-03-19 More docs.
109
110 Usage:
111
112 ```javascript
34274e30 »
2012-03-19 More docs.
113 grunt.loadNpmTasks()
dbaee9c8 »
2012-03-19 More docs.
114 ```
115
0e2160ef »
2012-03-19 More docs.
116 ## Defining and Executing Helpers
dbaee9c8 »
2012-03-19 More docs.
117
48bcd441 »
2012-03-19 More docs.
118 ### grunt.registerHelper
fbc09866 »
2012-03-19 More docs.
119 This method is an alias for the [task.registerHelper](api_task.md) method.
dbaee9c8 »
2012-03-19 More docs.
120
121 Usage:
122
123 ```javascript
34274e30 »
2012-03-19 More docs.
124 grunt.registerHelper(helperName, helperFunction)
dbaee9c8 »
2012-03-19 More docs.
125 ```
126
48bcd441 »
2012-03-19 More docs.
127 ### grunt.helper
fbc09866 »
2012-03-19 More docs.
128 This method is an alias for the [task.helper](api_task.md) method.
dbaee9c8 »
2012-03-19 More docs.
129
130 Usage:
131
132 ```javascript
34274e30 »
2012-03-19 More docs.
133 grunt.helper(helperName [, arguments...])
dbaee9c8 »
2012-03-19 More docs.
134 ```
7ee61b69 »
2012-02-04 Docs reorganization.
135
b260167c »
2012-03-19 More docs.
136 ## Inside Tasks
137
138 ### this.foo
139 EXPLAIN
140
141
142
7ee61b69 »
2012-02-04 Docs reorganization.
143 ## Internals
144
dbaee9c8 »
2012-03-19 More docs.
145 * [grunt.utils](api_utils.md) - miscellaneous utilities
146 * [grunt.template](api_template.md) - template methods
147 * [grunt.task](api_task.md) - the entire task interface
148 * [grunt.file](api_file.md) - glob expansion, file reading, writing, directory traversing
149 * [grunt.fail](api_fail.md) - more serious than error logging, `fail.warn` and `fail.fatal` will halt everything
150 * [grunt.config](api_config.md) - reading values from the grunt configuration
151 * [grunt.option](api_option.md) - reading values from the command-line options
152 * [grunt.log](api_log.md) - don't use `console.log`, use `log.writeln` instead!
153 * [grunt.verbose](api_verbose.md) - just like `log`, but only logs if `--verbose` was specified.
7ee61b69 »
2012-02-04 Docs reorganization.
154
392aef19 »
2012-03-05 Removing globals "underscore" and "async" which are now available as …
155 ## External libraries, exposed
156
dbaee9c8 »
2012-03-19 More docs.
157 * [utils.async](api_utils.md) - [Async utilities](https://github.com/caolan/async)
158 * [utils._](api_utils.md) - [Underscore.js](http://underscorejs.org/), including [Underscore.string](https://github.com/epeli/underscore.string)
159 * [utils.hooker](api_utils.md) - [JavaScript hooker](https://github.com/cowboy/javascript-hooker)
392aef19 »
2012-03-05 Removing globals "underscore" and "async" which are now available as …
160
7ee61b69 »
2012-02-04 Docs reorganization.
161 Unfortunately, I haven't documented everything yet. Fortunately, the source is open and browsable. Have fun!
Something went wrong with that request. Please try again.