npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-not-supported-file

v1.2.5

Published

Check the file before process it in your Gulp plugin

Downloads

501

Readme

gulp-not-supported-file

npm es2015 license Build Status

Not a Gulp plugin,
but for Gulp plugin developers.
Check the file before process it in your Gulp plugin

js-happiness-style

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

const through2 = require('through2');
const PluginError = require('plugin-error');
const PLUGIN_NAME = 'my-plugin';

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 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:

  • false if the file is suitable for work
  • Array if the file failed the test. Array will contain arguments. First of them is text status name of fail and next arguments for through2 callback.

Status list

  • 'isDirectory' - will be error
  • 'isNull' - will be error
  • 'isStream' - will be error
  • 'isEmpty' - skip file
  • 'isUnderscore' - skip file

Usage example

const through2 = require('through2');
const PluginError = require('plugin-error');
const PLUGIN_NAME = 'my-plugin';

const notSupportedFile = require('gulp-not-supported-file');

// ---------------------------
	
// private method plugin error
function pluginError (data, errorOptions) {
	return new PluginError(PLUGIN_NAME, data, errorOptions);
}

// core plugin method
function myGulpPlugin(options) {
	// process options if need
	// ...
	
	// processing
	return through2.obj(function (file, enc, cb) {
		let notSupported = notSupportedFile(file, pluginError);
		
		if (Array.isArray(notSupported)) {
			notSupported.shift();       // or with saving -> let failStatus = notSupported.shift();
			return cb(...notSupported); // or es5 apply -> 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 be an object

let notSupported = notSupportedFile(file, pluginError, options);

noUnderscore

type boolean / default true

File with empty content will be skipped and not using in stream next.

You will receive message in console if it happens
Example of log:

no-empty log example

noEmpty

type boolean / default true

File with empty content will be skipped and not using in stream next.
Return ['isEmpty']
Note! Spaces, tabs and newlines will be treated as empty content.

You will receive message in console if it happens_stream next.
Example of log:

no-empty log example

silent

type boolean / default false

No logs about noEmpty and noUnderscore files


Installing

npm install --save gulp-not-supported-file
# or using yarn cli
yarn add gulp-not-supported-file

Tests

  1. npm test for testing code style and run mocha tests
  2. npm run happiness-fix for automatically fix most of problems with code style

Changelog

Please read CHANGELOG.md

Contributing

Please read CONTRIBUTING.md