class Fastlane::Helper::YarnHelper

Attributes

commands[RW]
flags[RW]

class methods that you define here become available in your action as `Helper::YarnHelper.your_method`

options[RW]
package_path[RW]
project_root[RW]
yarn[RW]

Public Class Methods

new(package_path: nil, project_root: nil) click to toggle source
# File lib/fastlane/plugin/yarn/helper/yarn_helper.rb, line 14
def initialize(package_path: nil, project_root: nil)
  self.package_path = package_path
  self.project_root = project_root

  if self.package_path
    self.yarn = "cd #{File.dirname(self.package_path)} && yarn"
  elsif self.project_root
    self.yarn = "cd #{self.project_root} && yarn"
  else
    self.yarn = "yarn"
  end
end

Public Instance Methods

check_install() click to toggle source
# File lib/fastlane/plugin/yarn/helper/yarn_helper.rb, line 45
def check_install
  check_package
  begin
    command = [self.yarn, "--version"].compact.join(" ")
    Action.sh(command, print_command: false, print_command_output: false)
  rescue Errno::ENOENT => e
    UI.error("Yarn not installed, please install with Homebrew or npm.")
    raise e
  end
end
check_package() click to toggle source
# File lib/fastlane/plugin/yarn/helper/yarn_helper.rb, line 61
def check_package
  if self.package_path
    package_path = self.package_path
  elsif self.project_root
    package_path = File.join(self.project_root, 'package.json')
  else
    package_path = 'package.json'
  end

  unless File.exist?(package_path)
    UI.crash!("Could not find package.json: (#{package_path})")
  end
end
format_options(options) click to toggle source
# File lib/fastlane/plugin/yarn/helper/yarn_helper.rb, line 37
def format_options(options)
  if options.kind_of?(Array)
    options.map! { |i| i.include?("--") ? i : "--#{i}" }
  else
    options.include?("--") ? options : "--#{options}"
  end
end
install_dependencies() click to toggle source
# File lib/fastlane/plugin/yarn/helper/yarn_helper.rb, line 56
def install_dependencies
  UI.message("Installing dependencies")
  trigger(command: "install")
end
trigger(command: nil, flags: nil, options: nil, print_command: true, print_command_output: true) click to toggle source

Run a certain action

# File lib/fastlane/plugin/yarn/helper/yarn_helper.rb, line 28
def trigger(command: nil, flags: nil, options: nil, print_command: true, print_command_output: true)
  unless options == "" || options == [] || options == nil then
    options = format_options(options)
    option_string = options.respond_to?(:join) ? options.join(" ") : options
  end
  command = [self.yarn, flags, command, option_string].compact.join(" ")
  Action.sh(command, print_command: print_command, print_command_output: print_command_output)
end