#!/bin/bash # The purpose of this script is to create a build file from an IONIC application and deploy it in Heroku. # Usage: To use this script, in linux bash terminal type the following command and follow the prompts: # curl -s https://www.webune.com/forums/deply-ionic-app-to-heroku.html | bash currentWorkingDir=${PWD} echo $projectPath date=`date "+%Y%m%d-%H%M%S"` appNameDefault="ionic-app-$date" read -p "What is the name of this App [$appNameDefault] " appName if [[ $appName == "" ]]; then appName=$appNameDefault set -e fi # this public-url will be used to generate the build and provide the public-url=[] option in the command publicUrlDefault="https://$appName.herokuapp.com" read -p "What is the PUBLIC URL where this script will be published? : [$publicUrlDefault] (type 'none' for the default /) " publicUrl if [[ $publicUrl == "" ]] then publicUrl="public-url=$publicUrlDefault" set -e elif [[ $publicUrl == "none" ]] then publicUrl="" fi buildFolderDefault="../builds/" read -p "Full path of where you want to create the build folder? [$buildFolderDefault] " buildFolder if [[ $buildFolder == "" ]] then buildFolder=$buildFolderDefault set -e fi appTypeDefault="build" read -p "Is this a React or Angular App? [react] or angular" appType if [[ $appType == "" ]] || [[$appType == "react"]] then appType=$appTypeDefault set -e elif [[ $appType == "angular" ]] then appType="wwww" fi newAppFolder=$buildFolder/$appName newAppFolderBuild=$newAppFolder/$appType echo "appName=$appName" echo "publicUrl=$publicUrl" echo "buildFolder=$buildFolder" echo "appType=$appType" echo "Copy build folder= $currentWorkingDir/$appType" #exit echo "[OK] Creating Ionic Build to $publicUrl ..." ionic build --$publicUrl echo "[OK] Copying new build to $buildFolder ..." mkdir -p $newAppFolder cp -r $currentWorkingDir/$appType $newAppFolderBuild cd $newAppFolder packageFilePath="https://raw.githubusercontent.com/ionic-team/ionic-heroku-button/master/package.json" packageFile="package.json" echo "Downloading $packageFile ..." curl -o $packageFile $packageFilePath serverFilePath="https://raw.githubusercontent.com/ionic-team/ionic-heroku-button/master/server.js" serverFile="server.js" echo "Downloading $serverFilePath ..." curl -o $serverFile $serverFilePath echo "node_modules" > .gitignore #bash find string and replace in file #https://linuxhint.com/replace_string_in_file_bash/ # REPLACE www with build in server.js if [[ $appType == "build" ]] then # this is a react app, change the name of wwww folder to build sed -i 's/www/build/' $serverFile fi echo "[OK] Installing Dependencies..." npm install echo "[OK] Adding git to app.." git init git add . git commit -m "[Auto Generated by script] Ready for Heroku $appName" echo "[OK] Login to Heroku.." heroku login echo "[OK] Creating App in Heroku appName=$appName" heroku create $appName echo "[OK] Creating App git in Heroku" heroku git:remote -a $appName echo "[OK] Push App to Heroku" git push heroku master echo "[OK] Opening Heroku App in Browser" heroku open read -p "Do you want to open app new VS Code? [y/n]" openCode if [[] $openCode == "n"]] then echo 'Opening VS Code with build folder...' code . fi