module Fastlane::Tools

Constants

ROCKET_PATH

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

SOURCESPECS

源码repo

Public Class Methods

clone(git,branch,path,throw_exception=true) click to toggle source
# 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
deleteDirPath(dirPath,ignores=[],f="") click to toggle source
# 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
delete_path(path) click to toggle source
# 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
error(msg) click to toggle source
# 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) click to toggle source

格式化输出

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

获取shell的返回结果

# 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) click to toggle source

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

# 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) click to toggle source

批量执行

# 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) click to toggle source
# 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) click to toggle source
# File lib/fastlane/plugin/rocket/tools/message.rb, line 56
def self.warning(msg)
  UI.message("\033[33mrocket-warning : --- #{msg} ---↓↓\033[0m")
end