chore: refactor, auto-gen assets
This commit is contained in:
parent
73dbf1aa2e
commit
26b4c08a24
26 changed files with 75 additions and 45 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { _subs, _data } from './_internal'
|
||||
import { _data, _subs } from './_internal'
|
||||
|
||||
import type { ComponentType, ReactNode } from 'react'
|
||||
import type { DiscordModules } from '../../../types'
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ onModuleFirstRequired(0, function onceIndexRequired() {
|
|||
onModuleInitialized(0, function onceIndexInitialized() {
|
||||
runCatching(() => {
|
||||
// Register all plugins
|
||||
require('~plugins/all')
|
||||
require('~/plugins/all')
|
||||
|
||||
// Initialize init libraries
|
||||
require('@revenge-mod/plugins/init')
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { parse } from 'path'
|
||||
import { transform } from '@swc/core'
|
||||
import { $, main } from 'bun'
|
||||
import chalk from 'chalk'
|
||||
import { exists, mkdir, readdir, writeFile } from 'fs/promises'
|
||||
import { type OutputChunk, type RolldownPlugin, rolldown } from 'rolldown'
|
||||
import { aliasPlugin } from 'rolldown/experimental'
|
||||
|
||||
|
|
@ -12,6 +14,8 @@ if (main === import.meta.filename) build()
|
|||
export default async function build(dev = false, log = true) {
|
||||
const start = performance.now()
|
||||
|
||||
await generateAssets()
|
||||
|
||||
const bundle = await rolldown({
|
||||
input: 'src/index.ts',
|
||||
platform: 'neutral',
|
||||
|
|
@ -167,3 +171,22 @@ function hermesCPlugin({ afterComplete, flags }: { flags?: string[]; afterComple
|
|||
},
|
||||
} satisfies RolldownPlugin
|
||||
}
|
||||
|
||||
async function generateAssets() {
|
||||
const AssetsDir = 'src/assets'
|
||||
const GeneratedAssetsDir = 'dist/assets/generated'
|
||||
if (!(await exists(GeneratedAssetsDir))) await mkdir(GeneratedAssetsDir, { recursive: true })
|
||||
|
||||
for (const file of await readdir(AssetsDir)) {
|
||||
const { name, ext } = parse(file)
|
||||
const path = `${AssetsDir}/${file}`
|
||||
const path2 = `${GeneratedAssetsDir}/${name}.js`
|
||||
|
||||
if (await exists(path2)) continue
|
||||
|
||||
writeFile(
|
||||
path2,
|
||||
`const ${name}=require('@revenge-mod/assets').registerAsset({name:'${name}',type:'${ext}',uri:require('~/../${path}')})/**@type {ReturnType<import('@revenge-mod/assets').registerAsset>}*/\nexport default ${name}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
25
src/components/AssetIcon.tsx
Normal file
25
src/components/AssetIcon.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { getAssetByName, getAssetId } from '@revenge-mod/assets'
|
||||
import { Components } from '@revenge-mod/discord/ui'
|
||||
|
||||
import type { DiscordModules } from '@revenge-mod/discord/types'
|
||||
|
||||
export default function AssetIcon(props: AssetIconProps) {
|
||||
return (
|
||||
<Components.TableRow.Icon
|
||||
source={props.name ? getAssetId(getAssetByName(props.name)!)! : props.id!}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export type AssetIconProps = Omit<DiscordModules.Components.TableRowIconProps, 'source'> &
|
||||
(
|
||||
| {
|
||||
name: string
|
||||
id?: never
|
||||
}
|
||||
| {
|
||||
name?: never
|
||||
id: number
|
||||
}
|
||||
)
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
import { getAssetByName, getAssetId } from '@revenge-mod/assets'
|
||||
import { Components } from '@revenge-mod/discord/ui'
|
||||
|
||||
import type { DiscordModules } from '@revenge-mod/discord/types'
|
||||
|
||||
export default function AssetIcon(props: AssetIconProps) {
|
||||
return <Components.TableRow.Icon source={getAssetId(getAssetByName(props.name)!)!} {...props} />
|
||||
}
|
||||
|
||||
export interface AssetIconProps extends Omit<DiscordModules.Components.TableRowIconProps, 'source'> {
|
||||
name: string
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import { Components } from '@revenge-mod/discord/ui'
|
||||
|
||||
import RevengeIconWebp from '~assets/revenge.webp'
|
||||
|
||||
export default function RevengeIcon() {
|
||||
return <Components.TableRow.Icon source={{ uri: RevengeIconWebp }} />
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import { Components } from '@revenge-mod/discord/ui'
|
|||
|
||||
import { getErrorStack } from '@revenge-mod/utils/errors'
|
||||
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { pluginApi } from '..'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { React } from '@revenge-mod/react'
|
||||
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting } from '../constants'
|
||||
import { DevToolsContext, connectToDevTools, useIsDevToolsOpen } from '../devtools'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { React } from '@revenge-mod/react'
|
||||
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting } from '../constants'
|
||||
import { disconnectFromDevTools, useIsDevToolsOpen } from '../devtools'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { React } from '@revenge-mod/react'
|
||||
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting } from '../constants'
|
||||
import { DevToolsContext } from '../devtools'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting, UserSettingsSections } from '../constants'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { React } from '@revenge-mod/react'
|
||||
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting } from '../constants'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { React, ReactNative } from '@revenge-mod/react'
|
||||
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting } from '../constants'
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { React } from '@revenge-mod/react'
|
|||
|
||||
import { MobileSetting } from '../constants'
|
||||
|
||||
import AssetIcon from '~/components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import type { SettingsItem } from '@revenge-mod/discord/ui/settings'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { BundleUpdaterManager } from '@revenge-mod/discord/native'
|
||||
import { React } from '@revenge-mod/react'
|
||||
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting } from '../constants'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { React, ReactNative } from '@revenge-mod/react'
|
||||
|
||||
import { DiscordServerURL } from '~/constants'
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting } from '../constants'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting, UserSettingsSections } from '../constants'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { React, ReactNative } from '@revenge-mod/react'
|
||||
|
||||
import { GitHubOrganizationURL } from '~/constants'
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting } from '../constants'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { React } from '@revenge-mod/react'
|
||||
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import type { SettingsItem } from '@revenge-mod/discord/ui/settings'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { getEnabledPluginsCount } from '@revenge-mod/plugins/_'
|
||||
|
||||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting, UserSettingsSections } from '../constants'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import RevengeIcon from '~components/icons/RevengeIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
import RevengeIcon from '~assets/RevengeIcon'
|
||||
|
||||
import { MobileSetting, UserSettingsSections } from '../constants'
|
||||
|
||||
|
|
@ -7,7 +8,7 @@ import type { SettingsItem } from '@revenge-mod/discord/ui/settings'
|
|||
const RevengeSetting: SettingsItem = {
|
||||
parent: null,
|
||||
type: 'route',
|
||||
IconComponent: RevengeIcon,
|
||||
IconComponent: () => <AssetIcon id={RevengeIcon} />,
|
||||
title: () => 'Revenge',
|
||||
useTrailing: () => `${__BUILD_VERSION__}-${__BUILD_COMMIT__}-${__BUILD_BRANCH__}`,
|
||||
screen: {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import AssetIcon from '~components/icons/AssetIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
|
||||
import { MobileSetting, UserSettingsSections } from '../constants'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import RevengeIcon from '~components/icons/RevengeIcon'
|
||||
import AssetIcon from '~/components/AssetIcon'
|
||||
import RevengeIcon from '~assets/RevengeIcon'
|
||||
|
||||
import { MobileSetting } from '../constants'
|
||||
|
||||
|
|
@ -6,7 +7,7 @@ import type { SettingsItem } from '@revenge-mod/discord/ui/settings'
|
|||
|
||||
const RevengeVersionSetting: SettingsItem = {
|
||||
parent: MobileSetting.REVENGE,
|
||||
IconComponent: RevengeIcon,
|
||||
IconComponent: () => <AssetIcon id={RevengeIcon} />,
|
||||
title: () => 'Revenge',
|
||||
useDescription: () => `${__BUILD_VERSION__}-${__BUILD_COMMIT__}-${__BUILD_BRANCH__} (${__BUILD_ENV__})`,
|
||||
type: 'static',
|
||||
|
|
@ -4,11 +4,11 @@ import { InternalPluginFlags, registerPlugin } from '@revenge-mod/plugins/_'
|
|||
import { waitForModules } from '@revenge-mod/modules/finders'
|
||||
import { byName, byProps } from '@revenge-mod/modules/finders/filters'
|
||||
|
||||
import { _subs, _data } from '@revenge-mod/discord/_/ui/settings'
|
||||
import { _data, _subs } from '@revenge-mod/discord/_/ui/settings'
|
||||
|
||||
import { after } from '@revenge-mod/patcher'
|
||||
|
||||
import { onceSettingsModulesLoaded, type SettingsItem } from '@revenge-mod/discord/ui/settings'
|
||||
import { type SettingsItem, onceSettingsModulesLoaded } from '@revenge-mod/discord/ui/settings'
|
||||
import type { FC } from 'react'
|
||||
|
||||
registerPlugin(
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@
|
|||
"extends": "@revenge-mod/types/tsconfig",
|
||||
"compilerOptions": {
|
||||
"types": ["@revenge-mod/types", "./types", "./types.modules", "node/util"],
|
||||
"allowJs": true,
|
||||
"paths": {
|
||||
"~/*": ["./src/*"],
|
||||
"~assets/*": ["./src/assets/*"],
|
||||
"~components/*": ["./src/components/*"],
|
||||
"~plugins/*": ["./src/plugins/*"]
|
||||
"~assets/*": ["./dist/assets/generated/*"]
|
||||
}
|
||||
},
|
||||
"include": ["lib", "src", "shims"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue