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>import { UpdateFile } from "@alloy-js/core/stc";
UpdateFile({ defaultContent: Children, defaultContentPath: string, path: string,}).children(children)| children | (currentContents: string | null) => ChildrenFunction that receives the current file contents and returns the new content |
| defaultContent | optionalChildrenOptional default content to use when the target file doesn’t exist |
| defaultContentPath | optionalstringOptional path to a file containing default content to use when the target file doesn’t exist |
| path | stringThe relative path to the file to update or create |
Example
Section titled “Example”<UpdateFile path="config.json" defaultContent="{}"> {(currentContents) => { const config = currentContents ? JSON.parse(currentContents) : {}; config.newProperty = "value"; return JSON.stringify(config, null, 2); }}</UpdateFile>