From 896950a605c509f19f3e8cbde11e23ca87036ca3 Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Sat, 30 Jan 2016 15:41:14 -0500 Subject: [PATCH 1/3] Add task to create precompiled action_cable.js and reorganize to accommodate --- actioncable/.gitignore | 1 + actioncable/Rakefile | 29 +++++++++++++++++++ actioncable/actioncable.gemspec | 7 +++-- .../assets/javascripts/action_cable/index.js | 1 + .../{ => source}/connection.coffee | 0 .../{ => source}/connection_monitor.coffee | 0 .../action_cable/{ => source}/consumer.coffee | 8 ++--- .../source/index.coffee.erb} | 2 +- .../{ => source}/subscription.coffee | 0 .../{ => source}/subscriptions.coffee | 0 10 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 actioncable/.gitignore create mode 100644 actioncable/lib/assets/javascripts/action_cable/index.js rename actioncable/lib/assets/javascripts/action_cable/{ => source}/connection.coffee (100%) rename actioncable/lib/assets/javascripts/action_cable/{ => source}/connection_monitor.coffee (100%) rename actioncable/lib/assets/javascripts/action_cable/{ => source}/consumer.coffee (86%) rename actioncable/lib/assets/javascripts/{action_cable.coffee.erb => action_cable/source/index.coffee.erb} (95%) rename actioncable/lib/assets/javascripts/action_cable/{ => source}/subscription.coffee (100%) rename actioncable/lib/assets/javascripts/action_cable/{ => source}/subscriptions.coffee (100%) diff --git a/actioncable/.gitignore b/actioncable/.gitignore new file mode 100644 index 00000000000..ceeb05b4108 --- /dev/null +++ b/actioncable/.gitignore @@ -0,0 +1 @@ +/tmp diff --git a/actioncable/Rakefile b/actioncable/Rakefile index b6c56e9195a..9ba431f8a98 100644 --- a/actioncable/Rakefile +++ b/actioncable/Rakefile @@ -1,4 +1,8 @@ require 'rake/testtask' +require 'pathname' +require 'sprockets' +require 'coffee-script' +require 'action_cable' dir = File.dirname(__FILE__) @@ -11,3 +15,28 @@ Rake::TestTask.new do |t| t.verbose = true t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION) end + +namespace :assets do + desc "Compile dist/action_cable.js" + task :compile do + asset_mapping = { "source.js" => "action_cable.js" } + + root_path = Pathname.new(dir) + load_path = root_path.join("lib/assets/javascripts/action_cable") + + compile_path = root_path.join("tmp/sprockets") + compile_path.rmtree if compile_path.exist? + compile_path.mkpath + + environment = Sprockets::Environment.new + environment.append_path(load_path) + + manifest = Sprockets::Manifest.new(environment.index, compile_path) + manifest.compile(asset_mapping.keys) + + asset_mapping.each do |logical_path, dist_path| + fingerprint_path = manifest.assets[logical_path] + FileUtils.cp(compile_path.join(fingerprint_path), load_path.join("dist/#{dist_path}")) + end + end +end diff --git a/actioncable/actioncable.gemspec b/actioncable/actioncable.gemspec index 14f968f1ef1..0976895ef7e 100644 --- a/actioncable/actioncable.gemspec +++ b/actioncable/actioncable.gemspec @@ -24,9 +24,12 @@ Gem::Specification.new do |s| s.add_dependency 'nio4r', '~> 1.2' s.add_dependency 'websocket-driver', '~> 0.6.1' - s.add_development_dependency 'em-hiredis', '~> 0.3.0' + s.add_development_dependency 'coffee-script', '~> 2.4.1' + s.add_development_dependency 'coffee-script-source', '~> 1.10.0' + s.add_development_dependency 'em-hiredis', '~> 0.3.0' s.add_development_dependency 'mocha' s.add_development_dependency 'pg' s.add_development_dependency 'puma' - s.add_development_dependency 'redis', '~> 3.0' + s.add_development_dependency 'redis', '~> 3.0' + s.add_development_dependency 'sprockets', '~> 3.5.2' end diff --git a/actioncable/lib/assets/javascripts/action_cable/index.js b/actioncable/lib/assets/javascripts/action_cable/index.js new file mode 100644 index 00000000000..6c69e423370 --- /dev/null +++ b/actioncable/lib/assets/javascripts/action_cable/index.js @@ -0,0 +1 @@ +//= require ./dist/action_cable diff --git a/actioncable/lib/assets/javascripts/action_cable/connection.coffee b/actioncable/lib/assets/javascripts/action_cable/source/connection.coffee similarity index 100% rename from actioncable/lib/assets/javascripts/action_cable/connection.coffee rename to actioncable/lib/assets/javascripts/action_cable/source/connection.coffee diff --git a/actioncable/lib/assets/javascripts/action_cable/connection_monitor.coffee b/actioncable/lib/assets/javascripts/action_cable/source/connection_monitor.coffee similarity index 100% rename from actioncable/lib/assets/javascripts/action_cable/connection_monitor.coffee rename to actioncable/lib/assets/javascripts/action_cable/source/connection_monitor.coffee diff --git a/actioncable/lib/assets/javascripts/action_cable/consumer.coffee b/actioncable/lib/assets/javascripts/action_cable/source/consumer.coffee similarity index 86% rename from actioncable/lib/assets/javascripts/action_cable/consumer.coffee rename to actioncable/lib/assets/javascripts/action_cable/source/consumer.coffee index fcd8d0fb6c0..717c0641a92 100644 --- a/actioncable/lib/assets/javascripts/action_cable/consumer.coffee +++ b/actioncable/lib/assets/javascripts/action_cable/source/consumer.coffee @@ -1,7 +1,7 @@ -#= require action_cable/connection -#= require action_cable/connection_monitor -#= require action_cable/subscriptions -#= require action_cable/subscription +#= require ./connection +#= require ./connection_monitor +#= require ./subscriptions +#= require ./subscription # The ActionCable.Consumer establishes the connection to a server-side Ruby Connection object. Once established, # the ActionCable.ConnectionMonitor will ensure that its properly maintained through heartbeats and checking for stale updates. diff --git a/actioncable/lib/assets/javascripts/action_cable.coffee.erb b/actioncable/lib/assets/javascripts/action_cable/source/index.coffee.erb similarity index 95% rename from actioncable/lib/assets/javascripts/action_cable.coffee.erb rename to actioncable/lib/assets/javascripts/action_cable/source/index.coffee.erb index 7daea4ebcd1..f4615b7502a 100644 --- a/actioncable/lib/assets/javascripts/action_cable.coffee.erb +++ b/actioncable/lib/assets/javascripts/action_cable/source/index.coffee.erb @@ -1,5 +1,5 @@ #= require_self -#= require action_cable/consumer +#= require ./consumer @ActionCable = INTERNAL: <%= ActionCable::INTERNAL.to_json %> diff --git a/actioncable/lib/assets/javascripts/action_cable/subscription.coffee b/actioncable/lib/assets/javascripts/action_cable/source/subscription.coffee similarity index 100% rename from actioncable/lib/assets/javascripts/action_cable/subscription.coffee rename to actioncable/lib/assets/javascripts/action_cable/source/subscription.coffee diff --git a/actioncable/lib/assets/javascripts/action_cable/subscriptions.coffee b/actioncable/lib/assets/javascripts/action_cable/source/subscriptions.coffee similarity index 100% rename from actioncable/lib/assets/javascripts/action_cable/subscriptions.coffee rename to actioncable/lib/assets/javascripts/action_cable/source/subscriptions.coffee From 09a706065952d58d515420b19a55df619eb7f53d Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 30 Jan 2016 20:39:22 -0500 Subject: [PATCH 2/3] Improvements and reorganization of assets --- actioncable/.gitignore | 1 + actioncable/Rakefile | 10 ++++++++-- .../app/assets/javascripts/action_cable/index.js | 1 + .../javascripts/action_cable/source/connection.coffee | 0 .../action_cable/source/connection_monitor.coffee | 0 .../javascripts/action_cable/source/consumer.coffee | 0 .../javascripts/action_cable/source/index.coffee.erb | 0 .../action_cable/source/subscription.coffee | 0 .../action_cable/source/subscriptions.coffee | 0 .../lib/assets/javascripts/action_cable/index.js | 1 - 10 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 actioncable/app/assets/javascripts/action_cable/index.js rename actioncable/{lib => app}/assets/javascripts/action_cable/source/connection.coffee (100%) rename actioncable/{lib => app}/assets/javascripts/action_cable/source/connection_monitor.coffee (100%) rename actioncable/{lib => app}/assets/javascripts/action_cable/source/consumer.coffee (100%) rename actioncable/{lib => app}/assets/javascripts/action_cable/source/index.coffee.erb (100%) rename actioncable/{lib => app}/assets/javascripts/action_cable/source/subscription.coffee (100%) rename actioncable/{lib => app}/assets/javascripts/action_cable/source/subscriptions.coffee (100%) delete mode 100644 actioncable/lib/assets/javascripts/action_cable/index.js diff --git a/actioncable/.gitignore b/actioncable/.gitignore index ceeb05b4108..8ded1145481 100644 --- a/actioncable/.gitignore +++ b/actioncable/.gitignore @@ -1 +1,2 @@ +/lib/assets/javascripts/action_cable.js /tmp diff --git a/actioncable/Rakefile b/actioncable/Rakefile index 9ba431f8a98..0a036e3e3d4 100644 --- a/actioncable/Rakefile +++ b/actioncable/Rakefile @@ -19,10 +19,13 @@ end namespace :assets do desc "Compile dist/action_cable.js" task :compile do + puts 'Compiling Action Cable assets...' + asset_mapping = { "source.js" => "action_cable.js" } root_path = Pathname.new(dir) - load_path = root_path.join("lib/assets/javascripts/action_cable") + load_path = root_path.join("app/assets/javascripts/action_cable") + destination_path = root_path.join("lib/assets/javascripts") compile_path = root_path.join("tmp/sprockets") compile_path.rmtree if compile_path.exist? @@ -36,7 +39,10 @@ namespace :assets do asset_mapping.each do |logical_path, dist_path| fingerprint_path = manifest.assets[logical_path] - FileUtils.cp(compile_path.join(fingerprint_path), load_path.join("dist/#{dist_path}")) + FileUtils.cp(compile_path.join(fingerprint_path), destination_path.join(dist_path)) end + + puts '======' + puts 'Action Cable assets compiled successfully!' end end diff --git a/actioncable/app/assets/javascripts/action_cable/index.js b/actioncable/app/assets/javascripts/action_cable/index.js new file mode 100644 index 00000000000..e97870c3b04 --- /dev/null +++ b/actioncable/app/assets/javascripts/action_cable/index.js @@ -0,0 +1 @@ +//= require_tree ./source diff --git a/actioncable/lib/assets/javascripts/action_cable/source/connection.coffee b/actioncable/app/assets/javascripts/action_cable/source/connection.coffee similarity index 100% rename from actioncable/lib/assets/javascripts/action_cable/source/connection.coffee rename to actioncable/app/assets/javascripts/action_cable/source/connection.coffee diff --git a/actioncable/lib/assets/javascripts/action_cable/source/connection_monitor.coffee b/actioncable/app/assets/javascripts/action_cable/source/connection_monitor.coffee similarity index 100% rename from actioncable/lib/assets/javascripts/action_cable/source/connection_monitor.coffee rename to actioncable/app/assets/javascripts/action_cable/source/connection_monitor.coffee diff --git a/actioncable/lib/assets/javascripts/action_cable/source/consumer.coffee b/actioncable/app/assets/javascripts/action_cable/source/consumer.coffee similarity index 100% rename from actioncable/lib/assets/javascripts/action_cable/source/consumer.coffee rename to actioncable/app/assets/javascripts/action_cable/source/consumer.coffee diff --git a/actioncable/lib/assets/javascripts/action_cable/source/index.coffee.erb b/actioncable/app/assets/javascripts/action_cable/source/index.coffee.erb similarity index 100% rename from actioncable/lib/assets/javascripts/action_cable/source/index.coffee.erb rename to actioncable/app/assets/javascripts/action_cable/source/index.coffee.erb diff --git a/actioncable/lib/assets/javascripts/action_cable/source/subscription.coffee b/actioncable/app/assets/javascripts/action_cable/source/subscription.coffee similarity index 100% rename from actioncable/lib/assets/javascripts/action_cable/source/subscription.coffee rename to actioncable/app/assets/javascripts/action_cable/source/subscription.coffee diff --git a/actioncable/lib/assets/javascripts/action_cable/source/subscriptions.coffee b/actioncable/app/assets/javascripts/action_cable/source/subscriptions.coffee similarity index 100% rename from actioncable/lib/assets/javascripts/action_cable/source/subscriptions.coffee rename to actioncable/app/assets/javascripts/action_cable/source/subscriptions.coffee diff --git a/actioncable/lib/assets/javascripts/action_cable/index.js b/actioncable/lib/assets/javascripts/action_cable/index.js deleted file mode 100644 index 6c69e423370..00000000000 --- a/actioncable/lib/assets/javascripts/action_cable/index.js +++ /dev/null @@ -1 +0,0 @@ -//= require ./dist/action_cable From cb040aa0e54b8659c895cff3bf7302716f2b81ed Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 30 Jan 2016 20:51:18 -0500 Subject: [PATCH 3/3] Add Action Cable asset building as release step --- tasks/release.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/release.rb b/tasks/release.rb index c7704aa8656..25ba91cb49e 100644 --- a/tasks/release.rb +++ b/tasks/release.rb @@ -48,6 +48,7 @@ directory "pkg" task gem => %w(update_versions pkg) do cmd = "" cmd << "cd #{framework} && " unless framework == "rails" + cmd << "bundle exec rake assets:compile && " if framework == "actioncable" cmd << "gem build #{gemspec} && mv #{framework}-#{version}.gem #{root}/pkg/" sh cmd end