Skip to content

Instantly share code, notes, and snippets.

@pascalchevrel
Last active December 6, 2024 14:02
Show Gist options
  • Select an option

  • Save pascalchevrel/bc96b848b723d6f9901670c006a02a3e to your computer and use it in GitHub Desktop.

Select an option

Save pascalchevrel/bc96b848b723d6f9901670c006a02a3e to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
/*
PHP script to fetch Firefox Desktop and Android shipped versions from API
and output readable results to your terminal.
chmod +x this file and set it as a bash alias:
alias v="path/to/firefox_versions.php"
The output will look like this:
DESKTOP
ESR 115 115.18.0esr
ESR 128 128.5.1esr
Release 133.0
Beta 134.0b5
DevEdition 134.0b5
Nightly 135.0a1
ANDROID
Release 133.0.1
Beta 134.0b4
Nightly 135.0a1
*/
function getData(string $file): array {
return json_decode(file_get_contents('https://product-details.mozilla.org/1.0/' . $file), true);
}
function output(string $header, ?string $data = null):void {
$boldgreen = "\e[1;32m";
$cyan = "\e[96m";
$endcolor = "\e[0m";
if(! $data) {
echo $boldgreen . $header . $endcolor . PHP_EOL;
} else {
$header = ' ' . $header . '';
$header = str_pad($header, 12, ' ');
echo $cyan . $header . $endcolor . $data . PHP_EOL;
}
}
$desktop = getData('firefox_versions.json');
$android = getData('mobile_versions.json');
output('DESKTOP');
output('ESR 115', $desktop['FIREFOX_ESR115']);
output('ESR 128', $desktop['FIREFOX_ESR']);
output('Release', $desktop['LATEST_FIREFOX_VERSION']);
output('Beta', $desktop['LATEST_FIREFOX_RELEASED_DEVEL_VERSION']);
output('DevEdition', $desktop['FIREFOX_DEVEDITION']);
output('Nightly', $desktop['FIREFOX_NIGHTLY']);
output('ANDROID');
output('Release', $android['version']);
output('Beta', $android['beta_version']);
output('Nightly', $android['nightly_version']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment