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 % Create the directory "var/database" if it doesn't exist.
53 {ok
, Files_in_root
} = file:list_dir("."),
54 Var_exists
= lists:any(fun(Name
) -> Name
=:= "var" end, Files_in_root
),
59 {ok
, Files_in_var
} = file:list_dir("var"),
60 Database_exists
= lists:any(fun(Name
) -> Name
=:= "database" end, Files_in_var
),
61 if not Database_exists
->
62 file:make_dir("var/database");
65 % Build all the Erlang modules.
66 cmd("make", [], "modules").
68 % Update the version into somes files from the VERSION file.
70 log("Update the version tag"),
73 % Check the JavaScript files.
81 % Start the production processus.
83 compile_server_part(Uri
),
84 make_var_directory(Uri
),
86 define_files_rights(Uri
),
89 % Start the pre-production processus.
90 in_preprod(Uri
, data_path
) ->
91 compile_server_part(Uri
),
92 make_var_directory(Uri
),
94 define_files_rights(Uri
),
98 % Compile the Erlang modules.
99 compile_server_part(Uri
) ->
102 % Create the 'var' folder if it doesn't exist.
103 make_var_directory(Uri
) ->
106 % Copy files from developpement env to production server.
108 copy_static_part(Uri
),
111 % Copy all static files like modules, styles, pages, etc.
112 copy_static_part(Uri
) ->
113 %~ creer_rep('modules')
114 %~ system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules")
115 %~ system("rsync -r modules/include #{@uri}:#{@rep}/modules")
118 % Minify and pack JavaScript in one file then copy it to ther server.
119 copy_packed_js(Uri
) ->
122 % Define the rights for the copied folder et files.
123 define_files_rights(Uri
) ->
126 % Start the server if it not already started (in preproduction case only).
128 cmd("yaws --conf ./yaws.conf --sname yaws_dev --mnesiadir \"../var/database/\" -I debian_yaws_dev").
130 % Run a erlang script to