mirror of
https://github.com/zen-browser/surfer.git
synced 2025-07-12 11:15:31 +02:00
23 lines
820 B
TypeScript
23 lines
820 B
TypeScript
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
import execa from 'execa'
|
|
import { existsSync, statSync } from 'fs'
|
|
import { resolve } from 'path'
|
|
import { log } from '../log'
|
|
import { ENGINE_DIR } from '../constants'
|
|
|
|
export const discard = async (file: string): Promise<void> => {
|
|
const realFile = resolve(ENGINE_DIR, file)
|
|
|
|
log.info(`Discarding ${file}...`)
|
|
|
|
if (!existsSync(realFile)) throw new Error(`File ${file} does not exist`)
|
|
if (!statSync(realFile).isFile()) throw new Error('Target must be a file.')
|
|
|
|
try {
|
|
await execa('git', ['restore', file], { cwd: ENGINE_DIR })
|
|
} catch (e) {
|
|
log.warning(`The file ${file} was not changed`)
|
|
}
|
|
}
|