Skip to content

Commit

Permalink
Feature: Adds JS_ENGINE Input to decide which Package Minifies the JS…
Browse files Browse the repository at this point in the history
… files (#11)

* Adds JS_ENGINE Input to decide which Package Minifies the JS Files

* Adds Uglify to the Supported JS_ENGINE Packages
  • Loading branch information
nizarmah authored Jul 27, 2020
1 parent 10c596e commit 35e7f70
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Minifies JS and CSS files with Babel-Minify and CleanCSS
| directory | Directory that contains the files you want to minify. | false | . ( current directory ) |
| output | Directory that contains the minified files. | false | same as directory |
| 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 |

> With the addition of `maxdepth`, the action traverses by default into all subdirectories in a specified directory.
>
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ inputs:
description: "Descend at most levels (a non-negative integer) levels of directories below the starting-points."
required: false
default: ""
js_engine:
description: "Specifies which of the supported packages minifies JS files."
required: false
default: "babel"

runs:
using: "docker"
Expand Down
24 changes: 23 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ find_files () {
find $in_dir ${MAXDEPTH_KEY} ${MAXDEPTH_VAL} -type f -name "*.$1" | grep -v ".min.$1$"
}

exec_minify_js () {
: '
arguments:
1- input file
2- output file
returns the command needed to minify the js file
based on the requested JavaScript Engine in the
input `js_engine`
'
file=$1
out=$2

js_engine=$INPUT_JS_ENGINE

if [[ $js_engine == "babel" ]]; then
npx minify $file --out-file $out
elif [[ $js_engine == "uglify-js" ]]; then
npx uglifyjs $file --compress --mangle --output $out
fi
}

exec_minify_cmd () {
: '
arguments:
Expand All @@ -79,7 +101,7 @@ exec_minify_cmd () {
out=$2

if [[ $file == *.js ]]; then
npx minify $file --out-file $out
exec_minify_js $file $out
elif [[ $file == *.css ]]; then
npx cleancss -o $out $file
fi
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"repository": "nizarmah/auto-minify",
"homepage": "https://github.com/nizarmah/auto-minify/",
"dependencies": {
"uglify-js": "^3.10.0",
"babel-minify": "^0.5.1",
"clean-css-cli": "^4.3.0"
},
Expand Down

0 comments on commit 35e7f70

Please sign in to comment.