{"version":3,"file":"handleContentDeclarationFileChange.cjs","names":["formatPath","getBuiltDictionariesPath","loadLocalDictionaries","buildDictionary","cleanRemovedContentDeclaration","createDictionaryEntryPoint","createTypes","createModuleAugmentation"],"sources":["../../src/handleContentDeclarationFileChange.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config/logger';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { buildDictionary } from './buildIntlayerDictionary/buildIntlayerDictionary';\nimport { cleanRemovedContentDeclaration } from './cleanRemovedContentDeclaration';\nimport { createDictionaryEntryPoint } from './createDictionaryEntryPoint/createDictionaryEntryPoint';\nimport { getBuiltDictionariesPath } from './createDictionaryEntryPoint/getBuiltDictionariesPath';\nimport { createTypes } from './createType';\nimport { createModuleAugmentation } from './createType/createModuleAugmentation';\nimport { loadLocalDictionaries } from './loadDictionaries/loadLocalDictionaries';\nimport { formatPath } from './utils/formatter';\n\nexport const handleContentDeclarationFileChange = async (\n  filePath: string,\n  config: IntlayerConfig\n) => {\n  const appLogger = getAppLogger(config);\n\n  // Process the file with the functionToRun\n  appLogger(`Change detected: ${formatPath(filePath)}`, {\n    isVerbose: true,\n  });\n\n  const allDictionariesPaths: string[] = await getBuiltDictionariesPath(config);\n\n  const localeDictionaries = await loadLocalDictionaries(filePath, config);\n\n  const dictionariesOutput = await buildDictionary(localeDictionaries, config);\n  const updatedDictionaries = Object.values(\n    dictionariesOutput?.mergedDictionaries ?? {}\n  );\n  const updatedDictionariesPaths = updatedDictionaries.map(\n    (dictionary) => dictionary.dictionaryPath\n  );\n\n  const { excludeKeys, hasRebuilt } = await cleanRemovedContentDeclaration(\n    filePath,\n    localeDictionaries.map((dictionary) => dictionary.key),\n    config\n  );\n\n  const hasNewDictionaries = updatedDictionariesPaths.some(\n    (updatedDictionaryPath) =>\n      !allDictionariesPaths.includes(updatedDictionaryPath)\n  );\n\n  // Rebuild Entry Point & Module Augmentation\n  // These only need to be updated if the *list* of dictionaries changed (Add/Remove/Rename)\n  if (hasRebuilt || hasNewDictionaries) {\n    // If hasRebuilt is true, cleanRemovedContentDeclaration has already updated the entry point\n    // to remove the old keys (and it likely included the new ones if they were already on disk).\n    // If NOT hasRebuilt, we explicitly need to update the entry point to include the new dictionaries.\n    if (!hasRebuilt) {\n      await createDictionaryEntryPoint(config, { excludeKeys });\n      appLogger('Dictionary list built', {\n        isVerbose: true,\n      });\n    }\n  }\n\n  // Rebuild Types\n  // Always regenerate types when a file changes, as the content structure (interface) might have changed\n  // even if the key is the same.\n  const dictionariesToBuild = updatedDictionaries.map(\n    (dictionary) => dictionary.dictionary\n  );\n\n  await createTypes(dictionariesToBuild, config);\n  appLogger('TypeScript types built', {\n    isVerbose: true,\n  });\n\n  if (hasNewDictionaries) {\n    await createModuleAugmentation(config);\n    appLogger('Module augmentation built', {\n      isVerbose: true,\n    });\n  }\n\n  // Plugin transformation\n  // Allow plugins to post-process the final build output (e.g., write back ICU JSON)\n  for await (const plugin of config.plugins ?? []) {\n    const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;\n\n    await plugin.afterBuild?.({\n      dictionaries: {\n        unmergedDictionaries,\n        mergedDictionaries,\n      },\n      configuration: config,\n    });\n  }\n};\n"],"mappings":";;;;;;;;;;;;;AAWA,MAAa,qCAAqC,OAChD,UACA,WACG;CACH,MAAM,sDAAyB,MAAM;CAGrC,UAAU,oBAAoBA,mCAAW,QAAQ,KAAK,EACpD,WAAW,KACb,CAAC;CAED,MAAM,uBAAiC,MAAMC,qFAAyB,MAAM;CAE5E,MAAM,qBAAqB,MAAMC,qEAAsB,UAAU,MAAM;CAEvE,MAAM,qBAAqB,MAAMC,wEAAgB,oBAAoB,MAAM;CAC3E,MAAM,sBAAsB,OAAO,OACjC,oBAAoB,sBAAsB,CAAC,CAC7C;CACA,MAAM,2BAA2B,oBAAoB,KAClD,eAAe,WAAW,cAC7B;CAEA,MAAM,EAAE,aAAa,eAAe,MAAMC,sEACxC,UACA,mBAAmB,KAAK,eAAe,WAAW,GAAG,GACrD,MACF;CAEA,MAAM,qBAAqB,yBAAyB,MACjD,0BACC,CAAC,qBAAqB,SAAS,qBAAqB,CACxD;CAIA,IAAI,cAAc,oBAIhB;MAAI,CAAC,YAAY;GACf,MAAMC,yFAA2B,QAAQ,EAAE,YAAY,CAAC;GACxD,UAAU,yBAAyB,EACjC,WAAW,KACb,CAAC;EACH;;CAUF,MAAMC,0CAJsB,oBAAoB,KAC7C,eAAe,WAAW,UAGO,GAAG,MAAM;CAC7C,UAAU,0BAA0B,EAClC,WAAW,KACb,CAAC;CAED,IAAI,oBAAoB;EACtB,MAAMC,qEAAyB,MAAM;EACrC,UAAU,6BAA6B,EACrC,WAAW,KACb,CAAC;CACH;CAIA,WAAW,MAAM,UAAU,OAAO,WAAW,CAAC,GAAG;EAC/C,MAAM,EAAE,sBAAsB,uBAAuB;EAErD,MAAM,OAAO,aAAa;GACxB,cAAc;IACZ;IACA;GACF;GACA,eAAe;EACjB,CAAC;CACH;AACF"}