2015-01-15 12:28:02 -05:00
|
|
|
require 'rake/testtask'
|
2016-01-30 15:41:14 -05:00
|
|
|
require 'pathname'
|
|
|
|
require 'sprockets'
|
|
|
|
require 'coffee-script'
|
|
|
|
require 'action_cable'
|
2015-01-15 12:28:02 -05:00
|
|
|
|
2015-12-14 10:38:37 -05:00
|
|
|
dir = File.dirname(__FILE__)
|
|
|
|
|
2015-01-15 12:28:02 -05:00
|
|
|
task :default => :test
|
|
|
|
|
2016-01-31 13:01:03 -05:00
|
|
|
task :package => "assets:compile"
|
|
|
|
task "package:clean" => "assets:clean"
|
|
|
|
|
2015-12-14 10:38:37 -05:00
|
|
|
Rake::TestTask.new do |t|
|
2015-01-15 12:28:02 -05:00
|
|
|
t.libs << "test"
|
2015-12-14 10:38:37 -05:00
|
|
|
t.test_files = Dir.glob("#{dir}/test/**/*_test.rb")
|
|
|
|
t.warning = true
|
2015-01-15 12:28:02 -05:00
|
|
|
t.verbose = true
|
2015-12-14 10:38:37 -05:00
|
|
|
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
|
2015-01-15 12:28:02 -05:00
|
|
|
end
|
2016-01-30 15:41:14 -05:00
|
|
|
|
|
|
|
namespace :assets do
|
2016-01-31 13:01:03 -05:00
|
|
|
root_path = Pathname.new(dir)
|
|
|
|
destination_path = root_path.join("lib/assets/compiled")
|
|
|
|
|
2016-01-30 15:41:14 -05:00
|
|
|
desc "Compile dist/action_cable.js"
|
|
|
|
task :compile do
|
2016-01-30 20:39:22 -05:00
|
|
|
puts 'Compiling Action Cable assets...'
|
|
|
|
|
2016-01-31 13:01:03 -05:00
|
|
|
precompile_list = %w(action_cable.js)
|
2016-01-30 15:41:14 -05:00
|
|
|
|
2016-01-31 13:01:03 -05:00
|
|
|
environment = Sprockets::Environment.new
|
|
|
|
environment.gzip = false
|
|
|
|
Pathname.glob(root_path.join("app/assets/*/")) do |subdir|
|
|
|
|
environment.append_path subdir
|
|
|
|
end
|
2016-01-30 15:41:14 -05:00
|
|
|
|
|
|
|
compile_path = root_path.join("tmp/sprockets")
|
|
|
|
compile_path.rmtree if compile_path.exist?
|
|
|
|
compile_path.mkpath
|
|
|
|
|
|
|
|
manifest = Sprockets::Manifest.new(environment.index, compile_path)
|
2016-01-31 13:01:03 -05:00
|
|
|
manifest.compile(precompile_list)
|
2016-01-30 15:41:14 -05:00
|
|
|
|
2016-01-31 13:01:03 -05:00
|
|
|
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))
|
2016-01-30 15:41:14 -05:00
|
|
|
end
|
2016-01-30 20:39:22 -05:00
|
|
|
|
2016-01-31 13:01:03 -05:00
|
|
|
puts 'Done'
|
|
|
|
end
|
|
|
|
|
|
|
|
task :clean do
|
|
|
|
destination_path.rmtree if destination_path.exist?
|
2016-01-30 15:41:14 -05:00
|
|
|
end
|
|
|
|
end
|