#!/usr/bin/env escript % TODO : % * Create some unit tests with eunit before releasing in production. main(Args) -> file:set_cwd(".."), case Args of ["build"] -> build(); ["run"] -> run_debug(); ["pre"] -> in_preprod("gburri@euphorik.ch:/var/www/euphorik_preprod", "var/www/euphorik"); ["prod"] -> in_prod("gburri@euphorik.ch:/var/www/euphorik"); ["js"] -> verif_js(); ["version"] -> update_version(); _ -> io:format( "Usage : ~s (build | run | pre | prod | js | version)~n" " prod : in production~n" " pre : in preproduction, data are copied from production~n" " js : check the JavaScript files~n" " version : update the version into somes files from the VERSION file~n", [escript:script_name()] ) end. % A simple fonction to log message. log(Str) -> io:format("===== ~s =====~n", [Str]). % Execute an OS command and print the result to stdout. cmd(Command) -> cmd(Command, []). cmd(Command, Params) -> cmd(Command, Params, "."). cmd(Command, Params, Dir) -> InitialDir = file:get_cwd(), file:set_cwd(Dir), io:format("~s~n", [os:cmd(lists:flatten(io_lib:format(Command, Params)))]), file:set_cwd(InitialDir). -record(uri, { host, path % in absolute }). % Create an uri record from an uri string. create_uri(Uri_str) -> [Host, Path] = string:tokens(Uri_str, ":"), #uri{host = Host, path = Path}. build() -> % Build all the Erlang modules. cmd("make", [], "modules"). % Update the version into somes files from the VERSION file. update_version() -> log("Update the version tag"), todo. % Check the JavaScript files. verif_js() -> todo. run_debug() -> build(), todo. % Start the production processus. in_prod(Uri) -> compile_server_part(Uri), make_var_directory(Uri), copy_files(Uri), define_files_rights(Uri), update_server(). % Start the pre-production processus. in_preprod(Uri, data_path) -> compile_server_part(Uri), make_var_directory(Uri), copy_files(Uri), define_files_rights(Uri), start_server(), update_server(). % Compile the Erlang modules. compile_server_part(Uri) -> todo. % Create the 'var' folder if it doesn't exist. make_var_directory(Uri) -> todo. % Copy files from developpement env to production server. copy_files(Uri) -> copy_static_part(Uri), copy_packed_js(Uri). % Copy all static files like modules, styles, pages, etc. copy_static_part(Uri) -> %~ creer_rep('modules') %~ system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules") %~ system("rsync -r modules/include #{@uri}:#{@rep}/modules") todo. % Minify and pack JavaScript in one file then copy it to ther server. copy_packed_js(Uri) -> todo. % Define the rights for the copied folder et files. define_files_rights(Uri) -> todo. % Start the server if it not already started (in preproduction case only). start_server() -> cmd("yaws --conf ./yaws.conf --sname yaws_dev --mnesiadir \"../var/database/\" -I debian_yaws_dev"). % Run a erlang script to update_server() -> todo.