Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check node and yarn #222

Merged
merged 2 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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