Last active
May 19, 2016 12:22
-
-
Save alanning/11000555 to your computer and use it in GitHub Desktop.
Bash shell script that bundles Meteor app and includes date and latest git commit hash in destination filename. By default, will not bundle is there are uncommitted changes but you can override with the `-f` flag. Properly handles branches as well.
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 | |
set -o nounset | |
set -o errexit | |
FORCE=false | |
# Read parameters | |
# http://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash | |
while [[ $# > 0 ]] | |
do | |
key="$1" | |
case $key in | |
-f|--force) | |
FORCE=true | |
echo "Allowing bundle with uncommitted changes..." | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
shift | |
done | |
PREFIX="share911-app" | |
DATE=$(date +"%Y%m%d") | |
COMMIT=`git rev-parse HEAD` | |
BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
if [ "$BRANCH" = "master" ]; then | |
DEST="$HOME/tmp/apps/$PREFIX-$DATE-$COMMIT.tgz" | |
else | |
DEST="$HOME/tmp/apps/$PREFIX-$DATE-$COMMIT-$BRANCH.tgz" | |
fi | |
if [ "$FORCE" != true ] && [ ! -z "$(git status --porcelain)" ]; | |
then | |
echo "ERROR: uncommited or untracked changes found. Not bundling." | |
git status --porcelain | |
exit 1 | |
fi | |
if [[ -e "$DEST" ]]; then | |
echo "ERROR: target destination file already exists. Not bundling." | |
echo "$DEST" | |
exit 1 | |
fi | |
cat > server/version.js << EOF | |
// This file is automatically generated by the Share911 | |
// bundle script and should not be manually modified. | |
if ("undefined" === typeof S911) { | |
S911 = {} | |
} | |
S911.version = "$COMMIT"; | |
EOF | |
mkdir -p "$HOME/tmp/apps" | |
mrt bundle "$DEST" | |
if [ "$(uname)" == "Darwin" ]; then | |
echo "$DEST" | pbcopy | |
fi | |
echo "$DEST" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Put this script in your app directory. Instead of running 'meteor bundle', run this instead: