Skip to content

Commit

Permalink
Add support for bundler dependency manager
Browse files Browse the repository at this point in the history
Bundler was already around in the codebase with a Gemfile, but now it can explicitly included or excluded (default excluded). It copies the Gemfile and runs `bundle install`. It is enabled with the command line flag `--dependency-managers bundler` or in .liftoffrc: `dependency_managers: bundler`

Bundler comes first in the setup script because cocoapods can be installed via bundler.

Support bundler through the rest of the codebase

Shorten options line length

Format liftoffrc manpage

Reorder bundler in script

Bundler is used to install cocoapods so it should come first
  • Loading branch information
edwardloveall authored and gfontenot committed May 20, 2016
1 parent 5ab7846 commit 8439456
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 8 deletions.
1 change: 0 additions & 1 deletion defaults/liftoffrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ run_script_phases:

templates:
- travis.yml: .travis.yml
- Gemfile.rb: Gemfile
- test.sh: bin/test
- setup.sh: bin/setup
- README.md: README.md
Expand Down
1 change: 1 addition & 0 deletions lib/liftoff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'liftoff/cli'
require "liftoff/dependency_manager_coordinator"
require "liftoff/dependency_manager"
require "liftoff/dependency_managers/bundler"
require "liftoff/dependency_managers/carthage"
require "liftoff/dependency_managers/cocoapods"
require "liftoff/dependency_managers/null_dependency_manager"
Expand Down
4 changes: 3 additions & 1 deletion lib/liftoff/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ 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,carthage') do |list|
opts.on('--dependency-managers [NAME(s)]',
"Comma separated list of dependency managers to enable.\
Available options: cocoapods,carthage,bundler") do |list|
@options[:dependency_managers] = (list || "").split(",")
end

Expand Down
32 changes: 32 additions & 0 deletions lib/liftoff/dependency_managers/bundler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Liftoff
class Bundler < DependencyManager
def setup
if bundler_installed?
move_gemfile
else
puts "Please install Bundler or disable bundler from liftoff"
end
end

def install
if bundler_installed?
run_bundle_install
end
end

private

def bundler_installed?
system("which bundle > /dev/null")
end

def move_gemfile
FileManager.new.generate("Gemfile.rb", "Gemfile", config)
end

def run_bundle_install
puts "Running bundle install"
system("bundle install")
end
end
end
10 changes: 9 additions & 1 deletion lib/liftoff/launchpad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def dependency_manager_coordinator
end

def dependency_managers
@dependency_managers ||= [cocoapods, carthage]
@dependency_managers ||= [cocoapods, carthage, bundler]
end

def cocoapods
Expand All @@ -142,5 +142,13 @@ def carthage
NullDependencyManager.new(@config)
end
end

def bundler
if @config.dependency_manager_enabled?("bundler")
Bundler.new(@config)
else
NullDependencyManager.new(@config)
end
end
end
end
12 changes: 7 additions & 5 deletions man/liftoffrc.5
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,18 @@ affect the default templates. If you choose to be incorrect with your
indentation settings, we recommend that you also override the default templates
in order to be consistently wrong.
.It Ic dependency_managers
type: array
type: array
.br
default:
.Ic cocoapods
.Pp
Specify the dependency managers to use.
.Pp
Currently, this accepts
.Ic cocoapods
.Ic cocoapods ,
.Ic carthage ,
and/or
.Ic carthage
.Ic bundler
as options. For each dependency manager listed,
.Ic liftoff
will install the default dependency file, as well as perform any necessary
Expand Down Expand Up @@ -492,9 +493,10 @@ This template is installed to
.Pa Gemfile ,
and contains a set of default gems for use with the project. Right now, it
contains
.Ic CocoaPods
.Ic XCPretty
and
.Ic XCPretty .
.Ic CocoaPods
if the cocoapods dependency manager is enabled.
.It Pa test.sh
This template is installed to
.Pa bin/test
Expand Down
70 changes: 70 additions & 0 deletions spec/dependency_managers/bundler_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require "spec_helper"

RSpec.describe Liftoff::Bundler do
describe "#setup" do
it "checks to see if bundler is installed" do
system_call = "which bundle > /dev/null"
bundler = Liftoff::Bundler.new(:config)
allow(bundler).to receive(:system).with(system_call)

bundler.setup

expect(bundler).to have_received(:system).with(system_call)
end

context "when bundler is installed" do
it "asks FileManager to move the Gemfile" do
bundler = Liftoff::Bundler.new(:config)
allow(bundler).to receive(:bundler_installed?).and_return(true)
arguments = ["Gemfile.rb", "Gemfile", :config]
file_manager = double("FileManager")
allow(Liftoff::FileManager).to receive(:new).and_return(file_manager)
allow(file_manager).to receive(:generate).with(*arguments)

bundler.setup

expect(file_manager).to have_received(:generate).with(*arguments)
end
end

context "when bundler is not installed" do
it "puts a message out to the system" do
bundler = Liftoff::Bundler.new(:config)
output_string = "Please install Bundler or disable bundler from liftoff"
allow(bundler).to receive(:bundler_installed?).and_return(false)
allow(bundler).to receive(:puts).with(output_string)

bundler.setup

expect(bundler).to have_received(:puts).with(output_string)
end
end
end

describe "#install" do
context "if bundler is installed" do
it "runs bundle install" do
bundler = Liftoff::Bundler.new(:config)
allow(bundler).to receive(:bundler_installed?).and_return(true)
system_call = "bundle install"
allow(bundler).to receive(:system).with(system_call)

bundler.install

expect(bundler).to have_received(:system).with(system_call)
end
end

context "if bundler is not installed" do
it "does not run bundle install" do
bundler = Liftoff::Bundler.new(:config)
allow(bundler).to receive(:bundler_installed?).and_return(false)
allow(bundler).to receive(:system)

bundler.install

expect(bundler).not_to have_received(:system)
end
end
end
end
2 changes: 2 additions & 0 deletions templates/setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash

<% if dependency_manager_enabled?("bundler") %>
bundle install
<% end %>
<% if enable_settings && dependency_manager_enabled?("cocoapods") %>
pod install
<% end %>
Expand Down

0 comments on commit 8439456

Please sign in to comment.