Compare commits

...

5 Commits

Author SHA1 Message Date
a725c4dcf2 feat: improve cross-uni app workflow 2024-07-15 13:13:07 +02:00
2a1a7a5d5b fix: docs generation 2024-07-09 14:30:46 +02:00
Jovan Krunić
a69b80d1d4 feat: library account adjustments
Closes #214
2024-07-04 16:40:37 +02:00
e2abc983ef fix: list item layout broken 2024-07-03 16:26:36 +02:00
913193abdb fix: elasticsearch integration spams errors 2024-07-02 17:49:38 +02:00
60 changed files with 838 additions and 1001 deletions

View File

@@ -0,0 +1,5 @@
---
"@openstapps/easy-ast": patch
---
Fixed docs generation

View File

@@ -26,6 +26,7 @@ const config = {
'types',
'bin',
'files',
'builders',
'engines',
'scripts',
'dependencies',

View File

@@ -0,0 +1,25 @@
{
"inputPath": "node_modules/material-symbols/material-symbols-rounded.woff2",
"outputPath": "src/assets/icons.min.woff2",
"htmlGlob": "src/**/*.html",
"scriptGlob": "src/**/*.ts",
"additionalIcons": {
"about": ["copyright", "campaign", "policy", "description", "text_snippet"],
"navigation": [
"home",
"newspaper",
"search",
"calendar_month",
"local_cafe",
"local_library",
"inventory_2",
"map",
"grade",
"account_circle",
"settings",
"info",
"rate_review",
"work"
]
}
}

View File

@@ -16,11 +16,32 @@ android {
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
}
}
flavorDimensions 'uni'
productFlavors {
file('../../config').eachDir {
def config = new groovy.json.JsonSlurper().parseText(file("$it/default.json").text)
"${it.name}" {
dimension 'uni'
applicationId config.android.packageName
versionName config.appMarketingVersion
resValue 'string', 'app_name', config.appName
resValue 'string', 'title_activity_main', config.appName
resValue 'string', 'package_name', config.android.packageName
resValue 'string', 'custom_url_scheme', config.appUrlScheme
resValue 'string', 'app_host', config.appLinkHost
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
}
}
}

View File

@@ -11,7 +11,7 @@
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"builder": "@openstapps/angular-builder:application",
"options": {
"outputPath": "www",
"index": "src/index.html",

View File

@@ -1,9 +1,17 @@
import {CapacitorConfig} from '@capacitor/cli';
const variant = process.env.APP_VARIANT ?? 'default';
// eslint-disable-next-line unicorn/prefer-module, @typescript-eslint/no-var-requires
const uniConfig = require(`./config/${variant}/default.json`);
const config: CapacitorConfig = {
appId: 'de.anyschool.app',
appName: 'StApps',
appId: uniConfig.android.packageName, // TODO: iOS bundle ID
appName: uniConfig.appName,
webDir: 'www',
android: {
flavor: variant,
},
// TODO: iOS scheme
cordova: {
preferences: {
'AndroidXEnabled': 'true',

View File

@@ -0,0 +1,67 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "App Config",
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"appName": {
"type": "string",
"description": "Full app name",
"examples": ["Open StApps"]
},
"appDisplayName": {
"type": "string",
"description": "App name on mobile device homescreen (Not much space)",
"examples": ["StApps"]
},
"backendUrl": {
"type": "string",
"description": "Publicly available backend url",
"examples": ["https://your.backend.server.tld"]
},
"backendVersion": {
"type": "string",
"description": "Minimum backend version the app will request",
"examples": ["3.0.0"]
},
"appLinkHost": {
"type": "string",
"description": "Your host used for universal (deep) links",
"examples": ["your.deep.link.host.tdl"]
},
"appUrlScheme": {
"type": "string",
"description": "Custom url scheme for native app versions",
"examples": ["de.anyschool.app"]
},
"appMarketingVersion": {
"type": "string",
"description": "App marketing version used in Stores (preferably SemVer or CalVer)",
"examples": ["1.0.0"]
},
"android": {
"type": "object",
"properties": {
"packageName": {
"type": "string",
"description": "Android package name",
"examples": ["de.anyschool.app"]
}
},
"required": ["packageName"]
}
},
"required": [
"$schema",
"appName",
"appDisplayName",
"backendUrl",
"backendVersion",
"appLinkHost",
"appUrlScheme",
"appMarketingVersion",
"android"
]
}

View File

@@ -0,0 +1,13 @@
{
"$schema": "./config.schema.json",
"appName": "Open StApps",
"appDisplayName": "StApps",
"backendUrl": "http://localhost:3000",
"backendVersion": "3.0.0",
"appLinkHost": "localhost:3000",
"appUrlScheme": "de.anyschool.app",
"appMarketingVersion": "1.0.0",
"android": {
"packageName": "de.anyschool.app"
}
}

View File

@@ -0,0 +1,13 @@
{
"$schema": "../config.schema.json",
"appName": "Uni Frankfurt",
"appDisplayName": "Uni Frankfurt",
"backendUrl": "https://mobile.server.uni-frankfurt.de",
"backendVersion": "3.1.0",
"appLinkHost": "mobile.app.uni-frankfurt.de",
"appUrlScheme": "de.unifrankfurt.app",
"appMarketingVersion": "2.3.0",
"android": {
"packageName": "de.unifrankfurt.app"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@@ -1,43 +0,0 @@
/*
* 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/>.
*/
/** @type {import('./scripts/icon-config').IconConfig} */
const config = {
inputPath: 'node_modules/material-symbols/material-symbols-rounded.woff2',
outputPath: 'src/assets/icons.min.woff2',
htmlGlob: 'src/**/*.html',
scriptGlob: 'src/**/*.ts',
additionalIcons: {
about: ['copyright', 'campaign', 'policy', 'description', 'text_snippet'],
navigation: [
'home',
'newspaper',
'search',
'calendar_month',
'local_cafe',
'local_library',
'inventory_2',
'map',
'grade',
'account_circle',
'settings',
'info',
'rate_review',
'work',
],
},
};
export default config;

View File

@@ -14,14 +14,10 @@
"Thea Schöbl <dev@theaninova.de>"
],
"scripts": {
"analyze": "webpack-bundle-analyzer www/stats.json",
"build": "pnpm check-icons && ng build --configuration=production --stats-json && webpack-bundle-analyzer www/stats.json --mode static --report www/bundle-info.html --no-open",
"build:analyze": "npm run build:stats && npm run analyze",
"build": "ng build --configuration=production",
"build:android": "ionic capacitor build android --no-open && cd android && ./gradlew clean assemble && cd ..",
"build:prod": "ng build --configuration=production",
"build:stats": "ng build --configuration=production --stats-json",
"changelog": "conventional-changelog -p angular -i src/assets/about/CHANGELOG.md -s -r 0",
"check-icons": "node scripts/check-icon-correctness.mjs",
"chromium:no-cors": "chromium --disable-web-security --user-data-dir=\".browser-data/chromium\"",
"chromium:virtual-host": "chromium --host-resolver-rules=\"MAP mobile.app.uni-frankfurt.de:* localhost:8100\" --ignore-certificate-errors",
"cypress:open": "cypress open",
@@ -139,6 +135,7 @@
"@ionic/cli": "7.2.0",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@openstapps/angular-builder": "workspace:*",
"@types/fontkit": "2.0.7",
"@types/geojson": "1.0.6",
"@types/glob": "8.1.0",

View File

@@ -1,65 +0,0 @@
/*
* 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 {openSync} from 'fontkit';
import config from '../icons.config.mjs';
import {existsSync} from 'fs';
import {getUsedIconsHtml, getUsedIconsTS} from './gather-used-icons.mjs';
import {fetchCodePointMap} from './get-code-points.mjs';
const commandName = '"npm run minify-icons"';
if (!existsSync(config.outputPath)) {
console.error(`Minified font not found. Run ${commandName} first.`);
process.exit(-1);
}
/** @type {import('fontkit').Font} */
const modifiedFont = openSync(config.outputPath);
let success = true;
// eslint-disable-next-line unicorn/prefer-top-level-await
checkAll().then(() => {
console.log();
if (success) {
console.log('All icons are present in both fonts.');
} else {
console.error('Errors occurred.');
process.exit(-1);
}
});
/**
*
*/
async function checkAll() {
check(config.additionalIcons || {});
check(await getUsedIconsTS(config.scriptGlob));
check(await getUsedIconsHtml(config.htmlGlob));
}
/**
* @param {Record<string, string[]>} icons
*/
async function check(icons) {
const codePoints = await fetchCodePointMap();
for (const icon of Object.values(icons).flat()) {
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`);
}
}
}

View File

@@ -1,7 +0,0 @@
{
"extends": "@openstapps/tsconfig",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node"
}
}

View File

@@ -17,7 +17,7 @@ import {ActivatedRoute} from '@angular/router';
import {SCAboutPage, SCAppConfiguration} from '@openstapps/core';
import {ConfigProvider} from '../../config/config.provider';
import packageJson from '../../../../../package.json';
import config from 'capacitor.config';
import config from '../../../../../config/default.json';
import {App} from '@capacitor/app';
import {Capacitor} from '@capacitor/core';

View File

@@ -33,9 +33,9 @@ ion-item {
margin: var(--spacing-sm);
ion-thumbnail {
--ion-margin: var(--spacing-xs);
--size: 36px;
margin-block: auto;
margin: 0;
margin-inline: var(--spacing-md);
padding: 0;
}

View File

@@ -14,7 +14,7 @@
*/
import {Component, EventEmitter, Input, Output} from '@angular/core';
import {DocumentAction, PAIADocument, PAIADocumentStatus} from '../../../types';
import {DocumentAction, PAIADocument, PAIADocumentStatus, PAIADocumentVisualStatus} from '../../../types';
import {LibraryAccountService} from '../../library-account.service';
@Component({
@@ -27,12 +27,15 @@ export class PAIAItemComponent {
renewable: boolean;
visualStatus?: PAIADocumentVisualStatus;
constructor(private readonly libraryAccountService: LibraryAccountService) {}
@Input()
set item(value: PAIADocument) {
this._item = value;
void this.setRenewable();
this.visualStatus = this.getVisualStatus(Number(this.item.status));
}
get item(): PAIADocument {
@@ -56,4 +59,18 @@ export class PAIAItemComponent {
const isActive = await this.libraryAccountService.isActivePatron();
this.renewable = isActive && Number(this.item.status) === PAIADocumentStatus.Held;
}
private getVisualStatus(status: PAIADocumentStatus): PAIADocumentVisualStatus | undefined {
switch (status) {
case PAIADocumentStatus.Ordered: {
return {color: 'warning', status: status, statusText: 'ordered'};
}
case PAIADocumentStatus.Provided: {
return {color: 'success', status: status, statusText: 'ready'};
}
default: {
return undefined;
}
}
}
}

View File

@@ -14,10 +14,16 @@
-->
<ion-item>
<!-- TODO: text not selectable in Chrome, bugfix needed https://github.com/ionic-team/ionic-framework/issues/24956 -->
<ion-label class="ion-text-wrap">
@if (item.about) {
<h2 class="name">{{ item.about }}</h2>
<h2 class="name">
@if (visualStatus) {
<ion-badge [color]="visualStatus.color" slot="start">
{{ 'library.account.pages' + '.' + listName + '.' + visualStatus.statusText | translate }}
</ion-badge>
}
{{ item.about }}
</h2>
}
@for (property of propertiesToShow; track property) {
@if (item[property]) {

View File

@@ -12,3 +12,6 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
ion-badge {
vertical-align: bottom;
}

View File

@@ -35,23 +35,13 @@
@switch (activeSegment) {
@case ('orders') {
@for (hold of paiaDocuments; track hold) {
@if (toNumber(hold.status) === paiaDocumentStatus.Provided) {
<stapps-paia-item
[item]="hold"
[propertiesToShow]="['label', 'storage']"
(documentAction)="onDocumentAction($event)"
listName="holds"
>
</stapps-paia-item>
} @else {
<stapps-paia-item
[item]="hold"
[propertiesToShow]="['label']"
(documentAction)="onDocumentAction($event)"
listName="holds"
>
</stapps-paia-item>
}
<stapps-paia-item
[item]="hold"
[propertiesToShow]="['label', 'storage']"
(documentAction)="onDocumentAction($event)"
listName="holds"
>
</stapps-paia-item>
}
}
@case ('reservations') {

View File

@@ -88,3 +88,9 @@ export interface DocumentAction {
action: 'cancel' | 'renew';
doc: PAIADocument;
}
export interface PAIADocumentVisualStatus {
color: 'warning' | 'success';
status: PAIADocumentStatus;
statusText: 'ordered' | 'ready';
}

View File

@@ -21,9 +21,9 @@ import {
SCTranslations,
} from '@openstapps/core';
import {NavigationService} from './navigation.service';
import config from 'capacitor.config';
import {SettingsProvider} from '../../settings/settings.provider';
import {BreakpointObserver} from '@angular/cdk/layout';
import config from '../../../../../config/default.json';
/**
* Generated class for the MenuPage page.

View File

@@ -1,5 +0,0 @@
export function matchTagProperties(tag: string): RegExp;
export function matchPropertyContent(properties: string[]): RegExp;
export function matchPropertyAccess(objectName: string): RegExp;

View File

@@ -336,13 +336,15 @@
"title": "Titel",
"about": "Mehr Informationen",
"label": "Signatur",
"starttime": "Übermittelt am",
"starttime": "Vorgemerkt am",
"endtime": "Abzuholen bis",
"storage": "Abholtheke",
"queue": "Position in der Warteschlange"
},
"holds": "Bestellungen",
"reservations": "Vormerkungen"
"reservations": "Vormerkungen",
"ordered": "Bestellt",
"ready": "Abholbereit"
},
"checked_out": {
"title": "Deine Ausleihen",

View File

@@ -336,13 +336,15 @@
"title": "Title",
"about": "More information",
"label": "Shelfmark",
"starttime": "Submitted at",
"starttime": "Reserved on",
"endtime": "Available for pickup until",
"storage": "Pick-up counter",
"storage": "Pickup counter",
"queue": "Position in the queue"
},
"holds": "orders",
"reservations": "reservations"
"reservations": "reservations",
"ordered": "Ordered",
"ready": "Ready for pickup"
},
"checked_out": {
"title": "checked out items",

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -16,12 +16,13 @@
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.production.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
import config from '../../config/default.json';
export const environment = {
backend_url: 'https://mobile.server.uni-frankfurt.de',
app_host: 'mobile.app.uni-frankfurt.de',
custom_url_scheme: 'de.anyschool.app',
backend_version: '999.0.0',
backend_url: config.backendUrl,
app_host: config.appLinkHost,
custom_url_scheme: config.appUrlScheme,
backend_version: config.backendVersion,
production: true,
};

View File

@@ -16,12 +16,13 @@
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.production.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
import config from '../../config/default.json';
export const environment = {
backend_url: 'https://mobile.server.uni-frankfurt.de',
app_host: 'mobile.app.uni-frankfurt.de',
custom_url_scheme: 'de.anyschool.app',
backend_version: '999.0.0',
backend_url: config.backendUrl,
app_host: config.appLinkHost,
custom_url_scheme: config.appUrlScheme,
backend_version: config.backendVersion,
production: false,
};

View File

@@ -13,6 +13,7 @@
"deploy": "dotenv -c -- turbo run deploy --concurrency=1",
"dev": "dotenv -c -- turbo run dev",
"docs": "dotenv -c -- turbo run docs && typedoc && mkdir docs/api && cp packages/core/lib/api-doc.html docs/api/index.html && cp packages/core/lib/openapi.json docs/api/openapi.json && cp -r packages/core/lib/schema docs/api/schema",
"docs:serve": "http-server docs -p 8080 -o",
"format": "dotenv -c -- turbo run format",
"format:fix": "dotenv -c -- turbo run format:fix",
"lint": "dotenv -c -- turbo run lint",
@@ -34,6 +35,7 @@
"deepmerge": "4.3.1",
"dotenv-cli": "7.2.1",
"glob": "10.3.10",
"http-server": "14.1.1",
"junit-report-merger": "6.0.3",
"prettier": "3.1.1",
"syncpack": "12.3.0",

View File

@@ -0,0 +1,8 @@
{
"builders": {
"application": {
"implementation": "./lib/application.js",
"schema": "./node_modules/@angular-devkit/build-angular/src/builders/browser/schema.json"
}
}
}

View File

@@ -0,0 +1,72 @@
{
"name": "@openstapps/angular-builder",
"version": "3.2.0",
"type": "module",
"license": "GPL-3.0-only",
"author": "Thea Schöbl <dev@theaninova.de>",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib",
"schemas",
"builders.json",
"README.md",
"CHANGELOG.md"
],
"builders": "builders.json",
"scripts": {
"build": "tsup-node --dts",
"docs": "typedoc --json ./docs/docs.json --options ../../typedoc.base.json src/index.ts",
"format": "prettier . -c --ignore-path ../../.gitignore",
"format:fix": "prettier --write . --ignore-path ../../.gitignore",
"lint": "eslint --ext .ts src/",
"lint:fix": "eslint --fix --ext .ts src/",
"test": "c8 mocha"
},
"dependencies": {
"@angular-devkit/architect": "0.1703.0",
"@angular-devkit/build-angular": "17.3.0",
"@angular-devkit/core": "17.3.0",
"cosmiconfig": "8.1.3",
"rxjs": "7.8.1",
"fontkit": "2.0.2",
"glob": "10.3.10"
},
"devDependencies": {
"@angular-devkit/schematics": "17.3.0",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@types/fontkit": "2.0.7",
"@types/glob": "8.1.0",
"@types/node": "18.15.3",
"@types/chai": "4.3.5",
"@types/chai-as-promised": "7.1.5",
"@types/chai-spies": "1.0.3",
"@types/mocha": "10.0.1",
"c8": "7.14.0",
"chai": "4.3.7",
"chai-as-promised": "7.1.1",
"chai-spies": "1.0.0",
"mocha": "10.2.0",
"mocha-junit-reporter": "2.2.0",
"tsup": "6.7.0",
"ts-node": "10.9.2",
"typescript": "5.4.2"
},
"tsup": {
"entry": [
"src/application.ts",
"src/index.ts"
],
"sourcemap": true,
"clean": true,
"format": "esm",
"outDir": "lib"
},
"prettier": "@openstapps/prettier-config",
"eslintConfig": {
"extends": [
"@openstapps"
]
}
}

View File

@@ -0,0 +1,33 @@
/// <reference types="@angular-devkit/core" />
import {BuilderContext, BuilderOutput, createBuilder} from '@angular-devkit/architect';
import {BrowserBuilderOptions, executeBrowserBuilder} from '@angular-devkit/build-angular';
import {runPrebuild} from './shared.js';
import {from, of, mergeMap, Observable} from 'rxjs';
function applicationBuilder(
input: BrowserBuilderOptions,
context: BuilderContext,
): Observable<BuilderOutput> {
if (process.env.APP_VARIANT) {
input.fileReplacements ??= [];
input.fileReplacements.push(
{
replace: 'config/default.json',
with: `config/${process.env.APP_VARIANT}/default.json`,
},
{
replace: 'src/assets/imgs/logo.png',
with: `config/${process.env.APP_VARIANT}/logo.png`,
},
{
replace: 'src/assets/icon/favicon.png',
with: `config/${process.env.APP_VARIANT}/favicon.png`,
},
);
}
return from(runPrebuild(context)).pipe(
mergeMap(it => (it ? of(it) : executeBrowserBuilder(input, context, {}))),
);
}
export default createBuilder(applicationBuilder);

View 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`);
}
}
}

View File

@@ -14,16 +14,10 @@
*/
import {glob} from 'glob';
import {readFileSync} from 'fs';
import {
matchPropertyAccess,
matchPropertyContent,
matchTagProperties,
} from '../src/app/util/ion-icon/icon-match.mjs';
import {matchPropertyAccess, matchPropertyContent, matchTagProperties} from './icon-match.js';
import {IconConfig} from '../index.js';
/**
* @returns {Promise<Record<string, string[]>>}
*/
export async function getUsedIconsHtml(pattern = 'src/**/*.html') {
export async function getUsedIconsHtml(pattern = 'src/**/*.html'): Promise<Record<string, string[]>> {
return Object.fromEntries(
(await glob(pattern))
.map(file => [
@@ -39,10 +33,7 @@ export async function getUsedIconsHtml(pattern = 'src/**/*.html') {
);
}
/**
* @returns {Promise<Record<string, string[]>>}
*/
export async function getUsedIconsTS(pattern = 'src/**/*.ts') {
export async function getUsedIconsTS(pattern = 'src/**/*.ts'): Promise<Record<string, string[]>> {
const regex = matchPropertyAccess('SCIcon');
return Object.fromEntries(
(await glob(pattern))
@@ -50,3 +41,15 @@ export async function getUsedIconsTS(pattern = 'src/**/*.ts') {
.filter(([, values]) => values && values.length > 0),
);
}
export async function getUsedIcons(config: IconConfig) {
return new Set(
[
config.additionalIcons ?? {},
await getUsedIconsTS(config.scriptGlob),
await getUsedIconsHtml(config.htmlGlob),
]
.map(Object.values)
.flat(2),
);
}

View File

@@ -5,15 +5,12 @@ const url =
export async function fetchCodePointMap() {
const icons = await fetch(url)
.then(it => it.text())
.then(it => new Map(it.split('\n').map(it => /** @type {[string, string]} */ (it.split(' ')))));
.then(it => new Map(it.split('\n').map(it => it.split(' ') as [string, string])));
if (icons.size < 100) throw new Error(`Code point map is very small, is the URL incorrect? ${url}`);
return icons;
}
/**
* @param {string[]} icons
*/
export async function getCodePoints(icons) {
export async function getCodePoints(icons: string[]) {
const codePoints = await fetchCodePointMap();
return icons.map(icon => {
const code = codePoints.get(icon);

View File

@@ -0,0 +1,11 @@
import {cosmiconfig} from 'cosmiconfig';
import type {IconConfig} from '../index.js';
export async function getIconConfig(): Promise<IconConfig> {
const explorer = cosmiconfig('icons');
const result = await explorer.search();
if (!result) {
throw new Error('No icon configuration found');
}
return result.config;
}

View File

@@ -13,21 +13,26 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* eslint-disable unicorn/no-null */
import {matchPropertyAccess, matchPropertyContent, matchTagProperties} from './icon-match.mjs';
import {expect} from 'chai';
import {matchPropertyAccess, matchPropertyContent, matchTagProperties} from './icon-match.js';
import {describe} from 'mocha';
describe('matchTagProperties', function () {
const regex = matchTagProperties('test');
it('should match html tag content', function () {
expect('<test content></test>'.match(regex)).toEqual([' content']);
expect('<test content></test>'.match(regex)).to.deep.equal([' content']);
});
it('should match all tags', function () {
expect('<test content1></test> <test content2></test>'.match(regex)).toEqual([' content1', ' content2']);
expect('<test content1></test> <test content2></test>'.match(regex)).to.deep.equal([
' content1',
' content2',
]);
});
it('should not match wrong tags', function () {
expect('<no content></no>'.match(regex)).toEqual(null);
expect('<no content></no>'.match(regex)).to.deep.equal(null);
});
it('should accept valid html whitespaces', function () {
@@ -39,7 +44,7 @@ describe('matchTagProperties', function () {
</test
>
`.match(regex),
).toEqual(['\n content\n ']);
).to.deep.equal(['\n content\n ']);
});
});
@@ -47,15 +52,15 @@ describe('matchPropertyContent', function () {
const regex = matchPropertyContent(['test1', 'test2']);
it('should match bare literals', function () {
expect(`test1="content" test2="content1"`.match(regex)).toEqual(['content', 'content1']);
expect(`test1="content" test2="content1"`.match(regex)).to.deep.equal(['content', 'content1']);
});
it('should match angular literals', function () {
expect(`[test1]="'content'" [test2]="'content1'"`.match(regex)).toEqual(['content', 'content1']);
expect(`[test1]="'content'" [test2]="'content1'"`.match(regex)).to.deep.equal(['content', 'content1']);
});
it('should not match wrong literals', function () {
expect(`no="content" [no]="'content'"`.match(regex)).toEqual(null);
expect(`no="content" [no]="'content'"`.match(regex)).to.deep.equal(null);
});
});
@@ -65,23 +70,23 @@ describe('matchPropertyAccess', function () {
const regex = matchPropertyAccess(object);
it('should match property access', function () {
expect(`${object}.${property}`.match(regex)).toEqual([property]);
expect(`${object}.${property}`.match(regex)).to.deep.equal([property]);
});
it('should respect whitespace', function () {
expect(`${object}. ${property}`.match(regex)).toEqual([property]);
expect(`${object} .${property}`.match(regex)).toEqual([property]);
expect(`${object} . ${property}`.match(regex)).toEqual([property]);
expect(`${object} \n . \n ${property}`.match(regex)).toEqual([property]);
expect(`${object}. ${property}`.match(regex)).to.deep.equal([property]);
expect(`${object} .${property}`.match(regex)).to.deep.equal([property]);
expect(`${object} . ${property}`.match(regex)).to.deep.equal([property]);
expect(`${object} \n . \n ${property}`.match(regex)).to.deep.equal([property]);
});
it('should not include invalid trailing stuff', function () {
expect(`${object}.${property}!`.match(regex)).toEqual([property]);
expect(`${object}.${property}.`.match(regex)).toEqual([property]);
expect(`${object}.${property}-`.match(regex)).toEqual([property]);
expect(`${object}.${property}]`.match(regex)).toEqual([property]);
expect(`${object}.${property}}`.match(regex)).toEqual([property]);
expect(`${object}.${property};`.match(regex)).toEqual([property]);
expect(`${object}.${property}:`.match(regex)).toEqual([property]);
expect(`${object}.${property}!`.match(regex)).to.deep.equal([property]);
expect(`${object}.${property}.`.match(regex)).to.deep.equal([property]);
expect(`${object}.${property}-`.match(regex)).to.deep.equal([property]);
expect(`${object}.${property}]`.match(regex)).to.deep.equal([property]);
expect(`${object}.${property}}`.match(regex)).to.deep.equal([property]);
expect(`${object}.${property};`.match(regex)).to.deep.equal([property]);
expect(`${object}.${property}:`.match(regex)).to.deep.equal([property]);
});
});

View File

@@ -13,25 +13,16 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @param {string} tag
*/
export function matchTagProperties(tag) {
export function matchTagProperties(tag: string) {
return new RegExp(`(?<=<${tag})[\\s\\S]*?(?=>\\s*<\\/${tag}\\s*>)`, 'g');
}
/**
* @param {string[]} properties
*/
export function matchPropertyContent(properties) {
export function matchPropertyContent(properties: string[]) {
const names = properties.join('|');
return new RegExp(`((?<=(${names})=")[\\w-]+(?="))|((?<=\\[(${names})]="')[\\w-]+(?='"))`, 'g');
}
/**
* @param {string} objectName
*/
export function matchPropertyAccess(objectName) {
export function matchPropertyAccess(objectName: string) {
return new RegExp(`(?<=${objectName}\\s*\\.\\s*)\\w+`, 'g');
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 StApps
* Copyright (C) 2024 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.
@@ -20,3 +20,9 @@ export interface IconConfig {
outputPath: string;
additionalIcons?: {[purpose: string]: string[]};
}
export function defineIconConfig(config: IconConfig): IconConfig {
return config;
}
export * from './icons/icon-match.js';

View File

View File

View File

@@ -0,0 +1,20 @@
import {BuilderContext, BuilderOutput} from '@angular-devkit/architect';
import {checkIconCorrectness} from './icons/check-icon-correctness.js';
import {getIconConfig} from './icons/icon-config.js';
export async function runPrebuild(context: BuilderContext): Promise<void | BuilderOutput> {
context.reportStatus('Checking icons');
if (!process.env.SKIP_ICON_CHECK) {
const iconConfig = await getIconConfig();
try {
await checkIconCorrectness(iconConfig);
} catch (error) {
return {
success: false,
error:
(error as Error).message + '\n\nTo skip this check, set the environment variable SKIP_ICON_CHECK=1',
};
}
}
context.reportStatus('✔ Icons are correct.');
}

View File

@@ -0,0 +1,4 @@
{
"extends": "@openstapps/tsconfig",
"exclude": ["lib", "app.js"]
}

View File

@@ -17,10 +17,8 @@ import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
import {TypeFlags} from 'typescript';
// @ts-expect-error unused type
type TestTypeAlias = number | string;
// @ts-expect-error unused type
enum TestEnum {
Foo,
Bar,

View File

@@ -18,13 +18,9 @@ import {LightweightDefinitionKind} from '../../src/index.js';
interface Random {}
// @ts-expect-error unused type
type TestArrayGeneric = Array<string>;
// @ts-expect-error unused type
type TestArrayLiteral = number[];
// @ts-expect-error unused type
type TestArrayReferenceGeneric = Array<Random>;
// @ts-expect-error unused type
type TestArrayReferenceLiteral = Random[];
export const testConfig: EasyAstSpecType = {

View File

@@ -16,12 +16,10 @@
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
// @ts-expect-error unused type
interface TestInterface {
foo: number;
}
// @ts-expect-error unused type
class TestClass {
bar: string = 'test';
}

View File

@@ -22,10 +22,8 @@ import {LightweightDefinitionKind} from '../../src/index.js';
* Class description
*
* More description
*
* @classTag classParameter1 classParameter2
*/
// @ts-expect-error unused type
interface TestInterface {
/**
* Property comment
@@ -33,7 +31,6 @@ interface TestInterface {
* Property description
*
* More description
*
* @propertyTag propertyParameter1 propertyParameter2
*/
foo: string;
@@ -45,10 +42,8 @@ interface TestInterface {
* Class description
*
* More description
*
* @classTag classParameter1 classParameter2
*/
// @ts-expect-error unused type
class TestClass {
/**
* Property comment
@@ -56,7 +51,6 @@ class TestClass {
* Property description
*
* More description
*
* @propertyTag propertyParameter1 propertyParameter2
*/
foo = 1;
@@ -68,10 +62,8 @@ class TestClass {
* Enum description
*
* More description
*
* @enumTag enumParameter1
*/
// @ts-expect-error unused type
enum TestAlias {}
export const testConfig: EasyAstSpecType = {

View File

@@ -20,7 +20,6 @@ interface Test1<T = number> {
foo: T;
}
// @ts-expect-error unused type
interface Test2 {
bar: Test1;
}

View File

@@ -17,13 +17,11 @@ import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
import {TypeFlags} from 'typescript';
// @ts-expect-error unused type
enum TestAuto {
Foo,
Bar,
}
// @ts-expect-error unused type
enum TestSpecified {
YES = 'yes',
NO = 'no',

View File

@@ -18,7 +18,6 @@ import {LightweightDefinitionKind} from '../../src/index.js';
interface $Random {}
// @ts-expect-error unused type
interface Generics {
baz: Foo<number, $Random>;
}

View File

@@ -18,12 +18,10 @@ import {LightweightDefinitionKind} from '../../src/index.js';
interface $Random {}
// @ts-expect-error unused
interface IndexSignatureObject {
[key: string]: $Random;
}
// @ts-expect-error unused
interface IndexSignaturePrimitive {
[key: string]: number;
}

View File

@@ -26,7 +26,6 @@ interface $BaseInterface2 {
class $BaseClass {}
// @ts-expect-error unused
class InheritingClass extends $BaseClass implements $BaseInterface<number>, $BaseInterface2 {
bar: string = '';

View File

@@ -16,7 +16,6 @@
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
// @ts-expect-error unused
interface NestedObject {
nested: {
deeplyNested: {

View File

@@ -17,7 +17,6 @@ import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
import {TypeFlags} from 'typescript';
// @ts-expect-error unused
interface Test {
number_type: number;
string_type: string;

View File

@@ -16,7 +16,6 @@
import {EasyAstSpecType} from '../easy-ast-spec-type.js';
import {LightweightDefinitionKind} from '../../src/index.js';
// @ts-expect-error unused
interface Foo<T extends Bar<string>> {
bar: T;
}

1135
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff