feat(update): migrate ffz script to typescript
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
9c1f5c271c
commit
970a380805
3 changed files with 47 additions and 19 deletions
|
@ -1,26 +1,9 @@
|
||||||
|
import { parseArgs } from './lib.ts';
|
||||||
import { updateFirefoxAddons } from '././firefox.ts';
|
import { updateFirefoxAddons } from '././firefox.ts';
|
||||||
|
|
||||||
/* Parse Args */
|
|
||||||
const args = {} as Record<string, unknown>;
|
|
||||||
let lastFlag: string | null = null;
|
|
||||||
|
|
||||||
for (let i = 2; i < process.argv.length; ++i) {
|
const args = parseArgs();
|
||||||
const arg = process.argv[i];
|
|
||||||
|
|
||||||
if (arg.toString().startsWith('-')) {
|
|
||||||
lastFlag = arg.toString().replace(/^-{1,2}/, '');
|
|
||||||
args[lastFlag] = true;
|
|
||||||
}
|
|
||||||
else if (lastFlag) {
|
|
||||||
args[lastFlag] = arg;
|
|
||||||
lastFlag = null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.error(`Could not parse args: ${arg.toString()}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Exec functions based on args */
|
|
||||||
if (args['f'] || args['firefox']) {
|
if (args['f'] || args['firefox']) {
|
||||||
console.log(updateFirefoxAddons());
|
console.log(updateFirefoxAddons());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,26 @@
|
||||||
import { spawnSync } from 'node:child_process';
|
import { spawnSync } from 'node:child_process';
|
||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
|
|
||||||
|
import { parseFetchurl } from './lib.ts';
|
||||||
|
|
||||||
/* Constants */
|
/* Constants */
|
||||||
const FLAKE = process.env.FLAKE;
|
const FLAKE = process.env.FLAKE;
|
||||||
|
|
||||||
|
|
||||||
|
const updateFFZ = () => {
|
||||||
|
const FILE = `${FLAKE}/pkgs/firefox-addons/default.nix`;
|
||||||
|
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 });
|
||||||
|
};
|
||||||
|
|
||||||
export const updateFirefoxAddons = () => {
|
export const updateFirefoxAddons = () => {
|
||||||
|
console.log('Updating FFZ addon');
|
||||||
|
updateFFZ();
|
||||||
|
|
||||||
console.log('Updating firefox addons using mozilla-addons-to-nix');
|
console.log('Updating firefox addons using mozilla-addons-to-nix');
|
||||||
|
|
||||||
const DIR = `${FLAKE}/pkgs/firefox-addons`;
|
const DIR = `${FLAKE}/pkgs/firefox-addons`;
|
||||||
|
|
30
apps/update/src/lib.ts
Normal file
30
apps/update/src/lib.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { spawnSync } from 'node:child_process';
|
||||||
|
|
||||||
|
|
||||||
|
export const parseArgs = () => {
|
||||||
|
const args = {} as Record<string, unknown>;
|
||||||
|
let lastFlag: string | null = null;
|
||||||
|
|
||||||
|
for (let i = 2; i < process.argv.length; ++i) {
|
||||||
|
const arg = process.argv[i];
|
||||||
|
|
||||||
|
if (arg.toString().startsWith('-')) {
|
||||||
|
lastFlag = arg.toString().replace(/^-{1,2}/, '');
|
||||||
|
args[lastFlag] = true;
|
||||||
|
}
|
||||||
|
else if (lastFlag) {
|
||||||
|
args[lastFlag] = arg;
|
||||||
|
lastFlag = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(`Could not parse args: ${arg.toString()}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const parseFetchurl = (url: string) => JSON.parse(spawnSync(
|
||||||
|
'nix', ['store', 'prefetch-file', '--refresh', '--json',
|
||||||
|
'--hash-type', 'sha256', url, '--name', '"escaped"'], { shell: true },
|
||||||
|
).stdout.toString()).hash;
|
Loading…
Reference in a new issue