Sha256: efd29dfb00f6906a28613d404d510edbc6b8960d074eebc47a8b48ea8ef38ec8

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

begin; require 'wake/event_handlers/em'; rescue LoadError; end
begin; require 'wake/deps'; rescue LoadError; end

# p "reload"

watch( %r(.*), :modified, lambda { |md| File.directory? md[0] } ) do |md|
  raise Wake::Refresh
end

watch( %r(jasmine.wake), :modified ) do |md|
  raise Wake::Refresh
end

map_to_test = lambda do |file, event|
  case file
  when %r(spec/(.*)([Ss]pec)\.js$)
    # Run JS spec's using parallel HTML file if it exists
    prefix = $~[1];
    prefix.sub! %r(_$), ""
    files = Dir[prefix+".*htm*"]
    if html = files.detect { |f| f =~ %r(\.x?html?) }
      event == :load ? nil : html
    else 
      file
    end
  else; file
  end
end

jazrb = lambda do |*args|
  files = []
  # boy, clean this up, but call/splat are subtle
  if Array === args[0]
    args = args[0][0]
    files = args.map { |pair| map_to_test.call( pair[0][0], pair[1] ) }
    files.compact!
    files.uniq!
  else
    (file, event) = *args
    file = map_to_test.call file, event
    if file
      files = [ file ]
    end
  end
  if !files.empty?
    deps = ""
    begin deps = "--deps #{db_path}"; rescue; end
    cmd = "jazrb #{deps} #{files.join(" ")}"
    puts cmd
    system cmd
    # puts "exit status: #{$?.exitstatus}" if $?.exited? && $?.exitstatus != 0
    if  $?.signaled? && $?.termsig == 2
      Process.kill 2, 0
    end
  end
end

watch( %r((^spec/.*[Ss]pec)\.js$), [ :load, :created, :modified ], nil, :batch => :js ) do |events|
  jazrb.call events
end

Signal.trap('QUIT') do
  EM.stop
end

# Local Variables:
# mode:ruby
# End:

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jazrb-0.1.1 vendor/jasmine/Wakefile