Permalink
Browse files

Support for coffeescript

  • Loading branch information...
1 parent 67f9bd7 commit 333e69dcac6a06935c4ac4d8381a15e56047d431 @ryanwilliams committed Sep 10, 2012
Showing with 32 additions and 7 deletions.
  1. +10 −5 lib/jah/commands/server.js
  2. +22 −2 lib/jah/server.js
View
@@ -12,8 +12,8 @@ var options = [
description: 'URL to serve the JavaScript as. Default is output defined in the config file',
value: true },
- { short: 'c',
- long: 'config',
+ { short: 'j',
+ long: 'jah-config',
description: 'Project configuration file. Default is jah.json',
value: true },
@@ -25,16 +25,21 @@ var options = [
{ short: 'p',
long: 'port',
description: 'Port to listen on. Default is 4000',
- value: true }
+ value: true },
+
+ { short: 'c',
+ long: 'coffee',
+ description: 'Compile src with coffeescript automatically',
+ value: false }
];
exports.description = 'Run the Jah development web server';
exports.run = function () {
opts.parse(options, true);
var host = opts.get('host') || '127.0.0.1',
port = opts.get('port') || 4000,
- config = opts.get('config') || 'jah.json',
+ config = opts.get('jah-config') || 'jah.json',
server = new Server(config)
- server.start(host, port)
+ server.start(host, port, opts.get('coffee'))
};
View
@@ -7,16 +7,36 @@ var sys = require('util'),
fs = require('fs'),
mimetypes = require('./mimetypes'),
Template = require('./template').Template,
- Compiler = require('./compiler').Compiler;
+ Compiler = require('./compiler').Compiler,
+ child_process = require('child_process');
function Server (config) {
this.compiler = new Compiler(config)
}
-Server.prototype.start = function (host, port) {
+Server.prototype.watchForCoffeeScript = function (src, dest) {
+ src = src || this.compiler.config.sourcePath
+ dest = dest || 'build/js'
+ this.compiler.config.sourcePath = dest
+
+ var coffee = child_process.spawn('coffee', ['-w', '-c', '-o', dest, src])
+ coffee.stderr.on('data', function (data) {
+ process.stderr.write(data.toString())
+ })
+ coffee.stdout.on('data', function (data) {
+ sys.print(data.toString())
+ })
+}
+
+
+Server.prototype.start = function (host, port, coffeescript) {
host = host || '127.0.0.1'
port = port || 4000
+ if (coffeescript) {
+ this.watchForCoffeeScript();
+ }
+
http.createServer(function (req, res) {
var uri = url.parse(req.url, true)
logger.group('Request', uri.pathname)

0 comments on commit 333e69d

Please sign in to comment.