🐛 Don't delete the engine directory every download

The primary justification for this is adding/updating extensions.
Ideally, you should just be able to run `download` again to get
the new extensions, which the current implementation does not
allow for.
This commit is contained in:
trickypr 2022-11-14 19:12:24 +11:00
parent c5db3d7b6a
commit 97a87f5eb4
3 changed files with 18 additions and 6 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Improved error handling and logging for the download command
- `download`: The `engine/` directory will only be deleted if it is empty. Otherwise it will skip. Justification can be found in [#27](https://github.com/pulse-browser/gluon/issues/27)
## [1.0.0-rc.2]

View file

@ -19,6 +19,7 @@ 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) {
}
export async function downloadInternals(version: string) {
// If gFFVersion isn't specified, provide legible error
// Provide a legible error if there is no version specified
if (!version) {
log.error(
'You have not specified a version of firefox in your config file. This is required to build a firefox fork.'
@ -119,9 +120,15 @@ export async function downloadInternals(version: string) {
process.exit(1)
}
if (existsSync(ENGINE_DIR)) {
log.info("Deleting engine/")
rmSync(ENGINE_DIR)
// If the engine directory is empty, we should delete its contents
const engineIsEmpty = await readdir(ENGINE_DIR).then((files) => files.length === 0)
if (existsSync(ENGINE_DIR) && engineIsEmpty) {
log.info("'engine/' is empty, deleting contents...")
rmSync(ENGINE_DIR, { recursive: true })
}
if (!existsSync(ENGINE_DIR)) {
await setupFirefoxSource(version)
}

View file

@ -1,22 +1,26 @@
// 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'
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)
log.success(
`Firefox has sucessfully been updated to ${version}.`,
`Firefox has successfully been updated to ${version}.`,
`You should be ready to make changes to ${config.name}.`,
'',
`You should import the patches next, run |${bin_name} import|.`,