@intlayer/cli 8.2.1 → 8.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +1 -1
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  3. package/dist/cjs/auth/login.cjs +2 -2
  4. package/dist/cjs/auth/login.cjs.map +1 -1
  5. package/dist/cjs/build.cjs +1 -1
  6. package/dist/cjs/build.cjs.map +1 -1
  7. package/dist/cjs/ci.cjs +1 -1
  8. package/dist/cjs/ci.cjs.map +1 -1
  9. package/dist/cjs/cli.cjs +1 -1
  10. package/dist/cjs/cli.cjs.map +1 -1
  11. package/dist/cjs/config.cjs +1 -1
  12. package/dist/cjs/config.cjs.map +1 -1
  13. package/dist/cjs/extract.cjs +1 -1
  14. package/dist/cjs/extract.cjs.map +1 -1
  15. package/dist/cjs/fill/deepMergeContent.cjs +1 -1
  16. package/dist/cjs/fill/deepMergeContent.cjs.map +1 -1
  17. package/dist/cjs/fill/fill.cjs +1 -1
  18. package/dist/cjs/fill/fill.cjs.map +1 -1
  19. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs +1 -1
  20. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs.map +1 -1
  21. package/dist/cjs/fill/listTranslationsTasks.cjs +1 -1
  22. package/dist/cjs/fill/translateDictionary.cjs +1 -1
  23. package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
  24. package/dist/cjs/fill/writeFill.cjs +1 -1
  25. package/dist/cjs/fill/writeFill.cjs.map +1 -1
  26. package/dist/cjs/getTargetDictionary.cjs +1 -1
  27. package/dist/cjs/init.cjs +1 -1
  28. package/dist/cjs/initMCP.cjs +1 -1
  29. package/dist/cjs/initSkills.cjs +1 -1
  30. package/dist/cjs/listContentDeclaration.cjs +1 -1
  31. package/dist/cjs/listProjects.cjs +1 -1
  32. package/dist/cjs/liveSync.cjs +1 -1
  33. package/dist/cjs/liveSync.cjs.map +1 -1
  34. package/dist/cjs/pull.cjs +1 -1
  35. package/dist/cjs/pull.cjs.map +1 -1
  36. package/dist/cjs/push/pullLog.cjs +1 -1
  37. package/dist/cjs/push/push.cjs +1 -1
  38. package/dist/cjs/push/push.cjs.map +1 -1
  39. package/dist/cjs/pushConfig.cjs +1 -1
  40. package/dist/cjs/pushConfig.cjs.map +1 -1
  41. package/dist/cjs/reviewDoc/reviewDoc.cjs +1 -1
  42. package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
  43. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +1 -1
  44. package/dist/cjs/searchDoc.cjs +1 -1
  45. package/dist/cjs/searchDoc.cjs.map +1 -1
  46. package/dist/cjs/test/listMissingTranslations.cjs +1 -1
  47. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  48. package/dist/cjs/test/test.cjs +1 -1
  49. package/dist/cjs/translateDoc/translateDoc.cjs +1 -1
  50. package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
  51. package/dist/cjs/translateDoc/translateFile.cjs +2 -2
  52. package/dist/cjs/watch.cjs +1 -1
  53. package/dist/cjs/watch.cjs.map +1 -1
  54. package/dist/esm/IntlayerEventListener.mjs +1 -1
  55. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  56. package/dist/esm/auth/login.mjs +2 -2
  57. package/dist/esm/auth/login.mjs.map +1 -1
  58. package/dist/esm/build.mjs +1 -1
  59. package/dist/esm/build.mjs.map +1 -1
  60. package/dist/esm/ci.mjs +1 -1
  61. package/dist/esm/ci.mjs.map +1 -1
  62. package/dist/esm/cli.mjs +1 -1
  63. package/dist/esm/cli.mjs.map +1 -1
  64. package/dist/esm/config.mjs +1 -1
  65. package/dist/esm/config.mjs.map +1 -1
  66. package/dist/esm/extract.mjs +1 -1
  67. package/dist/esm/extract.mjs.map +1 -1
  68. package/dist/esm/fill/deepMergeContent.mjs +1 -1
  69. package/dist/esm/fill/deepMergeContent.mjs.map +1 -1
  70. package/dist/esm/fill/fill.mjs +1 -1
  71. package/dist/esm/fill/fill.mjs.map +1 -1
  72. package/dist/esm/fill/getFilterMissingContentPerLocale.mjs +1 -1
  73. package/dist/esm/fill/getFilterMissingContentPerLocale.mjs.map +1 -1
  74. package/dist/esm/fill/listTranslationsTasks.mjs +1 -1
  75. package/dist/esm/fill/translateDictionary.mjs +1 -1
  76. package/dist/esm/fill/translateDictionary.mjs.map +1 -1
  77. package/dist/esm/fill/writeFill.mjs +1 -1
  78. package/dist/esm/fill/writeFill.mjs.map +1 -1
  79. package/dist/esm/getTargetDictionary.mjs +1 -1
  80. package/dist/esm/init.mjs +1 -1
  81. package/dist/esm/initMCP.mjs +1 -1
  82. package/dist/esm/initSkills.mjs +1 -1
  83. package/dist/esm/listContentDeclaration.mjs +1 -1
  84. package/dist/esm/listProjects.mjs +1 -1
  85. package/dist/esm/liveSync.mjs +1 -1
  86. package/dist/esm/liveSync.mjs.map +1 -1
  87. package/dist/esm/pull.mjs +1 -1
  88. package/dist/esm/pull.mjs.map +1 -1
  89. package/dist/esm/push/pullLog.mjs +1 -1
  90. package/dist/esm/push/push.mjs +1 -1
  91. package/dist/esm/push/push.mjs.map +1 -1
  92. package/dist/esm/pushConfig.mjs +1 -1
  93. package/dist/esm/pushConfig.mjs.map +1 -1
  94. package/dist/esm/reviewDoc/reviewDoc.mjs +1 -1
  95. package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
  96. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +1 -1
  97. package/dist/esm/searchDoc.mjs +1 -1
  98. package/dist/esm/searchDoc.mjs.map +1 -1
  99. package/dist/esm/test/listMissingTranslations.mjs +1 -1
  100. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  101. package/dist/esm/test/test.mjs +1 -1
  102. package/dist/esm/translateDoc/translateDoc.mjs +1 -1
  103. package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
  104. package/dist/esm/translateDoc/translateFile.mjs +2 -2
  105. package/dist/esm/watch.mjs +1 -1
  106. package/dist/esm/watch.mjs.map +1 -1
  107. package/dist/types/auth/login.d.ts.map +1 -1
  108. package/dist/types/build.d.ts.map +1 -1
  109. package/dist/types/cli.d.ts.map +1 -1
  110. package/dist/types/config.d.ts.map +1 -1
  111. package/dist/types/extract.d.ts.map +1 -1
  112. package/dist/types/fill/fill.d.ts.map +1 -1
  113. package/dist/types/fill/getFilterMissingContentPerLocale.d.ts.map +1 -1
  114. package/dist/types/fill/translateDictionary.d.ts.map +1 -1
  115. package/dist/types/pull.d.ts.map +1 -1
  116. package/dist/types/push/push.d.ts.map +1 -1
  117. package/dist/types/pushConfig.d.ts.map +1 -1
  118. package/dist/types/reviewDoc/reviewDoc.d.ts.map +1 -1
  119. package/dist/types/searchDoc.d.ts.map +1 -1
  120. package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
  121. package/dist/types/watch.d.ts.map +1 -1
  122. package/package.json +14 -14
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=(t,n)=>{if(!t)return n;if(!n)return t;if(typeof t!=`object`||typeof n!=`object`||Array.isArray(t)||Array.isArray(n))return n;let r={...t};for(let t in n)if(Object.hasOwn(n,t)){let i=n[t],a=r[t];typeof i==`object`&&i&&!Array.isArray(i)&&typeof a==`object`&&a&&!Array.isArray(a)?r[t]=e(a,i):r[t]=i}return r};exports.deepMergeContent=e;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=(t,n)=>{if(t==null)return n;if(n==null)return t;if(typeof t!=`object`||typeof n!=`object`||Array.isArray(t)||Array.isArray(n))return n;let r={...t};for(let t in n)if(Object.hasOwn(n,t)){let i=n[t],a=r[t];typeof i==`object`&&i&&!Array.isArray(i)&&typeof a==`object`&&a&&!Array.isArray(a)?r[t]=e(a,i):r[t]=i}return r};exports.deepMergeContent=e;
2
2
  //# sourceMappingURL=deepMergeContent.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"deepMergeContent.cjs","names":[],"sources":["../../../src/fill/deepMergeContent.ts"],"sourcesContent":["/**\n * Deep merge two plain objects (for per-locale content).\n * The second object's values take precedence over the first.\n *\n * @param target - The base object\n * @param source - The object to merge in (takes precedence)\n * @returns The merged object\n */\nexport const deepMergeContent = <T = any>(target: T, source: T): T => {\n // Handle null/undefined\n if (!target) return source;\n if (!source) return target;\n\n // Handle non-objects (primitives, arrays)\n if (\n typeof target !== 'object' ||\n typeof source !== 'object' ||\n Array.isArray(target) ||\n Array.isArray(source)\n ) {\n return source;\n }\n\n // Merge objects\n const result: any = { ...target };\n\n for (const key in source) {\n if (Object.hasOwn(source, key)) {\n const sourceValue = (source as any)[key];\n const targetValue = result[key];\n\n if (\n typeof sourceValue === 'object' &&\n sourceValue !== null &&\n !Array.isArray(sourceValue) &&\n typeof targetValue === 'object' &&\n targetValue !== null &&\n !Array.isArray(targetValue)\n ) {\n // Recursively merge nested objects\n result[key] = deepMergeContent(targetValue, sourceValue);\n } else {\n // Overwrite with source value\n result[key] = sourceValue;\n }\n }\n }\n\n return result;\n};\n"],"mappings":"mEAQA,MAAa,GAA6B,EAAW,IAAiB,CAEpE,GAAI,CAAC,EAAQ,OAAO,EACpB,GAAI,CAAC,EAAQ,OAAO,EAGpB,GACE,OAAO,GAAW,UAClB,OAAO,GAAW,UAClB,MAAM,QAAQ,EAAO,EACrB,MAAM,QAAQ,EAAO,CAErB,OAAO,EAIT,IAAM,EAAc,CAAE,GAAG,EAAQ,CAEjC,IAAK,IAAM,KAAO,EAChB,GAAI,OAAO,OAAO,EAAQ,EAAI,CAAE,CAC9B,IAAM,EAAe,EAAe,GAC9B,EAAc,EAAO,GAGzB,OAAO,GAAgB,UACvB,GACA,CAAC,MAAM,QAAQ,EAAY,EAC3B,OAAO,GAAgB,UACvB,GACA,CAAC,MAAM,QAAQ,EAAY,CAG3B,EAAO,GAAO,EAAiB,EAAa,EAAY,CAGxD,EAAO,GAAO,EAKpB,OAAO"}
1
+ {"version":3,"file":"deepMergeContent.cjs","names":[],"sources":["../../../src/fill/deepMergeContent.ts"],"sourcesContent":["/**\n * Deep merge two plain objects (for per-locale content).\n * The second object's values take precedence over the first.\n *\n * @param target - The base object\n * @param source - The object to merge in (takes precedence)\n * @returns The merged object\n */\nexport const deepMergeContent = <T = any>(target: T, source: T): T => {\n // Handle null/undefined\n if (target === null || target === undefined) return source;\n if (source === null || source === undefined) return target;\n\n // Handle non-objects (primitives, arrays)\n if (\n typeof target !== 'object' ||\n typeof source !== 'object' ||\n Array.isArray(target) ||\n Array.isArray(source)\n ) {\n return source;\n }\n\n // Merge objects\n const result: any = { ...target };\n\n for (const key in source) {\n if (Object.hasOwn(source, key)) {\n const sourceValue = (source as any)[key];\n const targetValue = result[key];\n\n if (\n typeof sourceValue === 'object' &&\n sourceValue !== null &&\n !Array.isArray(sourceValue) &&\n typeof targetValue === 'object' &&\n targetValue !== null &&\n !Array.isArray(targetValue)\n ) {\n // Recursively merge nested objects\n result[key] = deepMergeContent(targetValue, sourceValue);\n } else {\n // Overwrite with source value\n result[key] = sourceValue;\n }\n }\n }\n\n return result;\n};\n"],"mappings":"mEAQA,MAAa,GAA6B,EAAW,IAAiB,CAEpE,GAAI,GAAW,KAA8B,OAAO,EACpD,GAAI,GAAW,KAA8B,OAAO,EAGpD,GACE,OAAO,GAAW,UAClB,OAAO,GAAW,UAClB,MAAM,QAAQ,EAAO,EACrB,MAAM,QAAQ,EAAO,CAErB,OAAO,EAIT,IAAM,EAAc,CAAE,GAAG,EAAQ,CAEjC,IAAK,IAAM,KAAO,EAChB,GAAI,OAAO,OAAO,EAAQ,EAAI,CAAE,CAC9B,IAAM,EAAe,EAAe,GAC9B,EAAc,EAAO,GAGzB,OAAO,GAAgB,UACvB,GACA,CAAC,MAAM,QAAQ,EAAY,EAC3B,OAAO,GAAgB,UACvB,GACA,CAAC,MAAM,QAAQ,EAAY,CAG3B,EAAO,GAAO,EAAiB,EAAa,EAAY,CAGxD,EAAO,GAAO,EAKpB,OAAO"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../getTargetDictionary.cjs`),t=require(`../utils/setupAI.cjs`),n=require(`./listTranslationsTasks.cjs`),r=require(`./translateDictionary.cjs`),i=require(`./writeFill.cjs`);let a=require(`@intlayer/chokidar/utils`),o=require(`@intlayer/config/node`),s=require(`node:path`),c=require(`@intlayer/config/logger`),l=require(`@intlayer/chokidar/build`);const u=async u=>{let d=(0,o.getConfiguration)(u?.configOptions),f=(0,c.getAppLogger)(d);u?.build===!0?await(0,l.prepareIntlayer)(d,{forceRun:!0}):u?.build===void 0&&await(0,l.prepareIntlayer)(d);let{defaultLocale:p,locales:m}=d.internationalization,h=u?.mode??`complete`,g=u?.sourceLocale??p,_=u?.outputLocales?e.ensureArray(u.outputLocales):m,v=await t.setupAI(d,u?.aiOptions);if(!v?.hasAIAccess)return;let{aiClient:y,aiConfig:b}=v,x=await e.getTargetUnmergedDictionaries(u),S=new Set;x.forEach(e=>{S.add(e.key)});let C=Array.from(S);if(f([`Affected dictionary keys for processing:`,C.length>0?C.map(e=>(0,c.colorizeKey)(e)).join(`, `):(0,c.colorize)(`No keys found`,c.ANSIColors.YELLOW)]),C.length===0)return;let w=n.listTranslationsTasks(x.map(e=>e.localId),_,h,g,d),T=u?.nbConcurrentTranslations??7,E=(0,a.getGlobalLimiter)(T),D=(0,a.getTaskLimiter)(Math.max(1,Math.min(u?.nbConcurrentTasks??T,w.length))),O=w.map(e=>D(async()=>{let t=(0,s.relative)(d?.content?.baseDir??process.cwd(),e?.dictionaryFilePath??``);f(`${e.dictionaryPreset} Processing ${(0,c.colorizePath)((0,s.basename)(t))}`,{level:`info`});let n=await r.translateDictionary(e,d,{mode:h,aiOptions:u?.aiOptions,fillMetadata:!u?.skipMetadata,onHandle:E,aiClient:y,aiConfig:b});if(!n?.dictionaryOutput)return;let{dictionaryOutput:o,sourceLocale:p}=n,m=typeof o.fill==`string`||typeof o.fill==`object`,g=typeof o.locale==`string`,v=m?o.fill:g?d.dictionary?.fill??!0:!1;typeof v==`string`||typeof v==`object`?await i.writeFill({...o,fill:v},_,[p],d):(await(0,l.writeContentDeclaration)(o,d),o.filePath&&f(`${e.dictionaryPreset} Content declaration written to ${(0,a.formatPath)((0,s.basename)(o.filePath))}`,{level:`info`}))}));await Promise.all(O),await E.onIdle()};exports.fill=u;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../getTargetDictionary.cjs`),t=require(`../utils/setupAI.cjs`),n=require(`./listTranslationsTasks.cjs`),r=require(`./translateDictionary.cjs`),i=require(`./writeFill.cjs`);let a=require(`@intlayer/config/logger`),o=require(`@intlayer/chokidar/cli`),s=require(`@intlayer/chokidar/utils`),c=require(`@intlayer/config/node`),l=require(`node:path`),u=require(`@intlayer/chokidar/build`);const d=async d=>{let f=(0,c.getConfiguration)(d?.configOptions);(0,o.logConfigDetails)(d?.configOptions);let p=(0,a.getAppLogger)(f);d?.build===!0?await(0,u.prepareIntlayer)(f,{forceRun:!0}):d?.build===void 0&&await(0,u.prepareIntlayer)(f);let{defaultLocale:m,locales:h}=f.internationalization,g=d?.mode??`complete`,_=d?.sourceLocale??m,v=d?.outputLocales?e.ensureArray(d.outputLocales):h,y=await t.setupAI(f,d?.aiOptions);if(!y?.hasAIAccess)return;let{aiClient:b,aiConfig:x}=y,S=await e.getTargetUnmergedDictionaries(d),C=new Set;S.forEach(e=>{C.add(e.key)});let w=Array.from(C);if(p([`Affected dictionary keys for processing:`,w.length>0?w.map(e=>(0,a.colorizeKey)(e)).join(`, `):(0,a.colorize)(`No keys found`,a.ANSIColors.YELLOW)]),w.length===0)return;let T=n.listTranslationsTasks(S.map(e=>e.localId),v,g,_,f),E=d?.nbConcurrentTranslations??7,D=(0,s.getGlobalLimiter)(E),O=(0,s.getTaskLimiter)(Math.max(1,Math.min(d?.nbConcurrentTasks??E,T.length))),k=T.map(e=>O(async()=>{let t=(0,l.relative)(f?.content?.baseDir??process.cwd(),e?.dictionaryFilePath??``);p(`${e.dictionaryPreset} Processing ${(0,a.colorizePath)((0,l.basename)(t))}`,{level:`info`});let n=await r.translateDictionary(e,f,{mode:g,aiOptions:d?.aiOptions,fillMetadata:!d?.skipMetadata,onHandle:D,aiClient:b,aiConfig:x});if(!n?.dictionaryOutput)return;let{dictionaryOutput:o,sourceLocale:c}=n,m=typeof o.fill==`string`||typeof o.fill==`object`,h=typeof o.locale==`string`,_=m?o.fill:h?f.dictionary?.fill??!0:!1;typeof _==`string`||typeof _==`object`?await i.writeFill({...o,fill:_},v,[c],f):(await(0,u.writeContentDeclaration)(o,f),o.filePath&&p(`${e.dictionaryPreset} Content declaration written to ${(0,s.formatPath)((0,l.basename)(o.filePath))}`,{level:`info`}))}));await Promise.all(k),await D.onIdle()};exports.fill=d;
2
2
  //# sourceMappingURL=fill.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"fill.cjs","names":["ensureArray","setupAI","getTargetUnmergedDictionaries","ANSIColors","listTranslationsTasks","translateDictionary","writeFill"],"sources":["../../../src/fill/fill.ts"],"sourcesContent":["import { basename, relative } from 'node:path';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n prepareIntlayer,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport type { ListGitFilesOptions } from '@intlayer/chokidar/cli';\nimport {\n formatPath,\n getGlobalLimiter,\n getTaskLimiter,\n} from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { Locale } from '@intlayer/types';\nimport {\n ensureArray,\n type GetTargetDictionaryOptions,\n getTargetUnmergedDictionaries,\n} from '../getTargetDictionary';\nimport { setupAI } from '../utils/setupAI';\nimport {\n listTranslationsTasks,\n type TranslationTask,\n} from './listTranslationsTasks';\nimport { translateDictionary } from './translateDictionary';\nimport { writeFill } from './writeFill';\n\nconst NB_CONCURRENT_TRANSLATIONS = 7;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locale;\n outputLocales?: Locale | Locale[];\n mode?: 'complete' | 'review';\n gitOptions?: ListGitFilesOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n nbConcurrentTasks?: number; // NEW: number of tasks that may run at once\n build?: boolean;\n skipMetadata?: boolean;\n} & GetTargetDictionaryOptions;\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options?: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n if (options?.build === true) {\n await prepareIntlayer(configuration, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(configuration);\n }\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options?.mode ?? 'complete';\n const baseLocale = options?.sourceLocale ?? defaultLocale;\n\n const outputLocales = options?.outputLocales\n ? ensureArray(options.outputLocales)\n : locales;\n\n const aiResult = await setupAI(configuration, options?.aiOptions);\n\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig } = aiResult;\n\n const targetUnmergedDictionaries =\n await getTargetUnmergedDictionaries(options);\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n const keysToProcess = Array.from(affectedDictionaryKeys);\n\n appLogger([\n 'Affected dictionary keys for processing:',\n keysToProcess.length > 0\n ? keysToProcess.map((key) => colorizeKey(key)).join(', ')\n : colorize('No keys found', ANSIColors.YELLOW),\n ]);\n\n if (keysToProcess.length === 0) return;\n\n /**\n * List the translations tasks\n *\n * Create a list of per-locale dictionaries to translate\n *\n * In 'complete' mode, filter only the missing locales to translate\n */\n const translationTasks: TranslationTask[] = listTranslationsTasks(\n targetUnmergedDictionaries.map((dictionary) => dictionary.localId!),\n outputLocales,\n mode,\n baseLocale,\n configuration\n );\n\n // AI calls in flight at once (translateJSON + metadata audit)\n const nbConcurrentTranslations =\n options?.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS;\n const globalLimiter = getGlobalLimiter(nbConcurrentTranslations);\n\n // NEW: number of *tasks* that may run at once (start/prepare/log/write)\n const nbConcurrentTasks = Math.max(\n 1,\n Math.min(\n options?.nbConcurrentTasks ?? nbConcurrentTranslations,\n translationTasks.length\n )\n );\n\n const taskLimiter = getTaskLimiter(nbConcurrentTasks);\n\n const runners = translationTasks.map((task) =>\n taskLimiter(async () => {\n const relativePath = relative(\n configuration?.content?.baseDir ?? process.cwd(),\n task?.dictionaryFilePath ?? ''\n );\n\n // log AFTER acquiring a task slot\n appLogger(\n `${task.dictionaryPreset} Processing ${colorizePath(basename(relativePath))}`,\n { level: 'info' }\n );\n\n const translationTaskResult = await translateDictionary(\n task,\n configuration,\n {\n mode,\n aiOptions: options?.aiOptions,\n fillMetadata: !options?.skipMetadata,\n onHandle: globalLimiter, // <= AI calls go through here\n aiClient,\n aiConfig,\n }\n );\n\n if (!translationTaskResult?.dictionaryOutput) return;\n\n const { dictionaryOutput, sourceLocale } = translationTaskResult;\n\n // Determine if we should write to separate files\n // - If dictionary has explicit fill setting (string or object), use it\n // - If dictionary is per-locale AND has no explicit fill=false, use global fill config\n // - If dictionary is multilingual (no locale property), always write to same file\n const hasDictionaryLevelFill =\n typeof dictionaryOutput.fill === 'string' ||\n typeof dictionaryOutput.fill === 'object';\n\n const isPerLocale = typeof dictionaryOutput.locale === 'string';\n\n const effectiveFill = hasDictionaryLevelFill\n ? dictionaryOutput.fill\n : isPerLocale\n ? (configuration.dictionary?.fill ?? true)\n : false; // Multilingual dictionaries don't use fill by default\n\n const isFillOtherFile =\n typeof effectiveFill === 'string' || typeof effectiveFill === 'object';\n\n if (isFillOtherFile) {\n await writeFill(\n {\n ...dictionaryOutput,\n // Ensure fill is set on the dictionary for writeFill to use\n fill: effectiveFill,\n },\n outputLocales,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(dictionaryOutput, configuration);\n\n if (dictionaryOutput.filePath) {\n appLogger(\n `${task.dictionaryPreset} Content declaration written to ${formatPath(basename(dictionaryOutput.filePath))}`,\n { level: 'info' }\n );\n }\n }\n })\n );\n\n await Promise.all(runners);\n await (globalLimiter as any).onIdle();\n};\n"],"mappings":"4dAkCA,MAmBa,EAAO,KAAO,IAAyC,CAClE,IAAM,GAAA,EAAA,EAAA,kBAAiC,GAAS,cAAc,CACxD,GAAA,EAAA,EAAA,cAAyB,EAAc,CAEzC,GAAS,QAAU,GACrB,MAAA,EAAA,EAAA,iBAAsB,EAAe,CAAE,SAAU,GAAM,CAAC,CACxC,GAAS,QAAU,QACnC,MAAA,EAAA,EAAA,iBAAsB,EAAc,CAGtC,GAAM,CAAE,gBAAe,WAAY,EAAc,qBAC3C,EAAO,GAAS,MAAQ,WACxB,EAAa,GAAS,cAAgB,EAEtC,EAAgB,GAAS,cAC3BA,EAAAA,YAAY,EAAQ,cAAc,CAClC,EAEE,EAAW,MAAMC,EAAAA,QAAQ,EAAe,GAAS,UAAU,CAEjE,GAAI,CAAC,GAAU,YAAa,OAE5B,GAAM,CAAE,WAAU,YAAa,EAEzB,EACJ,MAAMC,EAAAA,8BAA8B,EAAQ,CAExC,EAAyB,IAAI,IACnC,EAA2B,QAAS,GAAS,CAC3C,EAAuB,IAAI,EAAK,IAAI,EACpC,CAEF,IAAM,EAAgB,MAAM,KAAK,EAAuB,CASxD,GAPA,EAAU,CACR,2CACA,EAAc,OAAS,EACnB,EAAc,IAAK,IAAA,EAAA,EAAA,aAAoB,EAAI,CAAC,CAAC,KAAK,KAAK,EAAA,EAAA,EAAA,UAC9C,gBAAiBC,EAAAA,WAAW,OAAO,CACjD,CAAC,CAEE,EAAc,SAAW,EAAG,OAShC,IAAM,EAAsCC,EAAAA,sBAC1C,EAA2B,IAAK,GAAe,EAAW,QAAS,CACnE,EAC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nmergedDictionaries","ANSIColors","listTranslationsTasks","translateDictionary","writeFill"],"sources":["../../../src/fill/fill.ts"],"sourcesContent":["import { basename, relative } from 'node:path';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n prepareIntlayer,\n writeContentDeclaration,\n} from '@intlayer/chokidar/build';\nimport {\n type ListGitFilesOptions,\n logConfigDetails,\n} from '@intlayer/chokidar/cli';\nimport {\n formatPath,\n getGlobalLimiter,\n getTaskLimiter,\n} from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { Locale } from '@intlayer/types';\nimport {\n ensureArray,\n type GetTargetDictionaryOptions,\n getTargetUnmergedDictionaries,\n} from '../getTargetDictionary';\nimport { setupAI } from '../utils/setupAI';\nimport {\n listTranslationsTasks,\n type TranslationTask,\n} from './listTranslationsTasks';\nimport { translateDictionary } from './translateDictionary';\nimport { writeFill } from './writeFill';\n\nconst NB_CONCURRENT_TRANSLATIONS = 7;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locale;\n outputLocales?: Locale | Locale[];\n mode?: 'complete' | 'review';\n gitOptions?: ListGitFilesOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n nbConcurrentTasks?: number; // NEW: number of tasks that may run at once\n build?: boolean;\n skipMetadata?: boolean;\n} & GetTargetDictionaryOptions;\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options?: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options?.configOptions);\n logConfigDetails(options?.configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n if (options?.build === true) {\n await prepareIntlayer(configuration, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(configuration);\n }\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options?.mode ?? 'complete';\n const baseLocale = options?.sourceLocale ?? defaultLocale;\n\n const outputLocales = options?.outputLocales\n ? ensureArray(options.outputLocales)\n : locales;\n\n const aiResult = await setupAI(configuration, options?.aiOptions);\n\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig } = aiResult;\n\n const targetUnmergedDictionaries =\n await getTargetUnmergedDictionaries(options);\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n const keysToProcess = Array.from(affectedDictionaryKeys);\n\n appLogger([\n 'Affected dictionary keys for processing:',\n keysToProcess.length > 0\n ? keysToProcess.map((key) => colorizeKey(key)).join(', ')\n : colorize('No keys found', ANSIColors.YELLOW),\n ]);\n\n if (keysToProcess.length === 0) return;\n\n /**\n * List the translations tasks\n *\n * Create a list of per-locale dictionaries to translate\n *\n * In 'complete' mode, filter only the missing locales to translate\n */\n const translationTasks: TranslationTask[] = listTranslationsTasks(\n targetUnmergedDictionaries.map((dictionary) => dictionary.localId!),\n outputLocales,\n mode,\n baseLocale,\n configuration\n );\n\n // AI calls in flight at once (translateJSON + metadata audit)\n const nbConcurrentTranslations =\n options?.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS;\n const globalLimiter = getGlobalLimiter(nbConcurrentTranslations);\n\n // NEW: number of *tasks* that may run at once (start/prepare/log/write)\n const nbConcurrentTasks = Math.max(\n 1,\n Math.min(\n options?.nbConcurrentTasks ?? nbConcurrentTranslations,\n translationTasks.length\n )\n );\n\n const taskLimiter = getTaskLimiter(nbConcurrentTasks);\n\n const runners = translationTasks.map((task) =>\n taskLimiter(async () => {\n const relativePath = relative(\n configuration?.content?.baseDir ?? process.cwd(),\n task?.dictionaryFilePath ?? ''\n );\n\n // log AFTER acquiring a task slot\n appLogger(\n `${task.dictionaryPreset} Processing ${colorizePath(basename(relativePath))}`,\n { level: 'info' }\n );\n\n const translationTaskResult = await translateDictionary(\n task,\n configuration,\n {\n mode,\n aiOptions: options?.aiOptions,\n fillMetadata: !options?.skipMetadata,\n onHandle: globalLimiter, // <= AI calls go through here\n aiClient,\n aiConfig,\n }\n );\n\n if (!translationTaskResult?.dictionaryOutput) return;\n\n const { dictionaryOutput, sourceLocale } = translationTaskResult;\n\n // Determine if we should write to separate files\n // - If dictionary has explicit fill setting (string or object), use it\n // - If dictionary is per-locale AND has no explicit fill=false, use global fill config\n // - If dictionary is multilingual (no locale property), always write to same file\n const hasDictionaryLevelFill =\n typeof dictionaryOutput.fill === 'string' ||\n typeof dictionaryOutput.fill === 'object';\n\n const isPerLocale = typeof dictionaryOutput.locale === 'string';\n\n const effectiveFill = hasDictionaryLevelFill\n ? dictionaryOutput.fill\n : isPerLocale\n ? (configuration.dictionary?.fill ?? true)\n : false; // Multilingual dictionaries don't use fill by default\n\n const isFillOtherFile =\n typeof effectiveFill === 'string' || typeof effectiveFill === 'object';\n\n if (isFillOtherFile) {\n await writeFill(\n {\n ...dictionaryOutput,\n // Ensure fill is set on the dictionary for writeFill to use\n fill: effectiveFill,\n },\n outputLocales,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(dictionaryOutput, configuration);\n\n if (dictionaryOutput.filePath) {\n appLogger(\n `${task.dictionaryPreset} Content declaration written to ${formatPath(basename(dictionaryOutput.filePath))}`,\n { level: 'info' }\n );\n }\n }\n })\n );\n\n await Promise.all(runners);\n await (globalLimiter as any).onIdle();\n};\n"],"mappings":"ggBAqCA,MAmBa,EAAO,KAAO,IAAyC,CAClE,IAAM,GAAA,EAAA,EAAA,kBAAiC,GAAS,cAAc,EAC9D,EAAA,EAAA,kBAAiB,GAAS,cAAc,CAExC,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAEzC,GAAS,QAAU,GACrB,MAAA,EAAA,EAAA,iBAAsB,EAAe,CAAE,SAAU,GAAM,CAAC,CACxC,GAAS,QAAU,QACnC,MAAA,EAAA,EAAA,iBAAsB,EAAc,CAGtC,GAAM,CAAE,gBAAe,WAAY,EAAc,qB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,WACA,WACD,CACF,CAED,GAAI,CAAC,GAAuB,iBAAkB,OAE9C,GAAM,CAAE,mBAAkB,gBAAiB,EAMrC,EACJ,OAAO,EAAiB,MAAS,UACjC,OAAO,EAAiB,MAAS,SAE7B,EAAc,OAAO,EAAiB,QAAW,SAEjD,EAAgB,EAClB,EAAiB,KACjB,EACG,EAAc,YAAY,MAAQ,GACnC,GAGJ,OAAO,GAAkB,UAAY,OAAO,GAAkB,SAG9D,MAAMC,EAAAA,UACJ,CACE,GAAG,EAEH,KAAM,EACP,CACD,EACA,CAAC,EAAa,CACd,EACD,EAED,MAAA,EAAA,EAAA,yBAA8B,EAAkB,EAAc,CAE1D,EAAiB,UACnB,EACE,GAAG,EAAK,iBAAiB,mCAAA,EAAA,EAAA,aAAA,EAAA,EAAA,UAAsD,EAAiB,SAAS,CAAC,GAC1G,CAAE,MAAO,OAAQ,CAClB,GAGL,CACH,CAED,MAAM,QAAQ,IAAI,EAAQ,CAC1B,MAAO,EAAsB,QAAQ"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=(t,n)=>{if(n==null)return t;if(typeof t!=`object`||!t)return;if(Array.isArray(t)){if(!Array.isArray(n))return t;let r=t.map((t,r)=>e(t,n[r])).filter(e=>e!==void 0);return r.length>0?r:void 0}let r={},i=!1;for(let[a,o]of Object.entries(t)){let t=n?.[a],s=e(o,t);s!==void 0&&(r[a]=s,i=!0)}return i?r:void 0},t=(t,n)=>{if(!n||!n.content)return t;let r=e(t.content,n.content);return{...t,content:r??{}}};exports.getFilterMissingContentPerLocale=t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=(t,n)=>{if(t===null)return n===null?void 0:null;if(n==null)return t;if(typeof t!=`object`)return;if(Array.isArray(t)){if(!Array.isArray(n))return t;let r=t.map((t,r)=>e(t,n[r])).filter(e=>e!==void 0);return r.length>0?r:void 0}let r={},i=!1;for(let[a,o]of Object.entries(t)){let t=n?.[a],s=e(o,t);s!==void 0&&(r[a]=s,i=!0)}return i?r:void 0},t=(t,n)=>{if(!n||!n.content)return t;let r=e(t.content,n.content);return{...t,content:r??{}}};exports.getFilterMissingContentPerLocale=t;
2
2
  //# sourceMappingURL=getFilterMissingContentPerLocale.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilterMissingContentPerLocale.cjs","names":[],"sources":["../../../src/fill/getFilterMissingContentPerLocale.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types';\n\n/**\n * Recursively compares source content with target content and returns only the missing parts.\n * For per-locale files where content is simple JSON (not translation nodes).\n *\n * @param sourceContent - The source content to check\n * @param targetContent - The existing target content\n * @returns Only the content that's missing in the target\n */\nconst filterMissingContent = (sourceContent: any, targetContent: any): any => {\n // If target doesn't exist, all source content is missing\n if (targetContent === undefined || targetContent === null) {\n return sourceContent;\n }\n\n // Primitive values: if target exists (even if empty string), consider it translated\n if (typeof sourceContent !== 'object' || sourceContent === null) {\n return undefined;\n }\n\n // Handle arrays\n if (Array.isArray(sourceContent)) {\n if (!Array.isArray(targetContent)) {\n return sourceContent;\n }\n\n const missingItems = sourceContent\n .map((item, index) => filterMissingContent(item, targetContent[index]))\n .filter((item) => item !== undefined);\n\n return missingItems.length > 0 ? missingItems : undefined;\n }\n\n // Handle objects\n const result: any = {};\n let hasMissingContent = false;\n\n for (const [key, value] of Object.entries(sourceContent)) {\n const targetValue = targetContent?.[key];\n const missingValue = filterMissingContent(value, targetValue);\n\n if (missingValue !== undefined) {\n result[key] = missingValue;\n hasMissingContent = true;\n }\n }\n\n return hasMissingContent ? result : undefined;\n};\n\n/**\n * Filters a dictionary to only include content that's missing in the target dictionary.\n * Used for per-locale content declarations in 'complete' mode.\n *\n * @param sourceDictionary - The source dictionary with content to translate\n * @param targetDictionary - The existing target dictionary\n * @returns A dictionary with only the missing content\n */\nexport const getFilterMissingContentPerLocale = (\n sourceDictionary: Dictionary,\n targetDictionary: Dictionary | undefined\n): Dictionary => {\n if (!targetDictionary || !targetDictionary.content) {\n // If no target exists, all source content is missing\n return sourceDictionary;\n }\n\n const missingContent = filterMissingContent(\n sourceDictionary.content,\n targetDictionary.content\n );\n\n return {\n ...sourceDictionary,\n content: missingContent ?? {},\n };\n};\n"],"mappings":"mEAUA,MAAM,GAAwB,EAAoB,IAA4B,CAE5E,GAAI,GAAiD,KACnD,OAAO,EAIT,GAAI,OAAO,GAAkB,WAAY,EACvC,OAIF,GAAI,MAAM,QAAQ,EAAc,CAAE,CAChC,GAAI,CAAC,MAAM,QAAQ,EAAc,CAC/B,OAAO,EAGT,IAAM,EAAe,EAClB,KAAK,EAAM,IAAU,EAAqB,EAAM,EAAc,GAAO,CAAC,CACtE,OAAQ,GAAS,IAAS,IAAA,GAAU,CAEvC,OAAO,EAAa,OAAS,EAAI,EAAe,IAAA,GAIlD,IAAM,EAAc,EAAE,CAClB,EAAoB,GAExB,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAc,CAAE,CACxD,IAAM,EAAc,IAAgB,GAC9B,EAAe,EAAqB,EAAO,EAAY,CAEzD,IAAiB,IAAA,KACnB,EAAO,GAAO,EACd,EAAoB,IAIxB,OAAO,EAAoB,EAAS,IAAA,IAWzB,GACX,EACA,IACe,CACf,GAAI,CAAC,GAAoB,CAAC,EAAiB,QAEzC,OAAO,EAGT,IAAM,EAAiB,EACrB,EAAiB,QACjB,EAAiB,QAClB,CAED,MAAO,CACL,GAAG,EACH,QAAS,GAAkB,EAAE,CAC9B"}
1
+ {"version":3,"file":"getFilterMissingContentPerLocale.cjs","names":[],"sources":["../../../src/fill/getFilterMissingContentPerLocale.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types';\n\n/**\n * Recursively compares source content with target content and returns only the missing parts.\n * For per-locale files where content is simple JSON (not translation nodes).\n *\n * @param sourceContent - The source content to check\n * @param targetContent - The existing target content\n * @returns Only the content that's missing in the target\n */\nconst filterMissingContent = (sourceContent: any, targetContent: any): any => {\n // Source is null - only missing if target doesn't already have null\n if (sourceContent === null) {\n return targetContent === null ? undefined : null;\n }\n\n // If target doesn't exist or is null, all source content is missing\n if (targetContent === undefined || targetContent === null) {\n return sourceContent;\n }\n\n // Primitive values: if target exists (even if empty string), consider it translated\n if (typeof sourceContent !== 'object') {\n return undefined;\n }\n\n // Handle arrays\n if (Array.isArray(sourceContent)) {\n if (!Array.isArray(targetContent)) {\n return sourceContent;\n }\n\n const missingItems = sourceContent\n .map((item, index) => filterMissingContent(item, targetContent[index]))\n .filter((item) => item !== undefined);\n\n return missingItems.length > 0 ? missingItems : undefined;\n }\n\n // Handle objects\n const result: any = {};\n let hasMissingContent = false;\n\n for (const [key, value] of Object.entries(sourceContent)) {\n const targetValue = targetContent?.[key];\n const missingValue = filterMissingContent(value, targetValue);\n\n if (missingValue !== undefined) {\n result[key] = missingValue;\n hasMissingContent = true;\n }\n }\n\n return hasMissingContent ? result : undefined;\n};\n\n/**\n * Filters a dictionary to only include content that's missing in the target dictionary.\n * Used for per-locale content declarations in 'complete' mode.\n *\n * @param sourceDictionary - The source dictionary with content to translate\n * @param targetDictionary - The existing target dictionary\n * @returns A dictionary with only the missing content\n */\nexport const getFilterMissingContentPerLocale = (\n sourceDictionary: Dictionary,\n targetDictionary: Dictionary | undefined\n): Dictionary => {\n if (!targetDictionary || !targetDictionary.content) {\n // If no target exists, all source content is missing\n return sourceDictionary;\n }\n\n const missingContent = filterMissingContent(\n sourceDictionary.content,\n targetDictionary.content\n );\n\n return {\n ...sourceDictionary,\n content: missingContent ?? {},\n };\n};\n"],"mappings":"mEAUA,MAAM,GAAwB,EAAoB,IAA4B,CAE5E,GAAI,IAAkB,KACpB,OAAO,IAAkB,KAAO,IAAA,GAAY,KAI9C,GAAI,GAAiD,KACnD,OAAO,EAIT,GAAI,OAAO,GAAkB,SAC3B,OAIF,GAAI,MAAM,QAAQ,EAAc,CAAE,CAChC,GAAI,CAAC,MAAM,QAAQ,EAAc,CAC/B,OAAO,EAGT,IAAM,EAAe,EAClB,KAAK,EAAM,IAAU,EAAqB,EAAM,EAAc,GAAO,CAAC,CACtE,OAAQ,GAAS,IAAS,IAAA,GAAU,CAEvC,OAAO,EAAa,OAAS,EAAI,EAAe,IAAA,GAIlD,IAAM,EAAc,EAAE,CAClB,EAAoB,GAExB,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAc,CAAE,CACxD,IAAM,EAAc,IAAgB,GAC9B,EAAe,EAAqB,EAAO,EAAY,CAEzD,IAAiB,IAAA,KACnB,EAAO,GAAO,EACd,EAAoB,IAIxB,OAAO,EAAoB,EAAS,IAAA,IAWzB,GACX,EACA,IACe,CACf,GAAI,CAAC,GAAoB,CAAC,EAAiB,QAEzC,OAAO,EAGT,IAAM,EAAiB,EACrB,EAAiB,QACjB,EAAiB,QAClB,CAED,MAAO,CACL,GAAG,EACH,QAAS,GAAkB,EAAE,CAC9B"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../test/listMissingTranslations.cjs`);let t=require(`@intlayer/chokidar/utils`),n=require(`node:path`),r=require(`@intlayer/config/logger`),i=require(`@intlayer/unmerged-dictionaries-entry`),a=require(`@intlayer/core/plugins`),o=require(`@intlayer/dictionaries-entry`);const s=(s,c,l,u,d)=>{let f=(0,r.getAppLogger)(d),p=(0,o.getDictionaries)(d),m=(0,i.getUnmergedDictionaries)(d),h=Object.values(m).flat().filter(e=>s.includes(e.localId)),{missingTranslations:g}=e.listMissingTranslationsWithConfig(d),_=Math.max(...h.map(e=>e.key.length)),v=[];for(let e of h){let i=(0,r.colon)([` - `,(0,r.colorize)(`[`,r.ANSIColors.GREY_DARK),(0,r.colorizeKey)(e.key),(0,r.colorize)(`]`,r.ANSIColors.GREY_DARK)].join(``),{colSize:_+6}),o=e.key,s=e.localId,m=p[o];if((e.filled??!1)===!0||(e.fill??d.dictionary?.fill??!1)===!1)continue;let h=e.locale??u;if(!m){f(`${i} Dictionary not found in dictionariesRecord. Skipping.`,{level:`warn`});continue}if(!e.filePath){f(`${i} Dictionary has no file path. Skipping.`,{level:`warn`});continue}let y=(0,a.getFilterTranslationsOnlyDictionary)(m,h);if(Object.keys(y).length===0){f(`${i} No content found for dictionary in source locale ${(0,t.formatLocale)(h)}. Skipping translation for this dictionary.`,{level:`warn`});continue}let b=c;if(l===`complete`&&(b=g.find(e=>e.key===o)?.locales.filter(e=>c.includes(e))??[]),b.length===0){f(`${i} ${(0,r.colorize)(`No locales to fill, Skipping`,r.ANSIColors.GREY_DARK)} ${(0,r.colorizePath)((0,n.basename)(e.filePath))}`,{level:`warn`});continue}v.push({dictionaryKey:o,dictionaryLocalId:s,sourceLocale:h,targetLocales:b,dictionaryPreset:i,dictionaryFilePath:e.filePath})}return v};exports.listTranslationsTasks=s;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../test/listMissingTranslations.cjs`);let t=require(`@intlayer/config/logger`),n=require(`@intlayer/chokidar/utils`),r=require(`node:path`),i=require(`@intlayer/unmerged-dictionaries-entry`),a=require(`@intlayer/core/plugins`),o=require(`@intlayer/dictionaries-entry`);const s=(s,c,l,u,d)=>{let f=(0,t.getAppLogger)(d),p=(0,o.getDictionaries)(d),m=(0,i.getUnmergedDictionaries)(d),h=Object.values(m).flat().filter(e=>s.includes(e.localId)),{missingTranslations:g}=e.listMissingTranslationsWithConfig(d),_=Math.max(...h.map(e=>e.key.length)),v=[];for(let e of h){let i=(0,t.colon)([` - `,(0,t.colorize)(`[`,t.ANSIColors.GREY_DARK),(0,t.colorizeKey)(e.key),(0,t.colorize)(`]`,t.ANSIColors.GREY_DARK)].join(``),{colSize:_+6}),o=e.key,s=e.localId,m=p[o];if((e.filled??!1)===!0||(e.fill??d.dictionary?.fill??!1)===!1)continue;let h=e.locale??u;if(!m){f(`${i} Dictionary not found in dictionariesRecord. Skipping.`,{level:`warn`});continue}if(!e.filePath){f(`${i} Dictionary has no file path. Skipping.`,{level:`warn`});continue}let y=(0,a.getFilterTranslationsOnlyDictionary)(m,h);if(Object.keys(y).length===0){f(`${i} No content found for dictionary in source locale ${(0,n.formatLocale)(h)}. Skipping translation for this dictionary.`,{level:`warn`});continue}let b=c;if(l===`complete`&&(b=g.find(e=>e.key===o)?.locales.filter(e=>c.includes(e))??[]),b.length===0){f(`${i} ${(0,t.colorize)(`No locales to fill, Skipping`,t.ANSIColors.GREY_DARK)} ${(0,t.colorizePath)((0,r.basename)(e.filePath))}`,{level:`warn`});continue}v.push({dictionaryKey:o,dictionaryLocalId:s,sourceLocale:h,targetLocales:b,dictionaryPreset:i,dictionaryFilePath:e.filePath})}return v};exports.listTranslationsTasks=s;
2
2
  //# sourceMappingURL=listTranslationsTasks.cjs.map
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./deepMergeContent.cjs`),t=require(`./getFilterMissingContentPerLocale.cjs`);let n=require(`@intlayer/api`),r=require(`@intlayer/chokidar/utils`),i=require(`node:path`),a=require(`@intlayer/config/logger`),o=require(`@intlayer/config/utils`),s=require(`@intlayer/unmerged-dictionaries-entry`),c=require(`@intlayer/core/plugins`);const l=e=>!e.description||!e.title||!e.tags,u=1e3*10;let d=0;const f=async(f,p,m)=>{let h=(0,a.getAppLogger)(p),g=(0,n.getIntlayerAPIProxy)(void 0,p),{mode:_,aiOptions:v,fillMetadata:y,aiClient:b,aiConfig:x}={mode:`complete`,fillMetadata:!0,...m},S=()=>{d=0,m?.onSuccess?.()};return await(0,o.retryManager)(async()=>{let n=(0,s.getUnmergedDictionaries)(p),C=n[f.dictionaryKey].find(e=>e.localId===f.dictionaryLocalId);if(!C)return h(`${f.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,{level:`warn`}),{...f,dictionaryOutput:null};let w;if(y&&(l(C)||_===`review`)){let e=(0,c.getPerLocaleDictionary)(C,p.internationalization.defaultLocale);h(`${f.dictionaryPreset} Filling missing metadata for ${(0,a.colorizePath)((0,i.basename)(C.filePath))}`,{level:`info`});let t=async()=>b&&x?{data:await b.auditDictionaryMetadata({fileContent:JSON.stringify(e),aiConfig:x})}:await g.ai.auditContentDeclarationMetadata({fileContent:JSON.stringify(e),aiOptions:v});w=(m?.onHandle?await m.onHandle(t):await t()).data?.fileContent}let T=await Promise.all(f.targetLocales.map(async s=>{let l=structuredClone(C),p;if(typeof C.locale==`string`){let e=C.filePath?.replace(RegExp(`/${f.sourceLocale}/`,`g`),`/${s}/`),r=e?n[f.dictionaryKey]?.find(t=>t.filePath===e&&t.locale===s):void 0;p=r??{key:C.key,content:{},filePath:e,locale:s},_===`complete`&&(l=t.getFilterMissingContentPerLocale(l,r))}else _===`complete`&&(l=(0,c.getFilterMissingTranslationsDictionary)(l,s)),l=(0,c.getPerLocaleDictionary)(l,f.sourceLocale),p=(0,c.getPerLocaleDictionary)(C,s);let y=(0,a.colon)([(0,a.colorize)(`[`,a.ANSIColors.GREY_DARK),(0,r.formatLocale)(s),(0,a.colorize)(`]`,a.ANSIColors.GREY_DARK)].join(``),{colSize:18}),T=(e,t)=>t<=1?``:(0,a.colon)([(0,a.colorize)(`[`,a.ANSIColors.GREY_DARK),(0,a.colorizeNumber)(e+1),(0,a.colorize)(`/${t}`,a.ANSIColors.GREY_DARK),(0,a.colorize)(`]`,a.ANSIColors.GREY_DARK)].join(``),{colSize:5});h(`${f.dictionaryPreset}${y} Preparing ${(0,a.colorizePath)((0,i.basename)(p.filePath))}`,{level:`info`});let E=typeof l.content==`object`&&l.content!==null||Array.isArray(l.content),D=(0,r.chunkJSON)(E?l.content:{__INTLAYER_ROOT_PRIMITIVE_CONTENT__:l.content},7e3),O=D.length;O>1&&h(`${f.dictionaryPreset}${y} Split into ${(0,a.colorizeNumber)(O)} chunks for translation`,{level:`info`});let k=[],A=D.map(e=>{let t=T(e.index,e.total);O>1&&h(`${f.dictionaryPreset}${y}${t} Translating chunk`,{level:`info`});let n=(0,r.reconstructFromSingleChunk)(e),i=(0,r.reduceObjectFormat)(E?p.content:{__INTLAYER_ROOT_PRIMITIVE_CONTENT__:p.content},n),c=async()=>await(0,o.retryManager)(async()=>{let e;if(e=b&&x?await b.translateJSON({entryFileContent:n,presetOutputContent:i,dictionaryDescription:l.description??w?.description??``,entryLocale:f.sourceLocale,outputLocale:s,mode:_,aiConfig:x}):await g.ai.translateJSON({entryFileContent:n,presetOutputContent:i,dictionaryDescription:l.description??w?.description??``,entryLocale:f.sourceLocale,outputLocale:s,mode:_,aiOptions:v}).then(e=>e.data),!e?.fileContent)throw Error(`No content result`);let{isIdentic:t}=(0,r.verifyIdenticObjectFormat)(e.fileContent,n);if(!t)throw Error(`Translation result does not match expected format`);return S(),e.fileContent},{maxRetry:3,delay:u,onError:({error:t,attempt:n,maxRetry:r})=>{let i=T(e.index,e.total);h(`${f.dictionaryPreset}${y}${i} ${(0,a.colorize)(`Error filling:`,a.ANSIColors.RED)} ${(0,a.colorize)(typeof t==`string`?t:JSON.stringify(t),a.ANSIColors.GREY_DARK)} - Attempt ${(0,a.colorizeNumber)(n+1)} of ${(0,a.colorizeNumber)(r)}`,{level:`error`}),d+=1,d>=10&&(h(`There is something wrong.`,{level:`error`}),process.exit(1))}})();return(m?.onHandle?m.onHandle(c):c()).then(t=>({chunk:e,result:t}))});(await Promise.all(A)).sort((e,t)=>e.chunk.index-t.chunk.index).forEach(({result:e})=>{k.push(e)});let j=(0,r.mergeChunks)(k),M={...l,content:j}.content;return E||(M=M?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__),typeof C.locale==`string`&&(M=e.deepMergeContent(p.content??{},M)),[s,M]})),E=Object.fromEntries(T),D={...(0,c.getMultilingualDictionary)(C.locale?{...C,key:C.key,content:{}}:C),locale:void 0,...w};for(let e of f.targetLocales)E[e]&&(D=(0,c.insertContentInDictionary)(D,E[e],e));if(h(`${f.dictionaryPreset} ${(0,a.colorize)(`Translation completed successfully`,a.ANSIColors.GREEN)} for ${(0,a.colorizePath)((0,i.basename)(D.filePath))}`,{level:`info`}),C.locale&&(C.fill===!0||C.fill===void 0)&&C.location===`local`){let e=C.filePath.split(`.`).slice(0,-1),t=e[e.length-1];return JSON.parse(JSON.stringify({...f,dictionaryOutput:{...D,fill:void 0,filled:!0}}).replaceAll(RegExp(`\\.${t}\\.[a-zA-Z0-9]+`,`g`),`.filled.${t}.json`))}return{...f,dictionaryOutput:D}},{maxRetry:2,delay:u,onError:({error:e,attempt:t,maxRetry:n})=>h(`${f.dictionaryPreset} ${(0,a.colorize)(`Error:`,a.ANSIColors.RED)} ${(0,a.colorize)(typeof e==`string`?e:JSON.stringify(e),a.ANSIColors.GREY_DARK)} - Attempt ${(0,a.colorizeNumber)(t+1)} of ${(0,a.colorizeNumber)(n)}`,{level:`error`}),onMaxTryReached:({error:e})=>h(`${f.dictionaryPreset} ${(0,a.colorize)(`Maximum number of retries reached:`,a.ANSIColors.RED)} ${(0,a.colorize)(typeof e==`string`?e:JSON.stringify(e),a.ANSIColors.GREY_DARK)}`,{level:`error`})})()};exports.translateDictionary=f;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./deepMergeContent.cjs`),t=require(`./getFilterMissingContentPerLocale.cjs`);let n=require(`@intlayer/api`),r=require(`@intlayer/config/logger`),i=require(`@intlayer/chokidar/utils`),a=require(`node:path`),o=require(`@intlayer/config/utils`),s=require(`@intlayer/unmerged-dictionaries-entry`),c=require(`@intlayer/core/plugins`);const l=e=>!e.description||!e.title||!e.tags,u=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return{content:e,nulls:void 0,hasNulls:!1};let t={},n={},r=!1;for(let[i,a]of Object.entries(e))if(a===null)n[i]=null,r=!0;else{let e=u(a);t[i]=e.content,e.hasNulls&&(n[i]=e.nulls,r=!0)}return{content:t,nulls:r?n:void 0,hasNulls:r}},d=1e3*10;let f=0;const p=async(p,m,h)=>{let g=(0,r.getAppLogger)(m),_=(0,n.getIntlayerAPIProxy)(void 0,m),{mode:v,aiOptions:y,fillMetadata:b,aiClient:x,aiConfig:S}={mode:`complete`,fillMetadata:!0,...h},C=()=>{f=0,h?.onSuccess?.()};return await(0,o.retryManager)(async()=>{let n=(0,s.getUnmergedDictionaries)(m),w=n[p.dictionaryKey].find(e=>e.localId===p.dictionaryLocalId);if(!w)return g(`${p.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,{level:`warn`}),{...p,dictionaryOutput:null};let T;if(b&&(l(w)||v===`review`)){let e=(0,c.getPerLocaleDictionary)(w,m.internationalization.defaultLocale);g(`${p.dictionaryPreset} Filling missing metadata for ${(0,r.colorizePath)((0,a.basename)(w.filePath))}`,{level:`info`});let t=async()=>x&&S?{data:await x.auditDictionaryMetadata({fileContent:JSON.stringify(e),aiConfig:S})}:await _.ai.auditContentDeclarationMetadata({fileContent:JSON.stringify(e),aiOptions:y});T=(h?.onHandle?await h.onHandle(t):await t()).data?.fileContent}let E=await Promise.all(p.targetLocales.map(async s=>{let l=structuredClone(w),m;if(typeof w.locale==`string`){let e=w.filePath?.replace(RegExp(`/${p.sourceLocale}/`,`g`),`/${s}/`),r=e?n[p.dictionaryKey]?.find(t=>t.filePath===e&&t.locale===s):void 0;m=r??{key:w.key,content:{},filePath:e,locale:s},v===`complete`&&(l=t.getFilterMissingContentPerLocale(l,r))}else v===`complete`&&(l=(0,c.getFilterMissingTranslationsDictionary)(l,s)),l=(0,c.getPerLocaleDictionary)(l,p.sourceLocale),m=(0,c.getPerLocaleDictionary)(w,s);let b=(0,r.colon)([(0,r.colorize)(`[`,r.ANSIColors.GREY_DARK),(0,i.formatLocale)(s),(0,r.colorize)(`]`,r.ANSIColors.GREY_DARK)].join(``),{colSize:18}),E=(e,t)=>t<=1?``:(0,r.colon)([(0,r.colorize)(`[`,r.ANSIColors.GREY_DARK),(0,r.colorizeNumber)(e+1),(0,r.colorize)(`/${t}`,r.ANSIColors.GREY_DARK),(0,r.colorize)(`]`,r.ANSIColors.GREY_DARK)].join(``),{colSize:5});g(`${p.dictionaryPreset}${b} Preparing ${(0,r.colorizePath)((0,a.basename)(m.filePath))}`,{level:`info`});let D=typeof l.content==`object`&&l.content!==null||Array.isArray(l.content),{content:O,nulls:k}=u(D?l.content:{__INTLAYER_ROOT_PRIMITIVE_CONTENT__:l.content}),A=(0,i.chunkJSON)(O,7e3),j=A.length;j>1&&g(`${p.dictionaryPreset}${b} Split into ${(0,r.colorizeNumber)(j)} chunks for translation`,{level:`info`});let M=[],N=A.map(e=>{let t=E(e.index,e.total);j>1&&g(`${p.dictionaryPreset}${b}${t} Translating chunk`,{level:`info`});let n=(0,i.reconstructFromSingleChunk)(e),a=(0,i.reduceObjectFormat)(D?m.content:{__INTLAYER_ROOT_PRIMITIVE_CONTENT__:m.content},n),c=async()=>await(0,o.retryManager)(async()=>{let e;if(e=x&&S?await x.translateJSON({entryFileContent:n,presetOutputContent:a,dictionaryDescription:l.description??T?.description??``,entryLocale:p.sourceLocale,outputLocale:s,mode:v,aiConfig:S}):await _.ai.translateJSON({entryFileContent:n,presetOutputContent:a,dictionaryDescription:l.description??T?.description??``,entryLocale:p.sourceLocale,outputLocale:s,mode:v,aiOptions:y}).then(e=>e.data),!e?.fileContent)throw Error(`No content result`);let{isIdentic:t}=(0,i.verifyIdenticObjectFormat)(e.fileContent,n);if(!t)throw Error(`Translation result does not match expected format`);return C(),e.fileContent},{maxRetry:3,delay:d,onError:({error:t,attempt:n,maxRetry:i})=>{let a=E(e.index,e.total);g(`${p.dictionaryPreset}${b}${a} ${(0,r.colorize)(`Error filling:`,r.ANSIColors.RED)} ${(0,r.colorize)(typeof t==`string`?t:JSON.stringify(t),r.ANSIColors.GREY_DARK)} - Attempt ${(0,r.colorizeNumber)(n+1)} of ${(0,r.colorizeNumber)(i)}`,{level:`error`}),f+=1,f>=10&&(g(`There is something wrong.`,{level:`error`}),process.exit(1))}})();return(h?.onHandle?h.onHandle(c):c()).then(t=>({chunk:e,result:t}))});(await Promise.all(N)).sort((e,t)=>e.chunk.index-t.chunk.index).forEach(({result:e})=>{M.push(e)});let P=(0,i.mergeChunks)(M);k&&(P=e.deepMergeContent(P,k));let F={...l,content:P}.content;return D||(F=F?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__),typeof w.locale==`string`&&(F=e.deepMergeContent(m.content??{},F)),[s,F]})),D=Object.fromEntries(E),O={...(0,c.getMultilingualDictionary)(w.locale?{...w,key:w.key,content:{}}:w),locale:void 0,...T};for(let e of p.targetLocales)D[e]&&(O=(0,c.insertContentInDictionary)(O,D[e],e));if(g(`${p.dictionaryPreset} ${(0,r.colorize)(`Translation completed successfully`,r.ANSIColors.GREEN)} for ${(0,r.colorizePath)((0,a.basename)(O.filePath))}`,{level:`info`}),w.locale&&(w.fill===!0||w.fill===void 0)&&w.location===`local`){let e=w.filePath.split(`.`).slice(0,-1),t=e[e.length-1];return JSON.parse(JSON.stringify({...p,dictionaryOutput:{...O,fill:void 0,filled:!0}}).replaceAll(RegExp(`\\.${t}\\.[a-zA-Z0-9]+`,`g`),`.filled.${t}.json`))}return{...p,dictionaryOutput:O}},{maxRetry:2,delay:d,onError:({error:e,attempt:t,maxRetry:n})=>g(`${p.dictionaryPreset} ${(0,r.colorize)(`Error:`,r.ANSIColors.RED)} ${(0,r.colorize)(typeof e==`string`?e:JSON.stringify(e),r.ANSIColors.GREY_DARK)} - Attempt ${(0,r.colorizeNumber)(t+1)} of ${(0,r.colorizeNumber)(n)}`,{level:`error`}),onMaxTryReached:({error:e})=>g(`${p.dictionaryPreset} ${(0,r.colorize)(`Maximum number of retries reached:`,r.ANSIColors.RED)} ${(0,r.colorize)(typeof e==`string`?e:JSON.stringify(e),r.ANSIColors.GREY_DARK)}`,{level:`error`})})()};exports.translateDictionary=p;
2
2
  //# sourceMappingURL=translateDictionary.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"translateDictionary.cjs","names":["getFilterMissingContentPerLocale","ANSIColors","deepMergeContent"],"sources":["../../../src/fill/translateDictionary.ts"],"sourcesContent":["import { basename } from 'node:path';\nimport type { AIConfig } from '@intlayer/ai';\nimport { type AIOptions, getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n chunkJSON,\n formatLocale,\n type JsonChunk,\n mergeChunks,\n reconstructFromSingleChunk,\n reduceObjectFormat,\n verifyIdenticObjectFormat,\n} from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport {\n getFilterMissingTranslationsDictionary,\n getMultilingualDictionary,\n getPerLocaleDictionary,\n insertContentInDictionary,\n} from '@intlayer/core/plugins';\nimport type { Dictionary, IntlayerConfig, Locale } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport type { AIClient } from '../utils/setupAI';\nimport { deepMergeContent } from './deepMergeContent';\nimport { getFilterMissingContentPerLocale } from './getFilterMissingContentPerLocale';\nimport type { TranslationTask } from './listTranslationsTasks';\n\ntype TranslateDictionaryResult = TranslationTask & {\n dictionaryOutput: Dictionary | null;\n};\n\ntype TranslateDictionaryOptions = {\n mode: 'complete' | 'review';\n aiOptions?: AIOptions;\n fillMetadata?: boolean;\n onHandle?: ReturnType<\n typeof import('@intlayer/chokidar/utils').getGlobalLimiter\n >;\n onSuccess?: () => void;\n onError?: (error: unknown) => void;\n getAbortError?: () => Error | null;\n aiClient?: AIClient;\n aiConfig?: AIConfig;\n};\n\nconst hasMissingMetadata = (dictionary: Dictionary) =>\n !dictionary.description || !dictionary.title || !dictionary.tags;\n\nconst CHUNK_SIZE = 7000; // GPT-5 Mini safe input size\nconst GROUP_MAX_RETRY = 2;\nconst MAX_RETRY = 3;\nconst RETRY_DELAY = 1000 * 10; // 10 seconds\n\nconst MAX_FOLLOWING_ERRORS = 10; // 10 errors in a row, hard exit the process\nlet followingErrors = 0;\n\nexport const translateDictionary = async (\n task: TranslationTask,\n configuration: IntlayerConfig,\n options?: TranslateDictionaryOptions\n): Promise<TranslateDictionaryResult> => {\n const appLogger = getAppLogger(configuration);\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n const { mode, aiOptions, fillMetadata, aiClient, aiConfig } = {\n mode: 'complete',\n fillMetadata: true,\n ...options,\n } as const;\n\n const notifySuccess = () => {\n followingErrors = 0;\n options?.onSuccess?.();\n };\n\n const result = await retryManager(\n async () => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n\n const baseUnmergedDictionary: Dictionary | undefined =\n unmergedDictionariesRecord[task.dictionaryKey].find(\n (dict) => dict.localId === task.dictionaryLocalId\n );\n\n if (!baseUnmergedDictionary) {\n appLogger(\n `${task.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n return { ...task, dictionaryOutput: null };\n }\n\n let metadata:\n | Pick<Dictionary, 'description' | 'title' | 'tags'>\n | undefined;\n\n if (\n fillMetadata &&\n (hasMissingMetadata(baseUnmergedDictionary) || mode === 'review')\n ) {\n const defaultLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n configuration.internationalization.defaultLocale\n );\n\n appLogger(\n `${task.dictionaryPreset} Filling missing metadata for ${colorizePath(basename(baseUnmergedDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const runAudit = async () => {\n if (aiClient && aiConfig) {\n const result = await aiClient.auditDictionaryMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiConfig,\n });\n\n return {\n data: result,\n };\n }\n\n return await intlayerAPI.ai.auditContentDeclarationMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiOptions,\n });\n };\n\n const metadataResult = options?.onHandle\n ? await options.onHandle(runAudit)\n : await runAudit();\n\n metadata = metadataResult.data?.fileContent;\n }\n\n const translatedContentResults = await Promise.all(\n task.targetLocales.map(async (targetLocale) => {\n /**\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * targetLocale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\n // Reset to base dictionary for each locale to ensure we filter from the original\n let dictionaryToProcess = structuredClone(baseUnmergedDictionary);\n\n let targetLocaleDictionary: Dictionary;\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // For per-locale files, the content is already in simple JSON format (not translation nodes)\n // The base dictionary is already the source locale content\n\n // Load the existing target locale dictionary\n const targetLocaleFilePath =\n baseUnmergedDictionary.filePath?.replace(\n new RegExp(`/${task.sourceLocale}/`, 'g'),\n `/${targetLocale}/`\n );\n\n // Find the target locale dictionary in unmerged dictionaries\n const targetUnmergedDictionary = targetLocaleFilePath\n ? unmergedDictionariesRecord[task.dictionaryKey]?.find(\n (dict) =>\n dict.filePath === targetLocaleFilePath &&\n dict.locale === targetLocale\n )\n : undefined;\n\n targetLocaleDictionary = targetUnmergedDictionary ?? {\n key: baseUnmergedDictionary.key,\n content: {},\n filePath: targetLocaleFilePath,\n locale: targetLocale,\n };\n\n // In complete mode, filter out already translated content\n if (mode === 'complete') {\n dictionaryToProcess = getFilterMissingContentPerLocale(\n dictionaryToProcess,\n targetUnmergedDictionary\n );\n }\n } else {\n // For multilingual dictionaries\n if (mode === 'complete') {\n // Remove all nodes that don't have any content to translate\n dictionaryToProcess = getFilterMissingTranslationsDictionary(\n dictionaryToProcess,\n targetLocale\n );\n }\n\n dictionaryToProcess = getPerLocaleDictionary(\n dictionaryToProcess,\n task.sourceLocale\n );\n\n targetLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n targetLocale\n );\n }\n\n const localePreset = colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n formatLocale(targetLocale),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 18 }\n );\n\n const createChunkPreset = (\n chunkIndex: number,\n totalChunks: number\n ) => {\n if (totalChunks <= 1) return '';\n return colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n colorizeNumber(chunkIndex + 1),\n colorize(`/${totalChunks}`, ANSIColors.GREY_DARK),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 5 }\n );\n };\n\n appLogger(\n `${task.dictionaryPreset}${localePreset} Preparing ${colorizePath(basename(targetLocaleDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const isContentStructured =\n (typeof dictionaryToProcess.content === 'object' &&\n dictionaryToProcess.content !== null) ||\n Array.isArray(dictionaryToProcess.content);\n\n const contentToProcess = isContentStructured\n ? dictionaryToProcess.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n dictionaryToProcess.content,\n };\n\n const chunkedJsonContent: JsonChunk[] = chunkJSON(\n contentToProcess as unknown as Record<string, any>,\n CHUNK_SIZE\n );\n\n const nbOfChunks = chunkedJsonContent.length;\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset} Split into ${colorizeNumber(nbOfChunks)} chunks for translation`,\n {\n level: 'info',\n }\n );\n }\n\n const chunkResult: JsonChunk[] = [];\n\n // Process chunks in parallel (globally throttled) to allow concurrent translation\n const chunkPromises = chunkedJsonContent.map((chunk) => {\n const chunkPreset = createChunkPreset(chunk.index, chunk.total);\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} Translating chunk`,\n {\n level: 'info',\n }\n );\n }\n\n // Reconstruct partial JSON content from this chunk's patches\n const chunkContent = reconstructFromSingleChunk(chunk);\n const presetOutputContent = reduceObjectFormat(\n isContentStructured\n ? targetLocaleDictionary.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n targetLocaleDictionary.content,\n },\n chunkContent\n ) as unknown as JSON;\n\n const executeTranslation = async () => {\n return await retryManager(\n async () => {\n let translationResult: any;\n\n if (aiClient && aiConfig) {\n translationResult = await aiClient.translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiConfig,\n });\n } else {\n translationResult = await intlayerAPI.ai\n .translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions,\n })\n .then((result) => result.data);\n }\n\n if (!translationResult?.fileContent) {\n throw new Error('No content result');\n }\n\n const { isIdentic } = verifyIdenticObjectFormat(\n translationResult.fileContent,\n chunkContent\n );\n\n if (!isIdentic) {\n throw new Error(\n 'Translation result does not match expected format'\n );\n }\n\n notifySuccess();\n return translationResult.fileContent;\n },\n {\n maxRetry: MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) => {\n const chunkPreset = createChunkPreset(\n chunk.index,\n chunk.total\n );\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} ${colorize('Error filling:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n );\n\n followingErrors += 1;\n\n if (followingErrors >= MAX_FOLLOWING_ERRORS) {\n appLogger(`There is something wrong.`, {\n level: 'error',\n });\n process.exit(1); // 1 for error\n }\n },\n }\n )();\n };\n\n const wrapped = options?.onHandle\n ? options.onHandle(executeTranslation) // queued in global limiter\n : executeTranslation(); // no global limiter\n\n return wrapped.then((result) => ({ chunk, result }));\n });\n\n // Wait for all chunks for this locale in parallel (still capped by global limiter)\n const chunkResults = await Promise.all(chunkPromises);\n\n // Maintain order\n chunkResults\n .sort((chunkA, chunkB) => chunkA.chunk.index - chunkB.chunk.index)\n .forEach(({ result }) => {\n chunkResult.push(result);\n });\n\n // Merge partial JSON objects produced from each chunk into a single object\n const mergedContent = mergeChunks(chunkResult);\n\n const merged = {\n ...dictionaryToProcess,\n content: mergedContent,\n };\n\n // For per-locale files, merge the newly translated content with existing target content\n let finalContent = merged.content;\n\n if (!isContentStructured) {\n finalContent = (finalContent as any)\n ?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__;\n }\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // Deep merge: existing content + newly translated content\n finalContent = deepMergeContent(\n targetLocaleDictionary.content ?? {},\n finalContent\n );\n }\n\n return [targetLocale, finalContent] as const;\n })\n );\n\n const translatedContent: Partial<Record<Locale, Dictionary['content']>> =\n Object.fromEntries(translatedContentResults);\n\n const baseDictionary = baseUnmergedDictionary.locale\n ? {\n ...baseUnmergedDictionary,\n key: baseUnmergedDictionary.key!,\n content: {},\n }\n : baseUnmergedDictionary;\n\n let dictionaryOutput: Dictionary = {\n ...getMultilingualDictionary(baseDictionary),\n locale: undefined, // Ensure the dictionary is multilingual\n ...metadata,\n };\n\n for (const targetLocale of task.targetLocales) {\n if (translatedContent[targetLocale]) {\n dictionaryOutput = insertContentInDictionary(\n dictionaryOutput,\n translatedContent[targetLocale],\n targetLocale\n );\n }\n }\n\n appLogger(\n `${task.dictionaryPreset} ${colorize('Translation completed successfully', ANSIColors.GREEN)} for ${colorizePath(basename(dictionaryOutput.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n if (\n baseUnmergedDictionary.locale &&\n (baseUnmergedDictionary.fill === true ||\n baseUnmergedDictionary.fill === undefined) &&\n baseUnmergedDictionary.location === 'local'\n ) {\n const dictionaryFilePath = baseUnmergedDictionary\n .filePath!.split('.')\n .slice(0, -1);\n\n const contentIndex = dictionaryFilePath[dictionaryFilePath.length - 1];\n\n return JSON.parse(\n JSON.stringify({\n ...task,\n dictionaryOutput: {\n ...dictionaryOutput,\n fill: undefined,\n filled: true,\n },\n }).replaceAll(\n new RegExp(`\\\\.${contentIndex}\\\\.[a-zA-Z0-9]+`, 'g'),\n `.filled.${contentIndex}.json`\n )\n );\n }\n\n return {\n ...task,\n dictionaryOutput,\n };\n },\n {\n maxRetry: GROUP_MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Error:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n ),\n onMaxTryReached: ({ error }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Maximum number of retries reached:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)}`,\n {\n level: 'error',\n }\n ),\n }\n )();\n\n return result as TranslateDictionaryResult;\n};\n"],"mappings":"0cAoDA,MAAM,EAAsB,GAC1B,CAAC,EAAW,aAAe,CAAC,EAAW,OAAS,CAAC,EAAW,KAKxD,EAAc,IAAO,GAG3B,IAAI,EAAkB,EAEtB,MAAa,EAAsB,MACjC,EACA,EACA,IACuC,CACvC,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CACvC,GAAA,EAAA,EAAA,qBAAkC,IAAA,GAAW,EAAc,CAE3D,CAAE,OAAM,YAAW,eAAc,WAAU,YAAa,CAC5D,KAAM,WACN,aAAc,GACd,GAAG,EACJ,CAEK,MAAsB,CAC1B,EAAkB,EAClB,GAAS,aAAa,EAqbxB,OAlbe,MAAA,EAAA,EAAA,cACb,SAAY,CACV,IAAM,GAAA,EAAA,EAAA,yBAAqD,EAAc,CAEnE,EACJ,EAA2B,EAAK,eAAe,KAC5C,GAAS,EAAK,UAAY,EAAK,kBACjC,CAEH,GAAI,CAAC,EAOH,OANA,EACE,GAAG,EAAK,iBAAiB,+DACzB,CACE,MAAO,OACR,CACF,CACM,CAAE,GAAG,EAAM,iBAAkB,KAAM,C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IAAA,EAAA,EAAA,UAAY,OAAO,GAAU,SAAW,EAAQ,KAAK,UAAU,EAAM,CAAEA,EAAAA,WAAW,UAAU,CAAC,cAAA,EAAA,EAAA,gBAA4B,EAAU,EAAE,CAAC,OAAA,EAAA,EAAA,gBAAqB,EAAS,GACnO,CACE,MAAO,QACR,CACF,CACH,iBAAkB,CAAE,WAClB,EACE,GAAG,EAAK,iBAAiB,IAAA,EAAA,EAAA,UAAY,qCAAsCA,EAAAA,WAAW,IAAI,CAAC,IAAA,EAAA,EAAA,UAAY,OAAO,GAAU,SAAW,EAAQ,KAAK,UAAU,EAAM,CAAEA,EAAAA,WAAW,UAAU,GACvL,CACE,MAAO,QACR,CACF,CACJ,CACF,EAAE"}
1
+ {"version":3,"file":"translateDictionary.cjs","names":["getFilterMissingContentPerLocale","ANSIColors","deepMergeContent"],"sources":["../../../src/fill/translateDictionary.ts"],"sourcesContent":["import { basename } from 'node:path';\nimport type { AIConfig } from '@intlayer/ai';\nimport { type AIOptions, getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n chunkJSON,\n formatLocale,\n type JsonChunk,\n mergeChunks,\n reconstructFromSingleChunk,\n reduceObjectFormat,\n verifyIdenticObjectFormat,\n} from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport {\n getFilterMissingTranslationsDictionary,\n getMultilingualDictionary,\n getPerLocaleDictionary,\n insertContentInDictionary,\n} from '@intlayer/core/plugins';\nimport type { Dictionary, IntlayerConfig, Locale } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport type { AIClient } from '../utils/setupAI';\nimport { deepMergeContent } from './deepMergeContent';\nimport { getFilterMissingContentPerLocale } from './getFilterMissingContentPerLocale';\nimport type { TranslationTask } from './listTranslationsTasks';\n\ntype TranslateDictionaryResult = TranslationTask & {\n dictionaryOutput: Dictionary | null;\n};\n\ntype TranslateDictionaryOptions = {\n mode: 'complete' | 'review';\n aiOptions?: AIOptions;\n fillMetadata?: boolean;\n onHandle?: ReturnType<\n typeof import('@intlayer/chokidar/utils').getGlobalLimiter\n >;\n onSuccess?: () => void;\n onError?: (error: unknown) => void;\n getAbortError?: () => Error | null;\n aiClient?: AIClient;\n aiConfig?: AIConfig;\n};\n\nconst hasMissingMetadata = (dictionary: Dictionary) =>\n !dictionary.description || !dictionary.title || !dictionary.tags;\n\n/**\n * Recursively strips null values from an object, returning the cleaned content\n * and a separate object containing only the null-valued paths so they can be\n * re-injected after AI translation (nulls don't need translation).\n */\nconst stripNullValues = (\n obj: any\n): { content: any; nulls: any; hasNulls: boolean } => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return { content: obj, nulls: undefined, hasNulls: false };\n }\n\n const content: any = {};\n const nulls: any = {};\n let hasNulls = false;\n\n for (const [key, value] of Object.entries(obj)) {\n if (value === null) {\n nulls[key] = null;\n hasNulls = true;\n } else {\n const child = stripNullValues(value);\n content[key] = child.content;\n if (child.hasNulls) {\n nulls[key] = child.nulls;\n hasNulls = true;\n }\n }\n }\n\n return { content, nulls: hasNulls ? nulls : undefined, hasNulls };\n};\n\nconst CHUNK_SIZE = 7000; // GPT-5 Mini safe input size\nconst GROUP_MAX_RETRY = 2;\nconst MAX_RETRY = 3;\nconst RETRY_DELAY = 1000 * 10; // 10 seconds\n\nconst MAX_FOLLOWING_ERRORS = 10; // 10 errors in a row, hard exit the process\nlet followingErrors = 0;\n\nexport const translateDictionary = async (\n task: TranslationTask,\n configuration: IntlayerConfig,\n options?: TranslateDictionaryOptions\n): Promise<TranslateDictionaryResult> => {\n const appLogger = getAppLogger(configuration);\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n const { mode, aiOptions, fillMetadata, aiClient, aiConfig } = {\n mode: 'complete',\n fillMetadata: true,\n ...options,\n } as const;\n\n const notifySuccess = () => {\n followingErrors = 0;\n options?.onSuccess?.();\n };\n\n const result = await retryManager(\n async () => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n\n const baseUnmergedDictionary: Dictionary | undefined =\n unmergedDictionariesRecord[task.dictionaryKey].find(\n (dict) => dict.localId === task.dictionaryLocalId\n );\n\n if (!baseUnmergedDictionary) {\n appLogger(\n `${task.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n return { ...task, dictionaryOutput: null };\n }\n\n let metadata:\n | Pick<Dictionary, 'description' | 'title' | 'tags'>\n | undefined;\n\n if (\n fillMetadata &&\n (hasMissingMetadata(baseUnmergedDictionary) || mode === 'review')\n ) {\n const defaultLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n configuration.internationalization.defaultLocale\n );\n\n appLogger(\n `${task.dictionaryPreset} Filling missing metadata for ${colorizePath(basename(baseUnmergedDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const runAudit = async () => {\n if (aiClient && aiConfig) {\n const result = await aiClient.auditDictionaryMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiConfig,\n });\n\n return {\n data: result,\n };\n }\n\n return await intlayerAPI.ai.auditContentDeclarationMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiOptions,\n });\n };\n\n const metadataResult = options?.onHandle\n ? await options.onHandle(runAudit)\n : await runAudit();\n\n metadata = metadataResult.data?.fileContent;\n }\n\n const translatedContentResults = await Promise.all(\n task.targetLocales.map(async (targetLocale) => {\n /**\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * targetLocale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\n // Reset to base dictionary for each locale to ensure we filter from the original\n let dictionaryToProcess = structuredClone(baseUnmergedDictionary);\n\n let targetLocaleDictionary: Dictionary;\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // For per-locale files, the content is already in simple JSON format (not translation nodes)\n // The base dictionary is already the source locale content\n\n // Load the existing target locale dictionary\n const targetLocaleFilePath =\n baseUnmergedDictionary.filePath?.replace(\n new RegExp(`/${task.sourceLocale}/`, 'g'),\n `/${targetLocale}/`\n );\n\n // Find the target locale dictionary in unmerged dictionaries\n const targetUnmergedDictionary = targetLocaleFilePath\n ? unmergedDictionariesRecord[task.dictionaryKey]?.find(\n (dict) =>\n dict.filePath === targetLocaleFilePath &&\n dict.locale === targetLocale\n )\n : undefined;\n\n targetLocaleDictionary = targetUnmergedDictionary ?? {\n key: baseUnmergedDictionary.key,\n content: {},\n filePath: targetLocaleFilePath,\n locale: targetLocale,\n };\n\n // In complete mode, filter out already translated content\n if (mode === 'complete') {\n dictionaryToProcess = getFilterMissingContentPerLocale(\n dictionaryToProcess,\n targetUnmergedDictionary\n );\n }\n } else {\n // For multilingual dictionaries\n if (mode === 'complete') {\n // Remove all nodes that don't have any content to translate\n dictionaryToProcess = getFilterMissingTranslationsDictionary(\n dictionaryToProcess,\n targetLocale\n );\n }\n\n dictionaryToProcess = getPerLocaleDictionary(\n dictionaryToProcess,\n task.sourceLocale\n );\n\n targetLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n targetLocale\n );\n }\n\n const localePreset = colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n formatLocale(targetLocale),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 18 }\n );\n\n const createChunkPreset = (\n chunkIndex: number,\n totalChunks: number\n ) => {\n if (totalChunks <= 1) return '';\n return colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n colorizeNumber(chunkIndex + 1),\n colorize(`/${totalChunks}`, ANSIColors.GREY_DARK),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 5 }\n );\n };\n\n appLogger(\n `${task.dictionaryPreset}${localePreset} Preparing ${colorizePath(basename(targetLocaleDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const isContentStructured =\n (typeof dictionaryToProcess.content === 'object' &&\n dictionaryToProcess.content !== null) ||\n Array.isArray(dictionaryToProcess.content);\n\n const rawContentToProcess = isContentStructured\n ? dictionaryToProcess.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n dictionaryToProcess.content,\n };\n\n // Strip null values before sending to AI — nulls need no translation\n // and confuse the model. They will be re-injected after merging.\n const { content: contentToProcess, nulls: strippedNullValues } =\n stripNullValues(rawContentToProcess);\n\n const chunkedJsonContent: JsonChunk[] = chunkJSON(\n contentToProcess as unknown as Record<string, any>,\n CHUNK_SIZE\n );\n\n const nbOfChunks = chunkedJsonContent.length;\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset} Split into ${colorizeNumber(nbOfChunks)} chunks for translation`,\n {\n level: 'info',\n }\n );\n }\n\n const chunkResult: JsonChunk[] = [];\n\n // Process chunks in parallel (globally throttled) to allow concurrent translation\n const chunkPromises = chunkedJsonContent.map((chunk) => {\n const chunkPreset = createChunkPreset(chunk.index, chunk.total);\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} Translating chunk`,\n {\n level: 'info',\n }\n );\n }\n\n // Reconstruct partial JSON content from this chunk's patches\n const chunkContent = reconstructFromSingleChunk(chunk);\n const presetOutputContent = reduceObjectFormat(\n isContentStructured\n ? targetLocaleDictionary.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n targetLocaleDictionary.content,\n },\n chunkContent\n ) as unknown as JSON;\n\n const executeTranslation = async () => {\n return await retryManager(\n async () => {\n let translationResult: any;\n\n if (aiClient && aiConfig) {\n translationResult = await aiClient.translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiConfig,\n });\n } else {\n translationResult = await intlayerAPI.ai\n .translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions,\n })\n .then((result) => result.data);\n }\n\n if (!translationResult?.fileContent) {\n throw new Error('No content result');\n }\n\n const { isIdentic } = verifyIdenticObjectFormat(\n translationResult.fileContent,\n chunkContent\n );\n\n if (!isIdentic) {\n throw new Error(\n 'Translation result does not match expected format'\n );\n }\n\n notifySuccess();\n return translationResult.fileContent;\n },\n {\n maxRetry: MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) => {\n const chunkPreset = createChunkPreset(\n chunk.index,\n chunk.total\n );\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} ${colorize('Error filling:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n );\n\n followingErrors += 1;\n\n if (followingErrors >= MAX_FOLLOWING_ERRORS) {\n appLogger(`There is something wrong.`, {\n level: 'error',\n });\n process.exit(1); // 1 for error\n }\n },\n }\n )();\n };\n\n const wrapped = options?.onHandle\n ? options.onHandle(executeTranslation) // queued in global limiter\n : executeTranslation(); // no global limiter\n\n return wrapped.then((result) => ({ chunk, result }));\n });\n\n // Wait for all chunks for this locale in parallel (still capped by global limiter)\n const chunkResults = await Promise.all(chunkPromises);\n\n // Maintain order\n chunkResults\n .sort((chunkA, chunkB) => chunkA.chunk.index - chunkB.chunk.index)\n .forEach(({ result }) => {\n chunkResult.push(result);\n });\n\n // Merge partial JSON objects produced from each chunk into a single object\n let mergedContent = mergeChunks(chunkResult);\n\n // Re-inject null values that were stripped before AI translation\n if (strippedNullValues) {\n mergedContent = deepMergeContent(mergedContent, strippedNullValues);\n }\n\n const merged = {\n ...dictionaryToProcess,\n content: mergedContent,\n };\n\n // For per-locale files, merge the newly translated content with existing target content\n let finalContent = merged.content;\n\n if (!isContentStructured) {\n finalContent = (finalContent as any)\n ?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__;\n }\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // Deep merge: existing content + newly translated content\n finalContent = deepMergeContent(\n targetLocaleDictionary.content ?? {},\n finalContent\n );\n }\n\n return [targetLocale, finalContent] as const;\n })\n );\n\n const translatedContent: Partial<Record<Locale, Dictionary['content']>> =\n Object.fromEntries(translatedContentResults);\n\n const baseDictionary = baseUnmergedDictionary.locale\n ? {\n ...baseUnmergedDictionary,\n key: baseUnmergedDictionary.key!,\n content: {},\n }\n : baseUnmergedDictionary;\n\n let dictionaryOutput: Dictionary = {\n ...getMultilingualDictionary(baseDictionary),\n locale: undefined, // Ensure the dictionary is multilingual\n ...metadata,\n };\n\n for (const targetLocale of task.targetLocales) {\n if (translatedContent[targetLocale]) {\n dictionaryOutput = insertContentInDictionary(\n dictionaryOutput,\n translatedContent[targetLocale],\n targetLocale\n );\n }\n }\n\n appLogger(\n `${task.dictionaryPreset} ${colorize('Translation completed successfully', ANSIColors.GREEN)} for ${colorizePath(basename(dictionaryOutput.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n if (\n baseUnmergedDictionary.locale &&\n (baseUnmergedDictionary.fill === true ||\n baseUnmergedDictionary.fill === undefined) &&\n baseUnmergedDictionary.location === 'local'\n ) {\n const dictionaryFilePath = baseUnmergedDictionary\n .filePath!.split('.')\n .slice(0, -1);\n\n const contentIndex = dictionaryFilePath[dictionaryFilePath.length - 1];\n\n return JSON.parse(\n JSON.stringify({\n ...task,\n dictionaryOutput: {\n ...dictionaryOutput,\n fill: undefined,\n filled: true,\n },\n }).replaceAll(\n new RegExp(`\\\\.${contentIndex}\\\\.[a-zA-Z0-9]+`, 'g'),\n `.filled.${contentIndex}.json`\n )\n );\n }\n\n return {\n ...task,\n dictionaryOutput,\n };\n },\n {\n maxRetry: GROUP_MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Error:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n ),\n onMaxTryReached: ({ error }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Maximum number of retries reached:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)}`,\n {\n level: 'error',\n }\n ),\n }\n )();\n\n return result as TranslateDictionaryResult;\n};\n"],"mappings":"0cAoDA,MAAM,EAAsB,GAC1B,CAAC,EAAW,aAAe,CAAC,EAAW,OAAS,CAAC,EAAW,KAOxD,EACJ,GACoD,CACpD,GAAI,OAAO,GAAQ,WAAY,GAAgB,MAAM,QAAQ,EAAI,CAC/D,MAAO,CAAE,QAAS,EAAK,MAAO,IAAA,GAAW,SAAU,GAAO,CAG5D,IAAM,EAAe,EAAE,CACjB,EAAa,EAAE,CACjB,EAAW,GAEf,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAI,CAC5C,GAAI,IAAU,KACZ,EAAM,GAAO,KACb,EAAW,OACN,CACL,IAAM,EAAQ,EAAgB,EAAM,CACpC,EAAQ,GAAO,EAAM,QACjB,EAAM,WACR,EAAM,GAAO,EAAM,MACnB,EAAW,IAKjB,MAAO,CAAE,UAAS,MAAO,EAAW,EAAQ,IAAA,GAAW,WAAU,EAM7D,EAAc,IAAO,GAG3B,IAAI,EAAkB,EAEtB,MAAa,EAAsB,MACjC,EACA,EACA,IACuC,CACvC,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CACvC,GAAA,EAAA,EAAA,qBAAkC,IAAA,GAAW,EAAc,CAE3D,CAA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AAS,IAAA,KAClC,EAAuB,WAAa,QACpC,CACA,IAAM,EAAqB,EACxB,SAAU,MAAM,IAAI,CACpB,MAAM,EAAG,GAAG,CAET,EAAe,EAAmB,EAAmB,OAAS,GAEpE,OAAO,KAAK,MACV,KAAK,UAAU,CACb,GAAG,EACH,iBAAkB,CAChB,GAAG,EACH,KAAM,IAAA,GACN,OAAQ,GACT,CACF,CAAC,CAAC,WACG,OAAO,MAAM,EAAa,iBAAkB,IAAI,CACpD,WAAW,EAAa,OACzB,CACF,CAGH,MAAO,CACL,GAAG,EACH,mBACD,EAEH,CACE,SAAU,EACV,MAAO,EACP,SAAU,CAAE,QAAO,UAAS,cAC1B,EACE,GAAG,EAAK,iBAAiB,IAAA,EAAA,EAAA,UAAY,SAAUA,EAAAA,WAAW,IAAI,CAAC,IAAA,EAAA,EAAA,UAAY,OAAO,GAAU,SAAW,EAAQ,KAAK,UAAU,EAAM,CAAEA,EAAAA,WAAW,UAAU,CAAC,cAAA,EAAA,EAAA,gBAA4B,EAAU,EAAE,CAAC,OAAA,EAAA,EAAA,gBAAqB,EAAS,GACnO,CACE,MAAO,QACR,CACF,CACH,iBAAkB,CAAE,WAClB,EACE,GAAG,EAAK,iBAAiB,IAAA,EAAA,EAAA,UAAY,qCAAsCA,EAAAA,WAAW,IAAI,CAAC,IAAA,EAAA,EAAA,UAAY,OAAO,GAAU,SAAW,EAAQ,KAAK,UAAU,EAAM,CAAEA,EAAAA,WAAW,UAAU,GACvL,CACE,MAAO,QACR,CACF,CACJ,CACF,EAAE"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./formatFillData.cjs`),t=require(`./getAvailableLocalesInDictionary.cjs`);let n=require(`@intlayer/chokidar/utils`),r=require(`node:path`),i=require(`@intlayer/config/logger`),a=require(`@intlayer/chokidar/build`),o=require(`@intlayer/dictionaries-entry`);const s=async(s,c,l,u)=>{let d=(0,i.getAppLogger)(u),f=(0,o.getDictionaries)(u)[s.key],{filePath:p}=s;if(!p){d(`No file path found for dictionary`,{level:`error`});return}let m=s.fill??u.dictionary?.fill??!0;if(m===!1){d(`Auto fill is disabled for '${(0,i.colorizeKey)(f.key)}'`,{level:`info`});return}let h=(c??u.internationalization.locales).filter(e=>!l?.includes(e)),g=t.getAvailableLocalesInDictionary(s),_=h.filter(e=>g.includes(e));if(_.length===0){d(`No translations available for dictionary '${(0,i.colorizeKey)(f.key)}'`,{level:`info`});return}let v=e.formatFillData(m,_,p,f.key,u);for await(let e of v){if(!e.filePath){d(`No file path found for auto filled content declaration for '${(0,i.colorizeKey)(f.key)}'`,{level:`error`});continue}let{fill:t,...o}=s,c=(0,r.relative)(u.content.baseDir,e.filePath);if(await(0,a.writeContentDeclaration)({...o,filled:!0,locale:e.isPerLocale?e.localeList[0]:void 0,localId:`${s.key}::local::${c}`,filePath:c},u,{localeList:e.localeList}),e.isPerLocale){let t=e.localeList[0];d(`Auto filled per-locale content declaration for '${(0,i.colorizeKey)(f.key)}' written to ${(0,n.formatPath)(e.filePath)} for locale ${(0,n.formatLocale)(t)}`,{level:`info`})}else d(`Auto filled content declaration for '${(0,i.colorizeKey)(f.key)}' written to ${(0,n.formatPath)(e.filePath)}`,{level:`info`})}};exports.writeFill=s;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./formatFillData.cjs`),t=require(`./getAvailableLocalesInDictionary.cjs`);let n=require(`@intlayer/config/logger`),r=require(`@intlayer/chokidar/utils`),i=require(`node:path`),a=require(`@intlayer/chokidar/build`),o=require(`@intlayer/dictionaries-entry`);const s=async(s,c,l,u)=>{let d=(0,n.getAppLogger)(u),f=(0,o.getDictionaries)(u)[s.key],{filePath:p}=s;if(!p){d(`No file path found for dictionary`,{level:`error`});return}let m=s.fill??u.dictionary?.fill??!0;if(m===!1){d(`Auto fill is disabled for '${(0,n.colorizeKey)(f.key)}'`,{level:`info`});return}let h=(c??u.internationalization.locales).filter(e=>!l?.includes(e)),g=t.getAvailableLocalesInDictionary(s),_=h.filter(e=>g.includes(e));if(_.length===0){d(`No translations available for dictionary '${(0,n.colorizeKey)(f.key)}'`,{level:`info`});return}let v=e.formatFillData(m,_,p,f.key,u);for await(let e of v){if(!e.filePath){d(`No file path found for auto filled content declaration for '${(0,n.colorizeKey)(f.key)}'`,{level:`error`});continue}let{fill:t,...o}=s,c=(0,i.relative)(u.content.baseDir,e.filePath);if(await(0,a.writeContentDeclaration)({...o,filled:!0,locale:e.isPerLocale?e.localeList[0]:void 0,localId:`${s.key}::local::${c}`,filePath:c},u,{localeList:e.localeList}),e.isPerLocale){let t=e.localeList[0];d(`Auto filled per-locale content declaration for '${(0,n.colorizeKey)(f.key)}' written to ${(0,r.formatPath)(e.filePath)} for locale ${(0,r.formatLocale)(t)}`,{level:`info`})}else d(`Auto filled content declaration for '${(0,n.colorizeKey)(f.key)}' written to ${(0,r.formatPath)(e.filePath)}`,{level:`info`})}};exports.writeFill=s;
2
2
  //# sourceMappingURL=writeFill.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeFill.cjs","names":["getAvailableLocalesInDictionary","formatFillData"],"sources":["../../../src/fill/writeFill.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport { writeContentDeclaration } from '@intlayer/chokidar/build';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, Fill, IntlayerConfig, Locale } from '@intlayer/types';\nimport { type FillData, formatFillData } from './formatFillData';\nimport { getAvailableLocalesInDictionary } from './getAvailableLocalesInDictionary';\n\nexport const writeFill = async (\n contentDeclarationFile: Dictionary,\n outputLocales: Locale[],\n parentLocales: Locale[],\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n const dictionaries = getDictionaries(configuration);\n\n const fullDictionary = dictionaries[contentDeclarationFile.key];\n\n const { filePath } = contentDeclarationFile;\n\n if (!filePath) {\n appLogger('No file path found for dictionary', {\n level: 'error',\n });\n return;\n }\n\n const fillOptions: Fill | undefined =\n contentDeclarationFile.fill ?? configuration.dictionary?.fill ?? true;\n\n if ((fillOptions as boolean) === false) {\n appLogger(\n `Auto fill is disabled for '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'info',\n }\n );\n return;\n }\n\n const requestedLocales: Locale[] = (\n outputLocales ?? configuration.internationalization.locales\n ).filter((locale) => !parentLocales?.includes(locale));\n\n // Get locales that actually have translations in the content\n const availableLocales = getAvailableLocalesInDictionary(\n contentDeclarationFile\n );\n\n // Only write files for locales that have actual translations\n const localeList = requestedLocales.filter((locale) =>\n availableLocales.includes(locale)\n );\n\n if (localeList.length === 0) {\n appLogger(\n `No translations available for dictionary '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'info',\n }\n );\n return;\n }\n\n const fillData: FillData[] = formatFillData(\n fillOptions as Fill,\n localeList,\n filePath,\n fullDictionary.key,\n configuration\n );\n\n for await (const output of fillData) {\n if (!output.filePath) {\n appLogger(\n `No file path found for auto filled content declaration for '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'error',\n }\n );\n continue;\n }\n\n // biome-ignore lint/correctness/noUnusedVariables: Just filtering out the fill property\n const { fill, ...rest } = contentDeclarationFile;\n\n const relativeFilePath = relative(\n configuration.content.baseDir,\n output.filePath\n );\n\n // write file\n await writeContentDeclaration(\n {\n ...rest,\n filled: true,\n locale: output.isPerLocale ? output.localeList[0] : undefined,\n localId: `${contentDeclarationFile.key}::local::${relativeFilePath}`,\n filePath: relativeFilePath,\n },\n configuration,\n {\n localeList: output.localeList,\n }\n );\n\n if (output.isPerLocale) {\n const sourceLocale = output.localeList[0];\n\n appLogger(\n `Auto filled per-locale content declaration for '${colorizeKey(fullDictionary.key)}' written to ${formatPath(output.filePath)} for locale ${formatLocale(sourceLocale)}`,\n {\n level: 'info',\n }\n );\n } else {\n appLogger(\n `Auto filled content declaration for '${colorizeKey(fullDictionary.key)}' written to ${formatPath(output.filePath)}`,\n {\n level: 'info',\n }\n );\n }\n }\n};\n"],"mappings":"iYASA,MAAa,EAAY,MACvB,EACA,EACA,EACA,IACG,CACH,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAGvC,GAAA,EAAA,EAAA,iBAF+B,EAAc,CAEf,EAAuB,KAErD,CAAE,YAAa,EAErB,GAAI,CAAC,EAAU,CACb,EAAU,oCAAqC,CAC7C,MAAO,QACR,CAAC,CACF,OAGF,IAAM,EACJ,EAAuB,MAAQ,EAAc,YAAY,MAAQ,GAEnE,GAAK,IAA4B,GAAO,CACtC,EACE,+BAAA,EAAA,EAAA,aAA0C,EAAe,IAAI,CAAC,GAC9D,CACE,MAAO,OACR,CACF,CACD,OAGF,IAAM,GACJ,GAAiB,EAAc,qBAAqB,SACpD,OAAQ,GAAW,CAAC,GAAe,SAAS,EAAO,CAAC,CAGhD,EAAmBA,EAAAA,gCACvB,EACD,CAGK,EAAa,EAAiB,OAAQ,GAC1C,EAAiB,SAAS,EAAO,CAClC,CAED,GAAI,EAAW,SAAW,EAAG,CAC3B,EACE,8CAAA,EAAA,EAAA,aAAyD,EAAe,IAAI,CAAC,GAC7E,CACE,MAAO,OACR,CACF,CACD,OAGF,IAAM,EAAuBC,EAAAA,eAC3B,EACA,EACA,EACA,EAAe,IACf,EACD,CAED,UAAW,IAAM,KAAU,EAAU,CACnC,GAAI,CAAC,EAAO,SAAU,CACpB,EACE,gEAAA,EAAA,EAAA,aAA2E,EAAe,IAAI,CAAC,GAC/F,CACE,MAAO,QACR,CACF,CACD,SAIF,GAAM,CAAE,OAAM,GAAG,GAAS,EAEpB,GAAA,EAAA,EAAA,UACJ,EAAc,QAAQ,QACtB,EAAO,SACR,CAiBD,GAdA,MAAA,EAAA,EAAA,yBACE,CACE,GAAG,EACH,OAAQ,GACR,OAAQ,EAAO,YAAc,EAAO,WAAW,GAAK,IAAA,GACpD,QAAS,GAAG,EAAuB,IAAI,WAAW,IAClD,SAAU,EACX,CACD,EACA,CACE,WAAY,EAAO,WACpB,CACF,CAEG,EAAO,YAAa,CACtB,IAAM,EAAe,EAAO,WAAW,GAEvC,EACE,oDAAA,EAAA,EAAA,aAA+D,EAAe,IAAI,CAAC,gBAAA,EAAA,EAAA,YAA0B,EAAO,SAAS,CAAC,eAAA,EAAA,EAAA,cAA2B,EAAa,GACtK,CACE,MAAO,OACR,CACF,MAED,EACE,yCAAA,EAAA,EAAA,aAAoD,EAAe,IAAI,CAAC,gBAAA,EAAA,EAAA,YAA0B,EAAO,SAAS,GAClH,CACE,MAAO,OACR,CACF"}
1
+ {"version":3,"file":"writeFill.cjs","names":["getAvailableLocalesInDictionary","formatFillData"],"sources":["../../../src/fill/writeFill.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport { writeContentDeclaration } from '@intlayer/chokidar/build';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, Fill, IntlayerConfig, Locale } from '@intlayer/types';\nimport { type FillData, formatFillData } from './formatFillData';\nimport { getAvailableLocalesInDictionary } from './getAvailableLocalesInDictionary';\n\nexport const writeFill = async (\n contentDeclarationFile: Dictionary,\n outputLocales: Locale[],\n parentLocales: Locale[],\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n const dictionaries = getDictionaries(configuration);\n\n const fullDictionary = dictionaries[contentDeclarationFile.key];\n\n const { filePath } = contentDeclarationFile;\n\n if (!filePath) {\n appLogger('No file path found for dictionary', {\n level: 'error',\n });\n return;\n }\n\n const fillOptions: Fill | undefined =\n contentDeclarationFile.fill ?? configuration.dictionary?.fill ?? true;\n\n if ((fillOptions as boolean) === false) {\n appLogger(\n `Auto fill is disabled for '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'info',\n }\n );\n return;\n }\n\n const requestedLocales: Locale[] = (\n outputLocales ?? configuration.internationalization.locales\n ).filter((locale) => !parentLocales?.includes(locale));\n\n // Get locales that actually have translations in the content\n const availableLocales = getAvailableLocalesInDictionary(\n contentDeclarationFile\n );\n\n // Only write files for locales that have actual translations\n const localeList = requestedLocales.filter((locale) =>\n availableLocales.includes(locale)\n );\n\n if (localeList.length === 0) {\n appLogger(\n `No translations available for dictionary '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'info',\n }\n );\n return;\n }\n\n const fillData: FillData[] = formatFillData(\n fillOptions as Fill,\n localeList,\n filePath,\n fullDictionary.key,\n configuration\n );\n\n for await (const output of fillData) {\n if (!output.filePath) {\n appLogger(\n `No file path found for auto filled content declaration for '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'error',\n }\n );\n continue;\n }\n\n const { fill, ...rest } = contentDeclarationFile;\n\n const relativeFilePath = relative(\n configuration.content.baseDir,\n output.filePath\n );\n\n // write file\n await writeContentDeclaration(\n {\n ...rest,\n filled: true,\n locale: output.isPerLocale ? output.localeList[0] : undefined,\n localId: `${contentDeclarationFile.key}::local::${relativeFilePath}`,\n filePath: relativeFilePath,\n },\n configuration,\n {\n localeList: output.localeList,\n }\n );\n\n if (output.isPerLocale) {\n const sourceLocale = output.localeList[0];\n\n appLogger(\n `Auto filled per-locale content declaration for '${colorizeKey(fullDictionary.key)}' written to ${formatPath(output.filePath)} for locale ${formatLocale(sourceLocale)}`,\n {\n level: 'info',\n }\n );\n } else {\n appLogger(\n `Auto filled content declaration for '${colorizeKey(fullDictionary.key)}' written to ${formatPath(output.filePath)}`,\n {\n level: 'info',\n }\n );\n }\n }\n};\n"],"mappings":"iYASA,MAAa,EAAY,MACvB,EACA,EACA,EACA,IACG,CACH,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAGvC,GAAA,EAAA,EAAA,iBAF+B,EAAc,CAEf,EAAuB,KAErD,CAAE,YAAa,EAErB,GAAI,CAAC,EAAU,CACb,EAAU,oCAAqC,CAC7C,MAA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AoD,EAAe,IAAI,CAAC,gBAAA,EAAA,EAAA,YAA0B,EAAO,SAAS,GAClH,CACE,MAAO,OACR,CACF"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/config/node`),t=require(`node:path`),n=require(`@intlayer/chokidar/cli`),r=require(`@intlayer/unmerged-dictionaries-entry`);const i=e=>[e].flat(),a=async a=>{let o=(0,e.getConfiguration)(a?.configOptions),{baseDir:s}=o.content,c=(0,r.getUnmergedDictionaries)(o),l=Object.values(c).flat();if(a?.file!==void 0){let e=i(a?.file).map(e=>e.startsWith(`/`)?(0,t.relative)(s,e):(0,t.join)(`./`,e));l=l.filter(t=>t.filePath&&e.includes(t.filePath))}a?.keys!==void 0&&(l=l.filter(e=>i(a?.keys)?.includes(e.key))),a?.excludedKeys!==void 0&&(l=l.filter(e=>!i(a?.excludedKeys)?.includes(e.key))),a?.pathFilter!==void 0&&(l=l.filter(e=>i(a?.pathFilter)?.includes(e.filePath??``))),a?.filter!==void 0&&(l=l.filter(a?.filter));let u=a?.gitOptions;if(u){let e=await(0,n.listGitFiles)(u);e&&(l=l.filter(t=>t.filePath?e.some(e=>t.filePath===e):!1))}return l};exports.ensureArray=i,exports.getTargetUnmergedDictionaries=a;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/chokidar/cli`),t=require(`@intlayer/config/node`),n=require(`node:path`),r=require(`@intlayer/unmerged-dictionaries-entry`);const i=e=>[e].flat(),a=async a=>{let o=(0,t.getConfiguration)(a?.configOptions),{baseDir:s}=o.content,c=(0,r.getUnmergedDictionaries)(o),l=Object.values(c).flat();if(a?.file!==void 0){let e=i(a?.file).map(e=>e.startsWith(`/`)?(0,n.relative)(s,e):(0,n.join)(`./`,e));l=l.filter(t=>t.filePath&&e.includes(t.filePath))}a?.keys!==void 0&&(l=l.filter(e=>i(a?.keys)?.includes(e.key))),a?.excludedKeys!==void 0&&(l=l.filter(e=>!i(a?.excludedKeys)?.includes(e.key))),a?.pathFilter!==void 0&&(l=l.filter(e=>i(a?.pathFilter)?.includes(e.filePath??``))),a?.filter!==void 0&&(l=l.filter(a?.filter));let u=a?.gitOptions;if(u){let t=await(0,e.listGitFiles)(u);t&&(l=l.filter(e=>e.filePath?t.some(t=>e.filePath===t):!1))}return l};exports.ensureArray=i,exports.getTargetUnmergedDictionaries=a;
2
2
  //# sourceMappingURL=getTargetDictionary.cjs.map
package/dist/cjs/init.cjs CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`node:path`),t=require(`@intlayer/chokidar/cli`),n=require(`node:fs`);const r=t=>{let r=t;for(;r!==(0,e.resolve)(r,`..`);){if((0,n.existsSync)((0,e.join)(r,`package.json`)))return r;r=(0,e.resolve)(r,`..`)}return t},i=async n=>{await(0,t.initIntlayer)(r(n?(0,e.resolve)(n):process.cwd()))};exports.findProjectRoot=r,exports.init=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/chokidar/cli`),t=require(`node:path`),n=require(`node:fs`);const r=e=>{let r=e;for(;r!==(0,t.resolve)(r,`..`);){if((0,n.existsSync)((0,t.join)(r,`package.json`)))return r;r=(0,t.resolve)(r,`..`)}return e},i=async n=>{await(0,e.initIntlayer)(r(n?(0,t.resolve)(n):process.cwd()))};exports.findProjectRoot=r,exports.init=i;
2
2
  //# sourceMappingURL=init.cjs.map
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./init.cjs`),n=require(`./initSkills.cjs`);let r=require(`node:path`),i=require(`@intlayer/chokidar/cli`),a=require(`@clack/prompts`);a=e.__toESM(a);let o=require(`enquirer`);o=e.__toESM(o);const s=async e=>{let s=t.findProjectRoot(e?(0,r.resolve)(e):process.cwd());a.intro(`Initializing Intlayer MCP Server`);let c=n.getDetectedPlatform(),l;try{l=(await o.default.prompt({type:`autocomplete`,name:`platforms`,message:`Which platform are you using? (Type to search)`,multiple:!1,initial:c?i.PLATFORMS.indexOf(c):void 0,choices:n.PLATFORM_OPTIONS.map(e=>({name:e.value,message:e.label,hint:e.hint}))})).platforms}catch{a.cancel(`Operation cancelled.`);return}if(!l){a.cancel(`Operation cancelled. No platform selected.`);return}let u=await a.select({message:`Which transport method do you want to use?`,options:[{value:`stdio`,label:`Local server (stdio)`,hint:`Recommended. Integrates all features including CLI tools.`},{value:`sse`,label:`Remote server (SSE)`,hint:`Hosted by Intlayer. Documentation only.`}]});if(a.isCancel(u)||!u){a.cancel(`Operation cancelled.`);return}let d=a.spinner();d.start(`Configuring MCP Server...`);try{let e=await(0,i.installMCP)(s,l,u);d.stop(`MCP Server configured successfully`),a.note(e,`Success`)}catch(e){d.stop(`Failed to configure MCP Server`),a.log.error(e instanceof Error?e.message:String(e))}a.outro(`Intlayer MCP Server initialization complete`)};exports.initMCP=s;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./init.cjs`),n=require(`./initSkills.cjs`);let r=require(`@intlayer/chokidar/cli`),i=require(`node:path`),a=require(`enquirer`);a=e.__toESM(a);let o=require(`@clack/prompts`);o=e.__toESM(o);const s=async e=>{let s=t.findProjectRoot(e?(0,i.resolve)(e):process.cwd());o.intro(`Initializing Intlayer MCP Server`);let c=n.getDetectedPlatform(),l;try{l=(await a.default.prompt({type:`autocomplete`,name:`platforms`,message:`Which platform are you using? (Type to search)`,multiple:!1,initial:c?r.PLATFORMS.indexOf(c):void 0,choices:n.PLATFORM_OPTIONS.map(e=>({name:e.value,message:e.label,hint:e.hint}))})).platforms}catch{o.cancel(`Operation cancelled.`);return}if(!l){o.cancel(`Operation cancelled. No platform selected.`);return}let u=await o.select({message:`Which transport method do you want to use?`,options:[{value:`stdio`,label:`Local server (stdio)`,hint:`Recommended. Integrates all features including CLI tools.`},{value:`sse`,label:`Remote server (SSE)`,hint:`Hosted by Intlayer. Documentation only.`}]});if(o.isCancel(u)||!u){o.cancel(`Operation cancelled.`);return}let d=o.spinner();d.start(`Configuring MCP Server...`);try{let e=await(0,r.installMCP)(s,l,u);d.stop(`MCP Server configured successfully`),o.note(e,`Success`)}catch(e){d.stop(`Failed to configure MCP Server`),o.log.error(e instanceof Error?e.message:String(e))}o.outro(`Intlayer MCP Server initialization complete`)};exports.initMCP=s;
2
2
  //# sourceMappingURL=initMCP.cjs.map
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./init.cjs`);let n=require(`node:path`),r=require(`@intlayer/chokidar/cli`),i=require(`node:fs`),a=require(`@clack/prompts`);a=e.__toESM(a);let o=require(`enquirer`);o=e.__toESM(o);const s=r.PLATFORMS.filter(e=>r.PLATFORMS_METADATA[e].check).map(e=>({check:r.PLATFORMS_METADATA[e].check??(()=>!1),platform:e})),c=r.PLATFORMS.map(e=>({value:e,label:r.PLATFORMS_METADATA[e].label,hint:`(${r.PLATFORMS_METADATA[e].dir})`})),l=()=>s.find(({check:e})=>e())?.platform,u=e=>{try{let t=(0,n.join)(e,`package.json`);if(!(0,i.existsSync)(t))return{};let{dependencies:r={},devDependencies:a={}}=JSON.parse((0,i.readFileSync)(t,`utf-8`));return{...r,...a}}catch{return{}}},d=async e=>{let i=t.findProjectRoot(e?(0,n.resolve)(e):process.cwd());a.intro(`Initializing Intlayer skills`);let s=l(),d;try{d=(await o.default.prompt({type:`autocomplete`,name:`platforms`,message:`Which platforms are you using? (Type to search)`,multiple:!1,initial:s?r.PLATFORMS.indexOf(s):void 0,choices:c.map(e=>({name:e.value,message:e.label,hint:e.hint}))})).platforms}catch{a.cancel(`Operation cancelled.`);return}if(!d){a.log.warn(`No platform selected. Nothing to install.`);return}let f=(0,r.getInitialSkills)(u(i)),p=await a.multiselect({message:`Select the documentation skills to provide to your AI:`,initialValues:f,options:r.SKILLS.map(e=>({value:e,label:e,hint:r.SKILLS_METADATA[e]})),required:!1});if(a.isCancel(p)||!p||p.length===0){a.cancel(`Operation cancelled. No skills selected.`);return}let m=a.spinner();m.start(`Installing skills...`);try{let e=await(0,r.installSkills)(i,d,p);m.stop(`Skills installed successfully`),a.note(e,`Success`)}catch(e){m.stop(`Failed to install skills`),a.log.error(e instanceof Error?e.message:String(e))}a.outro(`Intlayer skills initialization complete`)};exports.PLATFORM_OPTIONS=c,exports.getDetectedPlatform=l,exports.initSkills=d;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./init.cjs`);let n=require(`@intlayer/chokidar/cli`),r=require(`node:path`),i=require(`node:fs`),a=require(`enquirer`);a=e.__toESM(a);let o=require(`@clack/prompts`);o=e.__toESM(o);const s=n.PLATFORMS.filter(e=>n.PLATFORMS_METADATA[e].check).map(e=>({check:n.PLATFORMS_METADATA[e].check??(()=>!1),platform:e})),c=n.PLATFORMS.map(e=>({value:e,label:n.PLATFORMS_METADATA[e].label,hint:`(${n.PLATFORMS_METADATA[e].dir})`})),l=()=>s.find(({check:e})=>e())?.platform,u=e=>{try{let t=(0,r.join)(e,`package.json`);if(!(0,i.existsSync)(t))return{};let{dependencies:n={},devDependencies:a={}}=JSON.parse((0,i.readFileSync)(t,`utf-8`));return{...n,...a}}catch{return{}}},d=async e=>{let i=t.findProjectRoot(e?(0,r.resolve)(e):process.cwd());o.intro(`Initializing Intlayer skills`);let s=l(),d;try{d=(await a.default.prompt({type:`autocomplete`,name:`platforms`,message:`Which platforms are you using? (Type to search)`,multiple:!1,initial:s?n.PLATFORMS.indexOf(s):void 0,choices:c.map(e=>({name:e.value,message:e.label,hint:e.hint}))})).platforms}catch{o.cancel(`Operation cancelled.`);return}if(!d){o.log.warn(`No platform selected. Nothing to install.`);return}let f=(0,n.getInitialSkills)(u(i)),p=await o.multiselect({message:`Select the documentation skills to provide to your AI:`,initialValues:f,options:n.SKILLS.map(e=>({value:e,label:e,hint:n.SKILLS_METADATA[e]})),required:!1});if(o.isCancel(p)||!p||p.length===0){o.cancel(`Operation cancelled. No skills selected.`);return}let m=o.spinner();m.start(`Installing skills...`);try{let e=await(0,n.installSkills)(i,d,p);m.stop(`Skills installed successfully`),o.note(e,`Success`)}catch(e){m.stop(`Failed to install skills`),o.log.error(e instanceof Error?e.message:String(e))}o.outro(`Intlayer skills initialization complete`)};exports.PLATFORM_OPTIONS=c,exports.getDetectedPlatform=l,exports.initSkills=d;
2
2
  //# sourceMappingURL=initSkills.cjs.map
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/chokidar/utils`),t=require(`@intlayer/config/node`),n=require(`node:path`),r=require(`@intlayer/config/logger`),i=require(`@intlayer/unmerged-dictionaries-entry`);const a=e=>{let r=(0,t.getConfiguration)(e?.configOptions),a=(0,i.getUnmergedDictionaries)(r);return Object.values(a).flat().map(t=>({key:t.key??``,path:e?.absolute?t.filePath??`Remote`:(0,n.relative)(r.content.baseDir,t.filePath??`Remote`)}))},o=n=>{let i=a(n);if(n?.json){console.log(JSON.stringify(i));return}let o=(0,r.getAppLogger)((0,t.getConfiguration)(n?.configOptions)),s=i.map(t=>[(0,r.colon)(` - ${(0,r.colorizeKey)(t.key)}`,{colSize:i.map(e=>e.key.length),maxSize:60}),` - `,(0,e.formatPath)(t.path)].join(``));o(`Content declaration files:`),s.forEach(e=>{o(e,{level:`info`})}),o(`Total content declaration files: ${(0,r.colorizeNumber)(i.length)}`)};exports.listContentDeclaration=o,exports.listContentDeclarationRows=a;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/config/logger`),t=require(`@intlayer/chokidar/utils`),n=require(`@intlayer/config/node`),r=require(`node:path`),i=require(`@intlayer/unmerged-dictionaries-entry`);const a=e=>{let t=(0,n.getConfiguration)(e?.configOptions),a=(0,i.getUnmergedDictionaries)(t);return Object.values(a).flat().map(n=>({key:n.key??``,path:e?.absolute?n.filePath??`Remote`:(0,r.relative)(t.content.baseDir,n.filePath??`Remote`)}))},o=r=>{let i=a(r);if(r?.json){console.log(JSON.stringify(i));return}let o=(0,e.getAppLogger)((0,n.getConfiguration)(r?.configOptions)),s=i.map(n=>[(0,e.colon)(` - ${(0,e.colorizeKey)(n.key)}`,{colSize:i.map(e=>e.key.length),maxSize:60}),` - `,(0,t.formatPath)(n.path)].join(``));o(`Content declaration files:`),s.forEach(e=>{o(e,{level:`info`})}),o(`Total content declaration files: ${(0,e.colorizeNumber)(i.length)}`)};exports.listContentDeclaration=o,exports.listContentDeclarationRows=a;
2
2
  //# sourceMappingURL=listContentDeclaration.cjs.map
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`node:path`),t=require(`@intlayer/chokidar/cli`);const n=async n=>{let{searchDir:r,projectsPath:i}=await(0,t.listProjects)(n),a=i.map(t=>n?.absolute?t:(0,e.relative)(r,t)).map(e=>e===``?`.`:e);if(n?.json){console.dir(a,{depth:null,arrayLimit:null});return}if(i.length===0){console.log(`No Intlayer projects found.`);return}console.log(`Found ${i.length} Intlayer project(s):\n`),i.forEach(e=>{console.log(` - ${e}`)})};exports.listProjectsCommand=n;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/chokidar/cli`),t=require(`node:path`);const n=async n=>{let{searchDir:r,projectsPath:i}=await(0,e.listProjects)(n),a=i.map(e=>n?.absolute?e:(0,t.relative)(r,e)).map(e=>e===``?`.`:e);if(n?.json){console.dir(a,{depth:null,arrayLimit:null});return}if(i.length===0){console.log(`No Intlayer projects found.`);return}console.log(`Found ${i.length} Intlayer project(s):\n`),i.forEach(e=>{console.log(` - ${e}`)})};exports.listProjectsCommand=n;
2
2
  //# sourceMappingURL=listProjects.cjs.map
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./IntlayerEventListener.cjs`);let n=require(`@intlayer/chokidar/utils`),r=require(`@intlayer/config/node`),i=require(`@intlayer/config/logger`),a=require(`node:http`),o=require(`@intlayer/unmerged-dictionaries-entry`),s=require(`@intlayer/chokidar/build`),c=require(`@intlayer/core/plugins`),l=require(`@intlayer/dictionaries-entry`),u=require(`@intlayer/config/package.json`);u=e.__toESM(u);const d=async(e,t)=>{(0,i.getAppLogger)(t)(`Writing dictionary ${e.key}`),await(0,s.buildDictionary)([e],t)},f=async e=>{let s=(0,r.getConfiguration)(e?.configOptions),f=(0,i.getAppLogger)(s),{liveSyncPort:p,liveSyncURL:m}=s.editor,h=null,g=null;if(e?.with&&(h=(0,n.runParallel)(e.with),h.result.catch(()=>{})),s.editor.liveSync&&s.editor.backendURL&&s.editor.clientId&&s.editor.clientSecret){g=new t.IntlayerEventListener(s),g.onConnectionOpen=()=>{f(`Live sync connection established`)},g.onConnectionError=e=>{let t=e;f(`Live sync connection error: ${t.message??`Unknown error`}`,{level:`warn`}),(t.message?.includes(`terminated`)||t.message?.includes(`closed`))&&f(`Server connection was terminated, automatic reconnection will be attempted...`,{level:`info`})},g.onDictionaryAdded=e=>d(e,s),g.onDictionaryChange=e=>d(e,s),g.onDictionaryDeleted=e=>d(e,s);try{await g.initialize()}catch(e){f(`Failed to initialize IntlayerEventListener:`,{level:`error`}),f(`Error: ${e instanceof Error?e.message:String(e)}`,{level:`error`})}}else s.editor.liveSync?(!s.editor.clientId||!s.editor.clientSecret)&&f(`Missing client credentials for hot reload. Please configure clientId and clientSecret`):f(`Hot reload is disabled. Please enable it in the configuration (editor.liveSync).`);let _=(0,a.createServer)(async(e,t)=>{if(e.method===`OPTIONS`){t.writeHead(200,{"Access-Control-Allow-Origin":`*`,"Access-Control-Allow-Methods":`GET, POST, PUT, DELETE, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type, Authorization`}),t.end();return}if(e.url?.startsWith(`/dictionaries`)){t.writeHead(200,{"Content-Type":`application/json; charset=utf-8`,"Cache-Control":`no-store`,"Access-Control-Allow-Origin":`*`,"Access-Control-Allow-Methods":`GET, POST, PUT, DELETE, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type, Authorization`});let n=(0,l.getDictionaries)(s);if(e.url.startsWith(`/dictionaries/`)){let[r,i]=decodeURIComponent(e.url).slice(14).split(`/`),a=n[r]??null;if(i){let e=(0,c.getLocalizedContent)(a.content,i,{dictionaryKey:r,keyPath:[]});t.end(JSON.stringify(e));return}t.end(JSON.stringify(a));return}t.end(JSON.stringify(n));return}if(e.url?.startsWith(`/unmerged_dictionaries`)){t.writeHead(200,{"Content-Type":`application/json; charset=utf-8`,"Cache-Control":`no-store`,"Access-Control-Allow-Origin":`*`,"Access-Control-Allow-Methods":`GET, POST, PUT, DELETE, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type, Authorization`});let n=(0,o.getUnmergedDictionaries)(s);if(e.url.startsWith(`/unmerged_dictionaries/`)){let r=n[decodeURIComponent(e.url.slice(23))]??null;t.end(JSON.stringify(r));return}t.end(JSON.stringify(n));return}if(e.url===`/configuration`){t.writeHead(200,{"Content-Type":`application/json; charset=utf-8`,"Cache-Control":`no-store`,"Access-Control-Allow-Origin":`*`,"Access-Control-Allow-Methods":`GET, POST, PUT, DELETE, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type, Authorization`}),t.end(JSON.stringify(s));return}if(e.url===`/health`){t.writeHead(200,{"Content-Type":`application/json; charset=utf-8`}),t.end(JSON.stringify({status:`ok`}));return}t.end(`Not found`)}),v=()=>s.editor.liveSync?`\x1B[32m✓ Enabled\x1B[0m`:`\x1B[31m✗ Disabled\x1B[0m`;_.listen(p,()=>{console.log(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./_virtual/_rolldown/runtime.cjs`),t=require(`./IntlayerEventListener.cjs`);let n=require(`@intlayer/config/logger`),r=require(`@intlayer/chokidar/utils`),i=require(`@intlayer/config/node`),a=require(`node:http`),o=require(`@intlayer/unmerged-dictionaries-entry`),s=require(`@intlayer/chokidar/build`),c=require(`@intlayer/core/plugins`),l=require(`@intlayer/dictionaries-entry`),u=require(`@intlayer/config/package.json`);u=e.__toESM(u);const d=async(e,t)=>{(0,n.getAppLogger)(t)(`Writing dictionary ${e.key}`),await(0,s.buildDictionary)([e],t)},f=async e=>{let s=(0,i.getConfiguration)(e?.configOptions),f=(0,n.getAppLogger)(s),{liveSyncPort:p,liveSyncURL:m}=s.editor,h=null,g=null;if(e?.with&&(h=(0,r.runParallel)(e.with),h.result.catch(()=>{})),s.editor.liveSync&&s.editor.backendURL&&s.editor.clientId&&s.editor.clientSecret){g=new t.IntlayerEventListener(s),g.onConnectionOpen=()=>{f(`Live sync connection established`)},g.onConnectionError=e=>{let t=e;f(`Live sync connection error: ${t.message??`Unknown error`}`,{level:`warn`}),(t.message?.includes(`terminated`)||t.message?.includes(`closed`))&&f(`Server connection was terminated, automatic reconnection will be attempted...`,{level:`info`})},g.onDictionaryAdded=e=>d(e,s),g.onDictionaryChange=e=>d(e,s),g.onDictionaryDeleted=e=>d(e,s);try{await g.initialize()}catch(e){f(`Failed to initialize IntlayerEventListener:`,{level:`error`}),f(`Error: ${e instanceof Error?e.message:String(e)}`,{level:`error`})}}else s.editor.liveSync?(!s.editor.clientId||!s.editor.clientSecret)&&f(`Missing client credentials for hot reload. Please configure clientId and clientSecret`):f(`Hot reload is disabled. Please enable it in the configuration (editor.liveSync).`);let _=(0,a.createServer)(async(e,t)=>{if(e.method===`OPTIONS`){t.writeHead(200,{"Access-Control-Allow-Origin":`*`,"Access-Control-Allow-Methods":`GET, POST, PUT, DELETE, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type, Authorization`}),t.end();return}if(e.url?.startsWith(`/dictionaries`)){t.writeHead(200,{"Content-Type":`application/json; charset=utf-8`,"Cache-Control":`no-store`,"Access-Control-Allow-Origin":`*`,"Access-Control-Allow-Methods":`GET, POST, PUT, DELETE, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type, Authorization`});let n=(0,l.getDictionaries)(s);if(e.url.startsWith(`/dictionaries/`)){let[r,i]=decodeURIComponent(e.url).slice(14).split(`/`),a=n[r]??null;if(i){let e=(0,c.getLocalizedContent)(a.content,i,{dictionaryKey:r,keyPath:[]});t.end(JSON.stringify(e));return}t.end(JSON.stringify(a));return}t.end(JSON.stringify(n));return}if(e.url?.startsWith(`/unmerged_dictionaries`)){t.writeHead(200,{"Content-Type":`application/json; charset=utf-8`,"Cache-Control":`no-store`,"Access-Control-Allow-Origin":`*`,"Access-Control-Allow-Methods":`GET, POST, PUT, DELETE, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type, Authorization`});let n=(0,o.getUnmergedDictionaries)(s);if(e.url.startsWith(`/unmerged_dictionaries/`)){let r=n[decodeURIComponent(e.url.slice(23))]??null;t.end(JSON.stringify(r));return}t.end(JSON.stringify(n));return}if(e.url===`/configuration`){t.writeHead(200,{"Content-Type":`application/json; charset=utf-8`,"Cache-Control":`no-store`,"Access-Control-Allow-Origin":`*`,"Access-Control-Allow-Methods":`GET, POST, PUT, DELETE, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type, Authorization`}),t.end(JSON.stringify(s));return}if(e.url===`/health`){t.writeHead(200,{"Content-Type":`application/json; charset=utf-8`}),t.end(JSON.stringify({status:`ok`}));return}t.end(`Not found`)}),v=()=>s.editor.liveSync?`\x1B[32m✓ Enabled\x1B[0m`:`\x1B[31m✗ Disabled\x1B[0m`;_.listen(p,()=>{console.log(`
2
2
  \x1b[1;90mINTLAYER v${u.default.version}\x1b[0m
3
3
 
4
4
  Live server running at: \x1b[90m${m}\x1b[0m
@@ -1 +1 @@
1
- {"version":3,"file":"liveSync.cjs","names":["IntlayerEventListener","packageJson"],"sources":["../../src/liveSync.ts"],"sourcesContent":["import { createServer } from 'node:http';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { buildDictionary } from '@intlayer/chokidar/build';\nimport { type ParallelHandle, runParallel } from '@intlayer/chokidar/utils';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport packageJson from '@intlayer/config/package.json';\nimport { getLocalizedContent } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { IntlayerEventListener } from './IntlayerEventListener';\n\ntype LiveSyncOptions = {\n with?: string | string[];\n configOptions?: GetConfigurationOptions;\n};\n\nconst writeDictionary = async (\n dictionary: DictionaryAPI,\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n appLogger(`Writing dictionary ${dictionary.key}`);\n await buildDictionary([dictionary], configuration);\n};\n\nexport const liveSync = async (options?: LiveSyncOptions) => {\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const { liveSyncPort, liveSyncURL } = configuration.editor;\n\n let parallelProcess: ParallelHandle | null = null;\n let eventListener: IntlayerEventListener | null = null;\n let _isHotReloadConnected = false;\n let _connectionStatus = 'disconnected'; // 'connected', 'connecting', 'reconnecting', 'disconnected', 'error'\n\n // Start the parallel process if provided\n if (options?.with) {\n parallelProcess = runParallel(options.with);\n // Handle the promise to avoid unhandled rejection\n parallelProcess.result.catch(() => {\n // Parallel process failed or was terminated\n });\n }\n\n // Initialize the event listener for hot reload if configured\n if (\n configuration.editor.liveSync &&\n configuration.editor.backendURL &&\n configuration.editor.clientId &&\n configuration.editor.clientSecret\n ) {\n eventListener = new IntlayerEventListener(configuration);\n _connectionStatus = 'connecting';\n\n // Set up connection callbacks\n eventListener.onConnectionOpen = () => {\n _connectionStatus = 'connected';\n _isHotReloadConnected = true;\n appLogger('Live sync connection established');\n };\n\n eventListener.onConnectionError = (error) => {\n _connectionStatus = 'error';\n _isHotReloadConnected = false;\n const errorEvent = error as any;\n appLogger(\n `Live sync connection error: ${errorEvent.message ?? 'Unknown error'}`,\n {\n level: 'warn',\n }\n );\n\n // If this is a \"terminated: other side closed\" error, it's likely a server restart\n if (\n errorEvent.message?.includes('terminated') ||\n errorEvent.message?.includes('closed')\n ) {\n appLogger(\n 'Server connection was terminated, automatic reconnection will be attempted...',\n {\n level: 'info',\n }\n );\n _connectionStatus = 'reconnecting';\n }\n };\n\n // Set up dictionary change callbacks\n eventListener.onDictionaryAdded = (dictionary) =>\n writeDictionary(dictionary, configuration);\n eventListener.onDictionaryChange = (dictionary) =>\n writeDictionary(dictionary, configuration);\n eventListener.onDictionaryDeleted = (dictionary) =>\n writeDictionary(dictionary, configuration);\n\n try {\n await eventListener.initialize();\n } catch (error) {\n _connectionStatus = 'error';\n _isHotReloadConnected = false;\n appLogger('Failed to initialize IntlayerEventListener:', {\n level: 'error',\n });\n appLogger(\n `Error: ${error instanceof Error ? error.message : String(error)}`,\n {\n level: 'error',\n }\n );\n }\n } else if (!configuration.editor.liveSync) {\n appLogger(\n 'Hot reload is disabled. Please enable it in the configuration (editor.liveSync).'\n );\n } else if (\n !configuration.editor.clientId ||\n !configuration.editor.clientSecret\n ) {\n appLogger(\n 'Missing client credentials for hot reload. Please configure clientId and clientSecret'\n );\n }\n\n const server = createServer(async (req, res) => {\n // Handle CORS preflight requests\n if (req.method === 'OPTIONS') {\n res.writeHead(200, {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n\n res.end();\n return;\n }\n\n if (req.url?.startsWith('/dictionaries')) {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Cache-Control': 'no-store',\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n const dictionaries = getDictionaries(configuration);\n\n const prefix = '/dictionaries/';\n if (req.url.startsWith(prefix)) {\n const [key, locale] = decodeURIComponent(req.url)\n .slice(prefix.length)\n .split('/');\n\n const dictionary = dictionaries[key] ?? null;\n\n if (locale) {\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const sourceLocaleContent = getLocalizedContent(\n dictionary.content,\n locale,\n {\n dictionaryKey: key,\n keyPath: [],\n }\n );\n\n res.end(JSON.stringify(sourceLocaleContent));\n return;\n }\n\n res.end(JSON.stringify(dictionary));\n return;\n }\n\n res.end(JSON.stringify(dictionaries));\n return;\n }\n\n if (req.url?.startsWith('/unmerged_dictionaries')) {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Cache-Control': 'no-store',\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n const unmergedDictionaries = getUnmergedDictionaries(configuration);\n\n const prefix = '/unmerged_dictionaries/';\n if (req.url.startsWith(prefix)) {\n const key = decodeURIComponent(req.url.slice(prefix.length));\n const one = unmergedDictionaries[key] ?? null;\n\n res.end(JSON.stringify(one));\n return;\n }\n\n res.end(JSON.stringify(unmergedDictionaries));\n return;\n }\n\n if (req.url === '/configuration') {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Cache-Control': 'no-store',\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n res.end(JSON.stringify(configuration));\n return;\n }\n\n if (req.url === '/health') {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n });\n res.end(JSON.stringify({ status: 'ok' }));\n return;\n }\n\n res.end('Not found');\n return;\n });\n\n const getLiveSyncParam = () => {\n if (!configuration.editor.liveSync) return '\\x1b[31m✗ Disabled\\x1b[0m';\n\n return '\\x1b[32m✓ Enabled\\x1b[0m';\n };\n server.listen(liveSyncPort, () => {\n console.log(`\n \\x1b[1;90mINTLAYER v${packageJson.version}\\x1b[0m\n \n Live server running at: \\x1b[90m${liveSyncURL}\\x1b[0m\n - Backend URL: \\x1b[90m${configuration.editor.backendURL ?? '-'}\\x1b[0m\n - Live sync: ${getLiveSyncParam()}\n - Parallel process: ${options?.with ? `\\x1b[90m${Array.isArray(options.with) ? options.with.join(' ') : options.with}\\x1b[0m` : '-'}\n - Access key: ${configuration.editor.clientId ?? '-'}\n `);\n });\n\n // Cleanup function to terminate child process and event listener when the main process exits\n const cleanup = () => {\n // Clean up event listener\n if (eventListener) {\n appLogger('Closing SSE connection...');\n eventListener.cleanup();\n }\n\n if (parallelProcess) {\n parallelProcess.kill();\n }\n\n server.close(() => {\n appLogger('Live sync server stopped');\n process.exit(0);\n });\n };\n\n // Handle process termination signals\n process.on('SIGINT', cleanup);\n process.on('SIGTERM', cleanup);\n process.on('exit', cleanup);\n};\n"],"mappings":"0gBAsBA,MAAM,EAAkB,MACtB,EACA,IACG,EAEH,EAAA,EAAA,cAD+B,EAAc,CACnC,sBAAsB,EAAW,MAAM,CACjD,MAAA,EAAA,EAAA,iBAAsB,CAAC,EAAW,CAAE,EAAc,EAGvC,EAAW,KAAO,IAA8B,CAC3D,IAAM,GAAA,EAAA,EAAA,kBAAiC,GAAS,cAAc,CACxD,GAAA,EAAA,EAAA,cAAyB,EAAc,CAEvC,CAAE,eAAc,eAAgB,EAAc,OAEhD,EAAyC,KACzC,EAA8C,KAclD,GATI,GAAS,OACX,GAA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EnB,2BAFoC,4BAI7C,EAAO,OAAO,MAAoB,CAChC,QAAQ,IAAI;4BACYC,EAAAA,QAAY,QAAQ;;iDAEC,EAAY;iDACZ,EAAc,OAAO,YAAc,IAAI;yCAC/C,GAAkB,CAAC;yCACnB,GAAS,KAAO,WAAW,MAAM,QAAQ,EAAQ,KAAK,CAAG,EAAQ,KAAK,KAAK,IAAI,CAAG,EAAQ,KAAK,SAAW,IAAI;yCAC9G,EAAc,OAAO,UAAY,IAAI;QACtE,EACJ,CAGF,IAAM,MAAgB,CAEhB,IACF,EAAU,4BAA4B,CACtC,EAAc,SAAS,EAGrB,GACF,EAAgB,MAAM,CAGxB,EAAO,UAAY,CACjB,EAAU,2BAA2B,CACrC,QAAQ,KAAK,EAAE,EACf,EAIJ,QAAQ,GAAG,SAAU,EAAQ,CAC7B,QAAQ,GAAG,UAAW,EAAQ,CAC9B,QAAQ,GAAG,OAAQ,EAAQ"}
1
+ {"version":3,"file":"liveSync.cjs","names":["IntlayerEventListener","packageJson"],"sources":["../../src/liveSync.ts"],"sourcesContent":["import { createServer } from 'node:http';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { buildDictionary } from '@intlayer/chokidar/build';\nimport { type ParallelHandle, runParallel } from '@intlayer/chokidar/utils';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport packageJson from '@intlayer/config/package.json' with { type: 'json' };\nimport { getLocalizedContent } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { IntlayerEventListener } from './IntlayerEventListener';\n\ntype LiveSyncOptions = {\n with?: string | string[];\n configOptions?: GetConfigurationOptions;\n};\n\nconst writeDictionary = async (\n dictionary: DictionaryAPI,\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n appLogger(`Writing dictionary ${dictionary.key}`);\n await buildDictionary([dictionary], configuration);\n};\n\nexport const liveSync = async (options?: LiveSyncOptions) => {\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n const { liveSyncPort, liveSyncURL } = configuration.editor;\n\n let parallelProcess: ParallelHandle | null = null;\n let eventListener: IntlayerEventListener | null = null;\n let _isHotReloadConnected = false;\n let _connectionStatus = 'disconnected'; // 'connected', 'connecting', 'reconnecting', 'disconnected', 'error'\n\n // Start the parallel process if provided\n if (options?.with) {\n parallelProcess = runParallel(options.with);\n // Handle the promise to avoid unhandled rejection\n parallelProcess.result.catch(() => {\n // Parallel process failed or was terminated\n });\n }\n\n // Initialize the event listener for hot reload if configured\n if (\n configuration.editor.liveSync &&\n configuration.editor.backendURL &&\n configuration.editor.clientId &&\n configuration.editor.clientSecret\n ) {\n eventListener = new IntlayerEventListener(configuration);\n _connectionStatus = 'connecting';\n\n // Set up connection callbacks\n eventListener.onConnectionOpen = () => {\n _connectionStatus = 'connected';\n _isHotReloadConnected = true;\n appLogger('Live sync connection established');\n };\n\n eventListener.onConnectionError = (error) => {\n _connectionStatus = 'error';\n _isHotReloadConnected = false;\n const errorEvent = error as any;\n appLogger(\n `Live sync connection error: ${errorEvent.message ?? 'Unknown error'}`,\n {\n level: 'warn',\n }\n );\n\n // If this is a \"terminated: other side closed\" error, it's likely a server restart\n if (\n errorEvent.message?.includes('terminated') ||\n errorEvent.message?.includes('closed')\n ) {\n appLogger(\n 'Server connection was terminated, automatic reconnection will be attempted...',\n {\n level: 'info',\n }\n );\n _connectionStatus = 'reconnecting';\n }\n };\n\n // Set up dictionary change callbacks\n eventListener.onDictionaryAdded = (dictionary) =>\n writeDictionary(dictionary, configuration);\n eventListener.onDictionaryChange = (dictionary) =>\n writeDictionary(dictionary, configuration);\n eventListener.onDictionaryDeleted = (dictionary) =>\n writeDictionary(dictionary, configuration);\n\n try {\n await eventListener.initialize();\n } catch (error) {\n _connectionStatus = 'error';\n _isHotReloadConnected = false;\n appLogger('Failed to initialize IntlayerEventListener:', {\n level: 'error',\n });\n appLogger(\n `Error: ${error instanceof Error ? error.message : String(error)}`,\n {\n level: 'error',\n }\n );\n }\n } else if (!configuration.editor.liveSync) {\n appLogger(\n 'Hot reload is disabled. Please enable it in the configuration (editor.liveSync).'\n );\n } else if (\n !configuration.editor.clientId ||\n !configuration.editor.clientSecret\n ) {\n appLogger(\n 'Missing client credentials for hot reload. Please configure clientId and clientSecret'\n );\n }\n\n const server = createServer(async (req, res) => {\n // Handle CORS preflight requests\n if (req.method === 'OPTIONS') {\n res.writeHead(200, {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n\n res.end();\n return;\n }\n\n if (req.url?.startsWith('/dictionaries')) {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Cache-Control': 'no-store',\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n const dictionaries = getDictionaries(configuration);\n\n const prefix = '/dictionaries/';\n if (req.url.startsWith(prefix)) {\n const [key, locale] = decodeURIComponent(req.url)\n .slice(prefix.length)\n .split('/');\n\n const dictionary = dictionaries[key] ?? null;\n\n if (locale) {\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const sourceLocaleContent = getLocalizedContent(\n dictionary.content,\n locale,\n {\n dictionaryKey: key,\n keyPath: [],\n }\n );\n\n res.end(JSON.stringify(sourceLocaleContent));\n return;\n }\n\n res.end(JSON.stringify(dictionary));\n return;\n }\n\n res.end(JSON.stringify(dictionaries));\n return;\n }\n\n if (req.url?.startsWith('/unmerged_dictionaries')) {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Cache-Control': 'no-store',\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n const unmergedDictionaries = getUnmergedDictionaries(configuration);\n\n const prefix = '/unmerged_dictionaries/';\n if (req.url.startsWith(prefix)) {\n const key = decodeURIComponent(req.url.slice(prefix.length));\n const one = unmergedDictionaries[key] ?? null;\n\n res.end(JSON.stringify(one));\n return;\n }\n\n res.end(JSON.stringify(unmergedDictionaries));\n return;\n }\n\n if (req.url === '/configuration') {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Cache-Control': 'no-store',\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n res.end(JSON.stringify(configuration));\n return;\n }\n\n if (req.url === '/health') {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n });\n res.end(JSON.stringify({ status: 'ok' }));\n return;\n }\n\n res.end('Not found');\n return;\n });\n\n const getLiveSyncParam = () => {\n if (!configuration.editor.liveSync) return '\\x1b[31m✗ Disabled\\x1b[0m';\n\n return '\\x1b[32m✓ Enabled\\x1b[0m';\n };\n server.listen(liveSyncPort, () => {\n console.log(`\n \\x1b[1;90mINTLAYER v${packageJson.version}\\x1b[0m\n \n Live server running at: \\x1b[90m${liveSyncURL}\\x1b[0m\n - Backend URL: \\x1b[90m${configuration.editor.backendURL ?? '-'}\\x1b[0m\n - Live sync: ${getLiveSyncParam()}\n - Parallel process: ${options?.with ? `\\x1b[90m${Array.isArray(options.with) ? options.with.join(' ') : options.with}\\x1b[0m` : '-'}\n - Access key: ${configuration.editor.clientId ?? '-'}\n `);\n });\n\n // Cleanup function to terminate child process and event listener when the main process exits\n const cleanup = () => {\n // Clean up event listener\n if (eventListener) {\n appLogger('Closing SSE connection...');\n eventListener.cleanup();\n }\n\n if (parallelProcess) {\n parallelProcess.kill();\n }\n\n server.close(() => {\n appLogger('Live sync server stopped');\n process.exit(0);\n });\n };\n\n // Handle process termination signals\n process.on('SIGINT', cleanup);\n process.on('SIGTERM', cleanup);\n process.on('exit', cleanup);\n};\n"],"mappings":"0gBAsBA,MAAM,EAAkB,MACtB,EACA,IACG,EAEH,EAAA,EAAA,cAD+B,EAAc,CACnC,sBAAsB,EAAW,MAAM,CACjD,MAAA,EAAA,EAAA,iBAAsB,CAAC,EAAW,CAAE,EAAc,EAGvC,EAAW,KAAO,IAA8B,CAC3D,IAAM,GAAA,EAAA,EAAA,kBAAiC,GAAS,cAAc,CACxD,GAAA,EAAA,EAAA,cAAyB,EAAc,CAEvC,CAAE,eAAc,eAAgB,EAAc,OAEhD,EAAyC,KACzC,EAA8C,KAclD,GATI,GAAS,OACX,GAAA,EAAA,EAAA,aAA8B,EAAQ,KAAK,CAE3C,EAAgB,OAAO,UAAY,GAEjC,EAKF,EAAc,OAAO,UACrB,EAAc,OAAO,YACrB,EAAc,OAAO,UACrB,EAAc,OAAO,aACrB,CACA,EAAgB,IAAIA,EAAAA,sBAAsB,EAAc,CAIxD,EAAc,qBAAyB,CAGrC,EAAU,mCAAmC,EAG/C,EAAc,kBAAqB,GAAU,CAG3C,IAAM,EAAa,EACnB,EACE,+BAA+B,EAAW,SAAW,kBACrD,CACE,MAAO,OACR,CACF,EAIC,EAAW,SAAS,SAAS,aAAa,EAC1C,EAAW,SAAS,SAAS,SAAS,GAEtC,EACE,gFACA,CACE,MAAO,OACR,CACF,EAML,EAAc,kBAAqB,GACjC,EAAgB,EAAY,EAAc,CAC5C,EAAc,mBAAsB,GAClC,EAAgB,EAAY,EAAc,CAC5C,EAAc,oBAAuB,GACnC,EAAgB,EAAY,EAAc,CAE5C,GAAI,CACF,MAAM,EAAc,YAAY,OACzB,EAAO,CAGd,EAAU,8CAA+C,CACvD,MAAO,QACR,CAAC,CACF,EACE,UAAU,aAAiB,MAAQ,EAAM,QAAU,O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ess.cjs`),t=require(`./push/pullLog.cjs`);let n=require(`@intlayer/api`),r=require(`@intlayer/chokidar/utils`),i=require(`@intlayer/config/node`),a=require(`node:path`),o=require(`@intlayer/config/logger`),s=require(`@intlayer/config/utils`),c=require(`node:fs`),l=require(`@intlayer/unmerged-dictionaries-entry`),u=require(`@intlayer/chokidar/build`);const d=async d=>{let f=(0,o.getAppLogger)(d?.configOptions?.override);try{let p=(0,i.getConfiguration)(d?.configOptions);if(!await e.checkCMSAuth(p))return;let m=(0,n.getIntlayerAPIProxy)(void 0,p),h=(0,l.getUnmergedDictionaries)(p),g=await m.dictionary.getDictionariesUpdateTimestamp();if(!g.data)throw Error(`No distant dictionaries found`);let _=g.data;d?.dictionaries&&(_=Object.fromEntries(Object.entries(_).filter(([e])=>d.dictionaries?.includes(e)))),_=Object.fromEntries(Object.entries(_).filter(([e])=>{let t=h[e]?.[0]?.location??p.dictionary?.location??`remote`;return t===`remote`||t===`hybrid`}));let v=(0,a.join)(p.system.mainDir,`remote_dictionaries.cjs`),y=p.build?.require??(0,s.getProjectRequire)(),b=(0,c.existsSync)(v)?y(v):{},x=Object.entries(_),S=x.filter(([e,t])=>{if(!t)return!0;let n=typeof t==`object`?t.updatedAt:t,r=b[e];if(!r)return!0;let i=r?.updatedAt,a=typeof i==`number`?i:i?new Date(i).getTime():void 0;return typeof a==`number`?n>a:!0}).map(([e])=>e),C=x.filter(([e,t])=>{let n=typeof t==`object`?t.updatedAt:t,r=b[e]?.updatedAt,i=typeof r==`number`?r:r?new Date(r).getTime():void 0;return typeof i==`number`&&typeof n==`number`&&i>=n}).map(([e])=>e);if(x.length===0){f(`No dictionaries to fetch`,{level:`error`});return}f(`Fetching dictionaries:`);let w=[...C.map(e=>({dictionaryKey:e,status:`imported`})),...S.map(e=>({dictionaryKey:e,status:`pending`}))],T=new t.PullLogger;T.update(w.map(e=>({dictionaryKey:e.dictionaryKey,status:e.status})));let E=[];await(0,r.parallelize)(w,async e=>{let t=e.status===`imported`||e.status===`up-to-date`;t||(e.status=`fetching`,T.update([{dictionaryKey:e.dictionaryKey,status:`fetching`}]));try{let n;if(t&&(n=b[e.dictionaryKey]),n||=(await m.dictionary.getDictionary(e.dictionaryKey)).data,!n)throw Error(`Dictionary ${e.dictionaryKey} not found on remote`);let r=h[e.dictionaryKey]?.find(e=>e.location===`hybrid`);r&&(n={...n,location:`hybrid`,filePath:r.filePath,localId:r.localId});let{status:i}=await(0,u.writeContentDeclaration)(n,p,d);e.status=i,T.update([{dictionaryKey:e.dictionaryKey,status:i}]),E.push(n)}catch(t){e.status=`error`,e.error=t,e.errorMessage=`Error fetching dictionary ${e.dictionaryKey}: ${t}`,T.update([{dictionaryKey:e.dictionaryKey,status:`error`}])}},5),T.finish();let D=e=>{switch(e){case`fetched`:case`imported`:case`updated`:case`up-to-date`:case`reimported in JSON`:case`new content file`:return`✔`;case`error`:return`✖`;default:return`⏲`}},O=e=>{switch(e){case`fetched`:case`imported`:case`updated`:case`up-to-date`:return o.ANSIColors.GREEN;case`reimported in JSON`:case`new content file`:return o.ANSIColors.YELLOW;case`error`:return o.ANSIColors.RED;default:return o.ANSIColors.BLUE}};for(let e of w){let t=D(e.status),n=O(e.status);f(` - ${e.dictionaryKey} ${o.ANSIColors.GREY}[${n}${t} ${e.status}${o.ANSIColors.GREY}]${o.ANSIColors.RESET}`)}for(let e of w)e.errorMessage&&f(e.errorMessage,{level:`error`})}catch(e){f(e,{level:`error`})}};exports.pull=d;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);const e=require(`./utils/checkAccess.cjs`),t=require(`./push/pullLog.cjs`);let n=require(`@intlayer/api`),r=require(`@intlayer/config/logger`),i=require(`@intlayer/chokidar/cli`),a=require(`@intlayer/chokidar/utils`),o=require(`@intlayer/config/node`),s=require(`node:path`),c=require(`@intlayer/config/utils`),l=require(`node:fs`),u=require(`@intlayer/unmerged-dictionaries-entry`),d=require(`@intlayer/chokidar/build`);const f=async f=>{let p=(0,r.getAppLogger)(f?.configOptions?.override);try{let m=(0,o.getConfiguration)(f?.configOptions);if((0,i.logConfigDetails)(f?.configOptions),!await e.checkCMSAuth(m))return;let h=(0,n.getIntlayerAPIProxy)(void 0,m),g=(0,u.getUnmergedDictionaries)(m),_=await h.dictionary.getDictionariesUpdateTimestamp();if(!_.data)throw Error(`No distant dictionaries found`);let v=_.data;f?.dictionaries&&(v=Object.fromEntries(Object.entries(v).filter(([e])=>f.dictionaries?.includes(e)))),v=Object.fromEntries(Object.entries(v).filter(([e])=>{let t=g[e]?.[0]?.location??m.dictionary?.location??`remote`;return t===`remote`||t===`hybrid`}));let y=(0,s.join)(m.system.mainDir,`remote_dictionaries.cjs`),b=m.build?.require??(0,c.getProjectRequire)(),x=(0,l.existsSync)(y)?b(y):{},S=Object.entries(v),C=S.filter(([e,t])=>{if(!t)return!0;let n=typeof t==`object`?t.updatedAt:t,r=x[e];if(!r)return!0;let i=r?.updatedAt,a=typeof i==`number`?i:i?new Date(i).getTime():void 0;return typeof a==`number`?n>a:!0}).map(([e])=>e),w=S.filter(([e,t])=>{let n=typeof t==`object`?t.updatedAt:t,r=x[e]?.updatedAt,i=typeof r==`number`?r:r?new Date(r).getTime():void 0;return typeof i==`number`&&typeof n==`number`&&i>=n}).map(([e])=>e);if(S.length===0){p(`No dictionaries to fetch`,{level:`error`});return}p(`Fetching dictionaries:`);let T=[...w.map(e=>({dictionaryKey:e,status:`imported`})),...C.map(e=>({dictionaryKey:e,status:`pending`}))],E=new t.PullLogger;E.update(T.map(e=>({dictionaryKey:e.dictionaryKey,status:e.status})));let D=[];await(0,a.parallelize)(T,async e=>{let t=e.status===`imported`||e.status===`up-to-date`;t||(e.status=`fetching`,E.update([{dictionaryKey:e.dictionaryKey,status:`fetching`}]));try{let n;if(t&&(n=x[e.dictionaryKey]),n||=(await h.dictionary.getDictionary(e.dictionaryKey)).data,!n)throw Error(`Dictionary ${e.dictionaryKey} not found on remote`);let r=g[e.dictionaryKey]?.find(e=>e.location===`hybrid`);r&&(n={...n,location:`hybrid`,filePath:r.filePath,localId:r.localId});let{status:i}=await(0,d.writeContentDeclaration)(n,m,f);e.status=i,E.update([{dictionaryKey:e.dictionaryKey,status:i}]),D.push(n)}catch(t){e.status=`error`,e.error=t,e.errorMessage=`Error fetching dictionary ${e.dictionaryKey}: ${t}`,E.update([{dictionaryKey:e.dictionaryKey,status:`error`}])}},5),E.finish();let O=e=>{switch(e){case`fetched`:case`imported`:case`updated`:case`up-to-date`:case`reimported in JSON`:case`new content file`:return`✔`;case`error`:return`✖`;default:return`⏲`}},k=e=>{switch(e){case`fetched`:case`imported`:case`updated`:case`up-to-date`:return r.ANSIColors.GREEN;case`reimported in JSON`:case`new content file`:return r.ANSIColors.YELLOW;case`error`:return r.ANSIColors.RED;default:return r.ANSIColors.BLUE}};for(let e of T){let t=O(e.status),n=k(e.status);p(` - ${e.dictionaryKey} ${r.ANSIColors.GREY}[${n}${t} ${e.status}${r.ANSIColors.GREY}]${r.ANSIColors.RESET}`)}for(let e of T)e.errorMessage&&p(e.errorMessage,{level:`error`})}catch(e){p(e,{level:`error`})}};exports.pull=f;
2
2
  //# sourceMappingURL=pull.cjs.map