Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds exclude_directories input #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Minifies JS and CSS files with Babel-Minify and CleanCSS
| Input | Description | Required | Default Value |
| -- | -- | -- | -- |
| directory | Directory that contains the files you want to minify. | false | . ( current directory ) |
| exclude_directories | Exclude child folders from the main directory. Combine them in a string separated by semicolon and relative to the main directory eg. `dir1;js/dir2;js/test/dir3`. | false | "" (empty) |
| 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) |
Expand Down Expand Up @@ -127,3 +128,28 @@ steps:
```

> Please note that the `repository` when _auto comitting_ has to match `output` in _auto minify_

##### Excluding child directories

```
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.1
with:
directory: 'js'
exclude_directories: 'pdf_js'

# Auto commits minified files to the repository
# 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:
repository: 'js'
commit_message: "Github Action: Auto Minified JS and CSS files"
branch: ${{ github.ref }}
```

> Please note that the `exclude_directories` will be relative to the `directory` which here is `js`. In this example the `pdf_js` directory full path would be `js/pdf_js`.
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ inputs:
description: "Directory that contains the files you want to minify. Defaults to current directory (.)"
required: false
default: "."
exclude_directories:
description: "Exclude child folders from the main directory. Combine them in a string separated by semicolon and relative to the main directory eg. 'dir1;js/dir2;js/test/dir3'"
required: false
default: ""
Comment on lines +11 to +14
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @alexmigf!

Can you switch this please to use line breaks?

Here's an example from StackOverflow.
https://stackoverflow.com/a/75420778/5512292

output:
description: "Directory that contains the minified files. Defaults to same directory"
description: "Directory that contains the minified files. Defaults to same directory."
required: false
default: ""
overwrite:
Expand Down
29 changes: 21 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,32 @@ find_files () {

optional parameters:
- `-maxdepth`

Clear all optional parameter keys in case the values are empty
So, when appended to the command parameters, no error is caused
'

MAXDEPTH_KEY="-maxdepth"
MAXDEPTH_VAL=$INPUT_MAXDEPTH
if ! [ -z $INPUT_MAXDEPTH ] && [[ $INPUT_MAXDEPTH == ?(-)+([0-9]) ]]; then
MAXDEPTH="-maxdepth ${INPUT_MAXDEPTH}"
else
MAXDEPTH=""
fi

EXCLUDES=()
if ! [ -z $INPUT_EXCLUDE_DIRECTORIES ]; then
IFS=';' read -ra EXCLUDES_ARRAY <<< "$INPUT_EXCLUDE_DIRECTORIES"
for i in ${EXCLUDES_ARRAY[@]}; do
if [ -z $EXCLUDES ]; then
EXCLUDES+=("-path" "$in_dir/$i")
else
EXCLUDES+=("-o" "-path" "$in_dir/$i")
fi
done
fi

if [ -z $MAXDEPTH_VAL ]; then
MAXDEPTH_KEY=""
if ! [ -z $EXCLUDES ]; then
EXCLUDES="-type d \( ${EXCLUDES[@]} \) -prune -o"
fi

find $in_dir ${MAXDEPTH_KEY} ${MAXDEPTH_VAL} -type f -name "*.$1" -not \( -iname "*\.min.$1" \)
COMMAND="find $in_dir ${MAXDEPTH} ${EXCLUDES} -type f -name *.$1 -not \( -iname *\.min.$1 \) -print"
eval ${COMMAND}
}

exec_minify_js () {
Expand Down