Sha256: 44f3e5f49ccb7118cc98a354dc30b1bf59f8cc131a0941d34635b16471a6c899

Contents?: true

Size: 1.95 KB

Versions: 14

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

require 'xcodeproj'
require 'cfpropertylist'

module GoNative
  module Plugins
    module IOS
      class SetBundleId
        extend DSL::Serviceable
        
        attr_reader :bundle_id
        
        def initialize(bundle_id, update_entitlements)
          @bundle_id = bundle_id
          @update_entitlements = update_entitlements
        end
        
        def call
          update_project
          update_entitlements if update_entitlements?
        end
        
        def update_project
          proj = Xcodeproj::Project.open('./GoNativeIOS.xcodeproj')
          proj.targets.each do |target|
            case target.product_type
            when Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application]
              set_target_bundle_id(target, bundle_id)
            when Xcodeproj::Constants::PRODUCT_TYPE_UTI[:app_extension]
              set_target_bundle_id(target, bundle_id + '.' + target.name)
            else
              next
            end
          end
          
          proj.save
        end
        
        def update_entitlements
          entitlement_files = `find -E . -maxdepth 2 -regex ".*\.(entitlements)"`.split("\n")
          entitlement_files.each do |entitlement_file|
            plist = CFPropertyList::List.new(file: entitlement_file)
            entitlements = CFPropertyList.native_types(plist.value)
            entitlements['com.apple.security.application-groups'] = ['group.' + bundle_id]
            plist.value = CFPropertyList.guess(entitlements)
            plist.save(entitlement_file, CFPropertyList::List::FORMAT_XML)
          end
        end
        
        private
          
        def set_target_bundle_id(target, bundle_id)
          target.build_configurations.each do |config|
            config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = bundle_id
          end
        end
        
        def update_entitlements?
          @update_entitlements
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
gonative-cli-1.1.2 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.1.1 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.1.0 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.0.6 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.0.5 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.0.4 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.0.3 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.0.2 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.0.1 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.0.0 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-0.9.3 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-0.9.2 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-0.9.1 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-0.9.0 lib/gonative/plugins/ios/set_bundle_id.rb