Skip to documentation

package

@stackline/grunt-exec 1.0.2 — installation and API

Grunt task for executing shell commands.

Install @stackline/grunt-exec

npm install @stackline/[email protected]

Package version: 1.0.2. Metadata verified: 2026-11-12. This is separate from the framework version and demonstration runtime.

Node.js requirement
{"node": ">=0.8.0"}
Accepted peer dependencies (declared ranges)
{"grunt": ">=0.4"}

Tested environments are described in the versioned README and linked source checks. A declared peer range is not evidence that every version in it was tested.

Versioned reference

This reference comes from the published @stackline/[email protected] README. Its upstream attribution and license remain with the source. Benchmark and security statements describe the cited tests and advisories, not a guarantee for every application.

@stackline/grunt-exec

Grunt task for executing shell commands.

Documentation | npm | Issues | Repository

Current package version: 1.0.2


Why this package?

@stackline/grunt-exec is the Stackline-maintained distribution of [email protected]. It is an independent continuation of grunt-exec; original authors and licenses remain credited below.

Compatibility

Item Value
Package @stackline/[email protected]
API target [email protected]
Supported Node.js >=0.8.0
License MIT
Main entry Gruntfile.js
Runtime dependencies none
Peer dependencies grunt >=0.4

Installation

npm install @stackline/grunt-exec

Preserve existing imports and plugin resolution with an npm alias:

npm install grunt-exec@npm:@stackline/grunt-exec

Usage and API reference

grunt-exec

Grunt plugin for executing shell commands.

Installation

Install grunt-exec using npm:

$ npm install @stackline/grunt-exec --save-dev

Then add this line to your project's Gruntfile.js:

grunt.loadNpmTasks('@stackline/grunt-exec');

Usage

This plugin is a multi task, meaning that grunt will automatically iterate over all exec targets if a target is not specified.

If 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.

Properties

  • command (alias: cmd): The shell command to be executed. Must be a string or a function that returns a string.
  • stdin: If true, stdin will be redirected from the child process to the current process allowing user interactivity (EXPERIMENTAL)
  • stdout: If true, stdout will be printed. Defaults to true.
  • stderr: If true, stderr will be printed. Defaults to true.
  • cwd: Current working directory of the shell command. Defaults to the directory containing your Gruntfile.
  • exitCode (alias: exitCodes): The expected exit code(s), task will fail if the actual exit code doesn't match. Defaults to 0. Can be an array for multiple allowed exit codes.
  • callback: The callback function passed child_process.exec. Defaults to a noop.
  • callbackArgs: Additional arguments to pass to the callback. Defaults to empty array.
  • sync: Whether to use child_process.spawnSync. Defaults to false.
  • options: Options to provide to child_process.exec. NodeJS Documentation
  • cwd String Current working directory of the child process
  • env Object Environment key-value pairs
  • encoding String (Default: 'utf8')
  • shell String Shell to execute the command with (Default: '/bin/sh' on UNIX, 'cmd.exe' on Windows, The shell should understand the -c switch on UNIX or /s /c on Windows. On Windows, command line parsing should be compatible with cmd.exe.)
  • timeout Number (Default: 0)
  • maxBuffer Number largest amount of data (in bytes) allowed on stdout or stderr - if exceeded child process is killed (Default: 200*1024)
  • killSignal String (Default: 'SIGTERM')
  • uid Number Sets the user identity of the process. (See setuid(2).)
  • gid Number Sets the group identity of the process. (See setgid(2).)

If the configuration is instead a simple string, it will be interpreted as a full command itself:

exec: {
  echo_something: 'echo "This is something"'
}

Command Functions

If 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.

Passing arguments from the command line

Command functions can be called with arbitrary arguments. Let's say we have the following exec target that echoes a formatted name:

exec: {
  echo_name: {
    cmd: function(firstName, lastName) {
      var formattedName = [
        lastName.toUpperCase(),
        firstName.toUpperCase()
      ].join(', ');

      return 'echo ' + formattedName;
    }
  }
}

In order to get SIMPSON, HOMER echoed, you'd run grunt exec:echo_name:homer:simpson from the command line.

Accessing grunt object

All 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.

Example

The following examples are available in grunt-exec's Gruntfile.

grunt.initConfig({
  exec: {
    remove_logs: {
      command: 'rm -f *.log',
      stdout: false,
      stderr: false
    },
    list_files: {
      cmd: 'ls -l **'
    },
    list_all_files: 'ls -la',
    echo_grunt_version: {
      cmd: function() { return 'echo ' + this.version; }
    },
    echo_name: {
      cmd: function(firstName, lastName) {
        var formattedName = [
          lastName.toUpperCase(),
          firstName.toUpperCase()
        ].join(', ');

        return 'echo ' + formattedName;
      }
    }
  }
});

Testing

$ cd grunt-exec
$ npm test

Issues

Found a bug? Create an issue on GitHub.

https://github.com/jharding/grunt-exec/issues

Versioning

For transparency and insight into the release cycle, releases will be numbered with the follow format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backwards compatibility bumps the major
  • New additions without breaking backwards compatibility bumps the minor
  • Bug fixes and misc changes bump the patch

For more information on semantic versioning, please visit http://semver.org/.

License

Original Copyright (c) 2012-2014 Jake Harding Copyright (c) 2016 grunt-exec Licensed under the MIT License.

Credits and original authors

Original copyright, license notices and contributor acknowledgements remain part of this distribution. Stackline maintenance does not replace authorship of the original work.

License

MIT. See the license and notice files in the repository.

Use this repository's issue tracker for reproducible bugs and feature requests. Join r/Stackline for examples, usage questions and release discussions.