IT-Service / gulp-intermediate2

A gulp helper for tools that need files on disk
MIT License
0 stars 0 forks source link

gulp-intermediate2

GitHub release Build and Test Status

Semantic Versioning Conventional Commits

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 intermediate = require('gulp-intermediate2');

gulp.task('default', function () {
  return gulp.src('app/**/*.jade')
    .pipe(intermediate({ output: '_site' }, function (tempDir, cb) {
      // Run a command on the files in tempDir and write the results to
      // the specified output directory.
      var command = spawn('a_command', ['--dest', '_site'], {cwd: tempDir});
      command.on('close', cb);
    }))
    .pipe(gulp.dest('dist'));
});

API

intermediate([options], [process])

options

Type: object Optional

output

Type: string Default: '.'

The directory read back into the stream when processing is finished. Relative to tempDir.

container

Type: string Default: random uuid

The directory that files are written to, relative to the operating system's temporary directory. Defaults to a unique random directory on every run.

The container is emptied before every run.

process(tempDir, cb, [fileProps])

Type: function Optional

Run your commands inside the process callback. process comes with three arguments:

Notes

The files are written to tempDir using the vinyl file object's relative path, just like gulp.dest() writes to the output directory. Make sure you understand how globbing works to avoid unexpected errors: for example, the files in gulp.src(['files/*.json', config.yml]) will all be output at the root of tempDir.

Consider passing the { base: '.' } option to glob.src if you need to output a src glob as it exists on disk. When in doubt, log tempDir to the console and open it to see what's going on.