. ./@Core/Scripts/templates.sh

echo "${BUILDING_LAMBDAS}"

echo "Cleanup ---> Cleaning out dist folder"
rm -rf ./lambdaDist/*

echo "${YELLOW}Starting to build, compile and install all the API endpoints"
echo "${GREEN}Install core dependancies${NC}"
npm i
npm i esbuild

echo "${GREEN}Building Lambdas${NC}"

esbuild ./@Core/Scripts/Lambdas/*/index.ts --bundle --outdir=./lambdaDist/distZip/ --platform=node --target=node14 --minify-whitespace;

echo "${BLACK_TEXT_ON_GREEN_BACKGROUND} Lambdas build completed ${NC}"

mkdir ./lambdaDist/zipFile/
cd ./lambdaDist/distZip/

zip -r ../zipFile/zipFile.zip ./*

FILESIZE=$(ls -lh ../zipFile/zipFile.zip | awk '{print  $5}')

echo "File Size = ${FILESIZE}"

# Deploy manually from computer
    cd ..
    aws lambda update-function-code --function-name testIfServersAreAlive --zip-file fileb://./zipFile/zipFile.zip
# End Deploy Manually

echo "${DEV_BUILT_TEXT}"

exit 0
