Replace maven-frontend-plugin with sass-cli-maven-plugin

Use Maven wrapper around Dart SASS binary instead of downloading and installing NodeJS / NPM locally. This also eliminates dependency from Grunt and its modules.
This commit is contained in:
Florian Enner 2022-08-02 10:46:54 +02:00 committed by GitHub
parent 84c9a23fa9
commit a0a5f0ca85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 49 additions and 2634 deletions

@ -46,10 +46,6 @@ Application.setUserAgentStylesheet(new PrimerDark().getUserAgentStylesheet());
You can either use CLI or create run configuration in your favorite IDE. You can either use CLI or create run configuration in your favorite IDE.
```sh ```sh
# except building parent module, this will also install NodeJS along with NPM
# and all JS dependencies into root project directory, you don't need to install NodeJS system-wide
mvn --non-recursive install
# compile SASS into styles/dist directory, # compile SASS into styles/dist directory,
# you can stop here and use compiled CSS files in your app just like that # you can stop here and use compiled CSS files in your app just like that
mvn install -pl styles mvn install -pl styles
@ -65,25 +61,19 @@ After building module dependencies you can play with the sampler application. If
mvn javafx:run -pl sampler mvn javafx:run -pl sampler
``` ```
If you want to use hot reload (update CSS without restarting sampler) you have to start app in development mode. There's [ATLANTAFX_MODE](https://github.com/mkpaz/atlantafx/blob/master/sampler/src/main/java/atlantafx/sampler/Launcher.java#L45) variable for this. In that mode app won't use CSS from `base` module classpath, but from the `sampler/target/classes/atlantafx/sampler/theme-test` directory. Use `styles/compile-scss-dev.sh` to compile CSS files into that destination. If you want to use hot reload (update CSS without restarting sampler) you have to start app in development mode. There's [ATLANTAFX_MODE](https://github.com/mkpaz/atlantafx/blob/master/sampler/src/main/java/atlantafx/sampler/Launcher.java#L45) variable for this. In that mode app won't use CSS from `base` module classpath, but from the `sampler/target/classes/atlantafx/sampler/theme-test` directory. Use `-Pdev` to compile CSS files into that destination.
```sh ```sh
# compile CSS files first or there will be an exception # run sampler app in dev mode
cd styles mvn javafx:run -pl sampler -Pdev
./compile-scss-dev.sh
cd -
# then run sampler along with setting env variable # run hot reload sass
ATLANTAFX_MODE=dev mvn javafx:run -pl sampler mvn compile -pl styles -Pdev
``` ```
This may look a bit complicated, but at the end you just need to create 4 IDE run configurations and open VS Code instance in parallel in styles directory to edit and rebuild CSS files. Run `compile-scss-dev.sh` script each time to reflect made changes without restarting the application.
More details can be found in the source code: More details can be found in the source code:
* See [github worklow](https://github.com/mkpaz/atlantafx/blob/master/.github/workflows/tagged-release.yml) for install instructions. * See [github worklow](https://github.com/mkpaz/atlantafx/blob/master/.github/workflows/tagged-release.yml) for install instructions.
* See [Gruntfile.js](https://github.com/mkpaz/atlantafx/blob/master/styles/Gruntfile.js) to familiarize with CSS compilation.
## Motivation ## Motivation

@ -44,17 +44,6 @@
<filtering>false</filtering> <filtering>false</filtering>
</resource> </resource>
</resources> </resources>
<plugins>
<!-- not used, just prevents installing NodeJS to the module dir -->
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<configuration>
<installDirectory>${project.parent.basedir}</installDirectory>
</configuration>
</plugin>
</plugins>
</build> </build>
</project> </project>

2514
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,12 +0,0 @@
{
"name": "atlanta",
"version": "1.0.0",
"devDependencies": {
"grunt": "^1.4.1",
"grunt-cli": "^1.4.1",
"grunt-contrib-concat": "^2.0.0",
"grunt-contrib-cssmin": "^4.0.0",
"grunt-sass": "^3.1.0",
"sass": "^1.49.9"
}
}

35
pom.xml

@ -60,7 +60,6 @@
<java.version>17</java.version> <java.version>17</java.version>
<openjfx.version>17.0.0.1</openjfx.version> <openjfx.version>17.0.0.1</openjfx.version>
<nodejs.version>v16.14.2</nodejs.version>
<app.name>AtlantaFX</app.name> <app.name>AtlantaFX</app.name>
<!-- DO NOT use ${project.version} as jpackage will fail on <!-- DO NOT use ${project.version} as jpackage will fail on
@ -195,9 +194,9 @@
<version>3.0.0</version> <version>3.0.0</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>com.github.eirslett</groupId> <groupId>us.hebi.sass</groupId>
<artifactId>frontend-maven-plugin</artifactId> <artifactId>sass-cli-maven-plugin</artifactId>
<version>1.9.1</version> <version>1.0.1</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -262,34 +261,6 @@
</plugin> </plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<configuration>
<nodeVersion>${nodejs.version}</nodeVersion>
<workingDirectory>${project.basedir}</workingDirectory>
</configuration>
<executions>
<execution>
<id>install-node-and-npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>install-npm-packages</id>
<phase>generate-resources</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build> </build>
<profiles> <profiles>

@ -149,13 +149,6 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<configuration>
<installDirectory>${project.parent.basedir}</installDirectory>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> <artifactId>maven-dependency-plugin</artifactId>
@ -284,6 +277,22 @@
</build> </build>
<profiles> <profiles>
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<configuration>
<options>
<option>-Datlantafx.mode=dev</option>
</options>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile> <profile>
<id>linux-active</id> <id>linux-active</id>
<activation> <activation>

@ -1,29 +0,0 @@
module.exports = function (grunt) {
const SASS_COMPILER = require('sass');
const CSS_OUTPUT_DIR = process.env.NODE_ENV !== 'dev' ? 'dist' : '../sampler/target/classes/atlantafx/sampler/theme-test';
grunt.initConfig({
cssOutputDir: CSS_OUTPUT_DIR,
sass: {
options: {
implementation: SASS_COMPILER
},
dist: {
files: {
'<%= cssOutputDir %>/primer-light.css': [ 'src/primer-light.scss' ],
'<%= cssOutputDir %>/primer-dark.css': [ 'src/primer-dark.scss' ]
}
}
},
cssmin: {
dist: {
files: {}
}
}
});
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.registerTask('default', ['sass', 'cssmin']);
};

@ -1,6 +0,0 @@
#!/usr/bin/env sh
# This scipt compiles SCSS directly to the sampler classpath for hot reload (CSSFX).
PATH="../node:$(../node/npm bin):$PATH"
NODE_ENV=dev grunt --verbose --gruntfile=Gruntfile.js

@ -10,28 +10,35 @@
</parent> </parent>
<artifactId>atlantafx-styles</artifactId> <artifactId>atlantafx-styles</artifactId>
<properties>
<scss.inputDir>${project.basedir}/src</scss.inputDir>
<css.outputDir>${project.basedir}/dist</css.outputDir>
</properties>
<build> <build>
<plugins> <plugins>
<!-- compile SCSS --> <!-- compile SCSS -->
<plugin> <plugin>
<groupId>com.github.eirslett</groupId> <groupId>us.hebi.sass</groupId>
<artifactId>frontend-maven-plugin</artifactId> <artifactId>sass-cli-maven-plugin</artifactId>
<configuration> <configuration>
<installDirectory>${project.parent.basedir}</installDirectory> <args>
<arg>${scss.inputDir}/primer-light.scss:${css.outputDir}/primer-light.css</arg>
<arg>${scss.inputDir}/primer-dark.scss:${css.outputDir}/primer-dark.css</arg>
<arg>--no-source-map</arg>
</args>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<id>run-grunt</id> <id>run-sass</id>
<phase>generate-resources</phase> <phase>generate-resources</phase>
<goals> <goals>
<goal>grunt</goal> <goal>run</goal>
</goals> </goals>
<configuration>
<arguments>--verbose</arguments>
</configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- compress resulting CSS into archive for distribution --> <!-- compress resulting CSS into archive for distribution -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -67,4 +74,14 @@
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>dev</id>
<properties>
<css.outputDir>${project.basedir}/../sampler/target/classes/atlantafx/sampler/theme-test</css.outputDir>
<sass.watch>true</sass.watch>
</properties>
</profile>
</profiles>
</project> </project>