Refactoring: change order of parameters and remove parameter for Conversion.ts

This commit is contained in:
Pieter Vander Vennet 2025-05-16 15:48:55 +02:00
parent 49fc8e4bcf
commit 72e06448fc
20 changed files with 147 additions and 213 deletions

View file

@ -5,32 +5,26 @@ import { QuestionableTagRenderingConfigJson } from "../src/Models/ThemeConfig/Js
import * as fakedom from "fake-dom"
import Script from "./Script"
import { FixedUiElement } from "../src/UI/Base/FixedUiElement"
import { ConversionContext } from "../src/Models/ThemeConfig/Conversion/ConversionContext"
class ExtractQuestionHint extends DesugaringStep<QuestionableTagRenderingConfigJson> {
constructor() {
super(
"ExtractQuestionHint",
"Tries to extract a 'questionHint' from the question",
["question", "questionhint"],
"ExtractQuestionHint"
)
}
convert(
json: QuestionableTagRenderingConfigJson,
context: string
): {
result: QuestionableTagRenderingConfigJson
errors?: string[]
warnings?: string[]
information?: string[]
} {
json: QuestionableTagRenderingConfigJson
): QuestionableTagRenderingConfigJson {
json = { ...json }
if (json.question === undefined || json.questionHint !== undefined) {
return { result: json }
return json
}
if (typeof json.question === "string") {
return { result: json }
return json
}
const hint: Record<string, string> = {}
@ -64,12 +58,11 @@ class ExtractQuestionHint extends DesugaringStep<QuestionableTagRenderingConfigJ
console.log("Inspecting ", json.question)
return { result: json }
return json
}
}
class FixQuestionHint extends Script {
private fs: any
constructor() {
super("Extracts a 'questionHint' from a question for a given 'layer.json' or 'theme.json'")
if (fakedom === undefined) {
@ -89,7 +82,9 @@ class FixQuestionHint extends Script {
}
contents[key] = convertor.convertStrict(
tr,
"While automatically extracting questiondHints of " + filepath
ConversionContext.construct([],
["While automatically extracting questiondHints of " + filepath]
)
)
}
fs.writeFileSync(filepath, JSON.stringify(contents, null, " "), { encoding: "utf-8" })
@ -105,7 +100,9 @@ class FixQuestionHint extends Script {
}
layer.tagRenderings[i] = convertor.convertStrict(
<QuestionableTagRenderingConfigJson>tagRendering,
ConversionContext.construct([], [
"While automatically extracting questionHints of " + filepath
])
)
}
}

View file

@ -9,16 +9,12 @@ import {
DoesImageExist,
PrevalidateTheme,
ValidateLayer,
ValidateThemeEnsemble,
ValidateThemeEnsemble
} from "../src/Models/ThemeConfig/Conversion/Validation"
import { Translation } from "../src/UI/i18n/Translation"
import { PrepareLayer } from "../src/Models/ThemeConfig/Conversion/PrepareLayer"
import { PrepareTheme } from "../src/Models/ThemeConfig/Conversion/PrepareTheme"
import {
Conversion,
DesugaringContext,
DesugaringStep,
} from "../src/Models/ThemeConfig/Conversion/Conversion"
import { Conversion, DesugaringContext, DesugaringStep } from "../src/Models/ThemeConfig/Conversion/Conversion"
import { Utils } from "../src/Utils"
import Script from "./Script"
import { AllSharedLayers } from "../src/Customizations/AllSharedLayers"
@ -35,10 +31,7 @@ import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable"
import { ValidateThemeAndLayers } from "../src/Models/ThemeConfig/Conversion/ValidateThemeAndLayers"
import { ExtractImages } from "../src/Models/ThemeConfig/Conversion/FixImages"
import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson"
import {
LayerConfigDependencyGraph,
LevelInfo,
} from "../src/Models/ThemeConfig/LayerConfigDependencyGraph"
import { LayerConfigDependencyGraph, LevelInfo } from "../src/Models/ThemeConfig/LayerConfigDependencyGraph"
// This scripts scans 'src/assets/layers/*.json' for layer definition files and 'src/assets/themes/*.json' for theme definition files.
// It spits out an overview of those to be used to load them
@ -54,7 +47,7 @@ class ParseLayer extends Conversion<
private readonly _doesImageExist: DoesImageExist
constructor(prepareLayer: PrepareLayer, doesImageExist: DoesImageExist) {
super("Parsed a layer from file, validates it", [], "ParseLayer")
super("ParseLayer", "Parsed a layer from file, validates it", [])
this._prepareLayer = prepareLayer
this._doesImageExist = doesImageExist
}
@ -158,7 +151,7 @@ class LayerBuilder extends Conversion<object, Map<string, LayerConfigJson>> {
states: Map<string, "clean" | "dirty" | "changed">,
sharedTagRenderings: QuestionableTagRenderingConfigJson[]
) {
super("Builds all the layers, writes them to file", [], "LayerBuilder")
super("LayerBuilder", "Builds all the layers, writes them to file", [])
this._levels = levels
this._dependencies = dependencies
this._states = states