# grunt-spawn

> A process launcher designed for when you dont have a grunt plugin, or know the console command but cannot be bothered adding yet another plugin to your arsenal of growing tools :)

Latest version **1.1.74** (published 2015-12-07) · 0 weekly downloads

## Install

```sh
npm install grunt-spawn
pnpm add grunt-spawn
yarn add grunt-spawn
bun add grunt-spawn
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.74 |
| Published | 2015-12-07 |
| First published | 2013-06-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | 0.10.x |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+12 in 3 direct dependencies) |
| Install scripts | no |
| Author | fir3pho3nixx@gmail.com |
| Maintainers | fir3pho3nixx |
| Keywords | grunt, spawn, shell, cmd, command, exec, execute, gruntplugin |

## Links

- npm: https://www.npmjs.com/package/grunt-spawn
- Repository: https://github.com/fir3pho3nixx/grunt-spawn
- Issues: https://github.com/fir3pho3nixx/grunt-spawn/issues
- npm.io page: https://npm.io/package/grunt-spawn

## Dependencies (6)

- [async](https://npm.io/package/async.md) 0.9.0
- [lodash](https://npm.io/package/lodash.md) 3.4.0
- [string](https://npm.io/package/string.md) 3.3.1
- [fs-tools](https://npm.io/package/fs-tools.md) 0.2.11
- [minimatch](https://npm.io/package/minimatch.md) 2.0.1
- [string-format](https://npm.io/package/string-format.md) 0.5.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.1.74 (latest) — 2015-12-07
- 1.1.72 — 2015-03-11
- 1.1.71 — 2015-03-11
- 1.1.69 — 2015-03-08
- 1.1.66 — 2015-01-18
- 1.1.65 — 2015-01-18
- 1.1.62 — 2014-09-01
- 1.1.60 — 2014-09-01
- 1.1.59 — 2014-09-01
- 1.1.57 — 2014-09-01
- 1.1.54 — 2014-08-24
- 1.1.52 — 2013-11-13
- 1.0.51 — 2013-11-13
- 1.0.49 — 2013-11-10
- 1.0.47 — 2013-11-09
- … 48 more at https://npm.io/package/grunt-spawn/versions

## README

grunt-spawn [![Build Status](https://travis-ci.org/fir3pho3nixx/grunt-spawn.png?branch=master)](https://travis-ci.org/fir3pho3nixx/grunt-spawn)
===========

A process launcher designed for when you dont have a grunt plugin, or know the console command but cannot be bothered adding yet
another plugin to your arsenal of tools :)

Sometimes bootstrapping the console is the simplist way and removes a layer of abstraction between you as the developer and the kind of automation you need. I also found it particularly useful for teaching javascript automation in a predominently C# environment where knowledge of javascript is zero to none. 

## What is this?

This project is a plugin for Grunt.JS that gives one the ability to spawn processes. This project has been tested heaps on windows but most of the development happens from a Unix flavour of some description(Mac).

## How do I use it?

### npm install

You can install this plugin via the node package manager. 

    npm install grunt-cli -g
    npm install grunt
    npm install grunt-spawn

### package.json

It is also good to create yourself a package.json file and embed this in your devDependencies section. For more please click [here](https://docs.npmjs.com/files/package.json). Example below: 

    {
      "name": "my-project",
      "version": "0.0.1",
      "private": true,
      "author": "foo@world.com",
      "description": "my-project",
      "keywords": [
        "grunt",
        "spawn"
      ],
      "repository": {
        "type": "git",
        "url": "https://github.com/me/my-project.git"
      },
      "dependencies": {
      },
      "devDependencies": {
        "grunt": "0.4.x",
        "grunt-spawn": "0.0.x"
      },
      "scripts": {
        "test": "grunt spawn:test"
      },
      "engines": {
        "node": "0.10.x"
      }
    }

## What about Grunt?

### gruntfile.js

You can use the following example to setup your grunt file. To get you started.

    path = require("path");

    module.exports = function(grunt) {
    //grunt.option("force", true);
    
    grunt.initConfig({
      
      pkg: grunt.file.readJSON("package.json"),

      jshint: {
        files: [
          "package.json",
          "gruntfile.js", 
          "lib/**/*.js",
          "test/**/*.js"
        ]
      },

      spawn: {
        echo: {
          command: "echo",
          commandArgs: ["{0}"], 
          directory: "./tests",
          pattern: "**/*.js",
          useQuotes: true,
          quoteDelimiter: "\"",
          groupFiles: true,
          fileDelimiter: " ", 
          ignore: ["notNeededFile.js"]
        },
        list: {
          command: "ls",
          commandArgs: ["-la", "{0}"], 
          directory: "./tests"
        },
        test: {
          command: "mocha",
          commandArgs: ["--reporter", "spec", "{0}"],
          directory: "./tests",
          pattern: "**/*.js"
        }
      },

      release: {
        options: {
          bump: true,
          file: "package.json",
          add: true, 
          commit: true,
          tag: true,
          push: true,
          pushTags: true,
          npm: true
        }
      }

    });

    
      grunt.loadTasks("./tasks");
      grunt.loadNpmTasks("grunt-release");
      grunt.loadNpmTasks("grunt-contrib-jshint");

      grunt.registerTask("test", ["spawn:test"]);
      grunt.registerTask("default", ["spawn:test", "release"]);
    
    };

## What does it all mean?

### The 'spawn' task

Pay special attention to the spawn task above. There are two targets namely `list` which is merely a demonstration of a bare bones shell command and `test` which demonstrates how this plugin can be tweaked to do slightly more fine grained spawning. Grunt-cli commands below: 

    grunt spawn:echo

OR

    grunt spawn:list

OR

    grunt spawn:test

Here is a brief description of the elements involved when configuring a grunt-spawn subtask:

 - `command`: "echo" -> Any command
 - `commandArgs`: ["{0}"] -> commandArgs where '{0}' is a placeholder for a file
 - `directory`: "./tests" -> Working directory
 - `pattern`: "**/*.js" -> Globbing wildcard based on minimatch
 - `useQuotes`: true -> Whether to use the quote delimiter or not
 - `quoteDelimiter`: "\"" -> The actual quote delimiter if useQuotes = true
 - `groupFiles`: true -> Whether to group files into a single string
 - 'passThrough': good with groupFiles = true; removes lame file scanning.
 - `fileDelimiter`: " " -> The file delimiter if groupFiles = true
 - `ignore`: ["any.js"] -> The files you would like to exclude
 - `opts`: { cwd: process.cwd() } -> Pass through mechanism for passing 'opts' to grunt.spawn
 - `dontWait`: true | false -> To wait or not?

## More Examples?

Here is a further example of how you would create a start/wait task for express. This 
was tested with express v4.11.0. Notice how we use opts to override stdio. This is 
passed to nodejs spawn. 

### When to 'groupFiles'

If you are not scanning for any wildcard patterns and you would like to pass your
arguments as a space separated array to a single command then you would need to 
set this option to true. If you dont this, then each result found within the wildcard
matching pattern will be run individually against the command. So if three files are 
found, the command will be run 3 times. 

### When to 'passThrough'

If you are not interested in scanning the filesystem and have a command that does not require any file based input from grunt-spawn then you can use set this option to true. This will bypass any scanning done on the current directory. This can dramatically speed up the execution time of things. 

### Express example

Here is an example that launches and provides feedback from express in a blocking way. You
have to CTRL-C to exit.

    module.exports = function(grunt) {

      // Project configuration.
      grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),

        // *** - grunt-spawn: WebStart for Express {Start}
        spawn: {
          webstart: {
            command: 'node',
            commandArgs: ['{0}'],
            directory: './',
            groupFiles: true, 
            passThrough: false,
            pattern: 'www',
            opts: {
              stdio: 'inherit',
              cwd: __dirname + '/'
            }
          }
        // *** - grunt-spawn: WebStart for Express {End}
        }
      });

      // Grunt plugins.
      grunt.loadNpmTasks('grunt-spawn');
      grunt.loadNpmTasks('grunt-contrib-concat');
      grunt.loadNpmTasks('grunt-contrib-uglify');
      grunt.loadNpmTasks('grunt-contrib-qunit');
      grunt.loadNpmTasks('grunt-contrib-jshint');
      grunt.loadNpmTasks('grunt-contrib-watch');

      // Default task.
      grunt.registerTask('default', ['spawn:webstart']);

    };

###Express example output

Included some example output from an express process. 

    Running "spawn:webstart" (spawn) task


    <grunt-spawn/>: Launching child process
    >> <grunt-spawn/>: Launching 'node bin/www' starting in '/usr/local/src/nodejs/poly-plates' overridden with cwd='/usr/local/src/nodejs/poly-plates/'
    GET / 304 314.669 ms - -
    GET /stylesheets/style.css 304 5.350 ms - -
    GET /favicon.ico 404 57.264 ms - 1186


More examples coming soon. Any problems, please raise issues.

---
_Source: https://npm.io/package/grunt-spawn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
