Created
June 24, 2019 18:51
-
-
Save fedek6/f6a1e134137c3eb66cb8aa43b2a8efd1 to your computer and use it in GitHub Desktop.
Packer for web projects. It will pack public dir in current path. Archive name will include info from package.json.
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/sh | |
# Extract JSON value | |
parse_json () { | |
echo $1 | \ | |
sed -e 's/[{}]/''/g' | \ | |
sed -e 's/", "/'\",\"'/g' | \ | |
sed -e 's/" ,"/'\",\"'/g' | \ | |
sed -e 's/" , "/'\",\"'/g' | \ | |
sed -e 's/","/'\"---SEPERATOR---\"'/g' | \ | |
awk -F=':' -v RS='---SEPERATOR---' "\$1~/\"$2\"/ {print}" | \ | |
sed -e "s/\"$2\"://" | \ | |
tr -d "\n\t" | \ | |
sed -e 's/\\"/"/g' | \ | |
sed -e 's/\\\\/\\/g' | \ | |
sed -e 's/^[ \t]*//g' | \ | |
sed -e 's/^"//' -e 's/"$//' | |
} | |
# Path | |
result=${PWD##*/} | |
# Get version | |
json=`cat package.json` | |
version=`parse_json "$json" version` | |
name=`parse_json "$json" name` | |
# Current date | |
now=$(date +"%d_%m_%Y") | |
machine=$(hostname) | |
(cd ./public && /usr/bin/zip -r ../"$now"-"$name"-"$machine"-v"$version".zip .) | |
echo "OK! It's all packed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment