11import { log , outro , spinner } from "@clack/prompts" ;
2+ import { consola } from "consola" ;
23import pc from "picocolors" ;
34
4- export interface SponsorEntry {
5- readonly sponsor : {
6- readonly login : string ;
7- readonly name ?: string | null ;
8- readonly avatarUrl ?: string | null ;
9- readonly websiteUrl ?: string | null ;
10- readonly linkUrl ?: string | null ;
11- readonly type ?: string ;
5+ type SponsorSummary = {
6+ total_sponsors : number ;
7+ total_lifetime_amount : number ;
8+ total_current_monthly : number ;
9+ special_sponsors : number ;
10+ current_sponsors : number ;
11+ past_sponsors : number ;
12+ backers : number ;
13+ top_sponsor ?: {
14+ name : string ;
15+ amount : number ;
1216 } ;
13- readonly isOneTime : boolean ;
14- readonly monthlyDollars ?: number ;
15- readonly tierName ?: string ;
16- }
17+ } ;
18+
19+ type Sponsor = {
20+ name ?: string ;
21+ githubId : string ;
22+ avatarUrl : string ;
23+ websiteUrl ?: string ;
24+ githubUrl : string ;
25+ tierName ?: string ;
26+ sinceWhen : string ;
27+ transactionCount : number ;
28+ totalProcessedAmount ?: number ;
29+ formattedAmount ?: string ;
30+ } ;
1731
18- export const SPONSORS_JSON_URL = "https://sponsors.amanv.dev/sponsors.json" ;
32+ type SponsorEntry = {
33+ generated_at : string ;
34+ summary : SponsorSummary ;
35+ specialSponsors : Sponsor [ ] ;
36+ sponsors : Sponsor [ ] ;
37+ pastSponsors : Sponsor [ ] ;
38+ backers : Sponsor [ ] ;
39+ } ;
40+
41+ export const SPONSORS_JSON_URL =
42+ "https://sponsors.better-t-stack.dev/sponsors.json" ;
1943
2044export async function fetchSponsors (
2145 url : string = SPONSORS_JSON_URL ,
22- ) : Promise < SponsorEntry [ ] > {
46+ ) : Promise < SponsorEntry > {
2347 const s = spinner ( ) ;
2448 s . start ( "Fetching sponsors…" ) ;
2549
@@ -29,13 +53,14 @@ export async function fetchSponsors(
2953 throw new Error ( `Failed to fetch sponsors: ${ response . statusText } ` ) ;
3054 }
3155
32- const sponsors = ( await response . json ( ) ) as SponsorEntry [ ] ;
56+ const sponsors = ( await response . json ( ) ) as SponsorEntry ;
3357 s . stop ( "Sponsors fetched successfully!" ) ;
3458 return sponsors ;
3559}
3660
37- export function displaySponsors ( sponsors : SponsorEntry [ ] ) {
38- if ( sponsors . length === 0 ) {
61+ export function displaySponsors ( sponsors : SponsorEntry ) {
62+ const { total_sponsors } = sponsors . summary ;
63+ if ( total_sponsors === 0 ) {
3964 log . info ( "No sponsors found. You can be the first one! ✨" ) ;
4065 outro (
4166 pc . cyan (
@@ -45,24 +70,47 @@ export function displaySponsors(sponsors: SponsorEntry[]) {
4570 return ;
4671 }
4772
48- sponsors . forEach ( ( entry : SponsorEntry , idx : number ) => {
49- const sponsor = entry . sponsor ;
50- const displayName = sponsor . name ?? sponsor . login ;
51- const tier = entry . tierName ? ` (${ entry . tierName } )` : "" ;
52-
53- log . step ( `${ idx + 1 } . ${ pc . green ( displayName ) } ${ pc . yellow ( tier ) } ` ) ;
54- log . message ( ` ${ pc . dim ( "GitHub:" ) } https://github.com/${ sponsor . login } ` ) ;
73+ displaySponsorsBox ( sponsors ) ;
5574
56- const website = sponsor . websiteUrl ?? sponsor . linkUrl ;
57- if ( website ) {
58- log . message ( ` ${ pc . dim ( "Website:" ) } ${ website } ` ) ;
59- }
60- } ) ;
61-
62- log . message ( "" ) ;
75+ if ( total_sponsors - sponsors . specialSponsors . length > 0 ) {
76+ log . message (
77+ pc . blue (
78+ `+ ${ total_sponsors - sponsors . specialSponsors . length } more amazing sponsors.\n` ,
79+ ) ,
80+ ) ;
81+ }
6382 outro (
6483 pc . magenta (
6584 "Visit https://github.com/sponsors/AmanVarshney01 to become a sponsor." ,
6685 ) ,
6786 ) ;
6887}
88+
89+ function displaySponsorsBox ( sponsors : SponsorEntry ) {
90+ if ( sponsors . specialSponsors . length === 0 ) {
91+ return ;
92+ }
93+
94+ let output = `${ pc . bold ( pc . cyan ( "-> Special Sponsors" ) ) } \n\n` ;
95+
96+ sponsors . specialSponsors . forEach ( ( sponsor : Sponsor , idx : number ) => {
97+ const displayName = sponsor . name ?? sponsor . githubId ;
98+ const tier = sponsor . tierName
99+ ? ` ${ pc . yellow ( `(${ sponsor . tierName } )` ) } `
100+ : "" ;
101+
102+ output += `${ pc . green ( `• ${ displayName } ` ) } ${ tier } \n` ;
103+ output += ` ${ pc . dim ( "GitHub:" ) } https://github.com/${ sponsor . githubId } \n` ;
104+
105+ const website = sponsor . websiteUrl ?? sponsor . githubUrl ;
106+ if ( website ) {
107+ output += ` ${ pc . dim ( "Website:" ) } ${ website } \n` ;
108+ }
109+
110+ if ( idx < sponsors . specialSponsors . length - 1 ) {
111+ output += "\n" ;
112+ }
113+ } ) ;
114+
115+ consola . box ( output ) ;
116+ }
0 commit comments