4 % * Create some unit tests with eunit before releasing in production.
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");
14 ["version"] -> update_version();
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()]
26 % A simple fonction to log message.
28 io:format("===== ~s =====~n", [Str
]).
30 % Execute an OS command and print the result to stdout.
33 cmd(Command
, Params
) ->
34 cmd(Command
, Params
, ".").
35 cmd(Command
, Params
, Dir
) ->
36 InitialDir
= file:get_cwd(),
38 io:format("~s~n", [os:cmd(lists:flatten(io_lib:format(Command
, Params
)))]),
39 file:set_cwd(InitialDir
).
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
}.
52 % Build all the Erlang modules.
53 cmd("make", [], "modules").
55 % Update the version into somes files from the VERSION file.
57 log("Update the version tag"),
60 % Check the JavaScript files.
68 % Start the production processus.
70 compile_server_part(Uri
),
71 make_var_directory(Uri
),
73 define_files_rights(Uri
),
76 % Start the pre-production processus.
77 in_preprod(Uri
, data_path
) ->
78 compile_server_part(Uri
),
79 make_var_directory(Uri
),
81 define_files_rights(Uri
),
85 % Compile the Erlang modules.
86 compile_server_part(Uri
) ->
89 % Create the 'var' folder if it doesn't exist.
90 make_var_directory(Uri
) ->
93 % Copy files from developpement env to production server.
95 copy_static_part(Uri
),
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")
105 % Minify and pack JavaScript in one file then copy it to ther server.
106 copy_packed_js(Uri
) ->
109 % Define the rights for the copied folder et files.
110 define_files_rights(Uri
) ->
113 % Start the server if it not already started (in preproduction case only).
115 cmd("yaws --conf ./yaws.conf --sname yaws_dev --mnesiadir \"../var/database/\" -I debian_yaws_dev").
117 % Run a erlang script to