Sha256: 457fb28aec831b9e9ac0ac90ce9ed442ba0ffc76078672e71ebfbc1060abe39d

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

#!/usr/bin/env watchr

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

# p "reload"

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

watch( %r(jasmine.watchr), :modified ) do |md|
  raise Watchr::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.0 vendor/jasmine/jasmine.watchr