Regenerate schemas, more fixes to images and licenses

This commit is contained in:
Pieter Vander Vennet 2022-02-18 23:10:27 +01:00
parent 5ab2e8eabe
commit 682b68a094
34 changed files with 1298 additions and 118 deletions

View file

@ -6,9 +6,11 @@ import * as tagrenderingmetapaths from "../../../assets/tagrenderingconfigmeta.j
export class ExtractImages extends Conversion<LayoutConfigJson, string[]> {
private _isOfficial: boolean;
constructor(isOfficial: boolean) {
private _sharedTagRenderings: Map<string, any>;
constructor(isOfficial: boolean, sharedTagRenderings: Map<string, any>) {
super("Extract all images from a layoutConfig using the meta paths",[],"ExctractImages");
this._isOfficial = isOfficial;
this._sharedTagRenderings = sharedTagRenderings;
}
convert(json: LayoutConfigJson, context: string): { result: string[], errors: string[], warnings: string[] } {
@ -29,8 +31,19 @@ export class ExtractImages extends Conversion<LayoutConfigJson, string[]> {
const found = Utils.CollectPath(metapath.path, json)
if (mightBeTr) {
// We might have tagRenderingConfigs containing icons here
for (const foundImage of found) {
for (const {path, leaf} of found) {
const foundImage = leaf;
if (typeof foundImage === "string") {
if(foundImage == ""){
errors.push(context+"."+path.join(".")+" Found an empty image")
}
if(this._sharedTagRenderings?.has(foundImage)){
// This is not an image, but a shared tag rendering
continue
}
allFoundImages.push(foundImage)
} else{
// This is a tagRendering where every rendered value might be an icon!
@ -45,6 +58,11 @@ export class ExtractImages extends Conversion<LayoutConfigJson, string[]> {
}
}
allFoundImages.push(...fromPath.filter(i => typeof i === "string"))
for (const pathAndImg of fromPath) {
if(pathAndImg.leaf === "" || pathAndImg.leaf["path"] == ""){
errors.push(context+[...path,...pathAndImg.path].join(".")+": Found an empty image at ")
}
}
}
}
@ -108,7 +126,7 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
continue
}
const mightBeTr = Array.isArray(metapath.type) && metapath.type.some(t => t["$ref"] == "#/definitions/TagRenderingConfigJson")
Utils.WalkPath(metapath.path, json, leaf => {
Utils.WalkPath(metapath.path, json, (leaf, path) => {
if (typeof leaf === "string") {
return replaceString(leaf)
}

View file

@ -75,14 +75,14 @@ class ExpandTagRendering extends Conversion<string | TagRenderingConfigJson | {
if (typeof tr === "string") {
const lookup = this.lookup(tr);
if (lookup !== undefined) {
return lookup
if (lookup === undefined) {
warnings.push(ctx + "A literal rendering was detected: " + tr)
return [{
render: tr,
id: tr.replace(/![a-zA-Z0-9]/g, "")
}]
}
warnings.push(ctx + "A literal rendering was detected: " + tr)
return [{
render: tr,
id: tr.replace(/![a-zA-Z0-9]/g, "")
}]
return lookup
}
if (tr["builtin"] !== undefined) {
@ -122,7 +122,7 @@ class ExpandTagRendering extends Conversion<string | TagRenderingConfigJson | {
const result = []
for (const tr of trs) {
if (tr["builtin"] !== undefined) {
if (typeof tr === "string" || tr["builtin"] !== undefined) {
const stable = this.convertUntilStable(tr, warnings, errors, ctx + "(RECURSIVE RESOLVE)")
result.push(...stable)
} else {

View file

@ -432,8 +432,12 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
new PreparePersonalTheme(state),
new OnEveryConcat("layers", new SubstituteLayer(state)),
new SetDefault("socialImage", "assets/SocialImage.png", true),
// We expand all tagrenderings first...
new OnEvery("layers", new PrepareLayer(state)),
// Then we apply the override all
new ApplyOverrideAll(),
// And then we prepare all the layers _again_ in case that an override all contained unexpanded tagrenderings!
new OnEvery("layers", new PrepareLayer(state)),
new AddDefaultLayers(state),
new AddDependencyLayersToTheme(state),
new AddImportLayers(),

View file

@ -12,6 +12,7 @@ import {ExtractImages} from "./FixImages";
import ScriptUtils from "../../../scripts/ScriptUtils";
import {And} from "../../../Logic/Tags/And";
import Translations from "../../../UI/i18n/Translations";
import Svg from "../../../Svg";
class ValidateLanguageCompleteness extends DesugaringStep<any> {
@ -50,12 +51,14 @@ class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
private readonly _path?: string;
private readonly knownImagePaths: Set<string>;
private readonly _isBuiltin: boolean;
private _sharedTagRenderings: Map<string, any>;
constructor(knownImagePaths: Set<string>, path: string, isBuiltin: boolean) {
constructor(knownImagePaths: Set<string>, path: string, isBuiltin: boolean, sharedTagRenderings: Map<string, any>) {
super("Doesn't change anything, but emits warnings and errors", [], "ValidateTheme");
this.knownImagePaths = knownImagePaths;
this._path = path;
this._isBuiltin = isBuiltin;
this._sharedTagRenderings = sharedTagRenderings;
}
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[], warnings: string[], information: string[] } {
@ -78,7 +81,7 @@ class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
}
{
// Check images: are they local, are the licenses there, is the theme icon square, ...
const images = new ExtractImages(this._isBuiltin).convertStrict(json, "validation")
const images = new ExtractImages(this._isBuiltin, this._sharedTagRenderings).convertStrict(json, "validation")
const remoteImages = images.filter(img => img.indexOf("http") == 0)
for (const remoteImage of remoteImages) {
errors.push("Found a remote image: " + remoteImage + " in theme " + json.id + ", please download it.")
@ -93,8 +96,11 @@ class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
continue
}
if (image.match(/[a-z]*/)) {
// This is a builtin img, e.g. 'checkmark' or 'crosshair'
continue;
if(Svg.All[image + ".svg"] !== undefined){
// This is a builtin img, e.g. 'checkmark' or 'crosshair'
continue;
}
}
if (this.knownImagePaths !== undefined && !this.knownImagePaths.has(image)) {
@ -163,10 +169,10 @@ class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
}
export class ValidateThemeAndLayers extends Fuse<LayoutConfigJson> {
constructor(knownImagePaths: Set<string>, path: string, isBuiltin: boolean) {
constructor(knownImagePaths: Set<string>, path: string, isBuiltin: boolean, sharedTagRenderings: Map<string, any>) {
super("Validates a theme and the contained layers",
new ValidateTheme(knownImagePaths, path, isBuiltin),
new OnEvery("layers", new ValidateLayer(knownImagePaths, undefined, false))
new ValidateTheme(knownImagePaths, path, isBuiltin, sharedTagRenderings),
new OnEvery("layers", new ValidateLayer(undefined, false))
);
}
}
@ -302,12 +308,10 @@ export class ValidateLayer extends DesugaringStep<LayerConfigJson> {
* @private
*/
private readonly _path?: string;
private readonly knownImagePaths?: Set<string>;
private readonly _isBuiltin: boolean;
constructor(knownImagePaths: Set<string>, path: string, isBuiltin: boolean) {
constructor(path: string, isBuiltin: boolean) {
super("Doesn't change anything, but emits warnings and errors", [], "ValidateLayer");
this.knownImagePaths = knownImagePaths;
this._path = path;
this._isBuiltin = isBuiltin;
}

View file

@ -71,7 +71,7 @@ export default class LayoutConfig {
this.credits = json.credits;
this.version = json.version;
this.language = json.mustHaveLanguage ?? Array.from(Object.keys(json.title));
this.usedImages = Array.from(new ExtractImages(official).convertStrict(json, "while extracting the images of " + json.id + " " + context ?? "")).sort()
this.usedImages = Array.from(new ExtractImages(official, undefined).convertStrict(json, "while extracting the images of " + json.id + " " + context ?? "")).sort()
{
if (typeof json.title === "string") {
throw `The title of a theme should always be a translation, as it sets the corresponding languages (${context}.title). The themenID is ${this.id}; the offending object is ${JSON.stringify(json.title)} which is a ${typeof json.title})`