Sha256: 323f093a0e7c15332d1c83319eb8daff8f945fe4919f501455979ba3f5e65414

Contents?: true

Size: 1.25 KB

Versions: 53

Compression:

Stored size: 1.25 KB

Contents

module Fastlane
  # Guides the new user through creating a new action
  module NewAction
    def self.run
      name = fetch_name
      generate_action(name)
    end

    def self.fetch_name
      puts "Must be lower case, and use a '_' between words. Do not use '.'".green
      puts "examples: 'testflight', 'upload_to_s3'".green
      name = ask('Name of your action: ')
      until name_valid?(name)
        puts 'Name invalid!'
        name = ask('Name of your action: ')
      end
      name
    end

    def self.generate_action(name)
      template = File.read("#{Helper.gem_path('fastlane')}/lib/assets/custom_action_template.rb")
      template.gsub!('[[NAME]]', name)
      template.gsub!('[[NAME_UP]]', name.upcase)
      template.gsub!('[[NAME_CLASS]]', name.fastlane_class + 'Action')

      actions_path = File.join((FastlaneFolder.path || Dir.pwd), 'actions')
      FileUtils.mkdir_p(actions_path) unless File.directory?(actions_path)

      path = File.join(actions_path, "#{name}.rb")
      File.write(path, template)
      Helper.log.info "Created new action file '#{path}'. Edit it to implement your custom action.".green
    end

    private

    def self.name_valid?(name)
      name == name.downcase && name.length > 0 && !name.include?('.')
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
fastlane-1.51.0 lib/fastlane/new_action.rb
fastlane-1.50.0 lib/fastlane/new_action.rb
fastlane-1.49.0 lib/fastlane/new_action.rb
fastlane-1.48.0 lib/fastlane/new_action.rb
fastlane-1.47.0 lib/fastlane/new_action.rb
fastlane-1.46.1 lib/fastlane/new_action.rb
fastlane-1.46.0 lib/fastlane/new_action.rb
fastlane-1.45.0 lib/fastlane/new_action.rb
fastlane-1.44.0 lib/fastlane/new_action.rb
fastlane-1.43.0 lib/fastlane/new_action.rb
fastlane-1.42.0 lib/fastlane/new_action.rb
fastlane-1.41.1 lib/fastlane/new_action.rb
fastlane-1.41.0 lib/fastlane/new_action.rb
fastlane-1.40.0 lib/fastlane/new_action.rb
fastlane-1.39.0 lib/fastlane/new_action.rb
fastlane-1.38.1 lib/fastlane/new_action.rb
fastlane-1.38.0 lib/fastlane/new_action.rb
fastlane-1.37.0 lib/fastlane/new_action.rb
fastlane-1.36.4 lib/fastlane/new_action.rb
fastlane-1.36.3 lib/fastlane/new_action.rb