Skip to content
Merged
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
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ pnpm-lock.yaml
!src/pages/blog/2025-06-19-multioption-inputs-with-oneof/index.mdx
*.jpg

scripts/sync-sched/*.json
src/github-stats.json
scripts/**/*.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint:docs": "eslint --ignore-path .gitignore src/pages/learn --format stylish",
"lint:docs:ci": "eslint --ignore-path .gitignore src/pages/learn --format eslint-formatter-github",
"postbuild": "next-sitemap",
"prebuild": "tsx src/get-github-info.ts",
"prebuild": "tsx scripts/get-github-info",
"serve": "pnpx serve out",
"test": "playwright test && pnpm test:unit",
"test:e2e": "playwright test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,31 @@ import grayMatter from "gray-matter"
import {
getGitHubStats,
type GitHubInfo,
} from "../scripts/sort-libraries/get-github-stats"
} from "../sort-libraries/get-github-stats"

const DATA_PATH = new URL("./github-stats.json", import.meta.url).pathname
const LAST_RUN_PATH = new URL("./last-success.isodate", import.meta.url)
.pathname
const CODE_DIR = new URL("../../src/code", import.meta.url).pathname

async function main() {
const filePaths = await fg("./src/code/**/*.md")
const filePaths = await fg("./**/*.md", { cwd: CODE_DIR, absolute: true })

const errors: Error[] = []

{
// we only sync once every two hours
const TWO_HOURS = 2 * 60 * 60 * 1000
const lastRun = await fs.readFile(LAST_RUN_PATH, "utf8").catch(() => "")
const twoHoursAgo = new Date(Date.now() - TWO_HOURS)
if (lastRun && new Date(lastRun).getTime() > twoHoursAgo.getTime()) {
console.info(
"Skipping sync of GitHub stars, last run was within two hours.",
)
return
}
}

const newState = new Map<string /* repo name */, GitHubInfo>()
const filePathToRepoName = new Map<
string /* file path */,
Expand Down Expand Up @@ -57,8 +75,7 @@ async function main() {
// If it errored for some reason, we don't do anything.
// If we got it, we overwrite.
{
const dataPath = "./src/github-stats.json"
const data = await fs.readFile(dataPath, "utf8")
const data = await fs.readFile(DATA_PATH, "utf8")
const existingStats = JSON.parse(data) as Record<string, object>

const result: Record<string, object> = {}
Expand All @@ -79,7 +96,8 @@ async function main() {
result[repoName] = newState.get(repoName)!
}

await fs.writeFile(dataPath, JSON.stringify(result, null, 2))
await fs.writeFile(DATA_PATH, JSON.stringify(result, null, 2))
await fs.writeFile(LAST_RUN_PATH, new Date().toISOString())
}
}

Expand Down
Loading