Sha256: c52365e9188c8b67dc05d6ba6a2d6b950521c96c8875214ac4ecb858e9f9924b

Contents?: true

Size: 1.87 KB

Versions: 15

Compression:

Stored size: 1.87 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('./MedianIOS.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

15 entries across 15 versions & 1 rubygems

Version Path
gonative-cli-1.4.4 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.4.3 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.4.2 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.4.1 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.4.0 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.3.9 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.3.8 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.3.7 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.3.6 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.3.5 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.3.4 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.3.3 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.3.2 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.3.1 lib/gonative/plugins/ios/set_bundle_id.rb
gonative-cli-1.3.0 lib/gonative/plugins/ios/set_bundle_id.rb