Skip to content

Commit

Permalink
Fix commandline invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuswestin committed Apr 30, 2012
1 parent 07eccd2 commit c3147c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 1 addition & 2 deletions bin/fun
Expand Up @@ -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',
Expand Down
13 changes: 10 additions & 3 deletions src/dev-server.js
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit c3147c0

Please sign in to comment.