lib/discourse_theme/watcher.rb in discourse_theme-1.1.0 vs lib/discourse_theme/watcher.rb in discourse_theme-2.0.0
- old
+ new
@@ -1,45 +1,24 @@
# frozen_string_literal: true
module DiscourseTheme
class Watcher
- LISTEN_IGNORE_PATTERNS = [%r{migrations/.+/.+\.js}]
-
def self.return_immediately!
@return_immediately = true
end
- def self.return_immediately=(val)
- @return_immediately = val
- end
-
def self.return_immediately?
!!@return_immediately
end
- def self.subscribe_start(&block)
- @subscribers ||= []
- @subscribers << block
- end
-
- def self.call_start_subscribers
- @subscribers&.each(&:call)
- end
-
- def self.reset_start_subscribers
- @subscribers = []
- end
-
def initialize(dir:, uploader:)
@dir = dir
@uploader = uploader
end
def watch
listener =
- Listen.to(@dir, ignore: LISTEN_IGNORE_PATTERNS) do |modified, added, removed|
- yield(modified, added, removed) if block_given?
-
+ Listen.to(@dir) do |modified, added, removed|
begin
if modified.length == 1 && added.length == 0 && removed.length == 0 &&
(resolved = resolve_file(modified[0]))
target, name, type_id = resolved
UI.progress "Fast updating #{target}.scss"
@@ -58,21 +37,20 @@
else
filename = modified[0] || added[0] || removed[0]
UI.progress "Detected changes in #{filename.gsub(@dir, "")}, uploading theme"
end
- @uploader.upload_full_theme
+ @uploader.upload_full_theme(skip_migrations: true)
end
UI.success "Done! Watching for changes..."
rescue DiscourseTheme::ThemeError => e
UI.error "#{e.message}"
UI.progress "Watching for changes..."
end
end
listener.start
- self.class.call_start_subscribers
- sleep 1 while !self.class.return_immediately?
+ sleep if !self.class.return_immediately?
end
protected
def resolve_file(path)