Skip to content

Commit

Permalink
Add ignore to config for skipping watched files
Browse files Browse the repository at this point in the history
* Leverages the .sentry.yml to add a list of patterns for files to
ignore from the watched file paths.  This can be useful for developers
whose editors produce temporary dotfiles (lock and/or autosave files)
for which it may not be desired to watch.
  • Loading branch information
apmiller108 committed Feb 28, 2018
1 parent 40a9685 commit 3f3a377
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .sentry.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ run_args:
watch:
- ./src/**/*.cr
- ./src/**/*.ecr

# The list of patterns of files to ignore from the watched file paths.
ignore:
- /\.swp$/
- /^\.#/
13 changes: 12 additions & 1 deletion src/sentry.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ module Sentry
watch: {
type: Array(String),
default: ["./src/**/*.cr", "./src/**/*.ecr"],
},
ignore: {
type: Array(String),
default: [] of String,
}
)

Expand All @@ -59,6 +63,7 @@ module Sentry
@run = nil
@run_args = ""
@watch = [] of String
@ignore = [] of String
end

def display_name
Expand Down Expand Up @@ -120,6 +125,7 @@ module Sentry
self.run = other.run if other.sets_run_command?
self.run_args = other.run_args.join(" ") unless other.run_args.empty?
self.watch = other.watch unless other.watch.empty?
self.ignore = other.ignore unless other.ignore.empty?
end

def to_s(io : IO)
Expand All @@ -133,6 +139,7 @@ module Sentry
run: #{run}
run_args: #{run_args}
watch: #{watch}
ignore: #{ignore}
CONFIG
end
end
Expand All @@ -142,6 +149,7 @@ module Sentry
property display_name : String
property should_build = true
property files = [] of String
property ignore_regexes = [] of Regex

def initialize(
@display_name : String,
Expand All @@ -150,9 +158,11 @@ module Sentry
@build_args : Array(String) = [] of String,
@run_args : Array(String) = [] of String,
files = [] of String,
ignore_regexes = [] of String,
should_build = true
)
@files = files
@ignore_regexes = ignore_regexes.map { |regex| Regex.new(regex.strip("/")) }
@should_build = should_build
@should_kill = false
@app_built = false
Expand Down Expand Up @@ -204,13 +214,14 @@ module Sentry
end
end

# Scans all of the `@files`
# Scans all of the `@files`, expect where matched with `@ignore_regexes`
#
def scan_files
file_changed = false
app_process = @app_process
files = @files
Dir.glob(files) do |file|
next if @ignore_regexes.any? { |r| r === file || r === file.split("/").last }
timestamp = get_timestamp(file)
if FILE_TIMESTAMPS[file]? && FILE_TIMESTAMPS[file] != timestamp
FILE_TIMESTAMPS[file] = timestamp
Expand Down
3 changes: 2 additions & 1 deletion src/sentry_cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ if Sentry::Config.shard_name
build_args: config.build_args,
run_args: config.run_args,
should_build: config.should_build?,
files: config.watch
files: config.watch,
ignore_regexes: config.ignore
)

process_runner.run
Expand Down

0 comments on commit 3f3a377

Please sign in to comment.