@echo off

echo Setting path variable
setx path "%path%;%cd%\protoc\bin"

echo Removing old files
CD "c:\temp\cd

"
del *.*

echo Downloading source code
cd c:\temp
 git clone https://d83f41c7ee08b4012364bd838e1611acc18f8093@shc004gitp01.shdc.chrysler.com/uconnect-ict/global-api.git
copy c:\temp\Global-API\fca_global_api-master\documents\API\API.html C:\temp\API.html

 echo Generating documentation 
cd c:\temp\Global-API\fca_global_api-master\protobufSrc
protoc --doc_out=..\documents\templates\fca.mustache,API.html:..\documents\API\ *.proto 

echo Comparing documentation
fc C:\temp\API.html ..\documents\API\API.html >null
if NOT ERRORLEVEL == 0 goto push-to-git
if ERRORLEVEL == 0 goto no-git-push

:push-to-git
echo Pushing updated file back to github
git  add ../documents/API/API.html
git commit -m "build API.html"
git push

:no-git-push
echo No need to push back to github

cd c:\temp
