|
6 | 6 |
|
7 | 7 | Bundler::GemHelper.install_tasks
|
8 | 8 |
|
9 |
| -require 'pathname' |
| 9 | +def copy_react_asset(webpack_file, destination_file) |
| 10 | + full_webpack_path = File.expand_path("../react-builds/build/#{webpack_file}", __FILE__) |
| 11 | + full_destination_path = File.expand_path("../lib/assets/react-source/#{destination_file}", __FILE__) |
| 12 | + FileUtils.cp(full_webpack_path, full_destination_path) |
| 13 | +end |
| 14 | + |
10 | 15 | namespace :react do
|
11 |
| - task :update do |
12 |
| - FileUtils.rm_f('vendor/react/.bower.json') |
13 |
| - `bower install react` |
14 |
| - assets_path = Pathname.new(File.dirname(__FILE__)).join('lib/assets/') |
15 |
| - copy_react_asset('JSXTransformer.js', assets_path.join('javascripts/JSXTransformer.js')) |
16 |
| - copy_react_asset('react.js', assets_path.join('react-source/development/react.js')) |
17 |
| - copy_react_asset('react.min.js', assets_path.join('react-source/production/react.js')) |
18 |
| - copy_react_asset('react-with-addons.js', assets_path.join('react-source/development-with-addons/react.js')) |
19 |
| - copy_react_asset('react-with-addons.min.js', assets_path.join('react-source/production-with-addons/react.js')) |
| 16 | + desc "Run the JS build process to put files in the gem source" |
| 17 | + task update: [:build, :copy] |
| 18 | + |
| 19 | + desc "Build the JS bundles with Webpack" |
| 20 | + task :build do |
| 21 | + Dir.chdir("react-builds") do |
| 22 | + `webpack` |
| 23 | + `NODE_ENV=production webpack` |
| 24 | + end |
20 | 25 | end
|
21 | 26 |
|
22 |
| - def copy_react_asset(source, destination) |
23 |
| - vendor_path = Pathname.new(File.dirname(__FILE__)).join('vendor/react') |
24 |
| - FileUtils.mkdir_p(destination.dirname.to_s) |
25 |
| - FileUtils.cp(vendor_path.join(source), destination.to_s) |
| 27 | + desc "Copy browser-ready JS files to the gem's asset paths" |
| 28 | + task :copy do |
| 29 | + environments = ["development", "production"] |
| 30 | + environments.each do |environment| |
| 31 | + # Without addons: |
| 32 | + copy_react_asset("#{environment}/react-browser.js", "#{environment}/react.js") |
| 33 | + copy_react_asset("#{environment}/react-server.js", "#{environment}/react-server.js") |
| 34 | + # With addons: |
| 35 | + copy_react_asset("#{environment}/react-browser-with-addons.js", "#{environment}-with-addons/react.js") |
| 36 | + copy_react_asset("#{environment}/react-server-with-addons.js", "#{environment}-with-addons/react-server.js") |
| 37 | + end |
26 | 38 | end
|
27 | 39 | end
|
28 | 40 |
|
|
0 commit comments