From 1995a2c583859eb00023fd89002c7fca28e7c716 Mon Sep 17 00:00:00 2001 From: Duncan McGreggor Date: Sun, 26 Feb 2017 01:13:37 -0600 Subject: [PATCH 1/3] For this project, it's all dev. No separate profiles needed. --- Makefile | 2 +- priv/make/base.mk | 9 +++------ priv/make/gen.mk | 3 +++ rebar.config | 41 +++++++++++++---------------------------- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index eb45a0e..8958666 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PROJECT = docs ROOT_DIR = $(shell pwd) REPO = $(shell git config --get remote.origin.url) -LFE = _build/dev/lib/lfe/bin/lfe +LFE = _build/default/lib/lfe/bin/lfe 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)))) diff --git a/priv/make/base.mk b/priv/make/base.mk index 37ec021..fb0ce2d 100644 --- a/priv/make/base.mk +++ b/priv/make/base.mk @@ -1,18 +1,15 @@ compile: - rebar3 as dev compile + rebar3 compile check: - @rebar3 as test eunit + @rebar3 eunit repl: compile @ERL_LIBS=$(ERL_LIBS) $(LFE) shell: - @rebar3 as dev shell + @rebar3 shell clean: @rebar3 clean @rm -rf ebin/* _build/*/lib/$(PROJECT) - -clean-all: clean - @rebar3 as dev lfe clean diff --git a/priv/make/gen.mk b/priv/make/gen.mk index c7fb17d..e0c3fdc 100644 --- a/priv/make/gen.mk +++ b/priv/make/gen.mk @@ -62,6 +62,9 @@ serve-watch-css: serve-header css-watch-dev serve-only serve-dev: docs-header clean compile css-dev serve-header @ERL_LIBS=$(ERL_LIBS) $(LFE) -s docs-cli gen-dev-httpd +serve-dev-watch: docs-header clean compile css-dev serve-header + @ERL_LIBS=$(ERL_LIBS) $(LFE) -s docs-cli gen-dev-watch + contributors: git log --pretty=format:"%an"|sort -u diff --git a/rebar.config b/rebar.config index c7bbcea..c56e452 100644 --- a/rebar.config +++ b/rebar.config @@ -1,3 +1,5 @@ +{erl_opts, [{src_dirs, ["src", "test"]}]}. + {erlydtl_opts, [ {source_ext, ".html"}, {module_ext, "-tmpl"}, @@ -6,44 +8,27 @@ {return_errors, true} ]}. +{eunit_opts, [verbose]}. + +{eunit_compile_opts, [{src_dirs, ["test", "src"]}]}. + {deps, [ + {lfe, {git, "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/rvirding/lfe.git", {branch, "develop"}}}, {poise, {git, "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/lfex/poise.git", {branch, "master"}}}, - {exemplar, {git, "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/lfex/exemplar.git", {tag, "0.5.0-rc2"}}}, {logjam, {git, "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/lfex/logjam.git", {tag, "0.5.0-rc2"}}}, {erlydtl, {git, "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/erlydtl/erlydtl.git", {tag, "0.12.1"}}}, - {lcfg, {git, "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/lfex/lcfg.git", {tag, "0.5.0-rc2"}}} + {lcfg, {git, "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/lfex/lcfg.git", {tag, "0.5.0-rc2"}}}, + {barista, {git, "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/lfe-mug/barista.git", {tag, "0.2.2"}}}, + {inotify, {git, "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/erlsci/inotify.git", {branch, "master"}}}, + {ltest, {git, "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/lfex/ltest.git", {tag, "0.10.0-rc6"}}} ]}. {plugins, [ {'lfe-compile', {git, "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/lfe-rebar3/compile.git", {tag, "0.8.0-rc3"}}}, {rebar3_erlydtl_plugin, {git, "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/tsloughter/rebar3_erlydtl_plugin.git", - {branch, "master"}}} + {branch, "master"}}}, + {'lfe-test', {git, "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/lfe-rebar3/test.git", {tag, "0.4.0-rc2"}}} ]}. {provider_hooks, [{pre, [{compile, {lfe, compile}}, {compile, {erlydtl, compile}}]}]}. - -{profiles, [ - {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"}}}, - {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"}}}, - {'lfe-clean', {git, "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/lfe-rebar3/clean.git", {tag, "0.4.0-rc1"}}} - ]} - ]}, - {test, [ - {eunit_compile_opts, [ - {src_dirs, ["test", "src"]} - ]}, - {deps, [ - {ltest, {git, "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/lfex/ltest.git", {tag, "0.10.0-rc6"}}}]}, - {plugins, [ - {'lfe-test', {git, "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/lfe-rebar3/test.git", {tag, "0.4.0-rc2"}}}]}, - {eunit_opts, [verbose]}, - {erl_opts, [{src_dirs, ["src", "test"]}]} - ]} - ]}. From 3d4c1474e88b5b016603ac7bfe8b715d53791ba0 Mon Sep 17 00:00:00 2001 From: Duncan McGreggor Date: Sun, 26 Feb 2017 01:16:33 -0600 Subject: [PATCH 2/3] Implemented watcher for LFE. --- src/docs-watcher.lfe | 55 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/src/docs-watcher.lfe b/src/docs-watcher.lfe index 2e3aeee..1d14af6 100644 --- a/src/docs-watcher.lfe +++ b/src/docs-watcher.lfe @@ -1,32 +1,56 @@ (defmodule docs-watcher (export all)) +(defun source-data () + `#("src" ,#'lfe-watcher/1)) + +(defun templates-data () + `#("priv/templates" ,#'erlydtl-watcher/1)) + (defun default-watch-data () - `(#("priv/templates" ,#'erlydtl-watcher/1) - #("src" ,#'lfe-watcher/1))) + `(,(templates-data) + ,(source-data))) -(defun lfe-compiler (filename) - (logjam:info "Recompiling LFE file: ~p" `(,filename))) +(defun lfe-compiler (path file) + (let ((`#(,source-dir ,watcher) (source-data)) + (outdir (get-ebin-dir file)) + (mod-name (get-module-name file)) + (filename (filename:join path file))) + (inotify:unwatch source-dir) + (code:purge mod-name) + (logjam:info "Recompiling LFE file ~p ..." `(,filename)) + (case (lfe_comp:file filename `(#(outdir ,outdir))) + (`#(ok ,_) + (logjam:info "Success.") + (logjam:info "Reloading module ~p ..." `(,mod-name)) + (case (code:load_file mod-name) + (`#(module ,_) (logjam:info "Success.")) + (err (logjam:error "Couldn't reload module: ~p" `(,err))))) + (err (logjam:error "Couldn't compile file: ~p" `(,err)))) + (inotify:watch source-dir watcher))) (defun erlydtl-compiler (filename) - (logjam:info "Recompiling ErlyDTL file: ~p" `(,filename))) + (logjam:info "Recompiling ErlyDTL file: ~p" `(,filename)) + (docs:httpd-restart)) (defun lfe-watcher ((`#(,path file close_write ,fd ,file)) - (lfe-compiler (filename:join path file))) - ((_arg) - 'skipping)) + (lfe-compiler path file)) + ((args) + (logjam:debug "LFE watcher event: ~p" `(,args)))) (defun erlydtl-watcher ((`#(,path file close_write ,fd ,file)) (erlydtl-compiler (filename:join path file))) - ((_) 'skipping)) + ((args) + (logjam:debug "ErlyDTL watcher event: ~p" `(,args)))) (defun start () (start (default-watch-data))) (defun start (watch-data) - (logjam:start) + (docs:start) + (docs:httpd) (application:ensure_all_started 'inotify) (case (lists:map (match-lambda ((`#(,path ,func)) (logjam:debug "Watching path: ~p with function: ~p" @@ -35,3 +59,14 @@ watch-data) ('(ok ok) 'ok) (err (logjam:error err)))) + +(defun get-module-name (filename) + (clj:-> filename + (filename:rootname) + (list_to_atom))) + +(defun get-ebin-dir (filename) + (clj:-> filename + (get-module-name) + (code:which) + (filename:dirname))) From b4fad584af1e66d4da9847a1a13571b0a844d57a Mon Sep 17 00:00:00 2001 From: Duncan McGreggor Date: Sun, 26 Feb 2017 01:17:28 -0600 Subject: [PATCH 3/3] Added cli function for running the watcher. --- src/docs-cli.lfe | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/docs-cli.lfe b/src/docs-cli.lfe index 550f835..8d895ea 100644 --- a/src/docs-cli.lfe +++ b/src/docs-cli.lfe @@ -20,3 +20,9 @@ (lambda () (docs:gen-dev) (docs:httpd)))) + +(defun gen-dev-watch () + (do-cmd + (lambda () + (docs:gen-dev) + (docs-watcher:start))))