refactor(update): split up script
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-07-20 20:30:43 -04:00
parent 96067d726b
commit 9c1f5c271c
3 changed files with 28 additions and 28 deletions

View file

@ -4,7 +4,7 @@
"bin": "out/bin/app.cjs", "bin": "out/bin/app.cjs",
"type": "module", "type": "module",
"scripts": { "scripts": {
"build": "node_ver=$(node -v); esbuild app.ts --bundle --platform=node --target=\"node${node_ver:1:2}\" --outfile=out/bin/app.cjs" "build": "node_ver=$(node -v); esbuild src/app.ts --bundle --platform=node --target=\"node${node_ver:1:2}\" --outfile=out/bin/app.cjs"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "9.7.0", "@eslint/js": "9.7.0",

26
apps/update/src/app.ts Normal file
View file

@ -0,0 +1,26 @@
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 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']) {
console.log(updateFirefoxAddons());
}

View file

@ -4,28 +4,8 @@ import { readFileSync } from 'node:fs';
/* Constants */ /* Constants */
const FLAKE = process.env.FLAKE; const FLAKE = process.env.FLAKE;
/* Parse Args */
const args = {} as Record<string, unknown>;
let lastFlag: string | null = null;
for (let i = 2; i < process.argv.length; ++i) { export const updateFirefoxAddons = () => {
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()}`);
}
}
/* Functions */
const updateFirefoxAddons = () => {
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`;
@ -78,9 +58,3 @@ const updateFirefoxAddons = () => {
.map((pname) => `${pname}: ${OLD_VERS[pname]} -> ${NEW_VERS[pname]}`) .map((pname) => `${pname}: ${OLD_VERS[pname]} -> ${NEW_VERS[pname]}`)
.join('\n'); .join('\n');
}; };
/* Exec functions based on args */
if (args['f'] || args['firefox']) {
console.log(updateFirefoxAddons());
}