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",
"type": "module",
"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": {
"@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 */
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) {
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 = () => {
export const updateFirefoxAddons = () => {
console.log('Updating firefox addons using mozilla-addons-to-nix');
const DIR = `${FLAKE}/pkgs/firefox-addons`;
@ -78,9 +58,3 @@ const updateFirefoxAddons = () => {
.map((pname) => `${pname}: ${OLD_VERS[pname]} -> ${NEW_VERS[pname]}`)
.join('\n');
};
/* Exec functions based on args */
if (args['f'] || args['firefox']) {
console.log(updateFirefoxAddons());
}