Skip to content

Commit

Permalink
Changed build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hzalaz committed Sep 14, 2015
1 parent e153227 commit eef6afd
Show file tree
Hide file tree
Showing 14 changed files with 475 additions and 294 deletions.
4 changes: 4 additions & 0 deletions script/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

PROJECT_NAME=JWTDecode
XCODE_WORKSPACE=JWTDecode.xcworkspace
XCODE_PROJECT=
18 changes: 0 additions & 18 deletions script/LICENSE.md

This file was deleted.

82 changes: 0 additions & 82 deletions script/README.md

This file was deleted.

230 changes: 205 additions & 25 deletions script/bootstrap
Original file line number Diff line number Diff line change
@@ -1,47 +1,227 @@
#!/bin/bash

export SCRIPT_DIR=$(dirname "$0")
set -e

##
## Bootstrap Process
##

main ()
install_homebrew ()
{
local submodules=$(git submodule status)
local result=$?
if [ -z $GITHUB_ACCESS_TOKEN ]
then
export HOMEBREW_GITHUB_API_TOKEN=$GITHUB_ACCESS_TOKEN
fi

if type brew > /dev/null
then
echo " ✔ brew is already installed"
echo ""
echo " → Updating homebrew formulas"
brew update > /dev/null || brew update > /dev/null
echo " ✔ formulas updated"
else
command -v ruby >/dev/null 2>&1 || { echo >&2 "Error: Some ruby of version is required to install homebrew. Aborting"; exit 1; }
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
}

if [ "$result" -ne "0" ]
# param $1 formula name
# param $2 [optional] tap path
brew_install ()
{
formula_version=`brew list --versions $1`
if [ -z "$formula_version" ]
then
if [ -z $2 ]
then
exit $result
formula_name=$1
else
formula_name="$2/$1"
fi
echo ""
echo " → Installing brew formula $formula_name"
brew install -v $formula_name > /dev/null 2>&1

if [ -n "$submodules" ]
# Extract version
regexp="^.*([0-9]\.[0-9]\.[0-9]).*$"
installed_version=""
eval "output=\"$(brew info $1)\""
if [[ $output =~ $regexp ]]
then
echo "*** Updating submodules..."
update_submodules
installed_version=${BASH_REMATCH[1]}
fi

echo "$formula_name $installed_version has been installed"
else
echo "$1 is already installed"
fi
}

bootstrap_submodule ()
print_gem_install_cmd ()
{
local bootstrap="script/bootstrap"

if [ -e "$bootstrap" ]
regexp="gem ['\"]([a-zA-Z0-9_-]+)['\"](,.*)?"
gems=""
while read -r line
do
if [[ $line =~ $regexp ]]
then
echo "*** Bootstrapping $name..."
"$bootstrap" >/dev/null
else
update_submodules
gems="$gems ${BASH_REMATCH[1]}"
fi
done < Gemfile

echo ""
echo " $> 'sudo gem install$gems'"
echo ""
}

bundle_install ()
{
echo ""
echo " → Installing gems"
echo ""
if type bundle > /dev/null
then
bundle install
else
# TODO ask user if he/she wants the script to try to install
# rbenv, ruby and bundler.
printf "\033[1;33m⚠ WARNING: Ruby gems in Gemfile could not be installed because 'bundler' is not available.\n" \
"You should install rbenv or rvm and bundler" \
"or try to install the gems globally by running the following command:"
print_gem_install_cmd
printf "\033[0m"
fi
}

install_git_hooks ()
{
if [ ! -z "$INSTALL_GITHOOKS" ]
then
echo ""
echo " → Installing git hooks"
echo ""
for hook in script/git_hooks/*
do
cp $hook .git/hooks
echo "$hook successfully installed"
done
echo ""
fi
}

bootstrap_carthage ()
{
echo ""
echo " → Bootstrapping Carthage"
echo ""
carthage_cmd="time carthage bootstrap --platform ios"

if [ "$USE_SSH" == "true" ]
then
carthage_cmd="$carthage_cmd --use-ssh"
fi
if [ "$USE_SUBMODULES" == "true" ]
then
carthage_cmd="$carthage_cmd --use-submodules --no-build"
fi
eval $carthage_cmd
}

bootstrap_cocoapods ()
{
echo ""
echo " → Bootstrapping Cocoapods"
echo ""
if type bundle > /dev/null && bundle show pod > /dev/null
then
bundle exec pod install
else
pod install
fi
}

echo_submodule_name ()
{
echo "$name successfully initialized"
}

update_submodules ()
init_submodules ()
{
git submodule sync --quiet && git submodule update --init && git submodule foreach --quiet bootstrap_submodule
echo ""
echo " → Initializing submodules ..."
echo ""
git submodule update --quiet --init --recursive > /dev/null
git submodule foreach --quiet echo_submodule_name
}

install_dependencies ()
{
echo ""
echo " → Installing dependencies"
echo ""
install_homebrew
brew_install "xcode-coveralls" "macmade/tap"

if [ -f script/script_hooks/bootstrap ]
then
script/script_hooks/bootstrap
fi
}

main ()
{
source script/.env

echo ""
echo " Bootstrapping $PROJECT_NAME"
echo ""

install_git_hooks
install_dependencies

if [ -f Cartfile ]
then
brew_install "carthage"
bootstrap_carthage
fi

if [ -f Gemfile ]
then
bundle_install
fi

if [ -f Podfile ]
then
bootstrap_cocoapods
fi

if [ -f .gitmodules ]
then
init_submodules
fi

open_file_name=""
if [ -z "$XCODE_WORKSPACE" ]
then
open_file_name=$XCODE_PROJECT
else
open_file_name=$XCODE_WORKSPACE
fi

echo ""
echo " $PROJECT_NAME successfully bootstrapped"
echo ""
echo " Usefull scripts:"
echo ""
echo " * 'script/test' to run tests."
echo " * 'script/build' to build the project."
echo " * 'script/update' to update project's dependencies."
echo ""
echo " You can start hacking by executing:"
echo ""
echo " open $open_file_name"
echo ""
}

export -f bootstrap_submodule
export -f update_submodules
export -f init_submodules
export -f echo_submodule_name
export -f brew_install

main
Loading

0 comments on commit eef6afd

Please sign in to comment.