aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/Rakefile
blob: 58c18dd45751fe116959140596014dc5e8e55f91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'rake/testtask'
require 'pathname'
require 'sprockets'
require 'coffee-script'
require 'action_cable'

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")
  t.warning = true
  t.verbose = true
  t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
end

namespace :test do
  task :isolated do
    Dir.glob("test/**/*_test.rb").all? do |file|
      sh(Gem.ruby, '-w', '-Ilib:test', file)
    end or raise "Failures"
  end

  task :javascript do
    require 'blade'
    Blade.start(interface: :runner)
  end
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...'

    precompile_list = %w(action_cable.js)

    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

    manifest = Sprockets::Manifest.new(environment.index, compile_path)
    manifest.compile(precompile_list)

    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 'Done'
  end

  task :clean do
    destination_path.rmtree if destination_path.exist?
  end
end