(id: string, opts: BuildOptions)
| 33 | const APIVariable = APIVariableImport; |
| 34 | |
| 35 | const 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 |
no test coverage detected