#!/bin/bash

# Package up a release ready to be uploaded to the Chrome Dev Store.

VERSION=`hg id -n | tr -d '+\n'`
hg archive ../Duckclient-${VERSION} -X ".hg*" -X "build" -X "test" -X "node_modules" -X "dist" -X "package.json" -X "cacert.pem" -X "docs"

# The certs folder is not version controlled, so we have to copy that
# over.
mkdir ../Duckclient-${VERSION}/certs
cp certs/cabundle.js ../Duckclient-${VERSION}/certs/

# If it's not a dev version, remove the unit tests.
if (echo ${VERSION} | egrep '\.') ; then
    echo "packaging production build"
    rm -r ../Duckclient-${VERSION}/test
else
    echo "packaging dev build"
fi

rm -f ../Duckclient-${VERSION}.zip

pushd ../Duckclient-${VERSION}

zip -r ../Duckclient-${VERSION}.zip *

popd
