feat: move hardcoded values to build constants, display source repo & license + remove github org in settings
This commit is contained in:
parent
ce1847eafd
commit
5e06aa831d
14 changed files with 132 additions and 39 deletions
|
|
@ -33,6 +33,9 @@ export default async function build(dev = Dev, log = true) {
|
|||
if (log) console.info(chalk.cyanBright('\u{1F5BB} Assets generated'))
|
||||
if (log) console.info(chalk.gray('\u{1F5CE} Compiling JS...'))
|
||||
|
||||
const COMMIT = (await $`git rev-parse HEAD`.text()).trim().substring(0, 7)
|
||||
const REPO = 'revenge-mod/revenge-bundle-next'
|
||||
|
||||
const bundle = await rolldown({
|
||||
input: 'src/index.ts',
|
||||
platform: 'neutral',
|
||||
|
|
@ -48,10 +51,17 @@ export default async function build(dev = Dev, log = true) {
|
|||
'.webp': 'dataurl',
|
||||
},
|
||||
define: {
|
||||
__BUILD_VERSION__: JSON.stringify(pkg.version),
|
||||
__BUILD_COMMIT__: JSON.stringify(
|
||||
(await $`git rev-parse HEAD`.text()).trim().substring(0, 7),
|
||||
__BUILD_DISCORD_SERVER_URL__: JSON.stringify(
|
||||
'https://discord.com/invite/ddcQf3s2Uq',
|
||||
),
|
||||
__BUILD_SOURCE_REPOSITORY_URL__: JSON.stringify(
|
||||
`https://github.com/${REPO}`,
|
||||
),
|
||||
__BUILD_LICENSE_URL__: JSON.stringify(
|
||||
`https://raw.githubusercontent.com/${REPO}/${COMMIT}/LICENSE`,
|
||||
),
|
||||
__BUILD_VERSION__: JSON.stringify(pkg.version),
|
||||
__BUILD_COMMIT__: JSON.stringify(COMMIT),
|
||||
__BUILD_BRANCH__: JSON.stringify(
|
||||
(await $`git rev-parse --abbrev-ref HEAD`.text()).trim(),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
export const GitHubOrganizationURL = 'https://github.com/revenge-mod'
|
||||
export const DiscordServerURL = 'https://discord.com/invite/ddcQf3s2Uq'
|
||||
export const LicenseFallbackURL = 'https://www.gnu.org/licenses/gpl-3.0.txt'
|
||||
export const BuildEnvironment = __DEV__ ? 'development' : 'production'
|
||||
export const FullVersion = `${__BUILD_VERSION__}-${__BUILD_COMMIT__}-${__BUILD_BRANCH__}`
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ export const Setting = {
|
|||
// SUBSETTINGS
|
||||
|
||||
RevengeDiscord: 'RevengeDiscord',
|
||||
RevengeGitHub: 'RevengeGitHub',
|
||||
RevengeSourceRepository: 'RevengeSourceRepository',
|
||||
RevengeLicense: 'RevengeLicense',
|
||||
Reload: 'Reload',
|
||||
|
||||
RevengeVersion: 'RevengeVersion',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import TableRowAssetIcon from '@revenge-mod/components/TableRowAssetIcon'
|
||||
import { Linking } from 'react-native'
|
||||
import { DiscordServerURL } from '~/constants'
|
||||
import { Setting } from '../constants'
|
||||
import type { SettingsItem } from '@revenge-mod/discord/modules/settings'
|
||||
|
||||
|
|
@ -8,8 +7,9 @@ const RevengeDiscordSetting: SettingsItem = {
|
|||
parent: Setting.Revenge,
|
||||
IconComponent: () => <TableRowAssetIcon name="Discord" />,
|
||||
title: () => 'Discord Server',
|
||||
useDescription: () => __BUILD_DISCORD_SERVER_URL__,
|
||||
onPress: () => {
|
||||
Linking.openURL(DiscordServerURL)
|
||||
Linking.openURL(__BUILD_DISCORD_SERVER_URL__)
|
||||
},
|
||||
type: 'pressable',
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
import TableRowAssetIcon from '@revenge-mod/components/TableRowAssetIcon'
|
||||
import { Linking } from 'react-native'
|
||||
import { GitHubOrganizationURL } from '~/constants'
|
||||
import { Setting } from '../constants'
|
||||
import type { SettingsItem } from '@revenge-mod/discord/modules/settings'
|
||||
|
||||
const RevengeGitHubSetting: SettingsItem = {
|
||||
parent: Setting.Revenge,
|
||||
IconComponent: () => (
|
||||
<TableRowAssetIcon name="img_account_sync_github_white" />
|
||||
),
|
||||
title: () => 'GitHub',
|
||||
onPress: () => {
|
||||
Linking.openURL(GitHubOrganizationURL)
|
||||
},
|
||||
type: 'pressable',
|
||||
}
|
||||
|
||||
export default RevengeGitHubSetting
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
import TableRowAssetIcon from '@revenge-mod/components/TableRowAssetIcon'
|
||||
import { AlertActionCreators } from '@revenge-mod/discord/actions'
|
||||
import { Design } from '@revenge-mod/discord/design'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { ScrollView, useWindowDimensions } from 'react-native'
|
||||
import { LicenseFallbackURL } from '~/constants'
|
||||
import { Setting } from '../constants'
|
||||
import type { SettingsItem } from '@revenge-mod/discord/modules/settings'
|
||||
|
||||
const RevengeLicenseSetting: SettingsItem = {
|
||||
parent: Setting.Revenge,
|
||||
IconComponent: () => <TableRowAssetIcon name="FileIcon" />,
|
||||
title: () => 'License',
|
||||
onPress: () => {
|
||||
AlertActionCreators.openAlert('revenge-license', <LicenseAlert />)
|
||||
},
|
||||
type: 'pressable',
|
||||
}
|
||||
|
||||
export default RevengeLicenseSetting
|
||||
|
||||
const trimStart = (text: string) => text.replaceAll(/^ +/gm, '')
|
||||
|
||||
function LicenseAlert() {
|
||||
const { height } = useWindowDimensions()
|
||||
const [license, setLicense] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
fetch(__BUILD_LICENSE_URL__)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch license: ${response.statusText}`,
|
||||
)
|
||||
}
|
||||
return response.text()
|
||||
})
|
||||
.then(trimStart)
|
||||
.then(setLicense)
|
||||
.catch(() => {
|
||||
// Fallback to the hardcoded license URL
|
||||
fetch(LicenseFallbackURL)
|
||||
.then(response => response.text())
|
||||
.then(trimStart)
|
||||
.then(setLicense)
|
||||
.catch(error => {
|
||||
console.error(
|
||||
'Failed to fetch fallback license:',
|
||||
error,
|
||||
)
|
||||
setLicense('Failed to load license.')
|
||||
})
|
||||
})
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Design.AlertModal
|
||||
title="License"
|
||||
content={
|
||||
<ScrollView
|
||||
fadingEdgeLength={32}
|
||||
style={{ height: height * 0.75 }}
|
||||
>
|
||||
<Design.Text
|
||||
variant="text-sm/medium"
|
||||
color="text-muted"
|
||||
selectable
|
||||
style={{ textAlign: 'left' }}
|
||||
>
|
||||
{license ?? 'Fetching...'}
|
||||
</Design.Text>
|
||||
</ScrollView>
|
||||
}
|
||||
actions={
|
||||
<Design.AlertActionButton text="Close" variant="secondary" />
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import TableRowAssetIcon from '@revenge-mod/components/TableRowAssetIcon'
|
||||
import { FullVersion } from '~/constants'
|
||||
import RevengeIcon from '~assets/RevengeIcon'
|
||||
import { RouteNames, Setting } from '../constants'
|
||||
import type { SettingsItem } from '@revenge-mod/discord/modules/settings'
|
||||
|
|
@ -8,8 +9,7 @@ const RevengeSetting: SettingsItem = {
|
|||
type: 'route',
|
||||
IconComponent: () => <TableRowAssetIcon id={RevengeIcon} />,
|
||||
title: () => 'Revenge',
|
||||
useTrailing: () =>
|
||||
`${__BUILD_VERSION__}-${__BUILD_COMMIT__}-${__BUILD_BRANCH__}`,
|
||||
useTrailing: () => FullVersion,
|
||||
screen: {
|
||||
route: RouteNames[Setting.Revenge],
|
||||
getComponent: () => require('../screens/RevengeSettingScreen').default,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
import TableRowAssetIcon from '@revenge-mod/components/TableRowAssetIcon'
|
||||
import { Linking } from 'react-native'
|
||||
import { Setting } from '../constants'
|
||||
import type { SettingsItem } from '@revenge-mod/discord/modules/settings'
|
||||
|
||||
const RevengeSourceRepositorySetting: SettingsItem = {
|
||||
parent: Setting.Revenge,
|
||||
IconComponent: () => <TableRowAssetIcon name="PaperIcon" />,
|
||||
title: () => 'Source Code',
|
||||
useDescription: () => __BUILD_SOURCE_REPOSITORY_URL__,
|
||||
onPress: () => {
|
||||
Linking.openURL(__BUILD_SOURCE_REPOSITORY_URL__)
|
||||
},
|
||||
type: 'pressable',
|
||||
}
|
||||
|
||||
export default RevengeSourceRepositorySetting
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import TableRowAssetIcon from '@revenge-mod/components/TableRowAssetIcon'
|
||||
import { BuildEnvironment } from '~/constants'
|
||||
import { BuildEnvironment, FullVersion } from '~/constants'
|
||||
import RevengeIcon from '~assets/RevengeIcon'
|
||||
import { Setting } from '../constants'
|
||||
import type { SettingsItem } from '@revenge-mod/discord/modules/settings'
|
||||
|
|
@ -8,8 +8,7 @@ const RevengeVersionSetting: SettingsItem = {
|
|||
parent: Setting.Revenge,
|
||||
IconComponent: () => <TableRowAssetIcon id={RevengeIcon} />,
|
||||
title: () => 'Revenge',
|
||||
useDescription: () =>
|
||||
`${__BUILD_VERSION__}-${__BUILD_COMMIT__}-${__BUILD_BRANCH__} (${BuildEnvironment})`,
|
||||
useDescription: () => `${FullVersion} (${BuildEnvironment})`,
|
||||
type: 'static',
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ import ReactVersionSetting from './definitions/ReactVersionSetting'
|
|||
import ReloadSetting from './definitions/ReloadSetting'
|
||||
import RevengeCustomPageSetting from './definitions/RevengeCustomPageSetting'
|
||||
import RevengeDiscordSetting from './definitions/RevengeDiscordSetting'
|
||||
import RevengeGitHubSetting from './definitions/RevengeGitHubSetting'
|
||||
import RevengeLicenseSetting from './definitions/RevengeLicenseSetting'
|
||||
import RevengePluginsSetting from './definitions/RevengePluginsSetting'
|
||||
import RevengeSetting from './definitions/RevengeSetting'
|
||||
import RevengeSourceRepositorySetting from './definitions/RevengeSourceRepositorySetting'
|
||||
import RevengeVersionSetting from './definitions/RevengeVersionSetting'
|
||||
|
||||
registerSettingsItems({
|
||||
|
|
@ -22,7 +23,8 @@ registerSettingsItems({
|
|||
// [MobileSetting.REVENGE_THEMES]: RevengeThemesSetting,
|
||||
// [MobileSetting.REVENGE_FONTS]: RevengeFontsSetting,
|
||||
[Setting.RevengeCustomPage]: RevengeCustomPageSetting,
|
||||
[Setting.RevengeGitHub]: RevengeGitHubSetting,
|
||||
[Setting.RevengeSourceRepository]: RevengeSourceRepositorySetting,
|
||||
[Setting.RevengeLicense]: RevengeLicenseSetting,
|
||||
[Setting.RevengeDiscord]: RevengeDiscordSetting,
|
||||
[Setting.Reload]: ReloadSetting,
|
||||
[Setting.RevengeVersion]: RevengeVersionSetting,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ export default function RevengeSettingScreen() {
|
|||
settings: [
|
||||
Setting.RevengeVersion,
|
||||
Setting.RevengeDiscord,
|
||||
Setting.RevengeGitHub,
|
||||
Setting.RevengeSourceRepository,
|
||||
Setting.RevengeLicense,
|
||||
],
|
||||
subLabel: (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { AppStartPerformance } from '@revenge-mod/discord/preinit'
|
||||
import { InternalPluginFlags, registerPlugin } from '@revenge-mod/plugins/_'
|
||||
import { PluginFlags } from '@revenge-mod/plugins/constants'
|
||||
import { BuildEnvironment } from '~/constants'
|
||||
import { BuildEnvironment, FullVersion } from '~/constants'
|
||||
|
||||
AppStartPerformance.mark('👊', 'Plugins register')
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ registerPlugin(
|
|||
performance.now() - tsInit,
|
||||
)
|
||||
logger.log(
|
||||
`👊 Revenge. Discord, your way. (${__BUILD_VERSION__}-${__BUILD_COMMIT__}-${__BUILD_BRANCH__} (${BuildEnvironment}))`,
|
||||
`👊 Revenge. Discord, your way. (${FullVersion} (${BuildEnvironment}))`,
|
||||
)
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {
|
|||
onModuleInitialized,
|
||||
} from '@revenge-mod/modules/metro/subscriptions'
|
||||
import { getErrorStack } from '@revenge-mod/utils/error'
|
||||
import { BuildEnvironment } from './constants'
|
||||
import { BuildEnvironment, FullVersion } from './constants'
|
||||
|
||||
const IndexModuleId = 0
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ function onError(e: unknown) {
|
|||
const Device = DeviceModule.getConstants()
|
||||
|
||||
alert(
|
||||
`Failed to load Revenge (${__BUILD_VERSION__}-${__BUILD_COMMIT__}-${__BUILD_BRANCH__} (${BuildEnvironment}))\n` +
|
||||
`Failed to load Revenge (${FullVersion} (${BuildEnvironment}))\n` +
|
||||
`Discord: ${Client.Version} (${Client.Build})\n` +
|
||||
`Device: ${Device.deviceManufacturer} ${Device.deviceModel}\n\n` +
|
||||
getErrorStack(e),
|
||||
|
|
|
|||
3
types.d.ts
vendored
3
types.d.ts
vendored
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
declare global {
|
||||
const __DEV__: boolean
|
||||
const __BUILD_DISCORD_SERVER_URL__: string
|
||||
const __BUILD_SOURCE_REPOSITORY_URL__: string
|
||||
const __BUILD_LICENSE_URL__: string
|
||||
const __BUILD_COMMIT__: string
|
||||
const __BUILD_BRANCH__: string
|
||||
const __BUILD_VERSION__: string
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue