mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
Fix#564: Update sponsors command to handle new API response format (#565)
Co-authored-by: Aman Varshney <amanvarshney.work@gmail.com>
This commit is contained in:
@@ -1,25 +1,49 @@
|
|||||||
import { log, outro, spinner } from "@clack/prompts";
|
import { log, outro, spinner } from "@clack/prompts";
|
||||||
|
import { consola } from "consola";
|
||||||
import pc from "picocolors";
|
import pc from "picocolors";
|
||||||
|
|
||||||
export interface SponsorEntry {
|
type SponsorSummary = {
|
||||||
readonly sponsor: {
|
total_sponsors: number;
|
||||||
readonly login: string;
|
total_lifetime_amount: number;
|
||||||
readonly name?: string | null;
|
total_current_monthly: number;
|
||||||
readonly avatarUrl?: string | null;
|
special_sponsors: number;
|
||||||
readonly websiteUrl?: string | null;
|
current_sponsors: number;
|
||||||
readonly linkUrl?: string | null;
|
past_sponsors: number;
|
||||||
readonly type?: string;
|
backers: number;
|
||||||
|
top_sponsor?: {
|
||||||
|
name: string;
|
||||||
|
amount: number;
|
||||||
};
|
};
|
||||||
readonly isOneTime: boolean;
|
};
|
||||||
readonly monthlyDollars?: number;
|
|
||||||
readonly tierName?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SPONSORS_JSON_URL = "https://sponsors.amanv.dev/sponsors.json";
|
type Sponsor = {
|
||||||
|
name?: string;
|
||||||
|
githubId: string;
|
||||||
|
avatarUrl: string;
|
||||||
|
websiteUrl?: string;
|
||||||
|
githubUrl: string;
|
||||||
|
tierName?: string;
|
||||||
|
sinceWhen: string;
|
||||||
|
transactionCount: number;
|
||||||
|
totalProcessedAmount?: number;
|
||||||
|
formattedAmount?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type SponsorEntry = {
|
||||||
|
generated_at: string;
|
||||||
|
summary: SponsorSummary;
|
||||||
|
specialSponsors: Sponsor[];
|
||||||
|
sponsors: Sponsor[];
|
||||||
|
pastSponsors: Sponsor[];
|
||||||
|
backers: Sponsor[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SPONSORS_JSON_URL =
|
||||||
|
"https://sponsors.better-t-stack.dev/sponsors.json";
|
||||||
|
|
||||||
export async function fetchSponsors(
|
export async function fetchSponsors(
|
||||||
url: string = SPONSORS_JSON_URL,
|
url: string = SPONSORS_JSON_URL,
|
||||||
): Promise<SponsorEntry[]> {
|
): Promise<SponsorEntry> {
|
||||||
const s = spinner();
|
const s = spinner();
|
||||||
s.start("Fetching sponsors…");
|
s.start("Fetching sponsors…");
|
||||||
|
|
||||||
@@ -29,13 +53,14 @@ export async function fetchSponsors(
|
|||||||
throw new Error(`Failed to fetch sponsors: ${response.statusText}`);
|
throw new Error(`Failed to fetch sponsors: ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sponsors = (await response.json()) as SponsorEntry[];
|
const sponsors = (await response.json()) as SponsorEntry;
|
||||||
s.stop("Sponsors fetched successfully!");
|
s.stop("Sponsors fetched successfully!");
|
||||||
return sponsors;
|
return sponsors;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function displaySponsors(sponsors: SponsorEntry[]) {
|
export function displaySponsors(sponsors: SponsorEntry) {
|
||||||
if (sponsors.length === 0) {
|
const { total_sponsors } = sponsors.summary;
|
||||||
|
if (total_sponsors === 0) {
|
||||||
log.info("No sponsors found. You can be the first one! ✨");
|
log.info("No sponsors found. You can be the first one! ✨");
|
||||||
outro(
|
outro(
|
||||||
pc.cyan(
|
pc.cyan(
|
||||||
@@ -45,24 +70,47 @@ export function displaySponsors(sponsors: SponsorEntry[]) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sponsors.forEach((entry: SponsorEntry, idx: number) => {
|
displaySponsorsBox(sponsors);
|
||||||
const sponsor = entry.sponsor;
|
|
||||||
const displayName = sponsor.name ?? sponsor.login;
|
|
||||||
const tier = entry.tierName ? ` (${entry.tierName})` : "";
|
|
||||||
|
|
||||||
log.step(`${idx + 1}. ${pc.green(displayName)}${pc.yellow(tier)}`);
|
if (total_sponsors - sponsors.specialSponsors.length > 0) {
|
||||||
log.message(` ${pc.dim("GitHub:")} https://github.com/${sponsor.login}`);
|
log.message(
|
||||||
|
pc.blue(
|
||||||
const website = sponsor.websiteUrl ?? sponsor.linkUrl;
|
`+${total_sponsors - sponsors.specialSponsors.length} more amazing sponsors.\n`,
|
||||||
if (website) {
|
),
|
||||||
log.message(` ${pc.dim("Website:")} ${website}`);
|
);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
log.message("");
|
|
||||||
outro(
|
outro(
|
||||||
pc.magenta(
|
pc.magenta(
|
||||||
"Visit https://github.com/sponsors/AmanVarshney01 to become a sponsor.",
|
"Visit https://github.com/sponsors/AmanVarshney01 to become a sponsor.",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function displaySponsorsBox(sponsors: SponsorEntry) {
|
||||||
|
if (sponsors.specialSponsors.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = `${pc.bold(pc.cyan("-> Special Sponsors"))}\n\n`;
|
||||||
|
|
||||||
|
sponsors.specialSponsors.forEach((sponsor: Sponsor, idx: number) => {
|
||||||
|
const displayName = sponsor.name ?? sponsor.githubId;
|
||||||
|
const tier = sponsor.tierName
|
||||||
|
? ` ${pc.yellow(`(${sponsor.tierName})`)}`
|
||||||
|
: "";
|
||||||
|
|
||||||
|
output += `${pc.green(`• ${displayName}`)}${tier}\n`;
|
||||||
|
output += ` ${pc.dim("GitHub:")} https://github.com/${sponsor.githubId}\n`;
|
||||||
|
|
||||||
|
const website = sponsor.websiteUrl ?? sponsor.githubUrl;
|
||||||
|
if (website) {
|
||||||
|
output += ` ${pc.dim("Website:")} ${website}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idx < sponsors.specialSponsors.length - 1) {
|
||||||
|
output += "\n";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
consola.box(output);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user