From 972d4e0de8711a64d3bf5e2adf81f945a389bfcb Mon Sep 17 00:00:00 2001 From: Philipp Melab Date: Fri, 19 Apr 2024 20:23:58 +0200 Subject: [PATCH] fix(SLB-222): build fontlist during prep --- apps/website/gatsby-ssr.tsx | 3 ++- packages/ui/package.json | 7 +------ packages/ui/preloaded-fonts.js | 10 ++++++++++ packages/ui/src/preloaded-fonts.ts | 7 ------- packages/ui/turbo.json | 5 +++++ 5 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 packages/ui/preloaded-fonts.js delete mode 100644 packages/ui/src/preloaded-fonts.ts diff --git a/apps/website/gatsby-ssr.tsx b/apps/website/gatsby-ssr.tsx index 513f3f3a1..8481b8ea3 100644 --- a/apps/website/gatsby-ssr.tsx +++ b/apps/website/gatsby-ssr.tsx @@ -1,8 +1,9 @@ import { Locale } from '@custom/schema'; -import { fonts } from '@custom/ui/preloaded-fonts'; import { GatsbySSR } from 'gatsby'; import React from 'react'; +import fonts from './node_modules/@custom/ui/build/preloaded-fonts.json'; + export const onRenderBody: GatsbySSR['onRenderBody'] = ({ setHtmlAttributes, pathname, diff --git a/packages/ui/package.json b/packages/ui/package.json index 88eef3bab..7d7d034d8 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -12,24 +12,19 @@ ], "./styles.css": [ "./build/styles.css" - ], - "./preloaded-fonts": [ - "./build/preloaded-fonts.js" ] }, "typesVersions": { "*": { "routes/*": [ "build/components/Routes/*.d.ts" - ], - "preloaded-fonts": [ - "build/preloaded-fonts.d.ts" ] } }, "scripts": { "prep:types": "tsc --emitDeclarationOnly", "prep:scripts": "swc ./src -d ./build", + "prep:fonts": "node preloaded-fonts.js", "prep:styles": "NODE_ENV=production pnpm postcss src/tailwind.css -o build/styles.css", "prep:iframe": "NODE_ENV=production pnpm postcss src/iframe.css -o build/iframe.css", "prep:gutenberg": "NODE_ENV=production PREFIX=gutenberg pnpm postcss src/tailwind.css -o build/gutenberg.css", diff --git a/packages/ui/preloaded-fonts.js b/packages/ui/preloaded-fonts.js new file mode 100644 index 000000000..f8a8f46fd --- /dev/null +++ b/packages/ui/preloaded-fonts.js @@ -0,0 +1,10 @@ +import { readdirSync, writeFileSync } from 'fs'; + +writeFileSync( + 'build/preloaded-fonts.json', + JSON.stringify( + readdirSync(`static/public/fonts/preload`).map((font) => { + return `/fonts/preload/${font}`; + }), + ), +); diff --git a/packages/ui/src/preloaded-fonts.ts b/packages/ui/src/preloaded-fonts.ts deleted file mode 100644 index 26b7dc854..000000000 --- a/packages/ui/src/preloaded-fonts.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { readdirSync } from 'fs'; - -export const fonts = readdirSync('./static/public/fonts/preload').map( - (font) => { - return `/fonts/preload/${font}`; - }, -); diff --git a/packages/ui/turbo.json b/packages/ui/turbo.json index 361810220..52b8064c4 100644 --- a/packages/ui/turbo.json +++ b/packages/ui/turbo.json @@ -2,6 +2,10 @@ "$schema": "https://turborepo.org/schema.json", "extends": ["//"], "pipeline": { + "prep:fonts": { + "inputs": ["static/public/fonts/preload/**"], + "outputs": ["build/preloaded-fonts.json"] + }, "prep:scripts": { "dependsOn": ["^prep"], "inputs": [ @@ -48,6 +52,7 @@ }, "prep": { "dependsOn": [ + "prep:fonts", "prep:types", "prep:scripts", "prep:styles",