diff --git a/.sentry.example.yml b/.sentry.example.yml index c1e38fe..d15787d 100644 --- a/.sentry.example.yml +++ b/.sentry.example.yml @@ -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$/ + - /^\.#/ diff --git a/CRYSTAL_API.md b/CRYSTAL_API.md index 5fdb3f6..3dbd9fb 100644 --- a/CRYSTAL_API.md +++ b/CRYSTAL_API.md @@ -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 ) -``` \ No newline at end of file +``` diff --git a/src/sentry.cr b/src/sentry.cr index 27b831b..1431baa 100644 --- a/src/sentry.cr +++ b/src/sentry.cr @@ -42,6 +42,10 @@ module Sentry watch: { type: Array(String), default: ["./src/**/*.cr", "./src/**/*.ecr"], + }, + ignore: { + type: Array(String), + default: [] of String, } ) @@ -59,6 +63,7 @@ module Sentry @run = nil @run_args = "" @watch = [] of String + @ignore = [] of String end def display_name @@ -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) @@ -133,6 +139,7 @@ module Sentry run: #{run} run_args: #{run_args} watch: #{watch} + ignore: #{ignore} CONFIG end end @@ -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, @@ -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 @@ -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 @@ -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 diff --git a/src/sentry_cli.cr b/src/sentry_cli.cr index 014b1ff..9005eff 100644 --- a/src/sentry_cli.cr +++ b/src/sentry_cli.cr @@ -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