diff --git a/README.md b/README.md index 1cc9282a3..a9083e977 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Webpacker ![travis-ci status](https://api.travis-ci.org/rails/webpacker.svg?branch=master) -[![node](https://img.shields.io/badge/node-%3E%3D%206.4.0-brightgreen.svg)](https://nodejs.org/en/) +[![node.js](https://img.shields.io/badge/node-%3E%3D%206.4.0-brightgreen.svg)](https://nodejs.org/en/) [![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://github.com/rails/webpacker) Webpacker makes it easy to use the JavaScript preprocessor and bundler [Webpack](https://webpack.github.io) @@ -15,7 +15,7 @@ that's been made default from that version forward. * Ruby 2.2+ * Rails 4.2+ -* Node 6.4.0+ +* Node.js 6.4.0+ * Yarn ## Installation diff --git a/lib/tasks/webpacker.rake b/lib/tasks/webpacker.rake index ed7eb6c31..b8d0a535b 100644 --- a/lib/tasks/webpacker.rake +++ b/lib/tasks/webpacker.rake @@ -1,6 +1,8 @@ tasks = { "webpacker:install" => "Installs and setup webpack with yarn", "webpacker:compile" => "Compiles webpack bundles based on environment", + "webpacker:check_node" => "Verifies if Node.js is installed", + "webpacker:check_yarn" => "Verifies if yarn is installed", "webpacker:verify_install" => "Verifies if webpacker is installed", "webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn", "webpacker:install:react" => "Installs and setup example react component", diff --git a/lib/tasks/webpacker/check_node.rake b/lib/tasks/webpacker/check_node.rake new file mode 100644 index 000000000..6049f3f3c --- /dev/null +++ b/lib/tasks/webpacker/check_node.rake @@ -0,0 +1,16 @@ +namespace :webpacker do + desc "Verifies if Node.js is installed" + task :check_node do + begin + node_version = `node -v` + if node_version.tr("v", "").to_f < 6.4 + puts "Webpacker requires Node.js >= 6.4 and you are using #{node_version}" + puts "Please upgrade Node.js https://nodejs.org/en/download/" + puts "Exiting!" && exit! + end + rescue Errno::ENOENT + puts "Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/" + puts "Exiting!" && exit! + end + end +end diff --git a/lib/tasks/webpacker/check_yarn.rake b/lib/tasks/webpacker/check_yarn.rake new file mode 100644 index 000000000..4317b6f61 --- /dev/null +++ b/lib/tasks/webpacker/check_yarn.rake @@ -0,0 +1,11 @@ +namespace :webpacker do + desc "Verifies if yarn is installed" + task :check_yarn do + begin + `yarn --version` + rescue Errno::ENOENT + puts "Webpacker requires yarn. Please download and install Yarn https://yarnpkg.com/lang/en/docs/install/" + puts "Exiting!" && exit! + end + end +end diff --git a/lib/tasks/webpacker/install.rake b/lib/tasks/webpacker/install.rake index e6bd16e8d..aafc368aa 100644 --- a/lib/tasks/webpacker/install.rake +++ b/lib/tasks/webpacker/install.rake @@ -2,7 +2,7 @@ WEBPACKER_APP_TEMPLATE_PATH = File.expand_path("../../install/template.rb", __di namespace :webpacker do desc "Install webpacker in this application" - task :install do + task install: [:check_node, :check_yarn] do if Rails::VERSION::MAJOR >= 5 exec "./bin/rails app:template LOCATION=#{WEBPACKER_APP_TEMPLATE_PATH}" else diff --git a/lib/tasks/webpacker/verify_install.rake b/lib/tasks/webpacker/verify_install.rake index 06aa46f9b..b318298d7 100644 --- a/lib/tasks/webpacker/verify_install.rake +++ b/lib/tasks/webpacker/verify_install.rake @@ -2,7 +2,7 @@ require "webpacker/configuration" namespace :webpacker do desc "Verifies if webpacker is installed" - task :verify_install do + task verify_install: [:check_node, :check_yarn] do if File.exist?(Webpacker::Configuration.file_path) puts "Webpacker is installed 🎉 🍰" puts "Using #{Webpacker::Configuration.file_path} file for setting up webpack paths"