Skip to content

Instantly share code, notes, and snippets.

@eran3d
Last active February 6, 2019 22:47
Show Gist options
  • Save eran3d/12342ae9097dd24b165083cbb2eca461 to your computer and use it in GitHub Desktop.
Save eran3d/12342ae9097dd24b165083cbb2eca461 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Bash Helper Parameters
set -o errexit # Exit on uncaught errors
set -o nounset # Don't allow unset variables
set -o pipefail # Fail pipe on first error
# Variables
xcodegen_yaml="https://gist.githubusercontent.com/eran3d/61018abb8d7736a0a380fa9fda20c6f9/raw/project.yml?cachebust=xxx"
gitignore_url="https://www.gitignore.io/api/swift,xcode,cocoapods,carthage,swiftpackagemanager,fastlane"
# Bash Helper Methods
error() {
printf "%b\n" "${*:-}" 1>&2
exit 1
}
print() {
printf "%b\n" "${*:-}" 2>&1
}
cleanup() {
print "==> Cleanup"
if [[ -d "${project_name}" ]]; then
echo "Deleting existing Directory: ${project_name}..."
rm -rf "${project_name}"
fi
}
# System Dependencies
dependency() {
for executable in "$@"; do
print "Checking dependency: ${executable}..."
! type ${executable} >/dev/null 2>&1 && \
print " ---> Dependency not installed: ${executable}" 1>&2 && return 1
done; return 0
}
installBundler() {
print "==> installBundler"
local required_version=$(cat ".bundler-version")
gem install bundler -v required_version
}
installDotenv() {
print "==> installDotenv"
# if you get the error: You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
# Make sure a global version of rbenv is set
# output of rbenv global should *not* be 'system'
gem install dotenv
}
installMacPorts() {
print "==> installMacPorts"
local version="2.5.4"
curl -O "https://distfiles.macports.org/MacPorts/MacPorts-2.5.4.tar.bz2"
tar xf "MacPorts-2.5.4.tar.bz2"
cd "Macports-${version}/"
./configure
make
sudo make install
addLineToZshrc "export PATH=/opt/local/bin:/opt/local/sbin:\$PATH"
sudo port selfupdate
sudo port install ImageMagick
}
installRbenv() {
print "==> installRbenv"
local rbenv_path="$HOME/.rbenv"
local git_url="https://github.com/rbenv/rbenv.git"
echo "Installing Rbenv..."
gitClone "${git_url:-}" "${rbenv_path:-}"
cd "${rbenv_path:-}"
./src/configure
make -C "./src"
export PATH="${rbenv_path:-}/bin:$PATH"
mkdir -p "${rbenv_path:-}/plugins"
installRubyBuild
rbenv install 2.6.0
installRbenvGemset
eval "$(rbenv init -)"
}
installRbenvGemset() {
print "==> installRbenvGemset"
local rbenv_path="$HOME/.rbenv"
local rbenv_gemset_path="${rbenv_path}/plugins/rbenv-gemset"
local git_url="https://github.com/jf/rbenv-gemset.git"
echo "Installing rbenv-gemset..."
gitClone "${git_url:-}" "${rbenv_gemset_path:-}"
export PATH="${rbenv_path:-}/plugins/rbenv-gemset/bin:$PATH"
}
installRubyBuild() {
print "==> installRubyBuild"
local ruby_build_path="${rbenv_path:-}/plugins/ruby-build"
local git_url="https://github.com/rbenv/ruby-build.git"
echo "Installing Ruby-build..."
gitClone "${git_url:-}" "${ruby_build_path:-}"
export PATH="${rbenv_path:-}/plugins/ruby-build/bin:$PATH"
}
# Project Dependencies
installProjectDependencies() {
print "==> installProjectDependencies"
local required_version=$(cat ".bundler-version")
local filter='/Bundler/ {print $3;}'
local version=$(bundler --version | awk "${filter}")
# [[ "${version}" == "${required_version}" ]] || error "Wrong Bundler Version"
addLineToProfile "export LANG=en_US.UTF-8"
# install cocoapods dependencies
bundle install
bundle exec pod install
}
installXcodegen() {
print "==> installXcodegen"
git clone https://github.com/yonaskolb/XcodeGen.git
cd XcodeGen
swift run xcodegen
}
# Project Setup
gitCheckout() {
[[ "$1" ]] || return 1
git checkout "$1"
}
gitClone() {
[[ "${1:-}" ]] || return 1
[[ "${2:-}" ]] || return 1
local url="${1:-}"
local destination="${2:-}"
echo "Cloning git repo: ${url:-} to: ${destination:-}..."
git clone "${url:-}" "${destination:-}"
}
copyPrivateConfiguration() {
print "==> copyPrivateConfiguration"
cp "$HOME/Configuration+Private.swift" "PerfectStore/Source/Configuration"
}
PrepareProjectDir(){
print "==> Preparing Project Directory...${project_name}"
cleanup # remove from production
mkdir "${project_name}"
}
CreateYaml() {
print "==> CreateYaml"
curl "${xcodegen_yaml:-}" | cat >project.yml
}
CreateGitignore() {
print "==> CreateGitignore"
touch .gitignore
curl -L -s "${gitignore_url:-}" | cat >.gitignore
}
# take parameter: project name
# create project directory
# check and install dependencies
# create yaml
# create folder tree
# create gitignore
# create private configuration
# xcodegen
# podfile
# fastfile
# Take first argument and set as project_name
[[ "${1:-}" ]] || error "No Project Name Given"
project_name="${1:-}"
PrepareProjectDir "${project_name:-}"
dependency "git" || return 1
dependency "rbenv" || installRbenv || return 1
dependency "dotenv" || installDotenv || return 1
dependency "xcodegen" || installXcodegen || return 1
cd "${project_name}"
CreateYaml
CreateGitignore
mkdir sources
xcodegen generate
# struct generate
# gitClone "${git_url}" "${project_name}"
# gitCheckout "${git_branch}"
# copyPrivateConfiguration
# dependency "bundler" || installBundler || return 1
# updateFastlane
# installProjectDependencies
# bundle exec fastlane beta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment