Tinfoil.ProjectEditor (tinfoil v0.2.22)

Copy Markdown View Source

Splice tinfoil + Burrito wiring into a mix.exs that was produced by mix new. The edits are intentionally string-based (not AST rewrites) so user formatting, comments, and layout are preserved.

The module exports one splicer per concern:

Every splicer is idempotent: if the target is already present, the source is returned unchanged with an :already_present status.

If a splicer can't find its anchor -- typically because the user customized the file beyond the mix new shape -- the caller gets {:error, reason} and should print a snippet for manual paste rather than guessing.

Summary

Functions

Add mod: {<app_module>.Application, []} to the application/0 keyword list, right after the extra_applications: [...] line.

Insert {:burrito, "~> 1.0"} into deps/0.

Back-compat alias for insert_tinfoil_dep/2. Kept because earlier callers used the shorter name.

Append a defp releases do ... end function with a Burrito :targets block for the given tinfoil targets. The function is inserted at the bottom of the module, right before the final end. The release name matches the app atom so Tinfoil.Burrito picks it by name.

Insert releases: releases() into project/0 right after the deps: deps() line.

Insert a minimal :tinfoil config block into project/0, right after the deps: deps() line.

Insert {:tinfoil, "~> <version>", runtime: false} as the first element of deps/0.

Types

status()

@type status() :: :inserted | :already_present

Functions

insert_application_mod(source, app_module)

@spec insert_application_mod(String.t(), String.t()) ::
  {:ok, String.t(), status()} | {:error, :application_anchor_not_found}

Add mod: {<app_module>.Application, []} to the application/0 keyword list, right after the extra_applications: [...] line.

insert_burrito_dep(source)

@spec insert_burrito_dep(String.t()) ::
  {:ok, String.t(), status()} | {:error, :deps_anchor_not_found}

Insert {:burrito, "~> 1.0"} into deps/0.

insert_dep(source, tinfoil_version)

@spec insert_dep(String.t(), String.t()) ::
  {:ok, String.t(), status()} | {:error, :deps_anchor_not_found}

Back-compat alias for insert_tinfoil_dep/2. Kept because earlier callers used the shorter name.

insert_releases_block(source, app, targets)

@spec insert_releases_block(String.t(), atom(), [atom()]) ::
  {:ok, String.t(), status()} | {:error, :module_end_not_found}

Append a defp releases do ... end function with a Burrito :targets block for the given tinfoil targets. The function is inserted at the bottom of the module, right before the final end. The release name matches the app atom so Tinfoil.Burrito picks it by name.

insert_releases_entry(source)

@spec insert_releases_entry(String.t()) ::
  {:ok, String.t(), status()} | {:error, :project_anchor_not_found}

Insert releases: releases() into project/0 right after the deps: deps() line.

insert_tinfoil_config(source, targets)

@spec insert_tinfoil_config(String.t(), [atom()]) ::
  {:ok, String.t(), status()} | {:error, :project_anchor_not_found}

Insert a minimal :tinfoil config block into project/0, right after the deps: deps() line.

insert_tinfoil_dep(source, tinfoil_version)

@spec insert_tinfoil_dep(String.t(), String.t()) ::
  {:ok, String.t(), status()} | {:error, :deps_anchor_not_found}

Insert {:tinfoil, "~> <version>", runtime: false} as the first element of deps/0.