From 5c167a11d9e522c6ec572d8dc2a738a9352f1b5a Mon Sep 17 00:00:00 2001 From: Adam Jacob Date: Tue, 18 Aug 2015 14:19:25 -0700 Subject: [PATCH] Updated to match rebar3 'release' template * Updates the webmachine template to be identical to the rebar3 release template * Obviously adds webmachine resources * Puts files in a webmachine/ subdirectory, so you could have more than one template extension installed --- rebar.config | 4 -- relx.config | 4 -- src/_.app.src | 21 ----------- src/_app.erl | 13 ------- src/_sup.erl | 20 ---------- webmachine.template | 34 ++++++++--------- webmachine/LICENSE | 29 +++++++++++++++ Makefile => webmachine/Makefile | 3 ++ _README.md => webmachine/README.md | 2 +- webmachine/app.erl | 27 ++++++++++++++ src/_config.erl => webmachine/config.erl | 19 +++++----- dot.gitignore => webmachine/gitignore | 0 webmachine/otp_app.app.src | 23 ++++++++++++ webmachine/relx_rebar.config | 23 ++++++++++++ src/_resource.erl => webmachine/resource.erl | 7 ++-- webmachine/sup.erl | 39 ++++++++++++++++++++ webmachine/sys.config | 3 ++ src/_.erl => webmachine/top.erl | 1 + webmachine/vm.args | 6 +++ 19 files changed, 186 insertions(+), 92 deletions(-) delete mode 100644 rebar.config delete mode 100644 relx.config delete mode 100644 src/_.app.src delete mode 100644 src/_app.erl delete mode 100644 src/_sup.erl create mode 100644 webmachine/LICENSE rename Makefile => webmachine/Makefile (93%) rename _README.md => webmachine/README.md (97%) create mode 100644 webmachine/app.erl rename src/_config.erl => webmachine/config.erl (59%) rename dot.gitignore => webmachine/gitignore (100%) create mode 100644 webmachine/otp_app.app.src create mode 100644 webmachine/relx_rebar.config rename src/_resource.erl => webmachine/resource.erl (87%) create mode 100644 webmachine/sup.erl create mode 100644 webmachine/sys.config rename src/_.erl => webmachine/top.erl (99%) create mode 100644 webmachine/vm.args diff --git a/rebar.config b/rebar.config deleted file mode 100644 index 79a0b84..0000000 --- a/rebar.config +++ /dev/null @@ -1,4 +0,0 @@ -%%-*- mode: erlang -*- -{deps, [ - {webmachine, "1.10.*", {git, "git://github.com/webmachine/webmachine", {branch, "develop"}}} -]}. diff --git a/relx.config b/relx.config deleted file mode 100644 index 8276cab..0000000 --- a/relx.config +++ /dev/null @@ -1,4 +0,0 @@ -{release, { {{name}}, "0.0.1"}, - [{{name}}]}. - -{extended_start_script, true}. diff --git a/src/_.app.src b/src/_.app.src deleted file mode 100644 index 2a11115..0000000 --- a/src/_.app.src +++ /dev/null @@ -1,21 +0,0 @@ -%%-*- mode: erlang -*- -{application, {{name}}, - [ - {description, "{{name}}"}, - {vsn, "1"}, - {modules, []}, - {registered, []}, - {applications, [ - kernel, - stdlib, - inets, - crypto, - mochiweb, - webmachine - ]}, - {mod, { {{name}}_app, []}}, - {env, [ - {web_ip, "0.0.0.0"}, - {web_port, 8080} - ]} - ]}. diff --git a/src/_app.erl b/src/_app.erl deleted file mode 100644 index 68d95f7..0000000 --- a/src/_app.erl +++ /dev/null @@ -1,13 +0,0 @@ --module({{name}}_app). - --behaviour(application). --export([ - start/2, - stop/1 -]). - -start(_Type, _StartArgs) -> - {{name}}_sup:start_link(). - -stop(_State) -> - ok. diff --git a/src/_sup.erl b/src/_sup.erl deleted file mode 100644 index df63a97..0000000 --- a/src/_sup.erl +++ /dev/null @@ -1,20 +0,0 @@ --module({{name}}_sup). --behaviour(supervisor). - -%% External exports --export([ - start_link/0 -]). - -%% supervisor callbacks --export([init/1]). - -start_link() -> - supervisor:start_link({local, ?MODULE}, ?MODULE, []). - -init([]) -> - Web = {webmachine_mochiweb, - {webmachine_mochiweb, start, [{{name}}_config:web_config()]}, - permanent, 5000, worker, [mochiweb_socket_server]}, - Processes = [Web], - {ok, { {one_for_one, 10, 10}, Processes} }. diff --git a/webmachine.template b/webmachine.template index 40d3900..a0a5697 100644 --- a/webmachine.template +++ b/webmachine.template @@ -1,23 +1,23 @@ %%-*- mode: erlang -*- -{description, "Generates an empty WebMachine application"}. +{description, "OTP Release structure for executable Webmachine programs"}. {variables, [ - {name, "wmskel", "name of the application to build"}, - {prefix, ".", "path where the application should be created"} + {name, "myapp", "Name of the OTP release. An app with this name will also be created."}, + {desc, "A Webmachine Service", "Short description of the release's main app's purpose"} ]}. -%% main project files -{template, "_README.md", "{{prefix}}/README.md"}. -{template, "Makefile", "{{prefix}}/Makefile"}. -{template, "rebar.config", "{{prefix}}/rebar.config"}. -{template, "relx.config", "{{prefix}}/relx.config"}. -{template, "dot.gitignore", "{{prefix}}/.gitignore"}. +{template, "webmachine/Makefile", "{{name}}/Makefile"}. +{template, "webmachine/app.erl", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}_app.erl"}. +{template, "webmachine/sup.erl", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}_sup.erl"}. +{template, "webmachine/config.erl", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}_config.erl"}. +{template, "webmachine/resource.erl", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}_resource.erl"}. +{template, "webmachine/top.erl", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}.erl"}. +{template, "webmachine/otp_app.app.src", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}.app.src"}. +{template, "webmachine/relx_rebar.config", "{{name}}/rebar.config"}. +{template, "webmachine/sys.config", "{{name}}/config/sys.config"}. +{template, "webmachine/vm.args", "{{name}}/config/vm.args"}. +{template, "webmachine/gitignore", "{{name}}/.gitignore"}. +{template, "webmachine/LICENSE", "{{name}}/LICENSE"}. +{template, "webmachine/README.md", "{{name}}/README.md"}. -{template, "src/_.app.src", "{{prefix}}/src/{{name}}.app.src"}. +{dir, "{{name}}/priv/www"}. -{template, "src/_.erl", "{{prefix}}/src/{{name}}.erl"}. -{template, "src/_app.erl", "{{prefix}}/src/{{name}}_app.erl"}. -{template, "src/_sup.erl", "{{prefix}}/src/{{name}}_sup.erl"}. -{template, "src/_config.erl", "{{prefix}}/src/{{name}}_config.erl"}. -{template, "src/_resource.erl", "{{prefix}}/src/{{name}}_resource.erl"}. - -{dir, "{{prefix}}/priv/www"}. diff --git a/webmachine/LICENSE b/webmachine/LICENSE new file mode 100644 index 0000000..41588ab --- /dev/null +++ b/webmachine/LICENSE @@ -0,0 +1,29 @@ +Copyright (c) {{copyright_year}}, {{author_name}} <{{author_email}}>. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +* The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/webmachine/Makefile similarity index 93% rename from Makefile rename to webmachine/Makefile index 14debc8..6564b12 100644 --- a/Makefile +++ b/webmachine/Makefile @@ -19,6 +19,9 @@ all: $(REBAR3) rel: all @$(REBAR3) release +prod: all + @$(REBAR3) as prod release + $(REBAR3): curl -Lo rebar3 $(REBAR3_URL) || wget $(REBAR3_URL) chmod a+x rebar3 diff --git a/_README.md b/webmachine/README.md similarity index 97% rename from _README.md rename to webmachine/README.md index 717c112..ea8158e 100644 --- a/_README.md +++ b/webmachine/README.md @@ -5,7 +5,7 @@ You should find in this directory: README : this file Makefile : simple make commands rebar.config : configuration for Rebar3 -/src +{{apps_dir}}/{{name}}/src /{{name}}.app.src : application information file for OTP /{{name}}.erl : the public API for your app /{{name}}_app.erl : base module for the Erlang application behavior diff --git a/webmachine/app.erl b/webmachine/app.erl new file mode 100644 index 0000000..2e7b909 --- /dev/null +++ b/webmachine/app.erl @@ -0,0 +1,27 @@ +%%%------------------------------------------------------------------- +%% @doc {{name}} public API +%% @end +%%%------------------------------------------------------------------- + +-module('{{name}}_app'). + +-behaviour(application). + +%% Application callbacks +-export([start/2 + ,stop/1]). + +%%==================================================================== +%% API +%%==================================================================== + +start(_StartType, _StartArgs) -> + '{{name}}_sup':start_link(). + +%%-------------------------------------------------------------------- +stop(_State) -> + ok. + +%%==================================================================== +%% Internal functions +%%==================================================================== diff --git a/src/_config.erl b/webmachine/config.erl similarity index 59% rename from src/_config.erl rename to webmachine/config.erl index e4475f2..7e24f2d 100644 --- a/src/_config.erl +++ b/webmachine/config.erl @@ -1,23 +1,24 @@ -module({{name}}_config). -export([ - dispatch/0, - web_config/0 -]). + dispatch/0, + web_config/0 + ]). -spec dispatch() -> [webmachine_dispatcher:route()]. dispatch() -> lists:flatten([ - {[], {{name}}_resource, []} - ]). + {[], {{name}}_resource, []} + ]). web_config() -> {ok, App} = application:get_application(?MODULE), {ok, Ip} = application:get_env(App, web_ip), {ok, Port} = application:get_env(App, web_port), [ - {ip, Ip}, - {port, Port}, - {log_dir, "priv/log"}, - {dispatch, dispatch()} + {ip, Ip}, + {port, Port}, + {log_dir, "priv/log"}, + {dispatch, dispatch()} ]. + diff --git a/dot.gitignore b/webmachine/gitignore similarity index 100% rename from dot.gitignore rename to webmachine/gitignore diff --git a/webmachine/otp_app.app.src b/webmachine/otp_app.app.src new file mode 100644 index 0000000..31542d0 --- /dev/null +++ b/webmachine/otp_app.app.src @@ -0,0 +1,23 @@ +{application, '{{name}}', + [{description, "{{desc}}"}, + {vsn, "0.1.0"}, + {registered, []}, + {mod, {'{{name}}_app', []}}, + {applications, + [kernel, + stdlib, + inets, + crypto, + mochiweb, + webmachine + ]}, + {env,[ + {web_ip, "0.0.0.0"}, + {web_port, 8080} + ]}, + {modules, []}, + + {contributors, []}, + {licenses, []}, + {links, []} + ]}. diff --git a/webmachine/relx_rebar.config b/webmachine/relx_rebar.config new file mode 100644 index 0000000..e095958 --- /dev/null +++ b/webmachine/relx_rebar.config @@ -0,0 +1,23 @@ +{erl_opts, [debug_info]}. + +{deps, [ + {webmachine, "1.10.*", {git, "git://github.com/webmachine/webmachine", {branch, "develop"}}} + ]}. + +{relx, [{release, {'{{name}}', "0.1.0"}, + ['{{name}}', + sasl]}, + + {sys_config, "./config/sys.config"}, + {vm_args, "./config/vm.args"}, + + {dev_mode, true}, + {include_erts, false}, + + {extended_start_script, true}] +}. + +{profiles, [{prod, [{relx, [{dev_mode, false}, + {include_erts, true}]}] + }] +}. diff --git a/src/_resource.erl b/webmachine/resource.erl similarity index 87% rename from src/_resource.erl rename to webmachine/resource.erl index a5cc066..eefffe2 100644 --- a/src/_resource.erl +++ b/webmachine/resource.erl @@ -1,8 +1,8 @@ -module({{name}}_resource). -export([ - init/1, - to_html/2 -]). + init/1, + to_html/2 + ]). -include_lib("webmachine/include/webmachine.hrl"). @@ -13,3 +13,4 @@ init([]) -> -spec to_html(wrq:reqdata(), term()) -> {iodata(), wrq:reqdata(), term()}. to_html(ReqData, State) -> {"Hello, new world", ReqData, State}. + diff --git a/webmachine/sup.erl b/webmachine/sup.erl new file mode 100644 index 0000000..4245303 --- /dev/null +++ b/webmachine/sup.erl @@ -0,0 +1,39 @@ +%%%------------------------------------------------------------------- +%% @doc {{name}} top level supervisor. +%% @end +%%%------------------------------------------------------------------- + +-module('{{name}}_sup'). + +-behaviour(supervisor). + +%% API +-export([start_link/0]). + +%% Supervisor callbacks +-export([init/1]). + +-define(SERVER, ?MODULE). + +%%==================================================================== +%% API functions +%%==================================================================== + +start_link() -> + supervisor:start_link({local, ?SERVER}, ?MODULE, []). + +%%==================================================================== +%% Supervisor callbacks +%%==================================================================== + +%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules} +init([]) -> + Web = {webmachine_mochiweb, + {webmachine_mochiweb, start, [{{name}}_config:web_config()]}, + permanent, 5000, worker, [mochiweb_socket_server]}, + Processes = [Web], + {ok, { {one_for_one, 10, 10}, Processes} }. + +%%==================================================================== +%% Internal functions +%%==================================================================== diff --git a/webmachine/sys.config b/webmachine/sys.config new file mode 100644 index 0000000..7fd6bcb --- /dev/null +++ b/webmachine/sys.config @@ -0,0 +1,3 @@ +[ + {'{{name}}', []} +]. diff --git a/src/_.erl b/webmachine/top.erl similarity index 99% rename from src/_.erl rename to webmachine/top.erl index 22124de..01566c0 100644 --- a/src/_.erl +++ b/webmachine/top.erl @@ -39,3 +39,4 @@ resolve_deps(App) -> is_otp_base_app(kernel) -> true; is_otp_base_app(stdlib) -> true; is_otp_base_app(_) -> false. + diff --git a/webmachine/vm.args b/webmachine/vm.args new file mode 100644 index 0000000..dd3ad4c --- /dev/null +++ b/webmachine/vm.args @@ -0,0 +1,6 @@ +-name {{name}}@127.0.0.1 + +-setcookie {{name}}_cookie + ++K true ++A30