Skip to content

Ignore files #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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$/
- /^\.#/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, what does the # do? I'm looking at the pattern reference and don't see a hash character. You either meant * or I got some learning to do.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are strings that we have to cast to regex, does that mean we have to add extra backslashes to everything (e.g. \\w, \\/)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That example was inspired by the issue I was having with the emacs lock files. Those lock files take on the format, .#my_file.cr; So, that pattern filters them out (any file starting with .#). The example patterns here could be better I think 🤔.

Since we're reading in the sentry.yml with File.read, the escape backslashes are added automatically: \nignore:\n - /\\.swp$/\n - /^\\.#/\n".

5 changes: 3 additions & 2 deletions CRYSTAL_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ process_runner = Sentry::ProcessRunner.new(
build_args: [], # Array of String
run_args: [], # Array of String
should_build: true, # Bool
files: [] # Array of String
files: [], # Array of String
ignore: [] # Array of String
)
```
```
19 changes: 18 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 = [] 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 = [] of String,
should_build = true
)
@files = files
@ignore = ignore.map { |regex| Regex.new(regex.strip("/")) }
@should_build = should_build
@should_kill = false
@app_built = false
Expand Down Expand Up @@ -190,6 +200,12 @@ module Sentry
File.stat(file).mtime.to_s("%Y%m%d%H%M%S")
end

private def ignored?(file : String)
@ignore.any? do |regex|
regex === file || regex === file.split("/").last
end
end

# Compiles and starts the application
#
def start_app
Expand All @@ -204,13 +220,14 @@ module Sentry
end
end

# Scans all of the `@files`
# Scans all of the `@files`, expect where matched with `@ignore`
#
def scan_files
file_changed = false
app_process = @app_process
files = @files
Dir.glob(files) do |file|
next if !File.exists?(file) || ignored?(file)
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: config.ignore
)

process_runner.run
Expand Down