$ show BarredEwe/Prefire
Prefire is a Swift developer tool that scans SwiftUI source files, extracts `#Preview` macros and `PreviewProvider` declarations, and generates automated snapshot tests plus an interactive "Playbook" component catalog. It is not a data project: it is a CLI/code generator with a runtime library and SwiftPM/Xcode build-tool plugins. The real pipeline is: a build plugin invokes the `prefire` binary with target/source/config arguments; the binary parses sources using SwiftSyntax for `#Preview` macro ranges and a Sourcery fork for `PreviewProvider` types; a fingerprint-based cache avoids re-parsing unchanged files; Stencil templates (one for snapshot tests, one for playbook models) render generated Swift code; snapshot tests run against swift-snapshot-testing and the bundled Prefire runtime, while `PlaybookView` renders the generated `PreviewModels` inside an app.
The LLM identified 4 files worth highlighting for reuse:
Locates `#Preview` macro bodies across Swift files using a SwiftSyntax SyntaxVisitor, capturing exact source ranges so braces inside string literals or comments never break extraction. It applies `.prefireIgnored()`/`.prefireEnabled()` filtering and hands raw preview bodies to a parser. This AST-driven collection pattern is directly reusable for any Swift source-analysis or generator tool.
Visitor-based parser that turns a `#Preview` macro expansion into structured metadata: display name, traits (including variadic and function-style traits), fixedLayout CGSize expression, `@Previewable` property declarations, and parameterized argument patterns. Shows advanced SwiftSyntax manipulation such as removing attributes from declarations while preserving source text, and is a solid reference for extracting macro semantics.
Provides a load-or-generate cache keyed by SHA-256 over sorted source paths, modification dates, and template content; persists parsed Sourcery Types via NSKeyedArchiver and parsed preview models as JSON, then reuses them when all source files are older than the cache. The pattern is generic and can be extracted for any expensive parse/render pipeline that wants fast rebuilds.
Efficiently hosts SwiftUI content for macOS snapshot tests in a single reusable off-screen NSWindow with pinned backing scale (default 2) and canvas clamping to 4096pt. It solves pixel-determinism and 3D-effect stability issues that naive hosting misses, and provides a clean API for snapshot test generation across platforms. This is a strong reference for AppKit-backed snapshot infrastructure.