(filePath: string, onError?: (error: string) => void)
| 45 | } |
| 46 | |
| 47 | export function readOrCreateFileSync(filePath: string, onError?: (error: string) => void): Playlist { |
| 48 | let error: Error | undefined; |
| 49 | let data: Playlist | undefined; |
| 50 | |
| 51 | try { |
| 52 | data = readFileSync(filePath, onError); |
| 53 | } catch (e: any) { |
| 54 | error = e; |
| 55 | } |
| 56 | |
| 57 | if (error || !data) { |
| 58 | data = deepCopy(DEFAULT_PLAYLIST_DATA); |
| 59 | saveFile(filePath, data).catch(() => console.log('Failed to save default config file!')); |
| 60 | } |
| 61 | |
| 62 | return data; |
| 63 | } |
| 64 | |
| 65 | export function saveFile(filePath: string, data: Playlist): Promise<void> { |
| 66 | const playlistToSave = { |
nothing calls this directly
no test coverage detected