Class: DevEnvUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/dev_env_utils.rb

Class Method Summary collapse

Class Method Details

.addGitTagAndPush(tag, pod_name) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/dev_env_utils.rb', line 78

def self.addGitTagAndPush(tag, pod_name)
  ret = system("git tag #{tag}")
  if ret == true
    ret = system("git push origin #{tag}")
    raise "💔 #{pod_name.yellow} push tag 失败" if ret != true
  end
  ret
end

.changeVersionInCocoapods(name, newVersion) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/dev_env_utils.rb', line 108

def self.changeVersionInCocoapods(name, newVersion)
  if newVersion.nil?
    Pod::UI.puts '💔 传入的修改目标版本号为空,无法设置版本号'.yellow
    return
  end
  newVersion = get_pure_version(newVersion)
  specName = name + '.podspec'
  FileProcesserManager.new(specName,
                           [
                              FileProcesser.new(lambda { |fileContent|
                                                 return fileContent.gsub(/(\.version *= *')(.*')/,
                                                                         '\\1' + newVersion + "'")
                                               }),
                              FileProcesser.new(lambda { |fileContent|
                                                 return fileContent.gsub(/(\.version *= *")(.*")/,
                                                                         '\\1' + newVersion + '"')
                                               })
                           ]).process
  `git add #{specName}
       git commit -m "Mod: 修改版本号为:#{newVersion} by cocoapods_dev_env plugin"`
end

.checkAndRemoveSubmodule(path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dev_env_utils.rb', line 17

def self.checkAndRemoveSubmodule(path)
  _currentDir = Dir.pwd
  Dir.chdir(path)
  output = `git status -s`
  puts output
  if output.length == 0
    output = `git status`
    raise "submodule #{path} 移除失败,有推送的修改" if output.include?('push')
  else
    raise "submodule #{path} 移除失败,有未提交的修改"
  end
  Dir.chdir(_currentDir)
  `
      git submodule deinit #{path}
      rm -rf #{path}
      git rm #{path}
      `
end

.checkGitStatusAndPush(pod_name) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dev_env_utils.rb', line 59

def self.checkGitStatusAndPush(pod_name)
  output = `git status -s`
  puts output
  if output.length == 0
    output = `git status`
    if output.include?('push')
      ret = system('git push')
      raise "💔 #{pod_name.yellow} push 失败" if ret != true
    end
  else
    raise "💔 #{pod_name.yellow} 有未提交的数据"
  end
end

.checkIsOnTrankBrachObject

检查是否在主分支上(main / master)



97
98
99
100
101
102
103
104
105
106
# File 'lib/dev_env_utils.rb', line 97

def self.checkIsOnTrankBrach()
  branch = `git branch --show-current`.chomp
  isOK = (branch == 'main' || branch == 'master')
  if !isOK
    puts ('💔 当前分支是: '.red + branch.green + ' 没在主分支,不符合规范,是否继续发布?'.red)
    if !inputNeedJumpForReson("")
      raise "已取消发布, 请切换子库分支到 master / main 后重新 pod install"
    end
  end
end

.checkRemoteTagExist(tag) ⇒ Object



73
74
75
76
# File 'lib/dev_env_utils.rb', line 73

def self.checkRemoteTagExist(tag)
  `git push --tags`
  system("git ls-remote --exit-code origin refs/tags/#{tag}")
end

.checkTagIsEqualToHead(tag, path) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dev_env_utils.rb', line 36

def self.checkTagIsEqualToHead(tag, path)
  _currentDir = Dir.pwd
  Dir.chdir(path)
  result = `git describe --abbrev=4 HEAD`
  Dir.chdir(_currentDir)
  if result.include?(tag)
    true
  else
    checkTagOrBranchIsEqalToHead(tag, path)
  end
end

.checkTagOrBranchIsEqalToHead(branchOrTag, path) ⇒ Object

这个函数有问题有时候拿不到相同的commit id



49
50
51
52
53
54
55
56
57
# File 'lib/dev_env_utils.rb', line 49

def self.checkTagOrBranchIsEqalToHead(branchOrTag, path)
  _currentDir = Dir.pwd
  Dir.chdir(path)
  headCommitID = `git rev-parse HEAD`
  tagCommitID = `git rev-parse #{branchOrTag}`
  Pod::UI.puts "#{`pwd`}  headCommitID:#{headCommitID} \n #{branchOrTag}ComitID:#{tagCommitID}"
  Dir.chdir(_currentDir)
  (headCommitID.length > 0 && headCommitID == tagCommitID)
end

.get_pure_version(version) ⇒ Object



130
131
132
# File 'lib/dev_env_utils.rb', line 130

def self.get_pure_version(version)
  version.split.last.scan(/\d+/).join('.')
end

.inputNeedJumpForReson(str) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/dev_env_utils.rb', line 87

def self.inputNeedJumpForReson(str)
  return false if ARGV.include? '--silent'

  puts str.green
  puts '是(Y), 任意其他输入或直接回车跳过'.green
  input = STDIN.gets
  input[0, 1] == 'Y'
end

.searchAndOpenLocalExample(path) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/dev_env_utils.rb', line 4

def self.searchAndOpenLocalExample(path)
  _currentDir = Dir.pwd
  Dir.chdir(path)
  Dir.chdir('Example')
  `pod install`
  projPaths = Dir.glob('*.xcworkspace')
  if projPaths.count > 0
    `open -a Terminal ./`
    `open #{projPaths[0]}`
  end
  Dir.chdir(_currentDir)
end