Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is a simple Shell Script that you can include in your project that will use the name and version values from your package.json and create a tar.gz build for you. Useful for manual builds where you need to copy your app to your server, unpack and launch.
# Generate a tar.gz build using name and version from package.json
# In your app root you need a builds/ directory, this is where your tar.gz file will be placed. Or change this location in line 25
# The script will ignore your node_modules and builds folders
# get app name from package.json
name=`grep "name" package.json | sed 's/,//g'`
name=`sed 's/"name"://g' <<< $name`
name=`sed 's#"# #g' <<< $name`
# get app version from package.json
version=`grep "version" package.json | sed 's/,//g'`
version=`sed 's/"version"://g' <<< $version`
version=`sed 's#"# #g' <<< $version`
# append them both and remove all whitespace and append .tar.gz to the file name string
filename=`sed 's/ //g' <<< $filename`
echo "--------------------------"
echo "lets make a new tar.gz"
echo "--------------------------"
# create the new tar.gz in your builds/ folder (exclude node_modules folder)
tar -zcvf "builds/"$filename --exclude "node_modules/" --exclude "builds/" *
echo "--------------------------"
echo "created new build tar.gz with filename = "$filename
echo "--------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment