-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcopy_static.escript
executable file
·77 lines (67 loc) · 1.9 KB
/
copy_static.escript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env escript
%% -*- erlang -*-
%% vim: ts=4 sw=4 et ft=erlang
%%
%% Coyright 2022 - Jesse Gumm
%%
%% MIT License
%%
%% About
%%
%% This will copy or link the nitrogen static directory into the
%% priv/static/nitrogen directory based on where it finds the nitrogen_core
%% directory (checkouts or lib)
prefix(checkouts) ->
"_checkouts/nitrogen_core";
prefix(build_checkouts) ->
"_build/default/checkouts/nitrogen_core";
prefix(build_lib) ->
"_build/default/lib/nitrogen_core".
possible_locations("static") ->
[
prefix(checkouts) ++ "/www", %% old loc, but let's check
prefix(checkouts) ++ "/priv/www",
prefix(build_checkouts) ++ "/priv/www",
prefix(build_lib) ++ "/priv/www"
];
possible_locations("doc") ->
Doc = "/doc/markdown",
[
prefix(checkouts) ++ Doc,
prefix(build_checkouts) ++ Doc,
prefix(build_lib) ++ Doc
].
dest("static") ->
"priv/static/nitrogen";
dest("doc") ->
"priv/static/doc".
main([]) ->
main(["copy", "static"]);
main([Action]) ->
main([Action, "static"]);
main([Action, Item])
when (Action=="copy" orelse Action=="link") andalso
(Item=="static" orelse Item=="doc") ->
PossibleLocations = possible_locations(Item),
Src = find_first_loc(PossibleLocations),
Dest = dest(Item),
do_action(Action, Src, Dest).
do_action(Action, Src, Dest) ->
cmd("rm -fr " ++ Dest),
case Action of
"copy" ->
cmd("mkdir -p " ++ Dest),
cmd("cp -r " ++ Src ++ "/* " ++ Dest);
"link" ->
cmd("ln -s `pwd`/" ++ Src ++ " " ++ Dest)
end.
cmd(Cmd) ->
io:format("Running: ~s~n", [Cmd]),
os:cmd(Cmd).
find_first_loc([]) ->
exit("nitrogen_core directory not found to link the www directory");
find_first_loc([H|T]) ->
case filelib:is_dir(H) of
true -> H;
false -> find_first_loc(T)
end.