CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/servers/hub/write-text-file-to-project.ts
Views: 687
1
import ensureContainingDirectoryExists from "@cocalc/backend/misc/ensure-containing-directory-exists";
2
import * as message from "@cocalc/util/message";
3
import { writeFile } from "fs/promises";
4
5
export default async function writeTextFileToProject(
6
socket,
7
mesg
8
): Promise<void> {
9
const { content, path } = mesg;
10
try {
11
await ensureContainingDirectoryExists(path);
12
await writeFile(path, content);
13
socket.write_mesg("json", message.file_written_to_project({ id: mesg.id }));
14
} catch (err) {
15
socket.write_mesg(
16
"json",
17
message.error({ id: mesg.id, error: err.message })
18
);
19
}
20
}
21
22