From f56d1acbbb5e47d6761cd767f1c0a68ef5161720 Mon Sep 17 00:00:00 2001 From: Johan Smits Date: Fri, 10 Aug 2018 22:12:01 +0200 Subject: [PATCH] Improve yarn detection Used the same detection as webpacker. https://github.com/rails/webpacker/blob/9d29ddd14c2cbe94f4aad154a92f4a2a40b498fd/lib/tasks/webpacker/check_yarn.rake#L4-L22 --- lib/generators/hyperloop/install_bootstrap_generator.rb | 7 ++++++- lib/generators/hyperloop/install_generator.rb | 7 ++++++- lib/generators/hyperloop/install_mui_generator.rb | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/generators/hyperloop/install_bootstrap_generator.rb b/lib/generators/hyperloop/install_bootstrap_generator.rb index 8992ce6..9f2984a 100644 --- a/lib/generators/hyperloop/install_bootstrap_generator.rb +++ b/lib/generators/hyperloop/install_bootstrap_generator.rb @@ -7,7 +7,12 @@ class InstallBootstrapGenerator < Rails::Generators::Base class_option 'no-build', type: :boolean def insure_yarn_loaded - raise Thor::Error.new("please insure the yarn command is available") if `command -v yarn`.blank? + begin + yarn_version = `yarn --version` + raise Errno::ENOENT if yarn_version.blank? + rescue Errno::ENOENT + raise Thor::Error.new("please insure the yarn command is available if using webpacker") + end end def add_to_manifests diff --git a/lib/generators/hyperloop/install_generator.rb b/lib/generators/hyperloop/install_generator.rb index f06e6a7..33a7371 100644 --- a/lib/generators/hyperloop/install_generator.rb +++ b/lib/generators/hyperloop/install_generator.rb @@ -8,7 +8,12 @@ class InstallGenerator < Rails::Generators::Base def insure_yarn_loaded return if skip_webpack? - raise Thor::Error.new("please insure the yarn command is available if using webpacker") if `command -v yarn`.blank? + begin + yarn_version = `yarn --version` + raise Errno::ENOENT if yarn_version.blank? + rescue Errno::ENOENT + raise Thor::Error.new("please insure the yarn command is available if using webpacker") + end end def inject_react_file_js diff --git a/lib/generators/hyperloop/install_mui_generator.rb b/lib/generators/hyperloop/install_mui_generator.rb index 51d8243..6ab87b0 100644 --- a/lib/generators/hyperloop/install_mui_generator.rb +++ b/lib/generators/hyperloop/install_mui_generator.rb @@ -7,7 +7,12 @@ class InstallMuiGenerator < Rails::Generators::Base class_option 'no-build', type: :boolean def insure_yarn_loaded - raise Thor::Error.new("please insure the yarn command is available") if `command -v yarn`.blank? + begin + yarn_version = `yarn --version` + raise Errno::ENOENT if yarn_version.blank? + rescue Errno::ENOENT + raise Thor::Error.new("please insure the yarn command is available if using webpacker") + end end def add_to_manifests