MeetYouDevs / cocoapods-imy-bin

1.05k stars 245 forks source link

多个项目bin_xx.yml配置如何配置? #113

Open y2kbug opened 3 years ago

y2kbug commented 3 years ago

从ReadMe上看到只能配置环境 dev / debug_iphoneos / release_iphoneos , bin+xx.yml 默认都是在.cocoapods目录下,多个项目初始化会覆盖,如何配置多个项目呢?

miroda commented 3 years ago

这个问题提的好,是新需求啊

dabing1022 commented 3 years ago

嗯 是新的需求

dabing1022 commented 3 years ago

不过可以通过另外的方式来实现,下面我分析下:

def config_file_with_configuration_env(configuration_env)
      file = config_dev_file
      if configuration_env == "release_iphoneos"
        file = config_release_iphoneos_file
        puts "\n======  #{configuration_env} 环境 ========"
      elsif configuration_env == "debug_iphoneos"
        file = config_debug_iphoneos_file
        puts "\n======  #{configuration_env} 环境 ========"
      elsif configuration_env == "dev"
        puts "\n======  #{configuration_env} 环境 ========"
      else
        raise "\n=====  #{configuration_env} 参数有误,请检查%w[dev debug_iphoneos release_iphoneos]===="
      end

      File.expand_path("#{Pod::Config.instance.home_dir}/#{file}")
    end

注意这里的配置文件地址 File.expand_path("#{Pod::Config.instance.home_dir}/#{file}"), 而Pod::Config.instance.home_dir是可以自定义的,可以看

# cocoapods/config.rb
    def home_dir
      @home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || '~/.cocoapods').expand_path
    end

所以你每次不同项目操作的时候,使用CP_HOME_DIR=/Users/XXX/AAAProject pod bin init(auto、install、update)等操作就会带上CP_HOME_DIR自定义路径。可以通过自定义路径将不同项目区分开来。

但目前imy-bin存在一个小问题,这个自定义路径(文件夹)需要提前创建好,不然会报Errno::ENOENT - No such file or directory @ rb_sysopen - XX/XX/XX/XX路径不存在问题。主要问题出在

# imy-bin
# cocoapods-imy-bin/config/config.rb
    def sync_config(config)
      File.open(config_file_with_configuration_env(config['configuration_env']), 'w+') do |f|
        f.write(config.to_yaml)
      end
    end

这里写配置的时候直接File.open了,但可能文件夹还没创建好。暂时可以先把自定义路径的文件夹创建好。

dabing1022 commented 3 years ago

上面的方式虽然可以解决问题,但稍显丑陋。未来可能会通过pod bin 参数的形式来支持不同项目。