Skip to content

Commit 60f79ec

Browse files
author
Ian Sibner
committed
add glob support
1 parent 05d0ef1 commit 60f79ec

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

README.markdown

+15-4
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,25 @@ https://github.com/heroku/heroku-buildpack-ruby
3636
https://github.com/Lostmyname/heroku-buildpack-post-build-clean
3737
```
3838

39-
The `.slug-post-clean` file supports single-file and single-directory
40-
declarations only, e.g.:
39+
The `.slug-post-clean` file supports single-file and single-directory patterns, **as well as glob patterns**, e.g.:
4140

4241
```
4342
some_huge_file.psd
4443
some/nested/directory
4544
why_does_this_app_even_contain_a.tiff
45+
your_frontend/build/*.map
4646
```
4747

48-
I might expand it to support file globs, but for the moment it's not
49-
necessary and the testing implications give me the willies.
48+
Glob patterns are expanded using Bash syntax - not with a third-party library such as [node-glob](https://github.com/isaacs/node-glob). You can see what your glob matches from `bash` with this command:
49+
50+
```bash
51+
ls -d1 your/glob/pattern/*
52+
```
53+
54+
## Testing
55+
56+
The `bin/compile` script does all the heavy lifting for this package. It takes a single argument, $BUILD_DIR, the directory of your app. If you want to test it out locally and make sure your app still runs after the post-build cleanup, you can copy `bin/compile` into your app directory and run:
57+
58+
```bash
59+
chmod +x compile; ./compile .
60+
```

bin/compile

+20-6
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,29 @@ if [[ ! -f "${CLEAN_FILES}" ]]; then
1717
exit 1
1818
fi
1919

20+
function remove_file_or_dir {
21+
if [[ -f "$1" ]]; then
22+
echo "Removing file $1 from slug"
23+
rm -f $1
24+
elif [[ -d "$1" ]]; then
25+
echo "Removing directory $1 from slug"
26+
rm -rf $1
27+
else
28+
echo "Location $1 not found - ignoring"
29+
fi
30+
}
31+
32+
export -f remove_file_or_dir
33+
2034
while read file; do
2135
[[ ! -n "${file}" ]] && continue
2236

23-
if [[ -f "${file}" ]]; then
24-
echo "Removing file ${file} from slug"
25-
rm -f ${file}
26-
elif [[ -d "${file}" ]]; then
27-
echo "Removing directory ${file} from slug"
28-
rm -rf ${file}
37+
if [[ -f "${file}" || -d "${file}" ]]; then
38+
# Target is a file or directory, remove it
39+
remove_file_or_dir ${file}
40+
elif ls -d $(echo $file) &> /dev/null; then
41+
# target is a glob, expand it and remove everything it matches
42+
ls -d1 $(echo $file) | while read line; do remove_file_or_dir $line; done
2943
else
3044
echo "Location ${file} not found - ignoring"
3145
fi

0 commit comments

Comments
 (0)