View Source Igniter.Project.Config (igniter v0.4.0)

Codemods and utilities for modifying Elixir config files.

Summary

Functions

Sets a config value in the given configuration file, updating it with updater if it is already set.

Sets a config value in the given configuration file, if it is not already set.

Returns true if the given configuration path is set somewhere after the provided zipper, or in the given configuration file.

If the last argument is key, checks if either config :root_key, :key, ... or config :root_key, key: ... is set.

Same as configures_root_key?/3 but accepts a Zipper instead.

Checks if either config :root_key, _ or config :root_key, _, _ is present in the provided config file.

Modifies elixir configuration code starting at the configured zipper.

Functions

Link to this function

configure(igniter, file_name, app_name, config_path, value, opts \\ [])

View Source
@spec configure(
  Igniter.t(),
  Path.t(),
  atom(),
  [atom()],
  term(),
  opts :: Keyword.t()
) :: Igniter.t()

Sets a config value in the given configuration file, updating it with updater if it is already set.

If the value is source code, pass {:code, value}, otherwise pass just the value.

To produce this source code, we suggest using Sourceror.parse_string!. For example:

|> Igniter.Project.Config.configure(
  "fake.exs",
  :tailwind,
  [:default, :args],
  {:code,
   Sourceror.parse_string!("""
   ~w(--config=tailwind.config.js --input=css/app.css --output=../output/assets/app.css)
   """)}
)

Opts

  • :updater - A function that takes a zipper at a currently configured value and returns a new zipper with the value updated.
  • failure_message - A message to display to the user if the configuration change is unsuccessful.
Link to this function

configure_new(igniter, file_path, app_name, config_path, value, opts \\ [])

View Source
@spec configure_new(
  Igniter.t(),
  Path.t(),
  atom(),
  [atom()],
  term(),
  opts :: Keyword.t()
) :: Igniter.t()

Sets a config value in the given configuration file, if it is not already set.

See configure/6 for more.

Opts

  • failure_message - A message to display to the user if the configuration change is unsuccessful.
Link to this function

configure_runtime_env(igniter, env, app_name, config_path, value, opts \\ [])

View Source
@spec configure_runtime_env(
  Igniter.t(),
  atom(),
  atom(),
  [atom()],
  term(),
  opts :: Keyword.t()
) :: Igniter.t()
Link to this function

configures?(zipper, path, app_name)

View Source
This function is deprecated. Use configures_root_key?/2 or configures_key?/3 instead..
@spec configures?(Sourceror.Zipper.t(), [atom()], atom()) :: boolean()
Link to this function

configures?(igniter, config_file_name, path, app_name)

View Source
This function is deprecated. Use configures_root_key?/3 or configures_key?/4 instead..
@spec configures?(Igniter.t(), String.t(), [atom()], atom()) :: boolean()

Returns true if the given configuration path is set somewhere after the provided zipper, or in the given configuration file.

Link to this function

configures_key?(zipper, root_key, key_or_path)

View Source
@spec configures_key?(Sourceror.Zipper.t(), atom(), atom() | [atom()]) :: boolean()

Same as configures_key?/4 but accepts a Zipper.

Link to this function

configures_key?(igniter, config_file_name, root_key, key_or_path)

View Source
@spec configures_key?(
  Igniter.t(),
  String.t(),
  atom(),
  atom() | [atom()]
) :: boolean()

If the last argument is key, checks if either config :root_key, :key, ... or config :root_key, key: ... is set.

If the last argument is a keyword path, checks if config :root_key, path_head, [...] defines path_rest or if config :root_key, [...] defines path, where path_head is the first element of path and path_rest are the remaining elements.

Note: config_file_name should not include the config/ prefix.

Link to this function

configures_root_key?(zipper, root_key)

View Source
@spec configures_root_key?(Sourceror.Zipper.t(), atom()) :: boolean()

Same as configures_root_key?/3 but accepts a Zipper instead.

Link to this function

configures_root_key?(igniter, config_file_name, root_key)

View Source
@spec configures_root_key?(Igniter.t(), String.t(), atom()) :: boolean()

Checks if either config :root_key, _ or config :root_key, _, _ is present in the provided config file.

Note: The config file name should not include the config/ prefix.

Link to this function

modify_configuration_code(zipper, config_path, app_name, value, updater \\ nil)

View Source
@spec modify_configuration_code(
  Sourceror.Zipper.t(),
  [atom()],
  atom(),
  term(),
  (Sourceror.Zipper.t() -> {:ok, Sourceror.Zipper.t()} | :error) | nil
) :: Sourceror.Zipper.t()

Modifies elixir configuration code starting at the configured zipper.

If you want to set configuration, use configure/6 or configure_new/5 instead. This is a lower-level tool for modifying configuration files when you need to adjust some specific part of them.