Class: ShopifyCLI::JsSystem
- Inherits:
-
Object
- Object
- ShopifyCLI::JsSystem
- Includes:
- SmartProperties
- Defined in:
- lib/shopify_cli/js_system.rb
Overview
ShopifyCLI::JsSystem allows conditional system calls of npm or yarn commands.
Constant Summary collapse
- YARN_CORE_COMMAND =
"yarn"
- NPM_CORE_COMMAND =
"npm"
Class Method Summary collapse
-
.call(ctx, yarn:, npm:, capture_response: false) ⇒ Object
Proxy to instance method ‘ShopifyCLI::JsSystem.new.call`.
-
.yarn?(ctx) ⇒ Boolean
Proxy to instance method ‘ShopifyCLI::JsSystem.new.yarn?`.
Instance Method Summary collapse
-
#call(yarn:, npm:, capture_response: false) ⇒ Object
Runs a command with the proper JS package manager depending on the result of ‘yarn?`.
-
#package_manager ⇒ Object
Returns the name of the JS package manager being used.
-
#yarn? ⇒ Boolean
Returns true if yarn is available and false otherwise.
Class Method Details
.call(ctx, yarn:, npm:, capture_response: false) ⇒ Object
Proxy to instance method ‘ShopifyCLI::JsSystem.new.call`
#### Parameters
-
‘ctx`: running context from your command
-
‘yarn`: The proc, array, or string command to run if yarn is available
-
‘npm`: The proc, array, or string command to run if npm is available
#### Example
ShopifyCLI::JsSystem.call(ctx, yarn: ['install', '--silent'], npm: ['install', '--no-audit'])
40 41 42 |
# File 'lib/shopify_cli/js_system.rb', line 40 def call(ctx, yarn:, npm:, capture_response: false) JsSystem.new(ctx: ctx).call(yarn: yarn, npm: npm, capture_response: capture_response) end |
.yarn?(ctx) ⇒ Boolean
Proxy to instance method ‘ShopifyCLI::JsSystem.new.yarn?`
#### Parameters
-
‘ctx`: running context from your command
#### Example
ShopifyCLI::JsSystem.yarn?(ctx)
24 25 26 |
# File 'lib/shopify_cli/js_system.rb', line 24 def yarn?(ctx) JsSystem.new(ctx: ctx).yarn? end |
Instance Method Details
#call(yarn:, npm:, capture_response: false) ⇒ Object
Runs a command with the proper JS package manager depending on the result of ‘yarn?`
#### Parameters
-
‘ctx`: running context from your command
-
‘yarn`: The proc, array, or string command to run if yarn is available
-
‘npm`: The proc, array, or string command to run if npm is available
-
‘capture_response`: The boolean flag to capture the output of the running command if it is set to true
#### Example
ShopifyCLI::JsSystem.new(ctx: ctx).call(
yarn: ['install', '--silent'],
npm: ['install', '--no-audit'],
capture_response: false
)
89 90 91 92 93 94 95 |
# File 'lib/shopify_cli/js_system.rb', line 89 def call(yarn:, npm:, capture_response: false) if yarn? call_command(yarn, YARN_CORE_COMMAND, capture_response) else call_command(npm, NPM_CORE_COMMAND, capture_response) end end |
#package_manager ⇒ Object
Returns the name of the JS package manager being used
#### Example
ShopifyCLI::JsSystem.new(ctx: ctx).package_manager
54 55 56 |
# File 'lib/shopify_cli/js_system.rb', line 54 def package_manager yarn? ? YARN_CORE_COMMAND : NPM_CORE_COMMAND end |
#yarn? ⇒ Boolean
Returns true if yarn is available and false otherwise
#### Example
ShopifyCLI::JsSystem.new(ctx: ctx).yarn?
65 66 67 68 69 70 |
# File 'lib/shopify_cli/js_system.rb', line 65 def yarn? @has_yarn ||= begin cmd_path = @ctx.which("yarn") File.exist?(File.join(ctx.root, "yarn.lock")) && !cmd_path.nil? end end |