/* * Copyright (C) 2022 StApps * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ import {Font, open} from 'fontkit'; import {existsSync} from 'fs'; import {getUsedIcons} from './gather-used-icons.js'; import {fetchCodePointMap} from './get-code-points.js'; import type {IconConfig} from '../index.js'; export async function checkIconCorrectness(config: IconConfig) { if (!existsSync(config.outputPath)) { throw new Error('Icons have not been generated'); } const modifiedFont = (await open(config.outputPath)) as Font; const codePoints = await fetchCodePointMap(); for (const icon of await getUsedIcons(config)) { const codePoint = codePoints.get(icon); if (!codePoint) throw new Error(`"${icon}" is not a valid icon`); if (!modifiedFont.getGlyph(Number.parseInt(codePoint, 16))) { throw new Error(`"${icon}" (code point ${codePoint}) is missing`); } } }