Skip to content

🎥 Make videos programmatically with React

refactor script

Jonny Burger3ba65434b402
diff --git a/packages/google-fonts/scripts/generate-index.ts b/packages/google-fonts/scripts/generate-index.ts
index 114f7d6e6e..183d87a592 100644
--- a/packages/google-fonts/scripts/generate-index.ts
+++ b/packages/google-fonts/scripts/generate-index.ts
@@ -2,6 +2,7 @@ import fs from "node:fs";
import path from "path";
import prettier from "prettier";
import { googleFonts } from "./google-fonts";
+import { removeWhitespace, unqoute } from "./utils";
const OUTDIR = "./src";
@@ -12,11 +13,8 @@ const generate = async () => {
console.log(`- Generating ${filename}`);
let output = `export const availableFonts = ${JSON.stringify(
googleFonts.map((f) => ({
- fontFamily: f.family.replace(/^['"]/g, "").replace(/['"]$/g, ""),
- importName: f.family
- .replace(/^['"]/g, "")
- .replace(/['"]$/g, "")
- .replace(/\s/g, ""),
+ fontFamily: unqoute(f.family),
+ importName: removeWhitespace(unqoute(f.family)),
})),
null,
2
diff --git a/packages/google-fonts/scripts/generate.ts b/packages/google-fonts/scripts/generate.ts
index 633e78f755..14ccb5c5d2 100644
--- a/packages/google-fonts/scripts/generate.ts
+++ b/packages/google-fonts/scripts/generate.ts
@@ -5,7 +5,7 @@ import postcss from "postcss";
import prettier from "prettier";
import PQueue from "p-queue";
-import { getCssLink, unqoute, quote } from "./utils";
+import { getCssLink, unqoute, quote, removeWhitespace } from "./utils";
import { Font, googleFonts } from "./google-fonts";
const OUTDIR = "./src";
@@ -13,7 +13,7 @@ const CSS_CACHE_DIR = "./.cache-css";
const generate = async (font: Font) => {
// Prepare filename
- let importName = font.family.replace(/\s/g, "");
+ let importName = removeWhitespace(font.family);
const filename = `${importName}.ts`;
const cssname = `${font.family.toLowerCase().replace(/\s/g, "_")}_${
font.version
@@ -75,7 +75,7 @@ const generate = async (font: Font) => {
);
}
- info.fontFamily = decl.value;
+ fontFamily = decl.value;
});
// Parse style
@@ -117,8 +117,7 @@ const generate = async (font: Font) => {
// Prepare info data
const info = {
- fontFamily:
- fontFamily ?? font.family.replace(/^['"]/g, "").replace(/['"]$/g, ""),
+ fontFamily,
importName,
version: font.version,
url,
diff --git a/packages/google-fonts/scripts/utils.ts b/packages/google-fonts/scripts/utils.ts
index 88ff55d70a..25a2e3e1ed 100644
--- a/packages/google-fonts/scripts/utils.ts
+++ b/packages/google-fonts/scripts/utils.ts
@@ -5,6 +5,8 @@ export const unqoute = (str: string) =>
export const quote = (str: string) => `'${str}'`;
+export const removeWhitespace = (str: string) => str.replace(/\s/g, "");
+
export const getCssLink = (font: Font) => {
let url = "https://fonts.googleapis.com/css2?family=";
url += font.family.replace(/ /g, "+");