Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
106 lines
2.9 KiB
JavaScript
106 lines
2.9 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const fs = require('fs/promises')
|
|
const path = require('path')
|
|
const fetch = require('node-fetch')
|
|
|
|
;(async () => {
|
|
const { familyMetadataList } = await fetch(
|
|
'https://fonts.google.com/metadata/fonts'
|
|
).then((r) => r.json())
|
|
|
|
let fontFunctions = `/**
|
|
* This is an autogenerated file by scripts/update-google-fonts.js
|
|
*/
|
|
import type { CssVariable, NextFont, NextFontWithVariable, Display } from '../types'
|
|
`
|
|
const fontData = {}
|
|
const ignoredSubsets = [
|
|
'menu',
|
|
'japanese',
|
|
'korean',
|
|
'chinese-simplified',
|
|
'chinese-hongkong',
|
|
'chinese-traditional',
|
|
]
|
|
for (let { family, fonts, axes, subsets } of familyMetadataList) {
|
|
subsets = subsets.filter((subset) => !ignoredSubsets.includes(subset))
|
|
const hasPreloadableSubsets = subsets.length > 0
|
|
const weights = new Set()
|
|
const styles = new Set()
|
|
|
|
for (const variant of Object.keys(fonts)) {
|
|
if (variant.endsWith('i')) {
|
|
styles.add('italic')
|
|
weights.add(variant.slice(0, -1))
|
|
continue
|
|
} else {
|
|
styles.add('normal')
|
|
weights.add(variant)
|
|
}
|
|
}
|
|
|
|
const hasVariableFont = axes.length > 0
|
|
|
|
let optionalAxes
|
|
if (hasVariableFont) {
|
|
weights.add('variable')
|
|
|
|
const nonWeightAxes = axes.filter(({ tag }) => tag !== 'wght')
|
|
if (nonWeightAxes.length > 0) {
|
|
optionalAxes = nonWeightAxes
|
|
}
|
|
}
|
|
|
|
fontData[family] = {
|
|
weights: [...weights],
|
|
styles: [...styles],
|
|
axes: hasVariableFont ? axes : undefined,
|
|
subsets,
|
|
}
|
|
const optionalIfVariableFont = hasVariableFont ? '?' : ''
|
|
|
|
const formatUnion = (values) =>
|
|
values.map((value) => `"${value}"`).join('|')
|
|
|
|
const weightTypes = [...weights]
|
|
const styleTypes = [...styles]
|
|
|
|
fontFunctions += `export declare function ${(/\d/.test(family[0])
|
|
? '_' + family
|
|
: family
|
|
).replaceAll(' ', '_')}
|
|
<T extends CssVariable | undefined = undefined>(options${optionalIfVariableFont}: {
|
|
weight${optionalIfVariableFont}:${formatUnion(
|
|
weightTypes
|
|
)} | Array<${formatUnion(
|
|
weightTypes.filter((weight) => weight !== 'variable')
|
|
)}>
|
|
style?: ${formatUnion(styleTypes)} | Array<${formatUnion(styleTypes)}>
|
|
display?:Display
|
|
variable?: T
|
|
${hasPreloadableSubsets ? 'preload?:boolean' : ''}
|
|
fallback?: string[]
|
|
adjustFontFallback?: boolean
|
|
${hasPreloadableSubsets ? `subsets?: Array<${formatUnion(subsets)}>` : ''}
|
|
${
|
|
optionalAxes
|
|
? `axes?:(${formatUnion(optionalAxes.map(({ tag }) => tag))})[]`
|
|
: ''
|
|
}
|
|
}): T extends undefined ? NextFont : NextFontWithVariable
|
|
`
|
|
}
|
|
|
|
await Promise.all([
|
|
fs.writeFile(
|
|
path.join(__dirname, '../packages/font/src/google/index.ts'),
|
|
fontFunctions
|
|
),
|
|
fs.writeFile(
|
|
path.join(__dirname, '../packages/font/src/google/font-data.json'),
|
|
JSON.stringify(fontData, null, 2)
|
|
),
|
|
])
|
|
})()
|