Skip to content

Commit

Permalink
Add option for minified files to overwrite existing ones (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizarmah authored Aug 18, 2021
1 parent ebdd151 commit 75e2c2c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down Expand Up @@ -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

```
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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' )

Expand Down

0 comments on commit 75e2c2c

Please sign in to comment.