Add logging

This commit is contained in:
RMidhunSuresh 2022-07-17 20:58:58 +05:30
parent ce5db47708
commit 9e2d355573
2 changed files with 55 additions and 49 deletions

View File

@ -19,6 +19,7 @@ import {ColorSchemePreference} from "./ThemeLoader";
import {IconColorizer} from "./IconColorizer";
import {DerivedVariables} from "./DerivedVariables";
import {ThemeManifest} from "../types/theme";
import {ILogItem} from "../../logging/types";
export class ThemeBuilder {
private _idToManifest: Map<string, {manifest: ThemeManifest, location: string}>;
@ -33,9 +34,10 @@ export class ThemeBuilder {
this._platform = platform;
}
async populateDerivedTheme(manifest: ThemeManifest) {
const { manifest: baseManifest, location } = this._idToManifest.get(manifest.extends!)!;
const { cssLocation, derivedVariables, icons } = this._getsourceData(baseManifest, location);
async populateDerivedTheme(manifest: ThemeManifest, log: ILogItem) {
await log.wrap("ThemeBuilder.populateThemeMap", async (l) => {
const {manifest: baseManifest, location} = this._idToManifest.get(manifest.extends!)!;
const {cssLocation, derivedVariables, icons} = this._getSourceData(baseManifest, location, log);
const themeName = manifest.name;
if (!themeName) {
throw new Error(`Theme name not found in manifest!`);
@ -70,9 +72,11 @@ export class ThemeBuilder {
const variant = defaultDarkVariant.id ? defaultDarkVariant : defaultLightVariant;
this._themeMapping[`${themeName} ${variant.variantName}`] = { id: variant.id, cssLocation: variant.cssLocation };
}
});
}
private _getsourceData(manifest: ThemeManifest, location: string) {
private _getSourceData(manifest: ThemeManifest, location: string, log:ILogItem) {
return log.wrap("getSourceData", () => {
const runtimeCSSLocation = manifest.source?.["runtime-asset"];
if (!runtimeCSSLocation) {
throw new Error(`Run-time asset not found in source section for theme at ${location}`);
@ -87,6 +91,7 @@ export class ThemeBuilder {
throw new Error(`Icon mapping not found in source section for theme at ${location}`);
}
return { cssLocation, derivedVariables, icons };
});
}
get themeMapping() {

View File

@ -64,7 +64,7 @@ export class ThemeLoader {
const { body } = results[i];
try {
if (body.extends) {
await this._themeBuilder.populateDerivedTheme(body);
await this._themeBuilder.populateDerivedTheme(body, log);
}
else {
this._populateThemeMap(body, manifestLocations[i], log);
@ -183,6 +183,7 @@ export class ThemeLoader {
}
this._platform.replaceStylesheet(cssLocation);
if (variables) {
log?.log({l: "Derived Theme", variables});
this._themeBuilder.injectCSSVariables(variables);
}
else {