From 0c1568b38dfd655905da790d3a9e9a7ec7b5ee4d Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Sat, 30 Apr 2022 23:30:56 -0400 Subject: [PATCH] Renamed postbuild.mjs to postbuild.js --- package.json | 2 +- src/postbuild.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/postbuild.js diff --git a/package.json b/package.json index 43dd6cb..990a4d0 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "ng": "ng", "start": "ng serve", "build": "ng build --configuration production", - "prebuild": "node src/postbuild.mjs", + "prebuild": "node src/postbuild.js", "heroku-postbuild": "npm install --prefix backend", "test": "ng test", "lint": "ng lint", diff --git a/src/postbuild.js b/src/postbuild.js new file mode 100644 index 0000000..13be157 --- /dev/null +++ b/src/postbuild.js @@ -0,0 +1,43 @@ +const fs = require('fs-extra'); +const path = require('path'); +const xliffToJSON = require('xliff-to-json'); + +async function recFindByExt(base,ext,files,result) +{ + files = files || (await fs.readdir(base)) + result = result || [] + + for (const file of files) { + var newbase = path.join(base,file) + if ( (await fs.stat(newbase)).isDirectory() ) + { + result = await recFindByExt(newbase,ext,await fs.readdir(newbase),result) + } + else + { + if ( file.substr(-1*(ext.length+1)) == '.' + ext ) + { + result.push(newbase) + } + } + } + return result +} + +// outputs array of supported locales +async function createLocalizationJSON() { + xliffToJSON.convert('src/assets/i18n'); + const files = await recFindByExt(path.join('src', 'assets', 'i18n'), 'json'); + const locales = []; + + for (let i = 0; i < files.length; i++) { + const file = path.basename(files[i]); + const file_parts = file.split('.'); + locales.push(file_parts[1]); + } + + fs.unlinkSync('src/assets/i18n/messages.en.json'); + fs.writeJSONSync('src/assets/i18n/supported_locales.json', {supported_locales: locales}); +} + +createLocalizationJSON(); \ No newline at end of file