Class: BB::StableEnv

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb

Instance Method Summary collapse

Constructor Details

#initializeStableEnv

Returns a new instance of StableEnv.



5
6
7
8
9
10
# File 'lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb', line 5

def initialize()
    @cache = BB::Cache.new()
    configGitPath(@cache.cachePath)
    # 自动加载stable环境
    loadStaleEnv
end

Instance Method Details

#business_stableObject



71
72
73
# File 'lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb', line 71

def business_stable
  return @businessSpec
end

#loadStaleEnvObject

stable 环境,执行pod stable



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb', line 13

def loadStaleEnv
  unless File.exist?(File.join(Pathname.pwd, "Podfile"))
    err_msg = "- Error: #{File.join(Pathname.pwd, "Podfile")} is not exit"
    Pod::UI.puts "#{err_msg}".send(:red)
    exit -9001
  end

  #获取podfile 内容
  #1、删除所有注释行,避免干扰
  #2、正则匹配,筛选出stable 方法
  #3、执行stable 方法,获取配置
  podfileContent = File.read(File.join(Pathname.pwd, "Podfile"))
  podfileContent_vaild = podfileContent.lines.reject { |line| line.strip.start_with?("#") }.join
  stableCommand = podfileContent_vaild.match(/^\s*stable!\s*'([^']+)'(?:,\s*(\w+):\s*'([^']+)')*/m)
  unless stableCommand
    puts "- Error: not stable define in the podfile! you can define to podfile:".red
    puts "stable! 'https://git.babybus.co/babybus/ios/Specs/stable-specs.git', specs:'<业务线stbale名称-可选>', tag:'<标签-可选>', branch:'<分支-可选>'".green
    exit -9002
  end
  eval(stableCommand.to_s)
end

#stable!(source, options = {}) ⇒ Object

podfile 约定函数规则,切勿修改

help load podfile option



52
53
54
55
56
57
58
59
60
# File 'lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb', line 52

def stable!(source, options = {})
  @stable_source = source
  if options.has_key?(:specs) 
    @businessSpec = options[:specs]
  end
  @stable_tag = options[:tag] if options.has_key?(:tag) 
  @stable_branch = options[:branch] if options.has_key?(:branch)
  puts "###stable env => [stable公共源]:#{source} [业务线源名称]:#{@businessSpec} branch:#{@stable_branch} tag:#{@stable_tag}".yellow
end

#stable_branchObject



65
66
67
# File 'lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb', line 65

def stable_branch
  return @stable_branch
end

#stable_sourceObject



62
63
64
# File 'lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb', line 62

def stable_source
  return @stable_source
end

#stable_tagObject



68
69
70
# File 'lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb', line 68

def stable_tag
  return @stable_tag
end

#system_clone_stable_gitObject

拉取stable仓库代码 hook开发环境,执行pod install/update



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb', line 36

def system_clone_stable_git
    cachePath = @cache.cachePath
    puts "hook [pod install/update] fetch stable git=>#{cachePath}"
    if Dir.exist?(File.join(cachePath))
      # `cd #{cachePath}; git switch main; git pull --all`
      system "cd #{cachePath}; git switch main; git pull --all"
    else
      clonePath = File.dirname(cachePath)
      FileUtils.mkdir_p clonePath
      # `git clone #{@stable_source} #{cachePath}`
      system "git clone #{@stable_source} #{cachePath}"
    end
end

#verify_stable_env_existsObject

验证stable环境是否存在



75
76
77
# File 'lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb', line 75

def verify_stable_env_exists
  return @stable_source.empty? ? false : true
end