Erlang

The Erlang stack can seem quite involved, in the context of the demo_ps project, we’ve got

rebar.config / rebar.lock

This file contains the Erlang dependencies that need downloading and building as well as information about assets that need deploying along with any release (using rebar3 release)

In the case of demo_ps, those dependencies are fairly minimal

1
2
3
4
5
6
7
8
{deps,[
       {jsx, "2.8.0"},
       {recon, "2.3.6"},
       {eredis, {git, "https://github.com/wooga/eredis.git", {tag, "v1.2.0"}}},
       {erlydtl, {git, "https://github.com/erlydtl/erlydtl", {tag, "0.12.1"}}},
       {cowboy, { git, "https://github.com/ninenines/cowboy.git", { tag, "2.6.0" }}},
       {gproc, {git, "https://github.com/uwiger/gproc.git", {tag, "0.8.0"}}},
       {erlang_ls, { git, "https://github.com/erlang-ls/erlang_ls.git", {tag, "0.4.1"}}}
  • JSX is required because of the Purerl simple-json dependency
  • Cowboy is required because of the Purerl Stetson dependency

These are not added automatically but are merely documented as dependencies in those project README.mds. This is something to be aware of when bringing down Purerl dependencies.

The other dependencies are there to support code that we write in Purerl ourselves (covered later in this guide).

We’ll ignore the release process for now, but we’ll note that at the end of thise file we’re specifying the Makefiles that need executing to build the server and client apps in Purescript.

1
2
3
4
5
]}.
{pre_hooks,
  [
   {"(linux|darwin|solaris|win32)", compile, "bash -c 'make'"},
   {"(linux|darwin|solaris|win32)", clean, "make clean"}

src/demo_ps.app.src

This file is present to tell the runtime about the application, the most important aspect of this being the name of the module that needs executing.

1
  {mod, { bookApp@ps, []}},

This file also tells the runtime which applications need starting before this one, and that means most of the dependencies in rebar.config are duplicated in here. Welcome to Erlang.

1
2
3
4
5
6
7
8
9
  {applications,
   [kernel,
    stdlib,
    gproc,
    recon,
    sasl,
    cowboy,
    jsx,
    eredis

src/*

Any erlang found in this src folder will be compiled when running rebar3, this gives us the ability to write native Erlang that exists independently of the Purerl application.

src/compiled_ps

This is where the output of the Purerl code gets copied to, and because it happens to be beneath the src directory it then gets compiled to beam.

release-files/sys.config

This is a convention, but configuration is usually placed in this file.

priv/*

A special folder containing assets that’ll be deployed with a release. Amongst other things, this is where we’d usually find the static portions of the website that a web application consists of (a index.html, some css, etc). We’ll copy the bundled JS generated by the Purescript on the client side into here as well.