Class: Swiftproj::Core
- Inherits:
-
Object
- Object
- Swiftproj::Core
- Defined in:
- lib/swiftproj/core.rb
Instance Method Summary collapse
- #add_system_framework(project, target_name, framework_path) ⇒ Object
- #configure_scheme_with_buildable_targets(scheme, buildable_target_names) ⇒ Object
- #generate_xcconfig(podspec) ⇒ Object
- #generate_xcodeproj(argv = nil) ⇒ Object
-
#initialize(ui:, shell:, file:) ⇒ Core
constructor
A new instance of Core.
- #remove_framework(project, target_name, framework_name) ⇒ Object
Constructor Details
#initialize(ui:, shell:, file:) ⇒ Core
Returns a new instance of Core.
3 4 5 6 7 |
# File 'lib/swiftproj/core.rb', line 3 def initialize(ui:, shell:, file:) @ui = ui @shell = shell @file = file end |
Instance Method Details
#add_system_framework(project, target_name, framework_path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/swiftproj/core.rb', line 34 def add_system_framework(project, target_name, framework_path) target = project.targets.find { |t| t.name == target_name } if target.nil? raise Swiftproj::NoSuchTargetError.new end build_phase = target.frameworks_build_phase if build_phase.nil? raise Swiftproj::NoFrameworksBuildPhaseError.new end file = project.new_file(framework_path) build_phase.add_file_reference(file) project.save end |
#configure_scheme_with_buildable_targets(scheme, buildable_target_names) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/swiftproj/core.rb', line 70 def configure_scheme_with_buildable_targets(scheme, buildable_target_names) action = Xcodeproj::XCScheme::BuildAction.new for entry in scheme.build_action.entries blueprint_name = entry.buildable_references[0].blueprint_name if buildable_target_names.include? blueprint_name action.add_entry(entry) end end scheme.build_action = action scheme.save! end |
#generate_xcconfig(podspec) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/swiftproj/core.rb', line 17 def generate_xcconfig(podspec) config = "CURRENT_PROJECT_VERSION = #{podspec.version}\n" if target = podspec.ios.deployment_target config += "IPHONEOS_DEPLOYMENT_TARGET = #{target}\n" end if target = podspec.osx.deployment_target config += "MACOSX_DEPLOYMENT_TARGET = #{target}\n" end if target = podspec.tvos.deployment_target config += "TVOS_DEPLOYMENT_TARGET = #{target}\n" end if target = podspec.watchos.deployment_target config += "WATCHOS_DEPLOYMENT_TARGET = #{target}\n" end @file.write("Config.xcconfig", config) end |
#generate_xcodeproj(argv = nil) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/swiftproj/core.rb', line 9 def generate_xcodeproj(argv=nil) command = "swift package generate-xcodeproj" if argv command += " " + argv.join(" ") end @shell.run(command) end |
#remove_framework(project, target_name, framework_name) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/swiftproj/core.rb', line 50 def remove_framework(project, target_name, framework_name) target = project.targets.find { |t| t.name == target_name } if target.nil? raise Swiftproj::NoSuchTargetError.new end build_phase = target.frameworks_build_phase if build_phase.nil? raise Swiftproj::NoFrameworksBuildPhaseError.new end file = build_phase.files_references.find { |f| f.path == framework_name } if file.nil? raise Swiftproj::NoFrameworkError.new end build_phase.remove_file_reference(file) project.save end |