gulp-intermediate2 v3.0.3
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.
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.
Contents
Install
npm install --save-dev gulp-intermediate2
Examples
Using old intermediate
interface
Old intermediate
interface is supported now,
but deprecated.
In new intermediate2
interface process
has 3 parameters, not 2!
And options must be second parameter, not first
(as for intermediate
interface).
/* eslint-disable @typescript-eslint/no-deprecated */
import { intermediate } from '#gulp-intermediate2/compat';
import GulpClient from 'gulp';
import path from 'node:path';
import fs from 'node:fs';
function task1() {
return GulpClient.src('**/*', { cwd: path.resolve(__dirname, 'test-files') })
.pipe(intermediate(
{ output: 'out-sub-dir-in-temp' },
function (tempDir: string, callback): void {
// Files processing...
// For example, copy sources files to output directory
fs.copyFile(
path.join(tempDir, 'testfile1.txt'),
path.join(tempDir, 'out-sub-dir-in-temp/testfile1.txt'),
callback
);
}))
.pipe(GulpClient.dest('output', { cwd: __dirname }));
};
task1.description = 'Test gulp task which uses old gulp-intermediate interface';
task1.flags = {
'--test': 'Test task option'
};
GulpClient.task(task1);
function task2() {
return GulpClient.src('**/*', { cwd: path.resolve(__dirname, 'test-files') })
.pipe(intermediate(
function (tempDir: string, callback): void {
// Files processing on place
callback();
}))
.pipe(GulpClient.dest(path.join(__dirname, 'output')));
};
task2.description = 'Second test task';
GulpClient.task(task2);
Copy UTF-8 files without options
In this example intermediate2
copy source UTF-8 files to
container temp directory, invokes example process function,
and put UTF-8 files from output temp directory
to files pipe.
import { intermediate2 } from '#gulp-intermediate2';
import type { ProcessCallback } from '#gulp-intermediate2';
import GulpClient from 'gulp';
import path from 'node:path';
import fs from 'node:fs';
function task1() {
return GulpClient.src('**/*', { cwd: path.resolve(__dirname, 'test-files') })
.pipe(intermediate2(
function (srcDirPath: string, destDirPath: string, callback: ProcessCallback): void {
// Files processing...
// For example, copy sources files to output directory
fs.cp(srcDirPath, destDirPath, { recursive: true }, callback);
}
))
.pipe(GulpClient.dest('output', { cwd: __dirname }));
};
task1.description = 'Copy utf-8 files without options';
GulpClient.task(task1);
Copy binary files
In this example intermediate2
copy binary files to
container temp directory, invokes example process function,
and put all files from output temp directory
to files pipe.
import { intermediate2 } from '#gulp-intermediate2';
import type { ProcessCallback } from '#gulp-intermediate2';
import GulpClient from 'gulp';
import path from 'node:path';
import fs from 'node:fs';
function task1() {
return GulpClient.src('**/*', {
cwd: path.resolve(__dirname, 'test-files'),
encoding: false
})
.pipe(intermediate2(
function (srcDirPath: string, destDirPath: string, callback: ProcessCallback): void {
// For example, copy sources files to output directory
fs.cp(srcDirPath, destDirPath, { recursive: true }, callback);
},
{ srcOptions: { encoding: false } }
))
// processing output files in gulp style
.pipe(GulpClient.dest('output', { cwd: __dirname }));
};
task1.description = 'Copy utf-8 and binary files';
GulpClient.task(task1);
Streaming mode support
In this example intermediate2
copy binary files to
container temp directory in streaming mode.
import { intermediate2 } from '#gulp-intermediate2';
import type { ProcessCallback } from '#gulp-intermediate2';
import GulpClient from 'gulp';
import path from 'node:path';
import fs from 'node:fs';
function task1() {
return GulpClient.src('**/*', {
cwd: path.resolve(__dirname, 'test-files'),
encoding: false,
buffer: false
})
.pipe(intermediate2(
function (srcDirPath: string, destDirPath: string, callback: ProcessCallback): void {
// For example, copy sources files to output directory
fs.cp(srcDirPath, destDirPath, { recursive: true }, callback);
},
{
destOptions: { encoding: false },
srcOptions: { encoding: false, buffer: false },
container: 'test-container',
output: 'test-output'
}
))
// processing output files in gulp style
.pipe(GulpClient.dest('output', {
cwd: __dirname,
encoding: false
}));
};
task1.description = 'Copy utf-8 and binary files';
GulpClient.task(task1);
Process without callback
In this example intermediate2
uses async process
without callback.
Supported all process functions result types,
supported by async-done
module.
import { intermediate2 } from '#gulp-intermediate2';
import GulpClient from 'gulp';
import path from 'node:path';
import fs from 'node:fs';
function task1() {
return GulpClient.src('**/*', {
cwd: path.resolve(__dirname, 'test-files'),
encoding: false,
buffer: false
})
.pipe(intermediate2(
function (srcDirPath: string, destDirPath: string) {
// For example, copy sources files to output directory
// or
// return spawn('a_command', ['--dest', '_site'], {cwd: tempDir});
return fs.promises.cp(srcDirPath, destDirPath, { recursive: true });
},
{
destOptions: { encoding: false },
srcOptions: { encoding: false, buffer: false },
container: 'test-container',
output: 'test-output'
}
))
// processing output files in gulp style
.pipe(GulpClient.dest('output', {
cwd: __dirname,
encoding: false
}));
};
task1.description = 'Copy utf-8 and binary files';
GulpClient.task(task1);
API
Please, read the API reference.