class SvelteOnRails::Compiler

def compile_if_changes

compiler
def compile_if_changes
  # letzte Änderung innerhalb des ordners ermitteln
  watch_changes = SvelteOnRails::Configuration.instance.watch_changes?
  ts_file = SvelteOnRails::Configuration.instance.dist_folder.join('reset_timestamp')
  have_changes = if watch_changes && File.exist?(ts_file)
                   # compare last modification timestamp
                   last_modification = 100.years.ago.to_time
                   Dir.glob("#{SvelteOnRails::Configuration.instance.components_folder}**/*").each do |path|
                     if File.file?(path)
                       mtime = File.mtime(path)
                       if mtime > last_modification
                         last_modification = mtime
                       end
                     end
                   end
                   File.mtime(ts_file) < last_modification
                 elsif watch_changes
                   true
                 elsif !File.exist?(ts_file)
                   true
                 else
                   false
                 end
  if have_changes || !File.exist?(compiled_js_file) || !File.exist?(compiled_css_file)
    if have_changes || (!File.exist?(ts_file) && watch_changes)
      self.class.reset_dist
    end
    compile
  end
end