diff --git a/package.json b/package.json index 3b68cd0f..00705ed1 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "_format": "prettier '**/*.{ts,tsx,json,md}'", "format": "yarn _format --write", "format:check": "yarn _format --list-different", - "generate-messages": "ts-node --skipProject scripts/generate-i18n-messages.ts", + "generate-i18n-messages": "ts-node --skipProject scripts/generate-i18n-messages.ts", "link-in-app": "ts-node --skipProject scripts/link-in-app.ts", "link-in-starter": "yarn link-in-app keycloakify-starter", "tsc-watch": "tsc -p src/bin -w & tsc -p src/lib -w " diff --git a/scripts/generate-i18n-messages.ts b/scripts/generate-i18n-messages.ts index 3e8aec01..6334f775 100644 --- a/scripts/generate-i18n-messages.ts +++ b/scripts/generate-i18n-messages.ts @@ -16,71 +16,73 @@ const propertiesParser = require("properties-parser"); const { isSilent } = getCliOptions(process.argv.slice(2)); const logger = getLogger({ isSilent }); -for (const keycloakVersion of ["11.0.3", "15.0.2", "18.0.1"]) { - logger.log(JSON.stringify({ keycloakVersion })); +(async () => { + for (const keycloakVersion of ["11.0.3", "15.0.2", "18.0.1", "21.0.1"]) { + logger.log(JSON.stringify({ keycloakVersion })); - const tmpDirPath = pathJoin(getProjectRoot(), "tmp_xImOef9dOd44"); + const tmpDirPath = pathJoin(getProjectRoot(), "tmp_xImOef9dOd44"); - fs.rmSync(tmpDirPath, { "recursive": true, "force": true }); + fs.rmSync(tmpDirPath, { "recursive": true, "force": true }); - downloadBuiltinKeycloakTheme({ - keycloakVersion, - "destDirPath": tmpDirPath, - isSilent - }); + await downloadBuiltinKeycloakTheme({ + keycloakVersion, + "destDirPath": tmpDirPath, + isSilent + }); - type Dictionary = { [idiomId: string]: string }; + type Dictionary = { [idiomId: string]: string }; - const record: { [typeOfPage: string]: { [language: string]: Dictionary } } = {}; + const record: { [typeOfPage: string]: { [language: string]: Dictionary } } = {}; - { - const baseThemeDirPath = pathJoin(tmpDirPath, "base"); + { + const baseThemeDirPath = pathJoin(tmpDirPath, "base"); - crawl(baseThemeDirPath).forEach(filePath => { - const match = filePath.match(/^([^/]+)\/messages\/messages_([^.]+)\.properties$/); + crawl(baseThemeDirPath).forEach(filePath => { + const match = filePath.match(/^([^/]+)\/messages\/messages_([^.]+)\.properties$/); - if (match === null) { - return; - } + if (match === null) { + return; + } - const [, typeOfPage, language] = match; + const [, typeOfPage, language] = match; - (record[typeOfPage] ??= {})[language.replace(/_/g, "-")] = Object.fromEntries( - Object.entries(propertiesParser.parse(fs.readFileSync(pathJoin(baseThemeDirPath, filePath)).toString("utf8"))).map( - ([key, value]: any) => [key, value.replace(/''/g, "'")] - ) - ); + (record[typeOfPage] ??= {})[language.replace(/_/g, "-")] = Object.fromEntries( + Object.entries(propertiesParser.parse(fs.readFileSync(pathJoin(baseThemeDirPath, filePath)).toString("utf8"))).map( + ([key, value]: any) => [key, value.replace(/''/g, "'")] + ) + ); + }); + } + + fs.rmSync(tmpDirPath, { recursive: true, force: true }); + + Object.keys(record).forEach(pageType => { + const recordForPageType = record[pageType]; + + Object.keys(recordForPageType).forEach(language => { + const filePath = pathJoin(getProjectRoot(), "src", "lib", "i18n", "generated_messages", keycloakVersion, pageType, `${language}.ts`); + + fs.mkdirSync(pathDirname(filePath), { "recursive": true }); + + fs.writeFileSync( + filePath, + Buffer.from( + [ + `//This code was automatically generated by running ${pathRelative(getProjectRoot(), __filename)}`, + "//PLEASE DO NOT EDIT MANUALLY", + "", + "/* spell-checker: disable */", + `const messages= ${JSON.stringify(recordForPageType[language], null, 2)};`, + "", + "export default messages;", + "/* spell-checker: enable */" + ].join("\n"), + "utf8" + ) + ); + + logger.log(`${filePath} wrote`); + }); }); } - - fs.rmSync(tmpDirPath, { recursive: true, force: true }); - - Object.keys(record).forEach(pageType => { - const recordForPageType = record[pageType]; - - Object.keys(recordForPageType).forEach(language => { - const filePath = pathJoin(getProjectRoot(), "src", "lib", "i18n", "generated_messages", keycloakVersion, pageType, `${language}.ts`); - - fs.mkdirSync(pathDirname(filePath), { "recursive": true }); - - fs.writeFileSync( - filePath, - Buffer.from( - [ - `//This code was automatically generated by running ${pathRelative(getProjectRoot(), __filename)}`, - "//PLEASE DO NOT EDIT MANUALLY", - "", - "/* spell-checker: disable */", - `const messages= ${JSON.stringify(recordForPageType[language], null, 2)};`, - "", - "export default messages;", - "/* spell-checker: enable */" - ].join("\n"), - "utf8" - ) - ); - - logger.log(`${filePath} wrote`); - }); - }); -} +})(); diff --git a/src/bin/create-keycloak-email-directory.ts b/src/bin/create-keycloak-email-directory.ts index dfe70ae5..336dbe79 100644 --- a/src/bin/create-keycloak-email-directory.ts +++ b/src/bin/create-keycloak-email-directory.ts @@ -23,7 +23,7 @@ if (require.main === module) { const builtinKeycloakThemeTmpDirPath = pathJoin(keycloakThemeEmailDirPath, "..", "tmp_xIdP3_builtin_keycloak_theme"); - downloadBuiltinKeycloakTheme({ + await downloadBuiltinKeycloakTheme({ keycloakVersion, "destDirPath": builtinKeycloakThemeTmpDirPath, isSilent diff --git a/src/bin/tools/crc32.ts b/src/bin/tools/crc32.ts index c2211611..85f8f0bc 100644 --- a/src/bin/tools/crc32.ts +++ b/src/bin/tools/crc32.ts @@ -42,6 +42,7 @@ export function crc32(input: Readable | String | Buffer): Promise { } else if (input instanceof Readable) { return new Promise((resolve, reject) => { let crc = ~0; + input.setMaxListeners(Infinity); input.on("end", () => resolve((crc ^ -1) >>> 0)); input.on("error", e => reject(e)); input.on("data", (chunk: Buffer) => {