Replace some french comments by english ones.
[euphorik.git] / tools / tools.erl
1 #!/usr/bin/env escript
2
3 % TODO :
4 % * Create some unit tests with eunit before releasing in production.
5
6 main(Args) ->
7 file:set_cwd(".."),
8 case Args of
9 ["build"] -> build();
10 ["run"] -> run_debug();
11 ["pre"] -> in_preprod("gburri@euphorik.ch:/var/www/euphorik_preprod", "var/www/euphorik");
12 ["prod"] -> in_prod("gburri@euphorik.ch:/var/www/euphorik");
13 ["js"] -> verif_js();
14 ["version"] -> update_version();
15 _ ->
16 io:format(
17 "Usage : ~s (build | run | pre | prod | js | version)~n"
18 " prod : in production~n"
19 " pre : in preproduction, data are copied from production~n"
20 " js : check the JavaScript files~n"
21 " version : update the version into somes files from the VERSION file~n",
22 [escript:script_name()]
23 )
24 end.
25
26 % A simple fonction to log message.
27 log(Str) ->
28 io:format("===== ~s =====~n", [Str]).
29
30 % Execute an OS command and print the result to stdout.
31 cmd(Command) ->
32 cmd(Command, []).
33 cmd(Command, Params) ->
34 cmd(Command, Params, ".").
35 cmd(Command, Params, Dir) ->
36 InitialDir = file:get_cwd(),
37 file:set_cwd(Dir),
38 io:format("~s~n", [os:cmd(lists:flatten(io_lib:format(Command, Params)))]),
39 file:set_cwd(InitialDir).
40
41 -record(uri, {
42 host,
43 path % in absolute
44 }).
45
46 % Create an uri record from an uri string.
47 create_uri(Uri_str) ->
48 [Host, Path] = string:tokens(Uri_str, ":"),
49 #uri{host = Host, path = Path}.
50
51 build() ->
52 % Build all the Erlang modules.
53 cmd("make", [], "modules").
54
55 % Update the version into somes files from the VERSION file.
56 update_version() ->
57 log("Update the version tag"),
58 todo.
59
60 % Check the JavaScript files.
61 verif_js() ->
62 todo.
63
64 run_debug() ->
65 build(),
66 todo.
67
68 % Start the production processus.
69 in_prod(Uri) ->
70 compile_server_part(Uri),
71 make_var_directory(Uri),
72 copy_files(Uri),
73 define_files_rights(Uri),
74 update_server().
75
76 % Start the pre-production processus.
77 in_preprod(Uri, data_path) ->
78 compile_server_part(Uri),
79 make_var_directory(Uri),
80 copy_files(Uri),
81 define_files_rights(Uri),
82 start_server(),
83 update_server().
84
85 % Compile the Erlang modules.
86 compile_server_part(Uri) ->
87 todo.
88
89 % Create the 'var' folder if it doesn't exist.
90 make_var_directory(Uri) ->
91 todo.
92
93 % Copy files from developpement env to production server.
94 copy_files(Uri) ->
95 copy_static_part(Uri),
96 copy_packed_js(Uri).
97
98 % Copy all static files like modules, styles, pages, etc.
99 copy_static_part(Uri) ->
100 %~ creer_rep('modules')
101 %~ system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules")
102 %~ system("rsync -r modules/include #{@uri}:#{@rep}/modules")
103 todo.
104
105 % Minify and pack JavaScript in one file then copy it to ther server.
106 copy_packed_js(Uri) ->
107 todo.
108
109 % Define the rights for the copied folder et files.
110 define_files_rights(Uri) ->
111 todo.
112
113 % Start the server if it not already started (in preproduction case only).
114 start_server() ->
115 cmd("yaws --conf ./yaws.conf --sname yaws_dev --mnesiadir \"../var/database/\" -I debian_yaws_dev").
116
117 % Run a erlang script to
118 update_server() ->
119 todo.