From e8435a49ddf347eeeb3233ac185a772d5da6585d Mon Sep 17 00:00:00 2001 From: N1C4T Date: Sun, 25 Jan 2026 21:30:07 +0400 Subject: [PATCH] refactor: extract AUR/Nix data to json --- src/components/command/CommandFooter.tsx | 1 - src/lib/aur-packages.json | 36 ++++++++++ src/lib/aur.ts | 86 +++--------------------- src/lib/nix-unfree.json | 27 ++++++++ src/lib/nixUnfree.ts | 34 +++------- 5 files changed, 82 insertions(+), 102 deletions(-) create mode 100644 src/lib/aur-packages.json create mode 100644 src/lib/nix-unfree.json diff --git a/src/components/command/CommandFooter.tsx b/src/components/command/CommandFooter.tsx index 1d7fd4b..92477c7 100644 --- a/src/components/command/CommandFooter.tsx +++ b/src/components/command/CommandFooter.tsx @@ -105,7 +105,6 @@ export function CommandFooter({ helper: selectedHelper, }); const isNix = selectedDistro === 'nix'; - const ext = isNix ? 'nix' : 'sh'; const mimeType = isNix ? 'text/plain' : 'text/x-shellscript'; const blob = new Blob([script], { type: mimeType }); const url = URL.createObjectURL(blob); diff --git a/src/lib/aur-packages.json b/src/lib/aur-packages.json new file mode 100644 index 0000000..0e371bb --- /dev/null +++ b/src/lib/aur-packages.json @@ -0,0 +1,36 @@ +{ + "packages": [ + "google-chrome", + "zen-browser-bin", + "helium-browser-bin", + "slack-desktop", + "zoom", + "vesktop-bin", + "sublime-text-4", + "vscodium-bin", + "cursor-bin", + "vagrant", + "postman-bin", + "bruno-bin", + "hoppscotch-bin", + "spotify", + "stremio", + "heroic-games-launcher-bin", + "protonup-qt-bin", + "onlyoffice-bin", + "logseq-desktop-bin", + "joplin-appimage", + "proton-vpn-gtk-app", + "mullvad-vpn-bin", + "localsend-bin", + "dropbox", + "ab-download-manager-bin", + "bitwarden", + "cura", + "orcaslicer-bin", + "davinci-resolve", + "fsearch", + "brave-bin", + "librewolf-bin" + ] +} \ No newline at end of file diff --git a/src/lib/aur.ts b/src/lib/aur.ts index e04e690..e8bf199 100644 --- a/src/lib/aur.ts +++ b/src/lib/aur.ts @@ -1,86 +1,20 @@ -/** - * AUR package detection for Arch users. - * Figures out if a package comes from AUR or official repos. - * Necessary because yay/paru handle AUR packages differently. - */ +// AUR package detection for Arch users +// Identifies packages that come from the AUR vs official repos -/** Suffixes that scream "I'm from the AUR" */ +import aurPackages from './aur-packages.json'; + +// Suffixes that scream "I'm from the AUR" export const AUR_PATTERNS = ['-bin', '-git', '-appimage']; -/** - * Known AUR packages that don't follow the suffix naming convention. - * These are packages that exist only in AUR, not in official Arch repos. - */ -export const KNOWN_AUR_PACKAGES = new Set([ - // Browsers - 'google-chrome', - 'zen-browser-bin', - 'helium-browser-bin', +// Known AUR packages without standard suffixes +// Extracted to JSON for cleaner code +export const KNOWN_AUR_PACKAGES = new Set(aurPackages.packages); - // Communication - 'slack-desktop', - 'zoom', - 'vesktop-bin', - - // Dev Editors - 'sublime-text-4', - 'vscodium-bin', - 'cursor-bin', - - // Dev Tools - 'vagrant', - 'postman-bin', - 'bruno-bin', - 'hoppscotch-bin', - - // Dev Languages - - // Media - 'spotify', - 'stremio', - - // Gaming - 'heroic-games-launcher-bin', - 'protonup-qt-bin', - - // Office - 'onlyoffice-bin', - 'logseq-desktop-bin', - 'joplin-appimage', - - // VPN - 'proton-vpn-gtk-app', - 'mullvad-vpn-bin', - - // File Sharing - 'localsend-bin', - 'dropbox', - 'ab-download-manager-bin', - - // Security - 'bitwarden', - - // Creative - 'cura', - 'orcaslicer-bin', - 'davinci-resolve', - - // System - 'fsearch', - - // Browsers (additional) - 'brave-bin', - 'librewolf-bin', -]); - -/** - * Check if a package name is an AUR package - * @param packageName - The Arch package name to check - * @returns true if the package is from AUR - */ +// Check if a package name is an AUR package export function isAurPackage(packageName: string): boolean { if (KNOWN_AUR_PACKAGES.has(packageName)) { return true; } return AUR_PATTERNS.some(pattern => packageName.endsWith(pattern)); } + diff --git a/src/lib/nix-unfree.json b/src/lib/nix-unfree.json new file mode 100644 index 0000000..6fd6e74 --- /dev/null +++ b/src/lib/nix-unfree.json @@ -0,0 +1,27 @@ +{ + "packages": [ + "discord", + "slack", + "zoom-us", + "teams", + "skypeforlinux", + "google-chrome", + "vivaldi", + "opera", + "spotify", + "steam", + "vscode", + "sublime", + "sublime4", + "jetbrains", + "nvidia-x11", + "dropbox", + "1password", + "masterpdfeditor", + "postman", + "obsidian", + "davinci-resolve", + "code-cursor", + "vagrant" + ] +} \ No newline at end of file diff --git a/src/lib/nixUnfree.ts b/src/lib/nixUnfree.ts index 0a4b999..0cd90df 100644 --- a/src/lib/nixUnfree.ts +++ b/src/lib/nixUnfree.ts @@ -1,38 +1,22 @@ // Nix unfree package detection - these require allowUnfree = true -export const KNOWN_UNFREE_PACKAGES = new Set([ - 'discord', - 'slack', - 'zoom-us', - 'teams', - 'skypeforlinux', - 'google-chrome', - 'vivaldi', - 'opera', - 'spotify', - 'steam', - 'vscode', - 'sublime', - 'sublime4', - 'jetbrains', - 'nvidia-x11', - 'dropbox', - '1password', - 'masterpdfeditor', - 'postman', - 'obsidian', - 'davinci-resolve', - 'code-cursor', - 'vagrant', -]); +import unfreeData from './nix-unfree.json'; + +// Loaded from JSON source +export const KNOWN_UNFREE_PACKAGES = new Set(unfreeData.packages); export function isUnfreePackage(pkg: string): boolean { const cleanPkg = pkg.trim().toLowerCase(); + + // Direct match if (KNOWN_UNFREE_PACKAGES.has(cleanPkg)) return true; // Nested packages like jetbrains.idea-ultimate + // We iterate because the set is small (matches original logic) for (const unfree of KNOWN_UNFREE_PACKAGES) { if (cleanPkg.includes(unfree)) return true; } + return false; } +