A very capable asset manager. And a few more things.
StreamUR is a stream manipulation platform built on node.
Streams can be conventional file/audio/video but also higher level streams such as twitter feeds.
StreamUR provides filters to convert streams to different types, to combine several streams into one.
$ npm install streamur
streamur.stream method to create new streams that map to your resources.
var streamur = require'streamur';//register a few streams:streamurstream"jquery" "";streamurstream"myscript" __dirname+"/public/js/myscript.js";//Use as a connect/express middlewareappuse'/assets/' streamur;
You can then fetch the following 'files':
StreamUR revolves around two core concepts: streams ('jquery' and 'myscript') that are user defined and processors ('.', 'min', 'gzip' and 'js') that are provided.
That is 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:
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:
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 that descriptor used for that stream and must be alphanumeric.
locator is the path at which this stream can be found. It may be an absolute file path or a URL.
streamurstream"jquery" "";streamurstream"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. It groups streams together and chains them to the next processor.
Gzips the stream 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.
Minifies css code using clean-css.
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 JSON.
Sets the response's content type as CSS.
Aliases are useful to shorten the names of resources (such as when many streams are concatenated together).
There are three different ways to create an alias:
streamur.alias(name, expression). Example:
You can then request
scripts.gzip.js which would yield an identical result as
streamur.alias(name, function). Example:
streamuralias'scripts'aliasstream"jquery" __dirname+"/public/js/jquery-1.7.2.js";aliasstream"myscript" __dirname+"/public/js/myscript.js";;
scripts would be identical to
jquery.myscript, and the
jquery streams are also created.
streamur.aliasDirectory(name, path), where
path is the name of the folder containing all the files to be created as streams and made part of the alias. Example:
In this case, all files in the directory will be made streams. The name of each stream will be the file name, only keeping alphanumeric characters. In some rare cases, this may result in stream name collision.
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.
StreamUR will invalidate the cache if it detects that any of the underlying streams have been modified. This is useful during development, so that the server does not need to be restarted after each update.
Warning: Cache invalidation relies on Node's
fs.watch method which is currently not available on all platforms.
Source code is licenced under The MIT License.
This project was initially developped for the Summer Blast-off Hackathon, Saturday, June 23, 2012.
project : streamUR repo age : 13 days ago active : 9 days commits : 188 files : 26 authors : 106 Julien Dreux 56.4% 37 Thomas Getgood 19.7% 32 Stephen R. Hamilton 17.0% 12 ben-zen 6.4% 1 jdreux 0.5%