Skip to content

Commit

Permalink
erlca -> erica final name of couchapp utility in erlang.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitc committed Jun 7, 2011
1 parent e26fa50 commit 90f004c
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 177 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ doc:

clean:
@./rebar clean
@rm -f erlca
@rm -f erica

distclean: clean
@./rebar delete-deps
Expand Down
6 changes: 3 additions & 3 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

couchapp_log
------------
Based on rebar_log from rebar tool.
erica_log, erica_templater
-----------------------------
from rebar tool.

Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com)

Expand Down
16 changes: 8 additions & 8 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ main(Args) ->



%% Run erlca to do proper .app validation and such
erlca:main(["compile"] ++ Args),
%% Run erica to do proper .app validation and such
erica:main(["compile"] ++ Args),


%% Read the contents of the files in ebin and templates; note that we place
Expand All @@ -33,32 +33,32 @@ main(Args) ->
%% Archive was successfully created. Prefix that binary with our
%% header and write to "rebar" file
Script = <<"#!/usr/bin/env escript\n%%! -pa . -noshell -noinput -sasl errlog_type error\n", ZipBin/binary>>,
case file:write_file("erlca", Script) of
case file:write_file("erica", Script) of
ok ->
ok;
{error, WriteError} ->
io:format("Failed to write erlca script: ~p\n", [WriteError]),
io:format("Failed to write erica script: ~p\n", [WriteError]),
halt(1)
end;
{error, ZipError} ->
io:format("Failed to construct erlca archive: ~p\n", [ZipError]),
io:format("Failed to construct erica archive: ~p\n", [ZipError]),
halt(1)
end,

%% Finally, update executable perms for our script
case os:type() of
{unix,_} ->
[] = os:cmd("chmod u+x erlca"),
[] = os:cmd("chmod u+x erica"),
ok;
_ ->
ok
end,

%% Add a helpful message
io:format("Congratulations! You now have a self-contained script called \"erlca\" in\n"
io:format("Congratulations! You now have a self-contained script called \"erica\" in\n"
"your current working directory. Place this script anywhere in your path\n"
"and you can use build and push your design docs and docs
like erlca.\n").
like erica.\n").

load_files(Wildcard, Dir) ->
[read_file(Filename, Dir) || Filename <- filelib:wildcard(Wildcard,
Expand Down
14 changes: 7 additions & 7 deletions include/erlca.hrl → include/erica.hrl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%%% -*- erlang -*-
%%%
%%% This file is part of erlca released under the Apache 2 license.
%%% This file is part of erica released under the Apache 2 license.
%%% See the NOTICE for more information.

-record(config, { dir,
Expand All @@ -14,18 +14,18 @@

-define(FAIL, throw({error, failed})).

-define(ABORT(Str, Args), erlca_util:abort(Str, Args)).
-define(ABORT(Str, Args), erica_util:abort(Str, Args)).

-define(CONSOLE(Str, Args), io:format(Str, Args)).

-define(DEBUG(Str, Args), erlca_log:log(debug, Str, Args)).
-define(INFO(Str, Args), erlca_log:log(info, Str, Args)).
-define(WARN(Str, Args), erlca_log:log(warn, Str, Args)).
-define(ERROR(Str, Args), erlca_log:log(error, Str, Args)).
-define(DEBUG(Str, Args), erica_log:log(debug, Str, Args)).
-define(INFO(Str, Args), erica_log:log(info, Str, Args)).
-define(WARN(Str, Args), erica_log:log(warn, Str, Args)).
-define(ERROR(Str, Args), erica_log:log(error, Str, Args)).

-define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).

-record(erlca, {
-record(couchapp, {
config,
path,
att_dir,
Expand Down
23 changes: 23 additions & 0 deletions src/erica.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
%%% -*- erlang -*-
%%%
%%% This file is part of erica released under the Apache 2 license.
%%% See the NOTICE for more information.

{application, erica,
[{description, "erica: Couchdb Application Tool"},
{vsn, "0.1.0"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib]},
{included_applications, [crypto, sasl, ibrowse, ejson, couchbeam]},
{env, [
%% default log level
{log_level, error},

%% list of commands modules
{modules, [
erica_init,
erica_generate,
erica_push,
erica_clone]}
]}]}.
8 changes: 4 additions & 4 deletions src/erlca.erl → src/erica.erl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
%%% -*- erlang -*-
%%%
%%% This file is part of erlca released under the Apache 2 license.
%%% This file is part of erica released under the Apache 2 license.
%%% See the NOTICE for more information.

-module(erlca).
-module(erica).
-author('Benoît Chesneau <benoitc@e-engura.org>').

-export([main/1]).

main(Args) ->
case catch(erlca_core:run(Args)) of
case catch(erica_core:run(Args)) of
ok ->
ok;
{error, failed} ->
halt(1);
Error ->
io:format("Uncaught error in erlca: ~p\n", [Error]),
io:format("Uncaught error in erica: ~p\n", [Error]),
halt(1)
end.
26 changes: 13 additions & 13 deletions src/erlca_clone.erl → src/erica_clone.erl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
%%% -*- erlang -*-
%%%
%%% This file is part of erlca released under the Apache 2 license.
%%% This file is part of erica released under the Apache 2 license.
%%% See the NOTICE for more information.

-module(erlca_clone).
-module(erica_clone).

-include("erlca.hrl").
-include("erica.hrl").

-export([clone/2]).

Expand All @@ -18,7 +18,7 @@ clone([Url], Config) ->
clone([Url, Path|_], Config) ->
clone1(filename:absname(Path), Url, Config);
clone(_, _) ->
?ERROR("missing arguments. Command line should be :'erlca clone "
?ERROR("missing arguments. Command line should be :'couchapp clone "
++ "URL [CouchappDir]", []),
halt(1).

Expand All @@ -27,17 +27,17 @@ clone(_, _) ->
%% ====================================================================

clone1(Path, Url, Config) ->
case erlca_util:parse_erlca_url(Url) of
case erica_util:parse_couchapp_url(Url) of
{ok, Db, AppName, DocId} ->
Path1 = case Path of
"." ->
filename:join(erlca_util:get_cwd(), AppName);
filename:join(erica_util:get_cwd(), AppName);
_ ->
filename:absname(Path)
end,
case erlca_util:in_erlca(Path1) of
case erica_util:in_couchapp(Path1) of
{ok, _} ->
?ERROR("Can't clone in an existing erlca.~n",
?ERROR("Can't clone in an existing couchapp.~n",
[]),
halt(1);
_ ->
Expand All @@ -50,10 +50,10 @@ clone1(Path, Url, Config) ->
do_clone(Path, DocId, Db, Config) ->
case couchbeam:open_doc(Db, DocId) of
{ok, Doc} ->
% initialize the erlca directory
% initialize the couchapp directory
ok = filelib:ensure_dir(Path),
?DEBUG("path ~p~n", [Path]),
erlca_init:init([Path], Config),
erica_init:init([Path], Config),

AttDir = filename:join(Path, "_attachments"),
{Atts} = couchbeam_doc:get_value(<<"_attachments">>, Doc,
Expand Down Expand Up @@ -98,7 +98,7 @@ attachments_to_fs([AttName|Rest], Db, DocId, AttDir) ->
AttName1 = binary_to_list(AttName),
Path = filename:join(AttDir, filename:nativename(AttName1)),
Dir = filename:dirname(Path),
ok = erlca_util:make_dir(Dir),
ok = erica_util:make_dir(Dir),

%% we stream attachments.
{ok, Fd} = file:open(Path, [write]),
Expand Down Expand Up @@ -134,7 +134,7 @@ doc_to_fs([{<<"_attachments">>, _}|Rest], Dir, Manifest, Objects,
doc_to_fs([{PropName, Value}|Rest], Dir, Manifest, Objects, Depth) ->
Path = filename:join(Dir, binary_to_list(PropName)),
Dir1 = filename:dirname(Path),
ok = erlca_util:make_dir(Dir1),
ok = erica_util:make_dir(Dir1),
case Value of
{[_|_]} ->
case proplists:get_value(Path, Manifest) of
Expand All @@ -155,7 +155,7 @@ doc_to_fs([{PropName, Value}|Rest], Dir, Manifest, Objects, Depth) ->
{Path, V};
Ext when Ext =:= ".js" ->
SourceId = list_to_binary(
erlca_macros:get_source_id(Value)),
erica_macros:get_source_id(Value)),
V1 = case proplists:get_value(SourceId,
Objects) of
undefined ->
Expand Down
30 changes: 15 additions & 15 deletions src/erlca_config.erl → src/erica_config.erl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
%%% -*- erlang -*-
%%%
%%% This file is part of erlca released under the Apache 2 license.
%%% This file is part of erica released under the Apache 2 license.
%%% See the NOTICE for more information.

-module(erlca_config).
-module(erica_config).

-include("deps/couchbeam/include/couchbeam.hrl").
-include("erlca.hrl").
-include("erica.hrl").

-export([new/0, new/1,
update/2,
Expand All @@ -15,12 +15,12 @@
set/3,
set_global/2, get_global/2]).
new() ->
#config { dir = erlca_util:get_cwd(),
#config { dir = erica_util:get_cwd(),
opts = [] }.

new(Options) ->
UserConfFile = filename:join(erlca_util:user_path(),
".erlca.conf"),
UserConfFile = filename:join(erica_util:user_path(),
".erica.conf"),
UserConf = case filelib:is_regular(UserConfFile) of
true ->
{ok, Bin} = file:read_file(UserConfFile),
Expand All @@ -30,7 +30,7 @@ new(Options) ->
end,
{Dbs, Hooks, Extensions, Ignore} = parse_conf(UserConf),

#config { dir = erlca_util:get_cwd(),
#config { dir = erica_util:get_cwd(),
opts = Options,
dbs = Dbs,
hooks = Hooks,
Expand All @@ -40,9 +40,9 @@ new(Options) ->

update(AppDir, #config{dbs=Dbs, hooks=Hooks, extensions=Extensions,
ignore=Ignore}=Config) ->
RcFile = filename:join(AppDir, ".erlcarc"),
RcFile = filename:join(AppDir, ".couchapprc"),

%% load .erlcarc
%% load .couchapprc
AppConf = case filelib:is_regular(RcFile) of
true ->
{ok, Bin} = file:read_file(RcFile),
Expand All @@ -51,25 +51,25 @@ update(AppDir, #config{dbs=Dbs, hooks=Hooks, extensions=Extensions,
{[]}
end,

%% update conf from .erlcarc
%% update conf from .couchapprc
{Dbs1, Hooks1, Extensions1, Ignore1} = parse_conf(AppConf),
Config1 = Config#config { dbs = Dbs ++ Dbs1,
hooks = Hooks ++ Hooks1,
extensions = Extensions ++ Extensions1,
ignore = Ignore ++ Ignore1},

%% get ignore file patterns.
erlca_ignore:init(AppDir, Config1).
erica_ignore:init(AppDir, Config1).


get_db(Config, DbString) ->
proplists:get_value(DbString, Config#config.dbs).

set_global(Key, Value) ->
application:set_env(erlca_global, Key, Value).
application:set_env(erica_global, Key, Value).

get_global(Key, Default) ->
case application:get_env(erlca_global, Key) of
case application:get_env(erica_global, Key) of
undefined ->
Default;
{ok, Value} ->
Expand All @@ -96,7 +96,7 @@ parse_conf(Conf) ->
Extensions = case couchbeam_doc:get_value(<<"extensions">>, Conf) of
undefined -> [];
{Ext} ->
[{erlca_util:v2a(Mod), erlca_util:v2a(Command)}
[{erica_util:v2a(Mod), erica_util:v2a(Command)}
|| {Mod, Command} <- Ext]
end,
Hooks = case couchbeam_doc:get_value(<<"hooks">>, Conf) of
Expand All @@ -120,7 +120,7 @@ get_config_dbs([{Name, Obj}|Rest], Dbs) ->
undefined ->
get_config_dbs(Rest, Dbs);
DbString ->
Db = erlca_util:db_from_string(binary_to_list(DbString)),
Db = erica_util:db_from_string(binary_to_list(DbString)),
Db1 = case couchbeam_doc:get_value(<<"oauth">>, Obj) of
undefined ->
Db;
Expand Down
Loading

0 comments on commit 90f004c

Please sign in to comment.