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

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

Enable deployment with Grunt.

File size: 3.9 KB
Line 
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
26automatically iterate over all exec targets if a target is not specified.
27
28If the exit code generated by the specified shell command is greater than 0,
29grunt-exec will assume an error has occurred and will abort grunt immediately.
30
31[types_of_tasks]: http://gruntjs.com/configuring-tasks#task-configuration-and-targets
32
33### Properties
34
35*  __command__ (alias: __cmd__): The shell command to be executed. Must be a
36  string or a function that returns a string.
37*  __stdout__: If `true`, stdout will be printed. Defaults to `true`.
38*  __stderr__: If `true`, stderr will be printed. Defaults to `true`.
39*  __cwd__: Current working directory of the shell command. Defaults to the
40  directory containing your Gruntfile.
41*  __exitCode__ (alias: __exitCodes__): The expected exit code(s), task will
42  fail if the actual exit code doesn't match. Defaults to `0`. Can be an array
43  for multiple allowed exit codes.
44*  __callback__: The callback function passed `child_process.exec`. Defaults to
45  a noop.
46
47If the configuration is instead a simple `string`, it will be
48interpreted as a full command itself:
49
50```javascript
51exec: {
52  echo_something: 'echo "This is something"'
53}
54```
55
56### Command Functions
57
58If you plan on doing advanced stuff with grunt-exec, you'll most likely be using
59functions for the `command` property of your exec targets. This section details
60a couple of helpful tips about command functions that could help make your life
61easier.
62
63#### Passing arguments from the command line
64
65Command functions can be called with arbitrary arguments. Let's say we have the
66following exec target that echoes a formatted name:
67
68```javascript
69exec: {
70  echo_name: {
71    cmd: function(firstName, lastName) {
72      var formattedName = [
73        lastName.toUpperCase(),
74        firstName.toUpperCase()
75      ].join(', ');
76
77      return 'echo ' + formattedName;
78    }
79  }
80}
81```
82
83In order to get `SIMPSON, HOMER` echoed, you'd run
84`grunt exec:echo_name:homer:simpson` from the command line.
85
86### Accessing `grunt` object
87
88All command functions are called in the context of the `grunt` object that they
89are being ran with. This means you can access the `grunt` object through `this`.
90
91### Example
92
93The following examples are available in grunt-exec's Gruntfile.
94
95```javascript
96grunt.initConfig({
97  exec: {
98    remove_logs: {
99      command: 'rm -f *.log',
100      stdout: false,
101      stderr: false
102    },
103    list_files: {
104      cmd: 'ls -l **'
105    },
106    list_all_files: 'ls -la',
107    echo_grunt_version: {
108      cmd: function() { return 'echo ' + this.version; }
109    },
110    echo_name: {
111      cmd: function(firstName, lastName) {
112        var formattedName = [
113          lastName.toUpperCase(),
114          firstName.toUpperCase()
115        ].join(', ');
116
117        return 'echo ' + formattedName;
118      }
119    }
120  }
121});
122```
123
124Testing
125-------
126
127```
128$ cd grunt-exec
129$ npm test
130```
131
132Issues
133------
134
135Found a bug? Create an issue on GitHub.
136
137https://github.com/jharding/grunt-exec/issues
138
139Versioning
140----------
141
142For transparency and insight into the release cycle, releases will be numbered
143with the follow format:
144
145`<major>.<minor>.<patch>`
146
147And constructed with the following guidelines:
148
149* Breaking backwards compatibility bumps the major
150* New additions without breaking backwards compatibility bumps the minor
151* Bug fixes and misc changes bump the patch
152
153For more information on semantic versioning, please visit http://semver.org/.
154
155License
156-------
157
158Copyright (c) 2012 [Jake Harding](http://thejakeharding.com) 
159Licensed under the MIT License.
Note: See TracBrowser for help on using the repository browser.