Socket
Socket
Sign inDemoInstall

grunt-run

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-run - npm Package Compare versions

Comparing version 0.1.3 to 0.1.5

2

package.json
{
"name": "grunt-run",
"description": "Invite external commands into your grunt process with three tasks `run`, `wait` and `stop`.",
"version": "0.1.3",
"version": "0.1.5",
"homepage": "https://github.com/spenceralger/grunt-run",

@@ -6,0 +6,0 @@ "author": {

@@ -44,5 +44,7 @@ # grunt-run

Since this task doesn't operate on "files" it also doesn't use the standard src/files options. Instead, specify a `cmd` and `args` key to your test's config (see examples). `cmd` defaults to `"node"`.
Since this task doesn't operate on "files" it also doesn't use the standard src/files options. Instead, specify a `cmd:` and `args:` key to your test's config (see examples). `cmd:` defaults to `"node"`.
If you would like to specify your command as a single string, usefull for specifying multiple commands in one task, use the `exec:` key
### Options

@@ -76,2 +78,8 @@

#### options.passArgs
Type: `Array`
Default value: `[]`
Before running the command, look for these options using [grunt.option()](http://gruntjs.com/api/grunt.option#grunt.option). The syntax supported for specifying command line args in grunt is `--option1=myValue`.
### Usage Examples

@@ -86,3 +94,3 @@

tool: {
cmd: 'some-bash-script',
cmd: './some-bash-script',
}

@@ -95,2 +103,17 @@ }

#### Multiple scripts
Want to run a few commands. With this config calling `grunt run:commands` will run them.
```js
grunt.initConfig({
run: {
commands: {
exec: './some-bash-script && ./some-other-script',
}
}
});
grunt.loadNpmTasks('grunt-run');
```
#### `wait`ing

@@ -166,3 +189,28 @@ In this example, we are starting a small server that will serve our mocha tests to a browser. We will then open that page in the browser and tell grunt to wait until the process is exited, which probably won't happen so the process will just run until the user ends the process manually.

#### passing args
When you execute a command, sometimes you want to modify the script form the call to grunt.
```js
grunt.initConfig({
run: {
server: {
args: ['./server.js'],
options: {
passArgs: [
'port'
]
}
}
}
})
```
Then you can specify a `--port` option when calling grunt and it will be sent to the other process.
```
$ grunt run:server --port=8888
# calls "node ./server.js --port=8888"
```
## Contributing
Please lint and test your code with the included jshint config, or just run `grunt`.

@@ -8,11 +8,15 @@ /*

*/
module.exports = makeTask;
function makeTask(grunt) {
'use strict';
module.exports = function(grunt) {
var runningProcs = [];
var Readable = require('stream').Readable;
var EventEmitter = require('events').EventEmitter;
var _ = require('lodash');
var util = require('util');
var child_process = require('child_process');
var shouldEscapeRE = / |"|'|\$|&|\\/;
var dangerArgsRE = /"|\$|\\/g;
var runningProcs = [];
process.on('exit', function () {

@@ -31,13 +35,46 @@ _.each(runningProcs, function (proc) {

ready: 1000,
cwd: process.cwd()
cwd: process.cwd(),
passArgs: []
});
var proc = child_process.spawn(
self.data.cmd || 'node',
self.data.args,
{
stdio: ['ignore', 'pipe', 'pipe']
var cmd = this.data.cmd | 'node';
var args = this.data.args || [];
var additionalArgs = [];
opts.passArgs.map(function (arg) {
var val = grunt.option(arg);
if (val !== void 0) {
if (shouldEscapeRE.test(arg)) {
val = '"' + arg.replace(dangerArgsRE, function (match) {
return '\\' + match;
}) + '"';
}
additionalArgs.push('--' + arg + '=' + val);
}
);
});
if (this.data.exec) {
if (process.platform === 'win32') {
cmd = 'cmd';
args = ['/c', this.data.exec];
} else {
cmd = 'sh';
args = ['-c', this.data.exec];
}
if (additionalArgs.length) {
args[1]+= ' ' + additionalArgs.join(' ');
}
} else {
args = args.concat(additionalArgs);
}
grunt.verbose.writeln('running', cmd, 'with args', args);
var proc = child_process.spawn(cmd, args, {
stdio: ['ignore', 'pipe', 'pipe']
});
var done = this.async();

@@ -63,2 +100,6 @@ var timeoutId = null;

proc.on('error', function (err) {
grunt.log.error(err);
});
proc.on('close', function () {

@@ -111,6 +152,6 @@ var i;

} else {
grunt.log.writeLn('process already closed');
grunt.log.writeln('process already closed');
}
});
};
}

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