Comments (7)
It looks like you're looking for gulp-if
from gulp-exec.
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.
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.
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.
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.
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.
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)
- `exec` -> `execFile` HOT 4
- Allow outputting stderr, stdout even if the exec'd command fails with a nonzero exit code HOT 1
- stdout maxBuffer exceeded HOT 6
- Possible to parse report to then set variables? HOT 1
- gulp-exec not writing anything to console HOT 7
- Echo hangs and loops infinitely HOT 3
- Remove dependency on "gulplog" HOT 1
- Setting current working directory when executing command HOT 1
- Request for echo option HOT 1
- child process closing immediately HOT 2
- too many arguement HOT 3
- Replace deprecated dependency gulp-util
- stuck forever!
- stuck forever at "gulp task" HOT 1
- Can't continue to pipe output of exec HOT 6
- Incorrect handling of binary content from stdout HOT 2
- Windows & Path HOT 16
- Powershell logs during the execution HOT 1
- Color support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gulp-exec.