-
Notifications
You must be signed in to change notification settings - Fork 759
/
Rakefile
89 lines (71 loc) · 2.38 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
# frozen_string_literal: true
begin
require "bundler/setup"
rescue LoadError
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
end
Bundler::GemHelper.install_tasks
require "package_json"
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: %i[install build copy]
desc "Install the JavaScript dependencies"
task :install do
PackageJson.read("react-builds").manager.install
end
desc "Build the JS bundles with Webpack"
task :build do
PackageJson.read("react-builds").manager.run("build")
end
desc "Copy browser-ready JS files to the gem's asset paths"
task :copy do
environments = %w[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: %i[install build copy]
desc "Install the JavaScript dependencies"
task :install do
PackageJson.read.manager.install
end
desc "Build the JS bundles with Webpack"
task :build do
PackageJson.read.manager.run("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", __dir__)
full_destination_path = File.expand_path("lib/assets/javascripts/react_ujs.js", __dir__)
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 "minitest/test_task"
Minitest::TestTask.create(:test) do |t|
t.libs << "lib"
t.libs << "test"
t.test_globs = 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") do
PackageJson.read.manager.install
end
end
task test: :test_setup