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) => ChildrenFunction that receives the current file contents and returns the new content
defaultContentoptional ChildrenOptional default content to use when the target file doesn’t exist
defaultContentPathoptional stringOptional path to a file containing default content to use when the target file doesn’t exist
pathstringThe 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>