Git Product home page Git Product logo

gulp-exec's Introduction

gulp-exec status

exec plugin for gulp

Usage

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

gulp.task('reset', function() {
  var options = {
    continueOnError: false, // default = false, true means don't emit error event
    pipeStdout: false, // default = false, true means stdout is written to file.contents
  };
  var reportOptions = {
  	err: true, // default = true, false means don't write err
  	stderr: true, // default = true, false means don't write stderr
  	stdout: true // default = true, false means don't write stdout
  };
  return gulp.src('./**/**')
    .pipe(exec(file => `git checkout ${file.path} test`, options))
    .pipe(exec.reporter(reportOptions));
});

Note: If you just want to run a command, just run the command, don't use this plugin:

var exec = require('child_process').exec;

gulp.task('task', function (cb) {
  exec('ping localhost', function (err, stdout, stderr) {
    console.log(stdout);
    console.log(stderr);
    cb(err);
  });
})

gulp.src('.') does bad things. Don't do it.

Note: running and reporting are now separate, a breaking change from previous versions.

Upgrading

Version 5 and later no longer use lodash templates. Upgrade from:

.pipe(exec('git checkout <%= file.path %> <%= options.customTemplatingThing %>', options))

to:

.pipe(exec(file => `git checkout ${file.path} customTemplatingThing`, options))

Note how you can now resolve the command with an ES6 string template in the function.

LICENSE

(MIT License)

Copyright (c) 2014 Richardson & Sons, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gulp-exec's People

Contributors

edrex avatar glebka avatar mischah avatar perrin4869 avatar robrich avatar rogierschouten avatar sun-zheng-an avatar thedancingcode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gulp-exec's Issues

Setting current working directory when executing command

I need to be able to execute "npm install" on a number of subfolders, for which I need to change current working dir to a specific folder when execution my command. Unfortunately, I can find no way to do this in gulp-exec ?

Possible to parse report to then set variables?

I need to extract some text from stdout and make that available to subsequent & separate gulp tasks - how should I go about that? Both the parse & extract part, and the make-available part (maybe write to a file?).

Allow for not returning the error in the callback.

I'm currently operating on a hacked version where I null out the error for the callback for map. I'm using gulp with a watch and if it errors, it kills my watch, which makes me have to quit and restart gulp. Its enough for me to see an exception in the command line. It's normal to have something not right in your code, to correct it, and then to expect watch to just pick up from there.

Replace deprecated dependency gulp-util

gulp-util has been deprecated recently. Continuing to use this dependency may prevent the use of your library with the latest release of Gulp 4 so it is important to replace gulp-util.

The README.md lists alternatives for all the components so a simple replacement should be enough.

Your package is popular but still relying on gulp-util, it would be good to publish a fixed version to npm as soon as possible.

See:

Echo hangs and loops infinitely

If I echo out to a file, the command runs, but it loops infinitely and recursively writes to the target file.

Here's my use-case as to why I'm even performing an echo:

I really enjoy the safeguard in password protecting my SSH key. Not so much for the extra 'security', but it gives me a brief moment to decide if there's something I forgot and back out of a push. I'm in the process of automating an upstream setup using Gulp where I need to use a password-less key to handle the subtree setup. The point of the echo is to write to the SSH config to change the key to the p/w-less one for setting, pulling and merging the subtree, then restoring it once the process completes.

This is all you need to reproduce:

GULP.task('_homez', () => { return GULP.src('./**/**') .pipe( PLUGINS.exec('echo test > test.txt') ) .pipe( PLUGINS.exec.reporter()); } );

Can't get exec working with gulp 100%

Hi there.

Good package, was needed for running custom console commands after our builds are done, one problem - I can't chain anything after exec (like notifying), and it doesn't seem to work via a pipe command as you have in your example. This is what I've got:

gulp.task('publish', ['css', 'scripts'], function() {
    gulp.src('./**/**')
        .pipe(exec('php ../../artisan bundle:publish', { silent: false }));
        //.pipe(notify({ message: 'Assets published.' }));
});

This will break, complaining about line 24 on the index.js file:

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: spawn EMFILE
    at errnoException (child_process.js:980:11)
    at ChildProcess.spawn (child_process.js:927:11)
    at exports.spawn (child_process.js:715:9)
    at Object.exports.execFile (child_process.js:607:15)
    at exports.exec (child_process.js:578:18)
    at /Users/kirkbushell/Documents/Development/Tectonic/Award Force/www/bundles/shift/node_modules/gulp-exec/index.js:24:3
    at wrappedMapper (/Users/kirkbushell/Documents/Development/Tectonic/Award Force/www/bundles/shift/node_modules/gulp-exec/node_modules/map-stream/index.js:76:19)
    at Stream.stream.write (/Users/kirkbushell/Documents/Development/Tectonic/Award Force/www/bundles/shift/node_modules/gulp-exec/node_modules/map-stream/index.js:88:21)
    at Stream.ondata (stream.js:51:26)
    at Stream.EventEmitter.emit (events.js:95:17)

Now I've run this command manually, runs fine - but not in the context provided in the example provided on the front page.

Windows & Path

Hi,
Anyone could confirm the node_modules\bin path is working under windows?

.pipe($.exec('node_modules\\.bin\\lessc <%= file.path %>', {pipeStdout: true}))
.pipe($.exec('lessc <%= file.path %>', {pipeStdout: true}))

The first one is working, the second is not!
Thanks

Support function arguments

Sometimes the command to execute depends on state other than the filename. For example, you might want to execute different commands if the target file already exist or if it doesn't. The current template format does not allow for this kind of usage.
One simple solution to support this usage is that exec accept a function:

gulp.src(myfiles)
  .pipe(
    exec(file => accessAsync(file.path, F_OK)
      .then(() => 'command to execute if file exists')
      .catch(() => 'command to execute if file does not exist'))
  );

I can put together a PR to support this over the weekend.

Color support

Some commands have colors but via gulp-exec colors are stripped out:

Screen-Shot-2021-10-29-12-16-11 54

Possible to get color support in the future?

too many arguement

events.js:154
throw er; // Unhandled 'error' event
^
Error: Command failed: /bin/sh -c git clone https://github.com/peques/Basic-Portfolio,git clone https://github.com/jeffhatch/Basic-Portfolio
Too many arguments.

// Settings
	var site= "https://github.com/";
	var reponame = "/Basic-Portfolio";

	var studentList = [
		"peques",
		"jeffhatch"
	];

  var options = {
    continueOnError: false, 
    pipeStdout: false, 
    customTemplatingThing: "test" 
  };
  var reportOptions = {
  	err: true, 
  	stderr: true, 
  	stdout: true 
  }
	var urlList = [];
	for (var i = 0; i < studentList.length; i++) {	
		urlList[i] = 'git clone '+site+studentList[i]+reponame
		// console.log( 'git clone '+site+studentList[i]+reponame)
	};

	gulp.task('clone', function() {
		return gulp.src('./**/**')
	    .pipe(
	    	// how it should look...
		    	exec([urlList],options)
	    )
	    // comment out the line below
	    .pipe(exec.reporter(reportOptions));
	});
'''

Wrong path

I try to compile plugin (gulpfile.js):

var path = {
    src: 'src/*.js',
    dest: 'dist/plugin.js'
};

gulp.task('dev', function () {
    gulp.src(path.src)
        .pipe(exec('traceur --out <%= options.dest %> --sourcemap <%= options.src %>',
            {
                src: path.src,
                dest: path.dest
            }))
});

Gives:

[gulp] Failed to load '..\src\*.js'


events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Command failed: Failed to load '..\src\*.js'

    at ChildProcess.exithandler (child_process.js:637:15)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)

For some reason it changes src/*.js to ..\src\*.js.

traceur itself works as expected:
traceur --out dist/plugin.js --sourcemap src/*.js

Seems that child_process.exec() fails.

exec.reporter causing a TypeError : Object #<File> has no method 'on' on stream.js

Hi, after I updated gulp-exec to ~2.0.0 and changed my gulp file to use the reporter, an error is being thrown by gulp-exec:

  dest.on('drain', ondrain);
       ^
TypeError: Object #<File> has no method 'on'
    at Transform.Stream.pipe (stream.js:65:8)
    at Transform._transform (C:\dev\foo\node_modules\gulp-exec\index.js:71:8)
    at Transform._read (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:179:10)
    at Transform._write (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:167:12)
    at doWrite (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:223:10)
    at writeOrBuffer (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:213:5)
    at Transform.Writable.write (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:180:11)
    at write (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:586:24)
    at flow (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:595:7)
    at Transform.pipeOnReadable (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:627:5)
    at Transform.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:411:10)
    at emitReadable (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:407:5)
    at readableAddChunk (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:168:9)
    at Transform.Readable.push (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:130:10)
    at Transform.push (C:\dev\foo\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:140:32)
    at C:\dev\foo\node_modules\gulp-exec\index.js:36:9
    at ChildProcess.exithandler (child_process.js:635:7)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)

This only happens when I try to use the reporter, if I don't do .pipe(exec.reporter(reportOptions)) everything works, but I don't get the stdout output that I need.

Thanks!

Allow custom name for streamed-in data

Currently, I have an array of strings and I want to run a bunch of exec things on each one.

I do this right now. It works, but people will think "what is this file?!"

var es = require('event-stream');
gulp.task('release', function() {
  es.readArray(config.modules)
    .pipe(task.exec('./scripts/bower-module <%= file %>'))
    //... other things with each module
});

I would like to be able to have a simple way to change the key in the template. Perhaps just a simple key option in the task? What do you think?

exec('./scripts/bower-module <%= module %>', { key: 'module' });

Can't continue to pipe output of exec

Hiya! I am trying to use gulp-exec to run a PHP compilation that continues to stream to a minified then a file. I can't seem to get this to work though. I am sure there is some simple answer that I am just missing. I see the output gets put on stdout with the .reporter function but I'm not sure how to get that back into a stream.

/* ******************************************************************
 * Basic PHP Compile Function
 * *****************************************************************/
function phpBuild(phpFilename, htmlFilename) {
  return () => {
    gulp.src(phpFilename)
      .pipe(exec('php <%= file.path %>'))
      .pipe(htmlMin({ collapseWhitespace: true }))
      .pipe(exec.reporter())
      .pipe(rename(path.basename(htmlFilename)))
      .pipe(gulp.dest(path.dirname(htmlFilename)));
  } // return
} // phpBuild

stdout maxBuffer exceeded

Hi!
I use galp-exec to generate the report for tests. But when the number of tests has increased , the report no longer fit into the buffer (200kb) and i receive "stdout maxBuffer exceeded".
How can i manage child_process-buffer from gulp-exec?
Thanks

child process closing immediately

If you're not familiar with icecast, it's a multimedia server.

When I run icecast -c ./icecast/icecast.xml in the terminal, it starts an icecast server, which stays alive.

So I want to run that command alongside my node.js process, every time I run gulp.

I added the following to my gulpfile.

import exec from 'gulp-exec'

...

const icecastDir = path.resolve(`${__dirname}/icecast/`)

...

gulp.task(`icecast`, () => {
  return exec(`/usr/local/bin/icecast -c ${icecastDir}/icecast.xml`)
    .on(`data`, () => {
      console.log(`data`)
    }) 
    .on(`error`, () => {
      console.log(`error`)
    }) 
    .on(`end`, () => {
      console.log(`end`)
    }) 
    .on(`close`, () => {
      console.log(`error`)
    }) 
    .on(`readable`, () => {
      console.log(`readable`)
    }) 
})

When I run the command gulp icecast in my terminal, gulp says Starting 'icecast'... and then immediately terminates. None of the callbacks fire. I'd really like it to stay alive until I cmd-c the gulp process.

`silent:false` not working and doesn't fail on error

First, I'm trying this on Windows and I'm using the latest from GitHub, not NPM.

silent

I assume it should show me the output. It doesn't. What I tried was installing an NPM package.

continueOnError

It doesn't fail if I try installing an NPM package that doesn't exist or run a command that doesn't exist like dsjodfbs9ucnu9wecsdfsfdsfs. (I didn't set continueOnError)

Use stdin and stdout

It would be nice if gulp-exec could (as an option) stream the result of the previous .pipe() into the stdin of the executed process, and stream the stdout of the process into the next .pipe().

stuck forever at "gulp task"

`gulp.task('task', function (cb) {

exec('ng test -cc', function (err, stdout, stderr) {

console.log(stdout);

console.log(stderr);

cb(err);
});

})`

Allow outputting stderr, stdout even if the exec'd command fails with a nonzero exit code

I couldn't figure out how to do this using gulp-exec. Is there a way to?

If I run a command that exits with a nonzero exit code I get the following vague output with no mention of the stdout or stderr of the failed command:

events.js:72
throw er; // Unhandled 'error' event
^
Error: Command failed:
at ChildProcess.exithandler (child_process.js:637:15)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)

Remove dependency on "gulplog"

I notice you have a dependency on "gulplog" in your package.json, but you use gutil.log with the source code.

Do you need this dependency any more?

Incorrect handling of binary content from stdout

Hi.

gulp-exec plugin corrupts binary data that come from stdout. See example gulpfile.js below.

gulp.task("extractAlpha", function() {
  var options = {
    continueOnError: false,
    pipeStdout: true,
    encoding: 'binary'
  };
  return gulp
    .src("./*.png")
    .pipe(
        exec(
          "convert <%= file.path %> -alpha extract -",
          options
        )
      )    
    .pipe(gulp.dest('out/'));    
});

Here you can see extractAlpha task that uses convert CLI tool from ImageMagick distribution. It extracts alpha channel as a separate image and outputs the result to the stdout.
When I run this task I get corrupted image in the output folder. Note, that I've specified encoding: 'binary' option for exec but it doesn't help.

The root cause of the issue is here:

file.contents = new Buffer(stdout); // FRAGILE: if it wasn't a buffer it is now

Providing an encoding when creating a Buffer should fix the issue.

Will create PR for this soon.

This issue occurs on:
Windows 8.1, NodeJS v8.11.2

Powershell logs during the execution

Hello,

How could I have the logs of my powershell tasks during the execution? Because for the moment, I am only able to write the result of my execution when the powershell execution is finished and that is an issue for the long running tasks because we have the feeling that nothing happen.

Here is the function I currently use:

const child_process = require('child_process');
const exec = child_process.exec;
function executePS(scriptPath, callback) {
    exec("Powershell.exe  -executionpolicy remotesigned " + scriptPath, function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
        callback(err);
    });
}

exports.executePS = executePS;

Regards,

Getting started

Hi.

I'm experimenting with gulp and was looking at the existing plugins. Unfortunately there's isn't a gulp-jekyll plugin so I thought I'd try gulp-exec to run jekyll.

var gulp = require("gulp");
var gutil = require("gulp-util");
var exec = require("gulp-exec");

gulp.task("default", function() {
    exec("jekyll build");
});

output

[gulp] Using file C:\Users\xmr\Desktop\mpc-hc.org\gulpfile.js
[gulp] Working directory changed to C:\Users\xmr\Desktop\mpc-hc.org
[gulp] Running 'default'...
[gulp] Finished 'default' in 233 μs

Note I'm fairly new to gulp so I'm probably doing something wrong.

Thanks in advance!

gulp-exec not writing anything to console

My task is similar to this:

gulp.task('db', function () {
  return gulp.src('./**/**')
    .pipe(exec('node ./scripts/dropDb.js'))
    .pipe(exec('node ./scripts/addRandomUsers.js'))
    .pipe(exec.reporter());
})

The script dropDb contains the following:

var generateDb = function() {  
  // do something
  Promise.resolve();
});
generateDb().then(function() {
  console.log("done!");
}).catch(function (err) {
  console.error(err);
}).finally(function () {
  process.exit();
});

The problem I have is that nothing is written to the console, and I have no idea what it is happening because it never seems to end.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.