Class: Fastlane::LaneList

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

Constant Summary collapse

SWIFT_FUNCTION_REGEX =

Print out the result of ‘generate`

/\s*func\s*(\w*)\s*\((.*)\)\s*/
SWIFT_DESC_REGEX =
/\s*desc\s*\(\s*"(.*)"\s*\)\s*/

Class Method Summary collapse

Class Method Details

.desc_entry_for_swift_lane(named: nil, potential_desc_line: nil) ⇒ Object

[View source]

40
41
42
43
44
45
46
47
48
49
50
51
# File 'fastlane/lib/fastlane/lane_list.rb', line 40

def self.desc_entry_for_swift_lane(named: nil, potential_desc_line: nil)
  unless named
    return nil
  end

  desc_match = SWIFT_DESC_REGEX.match(potential_desc_line)
  unless desc_match
    return nil
  end

  return desc_match[1]
end

.generate(path) ⇒ Object

[View source]

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'fastlane/lib/fastlane/lane_list.rb', line 66

def self.generate(path)
  lanes = {}
  if FastlaneCore::FastlaneFolder.swift?
    lanes = generate_swift_lanes(path)
  else
    ff = Fastlane::FastFile.new(path)
    lanes = ff.runner.lanes
  end

  output = ""

  all_keys = lanes.keys.reject(&:nil?)
  all_keys.unshift(nil) # because we want root elements on top. always! They have key nil

  all_keys.each do |platform|
    next if (lanes[platform] || []).count == 0

    plat_text = platform
    plat_text = "general" if platform.to_s.empty?
    output += "\n--------- #{plat_text}---------\n".yellow

    value = lanes[platform]
    next unless value

    value.each do |lane_name, lane|
      next if lane.is_private

      output += "----- fastlane #{lane.pretty_name}".green
      if lane.description.count > 0
        output += "\n" + lane.description.join("\n") + "\n\n"
      else
        output += "\n\n"
      end
    end
  end

  output
end

.generate_json(path) ⇒ Object

Returns a hash

[View source]

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'fastlane/lib/fastlane/lane_list.rb', line 110

def self.generate_json(path)
  output = {}
  return output if path.nil?
  ff = Fastlane::FastFile.new(path)

  all_keys = ff.runner.lanes.keys

  all_keys.each do |platform|
    next if (ff.runner.lanes[platform] || []).count == 0

    output[platform] ||= {}

    value = ff.runner.lanes[platform]
    next unless value

    value.each do |lane_name, lane|
      next if lane.is_private

      output[platform][lane_name] = {
        description: lane.description.join("\n")
      }
    end
  end

  return output
end

.generate_swift_lanes(path) ⇒ Object

[View source]

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
# File 'fastlane/lib/fastlane/lane_list.rb', line 12

def self.generate_swift_lanes(path)
  return unless (path || '').length > 0
  UI.user_error!("Could not find Fastfile.swift at path '#{path}'") unless File.exist?(path)
  path = File.expand_path(path)
  lane_content = File.read(path)

  current_lane_name = nil
  lanes_by_name = {}

  lane_content.split("\n").reject(&:empty?).each do |line|
    line.strip!
    if line.start_with?("func") && (current_lane_name = self.lane_name_from_swift_line(potential_lane_line: line))
      lanes_by_name[current_lane_name] = Fastlane::Lane.new(platform: nil, name: current_lane_name.to_sym, description: [])
    elsif line.start_with?("desc")
      lane_description = self.desc_entry_for_swift_lane(named: current_lane_name, potential_desc_line: line)
      unless lane_description
        next
      end

      lanes_by_name[current_lane_name].description = [lane_description]
      current_lane_name = nil
    end
  end
  # "" because that will be interpreted as general platform
  # (we don't detect platform right now)
  return { "" => lanes_by_name }
end

.lane_name_from_swift_line(potential_lane_line: nil) ⇒ Object

[View source]

53
54
55
56
57
58
59
60
61
62
63
64
# File 'fastlane/lib/fastlane/lane_list.rb', line 53

def self.lane_name_from_swift_line(potential_lane_line: nil)
  function_name_match = SWIFT_FUNCTION_REGEX.match(potential_lane_line)
  unless function_name_match
    return nil
  end

  unless function_name_match[1].downcase.end_with?("lane")
    return nil
  end

  return function_name_match[1]
end

.output(path) ⇒ Object

[View source]

6
7
8
9
10
# File 'fastlane/lib/fastlane/lane_list.rb', line 6

def self.output(path)
  puts(generate(path))

  puts("Execute using `fastlane [lane_name]`".yellow)
end

.output_json(path) ⇒ Object

[View source]

105
106
107
# File 'fastlane/lib/fastlane/lane_list.rb', line 105

def self.output_json(path)
  puts(JSON.pretty_generate(self.generate_json(path)))
end