Skip to content

Commit

Permalink
Improved the cocoapods/carthage setup part of generamba setup comma…
Browse files Browse the repository at this point in the history
…nd (Issue #50)
  • Loading branch information
Egor Tolstoy committed Dec 20, 2015
1 parent 108a1e5 commit 02f5880
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
27 changes: 15 additions & 12 deletions generamba/lib/generamba/cli/setup_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,11 @@ def setup
properties[PROJECT_NAME_KEY] = is_right_project_name ? project_name : ask_non_empty_string('The project name:', 'Project name should not be empty')
properties[PROJECT_PREFIX_KEY] = ask('The project prefix (if any):')

project_files = Dir['*.xcodeproj']
count = project_files.count
if count == 1
is_right_path = yes?("The path to a .xcodeproj file of the project is #{project_files[0]}. Do you want to use it? (yes/no)")
xcode_path = is_right_path ? project_files[0] : ask('The path to a .xcodeproj file of the project:')
else
xcode_path = ask('The path to a .xcodeproj file of the project:')
end
xcodeproj_path = ask_file_with_path('*.xcodeproj',
'.xcodeproj file of the project')

properties[XCODEPROJ_PATH_KEY] = xcode_path
project = Xcodeproj::Project.open(xcode_path)
properties[XCODEPROJ_PATH_KEY] = xcodeproj_path
project = Xcodeproj::Project.open(xcodeproj_path)

targets_prompt = ''
project.targets.each_with_index { |element, i| targets_prompt += ("#{i}. #{element.name}" + "\n") }
Expand All @@ -56,8 +50,17 @@ def setup
test_file_path = ask('The default path for creating tests (in the filesystem):')
end

properties[PODFILE_PATH_KEY] = ask('The Podfile path (if any):')
properties[CARTFILE_PATH_KEY] = ask('The Cartfile path (if any):')
using_pods = yes?('Are you using Cocoapods? (yes/no)')
if using_pods
properties[PODFILE_PATH_KEY] = ask_file_with_path('Podfile',
'Podfile')
end

using_carthage = yes?('Are you using Carthage? (yes/no)')
if using_carthage
properties[CARTFILE_PATH_KEY] = ask_file_with_path('Cartfile',
'Cartfile')
end

properties[PROJECT_TARGET_KEY] = project_target.name
properties[PROJECT_FILE_PATH_KEY] = project_file_path
Expand Down
13 changes: 13 additions & 0 deletions generamba/lib/generamba/cli/thor_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ def ask_with_validation(message, is_valid_value, description = 'Invalid value')
puts(description.red)
end
end

def ask_file_with_path(pattern, message_file_name)
project_files = Dir[pattern]
count = project_files.count
default_message = "The path to a #{message_file_name}:"
if count == 1
is_right_path = yes?"The path to a #{message_file_name} is '#{project_files[0]}'. Do you want to use it? (yes/no)"
xcode_path = is_right_path ? project_files[0] : ask(default_message)
else
xcode_path = ask(default_message)
end
return xcode_path
end
end
end
end
6 changes: 3 additions & 3 deletions generamba/lib/generamba/code_generation/Rambafile.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ test_file_path: {{ test_file_path }}{% endif %}
{% if test_group_path != "" %}# The Xcode group path to new tests
test_group_path: {{ test_group_path }}{% endif %}

{% if podfile_path != "" or cartfile_path != "" %}### Dependencies settings section{% endif %}
{% if podfile_path != "" %}podfile_path: {{ podfile_path }}{% endif %}
{% if cartfile_path != "" %}cartfile_path: {{ cartfile_path }}{% endif %}
{% if podfile_path != nil or cartfile_path != nil %}### Dependencies settings section{% endif %}
{% if podfile_path != nil %}podfile_path: {{ podfile_path }}{% endif %}
{% if cartfile_path != nil %}cartfile_path: {{ cartfile_path }}{% endif %}

### Templates
templates:
Expand Down

0 comments on commit 02f5880

Please sign in to comment.