• Stars
    star
    151
  • Rank 246,057 (Top 5 %)
  • Language
    JavaScript
  • License
    ISC License
  • Created over 10 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pipe to shell commands in gulp

gulp-run

Codacy Badge

Use shell commands in your gulp or vinyl pipeline.

Many command line interfaces are built around the idea of piping. Let's take advantage of that in our Gulp pipeline! To use gulp-run, simply tell it the command to process your files; gulp-run accepts any command you could write into your shell, including I/O redirection like python < baz.py | cat foo.txt - bar.txt. Additionally, node_modules/.bin is included on the path, so you can call programs supplied by your installed packages. Supports Unix and Windows.

This plugin is inspired by gulp-shell and gulp-spawn and attempts to improve upon their great work.

Usage

var run = require('gulp-run');

// use gulp-run to start a pipeline
gulp.task('hello-world', function() {
  return run('echo Hello World').exec()    // prints "Hello World\n".
    .pipe(gulp.dest('output'))      // writes "Hello World\n" to output/echo.
  ;
})


// use gulp-run in the middle of a pipeline:
gulp.task('even-lines', function() {
  return gulp
    .src('path/to/input/*')             // get input files.
    .pipe(run('awk "NR % 2 == 0"'))     // use awk to extract the even lines.
    .pipe(gulp.dest('path/to/output'))  // profit.
  ;
});

// use gulp-run without gulp
var cmd = new run.Command('cat');  // create a command object for `cat`.
cmd.exec('hello world');           // call `cat` with 'hello world' on stdin.

API

run(template, [options])

Creates a Vinyl (gulp) stream that transforms its input by piping it to a shell command.

See run.Command for a description of the arguments.

Returns

(stream.Transform in Object Mode): Returns a Transform stream that receives Vinyl files. For each input, a subprocess is started taking the contents of the input on stdin. A new file is pushed downstream containing the process's stdout.

Example

gulp.task('even-lines', function() {
  return gulp
    .src('path/to/input/*')             // get input files.
    .pipe(run('awk "NR % 2 == 0"'))     // use awk to extract the even lines.
    .pipe(gulp.dest('path/to/output'))  // profit.
  ;
})

run(...).exec([stdin], [callback])

Start a gulp pipeline and execute the command immediately, pushing the results downstream.

Arguments

  1. [stdin] (String | Buffer | Vinyl): If given, this will be used as stdin for the command.
  2. [callback] (Function): The callback is called once the command has exited. An Error is passed if the exit status was non-zero. The error will have a status property set to the exit status.

Returns

(Stream.Readable in Object Mode): Returns a Vinyl (gulp) stream which will push downstream the stdout of the command as a Vinyl file. The default path of the Vinyl file is the first word of the template; use gulp-rename for more versatility.

Example

gulp.task('hello-world', function() {
  return run('echo Hello World').exec()  // prints "[echo] Hello World\n".
    .pipe(gulp.dest('output'))           // writes "Hello World\n" to output/echo.
  ;
})

new run.Command(template, [options])

Represents a command to be run in a subshell.

Arguments

  1. template (String): The command to run. It can be a template interpolating the variable file which references the Vinyl file being input. The template need not interpolate anything; a simple shell command will do just fine. The command is passed as an argument to sh -c, so I/O redirection and the like will work as you would expect from a terminal.
  2. options (Object):
    • env (Object): The environmental variables for the child process. Defaults to process.env.
    • cwd (String): The initial working directory for the child process. Defaults to process.cwd().
    • silent (Boolean): If true, do not print the command's output. This is the same as setting verbosity to 1. Defaults to false.
    • verbosity (Number): Sets the verbosity level. Defaults to 2.
      • 0: Do not print anything, ever.
      • 1: Print the command being run and its stderr.
      • 2: Print the command, its stderr, and its stdout.
      • 3: Print the command, its stderr, and its stdout progressivly. Not useful if you have concurrent gulp-run instances, as the outputs may get mixed.
    • usePowerShell (Boolean): Windows only. If true uses the PowerShell instead of cmd.exe for command execution.

run.Command#exec([stdin], [callback])

Spawn a subshell and execute the command.

Arguments

  1. [stdin] (String | Buffer | Vinyl): If given, this will be used as stdin for the command.
  2. [callback] (Function): The callback is called once the command has exited. An Error is passed if the exit status was non-zero. The error will have a status property set to the exit status.

Returns

(Vinyl): Returns a Vinyl file wrapping the stdout of the command.

Example

var cmd = new run.Command('cat');  // create a command object for `cat`.
cmd.exec('hello world');           // call `cat` with 'hello world' on stdin.

The ISC License

Copyright (c) 2014 Chris Barrick [email protected] Copyright (c) 2016 Marc Binder [email protected]

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

More Repositories

1

acl

a lightweight acl manager for go.
Go
85
star
2

graphql-firestore-subscriptions

A simple & powerful package to broadcast events from Cloud Firestore over an AsyncIterator to your GraphQL Subscription Resolver.
TypeScript
65
star
3

relay-context

A simple way to manage your relay environment(s)
JavaScript
10
star
4

action-lerna

A simple GitHub Action to use _lerna_
Dockerfile
9
star
5

ng-confirm

Simple confirm button for angular.
JavaScript
8
star
6

grunt-codeclimate-reporter

Send your coverage to codeclimate.
JavaScript
6
star
7

tb

The tree builder (tb) allows the developer to specialize a configuration fast and without problems through an easy API.
JavaScript
6
star
8

node-config-uncached

Purge the internal require.cache for all files used by config.
JavaScript
5
star
9

protector

github branch protection as code
TypeScript
5
star
10

should-update

A simple shouldComponentUpdate utility
JavaScript
4
star
11

type-cfg

Declare your configuration schema using classes and decorators.
TypeScript
3
star
12

gulp-codeclimate-reporter

Send your coverage to codeclimate.
JavaScript
3
star
13

minionipsum

Sublime Text 2 Plugin to generate an awesome "Minion Ipsum..." text
Python
3
star
14

purejax

Purejax is a pure javascript ajax library.
JavaScript
2
star
15

yacfg

yacfg organizes the configuration for different deployment environments.
JavaScript
2
star
16

gulp-codacy

Send your coverage to codacy.
JavaScript
2
star
17

http-test

A simple and robust way to test your http endpoints.
JavaScript
2
star
18

iframe-communicator

Communicate between two iframes to run scripts synchronously (LocalConnection replacement).
JavaScript
2
star
19

store

store is a simple and flexible way to hold your data unified and handle it with methods store comes with.
PHP
1
star
20

mongoose-plugin-soft-delete

A mongoose plugin to handle soft-deletes
JavaScript
1
star
21

mrboolean.github.com

Private Github page.
1
star
22

dash-search

dash-search allows you to query the locally installed Dash for MAC instance.
JavaScript
1
star
23

ignore-props

A tiny library which gives you the possibility to remove all the unnecessary props.
JavaScript
1
star
24

nstrap

nstrap is a bootstrap library which allows you to start your application with less overhead and an unified interface.
JavaScript
1
star
25

express-hbs-segment

express-hbs-segment takes care of recurring hbs elements.
JavaScript
1
star
26

pass-props

A tiny library which gives you the possibility to pass specific props.
JavaScript
1
star
27

gulp-dev-server

With gulp-dev-server you can simplify your development environment easy and uncomplicated. The annoying stopping and starting your script has an end.
JavaScript
1
star