Class
MTLFileSystemStrategy
File system-based generation strategy that writes to disk.
actor MTLFileSystemStrategy
Overview
This strategy writes generated text directly to the file system, creating directories as needed and handling file modes (overwrite, append, create).
Overview
Features:
-
Automatic directory creation: Creates parent directories if they don’t exist
-
File mode handling: Supports overwrite, append, and create modes
-
Base path resolution: Resolves relative paths against a configurable base path
-
Character encoding: Supports configurable character encodings
File Modes
-
.overwrite: Replace existing file or create new -
.append: Append to existing file or create new -
.create: Create new file, fail if exists
Example Usage
let strategy = MTLFileSystemStrategy(basePath: "/output")
let writer = try await strategy.createWriter(
url: "models/Person.swift",
mode: .overwrite,
charset: "UTF-8",
indentation: MTLIndentation()
)
await writer.writeLine("// Generated file")
await writer.writeLine("class Person {}")
try await strategy.finalizeWriter(writer)
// File written to /output/models/Person.swift
Topics
Initializers
Creates a new file system strategy with the specified base path.
Instance Methods
Creates a new writer for the specified target.
Finalizes and commits the writer’s content to its target.