(opts: CLIOptions, fonts?: string[])
| 91 | const removeSubsetIds = new Set(['noto-serif-hk']); |
| 92 | |
| 93 | export const processGoogle = async (opts: CLIOptions, fonts?: string[]) => { |
| 94 | // Ensure all chosen dirs are created |
| 95 | const outDir = path.resolve(process.cwd(), 'fonts'); |
| 96 | await fs.ensureDir(outDir); |
| 97 | // Make tempdir for storing metadata in rebuilds |
| 98 | const tmpDir = path.join(outDir, 'fontsource_temp_packages'); |
| 99 | await fs.ensureDir(tmpDir); |
| 100 | |
| 101 | let fontIds = fonts; |
| 102 | if (opts.test) { |
| 103 | fontIds = testIds; |
| 104 | } else if (!fonts || fonts.length === 0) { |
| 105 | fontIds = Object.keys(APIv2); |
| 106 | } else { |
| 107 | throw new Error('No fonts specified.'); |
| 108 | } |
| 109 | |
| 110 | // Normal fonts |
| 111 | for (const id of fontIds) { |
| 112 | // Create default options |
| 113 | const buildOpts: BuildOptions = { |
| 114 | dir: outDir, |
| 115 | tmpDir, |
| 116 | noSubset: removeSubsetIds.has(id), |
| 117 | isVariable: false, |
| 118 | isIcon: false, |
| 119 | force: opts.force ?? false, |
| 120 | ttf: opts.ttf ?? false, |
| 121 | }; |
| 122 | |
| 123 | if (id in APIv2) { |
| 124 | // Create base font package |
| 125 | void queue |
| 126 | .add(() => buildPackage(id, buildOpts)) |
| 127 | .catch((error) => { |
| 128 | consola.error(`Error processing ${id}.`); |
| 129 | throw error; |
| 130 | }); |
| 131 | |
| 132 | // Build separate package for variable fonts |
| 133 | if (APIVariable[id] !== undefined) { |
| 134 | void queue |
| 135 | .add(() => buildVariablePackage(id, buildOpts)) |
| 136 | .catch((error) => { |
| 137 | consola.error(`Error processing ${id} [VARIABLE].`); |
| 138 | throw error; |
| 139 | }); |
| 140 | } |
| 141 | } else { |
| 142 | consola.warn(`Skipping ${id} as it is not a Google Font.`); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // Icons |
| 147 | if (!fonts || fonts.length === 0) { |
| 148 | fontIds = Object.keys(APIIconStatic); |
| 149 | } |
| 150 |
no test coverage detected