@@ -12,15 +12,20 @@ def copy_react_asset(webpack_file, destination_file)
1212 FileUtils . cp ( full_webpack_path , full_destination_path )
1313end
1414
15+ # Move to `dirname` and execute `yarn {cmd}`
16+ def yarn_run_in ( dirname , cmd )
17+ Dir . chdir ( dirname ) do
18+ `yarn #{ cmd } `
19+ end
20+ end
21+
1522namespace :react do
1623 desc "Run the JS build process to put files in the gem source"
1724 task update : [ :install , :build , :copy ]
1825
1926 desc "Build the JS bundles with Webpack"
2027 task :build do
21- Dir . chdir ( "react-builds" ) do
22- `yarn run build`
23- end
28+ yarn_run_in ( "react-builds" , "build" )
2429 end
2530
2631 desc "Copy browser-ready JS files to the gem's asset paths"
@@ -39,8 +44,36 @@ namespace :react do
3944
4045 desc "Install the JavaScript dependencies"
4146 task :install do
42- Dir . chdir ( "react-builds" ) do
43- `yarn upgrade`
47+ yarn_run_in ( "react-builds" , "upgrade" )
48+ end
49+ end
50+
51+ namespace :ujs do
52+ desc "Run the JS build process to put files in the gem source"
53+ task update : [ :install , :build , :copy ]
54+
55+ desc "Install the JavaScript dependencies"
56+ task :install do
57+ yarn_run_in ( "react_ujs" , "upgrade" )
58+ end
59+
60+
61+ desc "Build the JS bundles with Webpack"
62+ task :build do
63+ yarn_run_in ( "react_ujs" , "build" )
64+ end
65+
66+ desc "Copy browser-ready JS files to the gem's asset paths"
67+ task :copy do
68+ full_webpack_path = File . expand_path ( "../react_ujs/dist/react_ujs.js" , __FILE__ )
69+ full_destination_path = File . expand_path ( "../lib/assets/javascripts/react_ujs.js" , __FILE__ )
70+ FileUtils . cp ( full_webpack_path , full_destination_path )
71+ end
72+
73+ desc "Publish the package in ./react_ujs/ to npm as `react_ujs`"
74+ task :publish do
75+ Dir . chdir ( "react_ujs" ) do
76+ `npm publish`
4477 end
4578 end
4679end
@@ -57,3 +90,11 @@ Rake::TestTask.new(:test) do |t|
5790end
5891
5992task default : :test
93+
94+ task :test_setup do
95+ Dir . chdir ( "./test/dummy" ) do
96+ `yarn install`
97+ end
98+ end
99+
100+ task test : :test_setup
0 commit comments