Skip to content

Instantly share code, notes, and snippets.

@ytnobody
Last active November 15, 2018 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytnobody/e8217f6816b15a4fc5b95a5d0bc772ff to your computer and use it in GitHub Desktop.
Save ytnobody/e8217f6816b15a4fc5b95a5d0bc772ff to your computer and use it in GitHub Desktop.
Azure functions v1 -> v2 for Node.js applications for MacOSX
#!/bin/bash
show_help () {
cat <<EOF
Run "npm -g install azure-functions-core-tools" first.
EOF
exit;
}
list_required_extensions () {
grep '"type"' */function.json |
awk '{print($3);}' |
sed 's/",//g; s/"//g; s/Trigger//g;' |
sort | uniq |
awk '
{t[$1]=1;}
END {
if (t["queue"] || t["table"] || t["blob"]) { print("Microsoft.Azure.WebJobs.Extensions.Storage 3.*") }
if (t["eventGrid"]) { print("Microsoft.Azure.WebJobs.Extensions.EventGrid 2.*"); }
if (t["eventHub"]) { print("Microsoft.Azure.WebJobs.Extensions.EventHubs 3.*"); }
if (t["documentDB"]) { print("Microsoft.Azure.WebJobs.Extensions.CosmosDB 3.*"); }
if (t["sendGrid"]) { print("Microsoft.Azure.WebJobs.Extensions.SendGrid 3.*"); }
if (t["serviceBus"]) { print("Microsoft.Azure.WebJobs.Extensions.ServiceBus 3.*"); }
if (t["twilioSms"]) { print("Microsoft.Azure.WebJobs.Extensions.Twilio 3.*"); }
}
'
}
install_extensions () {
cat - | awk '
{
if ($1 ~ /\.CosmosDB$/) {
system("sed -i \"\" \"s/\\\"type\\\": \\\"documentDB/\\\"type\\\": \\\"cosmosDB/g; s/\\\"connection\\\"/\\\"connectionStringSetting\\\"/g;\" */function.json");
}
system("func extensions install --package "$1" --version "$2);
}
'
}
upgrade_host_runtime_version () {
sed -i '' -e '/"version"\:/d; 2i\
\ \ \ \ "version": "2.0",' host.json
}
FUNC_PATH=`which func`
if [ -z $FUNC_PATH ]; then
show_help
fi
func init --worker-runtime=node &&
list_required_extensions | install_extensions
upgrade_host_runtime_version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment