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

devour

v1.6.0

Published

Wrapper for gulp projects to provide a lot of syntactic sugar and re-use

Downloads

20

Readme

npm version

Devour

Wrapper for gulp projects to provide a lot of syntactic sugar and re-use

Install

npm install --save-dev devour

Concept

Devour provides a thin wrapper for gulp, enabling the use of tasks and pipes defined in separate files. All of the files will be loaded when devour is activated, then you specify which tasks should be build and whether or not to watch for changes.

Usage

As devour is designed to incorporate gulp, you simply include it in your (existing) gulpfile.js, it will not get in the way of your current tasks (as long as there are no task-name collisions, of course).

Starting

Devour installs two cli commands; devour and gulp. Both of these will start Devour (although the gulp command will inform you it was devoured). As with gulp itself, you can specify which tasks to run by providing them on the command line, for example:

devour myTask myOtherTask mySpecialTask

Will try to start (in order) myTask, myOtherTask, mySpecialTask. Whichever ones are found to be actual tasks are executed, feedback is provided on which tasks are running and which were not found. The provided tasks will only run once, and once all are done, Devour will exit. NOTE: when running specific tasks, the verbosity is set to false in order to reduce the output.

gulpfile.js

As devour is based on the concept of moving tasks into separate files, you (should) end up with a very clean gulpfile.js.

Without devour

Considering this example based on a normal (rather simple) gulpfile.js

var gulp = require('gulp'),
	concat = require('gulp-concat'),
	uglify = require('gulp-uglify'),
	minifycss = require('gulp-minify-css'),
	rename = require('gulp-rename');

gulp.task('combine_script', function() {
	gulp.src('./src/**/*.js')
		.pipe(concat())
		.pipe(rename(function(file) {
			file.basename = 'combine';
		}))
		.pipe(gulp.dest('./dist'))
		.pipe(uglify())
		.pipe(rename(function(file) {
			file.basename += '.min';
		}))
		.pipe(gulp.dest('./dist'))
	;
});

gulp.task('combine_style', function() {
	gulp.src('./src/**/*.css')
		.pipe(concat())
		.pipe(rename(function(file) {
			file.basename = 'combine';
		}))
		.pipe(gulp.dest('./dist'))
		.pipe(minifycss())
		.pipe(rename(function(file) {
			file.basename += '.min';
		}))
		.pipe(gulp.dest('./dist'))
	;
});

gulp.task('watch', function() {
	gulp.watch('./src/**/*.js', ['combine_script']);
	gulp.watch('./src/**/*.css', ['combine_style']);
});

gulp.task('default', ['combine_script', 'combine_style', 'watch']);

With devour

Now, let's move those parts around into a bunch of separate files

First, create a named "pipe", which is basically a plugin within your project

// file: gulp/pipe/combine.js
//  concatenate the input stream into a single file and name it combine.<extension>
//  this works the same for both javascript and stylesheets
module.exports = function(stream, devour) {
	return stream
		.pipe(devour.plugin('concat'))
		.pipe(devour.plugin('rename', function(file) {
			file.basename = 'combine';
		}))
		//  write the minified sources to the predefined destination
		.pipe(devour.write())
	;
};

Now create the tasks, one for javascripts (gulp/task/script.js) and one for stylesheets (gulp/task/style.js).

// file: gulp/task/script.js
//  concatenate scripts into a single file and uglify it
module.exports = function(stream, devour) {
	return stream
		//  call the named pipe 'combine'
		.pipe(devour.pipe('combine'))
		//  add some gulp plugins to do their magic
		.pipe(devour.plugin('uglify'))
		.pipe(devour.plugin('rename', devour.min))
		//  finally, write the minified sources to the predefined destination
		.pipe(devour.write())
	;
};

The task for stylesheets is similar, except it does not uglify but uses minify-css

// file: gulp/task/script.js
//  concatenate stylesheets into a single file and minify it
module.exports = function(stream, devour) {
	return stream
		//  call the named pipe 'combine'
		.pipe(devour.pipe('combine'))
		//  add some gulp plugins to do their magic
		.pipe(devour.plugin('minify-css'))
		.pipe(devour.plugin('rename', devour.min))
		//  finally, write the minified sources to the predefined destination
		.pipe(devour.write())
	;
};

So, ready for the grande finale? Ok, here comes the gulpfile:

//  file: gulpfile.js
var Devour = require('devour'),
	devour = new Devour(); //  using all the default settings by not providing any of our own

devour
	.task('script', ['./src/**/*.js'])
	.task('style', ['./src/**/*.css'])
	.start()
;

Your project structure now looks somewhat like this:

/gulp
  /pipe
     combine.js
  /task
     script.js
     style.js
 gulpfile.js

What did we just do exactly? We have moved everything into separate files, these files all have a single job, be it a task or a re-usable pipe. You may also have noticed that there are no requires for the gulp-<plugins>, this is because devour will take care of loading any plugin for you. You still needs to add plugins to your project yourself!.

Further reading

License

GPLv2 © Konfirm Open