# frozen_string_literal: true require 'yaml' require 'xcodeproj' module GoNative module Plugins module IOS class EmbedScripts TARGET_SCRIPTS_FILE_NAME = 'target_scripts.yml' extend DSL::Serviceable autoload :FileUtils, 'fileutils' attr_reader :scripts def call prepare_scripts return unless scripts? embed_in_project end def scripts? !scripts.empty? end def prepare_scripts scripts_paths = `find ./Pods -name #{TARGET_SCRIPTS_FILE_NAME}`.split("\n") @scripts = scripts_paths .map { |path| YAML.load_file(path)['scripts'] } .flatten end def embed_in_project proj = Xcodeproj::Project.open('MedianIOS.xcodeproj') app_target = proj.native_targets.first scripts.each do |script| app_target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase).tap do |phase| phase.name = script['name'] || 'New Run Script Phase' phase.input_paths = script['input_paths'] phase.output_paths = script['output_paths'] phase.shell_path = script['shell_path'] phase.shell_script = script['shell_script'] app_target.build_phases << phase end end proj.save end end end end end