-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert Listen into its own executable to run in separate process
- Loading branch information
Showing
4 changed files
with
77 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'forwardable' | ||
require_relative "runner/cached_test_file" | ||
|
||
module Retest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$stdout.sync = true | ||
|
||
require 'listen' | ||
require 'optparse' | ||
|
||
options = {} | ||
OptionParser.new do |opts| | ||
opts.banner = "Usage: scripts/listen.rb [options]" | ||
|
||
opts.on("--exts rb,js,ts", Array, "Extensions to watch for") do |list| | ||
options[:extensions] = list | ||
end | ||
|
||
opts.on("--polling BOOLEAN", "Force Listen to use polling") do |value| | ||
options[:polling] = value | ||
end | ||
|
||
opts.on("-w", "--watch .", "Directory to listen to") do |value| | ||
options[:dir] = value | ||
end | ||
|
||
opts.on("-h", "--help", "Prints help") do | ||
puts opts | ||
exit | ||
end | ||
end.parse! | ||
|
||
unless options.key?(:extensions) | ||
raise ArgumentError, 'must provide the files extensions to watch for' | ||
end | ||
|
||
unless options.key?(:polling) | ||
raise ArgumentError, 'must provide the polling option' | ||
end | ||
|
||
unless options.key?(:dir) | ||
raise ArgumentError, 'must provide the directory path to watch' | ||
end | ||
|
||
def extensions_regex(extensions) | ||
Regexp.new("\\.(?:#{extensions.join("|")})$") | ||
end | ||
|
||
Listen.adapter_warn_behavior = :log | ||
|
||
Listen.to(options[:dir], only: extensions_regex(options[:extensions]), polling: options[:polling]) do |modified, added, removed| | ||
if modified.any? | ||
$stdout.puts "modify:#{modified.first}" | ||
elsif added.any? | ||
$stdout.puts "create:#{added.first}" | ||
elsif removed.any? | ||
$stdout.puts "remove:#{removed.first}" | ||
end | ||
end.start | ||
sleep |