2024-07-20 19:56:59 -04:00
|
|
|
import { spawnSync } from 'node:child_process';
|
|
|
|
import { readFileSync } from 'node:fs';
|
|
|
|
|
2024-07-20 21:06:52 -04:00
|
|
|
import { parseFetchurl } from './lib.ts';
|
|
|
|
|
2024-07-20 19:56:59 -04:00
|
|
|
/* Constants */
|
|
|
|
const FLAKE = process.env.FLAKE;
|
|
|
|
|
|
|
|
|
2024-07-20 21:06:52 -04:00
|
|
|
const updateFFZ = () => {
|
2024-07-22 20:16:03 -04:00
|
|
|
const FILE = `${FLAKE}/legacyPackages/firefox-addons/default.nix`;
|
2024-07-20 21:06:52 -04:00
|
|
|
const URL = 'https://cdn.frankerfacez.com/script/frankerfacez-4.0-an+fx.xpi';
|
|
|
|
|
|
|
|
const HASH = parseFetchurl(URL);
|
|
|
|
|
|
|
|
spawnSync('sed', ['-i', `'s,url = .*,url = \"${URL}\";,'`, FILE], { shell: true });
|
|
|
|
spawnSync('sed', ['-i', `'s,sha256 = .*,sha256 = \"${HASH}\";,'`, FILE], { shell: true });
|
|
|
|
};
|
|
|
|
|
2024-07-20 20:30:43 -04:00
|
|
|
export const updateFirefoxAddons = () => {
|
2024-07-20 21:06:52 -04:00
|
|
|
console.log('Updating FFZ addon');
|
|
|
|
updateFFZ();
|
|
|
|
|
2024-07-20 19:56:59 -04:00
|
|
|
console.log('Updating firefox addons using mozilla-addons-to-nix');
|
|
|
|
|
2024-07-22 20:16:03 -04:00
|
|
|
const DIR = `${FLAKE}/legacyPackages/firefox-addons`;
|
2024-07-20 19:56:59 -04:00
|
|
|
const GENERATED_FILE = `${DIR}/generated-firefox-addons.nix`;
|
|
|
|
const SLUGS = `${DIR}/addons.json`;
|
|
|
|
|
|
|
|
const nameMap = Object.fromEntries([...JSON.parse(readFileSync(SLUGS, 'utf-8'))]
|
|
|
|
.map((addon) => [addon.slug, addon.pname || addon.slug]));
|
|
|
|
|
|
|
|
const nixExpr = `'
|
|
|
|
x: let
|
|
|
|
inherit (builtins) attrValues filter hasAttr isAttrs map;
|
|
|
|
in
|
|
|
|
map (d: d.name) (filter (y:
|
|
|
|
isAttrs y &&
|
|
|
|
hasAttr "type" y &&
|
|
|
|
y.type == "derivation") (attrValues x))
|
|
|
|
'`;
|
|
|
|
|
|
|
|
const OLD_VERS = Object.fromEntries([...JSON.parse(spawnSync('nix', [
|
|
|
|
'eval',
|
|
|
|
'.#legacyPackages.x86_64-linux.firefoxAddons',
|
|
|
|
'--apply',
|
|
|
|
nixExpr,
|
|
|
|
'--json',
|
|
|
|
], { shell: true }).stdout.toString())]
|
|
|
|
.map((p) => {
|
|
|
|
const pname = p.replace(/-[0-9].*$/, '');
|
|
|
|
|
|
|
|
return [pname, p.replace(`${pname}-`, '')];
|
|
|
|
})
|
|
|
|
.filter((pinfo) => pinfo[0] !== 'frankerfacez'));
|
|
|
|
|
|
|
|
const NEW_VERS = Object.fromEntries(spawnSync(
|
|
|
|
'mozilla-addons-to-nix',
|
|
|
|
[SLUGS, GENERATED_FILE],
|
|
|
|
{ shell: true },
|
|
|
|
).stdout
|
|
|
|
.toString()
|
|
|
|
.split('\n')
|
|
|
|
.map((p) => {
|
|
|
|
const pinfo = p.replace('Fetched ', '').split(' ');
|
|
|
|
|
|
|
|
return [nameMap[pinfo[0]], pinfo[2]];
|
|
|
|
}));
|
|
|
|
|
|
|
|
return Object.keys(OLD_VERS)
|
|
|
|
.sort()
|
|
|
|
.filter((pname) => OLD_VERS[pname] !== NEW_VERS[pname])
|
|
|
|
.map((pname) => `${pname}: ${OLD_VERS[pname]} -> ${NEW_VERS[pname]}`)
|
|
|
|
.join('\n');
|
|
|
|
};
|