Tinfoil.Generator (tinfoil v0.2.22)

Copy Markdown View Source

Renders tinfoil's EEx templates into the target project.

The generator is the mechanical half of mix tinfoil.init and mix tinfoil.generate: it takes a %Tinfoil.Config{} and writes (or returns) the files that make up the generated release pipeline:

  • .github/workflows/release.yml
  • scripts/install.sh (if installer enabled)
  • .tinfoil/formula.rb.eex (if homebrew enabled)

Summary

Functions

Return the CamelCase module name for an app atom (:my_cli -> "MyCli").

Return the list of generated files as {path, contents, executable?} tuples relative to the project root, without touching the filesystem.

Render the lib/<app>/application.ex boilerplate used by mix tinfoil.init --install. Not part of render/1 because this is a one-time scaffolding artifact, not something to regenerate on every mix tinfoil.generate.

Render a stub lib/<app>/cli.ex that <App>.Application.start/2 calls. Gives a fresh project something runnable before the user writes their real command tree.

Write all generated files into root (defaults to the current working directory). Returns {written, skipped} where each is a list of relative paths.

Types

generated()

@type generated() :: %{path: Path.t(), contents: String.t(), executable: boolean()}

Functions

app_module(app)

@spec app_module(atom()) :: String.t()

Return the CamelCase module name for an app atom (:my_cli -> "MyCli").

render(config)

@spec render(Tinfoil.Config.t()) :: [generated()]

Return the list of generated files as {path, contents, executable?} tuples relative to the project root, without touching the filesystem.

render_application(app)

@spec render_application(atom()) :: String.t()

Render the lib/<app>/application.ex boilerplate used by mix tinfoil.init --install. Not part of render/1 because this is a one-time scaffolding artifact, not something to regenerate on every mix tinfoil.generate.

render_cli(app)

@spec render_cli(atom()) :: String.t()

Render a stub lib/<app>/cli.ex that <App>.Application.start/2 calls. Gives a fresh project something runnable before the user writes their real command tree.

write!(config, opts \\ [])

@spec write!(
  Tinfoil.Config.t(),
  keyword()
) :: %{written: [Path.t()], skipped: [Path.t()]}

Write all generated files into root (defaults to the current working directory). Returns {written, skipped} where each is a list of relative paths.

Existing files are overwritten unless force: false is passed and the existing file differs from the generated contents (in which case it is skipped and reported).