module Fastlane class MarkdownDocsGenerator attr_accessor :categories def initialize require 'fastlane' require 'fastlane/documentation/actions_list' Fastlane.load_actions self.work end def work fill_built_in_actions end def fill_built_in_actions self.categories = {} Fastlane::Action::AVAILABLE_CATEGORIES.each { |a| self.categories[readable_category_name(a)] = {} } # Fill categories with all built-in actions ActionsList.all_actions do |action| readable = readable_category_name(action.category) if self.categories[readable].kind_of?(Hash) self.categories[readable][number_of_launches_for_action(action.action_name)] = action else UI.error("Action '#{action.name}' doesn't contain category information... skipping") end end end def number_of_launches_for_action(action_name) found = all_actions_from_enhancer.find { |c| c['action'] == action_name.to_s } return found["index"] if found return 10_000 + rand # new actions that we've never tracked before will be shown at the bottom of the page, need `rand` to not overwrite them end def all_actions_from_enhancer require 'json' @_launches ||= JSON.parse(File.read(File.join(Fastlane::ROOT, "assets/action_ranking.json"))) # root because we're in a temporary directory here end def generate!(target_path: "docs/Actions.md") template = File.join(Fastlane::ROOT, "lib/assets/Actions.md.erb") result = ERB.new(File.read(template), 0, '-').result(binding) # http://www.rrn.dk/rubys-erb-templating-system UI.verbose(result) File.write(target_path, result) UI.success(target_path) end private def readable_category_name(category_symbol) case category_symbol when :misc "Misc" when :source_control "Source Control" when :notifications "Notifications" when :code_signing "Code Signing" when :documentation "Documentation" when :testing "Testing" when :building "Building" when :push "Push" when :screenshots "Screenshots" when :project "Project" when :beta "Beta" when :production "Releasing your app" when :deprecated "Deprecated" else category_symbol.to_s.capitalize end end end end