Skip to content

Commit 1dc70fd

Browse files
committed
build: process JavaScript components with Babel.
As "frontend" plugin gets activated before executing any goals, this leads to a non obvious outcome that "mvn clean <some goal>" command doesn't regenerate JS-files. It happens because "frontent" plugin doesn't get activated as the target/classes/js/components directory exists in the begginning and hasn't been removed yet. As a workaround you might use: - mvn -Pfrontend clean <some goal> - mvn clean; mvn <some goal> Addressed to #1060 and (a little bit to) #1057
1 parent b65cc49 commit 1dc70fd

File tree

7 files changed

+32
-6
lines changed

7 files changed

+32
-6
lines changed

Dangerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ if File.file?(validator_output)
405405
print_errors_summary 'html5validator', errors_count
406406
end
407407

408+
# @todo #1060 Danger: handle Babel errors from frontend-maven-plugin
409+
408410
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:compile` output
409411
# Handle `mvn org.apache.maven.plugins:maven-compiler-plugin:testCompile` output
410412
# Handle `mvn org.codehaus.gmavenplus:gmavenplus-plugin:testCompile` output
@@ -696,8 +698,9 @@ if github.branch_for_head !~ /^gh[0-9]+_/
696698
end
697699

698700
js_file = %r{^src/main/javascript/.*\.js$}
701+
component_file = %r{^src/main/frontend/src/.*\.js$}
699702
css_file = %r{^src/main/webapp/.*\.css$}
700-
modified_resources = git.modified_files.any? { |file| file =~ js_file || file =~ css_file }
703+
modified_resources = git.modified_files.any? { |file| file =~ js_file || file =~ component_file || file =~ css_file }
701704
updated_url = git.modified_files.include? 'src/main/java/ru/mystamps/web/feature/site/ResourceUrl.java'
702705
if modified_resources && !updated_url
703706
warn("danger check: looks like you forgot to update `ResourceUrl.RESOURCES_VERSION` after modifying JS/CSS file(s)")

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ If you are programmer/sysadmin or you just feeling that you are able to run a lo
3636

3737
* *At the heart of*: Spring Framework (and especially Spring Boot)
3838
* *Template engine*: Thymeleaf
39-
* *UI*: HTML, Bootstrap and a bit of JavaScript with JQuery
39+
* *UI*: HTML, Bootstrap and JavaScript (React, JQuery)
4040
* *Security*: Spring Security
4141
* *Databases*: H2, MySQL or PostgreSQL
4242
* *Database access*: Spring's `JdbcTemplate`

pom.xml

+17
Original file line numberDiff line numberDiff line change
@@ -1223,8 +1223,15 @@
12231223
</profile>
12241224
<profile>
12251225
<id>frontend</id>
1226+
<activation>
1227+
<file>
1228+
<!-- Should be in sync with Babel configuration from src/main/frontend/package.json -->
1229+
<missing>target/classes/js/components</missing>
1230+
</file>
1231+
</activation>
12261232
<build>
12271233
<plugins>
1234+
<!-- @todo #1060 Document usage of frontend-maven-plugin -->
12281235
<!--
12291236
We assume that most of the time we develop backend rather frontend.
12301237
So, we cache and skip the frontend-related things by default. This
@@ -1257,6 +1264,16 @@
12571264
<arguments>ci</arguments>
12581265
</configuration>
12591266
</execution>
1267+
<execution>
1268+
<id>npm-run-build</id>
1269+
<goals>
1270+
<goal>npm</goal>
1271+
</goals>
1272+
<phase>generate-resources</phase>
1273+
<configuration>
1274+
<arguments>run build</arguments>
1275+
</configuration>
1276+
</execution>
12601277
</executions>
12611278
</plugin>
12621279
</plugins>

src/main/frontend/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"babel-preset-react": "^6.24.1"
1111
},
1212
"scripts": {
13-
"test": "echo \"Error: no test specified\" && exit 1"
13+
"build": "babel src --out-dir ../../../target/classes/js",
14+
"watch": "babel src --out-dir ../../../target/classes/js --watch"
1415
},
1516
"repository": {
1617
"type": "git",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//
2+
// IMPORTANT:
3+
// You must update ResourceUrl.RESOURCES_VERSION each time whenever you're modified this file!
4+
//
5+

src/main/scripts/ci/check-build-and-verify.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
200200
print_status "$ENFORCER_STATUS" 'Run maven-enforcer-plugin'
201201

202202
if [ "$TEST_STATUS" != 'skip' ]; then
203-
mvn --batch-mode test -Denforcer.skip=true -Dmaven.resources.skip=true -DskipMinify=true -DdisableXmlReport=false \
203+
mvn --batch-mode test -Denforcer.skip=true -Dmaven.resources.skip=true -DskipMinify=true -DdisableXmlReport=false -Dskip.npm -Dskip.installnodenpm \
204204
>test.log 2>&1 || TEST_STATUS=fail
205205
fi
206206
print_status "$TEST_STATUS" 'Run unit tests'
@@ -220,7 +220,7 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
220220
print_status "$SPOTBUGS_STATUS" 'Run SpotBugs'
221221
fi
222222

223-
mvn --batch-mode verify -Denforcer.skip=true -DskipUnitTests=true \
223+
mvn --batch-mode --activate-profiles frontend verify -Denforcer.skip=true -DskipUnitTests=true \
224224
>verify-raw.log 2>&1 || VERIFY_STATUS=fail
225225
# Workaround for #538
226226
"$(dirname "$0")/filter-out-htmlunit-messages.pl" <verify-raw.log >verify.log

src/main/scripts/ci/publish-code-coverage.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set -o pipefail
1515

1616
JACOCO_FAIL=
1717

18-
mvn --batch-mode jacoco:prepare-agent test jacoco:report -Denforcer.skip=true -DskipMinify=true >jacoco.log 2>&1 || JACOCO_FAIL=yes
18+
mvn --batch-mode jacoco:prepare-agent test jacoco:report -Denforcer.skip=true -DskipMinify=true -Dskip.npm -Dskip.installnodenpm >jacoco.log 2>&1 || JACOCO_FAIL=yes
1919

2020
# -Z Exit with 1 if not successful. Default will Exit with 0
2121
bash <(curl -s https://codecov.io/bash) -Z >>jacoco.log 2>&1 || JACOCO_FAIL=yes

0 commit comments

Comments
 (0)