Skip to main content

Lua API Reference

Archetype scripts are plain Lua. Archetect runs your script top-to-bottom — there is no framework lifecycle and no callbacks to register. You create a Context, prompt for values, render templates, and optionally compose other archetypes. When the script ends (or calls exit()), the render is complete.

Two kinds of API surface exist:

  • Globals — available in every script with no require().
  • archetect.* modules — loaded explicitly with require(), because they perform side effects beyond the render destination (subprocesses, network, archives) or pull in optional machinery (AML models).

Globals

GlobalPurposeReference
ContextSmart map of template variables + all prompt methodsContext
archetectBinary/process introspection: version, offline/headless flags, archetect.env platform infoGlobals
archetypeThe currently-rendering archetype: manifest metadata, destination, archetype.switches, answers(), library helpersGlobals
Case, CasesCase-expansion styles, presets, and direct string transformsGlobals
ExistingPolicy enum for files that already exist at the destinationGlobals
LocationPath-resolution scope enum for file.* operationsGlobals
directoryRender a whole template directoryRendering
fileSingle-file exists / read / render helpersRendering
templateInline template renderingRendering
catalogCompose other archetypes declared in this archetype's catalog: mapcatalog
formatJSON / YAML / TOML serialization and parsingformat, log & output
logStructured logging (info, debug, warn, error, trace)format, log & output
outputUser-facing output (print, banner)format, log & output
exitCleanly terminate the script earlyGlobals
requireLoad archetect.* modules or your own lib/ modulesbelow
note

There are no top-level switches or env globals. Switches live at archetype.switches, platform info at archetect.env.

require() modules

ModulePurposeReference
archetect.shellRun subprocesses (gated by the shell-execution security policy)shell, git, github & archive
archetect.gitInitialize repositories and drive git operationsshell, git, github & archive
archetect.githubCheck for / create GitHub repositoriesshell, git, github & archive
archetect.archiveProduce zip / tar / tar.gz archives from rendered outputshell, git, github & archive
archetect.modelLoad, parse, or build AML domain modelsmodel (AML)
archetect.model.interactivePrompt-driven interactive AML model buildermodel (AML)

require() also resolves Lua modules from the archetype itself: helpers in the archetype's lib/ directory are requirable by name (require("helpers")), and archetypes mounted as libraries expose their lib/ under the catalog mount key (require("my-lib.casing")). See Libraries.

A minimal script

local context = Context.new()

context:prompt_text("Project Name:", "project-name", {
cases = Cases.programming(),
})

directory.render("contents/base", context)

Everything above — Context, Cases, directory — is a global. No require() is needed until you reach for the archetect.* modules.