Skip to content
This repository has been archived by the owner on Jul 18, 2021. It is now read-only.
/ grunt-spawn-pipe Public archive

Grunt plugin for running and piping commands using spawn()

Notifications You must be signed in to change notification settings

lobodpav/grunt-spawn-pipe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

! CAUTION !

This module is not maintained anymore.

grunt-spawn-pipe

Execute your long-running app and pipe its output somewhere else.

Intro

You have a long running app and you want its output to be processed by another utility. For example, your Node.js app uses Bunyan for logging, you want the output to be pretty-printed. I.e. to pipe the output of your app to Bunyan.

Existing Grunt plugins use two approaches:

  1. Using child_process.exec() allows to easily pipe commands but will terminate your app once its buffer gets full. Not a solution for long running apps.
  2. Using child_process.spawn() fixes the buffer issue but does not allow easy piping.

This plugin is here to allow you to spawn processes and pipe them together.

Getting Started

This plugin requires Grunt ~1.0.1 and was tested on OS X operating system.

Install the plugin:

npm install grunt-spawn-pipe --save-dev

Once the plugin is installed, enable it inside your Gruntfile:

grunt.loadNpmTasks('grunt-spawn-pipe');

spawnPipe task

Run this task with the grunt spawnPipe command.

Options

The options you set are passed over to every call to Node's spawn() function. Read Node doc for more details on which options you can set.

Usage example

module.exports = function(grunt) {
    grunt.initConfig({
        spawnPipe: {
            ls: {
                options: {
                    cwd: '/'
                },
                commands: [
                    {cmd: 'ls',   args: ['-la']},
                    {cmd: 'grep', args: ['etc']}
                ]
            },
            startDev: {
                commands: [
                    {cmd: 'node',   args: ['src/index.js']},
                    {cmd: 'bunyan', args: ['-o', 'short', '--color']}
                ]
            }
        }
    });

    grunt.loadNpmTasks('grunt-spawn-pipe');
}

options and args properties are optional. The rest is mandatory.

Technical details

Output piping

  • The plugin pipes stdout of the first command to stdin of the second command and so on.
  • All stderrs are piped to stderr of the process executing the spawn commands.
  • stdout of the last command is piped to stdout of the process executing the spawn commands.

Error handling

If an error occurs in any of the command, for example because of a typo in command name, the first command is killed to ensure the whole piped chain gets terminated.

Environment

process.cwd and process.env are used as defaults for all spawn() calls. You can override these values in task options.

About

Grunt plugin for running and piping commands using spawn()

Resources

Stars

Watchers

Forks

Packages

No packages published