-
Notifications
You must be signed in to change notification settings - Fork 22
Templates
Shell commands in gulp-run are actually templates interpolating Vinyl.
Behind the scenes, Gulp works by passing virtual files (Vinyl) through the pipeline. Gulp plugins take these files, manipulate their contents, and push the changes down stream. In gulp-run, you have access to the file being processed in you command string.
Consider the following example:
gulp.src('input/*')
.pipe(run('echo <%= file.relative %>'))
.pipe(gulp.dest('output'))Let's assume that the directory ./input contains one file called foo.txt. In this example, Gulp sources the file ./input/foo.txt, then calls the command echo foo.txt (with the contents of foo.txt on stdin), and finally writes the output of the command to ./output/foo.txt.
You should have noticed that echo foo.txt was the command called, but echo <%= file.relative %> was the command given to gulp-run. Everything between <%= and %> is treated as JavaScript to be interpolated into the command at runtime. During the interpolation, you have access to a file variable which references the Vinyl file being processed.
For a list of available properties on the file object, checkout the Vinyl docs. And for more information on template interpolation, see the Lo-Dash docs.