{"version":3,"sources":["../../../../../src/transpiler/declaration_file_to_dictionary/i18next_dictionary/writeDictionary.ts"],"sourcesContent":["import { mkdir, writeFile } from 'fs/promises';\nimport { resolve } from 'path';\nimport { getConfiguration } from '@intlayer/config';\nimport type { I18nextDictionariesOutput } from './convertContentDeclarationInto18nDictionaries';\n\nexport type DictionariesDeclaration = Record<string, I18nextDictionariesOutput>;\n\n/**\n * This function writes the dictionaries to the file system\n */\nexport const writeDictionary = async (\n  dictionariesDeclaration: DictionariesDeclaration,\n  configuration = getConfiguration()\n) => {\n  const { i18nextResourcesDir } = configuration.content;\n\n  const resultDictionariesPaths: string[] = [];\n\n  for (const [nameSpace, localContent] of Object.entries(\n    dictionariesDeclaration\n  )) {\n    for await (const [locale, content] of Object.entries(localContent)) {\n      const contentString = JSON.stringify(content);\n\n      const outputFileName = `${nameSpace}.json`;\n      const resultDirPath = resolve(i18nextResourcesDir, locale);\n      const resultFilePath = resolve(resultDirPath, outputFileName);\n\n      // Create the dictionaries folder if it doesn't exist\n      await mkdir(resultDirPath, { recursive: true });\n\n      // Create the json file\n      await writeFile(resultFilePath, contentString, 'utf8').catch((err) => {\n        console.error(`Error creating ${outputFileName}:`, err);\n      });\n\n      resultDictionariesPaths.push(resultFilePath);\n    }\n  }\n\n  return resultDictionariesPaths;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAiC;AACjC,kBAAwB;AACxB,oBAAiC;AAQ1B,MAAM,kBAAkB,OAC7B,yBACA,oBAAgB,gCAAiB,MAC9B;AACH,QAAM,EAAE,oBAAoB,IAAI,cAAc;AAE9C,QAAM,0BAAoC,CAAC;AAE3C,aAAW,CAAC,WAAW,YAAY,KAAK,OAAO;AAAA,IAC7C;AAAA,EACF,GAAG;AACD,qBAAiB,CAAC,QAAQ,OAAO,KAAK,OAAO,QAAQ,YAAY,GAAG;AAClE,YAAM,gBAAgB,KAAK,UAAU,OAAO;AAE5C,YAAM,iBAAiB,GAAG,SAAS;AACnC,YAAM,oBAAgB,qBAAQ,qBAAqB,MAAM;AACzD,YAAM,qBAAiB,qBAAQ,eAAe,cAAc;AAG5D,gBAAM,uBAAM,eAAe,EAAE,WAAW,KAAK,CAAC;AAG9C,gBAAM,2BAAU,gBAAgB,eAAe,MAAM,EAAE,MAAM,CAAC,QAAQ;AACpE,gBAAQ,MAAM,kBAAkB,cAAc,KAAK,GAAG;AAAA,MACxD,CAAC;AAED,8BAAwB,KAAK,cAAc;AAAA,IAC7C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}