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) => Children Function that receives the current file contents and returns the new content |
defaultContent | optionalChildren Optional default content to use when the target file doesn’t exist |
defaultContentPath | optionalstring Optional path to a file containing default content to use when the target file doesn’t exist |
path | string The 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>