gulp-intermediate2
v1.0.3
Published
A gulp helper for tools that need files on disk.
Downloads
117
Maintainers
Readme
gulp-intermediate2
This plugin is a modern version of gulp-intermediate
.
Fully support various encodings and streaming mode.
A gulp helper for tools that need files on disk.
Some tools require access to files on disk instead of working with stdin
and stdout
(e.g., Jekyll, Ruby Sass).
gulp-intermediate2
is a convenience plugin
that writes the current vinyl stream to a temporary directory,
lets you run commands on the file system, and pushes the results back into the pipe.
NOTE: Writing intermediate files to disk is counter to the gulp philosophy.
If possible, use a tool that works with streams.
Use gulp-intermediate2
only if other (better) options aren't available.
Install
npm install --save-dev gulp-intermediate2
Usage
var gulp = require('gulp');
var spawn = require('child-process').spawn;
var intermediate2 = require('gulp-intermediate2');
gulp.task('default', function () {
return gulp.src('**/*', { encoding: false })
.pipe(intermediate2(
{
destOptions: { encoding: false },
srcOptions: { encoding: false }
},
function (srcDirPath, destDirPath, callback) {
// Run a command on the files in tempDir and write the results to
// the specified output directory.
spawn('a_command', ['--dest', '_site'], {cwd: tempDir});
.on('close', cb);
}
))
.pipe(gulp.dest(testDestFilesPath))
});
With streaming mode:
var gulp = require('gulp');
var spawn = require('child-process').spawn;
var intermediate2 = require('gulp-intermediate2');
gulp.task('default', function () {
return gulp.src('**/*', { encoding: false, buffer: false })
.pipe(plugin.intermediate2(
{
destOptions: { encoding: false },
srcOptions: { encoding: false, buffer: false },
container: 'test-container',
output: 'test-output'
},
function (srcDirPath, destDirPath, callback) {
// Run a command on the files in tempDir and write the results to
// the specified output directory.
spawn('a_command', ['--dest', '_site'], {cwd: tempDir});
.on('close', cb);
}
))
.pipe(gulp.dest(testDestFilesPath, { encoding: false }))
});
API
intermediate2([options], [process])
options
Type: object
Optional
destOptions
Type: object
Optional
All options, supported by gulp.dest
.
Options for writing input Vinyl files to temp directory.
srcOptions
Type: object
Optional
All options, supported by gulp.src
.
Options for reading output files from the temp output directory
after the process is completed.
output
Type: string
Default: '.'
The directory read back into the stream when processing is finished.
Relative to tempDir\<uniqueID>
.
container
Type: string
Default: random uuid
The directory that input files are written to.
Relative to tempDir\<uniqueID>
.
The container is emptied before every run.
process(srcDirPath, destDirPath, cb)
Type: function
Run your commands.
process
comes with three arguments:
srcDirPath
: The absolute path to the directory containing your input temporary files.destDirPath
: The absolute path to the directory containing your output temporary files.cb
: A callback function to call when the processing is finished. It pushes the output files (from destDirPath) back into the gulp stream.
Notes
The files are written to tempDir
using the vinyl file object's relative path,
with gulp.dest()
.