streamur

A very capable asset manager. And a few more things.

StreamUR

A very capable asset manager for node. But also a lot more.

$ npm install streamur

It is intuitive to use streamur as a powerful asset manager, easily allowing to minify and gzip resources.

Example:

var streamur = require('streamur');
 
//register a few streams: 
streamur.stream("jquery", "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js");
streamur.stream("myscript", __dirname+"/public/js/myscript.js");
 
app.use('/assets/', streamur());

You can then request:

  • /assets/jquery.myscript.js, which will be the combination of both files
  • /assets/jquery.myscript.min.js, same as above but the files are minified.
  • /assets/jquery.myscript.min.gzip.js, same as above, but the minified files are gziped.

StreamUR revolves around two core concepts: streams ('jquery' and 'myscript') that are user defined and processors ('.', 'min', 'gzip' and 'js') that are provided.

That's great for managing your assets but there is more StreamUR can do for you. For instance the jslint processors runs the JSLINT tool on the javscript code and presents the results:

/assets/myscript.jslint.json

Makes it easy for you to check how well your code is doing!

But JSON is not very nice to read. To get a nicer view of the results, you can use the prettyjslint processor that returns HTML:

/assets/myscript.prettyjslint.html

There are other useful processors that can be used, see the full list below.

Register streams by calling the streamur.stream(name, locator) method.

name is descriptor used for that stream and can only contain [a-z0-9].

locator is the path at which this stream can be found. It may be an absolute file path or a URL.

Example:

streamur.stream("jquery", "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js");
streamur.stream("myscript", __dirname+"/public/js/myscript.js");

There are a number of processors that apply to different types of streams, and more are in development, stay tuned!

The concatination processor for streams. It groups streams together and chains them to the next processor.

Minifies javascript code using uglifyjs.

Gzips files and sets the proper header on the response. Uses gzip.

Runs JSLINT on the stream and returns the result as raw JSON.

Runs JSLINT on the stream and formats the results in HTML format.

Highlights Javascript code in the stream using highlight. Returns HTML

Sets No-cache headers on the response, telling the client that the resource should not be cached.

Sets the response's content type as HTML.

Sets the response's content type as Javascript.

Sets the response's content type as JSON.

Sets the response's content type as CSS.

Aliases are useful to shorten the names of ressources (such as when many streams are concatinated together). To create an alias, use streamur.alias(name, alias).

Example:

streamur.alias('scripts', 'jquery.underscore.backbone.myscript1.myscrip2');

You can then request scripts.min.js which would yield an identical result as jquery.underscore.backbone.myscript1.myscrip2.min.js.

StreamUR caches the result of each script access. This is important especially as some processors are CPU intensive and take a long time to complete (e.g. min). If you use StreamUR in production, it is recommended that each resource is accessed at least once after server startup to populate the cache.

Source code is licenced under The MIT License.

This project was initially developped for the Summer Blast-off Hackathon, Saturday, June 23, 2012.

git-summary:

project  : streamUR
repo age : 10 days ago
active   : 6 days
commits  : 166
files    : 25
authors  : 
   84   Julien Dreux            50.6%
   37   Thomas Getgood          22.3%
   32   Stephen R. Hamilton     19.3%
   12   ben-zen                 7.2%
    1   jdreux                  0.6%