Produces the output of gulp to a variable
I am using the gulp-run plugin to get the git hash using the following code:
run('git log -1 --pretty=format:%H').exec();
I can add a pipe to save the output to a file, for example:
run('git log -1 --pretty=format:%H').exec().pipe(gulp.dest('some/dir'));
From there I can read the contents of the file using readFile () to get the git hash.
Is there a way to skip this step and get the gulp-run output into a variable directly?
+3
source to share
1 answer
Two comments:
I would recommend
git rev-parse HEAD
Instead git log -1 --pretty=format:%H
And you can easily do it with https://github.com/mgutz/execSync , gulp-run is not required.
var sh = require('execSync');
var revision = sh.run('git rev-parse HEAD');
console.log(revision); // => 93004330f14fd502e1568a0c2c1a645eae269e1b
0
source to share