Skip to content

Commit

Permalink
Allow for customizing what files get watched in local dev along with …
Browse files Browse the repository at this point in the history
…the defaults. Fixes #1747 Fixes #920 (#1767)
  • Loading branch information
jwoertink committed Dec 30, 2022
1 parent 33e9d66 commit daff211
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/lucky/server_settings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,35 @@ module Lucky::ServerSettings

extend self

# The host for your local development.
# Depending on your setup, you may need `localhost`, `127.0.0.1`, or `0.0.0.0`
def host : String
settings["host"].as_s
end

# The port to run your local dev server
def port : Int32
ENV["DEV_PORT"]?.try(&.to_i) || settings["port"].as_i
end

# This is the port the dev watcher service will run on
def reload_port : Int32
ENV["RELOAD_PORT"]?.try(&.to_i) || settings["reload_port"]?.try(&.as_i) || 3001
end

private def settings
YAML.parse(yaml_settings_file)
# Watch additional paths for changes
def reload_watch_paths : Array(String)
settings["extra_watch_paths"]?.try(&.as_a.map(&.as_s)) || [] of String
end

@@__settings : YAML::Any? = nil

private def settings : YAML::Any
if @@__settings.nil?
@@__settings = YAML.parse(yaml_settings_file)
else
@@__settings.as(YAML::Any)
end
end

private def yaml_settings_file
Expand Down
4 changes: 2 additions & 2 deletions tasks/watch.cr
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ class Watch < LuckyTask::Task
when "sse"
build_commands << "-Dlivereloadsse"
watcher_class = LuckySentry::ServerSentEventWatcher.new
files.push("./public/css/**/*.css", "./public/js/**/*.js")
files.concat(Lucky::ServerSettings.reload_watch_paths)
when "browsersync"
watcher_class = LuckySentry::BrowsersyncWatcher.new
else
build_commands << "-Dlivereloadws"
watcher_class = LuckySentry::WebSocketWatcher.new
files.push("./public/css/**/*.css", "./public/js/**/*.js")
files.concat(Lucky::ServerSettings.reload_watch_paths)
end
end

Expand Down

0 comments on commit daff211

Please sign in to comment.