diff --git a/bin/fun b/bin/fun index aaf7ac8..5cd893c 100755 --- a/bin/fun +++ b/bin/fun @@ -12,8 +12,7 @@ var commandline = optimist.usage('Usage: fun [compile] path/to/app.fun [--port=8 argv = commandline.argv, line = argv._, compile = line[0] == 'compile', - filenameRaw = (compile ? line[1] : line[0]), - filename = filenameRaw && filenameRaw[0] == '/' ? filenameRaw : path.join(process.cwd(), filenameRaw) + filename = (compile ? line[1] : line[0]) var opts = { 'minify': argv['minify'] == 'true', diff --git a/src/dev-server.js b/src/dev-server.js index 0e982dc..5260788 100644 --- a/src/dev-server.js +++ b/src/dev-server.js @@ -4,7 +4,8 @@ var socketIo = require('socket.io'), curry = require('std/curry'), fs = require('fs'), path = require('path'), - time = require('std/time') + time = require('std/time'), + http = require('http') module.exports = { compileFile: compileFile, @@ -15,12 +16,14 @@ module.exports = { } function compileFile(filename, opts, callback) { - loadCompiler().compileFile(filename, opts, callback) + loadCompiler().compileFile(_resolveFilename(filename), opts, callback) } -function listen(port, filename, opts) { +function listen(port, filenameRaw, opts) { if (!port) { port = 8080 } + var filename = _resolveFilename(filenameRaw) + try { var stat = fs.statSync(filename) } catch(e) { @@ -51,6 +54,10 @@ function listen(port, filename, opts) { console.log('Fun!'.magenta, 'Serving', filenameRaw.green, 'on', ('localhost:'+port).cyan, 'with these options:\n', opts) } +function _resolveFilename(filename) { + return filename[0] == '/' ? filename : path.join(process.cwd(), filename) +} + function serveDevClient(req, res) { fs.readFile(path.join(__dirname, './dev-client.html'), curry(respond, res)) }