Add force option to download command

This commit is contained in:
trickypr 2022-11-15 12:40:51 +11:00
parent e79d4b099c
commit 77a63264b7
4 changed files with 24 additions and 12 deletions

View file

@ -1,6 +1,8 @@
import execa from 'execa'
import { existsSync, rmSync, writeFileSync } from 'node:fs'
import { readdir } from 'node:fs/promises'
import { dirname, resolve } from 'node:path'
import { bin_name } from '../..'
import { BASH_PATH, ENGINE_DIR, MELON_TMP_DIR } from '../../constants'
import { log } from '../../log'
@ -19,7 +21,6 @@ import {
unpackAddon,
} from './addon'
import { configPath } from '../../utils'
import { readdir } from 'node:fs/promises'
export function shouldSetupFirefoxSource() {
return !(
@ -111,7 +112,7 @@ async function downloadFirefoxSource(version: string) {
return filename
}
export async function downloadInternals(version: string) {
export async function downloadInternals({ version, force }: { version: string, force?: boolean }) {
// Provide a legible error if there is no version specified
if (!version) {
log.error(
@ -120,6 +121,11 @@ export async function downloadInternals(version: string) {
process.exit(1)
}
if (force && existsSync(ENGINE_DIR)) {
log.info('Removing existing workspace')
rmSync(ENGINE_DIR, { recursive: true })
}
// If the engine directory is empty, we should delete it.
const engineIsEmpty = await readdir(ENGINE_DIR).then((files) => files.length === 0)
if (existsSync(ENGINE_DIR) && engineIsEmpty) {