🎥 Make videos programmatically with React
Update generate.ts
Jonny Burger2bb6f7f7e6ba
diff --git a/packages/google-fonts/scripts/generate.ts b/packages/google-fonts/scripts/generate.tsindex 47d2b9b52d..37f5a168a2 100644--- a/packages/google-fonts/scripts/generate.ts+++ b/packages/google-fonts/scripts/generate.ts@@ -1,6 +1,5 @@import fs, { mkdirSync } from "node:fs";import path from "path";-import got from "got";import postcss from "postcss";type FontInfo = {@@ -27,12 +26,17 @@ const CSS_CACHE_DIR = "./.cache-css";const generate = async (font: Font) => {// Prepare filename- let importName = removeWhitespace(font.family);+ const importName = removeWhitespace(font.family);const filename = `${importName}.ts`;+ const tsFile = path.resolve(OUTDIR, filename);+ if (fs.existsSync(tsFile)) {+ return;+ }const cssname = `${font.family.toLowerCase().replace(/\s/g, "_")}_${font.version}.css`;+// Get css linkconst url = getCssLink(font);@@ -42,7 +46,7 @@ const generate = async (font: Font) => {let cssFile = path.resolve(CSS_CACHE_DIR, cssname);if (!fs.existsSync(cssFile)) {// Get from url with user agent that support woff2- const res = await got.get(url, {+ const res = await fetch(url, {headers: {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36",@@ -50,14 +54,18 @@ const generate = async (font: Font) => {});// Save to cache- await fs.promises.writeFile(cssFile, res.body);+ const body = await res.text()+ await fs.promises.writeFile(cssFile, body);+ console.log("Generated", cssFile)- css = res.body;+ css = body;} else {// Read css from cachecss = await fs.promises.readFile(cssFile, "utf-8");}++if (!css) {throw new Error("no css");}@@ -169,7 +177,8 @@ export const loadFont = <T extends keyof Variants>(mkdirSync(OUTDIR, { recursive: true });// Save- await fs.promises.writeFile(path.resolve(OUTDIR, filename), output);+ await fs.promises.writeFile(tsFile, output);+ console.log('Wrote', tsFile)};const run = async () => {