MCPcopy Create free account
hub / github.com/fontsource/fontsource / generateGoogle

Function generateGoogle

registry/scripts/google.ts:827–894  ·  view source on GitHub ↗
(
	snapshot: GitSnapshot,
	root: string,
	previousFamilyIds: readonly string[],
	taxonomy: Taxonomy,
)

Source from the content-addressed store, hash-verified

825};
826
827export const generateGoogle = async (
828 snapshot: GitSnapshot,
829 root: string,
830 previousFamilyIds: readonly string[],
831 taxonomy: Taxonomy,
832): Promise<string[]> => {
833 const families = readGoogleFamilies(snapshot);
834 const tagsByFamily = readGoogleTags(snapshot, taxonomy);
835 const languageCatalog = readGoogleLanguages(snapshot);
836 const referencedLanguages = new Set(
837 [...families.values()].flatMap(({ family }) => [
838 ...family.languages,
839 ...(family.primaryLanguage ? [family.primaryLanguage] : []),
840 ]),
841 );
842 const unknownLanguages = [...referencedLanguages]
843 .filter((language) => !languageCatalog[language])
844 .toSorted(compareStrings);
845 if (unknownLanguages.length > 0) {
846 logger.warn(
847 `Ignoring ${unknownLanguages.length} stale Google language references: ${unknownLanguages.join(', ')}`,
848 );
849 }
850 await writeJson(join(root, 'languages.json'), languageCatalog);
851
852 const familyIds = new Set(previousFamilyIds);
853 const ctx = createFontContext();
854 const matchLanguages = createLanguageMatcher(languageCatalog);
855 const sortedFamilies = Array.from(families).toSorted(([left], [right]) =>
856 compareStrings(left, right),
857 );
858
859 try {
860 for (const [index, [id, family]] of sortedFamilies.entries()) {
861 const isNew = !familyIds.has(id);
862 await writeFamily(
863 snapshot,
864 id,
865 family,
866 root,
867 ctx,
868 tagsByFamily.get(family.family.name) ?? [],
869 languageCatalog,
870 matchLanguages,
871 isNew,
872 );
873 familyIds.add(id);
874 const processed = index + 1;
875 if (processed % 100 === 0 && processed < sortedFamilies.length) {
876 logger.info(
877 `Processed ${processed}/${sortedFamilies.length} font families`,
878 );
879 }
880 }
881 } finally {
882 ctx.destroy();
883 }
884

Callers 2

generateRegistryFunction · 0.90
registry.test.tsFile · 0.90

Calls 15

writeJsonFunction · 0.90
createFontContextFunction · 0.90
createLanguageMatcherFunction · 0.90
compareStringsFunction · 0.90
readJsonFunction · 0.90
readGoogleFamiliesFunction · 0.85
readGoogleTagsFunction · 0.85
readGoogleLanguagesFunction · 0.85
writeAxisRegistryFunction · 0.85
writeFamilyFunction · 0.70
valuesMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected