module Pod class Command class JxedtCommand < Command class Binary < JxedtCommand class Code < Binary self.summary = 'binary and source code linked.' self.description = <<-DESC binary and source code linked. DESC self.command = 'code' self.arguments = [ ] def self.options [ ['--link', 'link source code.'], ['--unlink', 'Remove source code linked.'], ] end def initialize(argv) @link = argv.flag?('link', false) @unlink = argv.flag?('unlink', false) super end def validate! help! "Please enter the necessary options." 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