-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f236f7a
commit e1cb4a4
Showing
5 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "Genie" | ||
uuid = "c43c736e-a2d1-11e8-161f-af95117fbd1e" | ||
authors = ["Adrian Salceanu <[email protected]>"] | ||
version = "5.0.0" | ||
version = "5.1.0" | ||
|
||
[deps] | ||
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" | ||
|
@@ -36,16 +36,16 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" | |
ArgParse = "1" | ||
EzXML = "1" | ||
FilePathsBase = "0.9" | ||
HTTP = "0.8, 0.9" | ||
HTTP = "0.9" | ||
HttpCommon = "0.5" | ||
Inflector = "1" | ||
JSON3 = "1" | ||
JuliaFormatter = "0.12 - 0.22, 1" | ||
JuliaFormatter = "1" | ||
Millboard = "0.2" | ||
Nettle = "0.5" | ||
OrderedCollections = "1" | ||
Reexport = "0.2, 1" | ||
Revise = "2, 3" | ||
Reexport = "1" | ||
Revise = "3" | ||
YAML = "0.4" | ||
julia = "1.6" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module Watch | ||
|
||
using Revise | ||
using Genie | ||
|
||
const _task = Ref{Core.Task}() | ||
const WATCHED_FOLDERS = Ref{Vector{String}}(String[]) | ||
|
||
function collect_watched_files(files::Vector{String} = String[], | ||
extensions::Vector{String} = Genie.config.watch_extensions) :: Vector{String} | ||
result = String[] | ||
|
||
for f in files | ||
try | ||
push!(result, Genie.Util.walk_dir(f, only_extensions = extensions)...) | ||
catch ex | ||
@error ex | ||
end | ||
end | ||
|
||
result |> unique! | ||
end | ||
|
||
function handlers() | ||
Genie.config.watch_handlers |> values |> collect | ||
end | ||
|
||
function watch(files::Vector{String}, extensions::Vector{String} = Genie.config.watch_extensions) :: Nothing | ||
push!(WATCHED_FOLDERS[], files...) | ||
WATCHED_FOLDERS[] = unique(WATCHED_FOLDERS[]) | ||
|
||
@info "Monitoring $files for changes" | ||
|
||
Revise.revise() | ||
|
||
_task[] = @async entr(collect_watched_files(files, extensions); all = true, postpone = true) do | ||
@info "Detected files changes" | ||
|
||
for fg in handlers() | ||
for f in fg | ||
try | ||
Base.invokelatest(f) | ||
catch ex | ||
@error ex | ||
end | ||
end | ||
end | ||
end | ||
|
||
nothing | ||
end | ||
|
||
watch(files::String, extensions::Vector{String} = Genie.config.watch_extensions) = watch(String[files], extensions) | ||
watch(files...; extensions::Vector{String} = Genie.config.watch_extensions) = watch(String[files...], extensions) | ||
watch() = watch(String[]) | ||
|
||
function unwatch(files::Vector{String}) :: Nothing | ||
filter!(e -> !(e in files), WATCHED_FOLDERS[]) | ||
watch() | ||
end | ||
unwatch(files...) = unwatch(String[files...]) | ||
|
||
end |