mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
feat: improve cross-uni app workflow
This commit is contained in:
36
packages/angular-builder/src/icons/check-icon-correctness.ts
Normal file
36
packages/angular-builder/src/icons/check-icon-correctness.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user