From 9c1f5c271c5658731145b5a4d5ce29d51637888e Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sat, 20 Jul 2024 20:30:43 -0400 Subject: [PATCH] refactor(update): split up script --- apps/update/package.json | 2 +- apps/update/src/app.ts | 26 ++++++++++++++++++++++++ apps/update/{app.ts => src/firefox.ts} | 28 +------------------------- 3 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 apps/update/src/app.ts rename apps/update/{app.ts => src/firefox.ts} (73%) diff --git a/apps/update/package.json b/apps/update/package.json index 4c7d26b4..d803e6be 100644 --- a/apps/update/package.json +++ b/apps/update/package.json @@ -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", diff --git a/apps/update/src/app.ts b/apps/update/src/app.ts new file mode 100644 index 00000000..090df6ae --- /dev/null +++ b/apps/update/src/app.ts @@ -0,0 +1,26 @@ +import { updateFirefoxAddons } from '././firefox.ts'; + +/* Parse Args */ +const args = {} as Record; +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()); +} diff --git a/apps/update/app.ts b/apps/update/src/firefox.ts similarity index 73% rename from apps/update/app.ts rename to apps/update/src/firefox.ts index 8386bdf3..2e1a8231 100644 --- a/apps/update/app.ts +++ b/apps/update/src/firefox.ts @@ -4,28 +4,8 @@ import { readFileSync } from 'node:fs'; /* Constants */ const FLAKE = process.env.FLAKE; -/* Parse Args */ -const args = {} as Record; -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()); -}