rad/util

A motley assortment of utility functions.

Constants

pub const lookups: List(
  #(List(String), List(#(String, List(String)))),
) = [
  #(
    ["color", "background"],
    [
      #("boi-blue", ["166", "240", "252"]),
      #("buttercup", ["255", "215", "175"]),
      #("hot-pink", ["217", "0", "184"]),
      #("mint", ["182", "255", "234"]),
      #("peach", ["255", "175", "194"]),
      #("pink", ["255", "175", "243"]),
      #("purple", ["217", "181", "255"]),
    ],
  ),
]

Custom color Lookups for rad.

pub const rad_path: String = "./build/dev/javascript/rad"

The base path for rad’s compiled JavaScript modules.

Functions

pub fn ebin_paths() -> Result(List(String), Nil)

Results in a list of paths comprising all compiled Erlang modules for a project and its dependencies on success, or Nil on failure.

pub fn encode_json(data: a) -> String

Returns a JSON string representation for any given data.

pub fn erlang_run(
  with args: List(String),
  opt options: List(CommandOpt),
) -> Result(String, Snag)

Runs Erlang with the given arguments and shellout CommandOpts. All dependency and project modules are preloaded and accessible.

pub fn file_exists(path: String) -> Bool

Returns a boolean indicating whether or not a file exists at the given path.

pub fn file_write(
  contents contents: String,
  to path: String,
) -> Result(String, Snag)

Tries to write some contents to a file at the given path.

Results in an empty string on success, or a Snag on failure.

pub fn is_directory(path: String) -> Bool

Returns a boolean indicating whether or not a directory exists at the given path.

pub fn javascript_run(
  deno deno_args: List(String),
  or nodejs_args: List(String),
  opt options: List(CommandOpt),
) -> Result(String, Snag)

Runs Deno or Node.js (depending on the JavaScript runtime specified in your project’s gleam.toml config) with the given arguments and shellout CommandOpts. All dependency and project modules are preloaded and accessible.

pub fn javascript_runtime() -> String

Returns a JavaScript runtime command name based on your project’s gleam.toml config.

Can be "node" or "deno"; "node" is the default.

pub fn make_directory(path: String) -> Result(String, Snag)

Tries to create a new directory at the given path.

No attempt is made to create any missing parent directories.

Results in an empty string on success, or a Snag on failure.

pub fn quiet_or_print(input: CommandInput) -> fn(String) -> Nil

Removes from the given input a flag specific to running rad’s unit tests.

Returns a function that does nothing if rad’s test flag is present in the given input, otherwise io.print.

Useful for suppressing output while running rad’s unit tests.

pub fn quiet_or_println(input: CommandInput) -> fn(String) -> Nil

Returns a function that does nothing if rad’s test flag is present in the given input, otherwise io.println.

Useful for suppressing output while running rad’s unit tests.

pub fn quiet_or_spawn(input: CommandInput) -> List(CommandOpt)

Instructs a shellout.command to capture all output if rad’s test flag is present in the given input, otherwise spawns the subprocess with stdout and stderr piped to its parent.

Useful for suppressing output while running rad’s unit tests.

pub fn recursive_delete(path: String) -> Result(String, Snag)

Tries to recursively delete the given path.

If the path is a directory, it will be deleted along with all of its contents.

Results in an empty string on success, or a Snag on failure.

pub fn refuse_erlang() -> Result(String, Snag)

Results in an error meant to notify users that a Task cannot be carried out using the Erlang runtime.

pub fn relay_flags(flags: Dict(String, Flag)) -> List(String)

Reconstructs a list of strings from a processed flag Map.

Useful for relaying the processed flags from a CommandInput to a new process.

pub fn rename(
  from source: String,
  to dest: String,
) -> Result(String, Snag)

Tries to move a given source path to a new location.

Results in an empty string on success, or a Snag on failure.

pub fn snag_pretty_print(snag: Snag) -> String

Turns a Snag into a multiline string optimized for readability.

pub fn which_rad() -> String

Returns the path of a runnable rad invocation script.

pub fn working_directory() -> Result(String, Snag)

Results in the current working directory path on success, or a Snag on failure.

Search Document