返回 oh-my-ppt
style-switch-job-files.ts
根目录 / src / main / edit-jobs / style-switch-job-files.ts
1 import fs from 'fs'
2 import type { StyleSwitchFileSnapshot } from './style-switch-job-types'
3
4 export const readStyleSwitchFileSnapshot = async (
5 filePath: string
6 ): Promise<StyleSwitchFileSnapshot> => {
7 if (!fs.existsSync(filePath)) return { exists: false, content: '' }
8 return { exists: true, content: await fs.promises.readFile(filePath, 'utf-8') }
9 }
10
11 export const restoreStyleSwitchFileSnapshot = async (
12 filePath: string,
13 snapshot: StyleSwitchFileSnapshot
14 ): Promise<void> => {
15 if (snapshot.exists) {
16 await fs.promises.writeFile(filePath, snapshot.content, 'utf-8')
17 return
18 }
19 await fs.promises.rm(filePath, { force: true })
20 }
21
21 lines TYPESCRIPT