Refactor config structure for better readability
Some checks failed
CI / test (pull_request) Has been cancelled
Some checks failed
CI / test (pull_request) Has been cancelled
Split nested dev/prod config object into a Config type with separate devConfig and prodConfig objects. This makes it clearer which values apply to which environment and ensures both configs match the type. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
bb401f8252
commit
85eea2f4ef
1
bun.lock
1
bun.lock
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"lockfileVersion": 1,
|
||||
"configVersion": 0,
|
||||
"workspaces": {
|
||||
"": {
|
||||
"name": "workshop",
|
||||
|
|
|
|||
|
|
@ -1,33 +1,34 @@
|
|||
export const getConfig = <K extends keyof typeof config>(key: K) => {
|
||||
const env = process.env.NODE_ENV === "production" ? "prod" : "dev"
|
||||
const value = config[key][env]
|
||||
return value as (typeof config)[K]["dev"]
|
||||
type Config = {
|
||||
dbPath: string
|
||||
channelId: string
|
||||
discordClientId: string
|
||||
dataDir: string
|
||||
giteaToDiscordUserMappings: Record<string, string>
|
||||
}
|
||||
|
||||
const config = {
|
||||
dbPath: {
|
||||
dev: ".//local-spike.db",
|
||||
prod: `${process.env.DATA_DIR}/spike.db`,
|
||||
},
|
||||
channelId: {
|
||||
dev: "1384275245174620370",
|
||||
prod: "1436392275696554055",
|
||||
},
|
||||
discordClientId: {
|
||||
dev: "1384271480119885977",
|
||||
prod: "1382067546651365416",
|
||||
},
|
||||
dataDir: {
|
||||
dev: "/Users/corey/code/tmp/data",
|
||||
prod: "/var/data",
|
||||
},
|
||||
const devConfig: Config = {
|
||||
dbPath: ".//local-spike.db",
|
||||
channelId: "1384275245174620370",
|
||||
discordClientId: "1384271480119885977",
|
||||
dataDir: "/Users/corey/code/tmp/data",
|
||||
giteaToDiscordUserMappings: {
|
||||
dev: {
|
||||
probablycorey: "corey",
|
||||
} as Record<string, string>,
|
||||
prod: {
|
||||
probablycorey: "corey",
|
||||
defunkt: "defunkt",
|
||||
} as Record<string, string>,
|
||||
probablycorey: "corey",
|
||||
},
|
||||
}
|
||||
|
||||
const prodConfig: Config = {
|
||||
dbPath: `${process.env.DATA_DIR}/spike.db`,
|
||||
channelId: "1436392275696554055",
|
||||
discordClientId: "1382067546651365416",
|
||||
dataDir: "/var/data",
|
||||
giteaToDiscordUserMappings: {
|
||||
probablycorey: "corey",
|
||||
defunkt: "defunkt",
|
||||
},
|
||||
}
|
||||
|
||||
const config = process.env.NODE_ENV === "production" ? prodConfig : devConfig
|
||||
|
||||
export function getConfig<K extends keyof Config>(key: K) {
|
||||
return config[key]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user