@lizardbyte/contribkit 2025.315.185528
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +231 -0
- package/bin/contribkit.mjs +2 -0
- package/dist/chunks/index.mjs +190 -0
- package/dist/chunks/index2.mjs +590 -0
- package/dist/chunks/index3.mjs +4905 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.mjs +399 -0
- package/dist/index.d.mts +494 -0
- package/dist/index.mjs +9 -0
- package/dist/shared/contribkit.QISHqB4U.mjs +1453 -0
- package/package.json +91 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Anthony Fu <https://github.com/antfu>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# ContribKit
|
|
2
|
+
|
|
3
|
+
[](https://github.com/LizardByte/contribkit)
|
|
4
|
+
[](https://github.com/LizardByte/contribkit/actions/workflows/CI.yml?query=branch%3Amaster)
|
|
5
|
+
[](https://codecov.io/gh/LizardByte/contribkit)
|
|
6
|
+
[](https://www.npmjs.com/package/@lizardbyte/contribkit)
|
|
7
|
+
[](https://www.npmjs.com/package/@lizardbyte/contribkit)
|
|
8
|
+
|
|
9
|
+
Toolkit for fetching contributor info and generating contributor images.
|
|
10
|
+
This is a fork of [sponsorkit](https://github.com/antfu-collective/sponsorkit) that supports contributors.
|
|
11
|
+
|
|
12
|
+
Supports:
|
|
13
|
+
|
|
14
|
+
- [**GitHub Sponsors**](https://github.com/sponsors)
|
|
15
|
+
- [**Patreon**](https://www.patreon.com/)
|
|
16
|
+
- [**OpenCollective**](https://opencollective.com/)
|
|
17
|
+
- [**Afdian**](https://afdian.com/)
|
|
18
|
+
- [**Polar**](https://polar.sh/)
|
|
19
|
+
- [**Liberapay**](https://liberapay.com/)
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Create `.env` file with:
|
|
24
|
+
|
|
25
|
+
```ini
|
|
26
|
+
; GitHub provider.
|
|
27
|
+
; Token requires the `read:user` and `read:org` scopes.
|
|
28
|
+
CONTRIBKIT_GITHUB_TOKEN=
|
|
29
|
+
CONTRIBKIT_GITHUB_LOGIN=
|
|
30
|
+
|
|
31
|
+
; Patreon provider.
|
|
32
|
+
; Create v2 API key at https://www.patreon.com/portal/registration/register-clients
|
|
33
|
+
; and use the "Creator’s Access Token".
|
|
34
|
+
CONTRIBKIT_PATREON_TOKEN=
|
|
35
|
+
|
|
36
|
+
; OpenCollective provider.
|
|
37
|
+
; Create an API key at https://opencollective.com/applications
|
|
38
|
+
CONTRIBKIT_OPENCOLLECTIVE_KEY=
|
|
39
|
+
; and provide the ID, slug or GitHub handle of your account.
|
|
40
|
+
CONTRIBKIT_OPENCOLLECTIVE_ID=
|
|
41
|
+
; or
|
|
42
|
+
CONTRIBKIT_OPENCOLLECTIVE_SLUG=
|
|
43
|
+
; or
|
|
44
|
+
CONTRIBKIT_OPENCOLLECTIVE_GH_HANDLE=
|
|
45
|
+
; If it is a personal account, set it to `person`. Otherwise not set or set to `collective`
|
|
46
|
+
CONTRIBKIT_OPENCOLLECTIVE_TYPE=
|
|
47
|
+
|
|
48
|
+
; Afdian provider.
|
|
49
|
+
; Get user_id at https://afdian.com/dashboard/dev
|
|
50
|
+
CONTRIBKIT_AFDIAN_USER_ID=
|
|
51
|
+
; Create token at https://afdian.com/dashboard/dev
|
|
52
|
+
CONTRIBKIT_AFDIAN_TOKEN=
|
|
53
|
+
|
|
54
|
+
; Polar provider.
|
|
55
|
+
; Get your token at https://polar.sh/settings
|
|
56
|
+
CONTRIBKIT_POLAR_TOKEN=
|
|
57
|
+
; The name of the organization to fetch sponsorships from.
|
|
58
|
+
CONTRIBKIT_POLAR_ORGANIZATION=
|
|
59
|
+
|
|
60
|
+
; Liberapay provider.
|
|
61
|
+
; The name of the profile.
|
|
62
|
+
CONTRIBKIT_LIBERAPAY_LOGIN=
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
> Only one provider is required to be configured.
|
|
66
|
+
|
|
67
|
+
Run:
|
|
68
|
+
|
|
69
|
+
```base
|
|
70
|
+
npx contribkit
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
[Example Setup](./example/) | [GitHub Actions Setup](https://github.com/antfu/static/blob/master/.github/workflows/scheduler.yml) | [Generated SVG](https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg)
|
|
74
|
+
|
|
75
|
+
### Configurations
|
|
76
|
+
|
|
77
|
+
Create `contribkit.config.js` file with:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { defineConfig, tierPresets } from '@lizardbyte/contribkit'
|
|
81
|
+
|
|
82
|
+
export default defineConfig({
|
|
83
|
+
// Providers configs
|
|
84
|
+
github: {
|
|
85
|
+
login: 'antfu',
|
|
86
|
+
type: 'user',
|
|
87
|
+
},
|
|
88
|
+
opencollective: {
|
|
89
|
+
// ...
|
|
90
|
+
},
|
|
91
|
+
patreon: {
|
|
92
|
+
// ...
|
|
93
|
+
},
|
|
94
|
+
afdian: {
|
|
95
|
+
// ...
|
|
96
|
+
},
|
|
97
|
+
polar: {
|
|
98
|
+
// ...
|
|
99
|
+
},
|
|
100
|
+
liberapay: {
|
|
101
|
+
// ...
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
// Rendering configs
|
|
105
|
+
width: 800,
|
|
106
|
+
renderer: 'tiers', // or 'circles'
|
|
107
|
+
formats: ['json', 'svg', 'png', 'webp'],
|
|
108
|
+
tiers: [
|
|
109
|
+
// Past sponsors, currently only supports GitHub
|
|
110
|
+
{
|
|
111
|
+
title: 'Past Sponsors',
|
|
112
|
+
monthlyDollars: -1,
|
|
113
|
+
preset: tierPresets.xs,
|
|
114
|
+
},
|
|
115
|
+
// Default tier
|
|
116
|
+
{
|
|
117
|
+
title: 'Backers',
|
|
118
|
+
preset: tierPresets.base,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
title: 'Sponsors',
|
|
122
|
+
monthlyDollars: 10,
|
|
123
|
+
preset: tierPresets.medium,
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
title: 'Silver Sponsors',
|
|
127
|
+
monthlyDollars: 50,
|
|
128
|
+
preset: tierPresets.large,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
title: 'Gold Sponsors',
|
|
132
|
+
monthlyDollars: 100,
|
|
133
|
+
preset: tierPresets.xl,
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Also check [the example](./example/).
|
|
140
|
+
|
|
141
|
+
### Programmatic Utilities
|
|
142
|
+
|
|
143
|
+
You can also use ContribKit programmatically:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { fetchSponsors } from '@lizardbyte/contribkit'
|
|
147
|
+
|
|
148
|
+
const sponsors = await fetchSponsors({
|
|
149
|
+
github: {
|
|
150
|
+
token,
|
|
151
|
+
login,
|
|
152
|
+
},
|
|
153
|
+
// ...
|
|
154
|
+
})
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Check the type definition or source code for more utils available.
|
|
158
|
+
|
|
159
|
+
### Renderers
|
|
160
|
+
|
|
161
|
+
We provide two renderers built-in:
|
|
162
|
+
|
|
163
|
+
- `tiers`: Render sponsors in tiers.
|
|
164
|
+
- `circles`: Render sponsors in packed circles.
|
|
165
|
+
|
|
166
|
+
#### Tiers Renderer
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
export default defineConfig({
|
|
170
|
+
renderer: 'tiers',
|
|
171
|
+
// ...
|
|
172
|
+
})
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
<p align="center">
|
|
176
|
+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
|
177
|
+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
|
|
178
|
+
</a>
|
|
179
|
+
</p>
|
|
180
|
+
|
|
181
|
+
#### Circles Renderer
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
export default defineConfig({
|
|
185
|
+
renderer: 'circles',
|
|
186
|
+
// ...
|
|
187
|
+
})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
<p align="center">
|
|
191
|
+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.circles.svg">
|
|
192
|
+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.circles.svg'/>
|
|
193
|
+
</a>
|
|
194
|
+
</p>
|
|
195
|
+
|
|
196
|
+
### Multiple Renders
|
|
197
|
+
|
|
198
|
+
We also support rendering multiple images at once with different configurations, via `renders` field:
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
import { defineConfig, tierPresets } from '@lizardbyte/contribkit'
|
|
202
|
+
|
|
203
|
+
export default defineConfig({
|
|
204
|
+
// Providers configs
|
|
205
|
+
github: { /* ... */ },
|
|
206
|
+
|
|
207
|
+
// Default configs
|
|
208
|
+
width: 800,
|
|
209
|
+
tiers: [
|
|
210
|
+
/* ... */
|
|
211
|
+
],
|
|
212
|
+
|
|
213
|
+
// Define multiple renders, each will inherit the top-level configs
|
|
214
|
+
renders: [
|
|
215
|
+
{
|
|
216
|
+
name: 'sponsors.tiers',
|
|
217
|
+
formats: ['svg'],
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: 'sponsors.wide',
|
|
221
|
+
width: 1200,
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: 'sponsors.circles',
|
|
225
|
+
renderer: 'circles',
|
|
226
|
+
width: 600,
|
|
227
|
+
},
|
|
228
|
+
// ...
|
|
229
|
+
],
|
|
230
|
+
})
|
|
231
|
+
```
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/*
|
|
2
|
+
How it works:
|
|
3
|
+
`this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
class Node {
|
|
7
|
+
value;
|
|
8
|
+
next;
|
|
9
|
+
|
|
10
|
+
constructor(value) {
|
|
11
|
+
this.value = value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class Queue {
|
|
16
|
+
#head;
|
|
17
|
+
#tail;
|
|
18
|
+
#size;
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
this.clear();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
enqueue(value) {
|
|
25
|
+
const node = new Node(value);
|
|
26
|
+
|
|
27
|
+
if (this.#head) {
|
|
28
|
+
this.#tail.next = node;
|
|
29
|
+
this.#tail = node;
|
|
30
|
+
} else {
|
|
31
|
+
this.#head = node;
|
|
32
|
+
this.#tail = node;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.#size++;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
dequeue() {
|
|
39
|
+
const current = this.#head;
|
|
40
|
+
if (!current) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.#head = this.#head.next;
|
|
45
|
+
this.#size--;
|
|
46
|
+
return current.value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
peek() {
|
|
50
|
+
if (!this.#head) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return this.#head.value;
|
|
55
|
+
|
|
56
|
+
// TODO: Node.js 18.
|
|
57
|
+
// return this.#head?.value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
clear() {
|
|
61
|
+
this.#head = undefined;
|
|
62
|
+
this.#tail = undefined;
|
|
63
|
+
this.#size = 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get size() {
|
|
67
|
+
return this.#size;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
* [Symbol.iterator]() {
|
|
71
|
+
let current = this.#head;
|
|
72
|
+
|
|
73
|
+
while (current) {
|
|
74
|
+
yield current.value;
|
|
75
|
+
current = current.next;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
* drain() {
|
|
80
|
+
let current;
|
|
81
|
+
while ((current = this.dequeue()) !== undefined) {
|
|
82
|
+
yield current;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function pLimit(concurrency) {
|
|
88
|
+
validateConcurrency(concurrency);
|
|
89
|
+
|
|
90
|
+
const queue = new Queue();
|
|
91
|
+
let activeCount = 0;
|
|
92
|
+
|
|
93
|
+
const resumeNext = () => {
|
|
94
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
95
|
+
queue.dequeue()();
|
|
96
|
+
// Since `pendingCount` has been decreased by one, increase `activeCount` by one.
|
|
97
|
+
activeCount++;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const next = () => {
|
|
102
|
+
activeCount--;
|
|
103
|
+
|
|
104
|
+
resumeNext();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const run = async (function_, resolve, arguments_) => {
|
|
108
|
+
const result = (async () => function_(...arguments_))();
|
|
109
|
+
|
|
110
|
+
resolve(result);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
await result;
|
|
114
|
+
} catch {}
|
|
115
|
+
|
|
116
|
+
next();
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const enqueue = (function_, resolve, arguments_) => {
|
|
120
|
+
// Queue `internalResolve` instead of the `run` function
|
|
121
|
+
// to preserve asynchronous context.
|
|
122
|
+
new Promise(internalResolve => {
|
|
123
|
+
queue.enqueue(internalResolve);
|
|
124
|
+
}).then(
|
|
125
|
+
run.bind(undefined, function_, resolve, arguments_),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
(async () => {
|
|
129
|
+
// This function needs to wait until the next microtask before comparing
|
|
130
|
+
// `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
|
|
131
|
+
// after the `internalResolve` function is dequeued and called. The comparison in the if-statement
|
|
132
|
+
// needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
|
|
133
|
+
await Promise.resolve();
|
|
134
|
+
|
|
135
|
+
if (activeCount < concurrency) {
|
|
136
|
+
resumeNext();
|
|
137
|
+
}
|
|
138
|
+
})();
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const generator = (function_, ...arguments_) => new Promise(resolve => {
|
|
142
|
+
enqueue(function_, resolve, arguments_);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
Object.defineProperties(generator, {
|
|
146
|
+
activeCount: {
|
|
147
|
+
get: () => activeCount,
|
|
148
|
+
},
|
|
149
|
+
pendingCount: {
|
|
150
|
+
get: () => queue.size,
|
|
151
|
+
},
|
|
152
|
+
clearQueue: {
|
|
153
|
+
value() {
|
|
154
|
+
queue.clear();
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
concurrency: {
|
|
158
|
+
get: () => concurrency,
|
|
159
|
+
|
|
160
|
+
set(newConcurrency) {
|
|
161
|
+
validateConcurrency(newConcurrency);
|
|
162
|
+
concurrency = newConcurrency;
|
|
163
|
+
|
|
164
|
+
queueMicrotask(() => {
|
|
165
|
+
// eslint-disable-next-line no-unmodified-loop-condition
|
|
166
|
+
while (activeCount < concurrency && queue.size > 0) {
|
|
167
|
+
resumeNext();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return generator;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function limitFunction(function_, option) {
|
|
178
|
+
const {concurrency} = option;
|
|
179
|
+
const limit = pLimit(concurrency);
|
|
180
|
+
|
|
181
|
+
return (...arguments_) => limit(() => function_(...arguments_));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function validateConcurrency(concurrency) {
|
|
185
|
+
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
186
|
+
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { pLimit as default, limitFunction };
|