Socket
Socket
Sign inDemoInstall

grunt-shell

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-shell - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

9

package.json
{
"name": "grunt-shell",
"version": "0.1.4",
"description": "Grunt task to run shell commands",
"version": "0.2.0",
"description": "Run shell commands",
"keywords": [

@@ -22,4 +22,2 @@ "gruntplugin",

},
"main": "grunt.js",
"bin": "bin/grunt-shell",
"repository": {

@@ -29,4 +27,5 @@ "type": "git",

},
"dependencies": {},
"devDependencies": {
"grunt": "~0.3.12"
"grunt": "~0.4.0"
},

@@ -33,0 +32,0 @@ "engines": {

# grunt-shell
*Requires grunt 0.4. Use version 0.1.4 for grunt 0.3 compatibility*
[Grunt][grunt] task to run shell commands.
E.g. compile Compass (`compass compile`) or get the current git branch (`git branch`).
A good way to interact with other CLI tools. E.g. compiling Compass `compass compile` or get the current git branch `git branch`.
## Getting started
## Getting Started
Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-shell`
If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide, as it explains how to create a [gruntfile][Getting Started] as well as install and use grunt plugins. Once you're familiar with that process, install this plugin with this command:
Then add this line to your project's `grunt.js` gruntfile:
```javascript
grunt.loadNpmTasks('grunt-shell');
```shell
npm install grunt-shell --save-dev
```
[grunt]: http://gruntjs.com
[Getting Started]: https://github.com/gruntjs/grunt/wiki/Getting-started
## Documentation

@@ -24,5 +27,3 @@

This grunt task is a [multi task](https://github.com/cowboy/grunt/blob/master/docs/types_of_tasks.md#multi-tasks-%E2%9A%91), which means you can specify multiple subtasks and grunt will iterate over them. The `dist` below is a subtask, you could e.g. create a `dev` subtask to handle stuff while developing. You can also add a special subtask named `_options` that can contain options for all your subtasks.
#### Run command

@@ -34,3 +35,3 @@

shell: {
make_directory: {
makeDir: {
command: 'mkdir test'

@@ -41,9 +42,9 @@ }

Command expand templates :
The `command` property supports templates :
```javascript
test_dir: 'test',
testDir: 'test',
shell: {
make_directory: {
command: 'mkdir <% test_dir %>'
makeDir: {
command: 'mkdir <%= testDir %>'
}

@@ -55,11 +56,13 @@ }

#### Run command and display output
#### Run command and display the output
Output a directory listing to your Terminal.
Output a directory listing in your Terminal.
```javascript
shell: {
directory_listing: {
dirListing: {
command: 'ls',
stdout: true
options: {
stdout: true
}
}

@@ -70,9 +73,9 @@ }

#### Run command and handle output
#### Custom callback
Do whatever you want with the stdout.
Do whatever you want with the output.
```javascript
function log() {
console.log( this );
function log(err, stdout, stderr, cb) {
console.log(stdout);
}

@@ -83,5 +86,7 @@

shell: {
directory_listing: {
dirListing: {
command: 'ls',
stdout: log
options: {
callback: log
}
}

@@ -93,11 +98,13 @@ }

Run a command in another directory. In this example we run it in a subfolder using the `cwd` option.
Run a command in another directory. In this example we run it in a subfolder using the `cwd` (current working directory) option.
```javascript
shell: {
subfolder_ls: {
subfolderLs: {
command: 'ls',
stdout: true,
execOptions: {
cwd: './tasks'
options: {
stdout: true,
execOptions: {
cwd: 'tasks'
}
}

@@ -109,78 +116,22 @@ }

#### Custom callback
### Config
Define custom callback method to handle everything yourself. Check out [shell.js](https://github.com/sindresorhus/grunt-shell/blob/master/tasks/shell.js) to see how it's handled by default.
```javascript
function customHandler() {
console.log( this, this.data.stdout );
}
#### command
...
**Required**
Type: `String`
shell: {
ls: {
command: 'ls',
callback: customHandler
}
}
```
The command you want to run. Supports templates.
#### Multiple subtasks
This task is a [multi task](https://github.com/cowboy/grunt/blob/master/docs/types_of_tasks.md#multi-tasks-%E2%9A%91), which means you can specify multiple subtasks and grunt will iterate over them.
```javascript
shell: {
directory_listing: {
command: 'ls',
stdout: true
},
compile_coffescript: {
command: 'coffee main.coffee',
failOnError: true
}
}
```
#### Global options
You can define global options in a subtask called `_options`. Your subtasks will then inherit those options with the ability to override them.
```javascript
shell: {
directory_listing: {
command: 'ls',
stdout: true
},
create_folder: {
command: 'mkdir test',
failOnError: false
},
_options: {
failOnError: true
}
}
```
### Options
#### command
**Required**
Accepts: String
Your command is my wish.
#### stdout
Default: `false`
Accepts: Boolean / Function
Type: `Boolean`
Show stdout in the Terminal. You can supply a function to handle the output.
Show stdout in the Terminal.

@@ -191,5 +142,5 @@

Default: `false`
Accepts: Boolean / Function
Type: `Boolean`
Show stderr in the Terminal. You can supply a function to handle the output.
Show stderr in the Terminal.

@@ -200,7 +151,17 @@

Default: `false`
Accepts: Boolean
Type: `Boolean`
Fail task if it encounters an error.
Fail task if it encounters an error. Does not apply if you specify a `callback`.
#### callback(err, stdout, stderr, cb)
Default: `function () {}`
Type: `Function`
Lets you override the default callback with your own.
**Make sure to call the `cb` method when you're done.**
#### execOptions

@@ -222,10 +183,7 @@

#### callback
## Upgrade from 0.1.3 to 0.2.0
Default: `undefined`
Accepts: Function
Because of the transition to grunt 0.4 there are some changes. To conform to new grunt standards, all options are now to be specified in an `options` object. I also took the opportunity to improve the task. The `stdout` and `stderr` options now only supports a boolean. If you want to do something with the result use the `callback` option. The `callback` option also changed.
Lets you override the default callback with your own. Everything you need is available on `this`.
## Tests

@@ -245,5 +203,1 @@

(c) [Sindre Sorhus](http://sindresorhus.com)
[grunt]: https://github.com/cowboy/grunt
[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md

@@ -1,50 +0,33 @@

/*
* grunt-shell
* 0.1.2 - 2012-06-28
* github.com/sindresorhus/grunt-shell
*
* (c) Sindre Sorhus
* sindresorhus.com
* MIT License
*/
module.exports = function( grunt ) {
'use strict';
'use strict';
module.exports = function (grunt) {
var exec = require('child_process').exec;
var _ = grunt.util._;
var _ = grunt.utils._;
var log = grunt.log;
grunt.registerMultiTask( 'shell', 'Run shell commands', function() {
var exec = require('child_process').exec;
var done = this.async();
var data = _.extend( [], grunt.config.get('shell')._options, this.data );
var dataOut = data.stdout;
var dataErr = data.stderr;
if ( _.isFunction( data.callback ) ) {
data.callback.call( this );
return;
}
exec( grunt.template.process(data.command), data.execOptions, function( err, stdout, stderr ) {
if ( stdout ) {
if ( _.isFunction( dataOut ) ) {
dataOut( stdout );
} else if ( dataOut === true ) {
log.write( stdout );
grunt.registerMultiTask('shell', 'Run shell commands', function () {
var cb = this.async();
var options = this.options({
stdout: false,
stderr: false,
failOnError: false
});
var cmd = grunt.template.process(this.data.command);
var cp = exec(cmd, options.execOptions, function (err, stdout, stderr) {
if (_.isFunction(options.callback)) {
options.callback.call(this, err, stdout, stderr, cb);
} else {
if (err && options.failOnError) {
grunt.warn(err);
}
cb();
}
});
if ( err ) {
if ( _.isFunction( dataErr ) ) {
dataErr( stderr );
} else if ( data.failOnError === true ) {
grunt.fatal( err );
} else if ( dataErr === true ) {
log.error( err );
}
}
if (options.stdout) {
cp.stdout.pipe(process.stdout);
}
done();
});
if (options.stderr) {
cp.stderr.pipe(process.stderr);
}
});
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc