3 % Copyright 2008 Grégory Burri
5 % This file is part of Euphorik.
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.
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.
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/>.
20 % This file replace the old one 'tools.rb' written in a crapy language ;)
22 % - création de unit tests (voir eunit) et validation avant la mise en prod
28 ["prod"] -> in_prod("gburri@euphorik.ch:/var/www/euphorik");
29 ["pre"] -> in_preprod("gburri@euphorik.ch:/var/www/euphorik_preprod", "var/www/euphorik");
31 ["version"] -> update_version();
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()]
44 % A simple fonction to log message.
46 io:format("===== ~s =====~n", [Str
]).
49 % Execute an OS commande and print the result to stdout.
51 cmd(Commande_str
, []).
52 cmd(Commande_str
, Params
) ->
53 io:format("~s~n", [os:cmd(lists:flatten(io_lib:format(Commande_str
, Params
)))]).
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
}.
68 % Update the version into somes files from the VERSION file.
70 log("Update the version tag"),
74 % Check the JavaScript files.
79 % Start the production processus.
81 compile_server_part(Uri
),
82 make_var_directory(Uri
),
84 define_files_rights(Uri
),
88 % Start the pre-production processus.
89 in_preprod(Uri
, data_path
) ->
90 compile_server_part(Uri
),
91 make_var_directory(Uri
),
93 define_files_rights(Uri
),
98 % Compile the Erlang modules.
99 compile_server_part(Uri
) ->
103 % Create the 'var' folder if it doesn't exist.
104 make_var_directory(Uri
) ->
108 % Copy files from developpement env to production server.
110 copy_static_part(Uri
),
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")
122 % Minify and pack JavaScript in one file then copy it to ther server.
123 copy_packed_js(Uri
) ->
127 % Define the rights for the copied folder et files.
128 define_files_rights(Uri
) ->
132 % Start the server if it not already started (in preproduction case only).
137 % Run a erlang script to