MCPcopy Create free account
hub / github.com/code100x/mobile-magic / ensureFileExists

Function ensureFileExists

ext/src/extension.ts:17–43  ·  view source on GitHub ↗
(filePath: string, content: string = '')

Source from the content-addressed store, hash-verified

15}
16
17async function ensureFileExists(filePath: string, content: string = '') {
18 try {
19 const uri = vscode.Uri.file(filePath);
20
21 // Check if the directory exists, create if not
22 const dirPath = path.dirname(filePath);
23 try {
24 await vscode.workspace.fs.stat(vscode.Uri.file(dirPath));
25 } catch {
26 // Directory doesn't exist, create it
27 await vscode.workspace.fs.createDirectory(vscode.Uri.file(dirPath));
28 }
29
30 // Check if file exists
31 try {
32 await vscode.workspace.fs.stat(uri);
33 } catch {
34 // File doesn't exist, create it
35 await vscode.workspace.fs.writeFile(uri, Buffer.from(content, 'utf8'));
36 }
37
38 return uri;
39 } catch (error) {
40 vscode.window.showErrorMessage(`Error ensuring file exists: ${error}`);
41 throw error;
42 }
43 }
44
45
46function initWs(context: vscode.ExtensionContext) {

Callers 1

initWsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected