Skip to content

Commit

Permalink
feat: refactor platform target
Browse files Browse the repository at this point in the history
  • Loading branch information
KagamiChan committed Oct 2, 2024
1 parent 56912b6 commit 2ef5d71
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 195 deletions.
50 changes: 13 additions & 37 deletions src/app/[locale]/download/[[...options]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import get from 'lodash/get'
import Link from 'next/link'
import { useMemo } from 'react'

import { Button } from '~/components/ui/button'
import { initTranslations } from '~/i18n'
Expand All @@ -10,7 +9,9 @@ import {
platformToTarget,
type DistributionType,
type LinuxPackageFormat,
PlatformSpec,
} from '~/lib/target'
import { cn } from '~/lib/utils'

export const runtime = 'edge'

Expand All @@ -19,28 +20,18 @@ export default async function DownloadPage({
}: {
params: {
locale: string
options?: [OS?, CPU?, (DistributionType | LinuxPackageFormat)?]
options?: [OS?, PlatformSpec?]
}
}) {
const { t } = await initTranslations(locale, ['common'])
const [os, cpu, pacakgeFormatOrDistributionType] = options
console.log(os, cpu, pacakgeFormatOrDistributionType)
const [os, spec] = options
console.log(os, spec)

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const possibleOptions = get(platformToTarget, [os!, cpu!], {})

console.log(
possibleOptions,
Object.keys(possibleOptions as object).length,
typeof possibleOptions,
pacakgeFormatOrDistributionType,
)

const shouldShowOptions =
os === undefined || (cpu === undefined && os !== OS.macos)
return (
<div>
<h2>{t('Operating system')}</h2>
<h2>
<Link href="/download">{t('Operating system')}</Link>
</h2>
{os === undefined && (
<div>
{Object.keys(platformToTarget).map((system) => (
Expand All @@ -50,31 +41,16 @@ export default async function DownloadPage({
))}
</div>
)}
<h2>{t('Platform')}</h2>
<h2>
<Link href={`/download/${os}`}>{t('Platform')}</Link>
</h2>
{os !== undefined &&
cpu === undefined &&
spec === undefined &&
Object.keys(platformToTarget[os] ?? {}).map((platform) => (
<Button key={platform} asChild>
<Link href={`./${platform}`}>{t(platform as CPU)}</Link>
<Link href={`./${platform}`}>{t(platform as PlatformSpec)}</Link>
</Button>
))}

{shouldShowOptions && (
<>
<h2>{t('Options')}</h2>
{pacakgeFormatOrDistributionType === undefined && (
<div>
{Object.keys(possibleOptions as object).map((option) => (
<Button key={option} asChild>
<Link href={`./${option}`}>
{t(option as DistributionType | LinuxPackageFormat)}
</Link>
</Button>
))}
</div>
)}
</>
)}
</div>
)
}
44 changes: 24 additions & 20 deletions src/lib/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,36 @@ export enum DistributionType {
portable = 'portable',
}

export enum PlatformSpec {
X64Setup = 'x64Setup', // setup for windows x64 and macOS Intel
X64Portable = 'x64Portable', // portable for windows x64 and Linux x64
IA32Setup = 'ia32Setup', // setup for windows x86
IA32Portable = 'ia32Portable', // portable for windows x86
ARM = 'arm', // setup for windows ARM and macOS Apple silicon
X64DEB = 'x64DEB', // deb package for linux x64
x64RPM = 'x64RPM', // rpm package for linux x64
ARMDEB = 'armDEB', // deb package for linux ARM
ARMPortable = 'armPortable', // currently for linux only, windows ARM is always setup
}

export const platformToTarget = {
[OS.windows]: {
[CPU.x64]: {
[DistributionType.setup]: Target.win64Setup,
[DistributionType.portable]: Target.win64,
},
[CPU.ia32]: {
[DistributionType.setup]: Target.win32Setup,
[DistributionType.portable]: Target.win32,
},
[CPU.arm]: Target.winArm,
[PlatformSpec.X64Setup]: Target.win64Setup,
[PlatformSpec.X64Portable]: Target.win64,
[PlatformSpec.IA32Setup]: Target.win32Setup,
[PlatformSpec.IA32Portable]: Target.win32,
[PlatformSpec.ARM]: Target.winArm,
},
[OS.macos]: {
[CPU.x64]: Target.macos,
[CPU.arm]: Target.macosArm,
[PlatformSpec.X64Setup]: Target.macos,
[PlatformSpec.ARM]: Target.macosArm,
},
[OS.linux]: {
[CPU.x64]: {
[LinuxPackageFormat.deb]: Target.linuxDeb,
[LinuxPackageFormat.rpm]: Target.linuxRpm,
[DistributionType.portable]: Target.linux,
},
[CPU.arm]: {
[LinuxPackageFormat.deb]: Target.linuxDebArm,
[DistributionType.portable]: Target.linuxArm,
},
[PlatformSpec.X64DEB]: Target.linuxDeb,
[PlatformSpec.x64RPM]: Target.linuxRpm,
[PlatformSpec.X64Portable]: Target.linux,
[PlatformSpec.ARMDEB]: Target.linuxDebArm,
[PlatformSpec.ARMPortable]: Target.linuxArm,
},
}

Expand Down
24 changes: 1 addition & 23 deletions src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
"opencollective": "OpenCollective",
"weibo": "Weibo",
"download": "Download {{version}}",
"linux-x64": "Linux (x64)",
"linux-arm": "Linux (ARM)",
"linux-deb-x64": "Debian / Ubuntu (x64)",
"linux-deb-arm": "Debian / Ubuntu (ARM)",
"linux-rpm-x64": "Fedora / CentOS (x64)",
"macos-x64": "macOS (x64)",
"macos-arm": "macOS (ARM)",
"win-ia32": "Windows (x86) Portable",
"win-ia32-setup": "Windows (x86)",
"win-x64": "Windows (x64) Portable",
"win-x64-setup": "Windows (x64)",
"win-arm": "Windows (ARM)",
"stable-hint": "Stable, for most users",
"beta-hint": "Beta, for new features",
"other-versions": "Check the complete list",
Expand Down Expand Up @@ -50,15 +38,5 @@
"Download options": "Download options",
"Operating system": "Operating system",
"Platform": "Platform",
"Options": "Options",
"windows": "Windows",
"linux": "Linux",
"macos": "macOS",
"x64": "64 bit",
"ia32": "32 bit",
"arm": "ARM",
"deb": "DEB",
"rpm": "RPM",
"setup": "Setup",
"portable": "Portable"
"Options": "Options"
}
24 changes: 1 addition & 23 deletions src/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
"opencollective": "OpenCollective",
"weibo": "Weibo",
"download": "Téléchargez {{version}}",
"linux-x64": "Linux (x64)",
"linux-arm": "Linux (ARM)",
"linux-deb-x64": "Debian / Ubuntu (x64)",
"linux-deb-arm": "Debian / Ubuntu (ARM)",
"linux-rpm-x64": "Fedora / CentOS (x64)",
"macos-x64": "macOS (x64)",
"macos-arm": "macOS (ARM)",
"win-ia32": "Windows (x86) Portable",
"win-ia32-setup": "Windows (x86)",
"win-x64": "Windows (x64) Portable",
"win-x64-setup": "Windows (x64)",
"win-arm": "Windows (ARM)",
"stable-hint": "Stable, pour la plupart des utilisateurs",
"beta-hint": "Beta, pour les nouvelles fonctionalités",
"telegram-group-link": "https://t.me/joinchat/ENYTx0Cr6B9OxSCRKUzYUw",
Expand Down Expand Up @@ -50,15 +38,5 @@
"Download options": "Options de téléchargement",
"Operating system": "Système opérateur",
"Platform": "Plate-forme",
"Options": "Possibilités",
"linux": "Linux",
"macos": "macOS",
"windows": "Windows",
"arm": "ARM",
"ia32": "32 bits",
"x64": "64 bits",
"deb": "DEB",
"portable": "Portable",
"rpm": "RPM",
"setup": "Installation"
"Options": "Possibilités"
}
24 changes: 1 addition & 23 deletions src/locales/ja/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
"opencollective": "OpenCollective",
"weibo": "Weibo",
"download": "{{version}} をダウンロードする",
"linux-x64": "64 ビット Linux バージョン",
"linux-arm": "ARM Linux バージョン",
"linux-deb-x64": "64 ビット Debian / Ubuntu バージョン",
"linux-deb-arm": "ARM Debian / Ubuntu バージョン",
"linux-rpm-x64": "64 ビット Fedora / CentOS バージョン",
"macos-x64": "64 ビット macOS バージョン",
"macos-arm": "ARM macOS バージョン",
"win-ia32": "32 ビット Windows バージョン",
"win-ia32-setup": "32 ビット Windows インストーラ",
"win-x64": "64 ビット Windows バージョン",
"win-x64-setup": "64 ビット Windows インストーラ",
"win-arm": "ARM Windows バージョン",
"stable-hint": "安定版・一般利用の方におすすめ",
"beta-hint": "開発版・新機能が欲しい方におすすめ",
"other-versions": "完全なリストを見る",
Expand Down Expand Up @@ -50,15 +38,5 @@
"Download options": "ダウンロードオプション",
"Operating system": "オペレーティング·システム",
"Platform": "プラットフォーム",
"Options": "オプション",
"linux": "Linux",
"macos": "macOS",
"windows": "Windows",
"arm": "ARM",
"ia32": "32ビット",
"x64": "64ビット",
"deb": "DEB",
"portable": "ポータブル",
"rpm": "RPM",
"setup": "インストーラ"
"Options": "オプション"
}
24 changes: 1 addition & 23 deletions src/locales/ko/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
"opencollective": "OpenCollective",
"weibo": "Weibo",
"download": "{{version}} 다운로드하기",
"linux-x64": "64비트 리눅스용",
"linux-arm": "ARM 리눅스용",
"linux-deb-x64": "64비트 데비안/우분투용",
"linux-deb-arm": "ARM 데비안/우분투용",
"linux-rpm-x64": "64비트 페도라/CentOS용",
"macos-x64": "64비트 macOS용",
"macos-arm": "ARM macOS용",
"win-ia32": "32비트 윈도우용 포터블 버전",
"win-ia32-setup": "32비트 윈도우용",
"win-x64": "64비트 윈도우용 포터블 버전",
"win-x64-setup": "64비트 윈도우용",
"win-arm": "ARM 윈도우용 포터블 버전",
"stable-hint": "일반 사용자용 안정 버전",
"beta-hint": "새로운 기능 맛보기용 베타 버전",
"other-versions": "모든 버전 목록 보기",
Expand Down Expand Up @@ -50,15 +38,5 @@
"Download options": "다운로드 옵션",
"Operating system": "운영 체제",
"Platform": "플랫폼",
"Options": "옵션",
"linux": "Linux",
"macos": "macOS",
"windows": "Windows",
"arm": "ARM",
"ia32": "32비트",
"x64": "64비트",
"deb": "DEB",
"portable": "가지고 다닐 수 있는",
"rpm": "RPM",
"setup": "윈도우용"
"Options": "옵션"
}
24 changes: 1 addition & 23 deletions src/locales/zh-Hans/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
"opencollective": "OpenCollective ",
"weibo": "新浪微博",
"download": "下载 {{version}}",
"linux-x64": "64 位 Linux 版",
"linux-arm": "ARM Linux 版",
"linux-deb-x64": "64 位 Debian / Ubuntu 版",
"linux-deb-arm": "ARM Debian / Ubuntu 版",
"linux-rpm-x64": "64 位 Fedora / CentOS 版",
"macos-x64": "64 位 macOS 版",
"macos-arm": "ARM macOS 版",
"win-ia32": "32 位 Windows 版",
"win-ia32-setup": "32 位 Windows 安装包",
"win-x64": "64 位 Windows 版",
"win-x64-setup": "64 位 Windows 安装包",
"win-arm": "ARM Windows 版",
"stable-hint": "正式版,适合大部分人使用",
"beta-hint": "测试版,包含最新的功能",
"other-versions": "浏览完整列表",
Expand Down Expand Up @@ -50,15 +38,5 @@
"Download options": "下载其它平台版本",
"Operating system": "操作系统",
"Platform": "平台",
"Options": "选项",
"linux": "Linux",
"macos": "macOS",
"windows": "Windows",
"arm": "ARM",
"ia32": "32位",
"x64": "64位",
"deb": "DEB",
"portable": "便携版",
"rpm": "RPM",
"setup": "安装包"
"Options": "选项"
}
24 changes: 1 addition & 23 deletions src/locales/zh-Hant/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
"opencollective": "OpenCollective",
"weibo": "新浪微博",
"download": "下載 {{version}}",
"linux-x64": "64 位 Linux 版",
"linux-arm": "ARM Linux 版",
"linux-deb-x64": "64 位 Debian / Ubuntu 版",
"linux-deb-arm": "ARM Debian / Ubuntu 版",
"linux-rpm-x64": "64 位 Fedora / CentOS 版",
"macos-x64": "64 位 macOS 版",
"macos-arm": "ARM macOS 版",
"win-ia32": "32 位 Windows 版",
"win-ia32-setup": "32 位 Windows 安裝包",
"win-x64": "64 位 Windows 版",
"win-x64-setup": "64 位 Windows 安裝包",
"win-arm": "ARM Windows 版",
"stable-hint": "正式版,適合大部分人使用",
"beta-hint": "測試版,包含最新的功能",
"other-versions": "瀏覽完整列表",
Expand Down Expand Up @@ -50,15 +38,5 @@
"Download options": "下載其它平臺版本",
"Operating system": "作業系統",
"Platform": "平台",
"Options": "選項",
"linux": "Linux",
"macos": "macOS",
"windows": "Windows",
"arm": "ARM",
"ia32": "32位",
"x64": "64位",
"deb": "DEB",
"portable": "便攜版",
"rpm": "RPM",
"setup": "安裝包"
"Options": "選項"
}

0 comments on commit 2ef5d71

Please sign in to comment.