#!/bin/bash

set -e

root=$(cd $(dirname ${0})/..; pwd)
node_modules=${root}/node_modules
src=${root}/src
tools=${root}/tools
third_party=${root}/third_party

identifier=coremltools
repository=https://github.com/apple/${identifier}.git

mkdir -p ${third_party}

if [ -d "${third_party}/${identifier}" ]; then
    git -C "${third_party}/${identifier}" fetch -p
    git -C "${third_party}/${identifier}" reset --hard origin/master
else
    echo "Clone ${repository}..."
    git -C "${third_party}" clone --recursive ${repository}
fi

echo "Generate '../src/coreml.js'"
${node_modules}/protobufjs/bin/pbjs -t static-module -w closure -r coreml -o ${src}/coreml.js ${third_party}/${identifier}/mlmodel/format/Model.proto
