Create node server to replace 'make watch'
Reviewers: xymostech Reviewed By: xymostech Differential Revision: http://phabricator.benalpert.com/D38
This commit is contained in:
parent
afb29f5df3
commit
4bc599966f
|
@ -1,4 +1,4 @@
|
|||
var parser = require("./parser");
|
||||
var parser = require("./parser.jison");
|
||||
|
||||
var buildExpression = function(expression) {
|
||||
return _.map(expression, function(ex, i) {
|
||||
|
|
6
Makefile
6
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
|
||||
|
|
31
jisonify.js
Normal file
31
jisonify.js
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
29
server.js
Normal file
29
server.js
Normal file
|
@ -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/ ...");
|
|
@ -3,7 +3,7 @@
|
|||
<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="MJLite.js" type="text/javascript"></script>
|
||||
<script src="main.js" type="text/javascript"></script>
|
||||
<link href="style.css" rel="stylesheet" type="text/css">
|
||||
</head>
|
Loading…
Reference in New Issue
Block a user