Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ CONTRIBKIT_GITLAB_CONTRIBUTORS_REPO_ID=
; Token requires the `read:user` and `read:org` scopes.
CONTRIBKIT_GITHUB_TOKEN=
CONTRIBKIT_GITHUB_LOGIN=
; Optional data mode:
; - sponsors: people sponsoring you (default)
; - sponsees: people you have sponsored, including past sponsorships
CONTRIBKIT_MODE=sponsors

; Patreon provider.
; Create v2 API key at https://www.patreon.com/portal/registration/register-clients
Expand Down Expand Up @@ -144,6 +148,11 @@ Create `contribkit.config.js` file with:
import { defineConfig, tierPresets } from '@lizardbyte/contribkit'

export default defineConfig({
// Data mode:
// - sponsors: people sponsoring you (default)
// - sponsees: people you have sponsored, including past sponsorships
mode: 'sponsors',

// Providers configs
github: {
login: 'antfu',
Expand Down Expand Up @@ -243,7 +252,7 @@ export default defineConfig({

<p align="center">
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg' alt="Sponsors"/>
</a>
</p>

Expand All @@ -258,7 +267,7 @@ export default defineConfig({

<p align="center">
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.circles.svg">
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.circles.svg'/>
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.circles.svg' alt="Sponsors"/>
</a>
</p>

Expand Down
50 changes: 20 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"scripts": {
"build": "unbuild",
"stub": "unbuild --stub",
"dev": "esno src/cli.ts",
"dev": "tsx src/cli.ts",
"test": "npm-run-all test:unit test:report test:lint test:typecheck",
"test:unit": "jest --coverage",
"test:report": "jest --reporters=jest-junit",
Expand All @@ -47,39 +47,39 @@
},
"dependencies": {
"@crowdin/crowdin-api-client": "^1.41.2",
"ansis": "^4.2.0",
"cac": "^6.7.14",
"consola": "^3.4.0",
"dotenv": "^17.3.1",
"ofetch": "^1.4.1",
"ansis": "^4.3.0",
"cac": "^7.0.0",
"consola": "^3.4.2",
"dotenv": "^17.4.2",
"ofetch": "^1.5.1",
"sharp": "^0.34.5",
"unconfig": "^7.3.0"
"unconfig": "^7.5.0"
},
"devDependencies": {
"@antfu/ni": "^30.0.0",
"@antfu/utils": "^9.1.0",
"@antfu/ni": "^30.1.0",
"@antfu/utils": "^9.3.0",
"@babel/core": "7.29.7",
"@babel/preset-env": "7.29.7",
"@codecov/webpack-plugin": "2.0.1",
"@eslint/js": "^10.0.1",
"@fast-csv/parse": "^5.0.2",
"@fast-csv/parse": "^5.0.7",
"@types/d3-hierarchy": "^3.1.7",
"@types/node": "^25.2.3",
"bumpp": "^11.0.1",
"@types/node": "^25.9.1",
"bumpp": "^11.1.0",
"d3-hierarchy": "^3.1.2",
"eslint": "^10.0.0",
"eslint": "^10.4.0",
"eslint-plugin-jest": "29.15.2",
"globals": "17.6.0",
"jest": "30.4.2",
"jest-environment-jsdom": "30.4.1",
"jest-junit": "17.0.0",
"jiti": "^2.4.2",
"jiti": "^2.7.0",
"normalize-url": "^9.0.0",
"npm-run-all2": "9.0.1",
"p-limit": "^7.3.0",
"tsx": "^4.19.3",
"typescript": "^5.8.2",
"unbuild": "^3.5.0"
"tsx": "^4.22.3",
"typescript": "^5.9.2",
"unbuild": "^3.6.1"
},
"jest": {
"collectCoverageFrom": [
Expand Down
3 changes: 2 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cac from 'cac'
import { version } from '../package.json'
import { run } from './run'

const RE_FILTER = /([<>=]+)(\d+)/
const cli = cac('contributors-svg')
.version(version)
.help()
Expand Down Expand Up @@ -36,7 +37,7 @@ cli.parse()
* @param template
*/
function createFilterFromString(template: string): ContribkitConfig['filter'] {
const [_, op, value] = template.split(/([<>=]+)/)
const [_, op, value] = template.split(RE_FILTER)
const num = Number.parseInt(value)
if (op === '<')
return s => s.monthlyDollars < num
Expand Down
3 changes: 2 additions & 1 deletion src/configs/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ text {
`

export const defaultConfig: ContribkitConfig = {
mode: 'sponsors',
width: 800,
outputDir: './contribkit',
cacheFile: '.cache.json',
cacheFileSponsees: '.cache.sponsees.json',
formats: ['json', 'svg', 'png'],
tiers: defaultTiers,
name: 'sponsors',
includePrivate: false,
svgInlineCSS: defaultInlineCSS,
}
3 changes: 2 additions & 1 deletion src/configs/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ function getDeprecatedEnv(name: string, replacement: string) {
}

export function loadEnv(): Partial<ContribkitConfig> {
dotenv.config()
dotenv.config({ quiet: true })

const config: Partial<ContribkitConfig> = {
mode: process.env.CONTRIBKIT_MODE as ContribkitConfig['mode'] | undefined,
github: {
login: process.env.CONTRIBKIT_GITHUB_LOGIN || process.env.GITHUB_LOGIN,
token: process.env.CONTRIBKIT_GITHUB_TOKEN || process.env.GITHUB_TOKEN,
Expand Down
5 changes: 5 additions & 0 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export async function loadConfig(inlineConfig: ContribkitConfig = {}): Promise<R
},
} as Required<ContribkitConfig>

if (!['sponsors', 'sponsees'].includes(resolved.mode))
throw new Error(`Invalid mode: ${resolved.mode}. Expected "sponsors" or "sponsees".`)

resolved.name = inlineConfig.name || config.name || env.name || resolved.mode

return resolved
}

Expand Down
2 changes: 1 addition & 1 deletion src/processing/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class SvgComposer {

generateSvg() {
return `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${this.config.width} ${this.height}" width="${this.config.width}" height="${this.height}">
<!-- Generated by https://github.com/antfu/sponsorskit -->
<!-- Generated by https://github.com/LizardByte/contribkit -->
<style>${this.config.svgInlineCSS}</style>
${this.body}
</svg>
Expand Down
7 changes: 6 additions & 1 deletion src/providers/afdian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { $fetch } from 'ofetch'
export const AfdianProvider: Provider = {
name: 'afdian',
fetchSponsors(config) {
if (config.mode === 'sponsees') {
console.warn('[contribkit] Afdian provider does not support `mode: "sponsees"` yet')
return Promise.resolve([])
}

return fetchAfdianSponsors(config.afdian)
},
}
Expand All @@ -29,7 +34,7 @@ export async function fetchAfdianSponsors(options: ContribkitConfig['afdian'] =
let pages = 1
do {
const params = JSON.stringify({ page })
const ts = Math.round(+new Date() / 1000)
const ts = Math.round(Date.now() / 1000)
const sign = md5(token, params, ts, userId)
const sponsorshipData = await $fetch(sponsorshipApi, {
method: 'POST',
Expand Down
Loading