A gulp plugin for removing files and folders safely as part of build workflows.
npx @tessl/cli install tessl/npm-gulp-clean@0.4.0A Gulp plugin for removing files and folders safely as part of build workflows. It provides a stream-based API that integrates with Gulp's file pipeline, allowing developers to clean directories and files before or after build processes.
Note: This package has been deprecated in favor of the official Gulp recipe for deleting files and folders.
npm install --save-dev gulp-cleanconst clean = require('gulp-clean');const gulp = require('gulp');
const clean = require('gulp-clean');
// Basic file cleaning
gulp.task('clean', function () {
return gulp.src('dist/*', { read: false })
.pipe(clean());
});
// Clean with force option (allows deletion outside CWD)
gulp.task('clean-all', function () {
return gulp.src('../temp/*', { read: false })
.pipe(clean({ force: true }));
});gulp-clean is built around Gulp's streaming architecture:
Creates a Transform stream for deleting files and folders from the filesystem.
/**
* Creates a Transform stream for deleting files and folders
* @param {Object} [options] - Configuration options
* @param {boolean} [options.force=false] - Allow deletion of files outside current working directory
* @returns {Object} - Transform stream for use in Gulp pipelines
*/
function clean(options)Parameters:
options (optional): Configuration object
force (boolean): When true, allows deletion of files outside the current working directory and the current working directory itself. Default: falseReturns:
Object: A Node.js Transform stream (through2 object stream) that processes Vinyl file objectsBehavior:
path.relative() to determine if files are outside CWDforce: true)force: true)Usage Examples:
const gulp = require('gulp');
const clean = require('gulp-clean');
// Clean build directory
gulp.task('clean:build', function () {
return gulp.src('build/**/*', { read: false })
.pipe(clean());
});
// Clean with logging
gulp.task('clean:temp', function () {
return gulp.src('temp/**/*', { read: false })
.pipe(clean())
.on('error', function(err) {
console.error('Clean failed:', err.message);
});
});
// Force clean files outside CWD (dangerous - use with caution)
gulp.task('clean:external', function () {
return gulp.src('../external-temp/*', { read: false })
.pipe(clean({ force: true }));
});
// Clean as part of build pipeline
gulp.task('build', gulp.series('clean:build', function() {
return gulp.src('src/**/*')
.pipe(/* other build steps */)
.pipe(gulp.dest('build/'));
}));The plugin emits error events in the following situations:
force: trueforce: trueAll errors are emitted as PluginError instances with descriptive messages:
// Exact error messages from source code:
// "Cannot delete current working directory. (" + filepath + "). Use option force."
// "Cannot delete files outside the current working directory. (" + filepath + "). Use option force."
// "Unable to delete \"" + filepath + "\" file (" + error.message + ")."src() and dest() methods{ read: false } option in gulp.src() for better performance when only deleting filesThe plugin includes a utilities module that re-exports common dependencies for internal use.
/**
* Utility exports for internal plugin operations
*/
const utils = {
PluginError: require('plugin-error'),
log: require('fancy-log'),
File: require('vinyl')
}Note: The utils module is primarily for internal use and is not part of the main public API.
The plugin relies on the following key dependencies: