Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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