forked from reactjs/react-rails
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
60 lines (50 loc) · 1.75 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
Bundler::GemHelper.install_tasks
def copy_react_asset(webpack_file, destination_file)
full_webpack_path = File.expand_path("../react-builds/build/#{webpack_file}", __FILE__)
full_destination_path = File.expand_path("../lib/assets/react-source/#{destination_file}", __FILE__)
FileUtils.cp(full_webpack_path, full_destination_path)
end
namespace :react do
desc "Run the JS build process to put files in the gem source"
task update: [:install, :build, :copy]
desc "Build the JS bundles with Webpack"
task :build do
Dir.chdir("react-builds") do
`webpack`
`NODE_ENV=production webpack -p`
end
end
desc "Copy browser-ready JS files to the gem's asset paths"
task :copy do
environments = ["development", "production"]
environments.each do |environment|
# Without addons:
copy_react_asset("#{environment}/react-browser.js", "#{environment}/react.js")
copy_react_asset("#{environment}/react-server.js", "#{environment}/react-server.js")
# With addons:
copy_react_asset("#{environment}/react-browser-with-addons.js", "#{environment}-with-addons/react.js")
copy_react_asset("#{environment}/react-server-with-addons.js", "#{environment}-with-addons/react-server.js")
end
end
desc "Use NPM to install the JavaScript dependencies"
task :install do
Dir.chdir("react-builds") do
`npm install`
end
end
end
require 'appraisal'
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = ENV['TEST_PATTERN'] || 'test/**/*_test.rb'
t.verbose = ENV['TEST_VERBOSE'] == '1'
t.warning = false
end
task default: :test