Giter Site home page Giter Site logo

Support function arguments about gulp-exec HOT 7 OPEN

robrich avatar robrich commented on August 24, 2024
Support function arguments

from gulp-exec.

Comments (7)

robrich avatar robrich commented on August 24, 2024

It looks like you're looking for gulp-if

from gulp-exec.

perrin4869 avatar perrin4869 commented on August 24, 2024

hm... yup totally missed it, what I wrote above can be done with gulp-if (using accessSync of course).
Wouldn't it be a stronger API, however, if exec accepted a function instead of a loadash template (and additionally, the function could return a Promise).

from gulp-exec.

robrich avatar robrich commented on August 24, 2024

It totally would, but arguably that breaks gulp-exec's "do one thing". I suspect we're quickly reaching the point where you've outgrown gulp-exec. Here's another strategy:

const through = require('through2');

gulp.task('task', function () {
  return gulp.src('/path/to/*.files')
    .pipe(through.obj(function (file, enc, callback) {
      const self = this;
      if (file.stat.isFile()) {
        exec('some-command', function(err, stdout, stderr) {
          this.push(file);
          callback();
        });
      } else {
        exec('other-command', function (err, stdout, stderr) {
          this.push(file);
          callback();
        });
      }
    }))
    .pipe(gulp.dest('/path/to/dist');
});

... granted this gets really cool when using async/await rather than callbacks. :D

from gulp-exec.

perrin4869 avatar perrin4869 commented on August 24, 2024

Hm... interesting that you say that it breaks gulp-exec do one thing. I see that gulp-exec dates all the way back to 2013, which explains the choice of the now awkward-looking lodash template. Removing the lodash dependency and leaving interpolation up to the user (who will, presumably, use ES6 backtick) makes gulp-exec lighter and more "do one thing".
Adding support for async commands in the form of Promise would be a nice simple bonus, since most libs support this by now. It is unfortunate though that through2 still only has a callback based api though haha

from gulp-exec.

robrich avatar robrich commented on August 24, 2024

Good point. Arguably all of gulp is "legacy". I typically don't use gulp directly anymore, leveraging Webpack instead. For the rare case where I do need to pipe files through a process I use vinyl-fs and through2, then after the last thing, I turn the stream into a promise using stream-promise, stream-to-promise, or this simple fn and then await it.

function waitStreamDone(stream) {
  return new Promise((resolve, reject) => {
    stream
      .on('error', reject)
      .on('end', resolve)
      .on('finish', resolve);
  });
}

from gulp-exec.

perrin4869 avatar perrin4869 commented on August 24, 2024

Well, gulp still has its place in 2020, doesn't it? It is a general task runner after all, you do not need to run streams on it necessarily. webpack provides an easy solution to bundle a website, but what about other applications, for example, something like electron? Or what if you do not want to use webpack, but are like me and want to build all parts of the application separately with rollup, postcss, minify images, manage gettext files (for which I want to use this plugin btw), etc.
What do you think about a major version of gulp-exec that accepts either a plain string command, or a function (file: VinylFile) => String? Adding promise support, now that I think about it, is not critical, because most fs functions have a sync version anyways. Although there is probably some use-case for them.

from gulp-exec.

robrich avatar robrich commented on August 24, 2024

Check out gulp-exec 5.0.0. It removes lodash templates and uses a sync function for resolving the command.

from gulp-exec.

Related Issues (20)

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.