diff --git a/README.md b/README.md index cd91849..67d5dd1 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,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 | +| 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 | @@ -36,6 +37,27 @@ steps: branch: ${{ github.ref }} ``` +##### Overwriting Existing Files + +``` +steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so auto-minify job can access it + - uses: actions/checkout@v2 + + - name: Auto Minify + uses: nizarmah/auto-minify@v2 + with: + overwrite: true + + # Auto commits minified content to the existing files + # Ignore it if you don't want to commit the files to the repository + - name: Auto committing minified files + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Github Action: Auto Minified JS and CSS files" + branch: ${{ github.ref }} +``` + ##### Specifying Maxdepth ``` diff --git a/action.yml b/action.yml index 85ef8cf..4f7620d 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,10 @@ inputs: description: "Directory that contains the minified files. Defaults to same directory" required: false default: "" + overwrite: + description: "Overwrites the existing files with the minified version. Defaults to false." + required: false + default: "false" maxdepth: description: "Descend at most levels (a non-negative integer) levels of directories below the starting-points." required: false diff --git a/entrypoint.sh b/entrypoint.sh index c516001..731a95a 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -35,7 +35,12 @@ output_name () { mkdir -p $f_path fi - echo "$f_path/$f_name.min$f_extn" | xargs readlink -m + min_extn=".min" + if $overwrite; then + min_extn="" + fi + + echo "$f_path/$f_name$min_extn$f_extn" | xargs readlink -m } find_files () { @@ -142,6 +147,11 @@ if [ ! -z $out_dir ]; then mkdir -p $out_dir fi +overwrite=false +if [ "${INPUT_OVERWRITE,,}" == "true" ]; then + overwrite=true +fi + js_files=$( find_files 'js' ) css_files=$( find_files 'css' )