Class: Fastlane::Helper::YarnHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/yarn/helper/yarn_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_path: nil, project_root: nil) ⇒ YarnHelper

Returns a new instance of YarnHelper.



14
15
16
17
18
19
20
21
22
23
24
25
# 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

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



8
9
10
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 8

def commands
  @commands
end

#flagsObject

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



7
8
9
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 7

def flags
  @flags
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 9

def options
  @options
end

#package_pathObject

Returns the value of attribute package_path.



10
11
12
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 10

def package_path
  @package_path
end

#project_rootObject

Returns the value of attribute project_root.



11
12
13
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 11

def project_root
  @project_root
end

#yarnObject

Returns the value of attribute yarn.



12
13
14
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 12

def yarn
  @yarn
end

Instance Method Details

#check_installObject



45
46
47
48
49
50
51
52
53
54
# 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_packageObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# 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) ⇒ Object



37
38
39
40
41
42
43
# 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_dependenciesObject



56
57
58
59
# 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) ⇒ Object

Run a certain action



28
29
30
31
32
33
34
35
# 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