-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathrender_svg.ts
More file actions
73 lines (60 loc) · 1.8 KB
/
render_svg.ts
File metadata and controls
73 lines (60 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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();