diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1b6191a..02f48ae 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,7 +59,7 @@ jobs: git commit -m "Release Ops" -a - name: Increase Version - run: npm version major + run: npm version patch - name: Push Updates uses: ad-m/github-push-action@master diff --git a/src/cli/i18n-msg/index.ts b/src/cli/i18n-msg/index.ts index 55bf47f..2bf9f73 100644 --- a/src/cli/i18n-msg/index.ts +++ b/src/cli/i18n-msg/index.ts @@ -5,6 +5,7 @@ import fs from "fs"; import path from "path"; import { EOL } from "os"; import config from "../../config"; +import { emitWarning } from "process"; export const CLI_NAME = "i18nMsg"; @@ -45,9 +46,9 @@ const AUTOGENERATED_HEADER = `// autogenerated with "i18n-msg" // // I/O files // +//const inputFile1 = path.join(process.cwd(),"./test/resources/prova/*"); const inputFile = path.join(process.cwd(), config.get(CLI_NAME).input); const mal = require(inputFile); // FIXME - const outMsgDir = path.join(process.cwd(), config.get(CLI_NAME).outMsg); const outTsFile = path.join(process.cwd(), config.get(CLI_NAME).outTs); const outTempDir = path.join(process.cwd(), config.get(CLI_NAME).outTemp); @@ -76,10 +77,12 @@ const writeObjJson = (filename: string, obj: object) => { } if (data) { - fs.writeFile(filename, data, (err) => { - if (err) console.log(err); + try { + fs.writeFileSync(filename, data); console.log(`Successfully written to file "${filename}"`); - }); + } catch (err) { + console.log(err); + } } }; @@ -95,10 +98,12 @@ const writeTs = (filename: string, messages: Message[]) => { return result + `export const ${tsName(msg.code)} = "${msg.code}";${EOL}`; }, AUTOGENERATED_HEADER); - fs.writeFile(filename, output, (err) => { - if (err) console.log(err); + try { + fs.writeFileSync(filename, output); console.log(`Successfully written to file "${filename}"`); - }); + } catch (err) { + console.log(err); + } }; const writeKeys = (key: string, translations: Translation[], output: OutputMessagesAllLangs) => { @@ -172,21 +177,89 @@ const writeNamespacesFile = (namespaces: MessagesNamespace[]) => { }); }; +const allLanguagesReport = (data: Message[], languages: string[])=>{ + data.forEach((value)=>{ + value.tr.forEach((i)=>{ + languages.push(i.l) + }) + if(value.overrides){ + value.overrides.forEach((i)=>{ + i.tr.forEach((v)=>{ + languages.push(v.l) + }) + }) + } + }) +} + +const report = (data: Message[], languages:string[])=>{ + data.forEach((value)=>{ + let valueLanguages: string[] = [] + let valueLanguagesOverrites: string[] = [] + value.tr.forEach((i)=>{ + valueLanguages.push(i.l) + }) + value.overrides?.forEach((i)=>{ + i.tr.forEach((value)=>{ + valueLanguagesOverrites.push(value.l) + }) + const differentArrOverrides = languages.filter(x => !valueLanguagesOverrites.includes(x)) + if(differentArrOverrides[0]){ + console.log(" Code: ",("\x1b[31m" + value.code + "\x1b[0m")," Customer: ",("\x1b[31m" + i.customer + "\x1b[0m")," is missing the following languages: ", differentArrOverrides) + } + valueLanguagesOverrites = [] + }) + const differentArr = languages.filter(x => !valueLanguages.includes(x)) + if(differentArr[0]){ + console.log(" Code: ",("\x1b[31m" + value.code + "\x1b[0m")," is missing the following languages: ", differentArr) + } + + }) +} + +const getAllLanguagesUnique = (languages: string[])=>{ + return languages.filter((value, index)=>languages.indexOf(value)===index) +} + +const multiFileReport = (languages:string[], namespaces:MessagesNamespace[])=>{ + console.log() + console.log("-------REPORT-------") + const uniqueLang = getAllLanguagesUnique(languages) + for (const [,messages] of namespaces) { + report(messages,uniqueLang) + } + console.log("All languages: ", uniqueLang) +} + +const singleFileReport = (message:Message[],languages:string[])=>{ + console.log() + console.log("-----REPORT-------") + const uniqueLang = getAllLanguagesUnique(languages) + report(message,uniqueLang) + console.log("All languages: ", uniqueLang) +} + const checkNamespaces = () => { fs.mkdirSync(outTempDir, { recursive: true }); fs.mkdirSync(outMsgDir, { recursive: true }); fs.mkdirSync(outTsDir, { recursive: true }); const namespaces: MessagesNamespace[] = mal.namespaces ? Object.entries(mal.namespaces) : []; - + const languages: string[] = [] if (namespaces.length > 0) { - namespaces.forEach(([ns, messages]) => { + for (const [ns, messages] of namespaces) { + allLanguagesReport(messages,languages) splitMessages(messages, ns); - }); + } + multiFileReport(languages,namespaces) writeNamespacesFile(namespaces); } else { + allLanguagesReport(mal.messages,languages) splitMessages(mal.messages); + singleFileReport(mal.messages, languages) } + + }; // main