Skip to content

🎥 Make videos programmatically with React

`@remotion/google-fonts`: Make `waitUntilDone()` available from `getAvailableFonts()`

Jonny Burger91043d4446fb
diff --git a/packages/google-fonts/scripts/generate-index.ts b/packages/google-fonts/scripts/generate-index.ts
index 4673cff2c5..2a4c00d057 100644
--- a/packages/google-fonts/scripts/generate-index.ts
+++ b/packages/google-fonts/scripts/generate-index.ts
@@ -1,12 +1,15 @@
-import fs from "node:fs";
-import path from "path";
-import prettier from "prettier";
-import { removeWhitespace, unquote } from "./utils";
-import { filteredFonts } from "./filtered-fonts";
+import fs from 'node:fs';
+import path from 'path';
+import prettier from 'prettier';
+import {filteredFonts} from './filtered-fonts';
+import {removeWhitespace, unquote} from './utils';
-const OUTDIR = "./src";
+const OUTDIR = './src';
const typesInfo = `
+// This file is auto-generated by 'bun scripts/generate-index.ts'
+// Do not edit this file manually
+
type Variants = Record<
string,
{
@@ -37,63 +40,65 @@ export type GoogleFont = {
}
| undefined
) => {
- fontFamily: string;
- fonts: Record<string, Record<string, Record<string, string>>>;
- unicodeRanges: Record<string, string>;
+ fontFamily: FontInfo['fontFamily'];
+ fonts: FontInfo['fonts'];
+ unicodeRanges: FontInfo['unicodeRanges'];
+ waitUntilDone: () => Promise<undefined>;
};
};
`;
const generate = async () => {
- // Prepare filename
- const filename = `index.ts`;
+ // Prepare filename
+ const filename = `index.ts`;
- console.log(`- Generating ${filename}`);
- let output = `${typesInfo}
+ console.log(`- Generating ${filename}`);
+ let output = `${typesInfo}
export const getAvailableFonts = () => ${JSON.stringify(
- filteredFonts.map((f) => {
- const importName = removeWhitespace(unquote(f.family));
- return {
- fontFamily: unquote(f.family),
- importName,
- load: `() => import('./${importName}') as Promise<GoogleFont>`,
- };
- })
- )};`.replace(/\"\(\)\s\=\>\s(.*?)\"/g, (e) => {
- return e.substring(1, e.length - 1);
- });
+ filteredFonts.map((f) => {
+ const importName = removeWhitespace(unquote(f.family));
+ return {
+ fontFamily: unquote(f.family),
+ importName,
+ load: `() => import('./${importName}') as Promise<GoogleFont>`,
+ };
+ }),
+ )};`.replace(/\"\(\)\s\=\>\s(.*?)\"/g, (e) => {
+ return e.substring(1, e.length - 1);
+ });
- // Format output
- output = await prettier.format(output, {
- parser: "typescript",
- singleQuote: true,
- quoteProps: "consistent",
- printWidth: 80,
- });
+ // Format output
+ output = await prettier.format(output, {
+ parser: 'typescript',
+ singleQuote: true,
+ quoteProps: 'consistent',
+ printWidth: 80,
+ useTabs: false,
+ });
- // Save
- await fs.promises.writeFile(path.resolve(OUTDIR, filename), output);
- console.log(`- ${filename} generated`);
+ // Save
+ await fs.promises.writeFile(path.resolve(OUTDIR, filename), output);
+ console.log(`- ${filename} generated`);
- // Generate file for package.json
- const packageFilename = `package.json`;
- const read = JSON.parse(await fs.promises.readFile(packageFilename, "utf-8"));
- for (const font of filteredFonts) {
- if (!read.typesVersions) read.typesVersions = {};
- if (!read.typesVersions[">=1.0"]) read.typesVersions[">=1.0"] = {};
- read.typesVersions[">=1.0"][removeWhitespace(unquote(font.family))] = [
- `dist/cjs/${removeWhitespace(unquote(font.family))}.d.ts`,
- ];
- }
+ // Generate file for package.json
+ const packageFilename = `package.json`;
+ const read = JSON.parse(await fs.promises.readFile(packageFilename, 'utf-8'));
+ for (const font of filteredFonts) {
+ if (!read.typesVersions) read.typesVersions = {};
+ if (!read.typesVersions['>=1.0']) read.typesVersions['>=1.0'] = {};
+ read.typesVersions['>=1.0'][removeWhitespace(unquote(font.family))] = [
+ `dist/cjs/${removeWhitespace(unquote(font.family))}.d.ts`,
+ ];
+ }
- await fs.promises.writeFile(
- packageFilename,
- JSON.stringify(read, null, 2) + "\n"
- );
+ await fs.promises.writeFile(
+ packageFilename,
+ JSON.stringify(read, null, '\t') + '\n',
+ );
};
generate().catch((err) => {
- console.error(err);
- process.exit(1);
+ console.error(err);
+ process.exit(1);
});
diff --git a/packages/google-fonts/src/index.ts b/packages/google-fonts/src/index.ts
index 0dd1fbf649..6618d86f12 100644
--- a/packages/google-fonts/src/index.ts
+++ b/packages/google-fonts/src/index.ts
@@ -1,3 +1,6 @@
+// This file is auto-generated by 'bun scripts/generate-index.ts'
+// Do not edit this file manually
+
type Variants = Record<
string,
{
@@ -28,9 +31,10 @@ export type GoogleFont = {
}
| undefined,
) => {
- fontFamily: string;
- fonts: Record<string, Record<string, Record<string, string>>>;
- unicodeRanges: Record<string, string>;
+ fontFamily: FontInfo['fontFamily'];
+ fonts: FontInfo['fonts'];
+ unicodeRanges: FontInfo['unicodeRanges'];
+ waitUntilDone: () => Promise<undefined>;
};
};