Skip to content

Instantly share code, notes, and snippets.

@newbreedofgeek
Last active January 23, 2017 16:34
Show Gist options
  • Save newbreedofgeek/db2b3fc1fc0cac592173 to your computer and use it in GitHub Desktop.
Save newbreedofgeek/db2b3fc1fc0cac592173 to your computer and use it in GitHub Desktop.
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.
#!/bin/bash
# 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=$name"-"$version
filename=`sed 's/ //g' <<< $filename`
filename+='.tar.gz'
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