Class: Gct::Command::Spec::Lint

Inherits:
Gct::Command::Spec show all
Defined in:
lib/gct/command/spec/lint.rb

Instance Method Summary collapse

Methods inherited from Gct::Command

#auto_add_tag, #check_branch_can_be_update, #config_gitlab, #current_branch, #file_contents, #get_project, #gitlab_error, options, run

Constructor Details

#initialize(argv) ⇒ Lint

Returns a new instance of Lint.



16
17
18
# File 'lib/gct/command/spec/lint.rb', line 16

def initialize(argv)
  super
end

Instance Method Details

#generate_podfile(pod_name, spec_path) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gct/command/spec/lint.rb', line 29

def generate_podfile(pod_name, spec_path)
  Pod::Podfile.new do
    install! 'cocoapods', :integrate_targets => false
    inhibit_all_warnings!
    source 'https://gi-dev.ccrgt.com/ios/iOSCRGTPodSource.git'
    target 'App' do
      platform :ios, 10.0
      pod pod_name, :podspec => spec_path, :inhibit_warnings => false
    end
  end
end

#lint_specObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gct/command/spec/lint.rb', line 41

def lint_spec
  spec_file = Pathname.glob('*.podspec').first
  raise "#{Dir.pwd} 目录下找不到podspec文件".red if spec_file.nil?

  spec_path = spec_file.realpath
  spec = Pod::Specification.from_file(spec_file)

  puts ''
  Pod::UI.section('校验组件循环引用'.green) do
    sandbox = Pod::Sandbox.new(Pod::Config.instance.sandbox_root)
    podfile = generate_podfile(spec.name, spec_path)
    installer = Pod::Installer.new(sandbox, podfile)
    %i(prepare resolve_dependencies download_dependencies write_lockfiles).each { |m| installer.send(m) }
  end

  puts ''
  Pod::UI.section('校验组件包含关系'.green) do
    specific_bussiness_line_pods = %w[
      GCT.R
    ].freeze
    specific_pods = []
    if spec.dependencies.length > 0
      specific_pods = spec.dependencies.select do |dep|
        specific_bussiness_line_pods.include?(dep.root_name)
      end
    end
    if spec.subspecs.length > 0 
      spec.subspecs.each do |subspec|
        new_specific_pods = []
        new_specific_pods = subspec.dependencies.select do |dep|
          specific_bussiness_line_pods.include?(dep.root_name)
        end
        specific_pods = specific_pods + new_specific_pods
      end
    end 

    if specific_pods.any?
      raise "podspec 不建议包含组件 #{specific_pods.map(&:name).join(', ')}".red
    end
    puts '业务线私有组件包含关系校验完毕'.green
  end
end

#runObject



24
25
26
27
# File 'lib/gct/command/spec/lint.rb', line 24

def run
  # system "pod lib lint --sources=#{Constant.GitURL}iOSCRGTPodSource.git --allow-warnings --verbose --skip-import-validation --use-libraries", exception: true
  lint_spec
end

#validate!Object



20
21
22
# File 'lib/gct/command/spec/lint.rb', line 20

def validate!
  super
end