11import type { ContribkitConfig , GitHubAccountType } from '../types'
22import process from 'node:process'
33import dotenv from 'dotenv'
4+ import { loadEnvCredentials , pruneUndefined } from './credentials'
45
5- function getDeprecatedEnv ( name : string , replacement : string ) {
6- const value = process . env [ name ]
7- if ( value )
8- console . warn ( `[contribkit] env.${ name } is deprecated, use env.${ replacement } instead` )
9- return value
6+ export interface EnvConfig {
7+ config : Partial < ContribkitConfig >
8+ credentials : ReturnType < typeof loadEnvCredentials >
109}
1110
12- export function loadEnv ( ) : Partial < ContribkitConfig > {
11+ export function loadEnv ( ) : EnvConfig {
1312 dotenv . config ( { quiet : true } )
1413
1514 const config : Partial < ContribkitConfig > = {
1615 mode : process . env . CONTRIBKIT_MODE as ContribkitConfig [ 'mode' ] | undefined ,
1716 github : {
1817 login : process . env . CONTRIBKIT_GITHUB_LOGIN || process . env . GITHUB_LOGIN ,
19- token : process . env . CONTRIBKIT_GITHUB_TOKEN || process . env . GITHUB_TOKEN ,
2018 type : ( process . env . CONTRIBKIT_GITHUB_TYPE || process . env . GITHUB_TYPE ) as GitHubAccountType | undefined ,
2119 } ,
22- patreon : {
23- token : process . env . CONTRIBKIT_PATREON_TOKEN || process . env . PATREON_TOKEN ,
24- } ,
2520 opencollective : {
26- key : process . env . CONTRIBKIT_OPENCOLLECTIVE_KEY || process . env . OPENCOLLECTIVE_KEY ,
2721 id : process . env . CONTRIBKIT_OPENCOLLECTIVE_ID || process . env . OPENCOLLECTIVE_ID ,
2822 slug : process . env . CONTRIBKIT_OPENCOLLECTIVE_SLUG || process . env . OPENCOLLECTIVE_SLUG ,
2923 githubHandle : process . env . CONTRIBKIT_OPENCOLLECTIVE_GH_HANDLE || process . env . OPENCOLLECTIVE_GH_HANDLE ,
3024 type : process . env . CONTRIBKIT_OPENCOLLECTIVE_TYPE || process . env . OPENCOLLECTIVE_TYPE ,
3125 } ,
3226 afdian : {
3327 userId : process . env . CONTRIBKIT_AFDIAN_USER_ID || process . env . AFDIAN_USER_ID ,
34- token : process . env . CONTRIBKIT_AFDIAN_TOKEN || process . env . AFDIAN_TOKEN ,
3528 exchangeRate : Number . parseFloat ( process . env . CONTRIBKIT_AFDIAN_EXCHANGE_RATE || process . env . AFDIAN_EXCHANGE_RATE || '0' ) || undefined ,
3629 } ,
3730 polar : {
38- token : process . env . CONTRIBKIT_POLAR_TOKEN || process . env . POLAR_TOKEN ,
3931 organization : process . env . CONTRIBKIT_POLAR_ORGANIZATION || process . env . POLAR_ORGANIZATION ,
4032 } ,
4133 liberapay : {
@@ -44,12 +36,10 @@ export function loadEnv(): Partial<ContribkitConfig> {
4436 outputDir : process . env . CONTRIBKIT_DIR ,
4537 githubContributors : {
4638 login : process . env . CONTRIBKIT_GITHUB_CONTRIBUTORS_LOGIN ,
47- token : process . env . CONTRIBKIT_GITHUB_CONTRIBUTORS_TOKEN ,
4839 minContributions : Number ( process . env . CONTRIBKIT_GITHUB_CONTRIBUTORS_MIN ) || 1 ,
4940 repo : process . env . CONTRIBKIT_GITHUB_CONTRIBUTORS_REPO ,
5041 } ,
5142 gitlabContributors : {
52- token : process . env . CONTRIBKIT_GITLAB_CONTRIBUTORS_TOKEN ,
5343 minContributions : Number ( process . env . CONTRIBKIT_GITLAB_CONTRIBUTORS_MIN ) || 1 ,
5444 repoId : Number ( process . env . CONTRIBKIT_GITLAB_CONTRIBUTORS_REPO_ID ) ,
5545 } ,
@@ -60,12 +50,14 @@ export function loadEnv(): Partial<ContribkitConfig> {
6050 } ,
6151 githubContributions : {
6252 login : process . env . CONTRIBKIT_GITHUB_CONTRIBUTIONS_LOGIN ,
63- token : process . env . CONTRIBKIT_GITHUB_CONTRIBUTIONS_TOKEN ,
6453 maxContributions : Number ( process . env . CONTRIBKIT_GITHUB_CONTRIBUTIONS_MAX ) || undefined ,
6554 logarithmicScaling : process . env . CONTRIBKIT_GITHUB_CONTRIBUTIONS_LOGARITHMIC === 'true' ,
6655 } ,
6756 }
6857
6958 // remove undefined keys
70- return JSON . parse ( JSON . stringify ( config ) )
59+ return {
60+ config : pruneUndefined ( config ) ,
61+ credentials : loadEnvCredentials ( ) ,
62+ }
7163}
0 commit comments