module Pod class Command class JxedtCommand < Command class Binary < JxedtCommand class Code < Binary self.summary = '创建源码链接' self.description = <<-DESC 创建源码链接\n 在'/Users/cocoapods-jxedt'目录下创建源码的链接,用于二进制调试 DESC self.command = 'code' self.arguments = [ ] def self.options [ ['--link', '创建源码软链接'], ['--unlink', '删除软链接'], ] end def initialize(argv) @link = argv.flag?('link', false) @unlink = argv.flag?('unlink', false) super end def validate! help! "至少要添加一个选项,'--link'或'--unlink'" unless @link || @unlink super end def run podfile = Pod::Config.instance.podfile help! '请检查命令执行路径,需要在Podfile文件所在目录执行' if podfile.nil? user_path = Pathname.new('/Users/cocoapods-jxedt') help! "#{user_path} 路径不存在,源码和二进制链接只支持此路径下的文件。你可以执行`pod jxedt user --add`来添加目录" unless user_path.exist? prebuild_sandbox_path = Jxedt.config.prebuild_sandbox_path help! '请配置正确的prebuild sandbox路径' if prebuild_sandbox_path.nil? sandbox_path = Pod::Config.instance.sandbox.root prebuild_sandbox_path = Pathname.new(prebuild_sandbox_path) if @link prebuild_sandbox_path.rmtree if prebuild_sandbox_path.exist? help! '不存在Pods文件夹,请检查你的目录' unless sandbox_path.exist? make_source_link(sandbox_path, prebuild_sandbox_path) Pod::UI.puts "🎉 源码二进制软链接已添加" else prebuild_sandbox_path.rmtree if prebuild_sandbox_path.exist? Pod::UI.puts "🎉 源码二进制软链接已删除" end end def make_source_link(source, target) source = Pathname.new(source) target = Pathname.new(target) target.parent.mkpath unless target.parent.exist? target.rmtree if target.exist? relative_source = source.relative_path_from(target.parent) FileUtils.ln_sf(relative_source, target) end end end end end end