diff --git a/.gitignore b/.gitignore index 9c0dd38..c11679b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ priv/templates/*.erl rebar.lock *.backup *.bak +compile_commands.json +rebar3.crashdump diff --git a/Makefile b/Makefile index 30b4443..eb45a0e 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ PROJECT = docs ROOT_DIR = $(shell pwd) REPO = $(shell git config --get remote.origin.url) LFE = _build/dev/lib/lfe/bin/lfe -ERL_LIBS = $(shell find ./_build/*/lib -maxdepth 1 -mindepth 1 -exec printf "%s:" {} \;) +ERL_LIBS = $(shell find ./_build/*/* -maxdepth 1 -mindepth 1 -exec printf "%s:" {} \;) RIGHT_PAREN = ) LOCAL_DOCS_HOST = $(subst $(RIGHT_PAREN),,$(strip $(lastword $(shell grep host lfe.config)))) LOCAL_DOCS_PORT = $(subst $(RIGHT_PAREN),,$(strip $(lastword $(shell grep port lfe.config)))) diff --git a/rebar.config b/rebar.config index c66343e..c7bbcea 100644 --- a/rebar.config +++ b/rebar.config @@ -27,7 +27,8 @@ {dev, [ {deps, [ {lfe, {git, "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/rvirding/lfe.git", {branch, "develop"}}}, - {barista, {git, "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/lfe-mug/barista.git", {tag, "0.2.2"}}} + {barista, {git, "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/lfe-mug/barista.git", {tag, "0.2.2"}}}, + {inotify, {git, "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/erlsci/inotify.git", {tag, "v0.5.0"}}} ]}, {plugins, [ {'lfe-version', {git, "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/lfe-rebar3/version.git", {tag, "0.5.0-rc2"}}}, diff --git a/src/docs-watcher.lfe b/src/docs-watcher.lfe new file mode 100644 index 0000000..2e3aeee --- /dev/null +++ b/src/docs-watcher.lfe @@ -0,0 +1,37 @@ +(defmodule docs-watcher + (export all)) + +(defun default-watch-data () + `(#("priv/templates" ,#'erlydtl-watcher/1) + #("src" ,#'lfe-watcher/1))) + +(defun lfe-compiler (filename) + (logjam:info "Recompiling LFE file: ~p" `(,filename))) + +(defun erlydtl-compiler (filename) + (logjam:info "Recompiling ErlyDTL file: ~p" `(,filename))) + +(defun lfe-watcher + ((`#(,path file close_write ,fd ,file)) + (lfe-compiler (filename:join path file))) + ((_arg) + 'skipping)) + +(defun erlydtl-watcher + ((`#(,path file close_write ,fd ,file)) + (erlydtl-compiler (filename:join path file))) + ((_) 'skipping)) + +(defun start () + (start (default-watch-data))) + +(defun start (watch-data) + (logjam:start) + (application:ensure_all_started 'inotify) + (case (lists:map (match-lambda ((`#(,path ,func)) + (logjam:debug "Watching path: ~p with function: ~p" + `(,path ,func)) + (inotify:watch path func))) + watch-data) + ('(ok ok) 'ok) + (err (logjam:error err))))