diff --git a/scripts/generateLayouts.ts b/scripts/generateLayouts.ts index adf069f5b..c3fafbc96 100644 --- a/scripts/generateLayouts.ts +++ b/scripts/generateLayouts.ts @@ -36,6 +36,7 @@ class GenerateLayouts extends Script { private previousSrc: Set = new Set() private eliUrlsCached: string[] private date = new Date().toISOString() + private branchName: string = undefined constructor() { super("Generates an '.html' and 'index_.ts' for every theme") @@ -45,6 +46,27 @@ class GenerateLayouts extends Script { return encodeURIComponent(str.toLowerCase()) } + getBranchName(): Promise { + if (this.branchName) { + return Promise.resolve(this.branchName) + } + const { exec } = require("child_process") + return new Promise((resolve, reject) => { + exec("git rev-parse --abbrev-ref HEAD", (err, stdout, stderr) => { + if (err) { + reject(err) + return + } + + if (typeof stdout === "string") { + this.branchName = stdout.trim() + resolve(stdout.trim()) + } + reject("Did not get output") + }) + }) + } + async createIcon(iconPath: string, size: number, alreadyWritten: string[]) { let name = iconPath.split(".").slice(0, -1).join(".") // drop svg suffix if (name.startsWith("./")) { @@ -466,6 +488,13 @@ class GenerateLayouts extends Script { ...apple_icons, ].join("\n") + let branchname = await this.getBranchName() + if (branchname === "master" || branchname === "main") { + branchname = "" + } else { + branchname = "
" + branchname + "
" + } + const loadingText = Translations.t.general.loadingTheme.Subs({ theme: layout.title }) // const templateLines: string[] = this.template.split("\n").slice(1) // Slice to remove the 'export {}'-line @@ -488,7 +517,7 @@ class GenerateLayouts extends Script { ) .replace( /.*/s, - "" + "" ) .replace( /.*\/src\/index\.ts.*/, @@ -499,7 +528,10 @@ class GenerateLayouts extends Script { /\n.*RemoveOtherLanguages.*\n/i, "\n\n" ) - .replace("Version", `${Constants.vNumber}
${this.date}
`) + .replace( + "Version", + `${Constants.vNumber}
${this.date}
${branchname}` + ) } async createIndexFor(theme: LayoutConfig) {