Class: Pod::Command::JxedtCommand::Binary::Code

Inherits:
Pod::Command::JxedtCommand::Binary show all
Defined in:
lib/cocoapods-jxedt/command/binary/command/code.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Code

Returns a new instance of Code.



20
21
22
23
24
# File 'lib/cocoapods-jxedt/command/binary/command/code.rb', line 20

def initialize(argv)
    @link = argv.flag?('link', false)
    @unlink = argv.flag?('unlink', false)
    super
end

Class Method Details

.optionsObject



14
15
16
17
18
19
# File 'lib/cocoapods-jxedt/command/binary/command/code.rb', line 14

def self.options
    [
        ['--link', '创建源码软链接'],
        ['--unlink', '删除软链接'],
    ]
end

Instance Method Details



55
56
57
58
59
60
61
62
# File 'lib/cocoapods-jxedt/command/binary/command/code.rb', line 55

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

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cocoapods-jxedt/command/binary/command/code.rb', line 31

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

#validate!Object



26
27
28
29
# File 'lib/cocoapods-jxedt/command/binary/command/code.rb', line 26

def validate!
    help! "至少要添加一个选项,'--link'或'--unlink'" unless @link || @unlink
    super
end