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

v1.1.0

Published

A wrapper that presents a set of Gulp tasks as an API using Express.

Downloads

74

Readme

gulp-endpoint

Sometimes we want to pipe files from a web server into Gulp.

And sometimes we want to pipe files out of Gulp into a web server.

But sometimes we just want Gulp to actually be a web server.

Overview

Look at this:

gulp.task('abc', function() {

});

gulp.task('xyz', function() {

});

Doesn't that look a little bit like an API?

I spent a lot of time looking at Sails, Hapi, LoopBack and more, and they're all really great. But I also realised that since I was putting a lot of energy into turning my apps into streams -- static site generators, email pipelines with Handlebars templates, transformation pipelines extracting text from PDFs and finding dates -- then why not use streams in my APIs too?

Many of these pipelines would work just as well in an API, so I decided to give it a go and have one set of Gulp tasks for doing things like my template transformation work, and then use those tasks to send email, to run in Express, and even to generate static files to upload to S3.

This module is the first cut of this, but I know its's going to grow.

Usage

To use simply install gulp-endpoint:

npm install --save markbirbeck/gulp-endpoint

and then run endpoint from the command-line:

endpoint

This will load your gulpfile, set up a route for each task, and then launch an Express server on the default port (3000).

Options

Port (default is 3000)

To select another port to listen on, either define the PORT environment variable:

PORT=3005 endpoint

or use the --port command line option:

endpoint --port 3005

Behaviour

Any request that hits a URL with the same name as the Gulp task will cause the corresponding task to be run. The gulp.src and gulp.dest functions are patched so that data provided with a POST to the task will become a source file, and any data pushed to dest() at the end will be returned to the API caller.

Example

For example, say we have the following simple gulpfile:

var gulp = require('gulp');
var concat = require('gulp-concat');
var swig = require('gulp-swig');
var frontMatter = require('gulp-front-matter');

gulp.task('concat', function() {
  return gulp.src(['hello.txt', 'world.txt'])
    .pipe(concat('result.txt', {newLine: ' '}))
    .pipe(gulp.dest('output'));
});

gulp.task('compile-page', function() {
  return gulp.src('page.html')
    .pipe(frontMatter({property: 'data'}))
    .pipe(swig())
    .pipe(gulp.dest('build'));
});

gulp.task('default', ['compile-page']);

Running endpoint from the same directory as this file will result in a server with three endpoints being created:

http://localhost:3000/
http://localhost:3000/compile-page
http://localhost:3000/concat

The first two both refer to the compile-page task, since any task called 'default' is connected to the root.

Now, if a GET request is made to any of these URLs then the corresponding task is run with the usual gulp.src function in place, which means processing of any values set in the gulpfile will take place. (In this case the files hello.txt, world.txt and page.html will be used in the pipeline.) The results of these tasks will then be returned in the HTTP response.

However, if a POST request is made to these same endpoints then the document that is posted as part of the request is fed in to the pipeline, and the files specified as input in the gulpfile are ignored.