lib/linner/command.rb in linner-0.4.0 vs lib/linner/command.rb in linner-0.4.1

- old
+ new

@@ -16,50 +16,22 @@ end desc "build", "build assets" def build Linner.compile = true - clean - - Notifier.profile do - Linner.perform - end + Notifier.profile { Linner.perform } end desc "watch", "watch assets" def watch - trap :INT do - Notifier.exit - Process.kill("QUIT", 0) - end - + trap(:INT) { exit! } clean - - @proc = Proc.new do |modified, added, removed| - begin - Notifier.profile{ Linner.perform } - rescue - Notifier.error $! - end - end - @proc.call - - Listen.to env.app_folder, env.vendor_folder, env.test_folder do |modified, added, removed| - is_include_partial_styles = (modified + added + removed).any? do |path| - Asset.new(path).stylesheet? and File.basename(path).start_with? "_" - end - Linner.cache.reject! {|k, v| v.stylesheet?} if is_include_partial_styles - @proc.call - end - - @reactor = Reactor.supervise_as(:reactor).actors.first - Listen.to env.public_folder, relative_path: true do |modified, added, removed| - @reactor.reload_browser(modified + added + removed) - end - - sleep + perform_proc.call + watch_for_perform + watch_for_reload + Process.wait end desc "clean", "clean assets" def clean FileUtils.rm_rf Dir.glob("#{env.public_folder}/*") @@ -72,9 +44,38 @@ end private def env Linner.env + end + + def perform_proc + @proc ||= Proc.new do |modified, added, removed| + begin + Notifier.profile{ Linner.perform } + rescue + Notifier.error $! + end + end + end + + def watch_for_perform + Listen.to env.watched_paths do |modified, added, removed| + Linner.cache.expire_by(modified + added + removed) + perform_proc.call + end + end + + def watch_for_reload + reactor = Reactor.supervise_as(:reactor).actors.first + Listen.to env.public_folder, relative_path: true do |modified, added, removed| + reactor.reload_browser(modified + added + removed) + end + end + + def exit! + Notifier.exit + Kernel::exit end end end