Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

(Iced)Coffeescript, nib, index and backend support #11

Open
wants to merge 4 commits into from

1 participant

@QaDeS

You can use (Iced)Coffeescript for JS files now, and nib inside your stylus templates.
You can specify and index page - serve will do an internal rewrite to serve it.
You can specify a script to hook into the server for providing a backend, exporting a run(server) function. This can also be an (Iced)Coffeescript.

@btmills btmills referenced this pull request
Open

CoffeeScript #15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 3, 2012
  1. @QaDeS

    added nib support

    QaDeS authored
  2. @QaDeS

    coffeescript support

    QaDeS authored
Commits on Oct 7, 2012
  1. @QaDeS
  2. @QaDeS

    index and backend documentation

    QaDeS authored
This page is out of date. Refresh to see the latest.
Showing with 58 additions and 14 deletions.
  1. +15 −11 Readme.md
  2. +40 −2 bin/serve
  3. +3 −1 package.json
View
26 Readme.md
@@ -15,16 +15,20 @@ Usage: serve [options] [dir]
Options:
- -v, --version output the version number
- -F, --format <fmt> specify the log format string
- -p, --port <port> specify the port [3000]
- -H, --hidden enable hidden file serving
- -S, --no-stylus disable stylus rendering
- -J, --no-jade disable jade rendering
- -I, --no-icons disable icons
- -L, --no-logs disable request logging
- -D, --no-dirs disable directory serving
- -h, --help output usage information
+ -v, --version output the version number
+ -F, --format <fmt> specify the log format string
+ -i, --index <url> specify the start page
+ -b, --backend <path> specify a backend script exporting a run(server) function
+ -p, --port <port> specify the port [3000]
+ -H, --hidden enable hidden file serving
+ -S, --no-stylus disable stylus rendering
+ -N, --no-nib disable nib rendering
+ -J, --no-jade disable jade rendering
+ -C, --no-coffee disable (Iced)CoffeeScript rendering
+ -I, --no-icons disable icons
+ -L, --no-logs disable request logging
+ -D, --no-dirs disable directory serving
+ -h, --help output usage information
```
@@ -78,4 +82,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
42 bin/serve
@@ -9,7 +9,9 @@ var resolve = require('path').resolve
, program = require('commander')
, connect = require('connect')
, stylus = require('stylus')
+ , nib = require('nib')
, jade = require('jade')
+ , iced = require('iced-coffee-script')
, url = require('url')
, fs = require('fs');
@@ -19,10 +21,14 @@ program
.version('1.1.0')
.usage('[options] [dir]')
.option('-F, --format <fmt>', 'specify the log format string', 'dev')
+ .option('-i, --index <url>', 'specify the start page')
+ .option('-b, --backend <path>', 'specify a backend script exporting a run(server) function')
.option('-p, --port <port>', 'specify the port [3000]', Number, 3000)
.option('-H, --hidden', 'enable hidden file serving')
.option('-S, --no-stylus', 'disable stylus rendering')
+ .option('-N, --no-nib', 'disable nib rendering')
.option('-J, --no-jade', 'disable jade rendering')
+ .option('-C, --no-coffee', 'disable (Iced)CoffeeScript rendering')
.option('-I, --no-icons', 'disable icons')
.option('-L, --no-logs', 'disable request logging')
.option('-D, --no-dirs', 'disable directory serving')
@@ -41,6 +47,19 @@ server.use(connect.favicon(program.favicon));
// logger
if (program.logs) server.use(connect.logger(program.format));
+if (program.backend) {
+ require(path + '/' + program.backend).run(server);
+}
+
+if (program.index) {
+ server.use(function(req, res, next){
+ if (req.url === '/') {
+ req.url = program.index;
+ }
+ return next();
+ });
+}
+
// convert .styl to .css to trick stylus.middleware
if (program.stylus) {
server.use(function(req, res, next){
@@ -67,10 +86,29 @@ if (program.jade) {
}
});
});
+
+ if (program.nib) {
+ // stylus nib rendering enabled
+ function compile(str, path) {
+ return stylus(str)
+ .set('filename', path)
+ .use(nib());
+ }
+ server.use(stylus.middleware({ src: path, compile: compile }));
+ } else {
+ server.use(stylus.middleware({ src: path }));
+ }
}
-// stylus
-server.use(stylus.middleware({ src: path }));
+// coffeescript
+if (program.coffee) {
+ server.use(function(req, res, next){
+ if (!req.url.match(/\.coffee|\.iced$/)) return next();
+ var file = join(path, url.parse(req.url).pathname);
+ res.setHeader('Content-Type', 'application/x-javascript');
+ res.end(iced.compile(fs.readFileSync(file).toString()));
+ });
+}
// static files
server.use(connect.static(path, { hidden: program.hidden }));
View
4 package.json
@@ -1,13 +1,15 @@
{
"name": "serve"
- , "version": "1.1.0"
+ , "version": "1.1.1"
, "description": "Simple command-line file / directory server built with connect"
, "keywords": ["static", "server", "connect"]
, "author": "TJ Holowaychuk <tj@vision-media.ca>"
, "dependencies": {
"connect": "2.3.x"
, "stylus": "*"
+ , "nib": "*"
, "jade": "*"
+ , "iced-coffee-script": "*"
, "commander": "0.6.1"
}
, "bin": { "serve": "./bin/serve" }
Something went wrong with that request. Please try again.