#!/bin/bash

if !(uname -a | grep 'Darwin') ; then
    echo "Not running on macOS; skipping macOS build."
    exit
fi

VERSION=`egrep \"version\" package.json | head -1 | egrep --only-match [0-9.]+`

# Fix icon line, which needs to be different for Windows builds than for Mac builds.
cp package.json package-old.json
sed -e 's/"icon": .*/"icon": "duckclient-128.icns",/' package-old.json >package.json

if [ -e node_modules/.bin ] ; then
    node_modules/.bin/nwbuild --platform=osx --arch=x64 --glob=false .
    # Fix a problem where the fontlist binary is not given proper permissions
    find dist -name 'fontlist' -exec chmod a+x {} \;
    exit
else
    echo "Did not find nwjs-builder-phoenix script. Run 'npm install'"
    echo "in the project root directory and try again."
    exit 1
fi
