From Rails to Erlyweb - Part II
2. Manage project
Erlyweb provides erlyweb:compile(App, ..) to compile the source files under app directory. To start an app, you usually should erlydb:start(mysql, ....) and compile app files first. To make life easy, you can put some scripting like code under myproject\script directory. Here's my project source tree:
myproject
+ apps
| + myapp
| + ebin
| + include
| + nbproject
| + src
| + components
| + lib
| + services
| + test
| + www
+ config
| * yaws.conf
+ script
+ ebin
* erlyweb_app.erl
Where, config/yaws.conf contains the configuration that will copy/paste to your real yaws.conf file. Here's mine:
## This is the configuration of apps that will copy/paste to your yaws.conf.
ebin_dir = D:/myapp/trunk/script/ebin
ebin_dir = D:/myapp/trunk/apps/myapp/ebin
<server localhost>
port = 8000
listen = 0.0.0.0
docroot = D:/myapp/trunk/apps/myapp/www
appmods = </myapp, erlyweb>
<opaque>
appname = myapp
</opaque>
</server>
You may have noticed, all beams under D:/myapp/trunk/script/ebin and D:/myapp/trunk/apps/myapp/ebin will be auto-loaded by yaws.
erlyweb_app.erl is the boot scripting code, which will be used to start db connection and compile the code. Currently I run these scripts manually. I'll talk later.
-module(erlyweb_app).
-export([main/1, boot/1, build/1, start_db/0]).
main([AppName]) ->
boot(AppName);
main(_) ->
usage().
boot(AppName) ->
build(AppName, true).
build(AppName) ->
build(AppName, false).
build(AppName, AutoCompile) ->
start_db(),
compile(AppName, [{auto_compile, AutoCompile}]).
start_db() ->
erlydb:start(
mysql,
[{hostname, "localhost"},
{username, "mememe"},
{password, "uuu"},
{database, "myapp_dev"}]).
compile(AppName, Options) ->
erlyweb:compile(
"./apps/" ++ AppName,
[{erlydb_driver, mysql}] ++ Options).
usage() ->
io:format("usage: erlyweb_app AppName\n"),
halt(1).
So, I start myapp by steps:
cd \myproject
yaws -i -sname yaws
1> erlyweb_app:build("myapp").
The erlyweb_app.erl is almost escript ready, but I use it as module functions currently. It's pre-compiled and erlyweb_app.beam is placed under script/ebin
After I made changes to myapp, I run above erlyweb_app:build("myapp"). again, then everything is up to date.
This is sure not the best way to handle the write-compile-run-test cycle, I'll improve the scripting to let starting yaws as a node, then hot-swap the compiled code to it.
Comparing to Rails, the Erlyweb project management needs improvement, such as store the database configuration in a plain environment file, and auto load it etc.
It's a good experience to play with Rails, I like rake db:migrate, script, config folder of Rails. And Grails also brings some good idea to manage web app project tree. I'll try to bring them into project manager of ErlyBird.
发表评论
最近加入圈子
最新评论
-
ErlyBird 0.16.0 Released
Others->Erlang...
-- by dcaoyuan -
ErlyBird 0.16.0 Released
为什么我在NB内导入完成后,在New Project里面无法看到 create ...
-- by fatdong -
新的Scala for NetBeans提 ...
因为NetBeans的几个基础模块在Trunk里有与6.1不兼容的的变化,所以现 ...
-- by dcaoyuan -
新的Scala for NetBeans提 ...
另外,dcaoyuan大叔有空时能否简单说一下为NetBeans开发某一门语言的 ...
-- by 自言200801 -
新的Scala for NetBeans提 ...
重新更新以后就装不起来啦,错误如下:====================== ...
-- by 自言200801







评论排行榜