Skip to main content

File

Creates and manages files in the filesystem with automatic directory creation and proper cleanup on deletion.

Properties

string
required
Path to the file (relative or absolute).
string
required
Content to write to the file.

Returns

string
Path to the created file.
string
Content of the file.

Examples

Create a simple text file

Create a file in a nested directory

Update file content and path


Folder

Creates and manages directories in the filesystem with automatic parent directory creation and cleanup on deletion.

Properties

string
Path to the folder. If not provided, uses the resource ID.
boolean
Whether to delete the folder during the delete phase.Default: true
boolean
Whether to clean the folder during deletion (even if it contains existing files).Default: false
boolean
Whether to create the folder recursively (including parent directories).Default: true

Returns

string
Path to the created folder.

Examples

Create a directory using id as path

Create a directory with explicit path

Create a nested directory structure

Persist folder on deletion


CopyFile

Copies a file from a source location to a destination location.

Properties

string
required
Source path of the file to copy.
string
required
Destination path where the file should be copied to.
boolean
Whether to overwrite the destination file if it already exists.Default: true

Returns

string
Source path of the file.
string
Destination path of the file.
boolean
Whether the file was successfully copied.
number
Timestamp when the copy operation completed.

Examples

Copy a file to a new location

Copy without overwriting


File References

Alchemy provides utilities for working with file references and collections, useful for documentation generation and template processing.

alchemy.file()

Creates a reference to a file in the filesystem. Used in template string interpolation to include file contents.

Example: Include in documentation generation

alchemy.files()

Creates a collection of files with their contents. Used in template string interpolation to include multiple file contents.

Variadic syntax

Example: Bulk documentation generation

alchemy.folder()

Gets all files in a directory and returns them as a FileCollection.

Example: Process all documentation files


Type Guards

isFileRef()

Type guard to check if a value is a FileRef.

isFileCollection()

Type guard to check if a value is a FileCollection.