This is an example Gleam project to help demonstrate how to use Glerd, a library that can generate metadata for Records in Gleam.
- Clone this repository:
git clone https://github.com/jasonprogrammer/glerd_example.git
- Change into the
glerd_example
directory:
cd glerd_example
- Install glerd as a development dependency:
gleam add --dev glerd
- Run Glerd:
gleam run -m glerd
- After running this, you'll notice that Glerd has created a
src/glerd_gen.gleam
file locally. The file looks like this:
// this file was generated via "gleam run -m glerd"
import glerd/types
pub const record_info = [
#(
"User",
"user",
[
#("id", types.IsInt), #("name", types.IsString),
#("email", types.IsString),
],
"",
),
]
This file was created as a result of Glerd scanning the src
directory,
finding the user.gleam
file:
pub type User {
User(id: Int, name: String, email: String)
}
and generating the glerd_gen.gleam
metadata file.
There are multiple ways of doing this. Here's one possibility. We could:
-
Clone the Glerd repository and build a single binary of Glerd using Gleescript.
-
Add this
glerd
binary to the project repo so that we can run it each time we build the Gleam project (e.g. before runninggleam run
).
Creating a single binary helps us avoid adding all of Glerd's dependencies to our project, and helps us avoid rebuilding Glerd each time we want to invoke it.
- Use a shell script or task runner
(e.g. task) to run Glerd and
gleam run
sequentially.