mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
* Wrote a simple render_svg.ts file that generates the svg given an github username, theme and out path. * render_svg.ts generates output dir if not exsists. * Added Section to README.md that explains how to use the render_svg.ts script. * Added an github action that utilizes the render_svg.ts script. * Added Usage of github action to README.md * Added simple CI Check if action runs. * Ran: deno fmt
73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import "https://deno.land/x/dotenv@v0.5.0/load.ts";
|
|
|
|
const username = Deno.args[0];
|
|
const outputPath = Deno.args[1] ?? "./assets/trophy.svg";
|
|
const themeName = Deno.args[2] ?? "default";
|
|
|
|
if (!username) {
|
|
console.error(
|
|
"Usage: deno run --allow-net --allow-env --allow-read --allow-write ./render_svg.ts USERNAME [OUTPUT_PATH] [THEME]",
|
|
);
|
|
Deno.exit(1);
|
|
}
|
|
|
|
import { GithubApiService } from "./src/Services/GithubApiService.ts";
|
|
import { Card } from "./src/card.ts";
|
|
import { COLORS } from "./src/theme.ts";
|
|
|
|
async function main() {
|
|
console.log("Starting trophy render...");
|
|
console.log("Username:", username);
|
|
console.log("Output path:", outputPath);
|
|
console.log("Theme:", themeName);
|
|
|
|
const svc = new GithubApiService();
|
|
|
|
const userInfoOrError = await svc.requestUserInfo(username);
|
|
|
|
if (
|
|
!(userInfoOrError && (userInfoOrError as any).totalCommits !== undefined)
|
|
) {
|
|
console.error(
|
|
"Failed to fetch user info. Check token, username and rate limits.",
|
|
);
|
|
Deno.exit(2);
|
|
}
|
|
|
|
const userInfo = userInfoOrError as any;
|
|
|
|
const panelSize = 115;
|
|
const maxRow = 10;
|
|
const maxColumn = -1; // auto
|
|
const marginWidth = 10;
|
|
const marginHeight = 10;
|
|
const noBackground = false;
|
|
const noFrame = false;
|
|
|
|
const card = new Card(
|
|
[],
|
|
[],
|
|
maxColumn,
|
|
maxRow,
|
|
panelSize,
|
|
marginWidth,
|
|
marginHeight,
|
|
noBackground,
|
|
noFrame,
|
|
);
|
|
const theme = (COLORS as any)[themeName] ?? (COLORS as any).default;
|
|
const svg = card.render(userInfo, theme);
|
|
|
|
try {
|
|
const dir = outputPath.replace(/\/[^/]+$/, "");
|
|
if (dir) await Deno.mkdir(dir, { recursive: true });
|
|
} catch {
|
|
console.error("Failed to create directory. No permission?");
|
|
Deno.exit(3);
|
|
}
|
|
|
|
await Deno.writeTextFile(outputPath, svg);
|
|
console.log(`Wrote ${outputPath}`);
|
|
}
|
|
|
|
await main();
|