-#!/usr/bin/env escript\r
-% coding: utf-8\r
-% Copyright 2008 Grégory Burri\r
-%\r
-% This file is part of Euphorik.\r
-%\r
-% Euphorik is free software: you can redistribute it and/or modify\r
-% it under the terms of the GNU General Public License as published by\r
-% the Free Software Foundation, either version 3 of the License, or\r
-% (at your option) any later version.\r
-%\r
-% Euphorik is distributed in the hope that it will be useful,\r
-% but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-% GNU General Public License for more details.\r
-%\r
-% You should have received a copy of the GNU General Public License\r
-% along with Euphorik. If not, see <http://www.gnu.org/licenses/>.\r
-\r
-% This file replace the old one 'tools.rb' written in a crapy language ;)\r
-% TODO :\r
-% - création de unit tests (voir eunit) et validation avant la mise en prod\r
-\r
-\r
-main(Args) ->\r
- file:set_cwd(".."),\r
- case Args of\r
- ["prod"] -> in_prod("gburri@euphorik.ch:/var/www/euphorik");\r
- ["pre"] -> in_preprod("gburri@euphorik.ch:/var/www/euphorik_preprod", "var/www/euphorik");\r
- ["js"] -> verif_js();\r
- ["version"] -> update_version();\r
- _ ->\r
- io:format(\r
- "Usage : ~s (prod | pre | js | version)~n"\r
- " prod : in production~n"\r
- " pre : in preproduction, data are copied from production~n"\r
- " js : check the JavaScript files~n"\r
- " version : update the version into somes files from the VERSION file",\r
- [escript:script_name()]\r
- )\r
- end.\r
-\r
-\r
-% A simple fonction to log message.\r
-log(Str) ->\r
- io:format("===== ~s =====~n", [Str]).\r
-\r
-\r
-% Execute an OS commande and print the result to stdout.\r
-cmd(Commande_str) ->\r
- cmd(Commande_str, []).\r
-cmd(Commande_str, Params) ->\r
- io:format("~s~n", [os:cmd(lists:flatten(io_lib:format(Commande_str, Params)))]).\r
-\r
-\r
--record(uri, {\r
- host,\r
- path % in absolute\r
-}).\r
-\r
-\r
-% Create an uri record from an uri string.\r
-create_uri(Uri_str) ->\r
- [Host, Path] = string:tokens(Uri_str, ":"),\r
- #uri{host = Host, path = Path}.\r
-\r
-\r
-% Update the version into somes files from the VERSION file.\r
-update_version() ->\r
- log("Update the version tag"),\r
- todo.\r
-\r
-\r
-% Check the JavaScript files.\r
-verif_js() ->\r
- todo.\r
-\r
-\r
-% Start the production processus.\r
-in_prod(Uri) ->\r
- compile_server_part(Uri),\r
- make_var_directory(Uri),\r
- copy_files(Uri),\r
- define_files_rights(Uri),\r
- update_server().\r
-\r
-\r
-% Start the pre-production processus.\r
-in_preprod(Uri, data_path) ->\r
- compile_server_part(Uri),\r
- make_var_directory(Uri),\r
- copy_files(Uri),\r
- define_files_rights(Uri),\r
- start_server(),\r
- update_server().\r
-\r
-\r
-% Compile the Erlang modules.\r
-compile_server_part(Uri) ->\r
- todo.\r
-\r
-\r
-% Create the 'var' folder if it doesn't exist.\r
-make_var_directory(Uri) ->\r
- todo.\r
-\r
-\r
-% Copy files from developpement env to production server.\r
-copy_files(Uri) ->\r
- copy_static_part(Uri),\r
- copy_packed_js(Uri).\r
-\r
-\r
-% Copy all static files like modules, styles, pages, etc.\r
-copy_static_part(Uri) ->\r
- %~ creer_rep('modules')\r
- %~ system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules")\r
- %~ system("rsync -r modules/include #{@uri}:#{@rep}/modules")\r
- todo.\r
-\r
-\r
-% Minify and pack JavaScript in one file then copy it to ther server.\r
-copy_packed_js(Uri) ->\r
- todo.\r
-\r
-\r
-% Define the rights for the copied folder et files.\r
-define_files_rights(Uri) ->\r
- todo.\r
-\r
-\r
-% Start the server if it not already started (in preproduction case only).\r
-start_server() ->\r
- todo.\r
-\r
-\r
-% Run a erlang script to\r
-update_server() ->\r
- todo.\r
-\r
+#!/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.