MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / readOrCreateFile

Function readOrCreateFile

src/back/ConfigFile.ts:19–35  ·  view source on GitHub ↗
(filePath: string, onError?: (error: string) => void)

Source from the content-addressed store, hash-verified

17 }
18
19 export async function readOrCreateFile(filePath: string, onError?: (error: string) => void): Promise<AppConfigData> {
20 let error: Error | undefined;
21 let data: AppConfigData | undefined;
22
23 try {
24 data = await readFile(filePath, onError);
25 } catch (e: any) {
26 error = e;
27 }
28
29 if (error || !data) {
30 data = deepCopy(getDefaultConfigData(process.platform));
31 saveFile(filePath, data).catch(() => console.log('Failed to save default config file!'));
32 }
33
34 return data;
35 }
36
37 export function readOrCreateFileSync(filePath: string, onError?: (error: string) => void): AppConfigData {
38 let error: Error | undefined;

Callers

nothing calls this directly

Calls 4

deepCopyFunction · 0.90
getDefaultConfigDataFunction · 0.90
readFileFunction · 0.70
saveFileFunction · 0.70

Tested by

no test coverage detected