Created
June 8, 2017 00:05
-
-
Save denvazh/9f5a76d00f6f53d17b900a2eb24ff34b to your computer and use it in GitHub Desktop.
Create build configuration in the library xcode project using same name and type as parent one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pathname' | |
require 'ostruct' | |
require 'bundler/setup' | |
require 'json' | |
require 'xcodeproj' | |
PLATFORM = :ios | |
APP_ROOT = Pathname.new(File.join(File.dirname(__FILE__), '..')) | |
APP_CONFIG = OpenStruct.new(JSON.parse(File.read(APP_ROOT.join('app.json')))) | |
raise('Run "npm install" before executing this script') unless Dir.exist?(APP_ROOT.join('node_modules')) | |
project_path = APP_ROOT.join(PLATFORM.to_s).children.find do |c| | |
c.to_s == File.join(File.dirname(c), "#{APP_CONFIG.name}.xcodeproj") | |
end | |
# open parent project | |
root_project = Xcodeproj::Project.open(project_path) | |
# read project dependencies | |
groups = root_project.groups.select { |g| g.name = 'Libraries' } | |
refs = groups.map(&:children).flatten.select { |ref| ref.isa == 'PBXFileReference' && ref.path.end_with?('xcodeproj') } | |
dependencies = refs.map { |r| Xcodeproj::Project.open(APP_ROOT.join(PLATFORM.to_s).join(r.path)) } | |
# mirror build configurations from root project to related dependencies | |
build_configs = root_project.build_configurations.reject { |bc| bc.name == 'Debug' || bc.name == 'Release' } | |
dependencies.each do |d| | |
build_configs.each do |cf| | |
if d.build_configurations.find { |bc| bc.name == cf.name && bc.type == cf.type } | |
puts "Build configuration #{cf.name} already exists in #{File.basename(d.path)}" | |
else | |
puts "Adding the following build configuration to #{File.basename(d.path)}: #{cf.name}(#{cf.type})" | |
d.add_build_configuration(cf.name, cf.type) | |
end | |
end | |
d.save | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment