diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-12-13 02:07:04 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-12-14 02:14:23 +0100 |
commit | a96c52b21e7e590bbdd70b80896780a446fa2e8b (patch) | |
tree | 663619baa254577bb2f5342192e80bca692ad91d /subprojects/language-web/build.gradle | |
parent | build: move modules into subproject directory (diff) | |
download | refinery-a96c52b21e7e590bbdd70b80896780a446fa2e8b.tar.gz refinery-a96c52b21e7e590bbdd70b80896780a446fa2e8b.tar.zst refinery-a96c52b21e7e590bbdd70b80896780a446fa2e8b.zip |
build: separate module for frontend
This allows us to simplify the webpack configuration and the gradle
build scripts.
Diffstat (limited to 'subprojects/language-web/build.gradle')
-rw-r--r-- | subprojects/language-web/build.gradle | 115 |
1 files changed, 18 insertions, 97 deletions
diff --git a/subprojects/language-web/build.gradle b/subprojects/language-web/build.gradle index a549288a..6be4d5e8 100644 --- a/subprojects/language-web/build.gradle +++ b/subprojects/language-web/build.gradle | |||
@@ -1,10 +1,14 @@ | |||
1 | plugins { | 1 | plugins { |
2 | id 'refinery-frontend-workspace' | ||
3 | id 'refinery-java-application' | 2 | id 'refinery-java-application' |
4 | id 'refinery-xtext-conventions' | 3 | id 'refinery-xtext-conventions' |
5 | } | 4 | } |
6 | 5 | ||
7 | import org.siouan.frontendgradleplugin.infrastructure.gradle.RunYarn | 6 | configurations { |
7 | webapp { | ||
8 | canBeConsumed = false | ||
9 | canBeResolved = true | ||
10 | } | ||
11 | } | ||
8 | 12 | ||
9 | dependencies { | 13 | dependencies { |
10 | implementation project(':refinery-language') | 14 | implementation project(':refinery-language') |
@@ -16,6 +20,7 @@ dependencies { | |||
16 | implementation libs.jetty.websocket.server | 20 | implementation libs.jetty.websocket.server |
17 | implementation libs.slf4j.simple | 21 | implementation libs.slf4j.simple |
18 | implementation libs.slf4j.log4j | 22 | implementation libs.slf4j.log4j |
23 | webapp project(path: ':refinery-frontend', configuration: 'productionAssets') | ||
19 | testImplementation testFixtures(project(':refinery-language')) | 24 | testImplementation testFixtures(project(':refinery-language')) |
20 | testImplementation libs.jetty.websocket.client | 25 | testImplementation libs.jetty.websocket.client |
21 | } | 26 | } |
@@ -28,120 +33,36 @@ for (taskName in ['compileJava', 'processResources']) { | |||
28 | } | 33 | } |
29 | } | 34 | } |
30 | 35 | ||
31 | def webpackOutputDir = "${buildDir}/webpack" | 36 | mainClassName = 'tools.refinery.language.web.ServerLauncher' |
32 | def productionResources = "${webpackOutputDir}/production" | ||
33 | def serverMainClass = 'tools.refinery.language.web.ServerLauncher' | ||
34 | |||
35 | frontend { | ||
36 | assembleScript = 'assemble:webpack' | ||
37 | } | ||
38 | |||
39 | def installFrontend = tasks.named('installFrontend') | ||
40 | |||
41 | def generateLezerGrammar = tasks.register('generateLezerGrammar', RunYarn) { | ||
42 | dependsOn installFrontend | ||
43 | inputs.file('src/main/js/language/problem.grammar') | ||
44 | inputs.files('package.json', 'yarn.lock') | ||
45 | outputs.file "${buildDir}/generated/sources/lezer/problem.ts" | ||
46 | outputs.file "${buildDir}/generated/sources/lezer/problem.terms.ts" | ||
47 | script = 'run assemble:lezer' | ||
48 | } | ||
49 | |||
50 | def assembleFrontend = tasks.named('assembleFrontend') | ||
51 | assembleFrontend.configure { | ||
52 | dependsOn generateLezerGrammar | ||
53 | inputs.dir 'src/main/css' | ||
54 | inputs.dir 'src/main/html' | ||
55 | inputs.dir 'src/main/js' | ||
56 | inputs.file "${buildDir}/generated/sources/lezer/problem.ts" | ||
57 | inputs.file "${buildDir}/generated/sources/lezer/problem.terms.ts" | ||
58 | inputs.files('package.json', 'yarn.lock', 'webpack.config.js') | ||
59 | outputs.dir productionResources | ||
60 | } | ||
61 | |||
62 | def eslint = tasks.register('eslint', RunYarn) { | ||
63 | dependsOn installFrontend | ||
64 | inputs.dir 'src/main/js' | ||
65 | inputs.files('.eslintrc.js', 'tsconfig.json') | ||
66 | if (project.hasProperty('ci')) { | ||
67 | outputs.file "${buildDir}/eslint.json" | ||
68 | script = 'run check:eslint:ci' | ||
69 | } else { | ||
70 | script = 'run check:eslint' | ||
71 | } | ||
72 | group = 'verification' | ||
73 | description = 'Check for TypeScript errors.' | ||
74 | } | ||
75 | |||
76 | def stylelint = tasks.register('stylelint', RunYarn) { | ||
77 | dependsOn installFrontend | ||
78 | inputs.dir 'src/main/css' | ||
79 | inputs.file '.stylelintrc.js' | ||
80 | if (project.hasProperty('ci')) { | ||
81 | outputs.file "${buildDir}/stylelint.json" | ||
82 | script = 'run check:stylelint:ci' | ||
83 | } else { | ||
84 | script = 'run check:stylelint' | ||
85 | } | ||
86 | group = 'verification' | ||
87 | description = 'Check for Sass errors.' | ||
88 | } | ||
89 | |||
90 | tasks.named('check') { | ||
91 | dependsOn(eslint, stylelint) | ||
92 | } | ||
93 | |||
94 | mainClassName = serverMainClass | ||
95 | 37 | ||
96 | tasks.named('jar') { | 38 | tasks.named('jar') { |
97 | dependsOn assembleFrontend | 39 | dependsOn project.configurations.webapp |
98 | from(productionResources) { | 40 | from(project.configurations.webapp) { |
99 | into 'webapp' | 41 | into 'webapp' |
100 | } | 42 | } |
101 | } | 43 | } |
102 | 44 | ||
103 | tasks.named('shadowJar') { | 45 | tasks.named('shadowJar') { |
104 | dependsOn assembleFrontend | 46 | dependsOn project.configurations.webapp |
105 | from(project.convention.getPlugin(JavaPluginConvention).sourceSets.main.output) | 47 | from(project.sourceSets.main.output) |
106 | configurations = [project.configurations.runtimeClasspath] | 48 | configurations = [project.configurations.runtimeClasspath] |
107 | exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA','schema/*', | 49 | exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA','schema/*', |
108 | '.options', '.api_description', '*.profile', 'about.*', 'about_*.html', 'about_files/*', | 50 | '.options', '.api_description', '*.profile', 'about.*', 'about_*.html', 'about_files/*', |
109 | 'plugin.xml', 'systembundle.properties', 'profile.list', 'META-INF/resources/xtext/**') | 51 | 'plugin.xml', 'systembundle.properties', 'profile.list', 'META-INF/resources/xtext/**') |
110 | append('plugin.properties') | 52 | append('plugin.properties') |
111 | from(productionResources) { | 53 | from(project.configurations.webapp) { |
112 | into 'webapp' | 54 | into 'webapp' |
113 | } | 55 | } |
114 | } | 56 | } |
115 | 57 | ||
116 | def jettyRun = tasks.register('jettyRun', JavaExec) { | 58 | def jettyRun = tasks.register('jettyRun', JavaExec) { |
117 | dependsOn assembleFrontend | 59 | dependsOn project.configurations.webapp |
118 | dependsOn sourceSets.main.runtimeClasspath | 60 | dependsOn sourceSets.main.runtimeClasspath |
119 | classpath = sourceSets.main.runtimeClasspath.filter{it.exists()} | 61 | classpath = sourceSets.main.runtimeClasspath |
120 | mainClass = serverMainClass | 62 | mainClass = mainClassName |
121 | standardInput = System.in | 63 | standardInput = System.in |
122 | environment BASE_RESOURCE: productionResources | 64 | def baseResource = project.configurations.webapp.incoming.artifacts.artifactFiles.first() |
65 | environment BASE_RESOURCE: baseResource | ||
123 | group = 'run' | 66 | group = 'run' |
124 | description = 'Start a Jetty web server serving the Xtex API and assets.' | 67 | description = 'Start a Jetty web server serving the Xtex API and assets.' |
125 | } | 68 | } |
126 | |||
127 | tasks.register('webpackServe', RunYarn) { | ||
128 | dependsOn installFrontend | ||
129 | dependsOn generateLezerGrammar | ||
130 | outputs.dir "${webpackOutputDir}/development" | ||
131 | script = 'run serve' | ||
132 | group = 'run' | ||
133 | description = 'Start a Webpack dev server with hot module replacement.' | ||
134 | } | ||
135 | |||
136 | sonarqube.properties { | ||
137 | properties['sonar.sources'] += [ | ||
138 | 'src/main/css', | ||
139 | 'src/main/html', | ||
140 | 'src/main/js', | ||
141 | ] | ||
142 | property 'sonar.nodejs.executable', "${frontend.nodeInstallDirectory.get()}/bin/node" | ||
143 | property 'sonar.eslint.reportPaths', "${buildDir}/eslint.json" | ||
144 | property 'sonar.css.stylelint.reportPaths', "${buildDir}/stylelint.json" | ||
145 | // SonarJS does not pick up typescript files with `exactOptionalPropertyTypes` | ||
146 | property 'sonar.typescript.tsconfigPath', 'tsconfig.sonar.json' | ||
147 | } | ||