Skip to content

Commit

Permalink
Misc fine tuning
Browse files Browse the repository at this point in the history
* Update travis to ruby 2.3.1
* Fixed doc in config file
* Update the assets.rake inclusion, as it cannot read the configuration
  when defining tasks.
* Add require for Addressable
  • Loading branch information
justin808 committed May 10, 2016
1 parent 540aa79 commit a9f1f38
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: required
language: ruby

rvm:
- 2.2.4
- 2.3.1

services:
- docker
Expand Down
1 change: 1 addition & 0 deletions app/helpers/react_on_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# 1. The white spacing in this file matters!
# 2. Keep all #{some_var} fully to the left so that all indentation is done evenly in that var
require "react_on_rails/prerender_error"
require "addressable/uri"

module ReactOnRailsHelper
# The env_javascript_include_tag and env_stylesheet_link_tag support the usage of a webpack
Expand Down
3 changes: 1 addition & 2 deletions lib/react_on_rails/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def self.ensure_assets_compiled(webpack_assets_status_checker: nil,
webpack_assets_status_checker ||=
WebpackAssetsStatusChecker.new(client_dir: client_dir,
generated_assets_dir: generated_assets_dir,
webpack_generated_files: webpack_generated_files
)
webpack_generated_files: webpack_generated_files)

unless @printed_once
puts
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/test_helper/ensure_assets_compiled.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def call
# Inform the developer that we're ensuring gen assets are ready.
puts_start_compile_check_message(stale_gen_files)

webpack_assets_compiler.compile_assets
webpack_assets_compiler.compile_asseta
end

def puts_start_compile_check_message(stale_files)
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module ReactOnRails
VERSION = "5.2.0".freeze
VERSION = "6.0.0.beta.2".freeze
end
107 changes: 55 additions & 52 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ end

namespace :react_on_rails do
namespace :assets do

if ReactOnRails.configuration.symlink_non_digested_assets_regex
desc "Creates non-digested symlinks for the assets in the public asset dir"
task symlink_non_digested_assets: :"assets:environment" do
desc "Creates non-digested symlinks for the assets in the public asset dir"
task symlink_non_digested_assets: :"assets:environment" do
if ReactOnRails.configuration.symlink_non_digested_assets_regex
manifest_path = Dir.glob(ReactOnRails::assets_path.join(".sprockets-manifest-*.json"))
.first
manifest_data = JSON.load(File.new(manifest_path))
Expand All @@ -42,74 +41,78 @@ namespace :react_on_rails do
end
end
end
end

desc "Cleans all broken symlinks for the assets in the public asset dir"
task delete_broken_symlinks: :"assets:environment" do
Dir.glob(ReactOnRails::assets_path.join("*")).each do |filename|
if File.lstat(filename).symlink?
begin
target = File.readlink(filename)
rescue
puts "React on Rails: Warning: your platform doesn't support File::readlink method."/
"Skipping broken link check."
return
end
path = Pathname.new(File.dirname(filename))
target_path = path.join(target)
unless File.exist?(target_path)
puts "React on Rails: Deleting broken link: #{filename}"
File.delete(filename)
end
desc "Cleans all broken symlinks for the assets in the public asset dir"
task delete_broken_symlinks: :"assets:environment" do
Dir.glob(ReactOnRails::assets_path.join("*")).each do |filename|
if File.lstat(filename).symlink?
begin
target = File.readlink(filename)
rescue
puts "React on Rails: Warning: your platform doesn't support File::readlink method."/
"Skipping broken link check."
return
end
path = Pathname.new(File.dirname(filename))
target_path = path.join(target)
unless File.exist?(target_path)
puts "React on Rails: Deleting broken link: #{filename}"
File.delete(filename)
end
end
end
end


# We might need the clear_prerequisites (delete after testing without)
# Rake::Task["assets:precompile"]
# .clear_prerequisites
# .enhance(["assets:compile_environment"])

if ReactOnRails.configuration.npm_build_production_command.present?
# In this task, set prerequisites for the assets:precompile task
desc <<-DESC
# In this task, set prerequisites for the assets:precompile task
desc <<-DESC
Create webpack assets before calling assets:environment
The webpack task must run before assets:environment task.
Otherwise Sprockets cannot find the files that webpack produces.
This is the secret sauce for how a Heroku deployment knows to create the webpack generated JavaScript files.
DESC
task compile_environment: :webpack do
Rake::Task["assets:environment"].invoke
end
DESC
task compile_environment: :webpack do
Rake::Task["assets:environment"].invoke
end

desc <<-DESC
desc <<-DESC
Compile assets with webpack
Uses command defined with ReactOnRails.configuration.npm_build_production_command
sh "cd client && #{ReactOnRails.configuration.npm_build_production_command}"
DESC
task :webpack do
sh "cd client && `ReactOnRails.configuration.npm_build_production_command`"
DESC
task webpack: :environment do
if ReactOnRails.configuration.npm_build_production_command.present?
sh "cd client && #{ReactOnRails.configuration.npm_build_production_command}"
end
end

desc "Delete assets created with webpack, in #{ReactOnRails.configuration.generated_assets_dir}"
task :clobber do
desc "Delete assets created with webpack, in the generated assetst directory (/app/assets/webpack)"
task clobber: :environment do
dir = Rails.root.join(ReactOnRails.configuration.generated_assets_dir)
if dir.present? && File.directory?(dir)
puts "Deleting files in directory #{dir}"
rm_r Dir.glob(Rails.root.join("#{ReactOnRails.configuration.generated_assets_dir}/*"))
else
puts "Could not find dir #{dir}"
end
end
end
end

if ReactOnRails.configuration.symlink_non_digested_assets_regex
Rake::Task["assets:precompile"].enhance do
Rake::Task["react_on_rails:assets:symlink_non_digested_assets"].invoke
Rake::Task["react_on_rails:assets:delete_broken_symlinks"].invoke
end
end

if ReactOnRails.configuration.npm_build_production_command.present?
Rake::Task["assets:precompile"].enhance do
Rake::Task["react_on_rails:assets:compile_environment"].invoke
end
end
# These tasks run as pre-requisites of assets:precompile.
# Note, it's not possible to refer to ReactOnRails configuration values at this point.
Rake::Task["assets:precompile"]
.clear_prerequisites
.enhance([:environment,
"react_on_rails:assets:compile_environment",
"react_on_rails:assets:symlink_non_digested_assets",
"react_on_rails:assets:delete_broken_symlinks"])

# puts "Enhancing assets:precompile with react_on_rails:assets:compile_environment"
# Rake::Task["assets:precompile"]
# .clear_prerequisites
# .enhance([:environment]) do
# Rake::Task["react_on_rails:assets:compile_environment"].invoke
# Rake::Task["react_on_rails:assets:symlink_non_digested_assets"].invoke
# Rake::Task["react_on_rails:assets:delete_broken_symlinks"].invoke
# end
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-on-rails",
"version": "5.2.0",
"version": "6.0.0-beta.2",
"description": "react-on-rails JavaScript for react_on_rails Ruby gem",
"main": "node_package/lib/ReactOnRails.js",
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
react_on_rails (5.2.0)
react_on_rails (6.0.0.beta.2)
addressable
connection_pool
execjs (~> 2.5)
Expand Down
5 changes: 0 additions & 5 deletions spec/dummy/config/initializers/react_on_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ def self.custom_context(view_context)
# to automatically refresh your webpack assets on every test run.
config.npm_build_test_command = "npm run build:test"

# If you are using the ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
# with rspec then this controls what npm command is run
# to automatically refresh your webpack assets on every test run.
config.npm_build_test_command = "npm run build:test"

# This configures the script to run to build the production assets by webpack. Set this to nil
# if you don't want react_on_rails building this file for you.
config.npm_build_production_command = "npm run build:production"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
def invoke_ensurer_with_doubles
ReactOnRails::TestHelper.ensure_assets_compiled(
webpack_assets_status_checker: assets_checker,
webpack_assets_compiler: compiler)
webpack_assets_compiler: compiler
)
end

def double_assets_checker(args = {})
Expand Down

0 comments on commit a9f1f38

Please sign in to comment.