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) ⇒ YarnHelper

Returns a new instance of YarnHelper.



13
14
15
16
17
18
19
20
21
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 13

def initialize(package_path: nil)
  self.package_path = package_path

  if self.package_path
    self.yarn = "cd #{File.dirname(self.package_path)} && 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

#yarnObject

Returns the value of attribute yarn.



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

def yarn
  @yarn
end

Instance Method Details

#check_installObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 29

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



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 45

def check_package
  if self.package_path.nil?
    package_path = 'package.json'
  else
    package_path = self.package_path
  end

  unless File.exist?(package_path)
    UI.error("Could not find package.json")
    raise Errno::ENOENT
  end
end

#install_dependenciesObject



40
41
42
43
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 40

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



24
25
26
27
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 24

def trigger(command: nil, flags: nil, options: nil, print_command: true, print_command_output: true)
  command = [self.yarn, command, flags, options].compact.join(" ")
  Action.sh(command, print_command: print_command, print_command_output: print_command_output)
end