Wrangle the asset build into something that sounds more general

This commit is contained in:
Matthew Draper 2016-02-01 04:31:03 +10:30
parent ca9603fc35
commit d6f2000a67
18 changed files with 51 additions and 17 deletions

@ -1,2 +1,2 @@
/lib/assets/javascripts/action_cable.js
/lib/assets/compiled
/tmp

@ -8,6 +8,9 @@ dir = File.dirname(__FILE__)
task :default => :test
task :package => "assets:compile"
task "package:clean" => "assets:clean"
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = Dir.glob("#{dir}/test/**/*_test.rb")
@ -17,32 +20,38 @@ Rake::TestTask.new do |t|
end
namespace :assets do
root_path = Pathname.new(dir)
destination_path = root_path.join("lib/assets/compiled")
desc "Compile dist/action_cable.js"
task :compile do
puts 'Compiling Action Cable assets...'
asset_mapping = { "source.js" => "action_cable.js" }
precompile_list = %w(action_cable.js)
root_path = Pathname.new(dir)
load_path = root_path.join("app/assets/javascripts/action_cable")
destination_path = root_path.join("lib/assets/javascripts")
environment = Sprockets::Environment.new
environment.gzip = false
Pathname.glob(root_path.join("app/assets/*/")) do |subdir|
environment.append_path subdir
end
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)
manifest.compile(precompile_list)
asset_mapping.each do |logical_path, dist_path|
fingerprint_path = manifest.assets[logical_path]
FileUtils.cp(compile_path.join(fingerprint_path), destination_path.join(dist_path))
destination_path.rmtree if destination_path.exist?
manifest.assets.each do |path, fingerprint_path|
destination_path.join(path).dirname.mkpath
FileUtils.cp(compile_path.join(fingerprint_path), destination_path.join(path))
end
puts '======'
puts 'Action Cable assets compiled successfully!'
puts 'Done'
end
task :clean do
destination_path.rmtree if destination_path.exist?
end
end

@ -1,5 +1,5 @@
#= require_self
#= require ./consumer
#= require ./action_cable/consumer
@ActionCable =
INTERNAL: <%= ActionCable::INTERNAL.to_json %>

@ -1 +0,0 @@
//= require_tree ./source

@ -3,6 +3,9 @@ require 'rake/testtask'
desc "Default Task"
task default: [ :test ]
task :package
task "package:clean"
# Run the unit tests
Rake::TestTask.new { |t|
t.libs << "test"

@ -5,6 +5,9 @@ test_files = Dir.glob('test/**/*_test.rb')
desc "Default Task"
task :default => :test
task :package
task "package:clean"
# Run the unit tests
Rake::TestTask.new do |t|
t.libs << 'test'

@ -3,6 +3,9 @@ require 'rake/testtask'
desc "Default Task"
task :default => :test
task :package
task "package:clean"
# Run the unit tests
desc "Run all unit tests"

@ -6,6 +6,9 @@ ACTIVEJOB_ADAPTERS -= %w(queue_classic) if defined?(JRUBY_VERSION)
task default: :test
task test: 'test:default'
task :package
task "package:clean"
namespace :test do
desc 'Run all adapter tests'
task :default do

@ -4,6 +4,9 @@ dir = File.dirname(__FILE__)
task :default => :test
task :package
task "package:clean"
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = Dir.glob("#{dir}/test/cases/**/*_test.rb")

@ -20,6 +20,9 @@ end
desc 'Run mysql2, sqlite, and postgresql tests by default'
task :default => :test
task :package
task "package:clean"
desc 'Run mysql2, sqlite, and postgresql tests'
task :test do
tasks = defined?(JRUBY_VERSION) ?

@ -1,6 +1,10 @@
require 'rake/testtask'
task :default => :test
task :package
task "package:clean"
Rake::TestTask.new do |t|
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'

@ -2,6 +2,9 @@ require 'rake/testtask'
task :default => :test
task :package
task "package:clean"
desc "Run all unit tests"
task :test => 'test:isolated'

@ -13,6 +13,7 @@
task :clean do
rm_f gem
sh "cd #{framework} && bundle exec rake package:clean" unless framework == "rails"
end
task :update_versions do
@ -48,7 +49,7 @@
task gem => %w(update_versions pkg) do
cmd = ""
cmd << "cd #{framework} && " unless framework == "rails"
cmd << "bundle exec rake assets:compile && " if framework == "actioncable"
cmd << "bundle exec rake package && " unless framework == "rails"
cmd << "gem build #{gemspec} && mv #{framework}-#{version}.gem #{root}/pkg/"
sh cmd
end