From 5d3aaed261ea1be118cb71d7cca252237cc8f6c0 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Wed, 25 May 2022 14:11:29 +0200 Subject: [PATCH] Fixes #21136: Minify js produced by elm - plugins --- api-authorizations/src/main/elm/build-app.sh | 25 --------- api-authorizations/src/main/elm/build.sh | 8 +++ .../ApiAccountsExtension.scala | 2 +- auth-backends/src/main/elm/build-app.sh | 24 --------- auth-backends/src/main/elm/build.sh | 7 +++ .../template/AuthBackendsManagement.html | 2 +- branding/src/main/elm/build-app.sh | 31 ----------- branding/src/main/elm/build-dev.sh | 2 +- branding/src/main/elm/build.sh | 7 +++ .../template/brandingManagement.html | 2 +- change-validation/src/main/elm/build-app.sh | 25 --------- change-validation/src/main/elm/build-dev.sh | 2 +- change-validation/src/main/elm/build.sh | 8 +++ .../template/ChangeValidationManagement.html | 4 +- plugins-common/elm.sh | 54 +++++++++++++++++++ plugins-common/pom-template.xml | 4 +- user-management/src/main/elm/build-app.sh | 23 -------- user-management/src/main/elm/build-dev.sh | 2 +- user-management/src/main/elm/build.sh | 7 +++ .../resources/template/UserManagement.html | 2 +- 20 files changed, 102 insertions(+), 139 deletions(-) delete mode 100755 api-authorizations/src/main/elm/build-app.sh create mode 100755 api-authorizations/src/main/elm/build.sh delete mode 100755 auth-backends/src/main/elm/build-app.sh create mode 100755 auth-backends/src/main/elm/build.sh delete mode 100755 branding/src/main/elm/build-app.sh create mode 100755 branding/src/main/elm/build.sh delete mode 100755 change-validation/src/main/elm/build-app.sh create mode 100755 change-validation/src/main/elm/build.sh create mode 100755 plugins-common/elm.sh delete mode 100755 user-management/src/main/elm/build-app.sh create mode 100755 user-management/src/main/elm/build.sh diff --git a/api-authorizations/src/main/elm/build-app.sh b/api-authorizations/src/main/elm/build-app.sh deleted file mode 100755 index 2da77e28f..000000000 --- a/api-authorizations/src/main/elm/build-app.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -set -e - -ELM_VER="0.19.1" - -if ! command -v elm-${ELM_VER} &> /dev/null -then - echo "# ERROR: missing elm-${ELM_VER} binary" - echo "# To install the right compiler version:" - echo "" - echo "$ curl -L -o elm-${ELM_VER}.gz https://github.com/elm/compiler/releases/download/${ELM_VER}/binary-for-linux-64-bit.gz" - echo "$ gzip -d elm-${ELM_VER}.gz" - echo "$ chmod +x elm-${ELM_VER}" - echo "# then put it somewhere in your PATH" - exit 1 -fi - -# we want that all elm-stuff stay in src/main/elm -# whatever the path from which this script is called -ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" -cd $ELM_DIR - -elm-${ELM_VER} make --optimize sources/ApiAuthorizations.elm --output=generated/api-authorizations.js -elm-${ELM_VER} make --optimize sources/UserApiToken.elm --output=generated/user-api-token.js diff --git a/api-authorizations/src/main/elm/build.sh b/api-authorizations/src/main/elm/build.sh new file mode 100755 index 000000000..af7109c7d --- /dev/null +++ b/api-authorizations/src/main/elm/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# we want that all elm-stuff stay in src/main/elm +# whatever the path from which this script is called +export ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" + +. ../../../../plugins-common/elm.sh SupervisedTargets "$@" +. ../../../../plugins-common/elm.sh WorkflowUsers "$@" diff --git a/api-authorizations/src/main/scala/com/normation/plugins/apiauthorizations/ApiAccountsExtension.scala b/api-authorizations/src/main/scala/com/normation/plugins/apiauthorizations/ApiAccountsExtension.scala index d7866ebbe..af551c2c0 100644 --- a/api-authorizations/src/main/scala/com/normation/plugins/apiauthorizations/ApiAccountsExtension.scala +++ b/api-authorizations/src/main/scala/com/normation/plugins/apiauthorizations/ApiAccountsExtension.scala @@ -104,7 +104,7 @@ class ApiAccountsExtension(val status: PluginStatus)(implicit val ttag: ClassTag
- +
diff --git a/auth-backends/src/main/elm/build-app.sh b/auth-backends/src/main/elm/build-app.sh deleted file mode 100755 index 63b3780cb..000000000 --- a/auth-backends/src/main/elm/build-app.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -set -e - -ELM_VER="0.19.1" - -if ! command -v elm-${ELM_VER} &> /dev/null -then - echo "# ERROR: missing elm-${ELM_VER} binary" - echo "# To install the right compiler version:" - echo "" - echo "$ curl -L -o elm-${ELM_VER}.gz https://github.com/elm/compiler/releases/download/${ELM_VER}/binary-for-linux-64-bit.gz" - echo "$ gzip -d elm-${ELM_VER}.gz" - echo "$ chmod +x elm-${ELM_VER}" - echo "# then put it somewhere in your PATH" - exit 1 -fi - -# we want that all elm-stuff stay in src/main/elm -# whatever the path from which this script is called -ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" -cd $ELM_DIR -elm-${ELM_VER} make --optimize sources/AuthBackends.elm --output=generated/auth-backends.js - diff --git a/auth-backends/src/main/elm/build.sh b/auth-backends/src/main/elm/build.sh new file mode 100755 index 000000000..c674be79a --- /dev/null +++ b/auth-backends/src/main/elm/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# we want that all elm-stuff stay in src/main/elm +# whatever the path from which this script is called +export ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" + +. ../../../../plugins-common/elm.sh AuthBackends "$@" diff --git a/auth-backends/src/main/resources/template/AuthBackendsManagement.html b/auth-backends/src/main/resources/template/AuthBackendsManagement.html index 4dbd55fd4..e79acb39d 100644 --- a/auth-backends/src/main/resources/template/AuthBackendsManagement.html +++ b/auth-backends/src/main/resources/template/AuthBackendsManagement.html @@ -9,7 +9,7 @@ Rudder :: Authentication Backends - + diff --git a/branding/src/main/elm/build-app.sh b/branding/src/main/elm/build-app.sh deleted file mode 100755 index 8662bfdbe..000000000 --- a/branding/src/main/elm/build-app.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -set -e - -ELM_VER="0.19.1" - -if ! command -v elm-${ELM_VER} &> /dev/null -then - echo "# ERROR: missing elm-${ELM_VER} binary" - echo "# To install the right compiler version:" - echo "" - echo "$ curl -L -o elm-${ELM_VER}.gz https://github.com/elm/compiler/releases/download/${ELM_VER}/binary-for-linux-64-bit.gz" - echo "$ gzip -d elm-${ELM_VER}.gz" - echo "$ chmod +x elm-${ELM_VER}" - echo "# then put it somewhere in your PATH" - exit 1 -fi - -# we want that all elm-stuff stay in src/main/elm -# whatever the path from which this script is called -ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" -cd $ELM_DIR - -# Only call elm-install if elm-stuff directory does not exists -# we don't need to it at every build, only if dependencies change -# And in most case, elm-make will treat them correctly -# If you need a dependency that cannot be installed with elm-make (ie elm-ui) -# Please for now delete elm-stuff file -# On CI, since we clean repository before build, elm-stuff will not exist - -elm-${ELM_VER} make --optimize sources/Branding.elm --output=generated/branding.js diff --git a/branding/src/main/elm/build-dev.sh b/branding/src/main/elm/build-dev.sh index dc8a6a15c..dcf56be2d 100755 --- a/branding/src/main/elm/build-dev.sh +++ b/branding/src/main/elm/build-dev.sh @@ -3,5 +3,5 @@ ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" cd $ELM_DIR -./build-app.sh +./build.sh cp generated/* ../../../target/classes/toserve/branding diff --git a/branding/src/main/elm/build.sh b/branding/src/main/elm/build.sh new file mode 100755 index 000000000..0e902af11 --- /dev/null +++ b/branding/src/main/elm/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# we want that all elm-stuff stay in src/main/elm +# whatever the path from which this script is called +export ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" + +. ../../../../plugins-common/elm.sh Branding "$@" diff --git a/branding/src/main/resources/template/brandingManagement.html b/branding/src/main/resources/template/brandingManagement.html index 323761fa7..c135ad6b6 100755 --- a/branding/src/main/resources/template/brandingManagement.html +++ b/branding/src/main/resources/template/brandingManagement.html @@ -7,7 +7,7 @@ - +
diff --git a/change-validation/src/main/elm/build-app.sh b/change-validation/src/main/elm/build-app.sh deleted file mode 100755 index 5514dbb9a..000000000 --- a/change-validation/src/main/elm/build-app.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -set -e - -ELM_VER="0.19.1" - -if ! command -v elm-${ELM_VER} &> /dev/null -then - echo "# ERROR: missing elm-${ELM_VER} binary" - echo "# To install the right compiler version:" - echo "" - echo "$ curl -L -o elm-${ELM_VER}.gz https://github.com/elm/compiler/releases/download/${ELM_VER}/binary-for-linux-64-bit.gz" - echo "$ gzip -d elm-${ELM_VER}.gz" - echo "$ chmod +x elm-${ELM_VER}" - echo "# then put it somewhere in your PATH" - exit 1 -fi - -# we want that all elm-stuff stay in src/main/elm -# whatever the path from which this script is called -ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" -cd $ELM_DIR - -elm-${ELM_VER} make --optimize sources/SupervisedTargets.elm --output=generated/supervised-targets.js -elm-${ELM_VER} make --optimize sources/WorkflowUsers.elm --output=generated/WorkflowUsers.js diff --git a/change-validation/src/main/elm/build-dev.sh b/change-validation/src/main/elm/build-dev.sh index fbf310fec..0d64a26b3 100755 --- a/change-validation/src/main/elm/build-dev.sh +++ b/change-validation/src/main/elm/build-dev.sh @@ -3,6 +3,6 @@ ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" cd $ELM_DIR -./build-app.sh +./build.sh cp generated/* ../../../target/classes/toserve/changevalidation cp ../resources/toserve/changevalidation/* ../../../target/classes/toserve/changevalidation \ No newline at end of file diff --git a/change-validation/src/main/elm/build.sh b/change-validation/src/main/elm/build.sh new file mode 100755 index 000000000..af7109c7d --- /dev/null +++ b/change-validation/src/main/elm/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# we want that all elm-stuff stay in src/main/elm +# whatever the path from which this script is called +export ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" + +. ../../../../plugins-common/elm.sh SupervisedTargets "$@" +. ../../../../plugins-common/elm.sh WorkflowUsers "$@" diff --git a/change-validation/src/main/resources/template/ChangeValidationManagement.html b/change-validation/src/main/resources/template/ChangeValidationManagement.html index 7263659dd..073409514 100644 --- a/change-validation/src/main/resources/template/ChangeValidationManagement.html +++ b/change-validation/src/main/resources/template/ChangeValidationManagement.html @@ -11,8 +11,8 @@ - - + +
diff --git a/plugins-common/elm.sh b/plugins-common/elm.sh new file mode 100755 index 000000000..7d681a1cc --- /dev/null +++ b/plugins-common/elm.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# Lib for building elm projects + +# Similar to https://github.com/Normation/rudder/blob/master/webapp/sources/rudder/rudder-web/src/main/elm/build.sh +# Should be kept in sync + +# Call without option for a dev build +# Call with --release for an optimized and minified build + +# The argument is the name of the elm source to compile +app="$1" +app_l=$(echo "${app}" | tr '[:upper:]' '[:lower:]') + +set -e + +ELM="elm-0.19.1" + +# ELM_DIR is set in every app build script before calling elm.sh +if [ -z $ELM_DIR ]; then + echo "Missing ELM_DIR variable" + exit 1 +fi + +if ! command -v ${ELM} &> /dev/null +then + echo "# ERROR: missing ${ELM} binary" + echo "# To install the right compiler version:" + echo "" + echo "$ curl -L -o ${ELM}.gz https://github.com/elm/compiler/releases/download/${ELM}/binary-for-linux-64-bit.gz" + echo "$ gzip -d ${ELM}.gz" + echo "$ chmod +x ${ELM}" + echo "# then put it somewhere in your PATH" + exit 1 +fi + +build_release() { + ${ELM} make --optimize sources/${app}.elm --output=generated/rudder-${app_l}.js + terser generated/rudder-${app_l}.js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' | terser --mangle --output=generated/rudder-${app_l}.min.js + # we use the same path for dev and prod so we can't really use .min.js + cp generated/rudder-${app_l}.min.js generated/rudder-${app_l}.js +} + +build_dev() { + ${ELM} make sources/${app}.elm --output=generated/rudder-${app_l}.js +} + +# Warning: the current fs scheme does not allow multiple elm app in a plugin +cd ${ELM_DIR}/ +if [ "$2" = "--release" ]; then + (set -x; build_release) +else + (set -x; build_dev) +fi diff --git a/plugins-common/pom-template.xml b/plugins-common/pom-template.xml index 6831e9058..033a1ebe0 100644 --- a/plugins-common/pom-template.xml +++ b/plugins-common/pom-template.xml @@ -137,8 +137,8 @@ exec - bash - src/main/elm/build-app.sh + src/main/elm/build.sh + --release diff --git a/user-management/src/main/elm/build-app.sh b/user-management/src/main/elm/build-app.sh deleted file mode 100755 index a68461f0d..000000000 --- a/user-management/src/main/elm/build-app.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -set -e - -ELM_VER="0.19.1" - -if ! command -v elm-${ELM_VER} &> /dev/null -then - echo "# ERROR: missing elm-${ELM_VER} binary" - echo "# To install the right compiler version:" - echo "" - echo "$ curl -L -o elm-${ELM_VER}.gz https://github.com/elm/compiler/releases/download/${ELM_VER}/binary-for-linux-64-bit.gz" - echo "$ gzip -d elm-${ELM_VER}.gz" - echo "$ chmod +x elm-${ELM_VER}" - echo "# then put it somewhere in your PATH" - exit 1 -fi - -# we want that all elm-stuff stay in src/main/elm -# whatever the path from which this script is called -ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" -cd $ELM_DIR -elm-${ELM_VER} make --optimize sources/UserManagement.elm --output=generated/UserManagement.js diff --git a/user-management/src/main/elm/build-dev.sh b/user-management/src/main/elm/build-dev.sh index bc440b579..4e302f8ea 100755 --- a/user-management/src/main/elm/build-dev.sh +++ b/user-management/src/main/elm/build-dev.sh @@ -3,6 +3,6 @@ ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" cd $ELM_DIR -./build-app.sh +./build.sh cp generated/* ../../../target/classes/toserve/usermanagement cp ../resources/toserve/usermanagement/* ../../../target/classes/toserve/usermanagement \ No newline at end of file diff --git a/user-management/src/main/elm/build.sh b/user-management/src/main/elm/build.sh new file mode 100755 index 000000000..efc836f86 --- /dev/null +++ b/user-management/src/main/elm/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# we want that all elm-stuff stay in src/main/elm +# whatever the path from which this script is called +export ELM_DIR="$( cd "$( dirname "$0" )" && pwd )" + +exec ../../../../plugins-common/elm.sh UserManagement "$@" diff --git a/user-management/src/main/resources/template/UserManagement.html b/user-management/src/main/resources/template/UserManagement.html index 14c9d2c09..2d476a699 100644 --- a/user-management/src/main/resources/template/UserManagement.html +++ b/user-management/src/main/resources/template/UserManagement.html @@ -10,7 +10,7 @@ Plugin :: User Management - +