Skip to content

Commit

Permalink
Transpiling Java to JavaScript with JSweet
Browse files Browse the repository at this point in the history
  • Loading branch information
ekuiter committed Oct 31, 2018
1 parent fa81e57 commit 2f98965
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 19 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ build process.

- `./gradlew build` builds a WAR file that can be deployed on Java servlet
containers, the `variED.sh` script runs the WAR file in Apache Tomcat
- `./gradlew client:build` and `./gradlew server:build` build only the client or
server
- `yarn start` inside the `client` directory runs the client on
`http://localhost:3000`
- `./gradlew server:run` runs the server on `http://localhost:8080`
Expand Down
18 changes: 13 additions & 5 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"name": "variED",
"description": "The variability editor",
"repository": "https://github.com/ekuiter/variED",
"keywords": ["variability", "feature modeling", "collaboration"]
}
"name": "variED",
"description": "The variability editor",
"repository": "https://github.com/ekuiter/variED",
"keywords": ["variability", "feature modeling", "collaboration"],
"buildpacks": [
{
"url": "heroku/nodejs"
},
{
"url": "heroku/gradle"
}
]
}
17 changes: 11 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
task build {
dependsOn ':clean', ':client:build', ':server:build'
dependsOn ':clean'
dependsOn ':client:clean'
dependsOn ':server:clean'
dependsOn ':client:build'
dependsOn ':server:build'
doLast() {
copy {
from 'server/build/libs'
Expand All @@ -8,14 +12,15 @@ task build {
}
}

tasks.getByPath(':client:clean').mustRunAfter ':clean'
tasks.getByPath(':server:clean').mustRunAfter ':client:clean'
tasks.getByPath(':client:build').mustRunAfter ':server:clean'
tasks.getByPath(':server:build').mustRunAfter ':client:build'

task stage(dependsOn: 'build')

task clean {
doLast {
delete 'build'
}
}

tasks.getByPath(':client:build').mustRunAfter ':clean'
tasks.getByPath(':server:build').mustRunAfter ':clean'
tasks.getByPath(':server:build').mustRunAfter ':client:build'
}
3 changes: 2 additions & 1 deletion client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
.env*.local
/coverage
/coverage
/src/common/*
5 changes: 3 additions & 2 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ node {
}

yarn.mustRunAfter 'clean'
yarn_build.mustRunAfter 'yarn'
tasks.getByPath(':server:transpileCommon').mustRunAfter ':client:yarn'
yarn_build.mustRunAfter ':server:transpileCommon'

task build {
dependsOn 'clean', 'yarn', 'yarn_build'
dependsOn 'clean', ':server:transpileCommon', 'yarn', 'yarn_build'
doLast {
copy {
from 'build'
Expand Down
5 changes: 4 additions & 1 deletion client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import reducer from './store/reducer';
import {initializeIcons} from 'office-ui-fabric-react/lib/Icons';
import actions from './store/actions';
import {LogLevel, setLogLevel} from './helpers/logger';
import {Test} from './common/Test';

if (window.location.protocol !== 'http:')
window.location.protocol = 'http:'; // TODO: hack until we support WSS
Expand All @@ -34,4 +35,6 @@ ReactDOM.render((
</Provider>
), document.getElementById('root'));

store.dispatch<any>(actions.server.join({artifactPath: {project: 'FeatureModeling', artifact: 'CTV'}}));
store.dispatch<any>(actions.server.join({artifactPath: {project: 'FeatureModeling', artifact: 'CTV'}}));

Test.doSomething();
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description": "This file forces Heroku to install Node.js for use in the build process.",
"engines": {
"node": "8.11.4"
}
}
3 changes: 2 additions & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
*.iml
/.git_private
/src/main/webapp/*
!/src/main/webapp/WEB-INF
!/src/main/webapp/WEB-INF
/.jsweet
37 changes: 36 additions & 1 deletion server/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
buildscript {
repositories {
maven { url "http://repository.jsweet.org/artifactory/libs-snapshot-local" }
maven { url "http://repository.jsweet.org/artifactory/plugins-snapshot-local" }
}
dependencies {
classpath('org.jsweet:jsweet-gradle-plugin:2.2.0-SNAPSHOT') { transitive = true }
}
}

plugins {
id 'war'
id 'idea'
id 'org.gretty' version '2.2.0'
}

apply plugin: 'org.jsweet.jsweet-gradle-plugin'

configurations {
copyOnly
}

repositories {
jcenter()
maven { url "http://repository.jsweet.org/artifactory/libs-snapshot-local" }
}

dependencies {
Expand All @@ -18,6 +31,7 @@ dependencies {
copyOnly 'org.apache.tomcat.embed:tomcat-embed-websocket:9.0.8'
compile 'com.google.code.gson:gson:2.8.5'
compile 'me.atrox.haikunator:Haikunator:1.3'
compile 'org.jsweet:jsweet-core:6-SNAPSHOT'
compile fileTree(dir: 'lib', include: '*.jar')
}

Expand All @@ -32,6 +46,16 @@ idea {
}
}

jsweet {
includes = ['de/ovgu/spldev/varied/common/**/*.java']
outDir = file('../client/src/common')
tsOut = file('.jsweet/ts')
workingDir = file('.jsweet')
declaration = true
noRootDirectories = true
module = 'es2015'
}

task copyWebappRunner {
doLast {
copy {
Expand All @@ -50,4 +74,15 @@ task copyWebappRunner {

build.mustRunAfter ':client:build'
build.dependsOn 'war', 'copyWebappRunner'
task run(dependsOn: 'appRun')
task run(dependsOn: 'appRun')

// As of now, this has to be run MANUALLY if any common classes changed.
task transpileCommon(dependsOn: 'jsweet')

task cleanCommon {
doLast {
delete fileTree(dir: '../client/src/common')
}
}

clean.dependsOn 'cleanCommon'
7 changes: 7 additions & 0 deletions server/src/main/java/de/ovgu/spldev/varied/common/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.ovgu.spldev.varied.common;

public class Test {
public static void doSomething() {
System.out.println("Test!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@jsweet.lang.Root
package de.ovgu.spldev.varied.common;

0 comments on commit 2f98965

Please sign in to comment.