From aca930445cad398e8446e3ab8d9110885cc4e3fb Mon Sep 17 00:00:00 2001 From: Jake Craige Date: Mon, 25 May 2015 12:38:07 -0700 Subject: [PATCH] Add Carthage support Added carthage as a dependency manager. What it does: - Adds an empty `Cartfile` - Runs `carthage update` - Adds the `copy-frameworks.sh` build phase to the project - Adds `carthage update` to `bin/setup` script --- lib/liftoff.rb | 1 + lib/liftoff/cli.rb | 2 +- lib/liftoff/dependency_managers/carthage.rb | 41 +++++++++++++++++++++ lib/liftoff/launchpad.rb | 14 +++++-- templates/Cartfile | 0 templates/Gemfile.rb | 2 + templates/copy_frameworks.sh | 1 + templates/gitignore | 1 + templates/setup.sh | 5 +++ 9 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 lib/liftoff/dependency_managers/carthage.rb create mode 100644 templates/Cartfile create mode 100644 templates/copy_frameworks.sh diff --git a/lib/liftoff.rb b/lib/liftoff.rb index 4fdd189..e85cac7 100644 --- a/lib/liftoff.rb +++ b/lib/liftoff.rb @@ -11,6 +11,7 @@ require 'liftoff/cli' require "liftoff/dependency_manager_coordinator" require "liftoff/dependency_manager" +require "liftoff/dependency_managers/carthage" require "liftoff/dependency_managers/cocoapods" require "liftoff/dependency_managers/null_dependency_manager" require 'liftoff/settings_generator' diff --git a/lib/liftoff/cli.rb b/lib/liftoff/cli.rb index fb81130..fca589e 100644 --- a/lib/liftoff/cli.rb +++ b/lib/liftoff/cli.rb @@ -35,7 +35,7 @@ def global_options @options[:strict_prompts] = strict_prompts end - opts.on('--dependency-managers [NAME(s)]', 'Comma separated list of dependency managers to enable. Available options: cocoapods') do |list| + opts.on('--dependency-managers [NAME(s)]', 'Comma separated list of dependency managers to enable. Available options: cocoapods,carthage') do |list| @options[:dependency_managers] = (list || "").split(",") end diff --git a/lib/liftoff/dependency_managers/carthage.rb b/lib/liftoff/dependency_managers/carthage.rb new file mode 100644 index 0000000..88a7f75 --- /dev/null +++ b/lib/liftoff/dependency_managers/carthage.rb @@ -0,0 +1,41 @@ +module Liftoff + class Carthage < DependencyManager + def setup + if carthage_installed? + move_cartfile + else + puts 'Please install Carthage or disable carthage from liftoff' + end + end + + def install + if carthage_installed? + run_carthage_update + end + end + + def run_script_phases + [ + { + "file" => "copy_frameworks.sh", + "name" => "Copy framworks (Carthage)", + } + ] + end + + private + + def carthage_installed? + system('which carthage > /dev/null') + end + + def move_cartfile + FileManager.new.generate('Cartfile', 'Cartfile', @config) + end + + def run_carthage_update + puts 'Running carthage update' + system('carthage update') + end + end +end diff --git a/lib/liftoff/launchpad.rb b/lib/liftoff/launchpad.rb index 5f78f21..dbb83e2 100644 --- a/lib/liftoff/launchpad.rb +++ b/lib/liftoff/launchpad.rb @@ -16,7 +16,7 @@ def liftoff(options) setup_dependency_managers generate_templates generate_settings - install_dependency_managers + install_dependencies perform_project_actions open_project end @@ -51,7 +51,7 @@ def setup_dependency_managers dependency_manager_coordinator.setup_dependencies end - def install_dependency_managers + def install_dependencies dependency_manager_coordinator.install_dependencies end @@ -124,7 +124,7 @@ def dependency_manager_coordinator end def dependency_managers - @dependency_managers ||= [cocoapods] + @dependency_managers ||= [cocoapods, carthage] end def cocoapods @@ -134,5 +134,13 @@ def cocoapods NullDependencyManager.new(@config) end end + + def carthage + if @config.dependency_manager_enabled?("carthage") + Carthage.new(@config) + else + NullDependencyManager.new(@config) + end + end end end diff --git a/templates/Cartfile b/templates/Cartfile new file mode 100644 index 0000000..e69de29 diff --git a/templates/Gemfile.rb b/templates/Gemfile.rb index 43c41f9..e5e1b9e 100644 --- a/templates/Gemfile.rb +++ b/templates/Gemfile.rb @@ -1,4 +1,6 @@ source 'https://rubygems.org' +<% if enable_settings && dependency_manager_enabled?("cocoapods") %> gem 'cocoapods' +<% end %> gem 'xcpretty' diff --git a/templates/copy_frameworks.sh b/templates/copy_frameworks.sh new file mode 100644 index 0000000..b03ada0 --- /dev/null +++ b/templates/copy_frameworks.sh @@ -0,0 +1 @@ +/usr/local/bin/carthage copy-frameworks diff --git a/templates/gitignore b/templates/gitignore index c6b1a70..e108a5c 100644 --- a/templates/gitignore +++ b/templates/gitignore @@ -26,6 +26,7 @@ build/ # Cocoapods Pods +Carthage # AppCode specific files .idea/ diff --git a/templates/setup.sh b/templates/setup.sh index 450c3ce..9df6560 100755 --- a/templates/setup.sh +++ b/templates/setup.sh @@ -1,4 +1,9 @@ #!/usr/bin/env bash bundle install +<% if enable_settings && dependency_manager_enabled?("cocoapods") %> pod install +<% end %> +<% if dependency_manager_enabled?("carthage") %> +carthage update +<% end %>