Fix tests

This commit is contained in:
Pieter Vander Vennet 2024-07-17 16:57:37 +02:00
parent e9d18d2337
commit 39376c0012

View file

@ -54,6 +54,20 @@ export class ExtractImages extends Conversion<
)
}
static isImageType(metapath: any): boolean {
if (metapath.hints.typehint === "icon" ||
metapath.hints.typehint === "image") {
return true
}
const types = metapath.hints.types?.split(";").map(x => x.trim())
if (types?.some(t => t === "icon" || t === "image")) {
return true
}
return false
}
/**
* const images = new ExtractImages(true, new Set<string>()).convert(<any>{
* "layers": [
@ -102,9 +116,14 @@ export class ExtractImages extends Conversion<
const allFoundImages: { path: string; context: string }[] = []
for (const metapath of ExtractImages.layoutMetaPaths) {
const mightBeTr = ExtractImages.mightBeTagRendering(<any>metapath)
const allRenderedValuesAreImages =
metapath.hints.typehint === "icon" || metapath.hints.typehint === "image"
const allRenderedValuesAreImages = ExtractImages.isImageType(metapath)
const found = Utils.CollectPath(metapath.path, json)
if(found.length === 0){
continue
}
if (mightBeTr) {
// We might have tagRenderingConfigs containing icons here
for (const el of found) {
@ -134,9 +153,9 @@ export class ExtractImages extends Conversion<
// Inspect all the rendered values
const fromPath = Utils.CollectPath(trpath.path, foundImage)
const isRendered = trpath.hints.typehint === "rendered"
const isImage =
trpath.hints.typehint === "icon" ||
trpath.hints.typehint === "image"
const isImage = ExtractImages.isImageType(trpath)
for (const img of fromPath) {
if (allRenderedValuesAreImages && isRendered) {
// What we found is an image
@ -158,7 +177,7 @@ export class ExtractImages extends Conversion<
} else {
allFoundImages.push({
path: img.leaf,
context: context + "." + path,
context: context + "." + path
})
}
}
@ -172,7 +191,7 @@ export class ExtractImages extends Conversion<
.ExtractImages(false)
.map((path) => ({
path,
context: context + "." + path,
context: context + "." + path
}))
)
}
@ -192,7 +211,7 @@ export class ExtractImages extends Conversion<
}
allFoundImages.push({
context: context.path.join(".") + "." + foundElement.path.join("."),
path: foundElement.leaf,
path: foundElement.leaf
})
}
}
@ -283,7 +302,6 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
const absolute = url.protocol + "//" + url.host
let relative = url.protocol + "//" + url.host + url.pathname
relative = relative.substring(0, relative.lastIndexOf("/"))
const self = this
if (relative.endsWith("assets/generated/themes")) {
context.warn(
@ -292,8 +310,10 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
relative = absolute
}
const knownImages = this._knownImages
function replaceString(leaf: string) {
if (self._knownImages.has(leaf)) {
if (knownImages.has(leaf)) {
return leaf
}
@ -316,7 +336,7 @@ export class FixImages extends DesugaringStep<LayoutConfigJson> {
json = Utils.Clone(json)
for (const metapath of metapaths) {
if (metapath.hints.typehint !== "image" && metapath.hints.typehint !== "icon") {
if (!ExtractImages.isImageType(metapath)) {
continue
}
const mightBeTr = ExtractImages.mightBeTagRendering(<any>metapath)