mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
add sponsors, builder, docs command in cli
This commit is contained in:
25
apps/cli/src/utils/open-url.ts
Normal file
25
apps/cli/src/utils/open-url.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { log } from "@clack/prompts";
|
||||
import { execa } from "execa";
|
||||
|
||||
export async function openUrl(url: string): Promise<void> {
|
||||
const platform = process.platform;
|
||||
let command: string;
|
||||
let args: string[] = [];
|
||||
|
||||
if (platform === "darwin") {
|
||||
command = "open";
|
||||
args = [url];
|
||||
} else if (platform === "win32") {
|
||||
command = "cmd";
|
||||
args = ["/c", "start", "", url.replace(/&/g, "^&")];
|
||||
} else {
|
||||
command = "xdg-open";
|
||||
args = [url];
|
||||
}
|
||||
|
||||
try {
|
||||
await execa(command, args, { stdio: "ignore" });
|
||||
} catch {
|
||||
log.message(`Please open ${url} in your browser.`);
|
||||
}
|
||||
}
|
||||
68
apps/cli/src/utils/sponsors.ts
Normal file
68
apps/cli/src/utils/sponsors.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { log, outro, spinner } from "@clack/prompts";
|
||||
import pc from "picocolors";
|
||||
|
||||
export interface SponsorEntry {
|
||||
readonly sponsor: {
|
||||
readonly login: string;
|
||||
readonly name?: string | null;
|
||||
readonly avatarUrl?: string | null;
|
||||
readonly websiteUrl?: string | null;
|
||||
readonly linkUrl?: string | null;
|
||||
readonly type?: string;
|
||||
};
|
||||
readonly isOneTime: boolean;
|
||||
readonly monthlyDollars?: number;
|
||||
readonly tierName?: string;
|
||||
}
|
||||
|
||||
export const SPONSORS_JSON_URL = "https://sponsors.amanv.dev/sponsors.json";
|
||||
|
||||
export async function fetchSponsors(
|
||||
url: string = SPONSORS_JSON_URL,
|
||||
): Promise<SponsorEntry[]> {
|
||||
const s = spinner();
|
||||
s.start("Fetching sponsors…");
|
||||
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
s.stop(pc.red(`Failed to fetch sponsors: ${response.statusText}`));
|
||||
throw new Error(`Failed to fetch sponsors: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const sponsors = (await response.json()) as SponsorEntry[];
|
||||
s.stop("Sponsors fetched successfully!");
|
||||
return sponsors;
|
||||
}
|
||||
|
||||
export function displaySponsors(sponsors: SponsorEntry[]): void {
|
||||
if (sponsors.length === 0) {
|
||||
log.info("No sponsors found. You can be the first one! ✨");
|
||||
outro(
|
||||
pc.cyan(
|
||||
"Visit https://github.com/sponsors/AmanVarshney01 to become a sponsor.",
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
sponsors.forEach((entry: SponsorEntry, idx: number) => {
|
||||
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)}`);
|
||||
log.message(` ${pc.dim("GitHub:")} https://github.com/${sponsor.login}`);
|
||||
|
||||
const website = sponsor.websiteUrl ?? sponsor.linkUrl;
|
||||
if (website) {
|
||||
log.message(` ${pc.dim("Website:")} ${website}`);
|
||||
}
|
||||
});
|
||||
|
||||
log.message("");
|
||||
outro(
|
||||
pc.magenta(
|
||||
"Visit https://github.com/sponsors/AmanVarshney01 to become a sponsor.",
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user