@intlayer/cli 6.0.0 → 6.0.2-canary.0

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 (86) hide show
  1. package/dist/cjs/cli.cjs +15 -1
  2. package/dist/cjs/cli.cjs.map +1 -1
  3. package/dist/cjs/fill/index.cjs +76 -84
  4. package/dist/cjs/fill/index.cjs.map +1 -1
  5. package/dist/cjs/{fill/getTargetDictionary.cjs → getTargetDictionary.cjs} +6 -15
  6. package/dist/cjs/getTargetDictionary.cjs.map +1 -0
  7. package/dist/cjs/listContentDeclaration.cjs +3 -12
  8. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  9. package/dist/cjs/liveSync.cjs +2 -2
  10. package/dist/cjs/liveSync.cjs.map +1 -1
  11. package/dist/cjs/pull.cjs +3 -6
  12. package/dist/cjs/pull.cjs.map +1 -1
  13. package/dist/cjs/push.cjs +13 -9
  14. package/dist/cjs/push.cjs.map +1 -1
  15. package/dist/cjs/pushConfig.cjs +3 -10
  16. package/dist/cjs/pushConfig.cjs.map +1 -1
  17. package/dist/cjs/reviewDoc.cjs +16 -11
  18. package/dist/cjs/reviewDoc.cjs.map +1 -1
  19. package/dist/cjs/test/index.cjs +1 -1
  20. package/dist/cjs/test/index.cjs.map +1 -1
  21. package/dist/cjs/test/listMissingTranslations.cjs +8 -16
  22. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  23. package/dist/cjs/translateDoc.cjs +15 -7
  24. package/dist/cjs/translateDoc.cjs.map +1 -1
  25. package/dist/cjs/utils/checkAccess.cjs +77 -0
  26. package/dist/cjs/utils/checkAccess.cjs.map +1 -0
  27. package/dist/cjs/utils/chunkInference.cjs +1 -2
  28. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  29. package/dist/esm/cli.mjs +15 -1
  30. package/dist/esm/cli.mjs.map +1 -1
  31. package/dist/esm/fill/index.mjs +83 -74
  32. package/dist/esm/fill/index.mjs.map +1 -1
  33. package/dist/esm/{fill/getTargetDictionary.mjs → getTargetDictionary.mjs} +4 -3
  34. package/dist/esm/getTargetDictionary.mjs.map +1 -0
  35. package/dist/esm/listContentDeclaration.mjs +2 -1
  36. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  37. package/dist/esm/liveSync.mjs +2 -2
  38. package/dist/esm/liveSync.mjs.map +1 -1
  39. package/dist/esm/pull.mjs +3 -6
  40. package/dist/esm/pull.mjs.map +1 -1
  41. package/dist/esm/push.mjs +11 -7
  42. package/dist/esm/push.mjs.map +1 -1
  43. package/dist/esm/pushConfig.mjs +3 -10
  44. package/dist/esm/pushConfig.mjs.map +1 -1
  45. package/dist/esm/reviewDoc.mjs +16 -11
  46. package/dist/esm/reviewDoc.mjs.map +1 -1
  47. package/dist/esm/test/index.mjs +1 -1
  48. package/dist/esm/test/index.mjs.map +1 -1
  49. package/dist/esm/test/listMissingTranslations.mjs +8 -4
  50. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  51. package/dist/esm/translateDoc.mjs +15 -7
  52. package/dist/esm/translateDoc.mjs.map +1 -1
  53. package/dist/esm/utils/checkAccess.mjs +52 -0
  54. package/dist/esm/utils/checkAccess.mjs.map +1 -0
  55. package/dist/esm/utils/chunkInference.mjs +2 -6
  56. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  57. package/dist/types/cli.d.ts.map +1 -1
  58. package/dist/types/fill/index.d.ts +3 -9
  59. package/dist/types/fill/index.d.ts.map +1 -1
  60. package/dist/types/getTargetDictionary.d.ts +15 -0
  61. package/dist/types/getTargetDictionary.d.ts.map +1 -0
  62. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  63. package/dist/types/pull.d.ts.map +1 -1
  64. package/dist/types/push.d.ts.map +1 -1
  65. package/dist/types/pushConfig.d.ts.map +1 -1
  66. package/dist/types/reviewDoc.d.ts +2 -2
  67. package/dist/types/reviewDoc.d.ts.map +1 -1
  68. package/dist/types/test/listMissingTranslations.d.ts +4 -4
  69. package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
  70. package/dist/types/translateDoc.d.ts +2 -2
  71. package/dist/types/translateDoc.d.ts.map +1 -1
  72. package/dist/types/utils/checkAccess.d.ts +5 -0
  73. package/dist/types/utils/checkAccess.d.ts.map +1 -0
  74. package/dist/types/utils/chunkInference.d.ts +2 -2
  75. package/dist/types/utils/chunkInference.d.ts.map +1 -1
  76. package/package.json +17 -17
  77. package/dist/cjs/fill/getTargetDictionary.cjs.map +0 -1
  78. package/dist/cjs/utils/checkAIAccess.cjs +0 -44
  79. package/dist/cjs/utils/checkAIAccess.cjs.map +0 -1
  80. package/dist/esm/fill/getTargetDictionary.mjs.map +0 -1
  81. package/dist/esm/utils/checkAIAccess.mjs +0 -20
  82. package/dist/esm/utils/checkAIAccess.mjs.map +0 -1
  83. package/dist/types/fill/getTargetDictionary.d.ts +0 -4
  84. package/dist/types/fill/getTargetDictionary.d.ts.map +0 -1
  85. package/dist/types/utils/checkAIAccess.d.ts +0 -4
  86. package/dist/types/utils/checkAIAccess.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/push.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport * as fsPromises from 'fs/promises';\nimport * as readline from 'readline';\nimport { PushLogger, type PushStatus } from './pushLog';\n\ntype PushOptions = {\n deleteLocaleDictionary?: boolean;\n keepLocaleDictionary?: boolean;\n dictionaries?: string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionary: Dictionary;\n status: 'pending' | 'pushing' | 'modified' | 'pushed' | 'unknown' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n/**\n * Get all local dictionaries and push them simultaneously.\n */\nexport const push = async (options?: PushOptions): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n const { clientId, clientSecret } = config.editor;\n try {\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n let dictionaries: Dictionary[] = Object.values(dictionariesRecord);\n const existingDictionariesKeys: string[] = Object.keys(dictionariesRecord);\n\n if (options?.dictionaries) {\n // Check if the provided dictionaries exist\n const noneExistingDictionariesOption = options.dictionaries.filter(\n (dictionaryId) => !existingDictionariesKeys.includes(dictionaryId)\n );\n\n if (noneExistingDictionariesOption.length > 0) {\n appLogger(\n `The following dictionaries do not exist: ${noneExistingDictionariesOption.join(\n ', '\n )} and have been ignored.`,\n {\n level: 'error',\n }\n );\n }\n\n // Filter the dictionaries from the provided list of IDs\n dictionaries = dictionaries.filter((dictionary) =>\n options.dictionaries!.includes(dictionary.key)\n );\n }\n\n if (options?.gitOptions) {\n const gitFiles = await listGitFiles(options.gitOptions);\n }\n\n // Check if the dictionaries list is empty\n if (dictionaries.length === 0) {\n appLogger('No local dictionaries found', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Pushing dictionaries:', {});\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = dictionaries.map(\n (dictionary) => ({\n dictionary,\n status: 'pending',\n })\n );\n\n // Initialize aggregated logger similar to loadDictionaries\n const logger = new PushLogger();\n logger.update(\n dictionariesStatuses.map<PushStatus>((s) => ({\n dictionaryKey: s.dictionary.key,\n status: 'pending',\n }))\n );\n\n const successfullyPushedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'pushing';\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'pushing' },\n ]);\n\n try {\n const pushResult = await intlayerAPI.dictionary.pushDictionaries([\n statusObj.dictionary,\n ]);\n\n const updatedDictionaries = pushResult.data?.updatedDictionaries || [];\n const newDictionaries = pushResult.data?.newDictionaries || [];\n\n if (updatedDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'modified';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'modified' },\n ]);\n } else if (newDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'pushed';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'pushed' },\n ]);\n } else {\n statusObj.status = 'unknown';\n }\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with a concurrency limit (reuse parallelize)\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n // Print per-dictionary summary similar to loadDictionaries\n const iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'pushed':\n case 'modified':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n };\n\n const colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'pushed':\n case 'modified':\n return ANSIColors.GREEN;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n };\n\n for (const s of dictionariesStatuses) {\n const icon = iconFor(s.status);\n const color = colorFor(s.status);\n appLogger(\n ` - ${s.dictionary.key} ${ANSIColors.GREY}[${color}${icon} ${s.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n\n // Handle delete or keep options\n const deleteOption = options?.deleteLocaleDictionary;\n const keepOption = options?.keepLocaleDictionary;\n\n if (deleteOption && keepOption) {\n throw new Error(\n 'Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.'\n );\n }\n\n if (deleteOption) {\n // Delete only the successfully pushed dictionaries\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n } else if (keepOption) {\n // Do nothing, keep the local dictionaries\n } else {\n // Ask the user\n const answer = await askUser(\n 'Do you want to delete the local dictionaries that were successfully pushed? (yes/no): '\n );\n if (answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y') {\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n\nconst askUser = (question: string): Promise<string> => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n return new Promise((resolve) => {\n rl.question(question, (answer: string) => {\n rl.close();\n resolve(answer);\n });\n });\n};\n\nconst deleteLocalDictionaries = async (\n dictionariesToDelete: Dictionary[],\n options?: PushOptions\n): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n // Use a Set to collect all unique file paths\n const filePathsSet: Set<string> = new Set();\n\n for (const dictionary of dictionariesToDelete) {\n const { filePath } = dictionary;\n\n if (!filePath) {\n appLogger(`Dictionary ${dictionary.key} does not have a file path`, {\n level: 'error',\n });\n continue;\n }\n\n filePathsSet.add(filePath);\n }\n\n for (const filePath of filePathsSet) {\n try {\n const stats = await fsPromises.lstat(filePath);\n\n if (stats.isFile()) {\n await fsPromises.unlink(filePath);\n appLogger(`Deleted file ${formatPath(filePath)}`, {});\n } else if (stats.isDirectory()) {\n appLogger(`Path is a directory ${formatPath(filePath)}, skipping.`, {});\n } else {\n appLogger(\n `Unknown file type for ${formatPath(filePath)}, skipping.`,\n {}\n );\n }\n } catch (err) {\n appLogger(`Error deleting ${formatPath(filePath)}: ${err}`, {\n level: 'error',\n });\n }\n }\n};\n\n// Legacy per-line spinner output removed in favor of aggregated PushLogger\n"],"mappings":"AAAA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,OAAO,wBAAwB;AAC/B,YAAY,gBAAgB;AAC5B,YAAY,cAAc;AAC1B,SAAS,kBAAmC;AAoBrC,MAAM,OAAO,OAAO,YAAyC;AAClE,QAAM,SAAS,iBAAiB,SAAS,aAAa;AACtD,QAAM,YAAY,aAAa,QAAQ;AAAA,IACrC,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AACD,QAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,MAAI;AACF,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,cAAc,oBAAoB,QAAW,MAAM;AAEzD,QAAI,eAA6B,OAAO,OAAO,kBAAkB;AACjE,UAAM,2BAAqC,OAAO,KAAK,kBAAkB;AAEzE,QAAI,SAAS,cAAc;AAEzB,YAAM,iCAAiC,QAAQ,aAAa;AAAA,QAC1D,CAAC,iBAAiB,CAAC,yBAAyB,SAAS,YAAY;AAAA,MACnE;AAEA,UAAI,+BAA+B,SAAS,GAAG;AAC7C;AAAA,UACE,4CAA4C,+BAA+B;AAAA,YACzE;AAAA,UACF,CAAC;AAAA,UACD;AAAA,YACE,OAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAGA,qBAAe,aAAa;AAAA,QAAO,CAAC,eAClC,QAAQ,aAAc,SAAS,WAAW,GAAG;AAAA,MAC/C;AAAA,IACF;AAEA,QAAI,SAAS,YAAY;AACvB,YAAM,WAAW,MAAM,aAAa,QAAQ,UAAU;AAAA,IACxD;AAGA,QAAI,aAAa,WAAW,GAAG;AAC7B,gBAAU,+BAA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A,MACxE,OAAO;AACL;AAAA,UACE,yBAAyB,WAAW,QAAQ,CAAC;AAAA,UAC7C,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF,SAAS,KAAK;AACZ,gBAAU,kBAAkB,WAAW,QAAQ,CAAC,KAAK,GAAG,IAAI;AAAA,QAC1D,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/push.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport * as fsPromises from 'fs/promises';\nimport { join } from 'path';\nimport * as readline from 'readline';\nimport { PushLogger, type PushStatus } from './pushLog';\nimport { checkCMSAuth } from './utils/checkAccess';\n\ntype PushOptions = {\n deleteLocaleDictionary?: boolean;\n keepLocaleDictionary?: boolean;\n dictionaries?: string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionary: Dictionary;\n status: 'pending' | 'pushing' | 'modified' | 'pushed' | 'unknown' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n/**\n * Get all local dictionaries and push them simultaneously.\n */\nexport const push = async (options?: PushOptions): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n try {\n const hasCMSAuth = await checkCMSAuth(config);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n const dictionariesRecord = getDictionaries(config);\n let dictionaries: Dictionary[] = Object.values(dictionariesRecord);\n const existingDictionariesKeys: string[] = Object.keys(dictionariesRecord);\n\n if (options?.dictionaries) {\n // Check if the provided dictionaries exist\n const noneExistingDictionariesOption = options.dictionaries.filter(\n (dictionaryId) => !existingDictionariesKeys.includes(dictionaryId)\n );\n\n if (noneExistingDictionariesOption.length > 0) {\n appLogger(\n `The following dictionaries do not exist: ${noneExistingDictionariesOption.join(\n ', '\n )} and have been ignored.`,\n {\n level: 'error',\n }\n );\n }\n\n // Filter the dictionaries from the provided list of IDs\n dictionaries = dictionaries.filter((dictionary) =>\n options.dictionaries!.includes(dictionary.key)\n );\n }\n\n if (options?.gitOptions) {\n const gitFiles = await listGitFiles(options.gitOptions);\n\n dictionaries = dictionaries.filter((dictionary) =>\n gitFiles.includes(\n join(config.content.baseDir, dictionary.filePath ?? '')\n )\n );\n }\n\n // Check if the dictionaries list is empty\n if (dictionaries.length === 0) {\n appLogger('No local dictionaries found', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Pushing dictionaries:', {});\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = dictionaries.map(\n (dictionary) => ({\n dictionary,\n status: 'pending',\n })\n );\n\n // Initialize aggregated logger similar to loadDictionaries\n const logger = new PushLogger();\n logger.update(\n dictionariesStatuses.map<PushStatus>((s) => ({\n dictionaryKey: s.dictionary.key,\n status: 'pending',\n }))\n );\n\n const successfullyPushedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'pushing';\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'pushing' },\n ]);\n\n try {\n const pushResult = await intlayerAPI.dictionary.pushDictionaries([\n statusObj.dictionary,\n ]);\n\n const updatedDictionaries = pushResult.data?.updatedDictionaries || [];\n const newDictionaries = pushResult.data?.newDictionaries || [];\n\n if (updatedDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'modified';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'modified' },\n ]);\n } else if (newDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'pushed';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'pushed' },\n ]);\n } else {\n statusObj.status = 'unknown';\n }\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with a concurrency limit (reuse parallelize)\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n // Print per-dictionary summary similar to loadDictionaries\n const iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'pushed':\n case 'modified':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n };\n\n const colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'pushed':\n case 'modified':\n return ANSIColors.GREEN;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n };\n\n for (const s of dictionariesStatuses) {\n const icon = iconFor(s.status);\n const color = colorFor(s.status);\n appLogger(\n ` - ${s.dictionary.key} ${ANSIColors.GREY}[${color}${icon} ${s.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n\n // Handle delete or keep options\n const deleteOption = options?.deleteLocaleDictionary;\n const keepOption = options?.keepLocaleDictionary;\n\n if (deleteOption && keepOption) {\n throw new Error(\n 'Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.'\n );\n }\n\n if (deleteOption) {\n // Delete only the successfully pushed dictionaries\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n } else if (keepOption) {\n // Do nothing, keep the local dictionaries\n } else {\n // Ask the user\n const answer = await askUser(\n 'Do you want to delete the local dictionaries that were successfully pushed? (yes/no): '\n );\n if (answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y') {\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n\nconst askUser = (question: string): Promise<string> => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n return new Promise((resolve) => {\n rl.question(question, (answer: string) => {\n rl.close();\n resolve(answer);\n });\n });\n};\n\nconst deleteLocalDictionaries = async (\n dictionariesToDelete: Dictionary[],\n options?: PushOptions\n): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n // Use a Set to collect all unique file paths\n const filePathsSet: Set<string> = new Set();\n\n for (const dictionary of dictionariesToDelete) {\n const { filePath } = dictionary;\n\n if (!filePath) {\n appLogger(`Dictionary ${dictionary.key} does not have a file path`, {\n level: 'error',\n });\n continue;\n }\n\n filePathsSet.add(filePath);\n }\n\n for (const filePath of filePathsSet) {\n try {\n const stats = await fsPromises.lstat(filePath);\n\n if (stats.isFile()) {\n await fsPromises.unlink(filePath);\n appLogger(`Deleted file ${formatPath(filePath)}`, {});\n } else if (stats.isDirectory()) {\n appLogger(`Path is a directory ${formatPath(filePath)}, skipping.`, {});\n } else {\n appLogger(\n `Unknown file type for ${formatPath(filePath)}, skipping.`,\n {}\n );\n }\n } catch (err) {\n appLogger(`Error deleting ${formatPath(filePath)}: ${err}`, {\n level: 'error',\n });\n }\n }\n};\n\n// Legacy per-line spinner output removed in favor of aggregated PushLogger\n"],"mappings":"AAAA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,uBAAuB;AAChC,YAAY,gBAAgB;AAC5B,SAAS,YAAY;AACrB,YAAY,cAAc;AAC1B,SAAS,kBAAmC;AAC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AAA,QAC1D,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
@@ -3,6 +3,7 @@ import {
3
3
  getAppLogger,
4
4
  getConfiguration
5
5
  } from "@intlayer/config";
6
+ import { checkCMSAuth } from "./utils/checkAccess.mjs";
6
7
  const pushConfig = async (options) => {
7
8
  const config = getConfiguration(options?.configOptions);
8
9
  const appLogger = getAppLogger(config, {
@@ -10,16 +11,8 @@ const pushConfig = async (options) => {
10
11
  prefix: ""
11
12
  }
12
13
  });
13
- const { clientId, clientSecret } = config.editor;
14
- if (!clientId || !clientSecret) {
15
- appLogger(
16
- "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.",
17
- {
18
- level: "error"
19
- }
20
- );
21
- return;
22
- }
14
+ const hasCMSAuth = await checkCMSAuth(config);
15
+ if (!hasCMSAuth) return;
23
16
  const intlayerAPI = getIntlayerAPIProxy(void 0, config);
24
17
  const getDictionariesKeysResult = await intlayerAPI.project.pushProjectConfiguration(config);
25
18
  if (!getDictionariesKeysResult.data) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n getAppLogger,\n getConfiguration,\n type GetConfigurationOptions,\n} from '@intlayer/config';\n\ntype PushOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const pushConfig = async (options?: PushOptions) => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n appLogger(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.',\n {\n level: 'error',\n }\n );\n return;\n }\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n // Push the project configuration\n const getDictionariesKeysResult =\n await intlayerAPI.project.pushProjectConfiguration(config);\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('Error pushing project configuration');\n }\n\n appLogger('Project configuration pushed successfully');\n\n appLogger(JSON.stringify(getDictionariesKeysResult.data, null, 2));\n};\n"],"mappings":"AAAA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAMA,MAAM,aAAa,OAAO,YAA0B;AACzD,QAAM,SAAS,iBAAiB,SAAS,aAAa;AACtD,QAAM,YAAY,aAAa,QAAQ;AAAA,IACrC,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AACA;AAAA,EACF;AAEA,QAAM,cAAc,oBAAoB,QAAW,MAAM;AAGzD,QAAM,4BACJ,MAAM,YAAY,QAAQ,yBAAyB,MAAM;AAE3D,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,YAAU,2CAA2C;AAErD,YAAU,KAAK,UAAU,0BAA0B,MAAM,MAAM,CAAC,CAAC;AACnE;","names":[]}
1
+ {"version":3,"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n getAppLogger,\n getConfiguration,\n type GetConfigurationOptions,\n} from '@intlayer/config';\nimport { checkCMSAuth } from './utils/checkAccess';\n\ntype PushOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const pushConfig = async (options?: PushOptions) => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n const hasCMSAuth = await checkCMSAuth(config);\n\n if (!hasCMSAuth) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n // Push the project configuration\n const getDictionariesKeysResult =\n await intlayerAPI.project.pushProjectConfiguration(config);\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('Error pushing project configuration');\n }\n\n appLogger('Project configuration pushed successfully');\n\n appLogger(JSON.stringify(getDictionariesKeysResult.data, null, 2));\n};\n"],"mappings":"AAAA,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,oBAAoB;AAMtB,MAAM,aAAa,OAAO,YAA0B;AACzD,QAAM,SAAS,iBAAiB,SAAS,aAAa;AACtD,QAAM,YAAY,aAAa,QAAQ;AAAA,IACrC,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,aAAa,MAAM,aAAa,MAAM;AAE5C,MAAI,CAAC,WAAY;AAEjB,QAAM,cAAc,oBAAoB,QAAW,MAAM;AAGzD,QAAM,4BACJ,MAAM,YAAY,QAAQ,yBAAyB,MAAM;AAE3D,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,YAAU,2CAA2C;AAErD,YAAU,KAAK,UAAU,0BAA0B,MAAM,MAAM,CAAC,CAAC;AACnE;","names":[]}
@@ -21,7 +21,7 @@ import pLimit from "p-limit";
21
21
  import { dirname, join, relative } from "path";
22
22
  import { fileURLToPath } from "url";
23
23
  import { chunkText } from "./utils/calculateChunks.mjs";
24
- import { checkAIAccess } from "./utils/checkAIAccess.mjs";
24
+ import { checkAIAccess } from "./utils/checkAccess.mjs";
25
25
  import { checkFileModifiedRange } from "./utils/checkFileModifiedRange.mjs";
26
26
  import { chunkInference } from "./utils/chunkInference.mjs";
27
27
  import { fixChunkStartEndChars } from "./utils/fixChunkStartEndChars.mjs";
@@ -29,9 +29,8 @@ import { getChunk } from "./utils/getChunk.mjs";
29
29
  import { getOutputFilePath } from "./utils/getOutputFilePath.mjs";
30
30
  const isESModule = typeof import.meta.url === "string";
31
31
  const dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;
32
- const reviewFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configOptions, customInstructions, changedLines) => {
32
+ const reviewFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configuration = getConfiguration(), customInstructions, changedLines) => {
33
33
  try {
34
- const configuration = getConfiguration(configOptions);
35
34
  const appLogger = getAppLogger(configuration, {
36
35
  config: {
37
36
  prefix: ""
@@ -49,10 +48,7 @@ const reviewFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOp
49
48
  `\u2192 ${ANSIColors.RESET}`
50
49
  ].join("");
51
50
  const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;
52
- const prefix = [
53
- colon(prefixText, { colSize: 40 }),
54
- `\u2192 ${ANSIColors.RESET}`
55
- ].join("");
51
+ const prefix = [colon(prefixText, { colSize: 40 })].join("");
56
52
  appLogger(
57
53
  `${filePrefix}Base file splitted into ${colorizeNumber(baseChunks.length)} chunks`
58
54
  );
@@ -94,10 +90,18 @@ const reviewFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOp
94
90
  { role: "user", content: baseChunkContext.content }
95
91
  ],
96
92
  aiOptions,
97
- configOptions
93
+ configuration
98
94
  );
99
95
  appLogger(
100
- `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Chunk ${colorizeNumber(i + 1)} of ${colorizeNumber(baseChunks.length)}`
96
+ [
97
+ `${prefix}`,
98
+ `${ANSIColors.GREY_DARK}[Chunk `,
99
+ colorizeNumber(i + 1),
100
+ `${ANSIColors.GREY_DARK} of `,
101
+ colorizeNumber(baseChunks.length),
102
+ `${ANSIColors.GREY_DARK}] \u2192${ANSIColors.RESET} `,
103
+ `${colorizeNumber(result.tokenUsed)} tokens used`
104
+ ].join("")
101
105
  );
102
106
  const fixedReviewedChunkResult = fixChunkStartEndChars(
103
107
  result?.fileContent,
@@ -143,6 +147,8 @@ const reviewDoc = async ({
143
147
  prefix: ""
144
148
  }
145
149
  });
150
+ const hasCMSAuth = await checkAIAccess(configuration, aiOptions);
151
+ if (!hasCMSAuth) return;
146
152
  if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {
147
153
  appLogger(
148
154
  `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`
@@ -161,7 +167,6 @@ const reviewDoc = async ({
161
167
  );
162
168
  }
163
169
  }
164
- checkAIAccess(configuration, aiOptions);
165
170
  appLogger(`Base locale is ${formatLocale(baseLocale)}`);
166
171
  appLogger(
167
172
  `Reviewing ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`
@@ -199,7 +204,7 @@ const reviewDoc = async ({
199
204
  locale,
200
205
  baseLocale,
201
206
  aiOptions,
202
- configOptions,
207
+ configuration,
203
208
  customInstructions,
204
209
  changedLines
205
210
  );
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/reviewDoc.ts"],"sourcesContent":["import { AIOptions } from '@intlayer/api'; // OAuth handled by API proxy\nimport {\n formatLocale,\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n Locales,\n retryManager,\n} from '@intlayer/config';\nimport { getLocaleName } from '@intlayer/core';\nimport fg from 'fast-glob';\nimport { mkdirSync, writeFileSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport pLimit from 'p-limit';\nimport { dirname, join, relative } from 'path';\nimport { fileURLToPath } from 'url';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAIAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getChunk } from './utils/getChunk';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;\n\n/**\n * Translate a single file for a given locale\n */\nexport const reviewFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locales,\n baseLocale: Locales,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions,\n customInstructions?: string,\n changedLines?: number[]\n) => {\n try {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const basedFileContent = await readFile(baseFilePath, 'utf-8');\n const fileToReviewContent = await readFile(outputFilePath, 'utf-8');\n\n let updatedFileContent = fileToReviewContent;\n let fileResultContent = '';\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = (\n await readFile(join(dir, './prompts/REVIEW_PROMPT.md'), 'utf-8')\n )\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const baseChunks = chunkText(basedFileContent, 800, 0);\n\n const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrexixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(baseChunks.length)} chunks`\n );\n\n for await (const [i, baseChunk] of baseChunks.entries()) {\n const baseChunkContext = baseChunk;\n\n if (changedLines) {\n const hasChangedLinesInChunk = changedLines.some(\n (line) =>\n line > baseChunkContext.lineStart &&\n line < baseChunkContext.lineStart + baseChunkContext.lineLength\n );\n\n if (!hasChangedLinesInChunk) {\n appLogger(\n `No git changed lines found for chunk ${colorizeNumber(i + 1)}`\n );\n\n const chunkWithNoChange = getChunk(updatedFileContent, {\n lineStart: baseChunkContext.lineStart,\n lineLength: baseChunkContext.lineLength,\n });\n\n fileResultContent += chunkWithNoChange;\n\n continue;\n }\n }\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (baseChunks[i - 1]?.content ?? '') +\n baseChunkContext.content +\n (baseChunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const getChunkToReviewPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the current chunk to review in ${formatLocale(locale, false)} as reference.\\n` +\n `///chunksStart///` +\n getChunk(updatedFileContent, {\n lineStart: baseChunks[i - 1]?.lineStart ?? 0,\n lineLength:\n (baseChunks[i - 1]?.lineLength ?? 0) +\n baseChunkContext.lineLength +\n (baseChunks[i + 1]?.lineLength ?? 0),\n }) +\n `///chunksEnd///`;\n\n // Make the actual translation call\n let reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getChunkToReviewPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(baseChunks.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: baseChunkContext.content },\n ],\n aiOptions,\n configOptions\n );\n\n appLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Chunk ${colorizeNumber(i + 1)} of ${colorizeNumber(baseChunks.length)}`\n );\n\n const fixedReviewedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n baseChunkContext.content\n );\n\n return fixedReviewedChunkResult;\n })();\n\n updatedFileContent = updatedFileContent.replace(\n baseChunkContext.content,\n reviewedChunkResult\n );\n\n fileResultContent += reviewedChunkResult;\n }\n\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype ReviewDocOptions = {\n docPattern: string[];\n locales: Locales[];\n excludedGlobPattern: string[];\n baseLocale: Locales;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main audit function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then audits them to each locale in LOCALE_LIST.\n */\nexport const reviewDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: ReviewDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n const limit = pLimit(nbSimultaneousFileProcessed ?? 3);\n\n let docList: string[] = fg.sync(docPattern, {\n ignore: excludedGlobPattern,\n });\n\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 docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n checkAIAccess(configuration, aiOptions);\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Reviewing ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Reviewing ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n const tasks = docList.map((docPath) =>\n locales.flatMap((locale) =>\n limit(async () => {\n appLogger(\n `Reviewing file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(\n configuration.content.baseDir,\n docPath\n );\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n let changedLines: number[] | undefined = undefined;\n // Disabled for now because it's leading to file format issues\n // if (gitOptions) {\n // const gitChangedLines = await listGitLines(\n // absoluteBaseFilePath,\n // gitOptions\n // );\n\n // appLogger(`Git changed lines: ${gitChangedLines.join(', ')}`);\n\n // changedLines = gitChangedLines;\n // }\n\n await reviewFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locales,\n baseLocale,\n aiOptions,\n configOptions,\n customInstructions,\n changedLines\n );\n })\n )\n );\n\n await Promise.all(tasks);\n};\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,OAAO,QAAQ;AACf,SAAS,WAAW,qBAAqB;AACzC,SAAS,gBAAgB;AACzB,OAAO,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AAAA,UACrB;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,cAAM,uBAAuB,uBAAuB,gBAAgB;AAAA,UAClE;AAAA,UACA;AAAA,QACF,CAAC;AAED,YAAI,qBAAqB,WAAW;AAClC,oBAAU,qBAAqB,OAAO;AACtC;AAAA,QACF;AAEA,YAAI,eAAqC;AAazC,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,QAAQ,IAAI,KAAK;AACzB;","names":[]}
1
+ {"version":3,"sources":["../../src/reviewDoc.ts"],"sourcesContent":["import { AIOptions } from '@intlayer/api'; // OAuth handled by API proxy\nimport {\n formatLocale,\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n IntlayerConfig,\n Locales,\n retryManager,\n} from '@intlayer/config';\nimport { getLocaleName } from '@intlayer/core';\nimport fg from 'fast-glob';\nimport { mkdirSync, writeFileSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport pLimit from 'p-limit';\nimport { dirname, join, relative } from 'path';\nimport { fileURLToPath } from 'url';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getChunk } from './utils/getChunk';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;\n\n/**\n * Translate a single file for a given locale\n */\nexport const reviewFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locales,\n baseLocale: Locales,\n aiOptions?: AIOptions,\n configuration: IntlayerConfig = getConfiguration(),\n customInstructions?: string,\n changedLines?: number[]\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const basedFileContent = await readFile(baseFilePath, 'utf-8');\n const fileToReviewContent = await readFile(outputFilePath, 'utf-8');\n\n let updatedFileContent = fileToReviewContent;\n let fileResultContent = '';\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = (\n await readFile(join(dir, './prompts/REVIEW_PROMPT.md'), 'utf-8')\n )\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const baseChunks = chunkText(basedFileContent, 800, 0);\n\n const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrexixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [colon(prefixText, { colSize: 40 })].join('');\n\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(baseChunks.length)} chunks`\n );\n\n for await (const [i, baseChunk] of baseChunks.entries()) {\n const baseChunkContext = baseChunk;\n\n if (changedLines) {\n const hasChangedLinesInChunk = changedLines.some(\n (line) =>\n line > baseChunkContext.lineStart &&\n line < baseChunkContext.lineStart + baseChunkContext.lineLength\n );\n\n if (!hasChangedLinesInChunk) {\n appLogger(\n `No git changed lines found for chunk ${colorizeNumber(i + 1)}`\n );\n\n const chunkWithNoChange = getChunk(updatedFileContent, {\n lineStart: baseChunkContext.lineStart,\n lineLength: baseChunkContext.lineLength,\n });\n\n fileResultContent += chunkWithNoChange;\n\n continue;\n }\n }\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (baseChunks[i - 1]?.content ?? '') +\n baseChunkContext.content +\n (baseChunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const getChunkToReviewPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, baseChunks.length)} of ${baseChunks.length}** is the current chunk to review in ${formatLocale(locale, false)} as reference.\\n` +\n `///chunksStart///` +\n getChunk(updatedFileContent, {\n lineStart: baseChunks[i - 1]?.lineStart ?? 0,\n lineLength:\n (baseChunks[i - 1]?.lineLength ?? 0) +\n baseChunkContext.lineLength +\n (baseChunks[i + 1]?.lineLength ?? 0),\n }) +\n `///chunksEnd///`;\n\n // Make the actual translation call\n let reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getChunkToReviewPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(baseChunks.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: baseChunkContext.content },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(baseChunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedReviewedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n baseChunkContext.content\n );\n\n return fixedReviewedChunkResult;\n })();\n\n updatedFileContent = updatedFileContent.replace(\n baseChunkContext.content,\n reviewedChunkResult\n );\n\n fileResultContent += reviewedChunkResult;\n }\n\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype ReviewDocOptions = {\n docPattern: string[];\n locales: Locales[];\n excludedGlobPattern: string[];\n baseLocale: Locales;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main audit function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then audits them to each locale in LOCALE_LIST.\n */\nexport const reviewDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: ReviewDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const hasCMSAuth = await checkAIAccess(configuration, aiOptions);\n\n if (!hasCMSAuth) return;\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n const limit = pLimit(nbSimultaneousFileProcessed ?? 3);\n\n let docList: string[] = fg.sync(docPattern, {\n ignore: excludedGlobPattern,\n });\n\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 docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Reviewing ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Reviewing ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n const tasks = docList.map((docPath) =>\n locales.flatMap((locale) =>\n limit(async () => {\n appLogger(\n `Reviewing file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(\n configuration.content.baseDir,\n docPath\n );\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n let changedLines: number[] | undefined = undefined;\n // Disabled for now because it's leading to file format issues\n // if (gitOptions) {\n // const gitChangedLines = await listGitLines(\n // absoluteBaseFilePath,\n // gitOptions\n // );\n\n // appLogger(`Git changed lines: ${gitChangedLines.join(', ')}`);\n\n // changedLines = gitChangedLines;\n // }\n\n await reviewFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locales,\n baseLocale,\n aiOptions,\n configuration,\n customInstructions,\n changedLines\n );\n })\n )\n );\n\n await Promise.all(tasks);\n};\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,OAAO,QAAQ;AACf,SAAS,WAAW,qBAAqB;AACzC,SAAS,gBAAgB;AACzB,OAAO,YAAY;AACnB,SAAS,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C,OAAO,aAAa,MAAM,CAAC;AAAA,QACnE;AAEA,cAAM,uBAAuB;AAAA,UAC3B,cAAc,QAAQ;AAAA,UACtB;AAAA,QACF;AACA,cAAM,iBAAiB;AAAA,UACrB;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,cAAM,uBAAuB,uBAAuB,gBAAgB;AAAA,UAClE;AAAA,UACA;AAAA,QACF,CAAC;AAED,YAAI,qBAAqB,WAAW;AAClC,oBAAU,qBAAqB,OAAO;AACtC;AAAA,QACF;AAEA,YAAI,eAAqC;AAazC,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,QAAQ,IAAI,KAAK;AACzB;","names":[]}
@@ -17,7 +17,7 @@ const testMissingTranslations = (options) => {
17
17
  prefix: ""
18
18
  }
19
19
  });
20
- const result = listMissingTranslations();
20
+ const result = listMissingTranslations(void 0, options?.configOptions);
21
21
  const maxKeyColSize = result.missingTranslations.map((t) => ` - ${t.key}`).reduce((max, t) => Math.max(max, t.length), 0);
22
22
  const maxLocalesColSize = result.missingTranslations.map((t) => formatLocale(t.locales, false)).reduce((max, t) => Math.max(max, t.length), 0);
23
23
  const formattedMissingTranslations = result.missingTranslations.map(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/test/index.ts"],"sourcesContent":["import { formatLocale, formatPath } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport { listMissingTranslations } from './listMissingTranslations';\n\nexport { listMissingTranslations };\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const testMissingTranslations = (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n const result = listMissingTranslations();\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n ' - ',\n translation.filePath ? formatPath(translation.filePath) : 'Remote',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n};\n"],"mappings":"AAAA,SAAS,cAAc,kBAAkB;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,+BAA+B;AAQjC,MAAM,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,KAAK,IAAI,aAAa,OAAO,gBAAgB,WAAW,GAAG,CAAC;AAAA,EAChJ;AAEA;AAAA,IACE,6BAA6B,OAAO,uBAAuB,WAAW,IAAI,SAAS,KAAK,WAAW,KAAK,IAAI,aAAa,OAAO,wBAAwB,WAAW,GAAG,CAAC;AAAA,EACzK;AACA;AAAA,IACE,0BAA0B,eAAe,OAAO,eAAe,QAAQ;AAAA,MACrE,OAAO,WAAW;AAAA,MAClB,MAAM,WAAW;AAAA,IACnB,CAAC,CAAC;AAAA,EACJ;AACA;AAAA,IACE,mCAAmC;AAAA,MACjC,OAAO,uBAAuB;AAAA,MAC9B;AAAA,QACE,OAAO,WAAW;AAAA,QAClB,MAAM,WAAW;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/test/index.ts"],"sourcesContent":["import { formatLocale, formatPath } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport { listMissingTranslations } from './listMissingTranslations';\n\nexport { listMissingTranslations };\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const testMissingTranslations = (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n const result = listMissingTranslations(undefined, options?.configOptions);\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n ' - ',\n translation.filePath ? formatPath(translation.filePath) : 'Remote',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n};\n"],"mappings":"AAAA,SAAS,cAAc,kBAAkB;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,+BAA+B;AAQjC,MAAM,0BAA0B,CACrC,YACG;AACH,QAAM,SAAS,iBAAiB,SAAS,aAAa;AACtD,QAAM,EAAE,SAAS,gBAAgB,IAAI,OAAO;AAE5C,QAAM,YAAY,aAAa,QAAQ;AAAA,IACrC,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,SAAS,wBAAwB,QAAW,SAAS,aAAa;AAExE,QAAM,gBAAgB,OAAO,oBAC1B,IAAI,CAAC,MAAM,MAAM,EAAE,GAAG,EAAE,EACxB,OAAO,CAAC,KAAK,MAAM,KAAK,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AA,IACE,mCAAmC;AAAA,MACjC,OAAO,uBAAuB;AAAA,MAC9B;AAAA,QACE,OAAO,WAAW;AAAA,QAClB,MAAM,WAAW;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,12 +1,16 @@
1
- import configuration from "@intlayer/config/built";
1
+ import {
2
+ getConfiguration
3
+ } from "@intlayer/config";
2
4
  import {
3
5
  getMissingLocalesContent
4
6
  } from "@intlayer/core";
5
- import unmergedDictionariesRecord from "@intlayer/unmerged-dictionaries-entry";
6
- const listMissingTranslations = (dictionariesRecord = unmergedDictionariesRecord) => {
7
+ import { getUnmergedDictionaries } from "@intlayer/unmerged-dictionaries-entry";
8
+ const listMissingTranslations = (dictionariesRecord, configurationOptions) => {
9
+ const configuration = getConfiguration(configurationOptions);
10
+ const unmergedDictionariesRecord = dictionariesRecord ?? getUnmergedDictionaries(configuration);
7
11
  const missingTranslations = [];
8
12
  const { locales, requiredLocales } = configuration.internationalization;
9
- for (const dictionaries of Object.values(dictionariesRecord)) {
13
+ for (const dictionaries of Object.values(unmergedDictionariesRecord)) {
10
14
  for (const dictionary of dictionaries) {
11
15
  const missingLocales2 = getMissingLocalesContent(
12
16
  dictionary,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport {\n type ContentNode,\n type Dictionary,\n getMissingLocalesContent,\n} from '@intlayer/core';\nimport unmergedDictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslations = (\n dictionariesRecord: keyof typeof unmergedDictionariesRecord = unmergedDictionariesRecord\n) => {\n const missingTranslations: {\n key: keyof typeof unmergedDictionariesRecord;\n filePath?: string;\n locales: Locales[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n for (const dictionaries of Object.values(dictionariesRecord)) {\n for (const dictionary of dictionaries as unknown as Dictionary[]) {\n const missingLocales = getMissingLocalesContent(\n dictionary as unknown as ContentNode,\n configuration.internationalization.locales,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionary.key,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap((t) => t.locales)\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n"],"mappings":"AACA,OAAO,mBAAmB;AAC1B;AAAA,EAGE;AAAA,OACK;AACP,OAAO,gCAAgC;AAEhC,MAAM,0BAA0B,CACrC,qBAA8D,+BAC3D;AACH,QAAM,sBAIA,CAAC;AAEP,QAAM,EAAE,SAAS,gBAAgB,IAAI,cAAc;AAEnD,aAAW,gBAAgB,OAAO,OAAO,kBAAkB,GAAG;AAC5D,eAAW,cAAc,cAAyC;AAChE,YAAMA,kBAAiB;AAAA,QACrB;AAAA,QACA,cAAc,qBAAqB;AAAA,QACnC;AAAA,UACE,eAAe,WAAW;AAAA,UAC1B,SAAS,CAAC;AAAA,UACV,SAAS,CAAC;AAAA,QACZ;AAAA,MACF;AAEA,UAAIA,gBAAe,SAAS,GAAG;AAC7B,4BAAoB,KAAK;AAAA,UACvB,KAAK,WAAW;AAAA,UAChB,UAAU,WAAW;AAAA,UACrB,SAASA;AAAA,QACX,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,QAAM,oBAAoB,IAAI;AAAA,IAC5B,oBAAoB,QAAQ,CAAC,MAAM,EAAE,OAAO;AAAA,EAC9C;AACA,QAAM,iBAAiB,MAAM,KAAK,iBAAiB;AAEnD,QAAM,yBAAyB,eAAe;AAAA,IAAO,CAAC,YACnD,mBAAmB,SAAS,SAAS,MAAM;AAAA,EAC9C;AAEA,SAAO,EAAE,qBAAqB,gBAAgB,uBAAuB;AACvE;","names":["missingLocales"]}
1
+ {"version":3,"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import {\n GetConfigurationOptions,\n type Locales,\n getConfiguration,\n} from '@intlayer/config';\nimport {\n type ContentNode,\n type Dictionary,\n getMissingLocalesContent,\n} from '@intlayer/core';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslations = (\n dictionariesRecord?: Record<string, Dictionary[]>,\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n const unmergedDictionariesRecord =\n dictionariesRecord ?? getUnmergedDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n locales: Locales[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n for (const dictionaries of Object.values(unmergedDictionariesRecord)) {\n for (const dictionary of dictionaries as unknown as Dictionary[]) {\n const missingLocales = getMissingLocalesContent(\n dictionary as unknown as ContentNode,\n configuration.internationalization.locales,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionary.key,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap((t) => t.locales)\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n"],"mappings":"AAAA;AAAA,EAGE;AAAA,OACK;AACP;AAAA,EAGE;AAAA,OACK;AACP,SAAS,+BAA+B;AAEjC,MAAM,0BAA0B,CACrC,oBACA,yBACG;AACH,QAAM,gBAAgB,iBAAiB,oBAAoB;AAC3D,QAAM,6BACJ,sBAAsB,wBAAwB,aAAa;AAE7D,QAAM,sBAIA,CAAC;AAEP,QAAM,EAAE,SAAS,gBAAgB,IAAI,cAAc;AAEnD,aAAW,gBAAgB,OAAO,OAAO,0BAA0B,GAAG;AACpE,eAAW,cAAc,cAAyC;AAChE,YAAMA,kBAAiB;AAAA,QACrB;AAAA,QACA,cAAc,qBAAqB;AAAA,QACnC;AAAA,UACE,eAAe,WAAW;AAAA,UAC1B,SAAS,CAAC;AAAA,UACV,SAAS,CAAC;AAAA,QACZ;AAAA,MACF;AAEA,UAAIA,gBAAe,SAAS,GAAG;AAC7B,4BAAoB,KAAK;AAAA,UACvB,KAAK,WAAW;AAAA,UAChB,UAAU,WAAW;AAAA,UACrB,SAASA;AAAA,QACX,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,QAAM,oBAAoB,IAAI;AAAA,IAC5B,oBAAoB,QAAQ,CAAC,MAAM,EAAE,OAAO;AAAA,EAC9C;AACA,QAAM,iBAAiB,MAAM,KAAK,iBAAiB;AAEnD,QAAM,yBAAyB,eAAe;AAAA,IAAO,CAAC,YACnD,mBAAmB,SAAS,SAAS,MAAM;AAAA,EAC9C;AAEA,SAAO,EAAE,qBAAqB,gBAAgB,uBAAuB;AACvE;","names":["missingLocales"]}
@@ -19,7 +19,7 @@ import pLimit from "p-limit";
19
19
  import { dirname, join, relative } from "path";
20
20
  import { fileURLToPath } from "url";
21
21
  import { chunkText } from "./utils/calculateChunks.mjs";
22
- import { checkAIAccess } from "./utils/checkAIAccess.mjs";
22
+ import { checkAIAccess } from "./utils/checkAccess.mjs";
23
23
  import { checkFileModifiedRange } from "./utils/checkFileModifiedRange.mjs";
24
24
  import { chunkInference } from "./utils/chunkInference.mjs";
25
25
  import { fixChunkStartEndChars } from "./utils/fixChunkStartEndChars.mjs";
@@ -27,9 +27,8 @@ import { getChunk } from "./utils/getChunk.mjs";
27
27
  import { getOutputFilePath } from "./utils/getOutputFilePath.mjs";
28
28
  const isESModule = typeof import.meta.url === "string";
29
29
  const dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;
30
- const translateFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configOptions, customInstructions) => {
30
+ const translateFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configuration = getConfiguration(), customInstructions) => {
31
31
  try {
32
- const configuration = getConfiguration(configOptions);
33
32
  const appLogger = getAppLogger(configuration, {
34
33
  config: {
35
34
  prefix: ""
@@ -72,10 +71,18 @@ const translateFile = async (baseFilePath, outputFilePath, locale, baseLocale, a
72
71
  { role: "user", content: fileToTranslateCurrentChunk }
73
72
  ],
74
73
  aiOptions,
75
- configOptions
74
+ configuration
76
75
  );
77
76
  appLogger(
78
- `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Chunk ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}`
77
+ [
78
+ `${prefix}`,
79
+ `${ANSIColors.GREY_DARK}[Chunk `,
80
+ colorizeNumber(i + 1),
81
+ `${ANSIColors.GREY_DARK} of `,
82
+ colorizeNumber(chunks.length),
83
+ `${ANSIColors.GREY_DARK}] \u2192${ANSIColors.RESET} `,
84
+ `${colorizeNumber(result.tokenUsed)} tokens used`
85
+ ].join("")
79
86
  );
80
87
  const fixedTranslatedChunkResult = fixChunkStartEndChars(
81
88
  result?.fileContent,
@@ -130,7 +137,8 @@ const translateDoc = async ({
130
137
  let docList = fg.sync(docPattern, {
131
138
  ignore: excludedGlobPattern
132
139
  });
133
- checkAIAccess(configuration, aiOptions);
140
+ const hasCMSAuth = await checkAIAccess(configuration, aiOptions);
141
+ if (!hasCMSAuth) return;
134
142
  if (gitOptions) {
135
143
  const gitChangedFiles = await listGitFiles(gitOptions);
136
144
  if (gitChangedFiles) {
@@ -180,7 +188,7 @@ const translateDoc = async ({
180
188
  locale,
181
189
  baseLocale,
182
190
  aiOptions,
183
- configOptions,
191
+ configuration,
184
192
  customInstructions
185
193
  );
186
194
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translateDoc.ts"],"sourcesContent":["import { AIOptions } from '@intlayer/api';\nimport {\n formatLocale,\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n Locales,\n retryManager,\n} from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport pLimit from 'p-limit';\nimport { dirname, join, relative } from 'path';\nimport { fileURLToPath } from 'url';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAIAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getChunk } from './utils/getChunk';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;\n\n/**\n * Translate a single file for a given locale\n */\nexport const translateFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locales,\n baseLocale: Locales,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions,\n customInstructions?: string\n) => {\n try {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n // Determine the target locale file path\n const fileContent = await readFile(baseFilePath, 'utf-8');\n let fileResultContent = fileContent;\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = (\n await readFile(join(dir, './prompts/TRANSLATE_PROMPT.md'), 'utf-8')\n )\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrexixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // 1. Chunk the file by number of lines instead of characters\n const chunks = chunkText(fileContent);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`\n );\n\n for await (const [i, chunk] of chunks.entries()) {\n const isFirstChunk = i === 0;\n\n // Build the chunk-specific prompt\n const getPrevChunkPrompt = () =>\n `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\\n` +\n `///chunkStart///` +\n getChunk(fileResultContent, chunks[i - 1]) +\n `///chunkEnd///`;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (chunks[i - 1]?.content ?? '') +\n chunks[i].content +\n (chunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Make the actual translation call\n let chunkTranslation = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n\n { role: 'system', content: getBaseChunkContextPrompt() },\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`,\n },\n { role: 'user', content: fileToTranslateCurrentChunk },\n ],\n aiOptions,\n configOptions\n );\n\n appLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Chunk ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}`\n );\n\n const fixedTranslatedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n\n return fixedTranslatedChunkResult;\n })();\n\n // Replace the chunk in the file content\n fileResultContent = fileResultContent.replace(\n fileToTranslateCurrentChunk,\n chunkTranslation\n );\n }\n\n // 4. Write the final translation to the appropriate file path\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype TranslateDocOptions = {\n docPattern: string[];\n locales: Locales[];\n excludedGlobPattern: string[];\n baseLocale: Locales;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main translate function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then translates them to each locale in LOCALE_LIST.\n */\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n const limit = pLimit(nbSimultaneousFileProcessed ?? 3);\n\n let docList: string[] = fg.sync(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n checkAIAccess(configuration, aiOptions);\n\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 docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Translating ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n const tasks = docList.map((docPath) =>\n locales.flatMap((locale) =>\n limit(async () => {\n appLogger(\n `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(\n configuration.content.baseDir,\n docPath\n );\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // check if the file exist, otherwise create it\n if (!existsSync(outputFilePath)) {\n appLogger(`File ${outputFilePath} does not exist, creating it...`);\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n await translateFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locales,\n baseLocale,\n aiOptions,\n configOptions,\n customInstructions\n );\n })\n )\n );\n\n await Promise.all(tasks);\n};\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,OACK;AACP,OAAO,QAAQ;AACf,SAAS,YAAY,WAAW,qBAAqB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Content":["import { AIOptions } from '@intlayer/api';\nimport {\n formatLocale,\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n IntlayerConfig,\n Locales,\n retryManager,\n} from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport pLimit from 'p-limit';\nimport { dirname, join, relative } from 'path';\nimport { fileURLToPath } from 'url';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getChunk } from './utils/getChunk';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;\n\n/**\n * Translate a single file for a given locale\n */\nexport const translateFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locales,\n baseLocale: Locales,\n aiOptions?: AIOptions,\n configuration: IntlayerConfig = getConfiguration(),\n customInstructions?: string\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n // Determine the target locale file path\n const fileContent = await readFile(baseFilePath, 'utf-8');\n let fileResultContent = fileContent;\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = (\n await readFile(join(dir, './prompts/TRANSLATE_PROMPT.md'), 'utf-8')\n )\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrexixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // 1. Chunk the file by number of lines instead of characters\n const chunks = chunkText(fileContent);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`\n );\n\n for await (const [i, chunk] of chunks.entries()) {\n const isFirstChunk = i === 0;\n\n // Build the chunk-specific prompt\n const getPrevChunkPrompt = () =>\n `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\\n` +\n `///chunkStart///` +\n getChunk(fileResultContent, chunks[i - 1]) +\n `///chunkEnd///`;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (chunks[i - 1]?.content ?? '') +\n chunks[i].content +\n (chunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Make the actual translation call\n let chunkTranslation = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n\n { role: 'system', content: getBaseChunkContextPrompt() },\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`,\n },\n { role: 'user', content: fileToTranslateCurrentChunk },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(chunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedTranslatedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n\n return fixedTranslatedChunkResult;\n })();\n\n // Replace the chunk in the file content\n fileResultContent = fileResultContent.replace(\n fileToTranslateCurrentChunk,\n chunkTranslation\n );\n }\n\n // 4. Write the final translation to the appropriate file path\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype TranslateDocOptions = {\n docPattern: string[];\n locales: Locales[];\n excludedGlobPattern: string[];\n baseLocale: Locales;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main translate function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then translates them to each locale in LOCALE_LIST.\n */\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n const limit = pLimit(nbSimultaneousFileProcessed ?? 3);\n\n let docList: string[] = fg.sync(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const hasCMSAuth = await checkAIAccess(configuration, aiOptions);\n\n if (!hasCMSAuth) return;\n\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 docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Translating ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n const tasks = docList.map((docPath) =>\n locales.flatMap((locale) =>\n limit(async () => {\n appLogger(\n `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(\n configuration.content.baseDir,\n docPath\n );\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // check if the file exist, otherwise create it\n if (!existsSync(outputFilePath)) {\n appLogger(`File ${outputFilePath} does not exist, creating it...`);\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n await translateFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locales,\n baseLocale,\n aiOptions,\n configuration,\n customInstructions\n );\n })\n )\n );\n\n await Promise.all(tasks);\n};\n"],"mappings":"A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AAEA,cAAM,uBAAuB,uBAAuB,gBAAgB;AAAA,UAClE;AAAA,UACA;AAAA,QACF,CAAC;AAED,YAAI,qBAAqB,WAAW;AAClC,oBAAU,qBAAqB,OAAO;AACtC;AAAA,QACF;AAEA,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,QAAQ,IAAI,KAAK;AACzB;","names":[]}
@@ -0,0 +1,52 @@
1
+ import { getIntlayerAPIProxy } from "@intlayer/api";
2
+ import { extractErrorMessage } from "@intlayer/chokidar";
3
+ import { getAppLogger } from "@intlayer/config";
4
+ const checkCMSAuth = async (configuration) => {
5
+ const appLogger = getAppLogger(configuration, {
6
+ config: {
7
+ prefix: ""
8
+ }
9
+ });
10
+ const hasCMSAuth = configuration.editor.clientId && configuration.editor.clientSecret;
11
+ if (!hasCMSAuth) {
12
+ appLogger("CMS auth not provided.", {
13
+ level: "error"
14
+ });
15
+ return false;
16
+ }
17
+ const intlayerAPI = getIntlayerAPIProxy(void 0, configuration);
18
+ try {
19
+ await intlayerAPI.oAuth.getOAuth2AccessToken();
20
+ } catch (error) {
21
+ const message = extractErrorMessage(error);
22
+ appLogger(message, {
23
+ level: "error"
24
+ });
25
+ return false;
26
+ }
27
+ return true;
28
+ };
29
+ const checkAIAccess = async (configuration, aiOptions) => {
30
+ const appLogger = getAppLogger(configuration, {
31
+ config: {
32
+ prefix: ""
33
+ }
34
+ });
35
+ const hasCMSAuth = configuration.editor.clientId && configuration.editor.clientSecret;
36
+ const hasHisOwnAIAPIKey = configuration.ai?.apiKey || aiOptions?.apiKey;
37
+ if (!hasCMSAuth && !hasHisOwnAIAPIKey) {
38
+ appLogger("AI options or API key not provided.", {
39
+ level: "error"
40
+ });
41
+ return false;
42
+ }
43
+ if (!hasHisOwnAIAPIKey) {
44
+ return await checkCMSAuth(configuration);
45
+ }
46
+ return true;
47
+ };
48
+ export {
49
+ checkAIAccess,
50
+ checkCMSAuth
51
+ };
52
+ //# sourceMappingURL=checkAccess.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/checkAccess.ts"],"sourcesContent":["import type { AIOptions } from '@intlayer/api';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport { extractErrorMessage } from '@intlayer/chokidar';\nimport { getAppLogger, type IntlayerConfig } from '@intlayer/config';\n\nexport const checkCMSAuth = async (\n configuration: IntlayerConfig\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const hasCMSAuth =\n configuration.editor.clientId && configuration.editor.clientSecret;\n if (!hasCMSAuth) {\n appLogger('CMS auth not provided.', {\n level: 'error',\n });\n\n return false;\n }\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n try {\n await intlayerAPI.oAuth.getOAuth2AccessToken();\n } catch (error) {\n const message = extractErrorMessage(error);\n\n appLogger(message, {\n level: 'error',\n });\n return false;\n }\n\n return true;\n};\n\nexport const checkAIAccess = async (\n configuration: IntlayerConfig,\n aiOptions?: AIOptions\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const hasCMSAuth =\n configuration.editor.clientId && configuration.editor.clientSecret;\n const hasHisOwnAIAPIKey = configuration.ai?.apiKey || aiOptions?.apiKey;\n\n // User need to provide either his own AI API key or the CMS auth\n if (!hasCMSAuth && !hasHisOwnAIAPIKey) {\n appLogger('AI options or API key not provided.', {\n level: 'error',\n });\n\n return false;\n }\n\n // If the user do not have his own AI API key, we need to check the CMS auth\n if (!hasHisOwnAIAPIKey) {\n return await checkCMSAuth(configuration);\n }\n\n return true;\n};\n"],"mappings":"AACA,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AACpC,SAAS,oBAAyC;AAE3C,MAAM,eAAe,OAC1B,kBACqB;AACrB,QAAM,YAAY,aAAa,eAAe;AAAA,IAC5C,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,aACJ,cAAc,OAAO,YAAY,cAAc,OAAO;AACxD,MAAI,CAAC,YAAY;AACf,cAAU,0BAA0B;AAAA,MAClC,OAAO;AAAA,IACT,CAAC;AAED,WAAO;AAAA,EACT;AACA,QAAM,cAAc,oBAAoB,QAAW,aAAa;AAEhE,MAAI;AACF,UAAM,YAAY,MAAM,qBAAqB;AAAA,EAC/C,SAAS,OAAO;AACd,UAAM,UAAU,oBAAoB,KAAK;AAEzC,cAAU,SAAS;AAAA,MACjB,OAAO;AAAA,IACT,CAAC;AACD,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,gBAAgB,OAC3B,eACA,cACqB;AACrB,QAAM,YAAY,aAAa,eAAe;AAAA,IAC5C,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,aACJ,cAAc,OAAO,YAAY,cAAc,OAAO;AACxD,QAAM,oBAAoB,cAAc,IAAI,UAAU,WAAW;AAGjE,MAAI,CAAC,cAAc,CAAC,mBAAmB;AACrC,cAAU,uCAAuC;AAAA,MAC/C,OAAO;AAAA,IACT,CAAC;AAED,WAAO;AAAA,EACT;AAGA,MAAI,CAAC,mBAAmB;AACtB,WAAO,MAAM,aAAa,aAAa;AAAA,EACzC;AAEA,SAAO;AACT;","names":[]}
@@ -1,14 +1,10 @@
1
1
  import {
2
2
  getIntlayerAPIProxy
3
3
  } from "@intlayer/api";
4
- import {
5
- getConfiguration,
6
- retryManager
7
- } from "@intlayer/config";
8
- const chunkInference = async (messages, aiOptions, configOptions) => {
4
+ import { retryManager } from "@intlayer/config";
5
+ const chunkInference = async (messages, aiOptions, configuration) => {
9
6
  let lastResult;
10
7
  await retryManager(async () => {
11
- const configuration = getConfiguration(configOptions);
12
8
  const api = getIntlayerAPIProxy(void 0, configuration);
13
9
  const response = await api.ai.customQuery({
14
10
  aiOptions,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/chunkInference.ts"],"sourcesContent":["import {\n type AIOptions,\n getIntlayerAPIProxy,\n type Messages,\n} from '@intlayer/api';\nimport {\n getConfiguration,\n type GetConfigurationOptions,\n retryManager,\n} from '@intlayer/config';\n\ntype ChunkInferenceResult = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Translates a single chunk via the OpenAI API.\n * Includes retry logic if the call fails.\n */\nexport const chunkInference = async (\n messages: Messages,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions\n): Promise<ChunkInferenceResult> => {\n let lastResult: ChunkInferenceResult;\n\n await retryManager(async () => {\n const configuration = getConfiguration(configOptions);\n const api = getIntlayerAPIProxy(undefined, configuration);\n const response = await api.ai.customQuery({\n aiOptions,\n messages,\n });\n\n if (!response.data) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response.data;\n\n const newContent = fileContent\n .replaceAll('///chunksStart///', '')\n .replaceAll('///chunkStart///', '')\n .replaceAll('///chunksEnd///', '')\n .replaceAll('///chunkEnd///', '')\n .replaceAll('///chunksStart///', '')\n .replaceAll('chunkStart///', '')\n .replaceAll('chunksEnd///', '')\n .replaceAll('chunkEnd///', '')\n .replaceAll('///chunksStart', '')\n .replaceAll('///chunkStart', '')\n .replaceAll('///chunksEnd', '')\n .replaceAll('///chunkEnd', '')\n .replaceAll('chunksStart', '')\n .replaceAll('chunkStart', '')\n .replaceAll('chunksEnd', '')\n .replaceAll('chunkEnd', '');\n\n lastResult = {\n fileContent: newContent,\n tokenUsed,\n };\n })();\n\n return lastResult!;\n};\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AAWA,MAAM,iBAAiB,OAC5B,UACA,WACA,kBACkC;AAClC,MAAI;AAEJ,QAAM,aAAa,YAAY;AAC7B,UAAM,gBAAgB,iBAAiB,aAAa;AACpD,UAAM,MAAM,oBAAoB,QAAW,aAAa;AACxD,UAAM,WAAW,MAAM,IAAI,GAAG,YAAY;AAAA,MACxC;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,SAAS,MAAM;AAClB,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AAEA,UAAM,EAAE,aAAa,UAAU,IAAI,SAAS;AAE5C,UAAM,aAAa,YAChB,WAAW,qBAAqB,EAAE,EAClC,WAAW,oBAAoB,EAAE,EACjC,WAAW,mBAAmB,EAAE,EAChC,WAAW,kBAAkB,EAAE,EAC/B,WAAW,qBAAqB,EAAE,EAClC,WAAW,iBAAiB,EAAE,EAC9B,WAAW,gBAAgB,EAAE,EAC7B,WAAW,eAAe,EAAE,EAC5B,WAAW,kBAAkB,EAAE,EAC/B,WAAW,iBAAiB,EAAE,EAC9B,WAAW,gBAAgB,EAAE,EAC7B,WAAW,eAAe,EAAE,EAC5B,WAAW,eAAe,EAAE,EAC5B,WAAW,cAAc,EAAE,EAC3B,WAAW,aAAa,EAAE,EAC1B,WAAW,YAAY,EAAE;AAE5B,iBAAa;AAAA,MACX,aAAa;AAAA,MACb;AAAA,IACF;AAAA,EACF,CAAC,EAAE;AAEH,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/utils/chunkInference.ts"],"sourcesContent":["import {\n type AIOptions,\n getIntlayerAPIProxy,\n type Messages,\n} from '@intlayer/api';\nimport { type IntlayerConfig, retryManager } from '@intlayer/config';\n\ntype ChunkInferenceResult = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Translates a single chunk via the OpenAI API.\n * Includes retry logic if the call fails.\n */\nexport const chunkInference = async (\n messages: Messages,\n aiOptions?: AIOptions,\n configuration?: IntlayerConfig\n): Promise<ChunkInferenceResult> => {\n let lastResult: ChunkInferenceResult;\n\n await retryManager(async () => {\n const api = getIntlayerAPIProxy(undefined, configuration);\n\n const response = await api.ai.customQuery({\n aiOptions,\n messages,\n });\n\n if (!response.data) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response.data;\n\n const newContent = fileContent\n .replaceAll('///chunksStart///', '')\n .replaceAll('///chunkStart///', '')\n .replaceAll('///chunksEnd///', '')\n .replaceAll('///chunkEnd///', '')\n .replaceAll('///chunksStart///', '')\n .replaceAll('chunkStart///', '')\n .replaceAll('chunksEnd///', '')\n .replaceAll('chunkEnd///', '')\n .replaceAll('///chunksStart', '')\n .replaceAll('///chunkStart', '')\n .replaceAll('///chunksEnd', '')\n .replaceAll('///chunkEnd', '')\n .replaceAll('chunksStart', '')\n .replaceAll('chunkStart', '')\n .replaceAll('chunksEnd', '')\n .replaceAll('chunkEnd', '');\n\n lastResult = {\n fileContent: newContent,\n tokenUsed,\n };\n })();\n\n return lastResult!;\n};\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,OAEK;AACP,SAA8B,oBAAoB;AAW3C,MAAM,iBAAiB,OAC5B,UACA,WACA,kBACkC;AAClC,MAAI;AAEJ,QAAM,aAAa,YAAY;AAC7B,UAAM,MAAM,oBAAoB,QAAW,aAAa;AAExD,UAAM,WAAW,MAAM,IAAI,GAAG,YAAY;AAAA,MACxC;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,SAAS,MAAM;AAClB,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AAEA,UAAM,EAAE,aAAa,UAAU,IAAI,SAAS;AAE5C,UAAM,aAAa,YAChB,WAAW,qBAAqB,EAAE,EAClC,WAAW,oBAAoB,EAAE,EACjC,WAAW,mBAAmB,EAAE,EAChC,WAAW,kBAAkB,EAAE,EAC/B,WAAW,qBAAqB,EAAE,EAClC,WAAW,iBAAiB,EAAE,EAC9B,WAAW,gBAAgB,EAAE,EAC7B,WAAW,eAAe,EAAE,EAC5B,WAAW,kBAAkB,EAAE,EAC/B,WAAW,iBAAiB,EAAE,EAC9B,WAAW,gBAAgB,EAAE,EAC7B,WAAW,eAAe,EAAE,EAC5B,WAAW,eAAe,EAAE,EAC5B,WAAW,cAAc,EAAE,EAC3B,WAAW,aAAa,EAAE,EAC1B,WAAW,YAAY,EAAE;AAE5B,iBAAa;AAAA,MACX,aAAa;AAAA,MACb;AAAA,IACF;AAAA,EACF,CAAC,EAAE;AAEH,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4BpC,eAAO,MAAM,OAAO,QAEP,CAAC;AA+Hd,KAAK,UAAU,GAAG;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,UAAU,CAAC;AA2Cf;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,QAAO,OAgXzB,CAAC"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4BpC,eAAO,MAAM,OAAO,QAEP,CAAC;AA+Hd,KAAK,UAAU,GAAG;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,UAAU,CAAC;AA2Cf;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,QAAO,OA8XzB,CAAC"}
@@ -1,23 +1,17 @@
1
1
  import { AIOptions } from '@intlayer/api';
2
2
  import { ListGitFilesOptions } from '@intlayer/chokidar';
3
- import { GetConfigurationOptions, Locales } from '@intlayer/config';
4
- import { type Dictionary } from '@intlayer/core';
3
+ import { Locales } from '@intlayer/config';
4
+ import { GetTargetDictionaryOptions } from '../getTargetDictionary';
5
5
  export type FillOptions = {
6
6
  sourceLocale?: Locales;
7
7
  outputLocales?: Locales | Locales[];
8
- file?: string | string[];
9
8
  mode?: 'complete' | 'review';
10
- keys?: string | string[];
11
- excludedKeys?: string | string[];
12
- filter?: (entry: Dictionary) => boolean;
13
- pathFilter?: string | string[];
14
9
  gitOptions?: ListGitFilesOptions;
15
- configOptions?: GetConfigurationOptions;
16
10
  aiOptions?: AIOptions;
17
11
  verbose?: boolean;
18
12
  nbConcurrentTranslations?: number;
19
13
  build?: boolean;
20
- };
14
+ } & GetTargetDictionaryOptions;
21
15
  /**
22
16
  * Fill translations based on the provided options.
23
17
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fill/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyB,MAAM,eAAe,CAAC;AACjE,OAAO,EAGL,mBAAmB,EAMpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAKL,uBAAuB,EACvB,OAAO,EACR,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,UAAU,EAIhB,MAAM,gBAAgB,CAAC;AAWxB,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC;IACpC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACjC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,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