-
Notifications
You must be signed in to change notification settings - Fork 0
/
watcher.rb
executable file
·48 lines (41 loc) · 1.06 KB
/
watcher.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby
require 'filewatcher'
require 'rainbow/refinement'
using Rainbow
# Files to watch for changes
WATCHED_FILES = {
content: 'contents/*.yml', # Content files
template: 'template.tex.erb', # LaTeX template
generator: 'generate.rb', # Generator script
config: 'config/*.yml' # Configuration files
}.freeze
def generate_resume
puts "🔄 Regenerating...".yellow
start_time = Time.now
if system('ruby generate.rb')
duration = (Time.now - start_time).round(2)
puts "✅ Done in #{duration}s".green
true
else
puts "❌ Error during generation".red
false
end
end
begin
puts "👀 Watching for changes in:".cyan
WATCHED_FILES.each do |type, pattern|
puts " #{type}: #{pattern}".cyan
end
Filewatcher.new(WATCHED_FILES.values).watch do |changes|
changes.each do |path, event|
puts " #{event}: #{path}".black.bright
end
generate_resume
end
rescue Interrupt
puts "\n👋 Stopping watch...".yellow
exit 0
rescue StandardError => e
puts "❌ Error: #{e.message}".red
exit 1
end