#!/bin/bash

set -e

. luan string:

rm -rf build
mkdir -p build/luan_editor/jars
cp $LUAN/jars/luan.jar build/luan_editor/jars
cp $LUAN/jars/miglayout-*.jar build/luan_editor/jars
cp $LUAN/jars/flatlaf-*.jar build/luan_editor/jars
cp lib/*.jar build/luan_editor/jars

. classpath.sh
cd src
javac -classpath $CLASSPATH `find . -name *.java`
jar cvf ../build/luan_editor/jars/luan_editor.jar `find . -name *.class -o -name *.luan`
cd ..

cp -r dictionaries build/luan_editor

cp scripts/install.sh build/luan_editor
cp scripts/uninstall.sh build/luan_editor
hg identify >build/luan_editor/hg_rev.txt

cd build

tar -cf ../website/src/download/luan_editor.tar luan_editor

luan_editor/install.sh || sudo luan_editor/install.sh

mkdir mac
mkdir mac/Luan_Editor.app
mkdir mac/Luan_Editor.app/Contents
mkdir mac/Luan_Editor.app/Contents/MacOS
mkdir mac/Luan_Editor.app/Contents/Resources
mkdir mac/Luan_Editor.app/Contents/Resources/CLI

cp ../scripts/mac/Info.plist mac/Luan_Editor.app/Contents
cp ../scripts/mac/launcher mac/Luan_Editor.app/Contents/MacOS
cp ../scripts/mac/install.sh mac/Luan_Editor.app/Contents/Resources/CLI
cp ../scripts/mac/uninstall.sh mac/Luan_Editor.app/Contents/Resources/CLI
cp -r luan_editor/jars mac/Luan_Editor.app/Contents/Resources
cp -r luan_editor/dictionaries mac/Luan_Editor.app/Contents/Resources

create-dmg \
	--volname "Luan Editor" \
	--window-pos 200 120 \
	--window-size 500 300 \
	--icon-size 100 \
	--icon "Luan_Editor.app" 100 100 \
	--app-drop-link 380 100 \
	"Luan_Editor.dmg" \
	"mac/"

cp Luan_Editor.dmg ../website/src/download

echo done
