www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 4bc599966f138f81bff56ca93ed79b11761a3536
parent afb29f5df3046fa523b3bdd3f9a3936b855f05be
Author: Ben Alpert <spicyjalapeno@gmail.com>
Date:   Fri,  5 Jul 2013 22:55:10 -0700

Create node server to replace 'make watch'

Reviewers: xymostech

Reviewed By: xymostech

Differential Revision: http://phabricator.benalpert.com/D38

Diffstat:
MMJLite.js | 2+-
MMakefile | 6+++---
Dbuild/.gitkeep | 0
Dindex.html | 14--------------
Ajisonify.js | 31+++++++++++++++++++++++++++++++
Mpackage.json | 6+++++-
Aserver.js | 29+++++++++++++++++++++++++++++
Astatic/index.html | 14++++++++++++++
Rmain.js -> static/main.js | 0
Rstyle.css -> static/style.css | 0
10 files changed, 83 insertions(+), 19 deletions(-)

diff --git a/MJLite.js b/MJLite.js @@ -1,4 +1,4 @@ -var parser = require("./parser"); +var parser = require("./parser.jison"); var buildExpression = function(expression) { return _.map(expression, function(ex, i) { diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ FILES=parser.js style.css build.js index.html -.PHONY: build ship copy watch +.PHONY: build ship copy server build: parser.js ship: build @@ -14,5 +14,5 @@ copy: build parser.js: parser.jison ./node_modules/.bin/jison parser.jison -watch: - ./node_modules/.bin/watchify MJLite.js --standalone MJLite -o build/MJLite.js +server: + node server.js diff --git a/build/.gitkeep b/build/.gitkeep diff --git a/index.html b/index.html @@ -1,14 +0,0 @@ -<!doctype html> -<html> - <head> - <title>MJLite Test</title> - <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js" type="text/javascript"></script> - <script src="build/MJLite.js" type="text/javascript"></script> - <script src="main.js" type="text/javascript"></script> - <link href="style.css" rel="stylesheet" type="text/css"> - </head> - <body> - <input type="text" value="2x^2 + 3" id="input" /> - <div id="math"></div> - </body> -</html> diff --git a/jisonify.js b/jisonify.js @@ -0,0 +1,31 @@ +var ebnfParser = require("ebnf-parser"); +var jison = require("jison"); +var through = require("through"); + +module.exports = function(file) { + if (!(/\.jison$/).test(file)) { + return through(); + } + + var data = ''; + return through(write, end); + + function write(buf) { + data += buf; + } + + function end() { + try { + var grammar = ebnfParser.parse(data); + var parser = new jison.Parser(grammar); + var js = parser.generate({moduleType: "js"}); + js += "\nmodule.exports = parser;"; + + this.queue(js); + this.queue(null); + } catch (e) { + // TODO(alpert): Does this do anything? (Is it useful?) + this.emit("error", e); + } + } +}; diff --git a/package.json b/package.json @@ -2,7 +2,11 @@ "name": "mjlite", "version": "0.0.1", "devDependencies": { + "browserify": "~2.23.1", + "ebnf-parser": "~0.1.5", + "express": "~3.3.3", + "lex-parser": "~0.1.2", "jison": "~0.4.6", - "watchify": "~0.1.0" + "through": "~2.3.4" } } diff --git a/server.js b/server.js @@ -0,0 +1,29 @@ +var path = require("path"); + +var browserify = require("browserify"); +var express = require("express"); + +var jisonify = require("./jisonify"); + +var app = express(); + +app.use(express.logger()); + +app.get("/MJLite.js", function(req, res) { + var b = browserify(); + b.add("./MJLite"); + b.transform(jisonify); + + var stream = b.bundle({standalone: "MJLite"}); + var body = ""; + stream.on("data", function(s) { body += s; }); + stream.on("end", function() { + res.setHeader("Content-Type", "text/javascript"); + res.send(body); + }); +}); + +app.use(express.static(path.join(__dirname, 'static'))); + +app.listen(7936); +console.log("Serving on http://0.0.0.0:7936/ ..."); diff --git a/static/index.html b/static/index.html @@ -0,0 +1,14 @@ +<!doctype html> +<html> + <head> + <title>MJLite Test</title> + <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js" type="text/javascript"></script> + <script src="MJLite.js" type="text/javascript"></script> + <script src="main.js" type="text/javascript"></script> + <link href="style.css" rel="stylesheet" type="text/css"> + </head> + <body> + <input type="text" value="2x^2 + 3" id="input" /> + <div id="math"></div> + </body> +</html> diff --git a/main.js b/static/main.js diff --git a/style.css b/static/style.css