source: Dev/trunk/node_modules/grunt-exec/README.md @ 484

Last change on this file since 484 was 484, checked in by hendrikvanantwerpen, 11 years ago

Commit node_modules, to make checkouts and builds more deterministic.

File size: 3.6 KB
RevLine 
[484]1[![build status](https://secure.travis-ci.org/jharding/grunt-exec.png?branch=master)](http://travis-ci.org/jharding/grunt-exec)
2grunt-exec
3==========
4
5Grunt plugin for executing shell commands.
6
7Installation
8------------
9
10Install grunt-exec using npm:
11
12```
13$ npm install grunt-exec
14```
15
16Then add this line to your project's *Gruntfile.js*:
17
18```javascript
19grunt.loadNpmTasks('grunt-exec');
20```
21
22Usage
23-----
24
25This plugin is a [multi task][types_of_tasks], meaning that grunt will automatically iterate over all exec targets if a target is not specified.
26
27If the exit code generated by the specified shell command is greater than 0, grunt-exec will assume an error has occurred and will abort grunt immediately.
28
29[types_of_tasks]: https://github.com/gruntjs/grunt/blob/master/docs/types_of_tasks.md#multi-tasks
30
31### Properties
32
33*   __command__: The shell command to be executed. Must be a string or a function that returns a string. (alias: __cmd__)
34*   __stdout__: If `true`, stdout will be printed. Defaults to `true`.
35*   __stderr__: If `true`, stderr will be printed. Defaults to `true`.
36*   __cwd__: Current working directory of the shell command. Defaults to the directory containing your Gruntfile.
37*   __exitCode__: The expected exit code, task will fail if the actual exit code doesn't match. Defaults to `0`.
38*   __callback__: The callback function passed `child_process.exec`. Defaults to a noop.
39
40### Command Functions
41
42If you plan on doing advanced stuff with grunt-exec, you'll most likely be using functions for the `command` property of your exec targets. This section details a couple of helpful tips about command functions that could help make your life easier.
43
44#### Passing arguments from the command line
45
46Command functions can be called with arbitrary arguments. Let's say we have the following exec target that echoes a formatted name:
47
48```javascript
49exec: {
50  echo_name: {
51    cmd: function(firstName, lastName) {
52      var formattedName = [
53        lastName.toUpperCase(),
54        firstName.toUpperCase()
55      ].join(', ');
56
57      return 'echo ' + formattedName;
58    }
59  }
60}
61```
62
63In order to get `SIMPSON, HOMER` echoed, you'd run `grunt exec:echo_name:homer:simpson` from the command line.
64
65### Accessing `grunt` object
66
67All command functions are called in the context of the `grunt` object that they are being ran with. This means you can access the `grunt` object through `this`.
68
69### Example
70
71The following examples are available in grunt-exec's Gruntfile.
72
73```javascript
74grunt.initConfig({
75  exec: {
76    remove_logs: {
77      command: 'rm -f *.log',
78      stdout: false,
79      stderr: false
80    },
81    list_files: {
82      cmd: 'ls -l **'
83    },
84    echo_grunt_version: {
85      cmd: function() { return 'echo ' + this.version; }
86    },
87    echo_name: {
88      cmd: function(firstName, lastName) {
89        var formattedName = [
90          lastName.toUpperCase(),
91          firstName.toUpperCase()
92        ].join(', ');
93
94        return 'echo ' + formattedName;
95      }
96    }
97  }
98});
99```
100
101Testing
102-------
103
104```
105$ cd grunt-exec
106$ npm test
107```
108
109Issues
110------
111
112Found a bug? Create an issue on GitHub.
113
114https://github.com/jharding/grunt-exec/issues
115
116Versioning
117----------
118
119For transparency and insight into the release cycle, releases will be numbered with the follow format:
120
121`<major>.<minor>.<patch>`
122
123And constructed with the following guidelines:
124
125* Breaking backwards compatibility bumps the major
126* New additions without breaking backwards compatibility bumps the minor
127* Bug fixes and misc changes bump the patch
128
129For more information on semantic versioning, please visit http://semver.org/.
130
131License
132-------
133
134Copyright (c) 2012 [Jake Harding](http://thejakeharding.com) 
135Licensed under the MIT License.
Note: See TracBrowser for help on using the repository browser.