export const COMMON_PLATFORM_MAPPINGS = { // Windows Platforms windows: 'win32', win: 'win32', win32: 'win32', win64: 'win32', // Node.js returns 'win32' for both 32-bit and 64-bit Windows mingw: 'win32', // Minimalist GNU for Windows // macOS Platforms macos: 'darwin', mac: 'darwin', osx: 'darwin', darwin: 'darwin', // This is the actual Node.js return value for macOS // Linux Platforms linux: 'linux', ubuntu: 'linux', debian: 'linux', centos: 'linux', fedora: 'linux', redhat: 'linux', rhel: 'linux', alpine: 'linux', // Alpine is a lightweight Linux distribution arch: 'linux', gentoo: 'linux', // Other Unix-like Platforms freebsd: 'freebsd', openbsd: 'openbsd', netbsd: 'netbsd', solaris: 'sunos', sunos: 'sunos', // SunOS, also referred to as Solaris // Android android: 'android', // Other platforms (less common) aix: 'aix', // IBM AIX platform cygwin: 'cygwin', // POSIX compatibility layer for Windows haiku: 'haiku', // Haiku OS } export const COMMON_ARCH_MAPPINGS = { // Common Architectures amd64: 'x64', // 64-bit architecture, commonly referred to as x64 x64: 'x64', // Node.js returns 'x64' for 64-bit systems x86_64: 'x64', // Another way to refer to 64-bit architecture ia32: 'x86', // 32-bit architecture, commonly referred to as x86 x86: 'x86', // Node.js returns 'ia32' for 32-bit systems // ARM Architectures arm: 'arm', // ARM 32-bit armv7: 'arm', // ARM 32-bit, version 7 arm64: 'arm64', // ARM 64-bit aarch64: 'arm64', // Another way to refer to ARM 64-bit // PowerPC Architectures ppc: 'ppc', // PowerPC 32-bit ppc64: 'ppc64', // PowerPC 64-bit powerpc: 'ppc', // Common alias for PowerPC // MIPS Architectures mips: 'mips', // MIPS architecture mips64: 'mips64', // 64-bit MIPS // RISC-V Architectures riscv: 'riscv', // RISC-V 32-bit riscv64: 'riscv64', // RISC-V 64-bit // Other Architectures s390x: 's390x', // IBM Z and LinuxONE mainframes (64-bit) s390: 's390', // IBM Z and LinuxONE mainframes (31-bit) // Aliases for Legacy or Less Common Architectures i386: 'x86', // 32-bit architecture, equivalent to 'ia32' or 'x86' i686: 'x86', // Another 32-bit alias, often used in Linux distros // Catch-all for unrecognized architectures unknown: 'unknown', } export function inferPlatformAndArch(fileName: string): { platform: string arch: string } { // Initialize with default values let inferredPlatform = 'unknown' let inferredArch = 'unknown' // Split the filename into tokens based on common delimiters const tokens = fileName .toLowerCase() .split(/[\._\-]/) .sort((a, b) => b.length - a.length) // Attempt to match platform and arch using the mappings for (const token of tokens) { if (COMMON_PLATFORM_MAPPINGS[token] && inferredPlatform === 'unknown') { inferredPlatform = COMMON_PLATFORM_MAPPINGS[token] } if (COMMON_ARCH_MAPPINGS[token] && inferredArch === 'unknown') { inferredArch = COMMON_ARCH_MAPPINGS[token] } } // console.log({ fileName, inferredPlatform, inferredArch }) return { platform: inferredPlatform, arch: inferredArch, } } export const app = { name: `Undefined App`, slug: `undefined`, binaryName: `undefined`, repo: `undefined`, homepage: `undefined`, inferPlatformAndArch, } export type App = typeof app