Skip to content

Commit d2b70ea

Browse files
committedJun 13, 2024
feat: add useRuntimeEnv function
1 parent a7ba06a commit d2b70ea

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"jiti": "^1.21.0",
3535
"pathe": "^1.1.2",
3636
"perfect-debounce": "^1.0.0",
37+
"scule": "^1.3.0",
3738
"unctx": "^2.3.1"
3839
},
3940
"devDependencies": {

‎pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/types/commands.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ type OptionDef =
113113
| DateOptionDef
114114
| UrlOptionDef
115115

116-
export type OptionsDef = Record<string, OptionDef>
116+
export interface OptionsDef {
117+
[x: string]: OptionDef
118+
}
117119

118120
export type ParsedOptionType =
119121
| string

‎src/types/harmonix.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ interface HarmonixDirs {
2727
preconditions: string
2828
}
2929

30+
interface RuntimeEnv {
31+
[key: string]: string | undefined
32+
}
33+
3034
export interface HarmonixOptions {
3135
rootDir: string
3236
srcDir: string
@@ -44,7 +48,7 @@ export interface HarmonixOptions {
4448
preconditions: HarmonixPreconditionInput[]
4549
client: ClientOptions
4650
clientId: string
47-
ownerIds: string[]
51+
env: RuntimeEnv
4852
}
4953

5054
type DeepPartial<T> =

‎src/uses.ts

+18
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,29 @@ import {
1313
type RoleSelectMenuBuilder,
1414
type MentionableSelectMenuBuilder
1515
} from 'discord.js'
16+
import { kebabCase, camelCase } from 'scule'
1617
import type { Stream } from 'node:stream'
1718
import { useHarmonix } from './harmonix'
1819
import type { EmbedOptions } from './types'
1920
import { getButton, getModal, getSelectMenu } from './getters'
2021

22+
export const useRuntimeEnv = (): Record<string, string | undefined> => {
23+
const harmonix = useHarmonix()
24+
const env = Object.entries(process.env).reduce(
25+
(acc, [key, value]) => {
26+
if (/^(HMX_)/.test(key) && value) {
27+
const _key = kebabCase(key.replace('HMX_', ''))
28+
29+
acc[camelCase(_key)] = value
30+
}
31+
return acc
32+
},
33+
{} as Record<string, string | undefined>
34+
)
35+
36+
return { ...harmonix.options.env, ...env }
37+
}
38+
2139
export const useButtons = () => {
2240
const { components } = useHarmonix()
2341

0 commit comments

Comments
 (0)