Last active
June 19, 2017 19:11
-
-
Save Joaquin6/aa62940418bd6dd84610c1b14063d8eb to your computer and use it in GitHub Desktop.
File that lives in ./bin from the root dir. It is responsible for cleaning up the directory as desired.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
declare -a CLEAN=( | |
./.sass-cache | |
./eslint-debug.log | |
./npm-debug.log | |
./yarn-error.log | |
./logs | |
./node_modules | |
./build | |
) | |
declare -a IGNORE=( | |
./static/index.html | |
) | |
confirm_existence() | |
{ | |
if [[ -d $1 ]] && [[ -n $1 ]] ; then | |
echo "\tDeleting Directory $1" | |
return 0 | |
fi | |
if [[ -f $1 ]] && [[ -n $1 ]] ; then | |
echo "\tDeleting File $1" | |
return 0 | |
fi | |
return 1 | |
} | |
delete() | |
{ | |
if hash rimraf 2>/dev/null; then | |
rimraf "$1" -s | |
else | |
rm -r "$1" | |
fi | |
echo "\t\tSuccessfully Deleted $1" | |
} | |
cleanup() | |
{ | |
if confirm_existence $1; then | |
delete $1 | |
else | |
echo "\t$1 Does Not Exist." | |
fi; | |
echo | |
} | |
ignore() | |
{ | |
for IGNORE_SRC in "${IGNORE[@]}" | |
do | |
if [[ $1 == "$IGNORE_SRC" ]]; then | |
return 0 | |
fi | |
done | |
return 1 | |
} | |
echo "\nCleaning Directory...\n"; | |
for i in "${CLEAN[@]}" | |
do | |
if ignore $i ; then | |
echo "\tNot Deleting $i" | |
else | |
cleanup $i | |
fi | |
done | |
echo "Done Cleaning\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment