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

v0.2.0

Published

Implicitly categorize your gulp tasks by their name.

Downloads

18

Readme

gulp-categorizer

Implicitly categorize your gulp tasks by their name.

Consider the following gulpfile.js:

const gulp = require('gulp');

gulp.task('js:foo', function() { /* ... */ });
gulp.task('js:bar', function() { /* ... */ });

gulp.task('js', [ 'js:foo', 'js:bar' ]);

gulp.task('default', [ 'js' ]);

Normally in gulp, you'd have to explicitly create a gulp task 'js' that depends on 'js:foo' and 'js:bar', as you have seen above in line 6. This quickly becomes tedious as your gulpfiles grow. You might create a new task 'js:baz', but forget to add it to the dependencies of 'js', leading to frustrating minutes of debugging and trying to figure out why 'js:baz' is not being run.

gulp-categorizer automatically organizes your gulp tasks into categories based on their name, and creates "implicit" gulp tasks for any categories not defined explicitly. So in the above example, gulp-categorizer will automatically create the 'js' gulp task for you, and sets its dependencies to 'js:foo' and 'js:bar'.

This is how the above code would look like when using gulp-categorizer:

const gulp = require('gulp'),
	gulpCat = require('gulp-categorizer')(gulp);

// For convenience, overwrite gulp.task with gulp-categorizer's wrapper function at the beginning of your gulpfile:
gulp.task = gulpCat.task;

// The main part of your gulpfile remains exactly the same:
gulp.task('js:foo', function() { /* ... */ });
gulp.task('js:bar', function() { /* ... */ });

// You can reference the 'js' target as you would normally:
gulp.task('default', [ 'js' ]);

// Add this line to the very end of your gulpfile:
gulpCat.makeCategoryTasks();

Now you can use the 'js' target as you would use any other target, for example by invoking gulp js.

See below for installation, usage details and configuration options.

Installation

Install using npm:

npm install --save-dev gulp-categorizer

Compatibility and dependencies

gulp-categorizer has no explicit dependencies, but the user has to pass its constructor a gulp object.

gulp-categorizer works with any gulp version compatible with version 3.9.1.

Usage

First, require the gulp-categorizer package and pass it the gulp object as well as any options (see below):

const gulpCat = require('gulp-categorizer')(gulp, options);

Now you can use gulpCat.task() as a drop-in replacement for gulp.task. You can, in fact, simply replace gulp.task with gulpCat.task:

gulp.task = gulpCat.task;

At the very end of your gulpfile, add the following line:

gulpCat.makeCategoryTasks();

This line will create the "implicit" gulp tasks for any categories for which you didn't define a task manually.

The "implicit" tasks that gulp-categorizer creates automatically can be used the same way as any other task, including in the command line, using gulp.run, or as a dependency.

You may also define any category tasks explicitly, after all of their dependencies have been defined:

const gulp = require('gulp'),
	gulpCat = require('gulp-categorizer')(gulp);

gulp.task = gulpCat.task;

gulp.task('js:foo', function() { /* ... */ });
gulp.task('js:bar', function() { /* ... */ });

// This task won't be automatically categorized as a 'js' task.
gulp.task('some-other-task', function() { /* ... */ });

// Define the 'js' task explicitly. gulp-categorizer will automatically add 'js:foo' and 'js:bar' to the array of dependencies, after 'some-other-task'.
gulp.task('js', [ 'some-other-task' ], function() { /* ... */ });

// Note that you cannot define any tasks that belong to the 'js' category after you've defined the task corresponding to that category.
// For example, this would throw an error:
//gulp.task('js:baz', function() { /* ... */ });

gulp.task('default', [ 'js' ]);

gulpCat.makeCategoryTasks();

Nested categories are also valid and work as you'd expect. For example:

gulp.task('js:server:foo', function() { /* ... */ });

gulp.task('js:client:bar', function() { /* ... */ });

Now you can use gulp js which will run both 'js:server:foo' and 'js:client:bar', or you can use gulp js:server which will run only 'js:server:foo'.

Options

You can pass an options object as the second argument of the gulp-categorizer constructor. All options are optional.

categorySeparator: String = ':'

The category separator to use. This is recommended to be a single character, but is allowed to be any string. Defaults to a colon (':').

License

MIT