Package Exports
- gulp-not-supported-file
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gulp-not-supported-file) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
gulp-not-supported-file
Not a Gulp plugin,
but for Gulp plugin developers.
Check the file before process it in your Gulp plugin
What is this and why it was created?
Most of Gulp plugins for compiling/rendering static files use through2 for processing. And first step of each code is a testing file
- it is not null
- it is not stream
- it is not ...
And after this checkouts we may work with file.
Little example
function myGulpPLugin(options) {
// process options if need
// ...
// processing
return through2.obj(function(file, enc, cb) {
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
if (!file.contents.length) {
return cb(null, file);
}
// and other if and if
// ...
// and then work with it
});
}I'm tired of writing the same code every time.
So I wrote it once and wrapped it in a tiny module.
How it works
Call this module with your file and with your plugin error handler. Module will return result:
falseif the file is suitable for workArrayif the file failed the test. Array will contain arguments forthrough2callback.
Usage example
const gutil = require('gulp-util');
const through2 = require('through2');
const notSupportedFile = require('gulp-not-supported-file');
// for check data type
const _isArray = require('lodash.isarray');
// my awesome plugin name
const pluginName = 'my-gulp-plugin';
// ---------------------------
// core plugin method
function myGulpPlugin(options) {
// process options if need
// ...
// private method plugin error
function pluginError (data, options) {
return new gutil.PluginError(pluginName, data, options);
}
// processing
return through2.obj(function (file, enc, cb) {
let notSupported = notSupportedFile(file, pluginError);
if (_isArray(notSupported)) {
// name of failed test
// - 'isDirectory' -> will be error
// - 'isNull' -> will be error
// - 'isStream' -> will be error
// - 'isEmpty' -> skip file
// - 'isUndercore' -> skip file
let failStatus = notSupported.shift();
// es6 spread
return cb(...notSupported);
// or es5 apply
return cb.apply(null, notSupported);
}
// work with file if passed
// ...
});
}
module.exports = myGulpPlugin;
Module also has few options
Options are passed by the third argument and must an object
let notSupported = notSupportedFile(file, pluginError, options);noEmpty
type boolean /
default true
File with empty content will be skipped
return 'isEmpty' on fail
noUnderscore
type boolean /
default true
File starting with _ will be skipped
return 'isUnderscore' on fail
silent
type boolean /
default false
No console logs if set true
Changelog
read CHANGELOG.md
Tests
Sorry but here no tests yet