Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

hooks support

  • Loading branch information...
commit 6dc485dde6acb53640872636bb9b60dc95332af7 1 parent 1d86a39
@chvanikoff authored
Showing with 28 additions and 0 deletions.
  1. +20 −0 README.markdown
  2. +8 −0 src/sync_scanner.erl
View
20 README.markdown
@@ -1,5 +1,25 @@
# Stay in Sync
+## About this fork
+
+This fork includes hooks support before and after updated src files compilation.
+To use hooks you should create a `sync_hooks.erl` file and export 2 functions: `before/1` and `'after'/1`
+
+```erlang
+-module(sync_hooks).
+-export([before/1, 'after'/1]).
+
+before("mymodule") ->
+ %% Do the stuff before "mymodule.erl" recompiled
+ ok;
+before(_File) -> ok.
+
+'after'("mymodule2") ->
+ %% Do the stuff after "mymodule2.erl" was recompiled
+ ok;
+'after'(_File) -> ok.
+```
+
## What is Sync?
Sync is a developer utility. It recompiles and reloads your Erlang
View
8 src/sync_scanner.erl
@@ -331,7 +331,9 @@ process_src_file_lastmod([{File, LastMod}|T1], [{File, LastMod}|T2], EnablePatch
process_src_file_lastmod(T1, T2, EnablePatching);
process_src_file_lastmod([{File, _}|T1], [{File, _}|T2], EnablePatching) ->
%% File has changed, recompile...
+ hook(before, File),
recompile_src_file(File, EnablePatching),
+ hook('after', File),
process_src_file_lastmod(T1, T2, EnablePatching);
process_src_file_lastmod([{File1, LastMod1}|T1], [{File2, LastMod2}|T2], EnablePatching) ->
%% Lists are different...
@@ -535,3 +537,9 @@ lisp_format(String0) ->
Lines1 = string:tokens(String1, [$\n]),
String2 = string:join(Lines1, "\\\" \\\""),
lists:flatten(["\\\"", String2, "\\\""]).
+
+hook(Type, File) ->
+ case code:which(sync_hooks) of
+ non_existing -> ok;
+ _ -> sync_hooks:Type(filename:basename(File, ".erl"))
+ end.
Please sign in to comment.
Something went wrong with that request. Please try again.