FIX suppression des /;;.*$/ (définit étant un commentaire) lors de la minification...
[euphorik.git] / tools / tools.erl
1 #!/usr/bin/env escript
2 % coding: utf-8
3 % Copyright 2008 Grégory Burri
4 %
5 % This file is part of Euphorik.
6 %
7 % Euphorik is free software: you can redistribute it and/or modify
8 % it under the terms of the GNU General Public License as published by
9 % the Free Software Foundation, either version 3 of the License, or
10 % (at your option) any later version.
11 %
12 % Euphorik is distributed in the hope that it will be useful,
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 % GNU General Public License for more details.
16 %
17 % You should have received a copy of the GNU General Public License
18 % along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
19
20 % This file replace the old one 'tools.rb' written in a crapy language ;)
21 % TODO :
22 % - création de unit tests (voir eunit) et validation avant la mise en prod
23
24
25 main(Args) ->
26 file:set_cwd(".."),
27 case Args of
28 ["prod"] -> in_prod("gburri@euphorik.ch:/var/www/euphorik");
29 ["pre"] -> in_preprod("gburri@euphorik.ch:/var/www/euphorik_preprod", "var/www/euphorik");
30 ["js"] -> verif_js();
31 ["version"] -> update_version();
32 _ ->
33 io:format(
34 "Usage : ~s (prod | pre | js | version)~n"
35 " prod : in production~n"
36 " pre : in preproduction, data are copied from production~n"
37 " js : check the JavaScript files~n"
38 " version : update the version into somes files from the VERSION file",
39 [escript:script_name()]
40 )
41 end.
42
43
44 % A simple fonction to log message.
45 log(Str) ->
46 io:format("===== ~s =====~n", [Str]).
47
48
49 % Execute an OS commande and print the result to stdout.
50 cmd(Commande_str) ->
51 cmd(Commande_str, []).
52 cmd(Commande_str, Params) ->
53 io:format("~s~n", [os:cmd(lists:flatten(io_lib:format(Commande_str, Params)))]).
54
55
56 -record(uri, {
57 host,
58 path % in absolute
59 }).
60
61
62 % Create an uri record from an uri string.
63 create_uri(Uri_str) ->
64 [Host, Path] = string:tokens(Uri_str, ":"),
65 #uri{host = Host, path = Path}.
66
67
68 % Update the version into somes files from the VERSION file.
69 update_version() ->
70 log("Update the version tag"),
71 todo.
72
73
74 % Check the JavaScript files.
75 verif_js() ->
76 todo.
77
78
79 % Start the production processus.
80 in_prod(Uri) ->
81 compile_server_part(Uri),
82 make_var_directory(Uri),
83 copy_files(Uri),
84 define_files_rights(Uri),
85 update_server().
86
87
88 % Start the pre-production processus.
89 in_preprod(Uri, data_path) ->
90 compile_server_part(Uri),
91 make_var_directory(Uri),
92 copy_files(Uri),
93 define_files_rights(Uri),
94 start_server(),
95 update_server().
96
97
98 % Compile the Erlang modules.
99 compile_server_part(Uri) ->
100 todo.
101
102
103 % Create the 'var' folder if it doesn't exist.
104 make_var_directory(Uri) ->
105 todo.
106
107
108 % Copy files from developpement env to production server.
109 copy_files(Uri) ->
110 copy_static_part(Uri),
111 copy_packed_js(Uri).
112
113
114 % Copy all static files like modules, styles, pages, etc.
115 copy_static_part(Uri) ->
116 %~ creer_rep('modules')
117 %~ system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules")
118 %~ system("rsync -r modules/include #{@uri}:#{@rep}/modules")
119 todo.
120
121
122 % Minify and pack JavaScript in one file then copy it to ther server.
123 copy_packed_js(Uri) ->
124 todo.
125
126
127 % Define the rights for the copied folder et files.
128 define_files_rights(Uri) ->
129 todo.
130
131
132 % Start the server if it not already started (in preproduction case only).
133 start_server() ->
134 todo.
135
136
137 % Run a erlang script to
138 update_server() ->
139 todo.
140