Class: Fastlane::Helper::YarnHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::YarnHelper
- Defined in:
- lib/fastlane/plugin/yarn/helper/yarn_helper.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#flags ⇒ Object
class methods that you define here become available in your action as ‘Helper::YarnHelper.your_method`.
-
#options ⇒ Object
Returns the value of attribute options.
-
#package_path ⇒ Object
Returns the value of attribute package_path.
-
#project_root ⇒ Object
Returns the value of attribute project_root.
-
#yarn ⇒ Object
Returns the value of attribute yarn.
Instance Method Summary collapse
- #check_install ⇒ Object
- #check_package ⇒ Object
- #format_options(options) ⇒ Object
-
#initialize(package_path: nil, project_root: nil) ⇒ YarnHelper
constructor
A new instance of YarnHelper.
- #install_dependencies ⇒ Object
-
#trigger(command: nil, flags: nil, options: nil, print_command: true, print_command_output: true) ⇒ Object
Run a certain action.
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
#commands ⇒ Object
Returns the value of attribute commands.
8 9 10 |
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 8 def commands @commands end |
#flags ⇒ Object
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 |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 9 def @options end |
#package_path ⇒ Object
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_root ⇒ Object
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 |
#yarn ⇒ Object
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_install ⇒ Object
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_package ⇒ Object
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 () if .kind_of?(Array) .map! { |i| i.include?("--") ? i : "--#{i}" } else .include?("--") ? : "--#{}" end end |
#install_dependencies ⇒ Object
56 57 58 59 |
# File 'lib/fastlane/plugin/yarn/helper/yarn_helper.rb', line 56 def install_dependencies UI.("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 == "" || == [] || == nil then = () option_string = .respond_to?(:join) ? .join(" ") : end command = [self.yarn, flags, command, option_string].compact.join(" ") Action.sh(command, print_command: print_command, print_command_output: print_command_output) end |