Skip to content

Commit

Permalink
Add server for development
Browse files Browse the repository at this point in the history
  • Loading branch information
bfirsh committed Jul 4, 2018
1 parent 6d25cd3 commit 3b32e95
Show file tree
Hide file tree
Showing 7 changed files with 2,926 additions and 73 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@

# integration test output
tests/__image_snapshots__/__diff_output__

# parcel
.cache
dist
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ For full usage, run `docker run arxivvanity/engrafo engrafo --help`.

## Development environment

In development, you can build an image locally and use a shortcut script to run the image:
In development, you can build an image locally and use a script to run the image:

$ script/build
$ script/engrafo -o output/ input/main.tex
$ script/engrafo -o output/ tests/documents/sample2e.tex

You can also run a server that allows you to view papers from Arxiv in a browser. Start it by running:
You can also run a server for developing CSS. It renders a file then runs a server that will automatically reload the CSS when you change it. Start it by running:

$ script/server
$ script/server tests/documents/sample2e.tex

And it will be available at [http://localhost:8010/](http://localhost:8010/).
And it will be available at [http://localhost:8000/](http://localhost:8000/).

## Tests

Expand Down
18 changes: 18 additions & 0 deletions bin/engrafo-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node

var server = require("../src/converter/server");
var path = require("path");
var fs = require("fs");
var program = require("commander");

program
.version("0.0.1")
.usage("[options] <tex file>")
.parse(process.argv);

if (program.args.length != 1) {
program.outputHelp();
process.exit(1);
}

server.start(program.args[0]);
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"aws-sdk": "^2.127.0",
"distill-template": "git+https://github.com/arxiv-vanity/template.git#engrafo",
"express": "^4.16.3",
"fs-extra": "^6.0.1",
"linkify-urls": "^2.0.0",
"mathjax-node-page": "^2.0.0",
Expand All @@ -22,7 +23,10 @@
"jest": "^23.2.0",
"jest-image-snapshot": "^2.4.3",
"jest-puppeteer": "^3.2.1",
"node-sass": "^4.9.0",
"parcel-bundler": "^1.8.1",
"prettier": "^1.13.7",
"puppeteer": "^1.5.0"
"puppeteer": "^1.5.0",
"tmp": "^0.0.33"
}
}
8 changes: 5 additions & 3 deletions script/server
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ exec docker run \
--init \
-v "$ENGRAFO_DIR:/app" \
-w /app \
-p 8010:8010 \
-w /app/server/ \
-p 8000:8000 \
-p 8001:8001 \
--rm \
-it \
--entrypoint node \
engrafo \
python server.py
bin/engrafo-server "$@"
18 changes: 18 additions & 0 deletions src/converter/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const Bundler = require("parcel-bundler");
const app = require("express")();
const render = require("./index").render;
const path = require("path");
const tmp = require("tmp-promise");

module.exports.start = async input => {
const tmpDir = await tmp.dir();
const htmlPath = await render({
input: input,
output: tmpDir.path
});

console.log("💅 Starting server at http://localhost:8000");
const bundler = new Bundler(htmlPath, { hmrPort: 8001 });
app.use(bundler.middleware());
app.listen(8000);
};
Loading

0 comments on commit 3b32e95

Please sign in to comment.