Chore: Fix build

This commit is contained in:
Pieter Vander Vennet 2024-09-15 00:57:38 +02:00
parent bf38d09032
commit 114f484faf
4 changed files with 93 additions and 42 deletions

View file

@ -94,19 +94,28 @@ export default class ScriptUtils {
})
}
public static getThemePaths(): string[] {
const blacklist = ["assets/themes/mapcomplete-changes/mapcomplete-changes.json"]
public static getThemePaths(useTranslationPaths = false): string[] {
const normalFiles = ScriptUtils.readDirRecSync("./assets/themes")
.filter((path) => path.endsWith(".json") && !path.endsWith(".proto.json"))
.filter((path) => path.indexOf("license_info.json") < 0)
.filter(path => !blacklist.some(black => path.endsWith(black)))
if (!useTranslationPaths) {
return normalFiles
}
const specialfiles = ["./assets/themes/mapcomplete-changes/mapcomplete-changes.proto.json"]
return normalFiles.concat(specialfiles)
const blacklist = ["assets/themes/mapcomplete-changes/mapcomplete-changes.json"]
const filtered = normalFiles.filter(path => !blacklist.some(black => path.endsWith(black)))
return filtered.concat(specialfiles)
}
public static getThemeFiles(): { parsed: LayoutConfigJson; path: string; raw: string }[] {
return this.getThemePaths().map((path) => {
public static getThemeFiles(useTranslationPaths = false): {
parsed: LayoutConfigJson;
path: string;
raw: string
}[] {
return this.getThemePaths(useTranslationPaths).map((path) => {
try {
const contents = readFileSync(path, { encoding: "utf8" })
if (contents === "") {
@ -153,6 +162,7 @@ export default class ScriptUtils {
const data = await ScriptUtils.Download(url, headers)
return JSON.parse(data["content"])
}
public static async DownloadFetch(
url: string,
headers?: any
@ -163,6 +173,7 @@ export default class ScriptUtils {
console.log("Fetched", url, data)
return { content: data }
}
public static Download(
url: string,
headers?: any
@ -198,17 +209,17 @@ export default class ScriptUtils {
path: urlObj.pathname + urlObj.search,
port: urlObj.port,
headers: headers,
headers: headers
},
(res) => {
const parts: string[] = []
res.setEncoding("utf8")
res.on("data", function (chunk) {
res.on("data", function(chunk) {
// @ts-ignore
parts.push(chunk)
})
res.addListener("end", function () {
res.addListener("end", function() {
if (res.statusCode === 301 || res.statusCode === 302) {
console.log("Got a redirect:", res.headers.location)
resolve({ redirect: res.headers.location })
@ -226,7 +237,7 @@ export default class ScriptUtils {
})
}
)
request.on("error", function (e) {
request.on("error", function(e) {
reject(e)
})
} catch (e) {

View file

@ -670,7 +670,7 @@ function removeNonEnglishTranslations(object: any) {
* Load the translations into the theme files
*/
function mergeThemeTranslations(englishOnly: boolean = false) {
const themeFiles = ScriptUtils.getThemeFiles()
const themeFiles = ScriptUtils.getThemeFiles(true)
for (const themeFile of themeFiles) {
let config = themeFile.parsed
mergeLayerTranslation(config, themeFile.path, loadTranslationFilesFrom("themes"))
@ -723,7 +723,7 @@ class GenerateTranslations extends Script {
{
const l1 = generateTranslationsObjectFrom(ScriptUtils.getLayerFiles(), "layers")
const l2 = generateTranslationsObjectFrom(
ScriptUtils.getThemeFiles().filter(
ScriptUtils.getThemeFiles(true).filter(
(th) => th.parsed.mustHaveLanguage === undefined
),
"themes"