Skip to content

Commit

Permalink
Check node and yarn (#222)
Browse files Browse the repository at this point in the history
* Check node and yarn before installing webpacker

Verify node and yarn before running installer

Take 2

Fix case

Use a new puts

Remove .

* Change to Node.js
  • Loading branch information
gauravtiwari authored and dhh committed Apr 4, 2017
1 parent 92616e1 commit 36f1300
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/tasks/webpacker.rake
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 16 additions & 0 deletions lib/tasks/webpacker/check_node.rake
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions lib/tasks/webpacker/check_yarn.rake
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/tasks/webpacker/install.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/webpacker/verify_install.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 36f1300

Please sign in to comment.