From 17c22610af769af25aba3e81f234b4153a442f82 Mon Sep 17 00:00:00 2001 From: renelamo <44474378+renelamo@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:59:20 +0100 Subject: [PATCH] Add Lightning CSS minifier (#36) --- README.md | 1 + action.yml | 4 ++++ entrypoint.sh | 24 +++++++++++++++++++++++- package.json | 3 ++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09da9bd..9d19e0b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Minifies JS and CSS files with Babel-Minify and CleanCSS | overwrite | Overwrites the existing files with the minified version. Defaults to false. | false | false | | maxdepth | Descend at most levels (a non-negative integer) levels of directories below the starting-points. | false | "" (empty) | | js_engine | Specifies which of the supported packages minifies JS files. Supported packages: `babel`, `uglify-js` | false | babel | +| css_engine | Specifies which of the supported packages minifies CSS files. Supported packages: `lightning`, `clean-css` | false | lightning | > With the addition of `maxdepth`, the action traverses by default into all subdirectories in a specified directory. > diff --git a/action.yml b/action.yml index 4f7620d..0c18d18 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,10 @@ inputs: description: "Specifies which of the supported packages minifies JS files." required: false default: "babel" + css_engine: + description: "Specifies which of the supported packages minifies CSS files." + required: false + default: "lightning" runs: using: "docker" diff --git a/entrypoint.sh b/entrypoint.sh index 1d2c05b..bba32d0 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -93,6 +93,28 @@ exec_minify_js () { fi } +exec_minify_css () { + : ' + arguments: + 1- input file + 2- output file + + returns the command needed to minify the css file + based on the requested CSS Engine in the + input `css_engine` + ' + file=$1 + out=$2 + + css_engine=$INPUT_CSS_ENGINE + + if [[ $css_engine == "clean-css" ]]; then + npx cleancss -o $out $file + elif [[ $css_engine == "lightning" ]]; then + npx lightningcss --minify $file --output-file $out + fi +} + exec_minify_cmd () { : ' arguments: @@ -108,7 +130,7 @@ exec_minify_cmd () { if [[ $file == *.js ]]; then exec_minify_js $file $out elif [[ $file == *.css ]]; then - npx cleancss -o $out $file + exec_minify_css $file $out fi } diff --git a/package.json b/package.json index 4f266f1..985aec1 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "dependencies": { "uglify-js": "^3.10.0", "babel-minify": "^0.5.1", - "clean-css-cli": "^4.3.0" + "clean-css-cli": "^4.3.0", + "lightningcss-cli": "^1.24.1" }, "author": { "name": "Nizar Mahmoud",