
#!/bin/bash

mkdir -p ../third_party

repository=git@github.com:tensorflow/tensorflow.git

if [ -d "../third_party/tensorflow" ]; then
    pushd "../third_party/tensorflow" > /dev/null
    echo "Fetch ${repository}..."
    git fetch -p
    echo "Reset ${repository}..."
    git reset --hard origin/master
    popd > /dev/null
else
    pushd "../third_party" > /dev/null
    echo "Clone ${repository}..."
    git clone --recursive ${repository}
    popd > /dev/null
fi

echo "Generate '../src/tf.js'"
../node_modules/protobufjs/bin/pbjs -t static-module -w closure -r tf -o ../src/tf.js \
    ../third_party/tensorflow/tensorflow/core/protobuf/saved_model.proto \
    ../third_party/tensorflow/tensorflow/core/protobuf/meta_graph.proto \
    ../third_party/tensorflow/tensorflow/core/protobuf/saver.proto \
    ../third_party/tensorflow/tensorflow/core/framework/graph.proto \
    ../third_party/tensorflow/tensorflow/core/framework/op_def.proto \
    ../third_party/tensorflow/tensorflow/core/framework/tensor_shape.proto \
    ../third_party/tensorflow/tensorflow/core/framework/types.proto \
    ../third_party/tensorflow/tensorflow/core/framework/node_def.proto \
    ../third_party/tensorflow/tensorflow/core/framework/versions.proto \
    ../third_party/tensorflow/tensorflow/core/framework/function.proto \
    ../third_party/tensorflow/tensorflow/core/framework/attr_value.proto \
    ../third_party/tensorflow/tensorflow/core/framework/tensor.proto \
    ../third_party/tensorflow/tensorflow/core/framework/resource_handle.proto \

echo "Generate '../src/tf-operator.json'"
python tf-operator-json.py
