Class: Fastlane::Actions::DetectUnusedImageAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/fastci/actions/detect_unused_image_action.rb

Overview

无用图片检查

Class Method Summary collapse

Class Method Details

.available_optionsObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fastlane/plugin/fastci/actions/detect_unused_image_action.rb', line 51

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :exclude,
      description: "要排除的路径,多个路径用逗号分隔。默认会排除 Carthage 和 Pods 目录",
      optional: true,
      default_value: nil,
      type: String
    )
  ]
end

.categoryObject



67
68
69
# File 'lib/fastlane/plugin/fastci/actions/detect_unused_image_action.rb', line 67

def self.category
  :testing
end

.descriptionObject



47
48
49
# File 'lib/fastlane/plugin/fastci/actions/detect_unused_image_action.rb', line 47

def self.description
  "无用图片检测"
end

.is_supported?(platform) ⇒ Boolean



63
64
65
# File 'lib/fastlane/plugin/fastci/actions/detect_unused_image_action.rb', line 63

def self.is_supported?(platform)
  platform == :ios
end

.run(params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fastlane/plugin/fastci/actions/detect_unused_image_action.rb', line 8

def self.run(params)
  UI.message("*************| 开始无用图片检查 |*************")

  # 检查是否安装了 Mint
  unless system("which mint > /dev/null")
    sh("brew install mint")
  end
  
  # 检查是否安装了 FengNiao
  unless system("mint list | grep -q onevcat/FengNiao")
    sh("mint install onevcat/FengNiao")
  end

  # 构建排除参数
  exclude_paths = ["Carthage", "Pods"]
  if params[:exclude] && !params[:exclude].empty?
    exclude_paths += params[:exclude].split(",").map(&:strip)
  end
  exclude_options = exclude_paths.join(" ")

  fengniao_output = sh("
  mint run onevcat/FengNiao fengniao \
  --list-only \
  --exclude #{exclude_options}
  ")

  CommonHelper.write_cached_txt(Constants.UNUSED_IMAGE_FILE, fengniao_output)

  # 输出无用图片检查报告
  UI.message("*************| 开始输出无用图片检查报告 |*************")

  CommonHelper.generate_and_open_html(
    "Unused Image Report",
    "generate_unused_image_html.py",
    Constants.UNUSED_IMAGE_FILE,
    Constants.UNUSED_IMAGE_HTML_FILE
  )
end