-
Notifications
You must be signed in to change notification settings - Fork 10
/
version.ts
42 lines (36 loc) · 1.42 KB
/
version.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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 axios from 'axios'
import { log } from '../log'
import { SupportedProducts } from './config'
import { config } from '..'
import { dynamicConfig } from '.'
const firefoxTargets = JSON.parse(`{
"${SupportedProducts.Firefox}": "LATEST_FIREFOX_VERSION",
"${SupportedProducts.FirefoxBeta}": "LATEST_FIREFOX_DEVEL_VERSION",
"${SupportedProducts.FirefoxDevelopment}": "FIREFOX_DEVEDITION",
"${SupportedProducts.FirefoxESR}": "FIREFOX_ESR",
"${SupportedProducts.FirefoxNightly}": "FIREFOX_NIGHTLY"
}`)
export const shouldUseCandidate = (): boolean => {
const brandingKey = dynamicConfig.get('brand')
return brandingKey !== 'stable' && (config.version.version !== config.version.candidate);
}
export const getFFVersionOrCandidate = () => {
return shouldUseCandidate() ? config.version.candidate : config.version.version
}
export const getLatestFF = async (
product: SupportedProducts = SupportedProducts.Firefox
): Promise<string> => {
try {
const { data } = await axios.get(
'https://product-details.mozilla.org/1.0/firefox_versions.json'
)
return data[firefoxTargets[product]]
} catch (error) {
log.warning('Failed to get latest firefox version with error:')
log.error(error)
return ''
}
}