metaserve
compile & serve metalanguage assets
Last updated 6 months ago by spro .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install metaserve 
SYNC missed versions from official npm registry.

metaserve

metaserve makes web application prototyping quicker by compiling and serving assets built with meta-languages[1] such as CoffeeScript, Jade, and Styl (currently the full list).

Use as a command or as middleware to handle requests for e.g. js/myapp.js by run-time-compiling the js/myapp.coffee source file into Javascript. Similar to (but less contrived than) the Rails Asset Pipeline.

Metaserve is based on a collection of plugins, which by default support Jade (to HTML), CoffeeScript (to Javascript), and Sass (to CSS) to support the Prontotype stack. New languages are easily added with a simple plugin architecture.

As a command

Install with npm install -g metaserve

Use within a directory that has a bunch of .jade, .sass and .coffee. Run metaserve with optional arguments --host and --port. Defaults to 0.0.0.0:8000.

As middleware

Install with npm install metaserve

Use by supplying a base directory, then hooking it in as Express/Connect middleware...

var express = require('express');
var metaserve = require('metaserve');

app = express();
app.use(metaserve('./app'));
app.listen(8550);

... or as a fallback method in a standard http server:

var http = require('http');
var metaserve = require('metaserve')('./app');

var server = http.createServer(function(req, res) {
    if (req.url === '/dogs') {
        return res.end('woof');
    } else {
        return metaserve(req, res);
    }
});

server.listen(8550);

Writing Plugins

A plugin is simply a Javascript module with a few fields:

  • ext
    • The extension that this plugin will match, e.g. "coffee"
  • default_config (optional)
    • Default config which will be extended and passed in as the config argument to the compiler function
  • compiler(filename, config, context, cb)
    • A function that should transform some source file and call back with an object {content_type, compiled}

Here's a simple plugin that reads and reverses a text file:

var fs = require('fs');

module.exports = {
    ext: 'txt',

    compile: function(filename, config, context, cb) {
        fs.readFile(filename, function(err, source) {
            if (err)
                return cb(err);
            else {
                source = source.toString();
                reversed = source.split('').reverse().join('')
                cb(null, {
                    content_type: 'text/plain',
                    compiled: reversed
                });
            }
        });
    }
};

By passing an object of compilers to the metaserve middleware, paths that match the extension key (here "txt") will be run through this plugin:

app.use(metaserve('./app', {
    txt: require('./reverse-plugin')
}));

Default Plugins


Notes

  1. Not to be confused with the real definition of a Metalanguage.

Current Tags

  • 0.8.5                                ...           latest (6 months ago)

44 Versions

  • 0.8.5                                ...           6 months ago
  • 0.8.4                                ...           2 years ago
  • 0.8.3                                ...           2 years ago
  • 0.8.1                                ...           2 years ago
  • 0.8.0                                ...           2 years ago
  • 0.7.3                                ...           2 years ago
  • 0.7.2                                ...           2 years ago
  • 0.7.1                                ...           3 years ago
  • 0.7.0                                ...           3 years ago
  • 0.6.0                                ...           3 years ago
  • 0.5.6                                ...           3 years ago
  • 0.5.5                                ...           3 years ago
  • 0.5.4                                ...           3 years ago
  • 0.5.3                                ...           3 years ago
  • 0.5.2                                ...           3 years ago
  • 0.4.7                                ...           3 years ago
  • 0.4.6                                ...           3 years ago
  • 0.4.5                                ...           4 years ago
  • 0.4.4                                ...           4 years ago
  • 0.4.3                                ...           4 years ago
  • 0.4.2                                ...           4 years ago
  • 0.4.1                                ...           4 years ago
  • 0.4.0                                ...           4 years ago
  • 0.3.7                                ...           5 years ago
  • 0.3.6                                ...           5 years ago
  • 0.3.5                                ...           5 years ago
  • 0.3.4                                ...           5 years ago
  • 0.3.3                                ...           5 years ago
  • 0.3.2                                ...           5 years ago
  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.2                                ...           6 years ago
  • 0.2.1                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.10                                ...           6 years ago
  • 0.1.9                                ...           6 years ago
  • 0.1.7                                ...           6 years ago
  • 0.1.6                                ...           6 years ago
  • 0.1.5                                ...           6 years ago
  • 0.1.4                                ...           6 years ago
  • 0.1.3                                ...           6 years ago
  • 0.1.2                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (5)
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |