1import { mkdir, writeFile } from "node:fs/promises";
2import { dirname, join } from "node:path";
3
4export interface WorkspaceContent {
5 filePath: string;
6 content: string;
7 bytes: number;
8}
9
10export async function writeWorkspaceFile(
11 workspacePath: string,
12 relativePath: string,
13 content: string,
14): Promise<WorkspaceContent> {
15 const filePath = join(workspacePath, relativePath);
16 await mkdir(dirname(filePath), { recursive: true });
17 await writeFile(filePath, content, "utf8");
18
19 return {
20 filePath,
21 content,
22 bytes: Buffer.byteLength(content, "utf8"),
23 };
24}