MCPcopy Index your code
hub / github.com/fontsource/fontsource / build

Function build

packages/cli/src/google/build.ts:35–176  ·  view source on GitHub ↗
(id: string, opts: BuildOptions)

Source from the content-addressed store, hash-verified

33const APIVariable = APIVariableImport;
34
35const build = async (id: string, opts: BuildOptions) => {
36 const font = opts.isIcon ? APIIconStatic[id] : APIv2[id];
37 const fontVariable = opts.isIcon ? APIIconVariable[id] : APIVariable[id];
38
39 // Determine license metadata
40 let fontLicense = APILicense[id];
41 if (!fontLicense?.license) {
42 consola.warn(`No license metadata found for ${id}`);
43 fontLicense = {
44 id,
45 authors: { copyright: 'Google Inc.' },
46 license: {
47 type: 'SIL Open Font License, 1.1',
48 url: 'http://scripts.sil.org/OFL',
49 },
50 original: 'Google Inc.',
51 };
52 }
53
54 // Set file directories
55 await fs.mkdir(opts.dir, { recursive: true });
56
57 // Check if updated
58 let changed = false;
59
60 try {
61 await fs.access(path.join(opts.dir, 'metadata.json'));
62 const metadata = JSON.parse(
63 await fs.readFile(path.join(opts.dir, 'metadata.json'), 'utf8'),
64 );
65 changed = metadata.lastModified !== font.lastModified;
66 } catch {
67 changed = true;
68 }
69
70 // If needs updating, preserve package.json in temporary folder till later
71 if (changed || opts.force) {
72 try {
73 // Copy to temp folder
74 const pkgJsonPath = path.join(opts.dir, 'package.json');
75 const tempPath = path.join(
76 opts.tmpDir,
77 opts.isVariable ? `${id}-variable.json` : `${id}.json`,
78 );
79
80 await fs.access(pkgJsonPath);
81 await fs.copy(pkgJsonPath, tempPath);
82 await fs.emptyDir(opts.dir);
83 // Copy back to original folder
84 await fs.copy(tempPath, pkgJsonPath);
85 await fs.remove(tempPath);
86 } catch {
87 // Continue regardless of error since package.json may not exist
88 }
89
90 // Download all font files
91 await download(id, opts);
92

Callers 4

buildPackageFunction · 0.90
buildVariablePackageFunction · 0.90
buildIconPackageFunction · 0.90
buildVariableIconPackageFunction · 0.90

Calls 13

downloadFunction · 0.90
packagerIconsVariableFunction · 0.90
packagerIconsStaticFunction · 0.90
packagerVariableFunction · 0.90
packagerV1Function · 0.90
packagerV2Function · 0.90
licenseShortFunction · 0.90
sassMetadataFunction · 0.90
readmeFunction · 0.90
generateLicenseFunction · 0.90
packageJsonFunction · 0.90
warnMethod · 0.80

Tested by

no test coverage detected