diff --git a/apps/update-sources/src/app.ts b/apps/update-sources/src/app.ts index 63053dc5..779085f4 100644 --- a/apps/update-sources/src/app.ts +++ b/apps/update-sources/src/app.ts @@ -1,19 +1,16 @@ import { spawnSync } from 'node:child_process'; import { writeFileSync } from 'node:fs'; +import { styleText } from 'node:util'; import { parseArgs } from './lib'; -import { updateCaddyPlugins } from './caddy'; -import { updateDocker } from './docker'; -import { updateFirefoxAddons } from '././firefox'; -import { updateFlakeInputs } from './flake'; +import updateCaddyPlugins from './caddy'; +import updateDocker from './docker'; +import updateFirefoxAddons from '././firefox'; +import updateFlakeInputs from './flake'; +import runNixUpdate from './nix-update'; import updateNodeModules from './node-modules'; - -import { - runNixUpdate, - updateVuetorrent, -} from './misc'; -import { styleText } from 'node:util'; +import updateVuetorrent from './vuetorrent'; /* Constants */ diff --git a/apps/update-sources/src/caddy.ts b/apps/update-sources/src/caddy.ts index 2bf4d782..2f6f46a3 100644 --- a/apps/update-sources/src/caddy.ts +++ b/apps/update-sources/src/caddy.ts @@ -34,7 +34,7 @@ ${Object.entries(plugins) } `; -export const updateCaddyPlugins = (): string => { +export default (): string => { console.log(styleText(['magenta'], '\nUpdating caddy plugins:\n')); let updates = ''; diff --git a/apps/update-sources/src/docker.ts b/apps/update-sources/src/docker.ts index a0390892..bfe33fde 100644 --- a/apps/update-sources/src/docker.ts +++ b/apps/update-sources/src/docker.ts @@ -16,7 +16,7 @@ const updateImages = (imagePath: string): string | undefined => { } }; -export const updateDocker = () => { +export default () => { console.log(styleText(['magenta'], '\nUpdating docker images:\n')); let updates = ''; diff --git a/apps/update-sources/src/firefox.ts b/apps/update-sources/src/firefox.ts index 72b48fd2..c363120d 100644 --- a/apps/update-sources/src/firefox.ts +++ b/apps/update-sources/src/firefox.ts @@ -6,7 +6,7 @@ import { styleText } from 'node:util'; /* Constants */ const FLAKE = process.env.FLAKE; -export const updateFirefoxAddons = () => { +export default () => { console.log(styleText(['magenta'], '\nUpdating firefox addons using mozilla-addons-to-nix:\n')); const DIR = `${FLAKE}/scopedPackages/firefox-addons`; diff --git a/apps/update-sources/src/flake.ts b/apps/update-sources/src/flake.ts index 424aafef..d3f022c1 100644 --- a/apps/update-sources/src/flake.ts +++ b/apps/update-sources/src/flake.ts @@ -5,7 +5,7 @@ import { styleText } from 'node:util'; /* Constants */ const FLAKE = process.env.FLAKE; -export const updateFlakeInputs = () => { +export default () => { console.log(styleText(['magenta'], '\nUpdating flake inputs:\n')); const output = spawnSync( diff --git a/apps/update-sources/src/nix-update.ts b/apps/update-sources/src/nix-update.ts new file mode 100644 index 00000000..3b787294 --- /dev/null +++ b/apps/update-sources/src/nix-update.ts @@ -0,0 +1,39 @@ +import { spawnSync } from 'node:child_process'; +import { styleText } from 'node:util'; + + +/* Constants */ +const FLAKE = process.env.FLAKE; + +const getAttrVersion = (attr: string): string => spawnSync('nix', + ['eval', '--raw', `${FLAKE}#${attr}.version`], + { shell: true }).stdout.toString(); + +export default ( + attr: string, + scope?: string, + scopeAttr?: string, +): { + changelog: string | null + stdout: string + stderr: string +} => { + const realAttr = scope ? `${attr}.x86_64-linux.${scope}.${scopeAttr}` : attr; + const cleanAttr = scope ? `${attr}.${scope}.${scopeAttr}` : attr; + + console.log(styleText(['magenta'], `\nUpdating ${realAttr}:\n`)); + + const OLD_VERSION = getAttrVersion(realAttr); + + const execution = spawnSync('nix-update', ['--flake', realAttr, '-u'], { cwd: FLAKE }); + + const NEW_VERSION = getAttrVersion(realAttr); + + return { + changelog: OLD_VERSION !== NEW_VERSION ? + `${cleanAttr}: ${OLD_VERSION} -> ${NEW_VERSION}\n` : + null, + stdout: execution.stdout.toString(), + stderr: execution.stderr.toString(), + }; +}; diff --git a/apps/update-sources/src/node-modules.ts b/apps/update-sources/src/node-modules.ts index afeb1225..6644494a 100644 --- a/apps/update-sources/src/node-modules.ts +++ b/apps/update-sources/src/node-modules.ts @@ -1,9 +1,9 @@ import { readPackageJSON, writePackageJSON } from 'pkg-types'; import { accessSync, constants, existsSync } from 'node:fs'; import { spawnSync } from 'node:child_process'; +import { styleText } from 'node:util'; import { replaceInFile, npmRun } from './lib'; -import { styleText } from 'node:util'; /* Constants */ @@ -11,7 +11,6 @@ const FLAKE = process.env.FLAKE as string; const PINS = new Map([]); - const updatePackageJson = async(workspaceDir: string, updates: object) => { const currentPackageJson = await readPackageJSON(`${workspaceDir}/package.json`); diff --git a/apps/update-sources/src/misc.ts b/apps/update-sources/src/vuetorrent.ts similarity index 54% rename from apps/update-sources/src/misc.ts rename to apps/update-sources/src/vuetorrent.ts index acd150fc..85a5ff7f 100644 --- a/apps/update-sources/src/misc.ts +++ b/apps/update-sources/src/vuetorrent.ts @@ -1,8 +1,8 @@ import { writeFileSync } from 'node:fs'; import { spawnSync } from 'node:child_process'; +import { styleText } from 'node:util'; import { parseFetchurl } from './lib'; -import { styleText } from 'node:util'; /* Constants */ @@ -20,7 +20,7 @@ const genVueText = ( } `; -export const updateVuetorrent = () => { +export default () => { console.log(styleText(['magenta'], '\nUpdating Vuetorrent:\n')); const FILE = `${FLAKE}/configurations/nos/modules/qbittorrent/vuetorrent.nix`; @@ -42,37 +42,3 @@ export const updateVuetorrent = () => { return OLD_VERSION !== VERSION ? `Vuetorrent: ${OLD_VERSION} -> ${VERSION}` : ''; }; - - -const getAttrVersion = (attr: string): string => spawnSync('nix', - ['eval', '--raw', `${FLAKE}#${attr}.version`], - { shell: true }).stdout.toString(); - -export const runNixUpdate = ( - attr: string, - scope?: string, - scopeAttr?: string, -): { - changelog: string | null - stdout: string - stderr: string -} => { - const realAttr = scope ? `${attr}.x86_64-linux.${scope}.${scopeAttr}` : attr; - const cleanAttr = scope ? `${attr}.${scope}.${scopeAttr}` : attr; - - console.log(styleText(['magenta'], `\nUpdating ${realAttr}:\n`)); - - const OLD_VERSION = getAttrVersion(realAttr); - - const execution = spawnSync('nix-update', ['--flake', realAttr, '-u'], { cwd: FLAKE }); - - const NEW_VERSION = getAttrVersion(realAttr); - - return { - changelog: OLD_VERSION !== NEW_VERSION ? - `${cleanAttr}: ${OLD_VERSION} -> ${NEW_VERSION}\n` : - null, - stdout: execution.stdout.toString(), - stderr: execution.stderr.toString(), - }; -};