Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GH star script for future run on CI #961

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import { productLinks, resourcesLinks } from "./Nav/links";

// Manual count of stars on GitHub for now
// Run pnpm run github:stars to get the latest count
const GITHUB_STARS = 2684;
import githubData from "src/data/github.json";

const githubStars = githubData.stars;

const menu: {
title: string;
Expand Down Expand Up @@ -214,7 +216,7 @@ function OpenSourceButton({ className = "" }: { className?: string }) {
>
<span className="hidden lg:inline">Open Source</span>
<RiGithubFill className="h-4 w-4 shrink-0" />
<span>{(GITHUB_STARS / 1000).toFixed(1)}K</span>
<span>{(githubStars / 1000).toFixed(1)}K</span>
<RiArrowDownSLine
className={`h-4 w-4 transition-all ${
open ? "rotate-180 md:rotate-0" : ""
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"env:pull": "vercel env pull",
"env:add": "vercel env add",
"env:rm": "vercel env rm",
"github:stars": "pnpm dlx ts-node ./utils/github.ts",
"github:stars": "pnpm dlx ts-node ./scripts/updateGithubStars.ts",
"preinstall": "npx only-allow pnpm"
},
"dependencies": {
Expand Down
19 changes: 19 additions & 0 deletions scripts/updateGithubStars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import fs from "node:fs";
import path from "node:path";
import { getTotalStars } from "../utils/github";

const FILENAME = "./data/github.json";
const filepath = path.join(__dirname, "..", FILENAME);

async function main() {
const totalStars = await getTotalStars("inngest");

const fileTemplate = {
__generated: `File generated at ${new Date().toISOString()}`,
stars: totalStars,
};
fs.writeFileSync(filepath, JSON.stringify(fileTemplate, null, 2));
console.log(`${totalStars} total stars`);
}

main();
9 changes: 1 addition & 8 deletions utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@ async function getRepoStars(org) {
return repos;
}

async function getTotalStars(org) {
export async function getTotalStars(org) {
const repos = await getRepoStars(org);
const totalStars = repos.reduce((acc, repo) => acc + repo.stars, 0);
return totalStars;
}

async function main() {
const totalStars = await getTotalStars("inngest");
console.log(`${totalStars} total stars`);
}

main();
Loading