@@ -12,15 +12,20 @@ def copy_react_asset(webpack_file, destination_file)
12
12
FileUtils . cp ( full_webpack_path , full_destination_path )
13
13
end
14
14
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
+
15
22
namespace :react do
16
23
desc "Run the JS build process to put files in the gem source"
17
24
task update : [ :install , :build , :copy ]
18
25
19
26
desc "Build the JS bundles with Webpack"
20
27
task :build do
21
- Dir . chdir ( "react-builds" ) do
22
- `yarn run build`
23
- end
28
+ yarn_run_in ( "react-builds" , "build" )
24
29
end
25
30
26
31
desc "Copy browser-ready JS files to the gem's asset paths"
@@ -39,9 +44,30 @@ namespace :react do
39
44
40
45
desc "Install the JavaScript dependencies"
41
46
task :install do
42
- Dir . chdir ( "react-builds" ) do
43
- `yarn install`
44
- end
47
+ yarn_run_in ( "react-builds" , "install" )
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" , "install" )
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 )
45
71
end
46
72
end
47
73
0 commit comments