mirror of
https://github.com/zen-browser/surfer.git
synced 2025-07-08 09:20:01 +02:00
✨ Add force option to download command
This commit is contained in:
parent
e79d4b099c
commit
77a63264b7
4 changed files with 24 additions and 12 deletions
|
@ -64,8 +64,14 @@ export const commands: Cmd[] = [
|
|||
requestController: async () => (await import('./commands/discard')).discard,
|
||||
},
|
||||
{
|
||||
cmd: 'download [ffVersion]',
|
||||
cmd: 'download',
|
||||
description: 'Download Firefox.',
|
||||
options: [
|
||||
{
|
||||
arg: '--force',
|
||||
description: 'Delete the engine directory if it already exists',
|
||||
}
|
||||
],
|
||||
requestController: async () =>
|
||||
(await import('./commands/download')).download,
|
||||
},
|
||||
|
|
|
@ -4,12 +4,15 @@
|
|||
|
||||
import { bin_name, config } from '..'
|
||||
import { log } from '../log'
|
||||
|
||||
import {
|
||||
downloadInternals
|
||||
} from './download/firefox'
|
||||
|
||||
export const download = async (): Promise<void> => {
|
||||
type Options = {
|
||||
force?: boolean
|
||||
}
|
||||
|
||||
export const download = async (options: Options): Promise<void> => {
|
||||
const version = config.version.version
|
||||
|
||||
// If gFFVersion isn't specified, provide legible error
|
||||
|
@ -20,7 +23,7 @@ export const download = async (): Promise<void> => {
|
|||
process.exit(1)
|
||||
}
|
||||
|
||||
await downloadInternals(version)
|
||||
await downloadInternals({version, force: options.force})
|
||||
|
||||
log.success(
|
||||
`You should be ready to make changes to ${config.name}.`,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// 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 { existsSync, rmSync } from 'node:fs'
|
||||
|
||||
import { bin_name, config } from '..'
|
||||
import { log } from '../log'
|
||||
|
@ -9,15 +8,13 @@ import {
|
|||
downloadInternals
|
||||
} from './download/firefox'
|
||||
import { getLatestFF } from '../utils'
|
||||
import { ENGINE_DIR } from '../constants'
|
||||
|
||||
export const update = async (): Promise<void> => {
|
||||
const version = await getLatestFF(config.version.product)
|
||||
|
||||
// Delete the existing engine directory to download the new version
|
||||
if (existsSync(ENGINE_DIR)) rmSync(ENGINE_DIR, { recursive: true })
|
||||
|
||||
await downloadInternals(version)
|
||||
// We are using force here to delete the engine directory if it already
|
||||
// exists to make way for the new version.
|
||||
await downloadInternals({version, force: true})
|
||||
|
||||
log.success(
|
||||
`Firefox has successfully been updated to ${version}.`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue