Skip to content

UpdateFile

A component for updating existing files or initializing new files.

This component allows you to read the current contents of a file and generate new content based on those contents. If the file doesn’t exist, it can use default content from either a file path or inline content.

Props for the UpdateFile component.

import { UpdateFile } from "@alloy-js/core";
<UpdateFile
defaultContent={Children}
defaultContentPath="string"
path="string"
>
{children}
</UpdateFile>
children(currentContents: string | null) => Children

Function that receives the current file contents and returns the new content

defaultContentoptionalChildren

Optional default content to use when the target file doesn’t exist

defaultContentPathoptionalstring

Optional path to a file containing default content to use when the target file doesn’t exist

pathstring

The relative path to the file to update or create

<UpdateFile path="config.json" defaultContent="{}">
{(currentContents) => {
const config = currentContents ? JSON.parse(currentContents) : {};
config.newProperty = "value";
return JSON.stringify(config, null, 2);
}}
</UpdateFile>