Skip to content

Commit

Permalink
Integrated puppeteer based rendering into build
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Mar 31, 2020
1 parent ea299d7 commit f9b74d8
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,5 @@ target
.ipynb_checkpoints
.ropeproject
__pycache__
node
node_modules
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions package.json
@@ -0,0 +1,21 @@
{
"name": "faust-gen",
"version": "1.0.0",
"description": "The Faust-Edition web application builds on data that is automatically pre-generated from the original XML files. This project integrates the various generation and upload processes (except for the images, actually).",
"main": "rendersvgs-puppeteer.js",
"dependencies": {
"puppeteer": "^2.1.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/faustedition/faust-gen.git"
},
"bugs": {
"url": "https://github.com/faustedition/faust-gen/issues"
},
"homepage": "https://github.com/faustedition/faust-gen#readme"
}
28 changes: 25 additions & 3 deletions pom.xml
Expand Up @@ -226,7 +226,7 @@
</activation>
<build>
<plugins>

<!-- PhantomJS or SlimerJS?
Uncomment either of the plugins below:
Expand All @@ -240,6 +240,24 @@
see the comment there.
-->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.9.1</version>
<configuration>
<nodeVersion>v12.16.1</nodeVersion>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals><goal>install-node-and-npm</goal></goals>
</execution>
<execution>
<id>npm install</id>
<goals><goal>npm</goal></goals>
</execution>
</executions>
</plugin>

<!-- <plugin>
<groupId>com.github.klieber</groupId>
Expand All @@ -255,7 +273,7 @@
</executions>
</plugin>
-->
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -286,6 +304,7 @@
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
</profile>
Expand Down Expand Up @@ -320,7 +339,10 @@
<!-- For PhantomJS: -->
<!-- <argument>-Dphantomjs.binary=${phantomjs.binary}</argument> -->
<!-- For SlimerJS instead: -->
<argument>-Dphantomjs.binary=${project.build.directory}/dependency/slimerjs-1.0.0-beta.1/slimerjs</argument>
<!--argument>-Dphantomjs.binary=${project.build.directory}/dependency/slimerjs-1.0.0-beta.1/slimerjs</argument-->
<!-- or for puppeteer: -->
<argument>-Dnode.binary=${project.basedir}/node/node</argument>
<argument>-Dnode.script=${project.basedir}/rendersvgs-puppeteer.js</argument>
<argument>-Dfaust.diplo.allowedFailures=${faust.diplo.allowedFailures}</argument>
<argument>-Dfaust.diplo.server=${faust.diplo.server}</argument>
<argument>-Dfaust.diplo.port=${faust.diplo.port}</argument>
Expand Down
50 changes: 29 additions & 21 deletions src/main/java/net/faustedition/gen/DiplomaticConversion.java
Expand Up @@ -72,8 +72,6 @@ public class DiplomaticConversion {

private static boolean onlyWebServer;

private static ImmutableList<String> baseCmdLine;

public static class TranscriptPage {
public final Document document;
private final String page;
Expand Down Expand Up @@ -133,17 +131,11 @@ public boolean buildSVGs() {
logger.fine("Converting " + this);
final Path resolvedSvgPath = diplomatic_path.resolve(getPagePath("svg"));
resolvedSvgPath.getParent().toFile().mkdirs();
final ArrayList<String> arguments = Lists.newArrayList(
System.getProperty("phantomjs.binary", "/usr/local/bin/phantomjs"),
"rendersvgs.js",
serverURL,
getJsonPath().toString(),
resolvedSvgPath.toString());
if (debugPhantomJS)
arguments.add(1, "--debug=errors");
if (arguments.get(0).contains("slimerjs"))
arguments.add(1, "--headless");

final ArrayList<String> arguments = getRenderCommandLine();

arguments.add(getJsonPath().toString());
arguments.add(resolvedSvgPath.toString());

final Optional<Path> imageLinkPath = getImageLinkPath();
if (imageLinkPath.isPresent()) {
arguments.add(imageLinkPath.get().toString());
Expand Down Expand Up @@ -183,7 +175,28 @@ private Path getJsonPath() {

}

public static class Document {
private static ArrayList<String> getRenderCommandLine() {
String renderScript = System.getProperty("node.script");
final String renderBinary;
if (renderScript == null) {
renderBinary = System.getProperty("phantomjs.binary", "/usr/local/bin/phantomjs");
renderScript = "rendersvgs.js";
} else {
renderBinary = System.getProperty("node.binary", "node");
}

final ArrayList<String> arguments = Lists.newArrayList(
renderBinary,
renderScript,
serverURL);
if (debugPhantomJS)
arguments.add(1, "--debug=errors");
if (arguments.get(0).contains("slimerjs"))
arguments.add(1, "--headless");
return arguments;
}

public static class Document {

private final Path path;
/** The base faust:// uri for the transcripts of this document */
Expand Down Expand Up @@ -231,13 +244,8 @@ public static void main(final String[] args) throws IOException {
try {
serverURL = new URL("http", "localhost", webServer.getListeningPort(), "/transcript-generation.html").toString();
logger.info(MessageFormat.format("Web server runs on {0}", serverURL));
baseCmdLine = ImmutableList.of(
System.getProperty("phantomjs.binary", "/usr/local/bin/phantomjs"),
"--profile", profile.toString(),
debugPhantomJS? "--debug=true" : "",
"rendersvgs.js",
serverURL);
logger.info(() -> "PhantomJS command line: " + String.join(" ", baseCmdLine) + " <input> <output> [<links> <linkoutput>]");
List<String> baseCmdLine = getRenderCommandLine();
logger.info(() -> "Render script command line: " + String.join(" ", baseCmdLine) + " <input> <output> [<links> <linkoutput>]");


if (onlyWebServer) {
Expand Down

0 comments on commit f9b74d8

Please sign in to comment.