Module: Fastlane::Tools

Defined in:
lib/fastlane/plugin/rocket/tools/file.rb,
lib/fastlane/plugin/rocket/tools/clone.rb,
lib/fastlane/plugin/rocket/tools/shell.rb,
lib/fastlane/plugin/rocket/tools/config.rb,
lib/fastlane/plugin/rocket/tools/message.rb

Constant Summary collapse

ROCKET_PATH =

脚本生成相关文件存放的地址

"/Users/Shared/rocket-cache/"
SOURCESPECS =

源码repo

"[email protected]:cocoapods/HDSourceSpecs.git"

Class Method Summary collapse

Class Method Details

.clone(git, branch, path, throw_exception = true) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fastlane/plugin/rocket/tools/clone.rb', line 9

def self.clone(git,branch,path,throw_exception=true)
  #如果存在缓存,就删除缓存
  Tools.delete_path(path)
  url = "git clone #{git} #{path} --template= --single-branch --depth 1 --branch #{branch}"
  status = Tools.shell(url,throw_exception)
  unless status == true
      #--depth 1 , 如果branch没有提交,将会导致拉取失败。去掉--depth 1 解决此问题
      url = "git clone #{git} #{path} --template= --single-branch --branch #{branch}"
      status = Tools.shell(url,throw_exception)
  end

  Tools.log(url)
  return status
end

.delete_path(path) ⇒ Object



5
6
7
8
9
# File 'lib/fastlane/plugin/rocket/tools/file.rb', line 5

def self.delete_path(path)
  if File.exist?(path) then
    FileUtils.rm_rf(path)
  end
end

.deleteDirPath(dirPath, ignores = [], f = "") ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fastlane/plugin/rocket/tools/file.rb', line 11

def self.deleteDirPath(dirPath,ignores=[],f="")
  if File.directory?(dirPath)
    Dir.foreach(dirPath) do |subFile|
      if subFile != '.' and subFile != '..'
          deleteDirPath(File.join(dirPath, subFile),ignores,f);
      end
    end
    ignores.each do |i|
      if dirPath == i
          return
      end
    end
    unless f == dirPath
      Dir.rmdir(dirPath);
    end
  else
   ignores.each do |i|
      if dirPath == i
          return
      end
   end
   File.delete(dirPath);
  end
end

.error(msg) ⇒ Object



51
52
53
54
# File 'lib/fastlane/plugin/rocket/tools/message.rb', line 51

def self.error(msg)
  UI.user_error!("rocket-error : #{msg}")
  # UI.message("\033[31mrocket-error:#{msg}\033[0m")
end

.formatLog(params, available_options) ⇒ Object

格式化输出



61
62
63
64
65
66
67
# File 'lib/fastlane/plugin/rocket/tools/message.rb', line 61

def self.formatLog(params,available_options)
  string = []
  available_options.each do |configItem|
      string << "#{configItem.key} => #{params[configItem.key]}"
  end
  logs("参数信息↓↓",string)   
end

.log(msg) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/fastlane/plugin/rocket/tools/message.rb', line 6

def self.log(msg)
  if msg == nil
    UI.message("")
  else
    UI.message("rocket-info : #{msg}")
  end
  
end

.logh(hash) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fastlane/plugin/rocket/tools/message.rb', line 31

def self.logh(hash)
  hash.keys.each do |key|
    title(key)
    value = hash[key]

    if value.is_a? Array
      value.each do |element|
        UI.message("rocket-info : #{element}")
      end
    else
      UI.message("rocket-info : #{value}")
    end
  end
end

.logs(msg, array, number = false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fastlane/plugin/rocket/tools/message.rb', line 15

def self.logs(msg,array,number=false)
  unless msg == nil
    title(msg)
  end
  for i in 0..array.size-1
    element = array[i]
    if number == false
      UI.message("rocket-info : #{element}")
    else
      UI.message("rocket-info : #{i+1}.#{element}")
    end
  end
  
end

.net_get(api, params) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/fastlane/plugin/rocket/tools/config.rb', line 27

def self.net_get(api,params)
  url = URI.parse(api)
  url.query = URI.encode_www_form(params)
  header = {'content-type':'application/json','PRIVATE-TOKEN':'DSscmq3EPy6QoFw_z3p-'}

  http = Net::HTTP.new(url.host, url.port)
  response = http.get(url, header)
  result = JSON.parse(response.body)
  return result
end

.net_post(api, params) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fastlane/plugin/rocket/tools/config.rb', line 14

def self.net_post(api,params)
  url = URI.parse(api)
  http = Net::HTTP.new(url.host, url.port)
  # 设置请求参数
  data = params.to_json
  # 设置请求头
  header = {'content-type':'application/json','PRIVATE-TOKEN':'DSscmq3EPy6QoFw_z3p-'}

  response = http.post(url, data, header)
  result = JSON.parse(response.body)
  return result
end

.return_shell(shell, throw_exception = true) ⇒ Object

获取shell的返回结果



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fastlane/plugin/rocket/tools/shell.rb', line 30

def self.return_shell(shell,throw_exception=true)
  code = `#{shell}`.chomp
  status = $?.to_i
  unless status == 0
    if throw_exception == false
      error_log("状态码 => #{status}")
      format_shell = "\n#{shell.gsub("&&","\n")}"
      raise "执行命令失败 => #{format_shell}"
    else
      return -1
    end
  end
  return code
end

.shell(shell, throw_exception = true) ⇒ Object

执行shell命令throw_exception == true 抛出异常throw_exception == false 报错终止命令



7
8
9
10
11
12
13
14
# File 'lib/fastlane/plugin/rocket/tools/shell.rb', line 7

def self.shell(shell,throw_exception=true)
    status = system "#{shell}"
    if throw_exception == false && status == false
      format_shell = "\n\n#{shell.gsub("&&","\n")}\n"
      raise "执行shell命令失败 => #{format_shell} "
    end
    return status
end

.shell_list(shells, throw_exception = true) ⇒ Object

批量执行



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fastlane/plugin/rocket/tools/shell.rb', line 17

def self.shell_list(shells,throw_exception=true)
    txt = ""
    shells.each do |shell|
      if txt == ""
        txt += "#{shell}"
      else
        txt += "&&#{shell}"
      end
    end
    return shell(txt,throw_exception)
end

.title(msg) ⇒ Object



46
47
48
49
# File 'lib/fastlane/plugin/rocket/tools/message.rb', line 46

def self.title(msg)
  UI.message("")
  UI.message("\033[32mrocket-title : --- #{msg} ---↓↓\033[0m")
end

.warning(msg) ⇒ Object



56
57
58
# File 'lib/fastlane/plugin/rocket/tools/message.rb', line 56

def self.warning(msg)
  UI.message("\033[33mrocket-warning : --- #{msg} ---↓↓\033[0m")
end