@intlayer/cli 6.0.0-canary.3 → 6.0.1

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 (90) hide show
  1. package/dist/cjs/cli.cjs +10 -0
  2. package/dist/cjs/cli.cjs.map +1 -1
  3. package/dist/cjs/editor.cjs +69 -0
  4. package/dist/cjs/editor.cjs.map +1 -0
  5. package/dist/cjs/fill/index.cjs +76 -84
  6. package/dist/cjs/fill/index.cjs.map +1 -1
  7. package/dist/cjs/{fill/getTargetDictionary.cjs → getTargetDictionary.cjs} +6 -15
  8. package/dist/cjs/getTargetDictionary.cjs.map +1 -0
  9. package/dist/cjs/index.cjs +2 -0
  10. package/dist/cjs/index.cjs.map +1 -1
  11. package/dist/cjs/listContentDeclaration.cjs +3 -12
  12. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  13. package/dist/cjs/liveSync.cjs +2 -2
  14. package/dist/cjs/liveSync.cjs.map +1 -1
  15. package/dist/cjs/pull.cjs +3 -6
  16. package/dist/cjs/pull.cjs.map +1 -1
  17. package/dist/cjs/push.cjs +13 -9
  18. package/dist/cjs/push.cjs.map +1 -1
  19. package/dist/cjs/pushConfig.cjs +3 -10
  20. package/dist/cjs/pushConfig.cjs.map +1 -1
  21. package/dist/cjs/reviewDoc.cjs +3 -2
  22. package/dist/cjs/reviewDoc.cjs.map +1 -1
  23. package/dist/cjs/test/index.cjs +1 -1
  24. package/dist/cjs/test/index.cjs.map +1 -1
  25. package/dist/cjs/test/listMissingTranslations.cjs +8 -16
  26. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  27. package/dist/cjs/translateDoc.cjs +3 -2
  28. package/dist/cjs/translateDoc.cjs.map +1 -1
  29. package/dist/cjs/utils/checkAccess.cjs +79 -0
  30. package/dist/cjs/utils/checkAccess.cjs.map +1 -0
  31. package/dist/esm/cli.mjs +10 -0
  32. package/dist/esm/cli.mjs.map +1 -1
  33. package/dist/esm/editor.mjs +44 -0
  34. package/dist/esm/editor.mjs.map +1 -0
  35. package/dist/esm/fill/index.mjs +83 -74
  36. package/dist/esm/fill/index.mjs.map +1 -1
  37. package/dist/esm/{fill/getTargetDictionary.mjs → getTargetDictionary.mjs} +4 -3
  38. package/dist/esm/getTargetDictionary.mjs.map +1 -0
  39. package/dist/esm/index.mjs +1 -0
  40. package/dist/esm/index.mjs.map +1 -1
  41. package/dist/esm/listContentDeclaration.mjs +2 -1
  42. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  43. package/dist/esm/liveSync.mjs +2 -2
  44. package/dist/esm/liveSync.mjs.map +1 -1
  45. package/dist/esm/pull.mjs +3 -6
  46. package/dist/esm/pull.mjs.map +1 -1
  47. package/dist/esm/push.mjs +11 -7
  48. package/dist/esm/push.mjs.map +1 -1
  49. package/dist/esm/pushConfig.mjs +3 -10
  50. package/dist/esm/pushConfig.mjs.map +1 -1
  51. package/dist/esm/reviewDoc.mjs +3 -2
  52. package/dist/esm/reviewDoc.mjs.map +1 -1
  53. package/dist/esm/test/index.mjs +1 -1
  54. package/dist/esm/test/index.mjs.map +1 -1
  55. package/dist/esm/test/listMissingTranslations.mjs +8 -4
  56. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  57. package/dist/esm/translateDoc.mjs +3 -2
  58. package/dist/esm/translateDoc.mjs.map +1 -1
  59. package/dist/esm/utils/checkAccess.mjs +54 -0
  60. package/dist/esm/utils/checkAccess.mjs.map +1 -0
  61. package/dist/types/cli.d.ts.map +1 -1
  62. package/dist/types/editor.d.ts +7 -0
  63. package/dist/types/editor.d.ts.map +1 -0
  64. package/dist/types/fill/index.d.ts +3 -9
  65. package/dist/types/fill/index.d.ts.map +1 -1
  66. package/dist/types/getTargetDictionary.d.ts +15 -0
  67. package/dist/types/getTargetDictionary.d.ts.map +1 -0
  68. package/dist/types/index.d.ts +1 -0
  69. package/dist/types/index.d.ts.map +1 -1
  70. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  71. package/dist/types/pull.d.ts.map +1 -1
  72. package/dist/types/push.d.ts.map +1 -1
  73. package/dist/types/pushConfig.d.ts.map +1 -1
  74. package/dist/types/reviewDoc.d.ts.map +1 -1
  75. package/dist/types/test/listMissingTranslations.d.ts +4 -4
  76. package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
  77. package/dist/types/translateDoc.d.ts.map +1 -1
  78. package/dist/types/utils/checkAccess.d.ts +5 -0
  79. package/dist/types/utils/checkAccess.d.ts.map +1 -0
  80. package/package.json +14 -14
  81. package/dist/cjs/fill/getTargetDictionary.cjs.map +0 -1
  82. package/dist/cjs/utils/checkAIAccess.cjs +0 -44
  83. package/dist/cjs/utils/checkAIAccess.cjs.map +0 -1
  84. package/dist/esm/fill/getTargetDictionary.mjs.map +0 -1
  85. package/dist/esm/utils/checkAIAccess.mjs +0 -20
  86. package/dist/esm/utils/checkAIAccess.mjs.map +0 -1
  87. package/dist/types/fill/getTargetDictionary.d.ts +0 -4
  88. package/dist/types/fill/getTargetDictionary.d.ts.map +0 -1
  89. package/dist/types/utils/checkAIAccess.d.ts +0 -4
  90. package/dist/types/utils/checkAIAccess.d.ts.map +0 -1
package/dist/cjs/cli.cjs CHANGED
@@ -38,6 +38,7 @@ var import_path = require("path");
38
38
  var import_url = require("url");
39
39
  var import_build = require('./build.cjs');
40
40
  var import_config = require('./config.cjs');
41
+ var import_editor = require('./editor.cjs');
41
42
  var import_fill = require('./fill/index.cjs');
42
43
  var import_listContentDeclaration = require('./listContentDeclaration.cjs');
43
44
  var import_liveSync = require('./liveSync.cjs');
@@ -391,6 +392,15 @@ const setAPI = () => {
391
392
  );
392
393
  applyOptions(liveCmd, liveOptions);
393
394
  liveCmd.action((options) => (0, import_liveSync.liveSync)(options));
395
+ const editorProgram = program.command("editor").description("Visual editor operations");
396
+ const editorStartCmd = editorProgram.command("start").description("Start the Intlayer visual editor");
397
+ applyConfigOptions(editorStartCmd);
398
+ editorStartCmd.action((options) => {
399
+ (0, import_editor.startEditor)({
400
+ env: options.env,
401
+ envFile: options.envFile
402
+ });
403
+ });
394
404
  program.parse(process.argv);
395
405
  return program;
396
406
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import type { AIOptions as BaseAIOptions } from '@intlayer/api';\nimport type { GetConfigurationOptions } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { Command } from 'commander';\nimport { dirname as pathDirname } from 'path';\nimport { fileURLToPath } from 'url';\nimport {\n DiffMode,\n ListGitFilesOptions,\n} from '../../chokidar/dist/types/listGitFiles';\nimport { build } from './build';\nimport { getConfig } from './config';\nimport { fill, FillOptions } from './fill';\nimport { listContentDeclaration } from './listContentDeclaration';\nimport { liveSync } from './liveSync';\nimport { pull } from './pull';\nimport { push } from './push';\nimport { pushConfig } from './pushConfig';\nimport { reviewDoc } from './reviewDoc';\nimport { testMissingTranslations } from './test';\nimport { translateDoc } from './translateDoc';\nimport { getParentPackageJSON } from './utils/getParentPackageJSON';\n\n// Extended AI options to include customPrompt\ntype AIOptions = BaseAIOptions & {\n customPrompt?: string;\n};\n\nconst isESModule = typeof import.meta.url === 'string';\n\nexport const dirname = isESModule\n ? pathDirname(fileURLToPath(import.meta.url))\n : __dirname;\n\nconst packageJson = getParentPackageJSON(dirname);\n\nconst logOptions = [\n ['--verbose', 'Verbose'],\n ['--prefix [prefix]', 'Prefix'],\n];\n\nconst configurationOptions = [\n ['--env-file [envFile]', 'Environment file'],\n ['-e, --env [env]', 'Environment'],\n ['--base-dir [baseDir]', 'Base directory'],\n ...logOptions,\n];\n\nconst aiOptions = [\n ['--provider [provider]', 'Provider'],\n ['--temperature [temperature]', 'Temperature'],\n ['--model [model]', 'Model'],\n ['--api-key [apiKey]', 'Provider API key'],\n ['--custom-prompt [prompt]', 'Custom prompt'],\n ['--application-context [applicationContext]', 'Application context'],\n];\n\nconst gitOptions = [\n ['--git-diff [gitDiff]', 'Git diff mode - Check git diff between two refs'],\n ['--git-diff-base [gitDiffBase]', 'Git diff base ref'],\n ['--git-diff-current [gitDiffCurrent]', 'Git diff current ref'],\n ['--uncommitted [uncommitted]', 'Uncommitted'],\n ['--unpushed [unpushed]', 'Unpushed'],\n ['--untracked [untracked]', 'Untracked'],\n];\n\nconst extractKeysFromOptions = (options: object, keys: string[]) =>\n keys.filter((key) => options[key as keyof typeof options]);\n\n/**\n * Helper functions to apply common options to commands\n */\nconst applyOptions = (command: Command, options: string[][]) => {\n options.forEach(([flag, description]) => command.option(flag, description));\n return command;\n};\n\nconst removeUndefined = <T extends Record<string, any>>(obj: T): T =>\n Object.fromEntries(\n Object.entries(obj).filter(([_, value]) => value !== undefined)\n ) as T;\n\nconst applyConfigOptions = (command: Command) =>\n applyOptions(command, configurationOptions);\nconst applyAIOptions = (command: Command) => applyOptions(command, aiOptions);\nconst applyGitOptions = (command: Command) => applyOptions(command, gitOptions);\n\nconst extractAiOptions = (options: AIOptions): AIOptions | undefined => {\n const {\n apiKey,\n provider,\n model,\n temperature,\n applicationContext,\n customPrompt,\n } = options;\n\n return removeUndefined({\n apiKey: apiKey ?? configuration.ai?.apiKey,\n provider: provider ?? (configuration.ai?.provider as AIOptions['provider']),\n model: model ?? configuration.ai?.model,\n temperature: temperature ?? configuration.ai?.temperature,\n applicationContext:\n applicationContext ?? configuration.ai?.applicationContext,\n customPrompt: customPrompt ?? (configuration.ai as any)?.customPrompt,\n });\n};\n\ntype GitOptions = {\n gitDiff?: boolean;\n gitDiffBase?: string;\n gitDiffCurrent?: string;\n uncommitted?: boolean;\n unpushed?: boolean;\n untracked?: boolean;\n};\n\nconst gitOptionKeys: (keyof GitOptions)[] = [\n 'gitDiff',\n 'gitDiffBase',\n 'gitDiffCurrent',\n 'uncommitted',\n 'unpushed',\n 'untracked',\n];\n\nconst extractGitOptions = (\n options: GitOptions\n): ListGitFilesOptions | undefined => {\n const filteredOptions = extractKeysFromOptions(options, gitOptionKeys);\n\n const isOptionEmpty = !Object.values(filteredOptions).some(Boolean);\n\n if (isOptionEmpty) return undefined;\n\n const {\n gitDiff,\n gitDiffBase,\n gitDiffCurrent,\n uncommitted,\n unpushed,\n untracked,\n } = options;\n\n const mode = [\n gitDiff && 'gitDiff',\n uncommitted && 'uncommitted',\n unpushed && 'unpushed',\n untracked && 'untracked',\n ].filter(Boolean) as DiffMode[];\n\n return removeUndefined({\n mode,\n baseRef: gitDiffBase,\n currentRef: gitDiffCurrent,\n absolute: true,\n });\n};\n\ntype LogOptions = {\n prefix?: string;\n verbose?: boolean;\n};\n\nexport type ConfigurationOptions = {\n baseDir?: string;\n env?: string;\n envFile?: string;\n} & LogOptions;\n\nconst configurationOptionKeys: (keyof ConfigurationOptions)[] = [\n 'baseDir',\n 'env',\n 'envFile',\n 'verbose',\n 'prefix',\n];\n\nconst extractConfigOptions = (\n options: ConfigurationOptions\n): GetConfigurationOptions | undefined => {\n const filteredOptions = extractKeysFromOptions(\n options,\n configurationOptionKeys\n );\n\n const isOptionEmpty = !Object.values(filteredOptions).some(Boolean);\n\n if (isOptionEmpty) {\n return undefined;\n }\n\n const { baseDir, env, envFile, verbose, prefix } = options;\n\n const log = {\n prefix: prefix ?? '', // Should not consider the prefix set in the intlayer configuration file\n verbose,\n };\n\n const override = {\n log,\n };\n\n return removeUndefined({\n baseDir,\n env,\n envFile,\n override,\n });\n};\n\n/**\n * Set the API for the CLI\n *\n * Example of commands:\n *\n * npm run intlayer build --watch\n * npm run intlayer push --dictionaries id1 id2 id3 --deleteLocaleDir\n */\nexport const setAPI = (): Command => {\n const program = new Command();\n\n program.version(packageJson.version!).description('Intlayer CLI');\n\n /**\n * DICTIONARIES\n */\n\n const dictionariesProgram = program\n .command('dictionary')\n .alias('dictionaries')\n .alias('dic')\n .description('Dictionaries operations');\n\n // Dictionary build command\n const buildOptions = {\n description: 'Build the dictionaries',\n options: [['-w, --watch', 'Watch for changes']],\n };\n\n // Add build command to dictionaries program\n const dictionariesBuildCmd = dictionariesProgram\n .command('build')\n .description(buildOptions.description);\n\n applyOptions(dictionariesBuildCmd, buildOptions.options);\n applyConfigOptions(dictionariesBuildCmd);\n dictionariesBuildCmd.action((options) => {\n build({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n // Add build command to root program as well\n const rootBuildCmd = program\n .command('build')\n .description(buildOptions.description);\n\n applyOptions(rootBuildCmd, buildOptions.options);\n applyConfigOptions(rootBuildCmd);\n rootBuildCmd.action((options) => {\n build({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n // Dictionary pull command\n const pullOptions = {\n description: 'Pull dictionaries from the server',\n options: [\n ['-d, --dictionaries [ids...]', 'List of dictionary IDs to pull'],\n ['--new-dictionaries-path [path]', 'Path to save the new dictionaries'],\n ],\n };\n\n // Add pull command to dictionaries program\n const dictionariesPullCmd = dictionariesProgram\n .command('pull')\n .description(pullOptions.description);\n\n applyOptions(dictionariesPullCmd, pullOptions.options);\n applyConfigOptions(dictionariesPullCmd);\n dictionariesPullCmd.action((options) => {\n pull({\n ...options,\n configOptions: {\n ...options.configOptions,\n baseDir: options.baseDir,\n },\n });\n });\n\n // Add pull command to root program as well\n const rootPullCmd = program\n .command('pull')\n .description(pullOptions.description);\n\n applyOptions(rootPullCmd, pullOptions.options);\n applyConfigOptions(rootPullCmd);\n rootPullCmd.action((options) => {\n pull({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n // Dictionary push command\n const pushOptions = {\n description:\n 'Push all dictionaries. Create or update the pushed dictionaries',\n options: [\n ['-d, --dictionaries [ids...]', 'List of dictionary IDs to push'],\n [\n '-r, --delete-locale-dictionary',\n 'Delete the local dictionaries after pushing',\n ],\n [\n '-k, --keep-locale-dictionary',\n 'Keep the local dictionaries after pushing',\n ],\n ],\n };\n\n // Add push command to dictionaries program\n const dictionariesPushCmd = dictionariesProgram\n .command('push')\n .description(pushOptions.description);\n\n applyOptions(dictionariesPushCmd, pushOptions.options);\n applyConfigOptions(dictionariesPushCmd);\n applyGitOptions(dictionariesPushCmd);\n\n dictionariesPushCmd.action((options) =>\n push({\n ...options,\n gitOptions: extractGitOptions(options),\n configOptions: extractConfigOptions(options),\n } as FillOptions)\n );\n\n // Add push command to root program as well\n const rootPushCmd = program\n .command('push')\n .description(pushOptions.description);\n\n applyOptions(rootPushCmd, pushOptions.options);\n applyConfigOptions(rootPushCmd);\n applyGitOptions(rootPushCmd);\n\n rootPushCmd.action((options) =>\n push({\n ...options,\n gitOptions: extractGitOptions(options),\n configOptions: extractConfigOptions(options),\n } as FillOptions)\n );\n\n /**\n * CONFIGURATION\n */\n\n // Define the parent command\n const configurationProgram = program\n .command('configuration')\n .alias('config')\n .alias('conf')\n .description('Configuration operations');\n\n const configGetCmd = configurationProgram\n .command('get')\n .description('Get the configuration');\n\n applyConfigOptions(configGetCmd);\n configGetCmd.action((options) => {\n getConfig({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n // Define the `push config` subcommand and add it to the `push` command\n const configPushCmd = configurationProgram\n .command('push')\n .description('Push the configuration');\n\n applyConfigOptions(configPushCmd);\n configPushCmd.action((options) => {\n pushConfig({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n /**\n * CONTENT DECLARATION\n */\n\n const contentProgram = program\n .command('content')\n .description('Content declaration operations');\n\n contentProgram\n .command('list')\n .description('List the content declaration files')\n .action(listContentDeclaration);\n\n const testProgram = contentProgram\n .command('test')\n .description('Test if there are missing translations');\n\n applyConfigOptions(testProgram);\n testProgram.action((options) => {\n testMissingTranslations({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n const fillProgram = program\n .command('fill')\n .description('Fill the dictionaries')\n .option('-f, --file [files...]', 'List of Dictionary files to fill')\n .option('--source-locale [sourceLocale]', 'Source locale to translate from')\n .option(\n '--output-locales [outputLocales...]',\n 'Target locales to translate to'\n )\n .option(\n '--mode [mode]',\n 'Fill mode: complete, review. Complete will fill all missing content, review will fill missing content and review existing keys',\n 'complete'\n )\n .option('-k, --keys [keys...]', 'Filter dictionaries based on keys')\n .option(\n '--excluded-keys [excludedKeys...]',\n 'Filter out dictionaries based on keys'\n )\n .option(\n '--path-filter [pathFilters...]',\n 'Filter dictionaries based on glob pattern'\n )\n .option(\n '--build [build]',\n 'Build the dictionaries before filling to ensure the content is up to date'\n );\n\n applyConfigOptions(fillProgram);\n applyAIOptions(fillProgram);\n applyGitOptions(fillProgram);\n\n fillProgram.action((options) =>\n fill({\n ...options,\n aiOptions: extractAiOptions(options),\n gitOptions: extractGitOptions(options),\n configOptions: extractConfigOptions(options),\n } as FillOptions)\n );\n\n /**\n * DOCS\n */\n\n const docParams = [\n ['--doc-pattern [docPattern...]', 'Documentation pattern'],\n [\n '--excluded-glob-pattern [excludedGlobPattern...]',\n 'Excluded glob pattern',\n ],\n [\n '--nb-simultaneous-file-processed [nbSimultaneousFileProcessed]',\n 'Number of simultaneous file processed',\n ],\n ['--locales [locales...]', 'Locales'],\n ['--base-locale [baseLocale]', 'Base locale'],\n [\n '--custom-instructions [customInstructions]',\n 'Custom instructions added to the prompt. Usefull to apply specific rules regarding formatting, urls translation, etc.',\n ],\n [\n '--skip-if-modified-before [skipIfModifiedBefore]',\n 'Skip the file if it has been modified before the given time. Can be an absolute time as \"2025-12-05\" (string or Date) or a relative time in ms `1 * 60 * 60 * 1000` (1 hour). This option check update time of the file using the `fs.stat` method. So it could be impacted by Git or other tools that modify the file.',\n ],\n [\n '--skip-if-modified-after [skipIfModifiedAfter]',\n 'Skip the file if it has been modified within the given time. Can be an absolute time as \"2025-12-05\" (string or Date) or a relative time in ms `1 * 60 * 60 * 1000` (1 hour). This option check update time of the file using the `fs.stat` method. So it could be impacted by Git or other tools that modify the file.',\n ],\n ];\n\n const docProgram = program\n .command('doc')\n .description('Documentation operations');\n\n const translateProgram = docProgram\n .command('translate')\n .description('Translate the documentation');\n\n applyConfigOptions(translateProgram);\n applyAIOptions(translateProgram);\n applyGitOptions(translateProgram);\n applyOptions(translateProgram, docParams);\n\n translateProgram.action((options) =>\n translateDoc({\n docPattern: options.docPattern,\n excludedGlobPattern: options.excludedGlobPattern,\n locales: options.locales,\n baseLocale: options.baseLocale,\n aiOptions: extractAiOptions(options),\n gitOptions: extractGitOptions(options),\n nbSimultaneousFileProcessed: options.nbSimultaneousFileProcessed,\n configOptions: extractConfigOptions(options),\n customInstructions: options.customInstructions,\n skipIfModifiedBefore: options.skipIfModifiedBefore,\n skipIfModifiedAfter: options.skipIfModifiedAfter,\n })\n );\n\n const reviewProgram = docProgram\n .command('review')\n .description('Review the documentation');\n\n applyConfigOptions(reviewProgram);\n applyAIOptions(reviewProgram);\n applyGitOptions(reviewProgram);\n applyOptions(reviewProgram, docParams);\n\n reviewProgram.action((options) =>\n reviewDoc({\n docPattern: options.docPattern,\n excludedGlobPattern: options.excludedGlobPattern,\n locales: options.locales,\n baseLocale: options.baseLocale,\n aiOptions: extractAiOptions(options),\n gitOptions: extractGitOptions(options),\n nbSimultaneousFileProcessed: options.nbSimultaneousFileProcessed,\n configOptions: extractConfigOptions(options),\n customInstructions: options.customInstructions,\n skipIfModifiedBefore: options.skipIfModifiedBefore,\n skipIfModifiedAfter: options.skipIfModifiedAfter,\n })\n );\n\n /**\n * LIVE SYNC\n */\n\n const liveOptions = [\n ['--process [process]', 'Start command in parallel with the live sync'],\n ];\n\n const liveCmd = program\n .command('live')\n .description(\n 'Live sync - Watch for changes made on the CMS and update the application content accordingly'\n );\n\n applyOptions(liveCmd, liveOptions);\n\n liveCmd.action((options) => liveSync(options));\n\n program.parse(process.argv);\n\n return program;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAC1B,uBAAwB;AACxB,kBAAuC;AACvC,iBAA8B;AAK9B,mBAAsB;AACtB,oBAA0B;AAC1B,kBAAkC;AAClC,oCAAuC;AACvC,sBAAyB;AACzB,kBAAqB;AACrB,kBAAqB;AACrB,wBAA2B;AAC3B,uBAA0B;AAC1B,kBAAwC;AACxC,0BAA6B;AAC7B,kCAAqC;AArBrC;AA4BA,MAAM,aAAa,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,MACrC,6BAA6B,QAAQ;AAAA,MACrC,eAAe,qBAAqB,OAAO;AAAA,MAC3C,oBAAoB,QAAQ;AAAA,MAC5B,sBAAsB,QAAQ;AAAA,MAC9B,qBAAqB,QAAQ;AAAA,IAC/B,CAAC;AAAA,EACH;AAEA,QAAM,gBAAgB,WACnB,QAAQ,QAAQ,EAChB,YAAY,0BAA0B;AAEzC,qBAAmB,aAAa;AAChC,iBAAe,aAAa;AAC5B,kBAAgB,aAAa;AAC7B,eAAa,eAAe,SAAS;AAErC,gBAAc;AAAA,IAAO,CAAC,gBACpB,4BAAU;AAAA,MACR,YAAY,QAAQ;AAAA,MACpB,qBAAqB,QAAQ;AAAA,MAC7B,SAAS,QAAQ;AAAA,MACjB,YAAY,QAAQ;AAAA,MACpB,WAAW,iBAAiB,OAAO;AAAA,MACnC,YAAY,kBAAkB,OAAO;AAAA,MACrC,6BAA6B,QAAQ;AAAA,MACrC,eAAe,qBAAqB,OAAO;AAAA,MAC3C,oBAAoB,QAAQ;AAAA,MAC5B,sBAAsB,QAAQ;AAAA,MAC9B,qBAAqB,QAAQ;AAAA,IAC/B,CAAC;AAAA,EACH;AAMA,QAAM,cAAc;AAAA,IAClB,CAAC,uBAAuB,8CAA8C;AAAA,EACxE;AAEA,QAAM,UAAU,QACb,QAAQ,MAAM,EACd;AAAA,IACC;AAAA,EACF;AAEF,eAAa,SAAS,WAAW;AAEjC,UAAQ,OAAO,CAAC,gBAAY,0BAAS,OAAO,CAAC;AAE7C,UAAQ,MAAM,QAAQ,IAAI;AAE1B,SAAO;AACT;","names":["pathDirname","configuration"]}
1
+ {"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import type { AIOptions as BaseAIOptions } from '@intlayer/api';\nimport type { GetConfigurationOptions } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { Command } from 'commander';\nimport { dirname as pathDirname } from 'path';\nimport { fileURLToPath } from 'url';\nimport {\n DiffMode,\n ListGitFilesOptions,\n} from '../../chokidar/dist/types/listGitFiles';\nimport { build } from './build';\nimport { getConfig } from './config';\nimport { startEditor } from './editor';\nimport { fill, FillOptions } from './fill';\nimport { listContentDeclaration } from './listContentDeclaration';\nimport { liveSync } from './liveSync';\nimport { pull } from './pull';\nimport { push } from './push';\nimport { pushConfig } from './pushConfig';\nimport { reviewDoc } from './reviewDoc';\nimport { testMissingTranslations } from './test';\nimport { translateDoc } from './translateDoc';\nimport { getParentPackageJSON } from './utils/getParentPackageJSON';\n\n// Extended AI options to include customPrompt\ntype AIOptions = BaseAIOptions & {\n customPrompt?: string;\n};\n\nconst isESModule = typeof import.meta.url === 'string';\n\nexport const dirname = isESModule\n ? pathDirname(fileURLToPath(import.meta.url))\n : __dirname;\n\nconst packageJson = getParentPackageJSON(dirname);\n\nconst logOptions = [\n ['--verbose', 'Verbose'],\n ['--prefix [prefix]', 'Prefix'],\n];\n\nconst configurationOptions = [\n ['--env-file [envFile]', 'Environment file'],\n ['-e, --env [env]', 'Environment'],\n ['--base-dir [baseDir]', 'Base directory'],\n ...logOptions,\n];\n\nconst aiOptions = [\n ['--provider [provider]', 'Provider'],\n ['--temperature [temperature]', 'Temperature'],\n ['--model [model]', 'Model'],\n ['--api-key [apiKey]', 'Provider API key'],\n ['--custom-prompt [prompt]', 'Custom prompt'],\n ['--application-context [applicationContext]', 'Application context'],\n];\n\nconst gitOptions = [\n ['--git-diff [gitDiff]', 'Git diff mode - Check git diff between two refs'],\n ['--git-diff-base [gitDiffBase]', 'Git diff base ref'],\n ['--git-diff-current [gitDiffCurrent]', 'Git diff current ref'],\n ['--uncommitted [uncommitted]', 'Uncommitted'],\n ['--unpushed [unpushed]', 'Unpushed'],\n ['--untracked [untracked]', 'Untracked'],\n];\n\nconst extractKeysFromOptions = (options: object, keys: string[]) =>\n keys.filter((key) => options[key as keyof typeof options]);\n\n/**\n * Helper functions to apply common options to commands\n */\nconst applyOptions = (command: Command, options: string[][]) => {\n options.forEach(([flag, description]) => command.option(flag, description));\n return command;\n};\n\nconst removeUndefined = <T extends Record<string, any>>(obj: T): T =>\n Object.fromEntries(\n Object.entries(obj).filter(([_, value]) => value !== undefined)\n ) as T;\n\nconst applyConfigOptions = (command: Command) =>\n applyOptions(command, configurationOptions);\nconst applyAIOptions = (command: Command) => applyOptions(command, aiOptions);\nconst applyGitOptions = (command: Command) => applyOptions(command, gitOptions);\n\nconst extractAiOptions = (options: AIOptions): AIOptions | undefined => {\n const {\n apiKey,\n provider,\n model,\n temperature,\n applicationContext,\n customPrompt,\n } = options;\n\n return removeUndefined({\n apiKey: apiKey ?? configuration.ai?.apiKey,\n provider: provider ?? (configuration.ai?.provider as AIOptions['provider']),\n model: model ?? configuration.ai?.model,\n temperature: temperature ?? configuration.ai?.temperature,\n applicationContext:\n applicationContext ?? configuration.ai?.applicationContext,\n customPrompt: customPrompt ?? (configuration.ai as any)?.customPrompt,\n });\n};\n\ntype GitOptions = {\n gitDiff?: boolean;\n gitDiffBase?: string;\n gitDiffCurrent?: string;\n uncommitted?: boolean;\n unpushed?: boolean;\n untracked?: boolean;\n};\n\nconst gitOptionKeys: (keyof GitOptions)[] = [\n 'gitDiff',\n 'gitDiffBase',\n 'gitDiffCurrent',\n 'uncommitted',\n 'unpushed',\n 'untracked',\n];\n\nconst extractGitOptions = (\n options: GitOptions\n): ListGitFilesOptions | undefined => {\n const filteredOptions = extractKeysFromOptions(options, gitOptionKeys);\n\n const isOptionEmpty = !Object.values(filteredOptions).some(Boolean);\n\n if (isOptionEmpty) return undefined;\n\n const {\n gitDiff,\n gitDiffBase,\n gitDiffCurrent,\n uncommitted,\n unpushed,\n untracked,\n } = options;\n\n const mode = [\n gitDiff && 'gitDiff',\n uncommitted && 'uncommitted',\n unpushed && 'unpushed',\n untracked && 'untracked',\n ].filter(Boolean) as DiffMode[];\n\n return removeUndefined({\n mode,\n baseRef: gitDiffBase,\n currentRef: gitDiffCurrent,\n absolute: true,\n });\n};\n\ntype LogOptions = {\n prefix?: string;\n verbose?: boolean;\n};\n\nexport type ConfigurationOptions = {\n baseDir?: string;\n env?: string;\n envFile?: string;\n} & LogOptions;\n\nconst configurationOptionKeys: (keyof ConfigurationOptions)[] = [\n 'baseDir',\n 'env',\n 'envFile',\n 'verbose',\n 'prefix',\n];\n\nconst extractConfigOptions = (\n options: ConfigurationOptions\n): GetConfigurationOptions | undefined => {\n const filteredOptions = extractKeysFromOptions(\n options,\n configurationOptionKeys\n );\n\n const isOptionEmpty = !Object.values(filteredOptions).some(Boolean);\n\n if (isOptionEmpty) {\n return undefined;\n }\n\n const { baseDir, env, envFile, verbose, prefix } = options;\n\n const log = {\n prefix: prefix ?? '', // Should not consider the prefix set in the intlayer configuration file\n verbose,\n };\n\n const override = {\n log,\n };\n\n return removeUndefined({\n baseDir,\n env,\n envFile,\n override,\n });\n};\n\n/**\n * Set the API for the CLI\n *\n * Example of commands:\n *\n * npm run intlayer build --watch\n * npm run intlayer push --dictionaries id1 id2 id3 --deleteLocaleDir\n */\nexport const setAPI = (): Command => {\n const program = new Command();\n\n program.version(packageJson.version!).description('Intlayer CLI');\n\n /**\n * DICTIONARIES\n */\n\n const dictionariesProgram = program\n .command('dictionary')\n .alias('dictionaries')\n .alias('dic')\n .description('Dictionaries operations');\n\n // Dictionary build command\n const buildOptions = {\n description: 'Build the dictionaries',\n options: [['-w, --watch', 'Watch for changes']],\n };\n\n // Add build command to dictionaries program\n const dictionariesBuildCmd = dictionariesProgram\n .command('build')\n .description(buildOptions.description);\n\n applyOptions(dictionariesBuildCmd, buildOptions.options);\n applyConfigOptions(dictionariesBuildCmd);\n dictionariesBuildCmd.action((options) => {\n build({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n // Add build command to root program as well\n const rootBuildCmd = program\n .command('build')\n .description(buildOptions.description);\n\n applyOptions(rootBuildCmd, buildOptions.options);\n applyConfigOptions(rootBuildCmd);\n rootBuildCmd.action((options) => {\n build({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n // Dictionary pull command\n const pullOptions = {\n description: 'Pull dictionaries from the server',\n options: [\n ['-d, --dictionaries [ids...]', 'List of dictionary IDs to pull'],\n ['--new-dictionaries-path [path]', 'Path to save the new dictionaries'],\n ],\n };\n\n // Add pull command to dictionaries program\n const dictionariesPullCmd = dictionariesProgram\n .command('pull')\n .description(pullOptions.description);\n\n applyOptions(dictionariesPullCmd, pullOptions.options);\n applyConfigOptions(dictionariesPullCmd);\n dictionariesPullCmd.action((options) => {\n pull({\n ...options,\n configOptions: {\n ...options.configOptions,\n baseDir: options.baseDir,\n },\n });\n });\n\n // Add pull command to root program as well\n const rootPullCmd = program\n .command('pull')\n .description(pullOptions.description);\n\n applyOptions(rootPullCmd, pullOptions.options);\n applyConfigOptions(rootPullCmd);\n rootPullCmd.action((options) => {\n pull({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n // Dictionary push command\n const pushOptions = {\n description:\n 'Push all dictionaries. Create or update the pushed dictionaries',\n options: [\n ['-d, --dictionaries [ids...]', 'List of dictionary IDs to push'],\n [\n '-r, --delete-locale-dictionary',\n 'Delete the local dictionaries after pushing',\n ],\n [\n '-k, --keep-locale-dictionary',\n 'Keep the local dictionaries after pushing',\n ],\n ],\n };\n\n // Add push command to dictionaries program\n const dictionariesPushCmd = dictionariesProgram\n .command('push')\n .description(pushOptions.description);\n\n applyOptions(dictionariesPushCmd, pushOptions.options);\n applyConfigOptions(dictionariesPushCmd);\n applyGitOptions(dictionariesPushCmd);\n\n dictionariesPushCmd.action((options) =>\n push({\n ...options,\n gitOptions: extractGitOptions(options),\n configOptions: extractConfigOptions(options),\n } as FillOptions)\n );\n\n // Add push command to root program as well\n const rootPushCmd = program\n .command('push')\n .description(pushOptions.description);\n\n applyOptions(rootPushCmd, pushOptions.options);\n applyConfigOptions(rootPushCmd);\n applyGitOptions(rootPushCmd);\n\n rootPushCmd.action((options) =>\n push({\n ...options,\n gitOptions: extractGitOptions(options),\n configOptions: extractConfigOptions(options),\n } as FillOptions)\n );\n\n /**\n * CONFIGURATION\n */\n\n // Define the parent command\n const configurationProgram = program\n .command('configuration')\n .alias('config')\n .alias('conf')\n .description('Configuration operations');\n\n const configGetCmd = configurationProgram\n .command('get')\n .description('Get the configuration');\n\n applyConfigOptions(configGetCmd);\n configGetCmd.action((options) => {\n getConfig({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n // Define the `push config` subcommand and add it to the `push` command\n const configPushCmd = configurationProgram\n .command('push')\n .description('Push the configuration');\n\n applyConfigOptions(configPushCmd);\n configPushCmd.action((options) => {\n pushConfig({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n /**\n * CONTENT DECLARATION\n */\n\n const contentProgram = program\n .command('content')\n .description('Content declaration operations');\n\n contentProgram\n .command('list')\n .description('List the content declaration files')\n .action(listContentDeclaration);\n\n const testProgram = contentProgram\n .command('test')\n .description('Test if there are missing translations');\n\n applyConfigOptions(testProgram);\n testProgram.action((options) => {\n testMissingTranslations({\n ...options,\n configOptions: extractConfigOptions(options),\n });\n });\n\n const fillProgram = program\n .command('fill')\n .description('Fill the dictionaries')\n .option('-f, --file [files...]', 'List of Dictionary files to fill')\n .option('--source-locale [sourceLocale]', 'Source locale to translate from')\n .option(\n '--output-locales [outputLocales...]',\n 'Target locales to translate to'\n )\n .option(\n '--mode [mode]',\n 'Fill mode: complete, review. Complete will fill all missing content, review will fill missing content and review existing keys',\n 'complete'\n )\n .option('-k, --keys [keys...]', 'Filter dictionaries based on keys')\n .option(\n '--excluded-keys [excludedKeys...]',\n 'Filter out dictionaries based on keys'\n )\n .option(\n '--path-filter [pathFilters...]',\n 'Filter dictionaries based on glob pattern'\n )\n .option(\n '--build [build]',\n 'Build the dictionaries before filling to ensure the content is up to date'\n );\n\n applyConfigOptions(fillProgram);\n applyAIOptions(fillProgram);\n applyGitOptions(fillProgram);\n\n fillProgram.action((options) =>\n fill({\n ...options,\n aiOptions: extractAiOptions(options),\n gitOptions: extractGitOptions(options),\n configOptions: extractConfigOptions(options),\n } as FillOptions)\n );\n\n /**\n * DOCS\n */\n\n const docParams = [\n ['--doc-pattern [docPattern...]', 'Documentation pattern'],\n [\n '--excluded-glob-pattern [excludedGlobPattern...]',\n 'Excluded glob pattern',\n ],\n [\n '--nb-simultaneous-file-processed [nbSimultaneousFileProcessed]',\n 'Number of simultaneous file processed',\n ],\n ['--locales [locales...]', 'Locales'],\n ['--base-locale [baseLocale]', 'Base locale'],\n [\n '--custom-instructions [customInstructions]',\n 'Custom instructions added to the prompt. Usefull to apply specific rules regarding formatting, urls translation, etc.',\n ],\n [\n '--skip-if-modified-before [skipIfModifiedBefore]',\n 'Skip the file if it has been modified before the given time. Can be an absolute time as \"2025-12-05\" (string or Date) or a relative time in ms `1 * 60 * 60 * 1000` (1 hour). This option check update time of the file using the `fs.stat` method. So it could be impacted by Git or other tools that modify the file.',\n ],\n [\n '--skip-if-modified-after [skipIfModifiedAfter]',\n 'Skip the file if it has been modified within the given time. Can be an absolute time as \"2025-12-05\" (string or Date) or a relative time in ms `1 * 60 * 60 * 1000` (1 hour). This option check update time of the file using the `fs.stat` method. So it could be impacted by Git or other tools that modify the file.',\n ],\n ];\n\n const docProgram = program\n .command('doc')\n .description('Documentation operations');\n\n const translateProgram = docProgram\n .command('translate')\n .description('Translate the documentation');\n\n applyConfigOptions(translateProgram);\n applyAIOptions(translateProgram);\n applyGitOptions(translateProgram);\n applyOptions(translateProgram, docParams);\n\n translateProgram.action((options) =>\n translateDoc({\n docPattern: options.docPattern,\n excludedGlobPattern: options.excludedGlobPattern,\n locales: options.locales,\n baseLocale: options.baseLocale,\n aiOptions: extractAiOptions(options),\n gitOptions: extractGitOptions(options),\n nbSimultaneousFileProcessed: options.nbSimultaneousFileProcessed,\n configOptions: extractConfigOptions(options),\n customInstructions: options.customInstructions,\n skipIfModifiedBefore: options.skipIfModifiedBefore,\n skipIfModifiedAfter: options.skipIfModifiedAfter,\n })\n );\n\n const reviewProgram = docProgram\n .command('review')\n .description('Review the documentation');\n\n applyConfigOptions(reviewProgram);\n applyAIOptions(reviewProgram);\n applyGitOptions(reviewProgram);\n applyOptions(reviewProgram, docParams);\n\n reviewProgram.action((options) =>\n reviewDoc({\n docPattern: options.docPattern,\n excludedGlobPattern: options.excludedGlobPattern,\n locales: options.locales,\n baseLocale: options.baseLocale,\n aiOptions: extractAiOptions(options),\n gitOptions: extractGitOptions(options),\n nbSimultaneousFileProcessed: options.nbSimultaneousFileProcessed,\n configOptions: extractConfigOptions(options),\n customInstructions: options.customInstructions,\n skipIfModifiedBefore: options.skipIfModifiedBefore,\n skipIfModifiedAfter: options.skipIfModifiedAfter,\n })\n );\n\n /**\n * LIVE SYNC\n */\n\n const liveOptions = [\n ['--process [process]', 'Start command in parallel with the live sync'],\n ];\n\n const liveCmd = program\n .command('live')\n .description(\n 'Live sync - Watch for changes made on the CMS and update the application content accordingly'\n );\n\n applyOptions(liveCmd, liveOptions);\n\n liveCmd.action((options) => liveSync(options));\n\n /**\n * EDITOR\n */\n\n const editorProgram = program\n .command('editor')\n .description('Visual editor operations');\n\n const editorStartCmd = editorProgram\n .command('start')\n .description('Start the Intlayer visual editor');\n\n applyConfigOptions(editorStartCmd);\n\n editorStartCmd.action((options) => {\n startEditor({\n env: options.env,\n envFile: options.envFile,\n });\n });\n\n program.parse(process.argv);\n\n return program;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAC1B,uBAAwB;AACxB,kBAAuC;AACvC,iBAA8B;AAK9B,mBAAsB;AACtB,oBAA0B;AAC1B,oBAA4B;AAC5B,kBAAkC;AAClC,oCAAuC;AACvC,sBAAyB;AACzB,kBAAqB;AACrB,kBAAqB;AACrB,wBAA2B;AAC3B,uBAA0B;AAC1B,kBAAwC;AACxC,0BAA6B;AAC7B,kCAAqC;AAtBrC;AA6BA,MAAM,aAAa,OAAO,YAAY,QAAQ;AAEvC,MAAM,UAAU,iBACnB,YAAAA,aAAY,0BAAc,YAAY,GAAG,CAAC,IAC1C;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OwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var editor_exports = {};
20
+ __export(editor_exports, {
21
+ startEditor: () => startEditor
22
+ });
23
+ module.exports = __toCommonJS(editor_exports);
24
+ var import_child_process = require("child_process");
25
+ var import_module = require("module");
26
+ var import_path = require("path");
27
+ const import_meta = {};
28
+ const startEditor = (options) => {
29
+ const args = ["start"];
30
+ if (options.env) args.push("--env", options.env);
31
+ if (options.envFile) args.push("--env-file", options.envFile);
32
+ const spawnNodeProcess = (binPath) => (0, import_child_process.spawn)(process.execPath, [binPath, ...args], {
33
+ stdio: "inherit",
34
+ env: { ...process.env }
35
+ });
36
+ const spawnWith = (cmd, cmdArgs) => (0, import_child_process.spawn)(cmd, cmdArgs, {
37
+ stdio: "inherit",
38
+ env: { ...process.env }
39
+ });
40
+ try {
41
+ const require2 = (0, import_module.createRequire)(import_meta.url);
42
+ const pkgJsonPath = require2.resolve("intlayer-editor/package.json");
43
+ const pkgDir = (0, import_path.dirname)(pkgJsonPath);
44
+ const binPath = (0, import_path.resolve)(pkgDir, "bin", "intlayer-editor.mjs");
45
+ const child = spawnNodeProcess(binPath);
46
+ child.on("error", () => runFallback());
47
+ child.on("exit", (code) => {
48
+ if (code === 255) process.exit(code ?? 0);
49
+ });
50
+ } catch {
51
+ runFallback();
52
+ }
53
+ function runFallback() {
54
+ const pnpm = spawnWith("pnpm", ["dlx", "intlayer-editor", ...args]);
55
+ pnpm.on("error", () => {
56
+ const npx = spawnWith("npx", ["-y", "intlayer-editor", ...args]);
57
+ npx.on("error", (err) => {
58
+ console.error("Unable to execute intlayer-editor via pnpm or npx.");
59
+ console.error(String(err?.message ?? err));
60
+ process.exit(1);
61
+ });
62
+ });
63
+ }
64
+ };
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ startEditor
68
+ });
69
+ //# sourceMappingURL=editor.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/editor.ts"],"sourcesContent":["import { spawn } from 'child_process';\nimport { createRequire } from 'module';\nimport { dirname as pathDirname, resolve as pathResolve } from 'path';\n\ntype StartEditorOptions = {\n env?: string;\n envFile?: string;\n};\n\nexport const startEditor = (options: StartEditorOptions): void => {\n const args: string[] = ['start'];\n\n if (options.env) args.push('--env', options.env);\n if (options.envFile) args.push('--env-file', options.envFile);\n\n const spawnNodeProcess = (binPath: string) =>\n spawn(process.execPath, [binPath, ...args], {\n stdio: 'inherit',\n env: { ...process.env },\n });\n\n const spawnWith = (cmd: string, cmdArgs: string[]) =>\n spawn(cmd, cmdArgs, {\n stdio: 'inherit',\n env: { ...process.env },\n });\n\n try {\n const require = createRequire(import.meta.url);\n const pkgJsonPath = require.resolve('intlayer-editor/package.json');\n const pkgDir = pathDirname(pkgJsonPath);\n const binPath = pathResolve(pkgDir, 'bin', 'intlayer-editor.mjs');\n\n const child = spawnNodeProcess(binPath);\n child.on('error', () => runFallback());\n child.on('exit', (code) => {\n if (code === 255) process.exit(code ?? 0);\n });\n } catch {\n runFallback();\n }\n\n function runFallback() {\n const pnpm = spawnWith('pnpm', ['dlx', 'intlayer-editor', ...args]);\n pnpm.on('error', () => {\n const npx = spawnWith('npx', ['-y', 'intlayer-editor', ...args]);\n npx.on('error', (err) => {\n console.error('Unable to execute intlayer-editor via pnpm or npx.');\n console.error(String(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AI,GAAG,SAAS,CAAC,QAAQ;AACvB,gBAAQ,MAAM,oDAAoD;AAClE,gBAAQ,MAAM,OAAO,KAAK,WAAW,GAAG,CAAC;AACzC,gBAAQ,KAAK,CAAC;AAAA,MAChB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":["require","pathDirname","pathResolve"]}
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var fill_exports = {};
30
20
  __export(fill_exports, {
@@ -35,12 +25,11 @@ var import_api = require("@intlayer/api");
35
25
  var import_chokidar = require("@intlayer/chokidar");
36
26
  var import_config = require("@intlayer/config");
37
27
  var import_core = require("@intlayer/core");
38
- var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
39
- var import_p_limit = __toESM(require("p-limit"));
28
+ var import_dictionaries_entry = require("@intlayer/dictionaries-entry");
40
29
  var import_path = require("path");
41
- var import_checkAIAccess = require('../utils/checkAIAccess.cjs');
30
+ var import_getTargetDictionary = require('../getTargetDictionary.cjs');
31
+ var import_checkAccess = require('../utils/checkAccess.cjs');
42
32
  var import_autoFill = require('./autoFill.cjs');
43
- var import_getTargetDictionary = require('./getTargetDictionary.cjs');
44
33
  const NB_CONCURRENT_TRANSLATIONS = 8;
45
34
  const fill = async (options) => {
46
35
  const configuration = (0, import_config.getConfiguration)(options.configOptions);
@@ -56,37 +45,40 @@ const fill = async (options) => {
56
45
  const mode = options.mode ?? "complete";
57
46
  const baseLocale = options.sourceLocale ?? defaultLocale;
58
47
  const outputLocales = (options.outputLocales ? (0, import_getTargetDictionary.ensureArray)(options.outputLocales) : locales).filter((locale) => locale !== baseLocale);
59
- (0, import_checkAIAccess.checkAIAccess)(configuration, options.aiOptions);
60
- let oAuth2AccessToken;
61
- if (configuration.editor.clientId) {
62
- const intlayerAuthAPI = (0, import_api.getOAuthAPI)(configuration);
63
- const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();
64
- oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
65
- }
66
- appLogger("Starting fill function", {
67
- level: "info"
68
- });
69
- const targetUnmergedDictionaries = await (0, import_getTargetDictionary.getTargetDictionary)(options);
48
+ const hasAIAccess = await (0, import_checkAccess.checkAIAccess)(configuration, options.aiOptions);
49
+ if (!hasAIAccess) return;
50
+ const intlayerAPI = (0, import_api.getIntlayerAPIProxy)(void 0, configuration);
51
+ const targetUnmergedDictionaries = await (0, import_getTargetDictionary.getTargetUnmergedDictionaries)(options);
70
52
  const affectedDictionaryKeys = /* @__PURE__ */ new Set();
71
53
  targetUnmergedDictionaries.forEach((dict) => {
72
54
  affectedDictionaryKeys.add(dict.key);
73
55
  });
74
- appLogger(
75
- [
76
- "Affected dictionary keys for processing:",
77
- Array.from(affectedDictionaryKeys).map((key) => (0, import_config.colorizeKey)(key)).join(", ")
78
- ],
79
- {
80
- isVerbose: true
81
- }
56
+ appLogger([
57
+ "Affected dictionary keys for processing:",
58
+ Array.from(affectedDictionaryKeys).map((key) => (0, import_config.colorizeKey)(key)).join(", ")
59
+ ]);
60
+ const maxKeyLength = Math.max(
61
+ ...targetUnmergedDictionaries.map((dict) => dict.key.length)
62
+ );
63
+ const maxLocaleLength = Math.max(
64
+ ...locales.map((locale) => (0, import_chokidar.formatLocale)(locale).length)
82
65
  );
83
66
  for (const targetUnmergedDictionary of targetUnmergedDictionaries) {
67
+ const dictionaryPreset = (0, import_config.colon)(
68
+ [
69
+ (0, import_config.colorize)(" - [", import_config.ANSIColors.GREY_DARK),
70
+ (0, import_config.colorizeKey)(targetUnmergedDictionary.key),
71
+ (0, import_config.colorize)("]", import_config.ANSIColors.GREY_DARK)
72
+ ].join(""),
73
+ { colSize: maxKeyLength + 6 }
74
+ );
84
75
  const dictionaryKey = targetUnmergedDictionary.key;
85
- const mainDictionaryToProcess = import_dictionaries_entry.default[dictionaryKey];
76
+ const dictionariesRecord = (0, import_dictionaries_entry.getDictionaries)(configuration);
77
+ const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];
86
78
  const sourceLocale = targetUnmergedDictionary.locale ?? baseLocale;
87
79
  if (!mainDictionaryToProcess) {
88
80
  appLogger(
89
- `Dictionary with key '${(0, import_config.colorizeKey)(dictionaryKey)}' not found in dictionariesRecord. Skipping.`,
81
+ `${dictionaryPreset} Dictionary not found in dictionariesRecord. Skipping.`,
90
82
  {
91
83
  level: "warn"
92
84
  }
@@ -94,21 +86,21 @@ const fill = async (options) => {
94
86
  continue;
95
87
  }
96
88
  if (!targetUnmergedDictionary.filePath) {
97
- appLogger(
98
- `Dictionary with key '${(0, import_config.colorizeKey)(dictionaryKey)}' has no file path. Skipping.`,
99
- {
100
- level: "warn"
101
- }
102
- );
89
+ appLogger(`${dictionaryPreset} Dictionary has no file path. Skipping.`, {
90
+ level: "warn"
91
+ });
103
92
  continue;
104
93
  }
105
94
  const relativePath = (0, import_path.relative)(
106
95
  configuration.content.baseDir,
107
96
  targetUnmergedDictionary.filePath
108
97
  );
109
- appLogger(`Processing content declaration: ${(0, import_config.colorizePath)(relativePath)}`, {
110
- level: "info"
111
- });
98
+ appLogger(
99
+ `${dictionaryPreset} Processing content declaration: ${(0, import_config.colorizePath)(relativePath)}`,
100
+ {
101
+ level: "info"
102
+ }
103
+ );
112
104
  const sourceLocaleContent = (0, import_core.getFilterTranslationsOnlyContent)(
113
105
  mainDictionaryToProcess,
114
106
  sourceLocale,
@@ -116,7 +108,7 @@ const fill = async (options) => {
116
108
  );
117
109
  if (Object.keys(sourceLocaleContent).length === 0) {
118
110
  appLogger(
119
- `No content found for dictionary '${(0, import_config.colorizeKey)(dictionaryKey)}' in source locale ${(0, import_chokidar.formatLocale)(sourceLocale)}. Skipping translation for this dictionary.`,
111
+ `${dictionaryPreset} No content found for dictionary in source locale ${(0, import_chokidar.formatLocale)(sourceLocale)}. Skipping translation for this dictionary.`,
120
112
  {
121
113
  level: "warn"
122
114
  }
@@ -124,9 +116,6 @@ const fill = async (options) => {
124
116
  continue;
125
117
  }
126
118
  const result = [];
127
- const limit = (0, import_p_limit.default)(
128
- options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS
129
- );
130
119
  let outputLocalesList = outputLocales;
131
120
  if (mode === "complete") {
132
121
  const missingLocales = (0, import_core.getMissingLocalesContent)(
@@ -140,10 +129,28 @@ const fill = async (options) => {
140
129
  );
141
130
  outputLocalesList = missingLocales;
142
131
  }
143
- const translationPromises = outputLocalesList.map(
144
- (targetLocale) => limit(async () => {
132
+ if (outputLocalesList.length === 0) {
133
+ appLogger(
134
+ `${dictionaryPreset} No locales to fill - Skipping dictionary`,
135
+ {
136
+ level: "warn"
137
+ }
138
+ );
139
+ continue;
140
+ }
141
+ const translationResults = await (0, import_chokidar.parallelize)(
142
+ outputLocalesList,
143
+ async (targetLocale) => {
144
+ const localePreset = (0, import_config.colon)(
145
+ [
146
+ (0, import_config.colorize)("[", import_config.ANSIColors.GREY_DARK),
147
+ (0, import_chokidar.formatLocale)(targetLocale),
148
+ (0, import_config.colorize)("]", import_config.ANSIColors.GREY_DARK)
149
+ ].join(""),
150
+ { colSize: maxLocaleLength }
151
+ );
145
152
  appLogger(
146
- `Preparing translation for '${(0, import_config.colorizeKey)(dictionaryKey)}' dictionary from ${(0, import_chokidar.formatLocale)(sourceLocale)} to ${(0, import_chokidar.formatLocale)(targetLocale)}`,
153
+ `${dictionaryPreset}${localePreset} Preparing translation for dictionary from ${(0, import_chokidar.formatLocale)(sourceLocale)} to ${(0, import_chokidar.formatLocale)(targetLocale)}`,
147
154
  {
148
155
  level: "info"
149
156
  }
@@ -154,36 +161,21 @@ const fill = async (options) => {
154
161
  { dictionaryKey, keyPath: [] }
155
162
  );
156
163
  try {
157
- const translationResult = await (0, import_api.getAiAPI)(
158
- void 0,
159
- configuration
160
- ).translateJSON(
161
- {
162
- entryFileContent: sourceLocaleContent.content,
163
- // Should be JSON, ensure getLocalisedContent provides this.
164
- presetOutputContent: presetOutputContent.content,
165
- // Should be JSON
166
- dictionaryDescription: mainDictionaryToProcess.description,
167
- entryLocale: sourceLocale,
168
- outputLocale: targetLocale,
169
- mode,
170
- aiOptions: options.aiOptions
171
- },
172
- {
173
- ...oAuth2AccessToken && {
174
- headers: {
175
- Authorization: `Bearer ${oAuth2AccessToken}`
176
- }
177
- }
178
- }
179
- );
164
+ const translationResult = await intlayerAPI.ai.translateJSON({
165
+ entryFileContent: sourceLocaleContent.content,
166
+ // Should be JSON, ensure getLocalisedContent provides this.
167
+ presetOutputContent: presetOutputContent.content,
168
+ // Should be JSON
169
+ dictionaryDescription: mainDictionaryToProcess.description ?? "",
170
+ entryLocale: sourceLocale,
171
+ outputLocale: targetLocale,
172
+ mode,
173
+ aiOptions: options.aiOptions
174
+ });
180
175
  if (!translationResult.data?.fileContent) {
181
- appLogger(
182
- `No content result found for '${(0, import_config.colorizeKey)(dictionaryKey)}' to ${(0, import_chokidar.formatLocale)(targetLocale)}`,
183
- {
184
- level: "error"
185
- }
186
- );
176
+ appLogger(`${dictionaryPreset}${localePreset} No content result`, {
177
+ level: "error"
178
+ });
187
179
  return null;
188
180
  }
189
181
  const processedPerLocaleDictionary = (0, import_chokidar.processPerLocaleDictionary)({
@@ -194,16 +186,16 @@ const fill = async (options) => {
194
186
  return processedPerLocaleDictionary;
195
187
  } catch (error) {
196
188
  appLogger(
197
- `Error filling '${(0, import_config.colorizeKey)(dictionaryKey)}' to ${(0, import_chokidar.formatLocale)(targetLocale)}:` + error,
189
+ `${dictionaryPreset}${localePreset} ${(0, import_config.colorize)("Error filling", import_config.ANSIColors.RED)}: ` + error,
198
190
  {
199
191
  level: "error"
200
192
  }
201
193
  );
202
194
  return null;
203
195
  }
204
- })
196
+ },
197
+ options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS
205
198
  );
206
- const translationResults = await Promise.all(translationPromises);
207
199
  translationResults.forEach((translationResult) => {
208
200
  if (translationResult) {
209
201
  result.push(translationResult);
@@ -241,7 +233,7 @@ const fill = async (options) => {
241
233
  );
242
234
  if (formattedDict.filePath) {
243
235
  appLogger(
244
- `Content declaration for '${(0, import_config.colorizeKey)(dictionaryKey)}' written to ${(0, import_chokidar.formatPath)(formattedDict.filePath)}`,
236
+ `${dictionaryPreset} Content declaration written to ${(0, import_chokidar.formatPath)(formattedDict.filePath)}`,
245
237
  {
246
238
  level: "info"
247
239
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fill/index.ts"],"sourcesContent":["import { AIOptions, getAiAPI, getOAuthAPI } from '@intlayer/api'; // Importing only getAiAPI for now\nimport {\n formatLocale,\n formatPath,\n ListGitFilesOptions,\n mergeDictionaries,\n prepareIntlayer,\n processPerLocaleDictionary,\n reduceDictionaryContent,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n colorizeKey,\n colorizePath,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n Locales,\n} from '@intlayer/config';\nimport {\n type ContentNode,\n type Dictionary,\n getFilterTranslationsOnlyContent,\n getLocalisedContent,\n getMissingLocalesContent,\n} from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport pLimit from 'p-limit';\nimport { relative } from 'path';\nimport { checkAIAccess } from '../utils/checkAIAccess';\nimport { autoFill } from './autoFill';\nimport { ensureArray, getTargetDictionary } from './getTargetDictionary';\n\nconst NB_CONCURRENT_TRANSLATIONS = 8;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locales;\n outputLocales?: Locales | Locales[];\n file?: string | string[];\n mode?: 'complete' | 'review';\n keys?: string | string[];\n excludedKeys?: string | string[];\n filter?: (entry: Dictionary) => boolean; // DictionaryEntry needs to be defined\n pathFilter?: string | string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n build?: boolean;\n};\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 config: {\n prefix: '',\n },\n });\n\n if (options.build) {\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 const outputLocales = (\n options.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) => locale !== baseLocale);\n\n checkAIAccess(configuration, options.aiOptions);\n\n let oAuth2AccessToken: string | undefined;\n if (configuration.editor.clientId) {\n const intlayerAuthAPI = getOAuthAPI(configuration);\n const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();\n\n oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n }\n\n appLogger('Starting fill function', {\n level: 'info',\n });\n\n const targetUnmergedDictionaries = await getTargetDictionary(options);\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n appLogger(\n [\n 'Affected dictionary keys for processing:',\n Array.from(affectedDictionaryKeys)\n .map((key) => colorizeKey(key))\n .join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryKey = targetUnmergedDictionary.key;\n const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `Dictionary with key '${colorizeKey(dictionaryKey)}' not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n if (!targetUnmergedDictionary.filePath) {\n appLogger(\n `Dictionary with key '${colorizeKey(dictionaryKey)}' has no file path. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const relativePath = relative(\n configuration.content.baseDir,\n targetUnmergedDictionary.filePath\n );\n\n appLogger(`Processing content declaration: ${colorizePath(relativePath)}`, {\n level: 'info',\n });\n\n const sourceLocaleContent = getFilterTranslationsOnlyContent(\n mainDictionaryToProcess as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n if (Object.keys(sourceLocaleContent).length === 0) {\n appLogger(\n `No content found for dictionary '${colorizeKey(dictionaryKey)}' in source locale ${formatLocale(sourceLocale)}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const result: Dictionary[] = [];\n\n // 5. for each locale to translate (exclude base locale) generate json translations\n // Limit concurrent translations to 5 at a time\n const limit = pLimit(\n options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS\n );\n\n // Determine output locales\n let outputLocalesList: Locales[] = outputLocales;\n\n // If mode is review, translate all locales\n // If mode is complete, translate only the locales that are not the source locale\n if (mode === 'complete') {\n const missingLocales = getMissingLocalesContent(\n mainDictionaryToProcess as unknown as ContentNode,\n outputLocales,\n {\n dictionaryKey: mainDictionaryToProcess.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n outputLocalesList = missingLocales;\n }\n\n const translationPromises = outputLocalesList.map((targetLocale) =>\n limit(async () => {\n appLogger(\n `Preparing translation for '${colorizeKey(dictionaryKey)}' dictionary from ${formatLocale(sourceLocale)} to ${formatLocale(targetLocale)}`,\n {\n level: 'info',\n }\n );\n\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n targetLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n try {\n const translationResult = await getAiAPI(\n undefined,\n configuration\n ).translateJSON(\n {\n entryFileContent: sourceLocaleContent.content, // Should be JSON, ensure getLocalisedContent provides this.\n presetOutputContent: presetOutputContent.content, // Should be JSON\n dictionaryDescription: mainDictionaryToProcess.description,\n entryLocale: sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions: options.aiOptions,\n },\n {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n }\n );\n\n if (!translationResult.data?.fileContent) {\n appLogger(\n `No content result found for '${colorizeKey(dictionaryKey)}' to ${formatLocale(targetLocale)}`,\n {\n level: 'error',\n }\n );\n return null;\n }\n\n const processedPerLocaleDictionary = processPerLocaleDictionary({\n ...mainDictionaryToProcess,\n content: translationResult.data?.fileContent,\n locale: targetLocale,\n });\n\n return processedPerLocaleDictionary;\n } catch (error) {\n appLogger(\n `Error filling '${colorizeKey(dictionaryKey)}' to ${formatLocale(targetLocale)}:` +\n error,\n {\n level: 'error',\n }\n );\n return null;\n }\n })\n );\n\n // Wait for all translations to complete\n const translationResults = await Promise.all(translationPromises);\n\n // Filter out null results and add to result array\n translationResults.forEach((translationResult) => {\n if (translationResult) {\n result.push(translationResult);\n }\n });\n\n const dictionaryToMerge =\n mode === 'review'\n ? [...result, mainDictionaryToProcess] // Mode review: generated content will override the base one\n : [mainDictionaryToProcess, ...result]; // Mode complete: base content will override the generated one\n\n const mergedResults = mergeDictionaries(dictionaryToMerge);\n\n let formattedDict = targetUnmergedDictionary;\n\n if (formattedDict.locale) {\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n formattedDict.locale,\n { dictionaryKey, keyPath: [] }\n );\n\n formattedDict = {\n ...formattedDict,\n content: presetOutputContent.content,\n };\n }\n\n const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);\n\n if (formattedDict.autoFill || configuration.content.autoFill) {\n await autoFill(\n mergedResults,\n targetUnmergedDictionary,\n formattedDict.autoFill ?? configuration.content.autoFill,\n outputLocalesList,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(\n { ...formattedDict, content: reducedResult.content },\n configuration,\n formattedDict.filePath\n );\n\n if (formattedDict.filePath) {\n appLogger(\n `Content declaration for '${colorizeKey(dictionaryKey)}' written to ${formatPath(formattedDict.filePath)}`,\n {\n level: 'info',\n }\n );\n }\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAiD;AACjD,sBASO;AACP,oBAOO;AACP,kBAMO;AACP,gCAA+B;AAC/B,qBAAmB;AACnB,kBAAyB;AACzB,2BAA8B;AAC9B,sBAAyB;AACzB,iCAAiD;AAEjD,MAAM,6BAA6B;AAuB5B,MAAM,OAAO,OAAO,YAAwC;AACjE,QAAM,oBAAgB,gCAAiB,QAAQ,aAAa;AAC5D,QAAM,gBAAY,4BAAa,eAAe;AAAA,IAC5C,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,MAAI,QAAQ,OAAO;AACjB,cAAM,iCAAgB,aAAa;AAAA,EACrC;AAEA,QAAM,EAAE,eAAe,QAAQ,IAAI,cAAc;AACjD,QAAM,OAAO,QAAQ,QAAQ;AAC7B,QAAM,aAAa,QAAQ,gBAAgB;AAC3C,QAAM,iBACJ,QAAQ,oBAAgB,wCAAY,QAAQ,aAAa,IAAI,SAC7D,OAAO,CAAC,WAAW,WAAW,UAAU;AAE1C,0CAAc,eAAe,QAAQ,SAAS;AAE9C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MACF;AAAA,IACF,OAAO;AACL,gBAAM;AAAA,QACJ,EAAE,GAAG,eAAe,SAAS,cAAc,QAAQ;AAAA,QACnD;AAAA,QACA,cAAc;AAAA,MAChB;AAEA,UAAI,cAAc,UAAU;AAC1B;AAAA,UACE,gCAA4B,2BAAY,aAAa,CAAC,oBAAgB,4BAAW,cAAc,QAAQ,CAAC;AAAA,UACxG;AAAA,YACE,OAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["dictionariesRecord","pLimit"]}
1
+ {"version":3,"sources":["../../../src/fill/index.ts"],"sourcesContent":["import { AIOptions, getIntlayerAPIProxy } from '@intlayer/api'; // Importing only getAiAPI for now\nimport {\n formatLocale,\n formatPath,\n ListGitFilesOptions,\n mergeDictionaries,\n parallelize,\n prepareIntlayer,\n processPerLocaleDictionary,\n reduceDictionaryContent,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n getConfiguration,\n Locales,\n} from '@intlayer/config';\nimport {\n type ContentNode,\n type Dictionary,\n getFilterTranslationsOnlyContent,\n getLocalisedContent,\n getMissingLocalesContent,\n} from '@intlayer/core';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { relative } from 'path';\nimport {\n ensureArray,\n GetTargetDictionaryOptions,\n getTargetUnmergedDictionaries,\n} from '../getTargetDictionary';\nimport { checkAIAccess } from '../utils/checkAccess';\nimport { autoFill } from './autoFill';\n\nconst NB_CONCURRENT_TRANSLATIONS = 8;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locales;\n outputLocales?: Locales | Locales[];\n mode?: 'complete' | 'review';\n gitOptions?: ListGitFilesOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n build?: 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 config: {\n prefix: '',\n },\n });\n\n if (options.build) {\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 const outputLocales = (\n options.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) => locale !== baseLocale);\n\n const hasAIAccess = await checkAIAccess(configuration, options.aiOptions);\n\n if (!hasAIAccess) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\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 appLogger([\n 'Affected dictionary keys for processing:',\n Array.from(affectedDictionaryKeys)\n .map((key) => colorizeKey(key))\n .join(', '),\n ]);\n\n const maxKeyLength = Math.max(\n ...targetUnmergedDictionaries.map((dict) => dict.key.length)\n );\n const maxLocaleLength = Math.max(\n ...locales.map((locale) => formatLocale(locale).length)\n );\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryPreset = colon(\n [\n colorize(' - [', ANSIColors.GREY_DARK),\n colorizeKey(targetUnmergedDictionary.key),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: maxKeyLength + 6 }\n );\n\n const dictionaryKey = targetUnmergedDictionary.key;\n const dictionariesRecord = getDictionaries(configuration);\n\n const mainDictionaryToProcess: Dictionary =\n dictionariesRecord[dictionaryKey];\n\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `${dictionaryPreset} Dictionary not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n if (!targetUnmergedDictionary.filePath) {\n appLogger(`${dictionaryPreset} Dictionary has no file path. Skipping.`, {\n level: 'warn',\n });\n continue;\n }\n\n const relativePath = relative(\n configuration.content.baseDir,\n targetUnmergedDictionary.filePath\n );\n\n appLogger(\n `${dictionaryPreset} Processing content declaration: ${colorizePath(relativePath)}`,\n {\n level: 'info',\n }\n );\n\n const sourceLocaleContent = getFilterTranslationsOnlyContent(\n mainDictionaryToProcess as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n if (Object.keys(sourceLocaleContent).length === 0) {\n appLogger(\n `${dictionaryPreset} No content found for dictionary in source locale ${formatLocale(sourceLocale)}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const result: Dictionary[] = [];\n\n // Determine output locales\n let outputLocalesList: Locales[] = outputLocales;\n\n // If mode is review, translate all locales\n // If mode is complete, translate only the locales that are not the source locale\n if (mode === 'complete') {\n const missingLocales = getMissingLocalesContent(\n mainDictionaryToProcess as unknown as ContentNode,\n outputLocales,\n {\n dictionaryKey: mainDictionaryToProcess.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n outputLocalesList = missingLocales;\n }\n\n if (outputLocalesList.length === 0) {\n appLogger(\n `${dictionaryPreset} No locales to fill - Skipping dictionary`,\n\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const translationResults = await parallelize(\n outputLocalesList,\n async (targetLocale) => {\n const localePreset = colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n formatLocale(targetLocale),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: maxLocaleLength }\n );\n\n appLogger(\n `${dictionaryPreset}${localePreset} Preparing translation for dictionary from ${formatLocale(sourceLocale)} to ${formatLocale(targetLocale)}`,\n {\n level: 'info',\n }\n );\n\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n targetLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n try {\n const translationResult = await intlayerAPI.ai.translateJSON({\n entryFileContent: sourceLocaleContent.content, // Should be JSON, ensure getLocalisedContent provides this.\n presetOutputContent: presetOutputContent.content, // Should be JSON\n dictionaryDescription: mainDictionaryToProcess.description ?? '',\n entryLocale: sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions: options.aiOptions,\n });\n\n if (!translationResult.data?.fileContent) {\n appLogger(`${dictionaryPreset}${localePreset} No content result`, {\n level: 'error',\n });\n return null;\n }\n\n const processedPerLocaleDictionary = processPerLocaleDictionary({\n ...mainDictionaryToProcess,\n content: translationResult.data?.fileContent,\n locale: targetLocale,\n });\n\n return processedPerLocaleDictionary;\n } catch (error) {\n appLogger(\n `${dictionaryPreset}${localePreset} ${colorize('Error filling', ANSIColors.RED)}: ` +\n error,\n {\n level: 'error',\n }\n );\n return null;\n }\n },\n options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS\n );\n\n // Filter out null results and add to result array\n translationResults.forEach((translationResult) => {\n if (translationResult) {\n result.push(translationResult);\n }\n });\n\n const dictionaryToMerge =\n mode === 'review'\n ? [...result, mainDictionaryToProcess] // Mode review: generated content will override the base one\n : [mainDictionaryToProcess, ...result]; // Mode complete: base content will override the generated one\n\n const mergedResults = mergeDictionaries(dictionaryToMerge);\n\n let formattedDict = targetUnmergedDictionary;\n\n if (formattedDict.locale) {\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n formattedDict.locale,\n { dictionaryKey, keyPath: [] }\n );\n\n formattedDict = {\n ...formattedDict,\n content: presetOutputContent.content,\n };\n }\n\n const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);\n\n if (formattedDict.autoFill || configuration.content.autoFill) {\n await autoFill(\n mergedResults,\n targetUnmergedDictionary,\n formattedDict.autoFill ?? configuration.content.autoFill,\n outputLocalesList,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(\n { ...formattedDict, content: reducedResult.content },\n configuration,\n formattedDict.filePath\n );\n\n if (formattedDict.filePath) {\n appLogger(\n `${dictionaryPreset} Content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UACE,GAAG,gBAAgB,uCAAmC,4BAAW,cAAc,QAAQ,CAAC;AAAA,UACxF;AAAA,YACE,OAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,30 +15,23 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var getTargetDictionary_exports = {};
30
20
  __export(getTargetDictionary_exports, {
31
21
  ensureArray: () => ensureArray,
32
- getTargetDictionary: () => getTargetDictionary
22
+ getTargetUnmergedDictionaries: () => getTargetUnmergedDictionaries
33
23
  });
34
24
  module.exports = __toCommonJS(getTargetDictionary_exports);
35
25
  var import_chokidar = require("@intlayer/chokidar");
36
26
  var import_config = require("@intlayer/config");
37
- var import_unmerged_dictionaries_entry = __toESM(require("@intlayer/unmerged-dictionaries-entry"));
27
+ var import_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
38
28
  var import_path = require("path");
39
29
  const ensureArray = (value) => [value].flat();
40
- const getTargetDictionary = async (options) => {
30
+ const getTargetUnmergedDictionaries = async (options) => {
41
31
  const configuration = (0, import_config.getConfiguration)(options.configOptions);
42
32
  const { baseDir } = configuration.content;
43
- let result = Object.values(import_unmerged_dictionaries_entry.default).flat();
33
+ const unmergedDictionariesRecord = (0, import_unmerged_dictionaries_entry.getUnmergedDictionaries)(configuration);
34
+ let result = Object.values(unmergedDictionariesRecord).flat();
44
35
  if (typeof options.file !== "undefined") {
45
36
  const fileArray = ensureArray(options.file);
46
37
  const absoluteFilePaths = fileArray.map((file) => (0, import_path.join)(baseDir, file));
@@ -81,6 +72,6 @@ const getTargetDictionary = async (options) => {
81
72
  // Annotate the CommonJS export names for ESM import in node:
82
73
  0 && (module.exports = {
83
74
  ensureArray,
84
- getTargetDictionary
75
+ getTargetUnmergedDictionaries
85
76
  });
86
77
  //# sourceMappingURL=getTargetDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/getTargetDictionary.ts"],"sourcesContent":["import { listGitFiles, ListGitFilesOptions } from '@intlayer/chokidar';\nimport { getConfiguration, GetConfigurationOptions } from '@intlayer/config';\nimport { Dictionary } from '@intlayer/core';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { join } from 'path';\n\nexport const ensureArray = <T>(value: T | T[]): T[] => [value].flat() as T[];\n\n// Arguments for the fill function\nexport type GetTargetDictionaryOptions = {\n file?: string | string[];\n keys?: string | string[];\n excludedKeys?: string | string[];\n filter?: (entry: Dictionary) => boolean; // DictionaryEntry needs to be defined\n pathFilter?: string | string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n};\n\nexport const getTargetUnmergedDictionaries = async (\n options: GetTargetDictionaryOptions\n): Promise<Dictionary[]> => {\n const configuration = getConfiguration(options.configOptions);\n\n const { baseDir } = configuration.content;\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n let result = Object.values(unmergedDictionariesRecord).flat();\n\n // 1. if filePath not defined, list all content declaration files based on unmerged dictionaries list\n if (typeof options.file !== 'undefined') {\n const fileArray = ensureArray(options.file);\n const absoluteFilePaths = fileArray.map((file) => join(baseDir, file));\n\n result = result.filter(\n (dict) =>\n dict.filePath &&\n (absoluteFilePaths.includes(dict.filePath) ||\n absoluteFilePaths.includes(join(baseDir, dict.filePath)))\n );\n }\n\n if (typeof options.keys !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.keys)?.includes(dict.key)\n );\n }\n\n if (typeof options.excludedKeys !== 'undefined') {\n result = result.filter(\n (dict) => !ensureArray(options.excludedKeys)?.includes(dict.key)\n );\n }\n\n if (typeof options.pathFilter !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.pathFilter)?.includes(dict.filePath ?? '')\n );\n }\n\n if (typeof options.filter !== 'undefined') {\n result = result.filter(options.filter);\n }\n\n const gitOptions = options.gitOptions;\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n result = result.filter((dict) => {\n if (!dict.filePath) return false;\n\n return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);\n });\n }\n }\n\n return result.filter((dict) => !dict.autoFilled);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAkD;AAClD,oBAA0D;AAE1D,yCAAwC;AACxC,kBAAqB;AAEd,MAAM,cAAc,CAAI,UAAwB,CAAC,KAAK,EAAE,KAAK;AAa7D,MAAM,gCAAgC,OAC3C,YAC0B;AAC1B,QAAM,oBAAgB,gCAAiB,QAAQ,aAAa;AAE5D,QAAM,EAAE,QAAQ,IAAI,cAAc;AAElC,QAAM,iCAA6B,4DAAwB,aAAa;AACxE,MAAI,SAAS,OAAO,OAAO,0BAA0B,EAAE,KAAK;AAG5D,MAAI,OAAO,QAAQ,SAAS,aAAa;AACvC,UAAM,YAAY,YAAY,QAAQ,IAA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