forked from reactjs/react-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
101 lines (84 loc) · 2.57 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
# Move to `dirname` and execute `yarn {cmd}`
def yarn_run_in(dirname, cmd)
Dir.chdir(dirname) do
`yarn #{cmd}`
end
end
namespace :react do
desc 'Run the JS build process to put files in the gem source'
task update: [:install, :build, :copy]
desc 'Install the JavaScript dependencies'
task :install do
yarn_run_in('react-builds', 'upgrade')
end
desc 'Build the JS bundles with Webpack'
task :build do
yarn_run_in('react-builds', 'build')
end
desc "Copy browser-ready JS files to the gem's asset paths"
task :copy do
environments = ['development', 'production']
environments.each do |environment|
copy_react_asset("#{environment}/react-browser.js", "#{environment}/react.js")
copy_react_asset("#{environment}/react-server.js", "#{environment}/react-server.js")
end
end
end
namespace :ujs do
desc 'Run the JS build process to put files in the gem source'
task update: [:install, :build, :copy]
desc 'Install the JavaScript dependencies'
task :install do
`yarn upgrade`
end
desc 'Build the JS bundles with Webpack'
task :build do
`yarn build`
end
desc "Copy browser-ready JS files to the gem's asset paths"
task :copy do
full_webpack_path = File.expand_path('../react_ujs/dist/react_ujs.js', __FILE__)
full_destination_path = File.expand_path('../lib/assets/javascripts/react_ujs.js', __FILE__)
FileUtils.cp(full_webpack_path, full_destination_path)
end
desc 'Publish the package in ./react_ujs/ to npm as `react_ujs`'
task publish: :update do
`npm publish`
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
task :test_setup do
Dir.chdir('./test/dummy_sprockets') do
`yarn install`
end
Dir.chdir('./test/dummy_webpacker1') do
`yarn install`
end
Dir.chdir('./test/dummy_webpacker2') do
`yarn install`
end
Dir.chdir('./test/dummy_webpacker3') do
`yarn install`
end
end
task test: :test_setup