Skip to content

Instantly share code, notes, and snippets.

@fedek6
Created June 24, 2019 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedek6/f6a1e134137c3eb66cb8aa43b2a8efd1 to your computer and use it in GitHub Desktop.
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.
#!/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