MCPcopy Index your code
hub / github.com/coder/coder / createFile

Function createFile

site/src/utils/filetree.ts:10–25  ·  view source on GitHub ↗
(
	path: string,
	fileTree: FileTree,
	value: string,
)

Source from the content-addressed store, hash-verified

8};
9
10export const createFile = (
11 path: string,
12 fileTree: FileTree,
13 value: string,
14): FileTree => {
15 if (existsFile(path, fileTree)) {
16 throw new Error(`File ${path} already exists`);
17 }
18 const pathError = validatePath(path, fileTree);
19 if (pathError) {
20 throw new Error(pathError);
21 }
22
23 const updatedFileTree = structuredClone(fileTree);
24 return set(updatedFileTree, path.split("/"), value);
25};
26
27export const validatePath = (
28 path: string,

Callers 3

filetree.test.tsFile · 0.90
TemplateVersionEditorFunction · 0.90
moveFileFunction · 0.70

Calls 3

existsFileFunction · 0.85
validatePathFunction · 0.85
setFunction · 0.85

Tested by

no test coverage detected