@intlayer/cli 5.8.1 → 6.0.0-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 (114) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +240 -0
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -0
  3. package/dist/cjs/cli.cjs +29 -7
  4. package/dist/cjs/cli.cjs.map +1 -1
  5. package/dist/cjs/config.cjs +5 -1
  6. package/dist/cjs/config.cjs.map +1 -1
  7. package/dist/cjs/fill/autoFill.cjs +105 -0
  8. package/dist/cjs/fill/autoFill.cjs.map +1 -0
  9. package/dist/cjs/fill/formatAutoFillData.cjs +108 -0
  10. package/dist/cjs/fill/formatAutoFillData.cjs.map +1 -0
  11. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +46 -0
  12. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -0
  13. package/dist/cjs/fill/getTargetDictionary.cjs +86 -0
  14. package/dist/cjs/fill/getTargetDictionary.cjs.map +1 -0
  15. package/dist/cjs/fill/index.cjs +257 -0
  16. package/dist/cjs/fill/index.cjs.map +1 -0
  17. package/dist/cjs/index.cjs +4 -2
  18. package/dist/cjs/index.cjs.map +1 -1
  19. package/dist/cjs/listContentDeclaration.cjs +37 -19
  20. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  21. package/dist/cjs/liveSync.cjs +254 -0
  22. package/dist/cjs/liveSync.cjs.map +1 -0
  23. package/dist/cjs/pull.cjs +18 -22
  24. package/dist/cjs/pull.cjs.map +1 -1
  25. package/dist/cjs/push.cjs +28 -27
  26. package/dist/cjs/push.cjs.map +1 -1
  27. package/dist/cjs/pushConfig.cjs +8 -15
  28. package/dist/cjs/pushConfig.cjs.map +1 -1
  29. package/dist/cjs/reviewDoc.cjs +43 -26
  30. package/dist/cjs/reviewDoc.cjs.map +1 -1
  31. package/dist/cjs/test/index.cjs +91 -0
  32. package/dist/cjs/test/index.cjs.map +1 -0
  33. package/dist/cjs/test/listMissingTranslations.cjs +73 -0
  34. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -0
  35. package/dist/cjs/translateDoc.cjs +40 -24
  36. package/dist/cjs/translateDoc.cjs.map +1 -1
  37. package/dist/cjs/utils/checkAIAccess.cjs +5 -1
  38. package/dist/cjs/utils/checkAIAccess.cjs.map +1 -1
  39. package/dist/esm/IntlayerEventListener.mjs +206 -0
  40. package/dist/esm/IntlayerEventListener.mjs.map +1 -0
  41. package/dist/esm/cli.mjs +26 -4
  42. package/dist/esm/cli.mjs.map +1 -1
  43. package/dist/esm/config.mjs +5 -1
  44. package/dist/esm/config.mjs.map +1 -1
  45. package/dist/esm/fill/autoFill.mjs +92 -0
  46. package/dist/esm/fill/autoFill.mjs.map +1 -0
  47. package/dist/esm/fill/formatAutoFillData.mjs +84 -0
  48. package/dist/esm/fill/formatAutoFillData.mjs.map +1 -0
  49. package/dist/esm/fill/formatAutoFilledFilePath.mjs +22 -0
  50. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -0
  51. package/dist/esm/fill/getTargetDictionary.mjs +51 -0
  52. package/dist/esm/fill/getTargetDictionary.mjs.map +1 -0
  53. package/dist/esm/fill/index.mjs +240 -0
  54. package/dist/esm/fill/index.mjs.map +1 -0
  55. package/dist/esm/index.mjs +2 -1
  56. package/dist/esm/index.mjs.map +1 -1
  57. package/dist/esm/listContentDeclaration.mjs +38 -17
  58. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  59. package/dist/esm/liveSync.mjs +220 -0
  60. package/dist/esm/liveSync.mjs.map +1 -0
  61. package/dist/esm/pull.mjs +19 -21
  62. package/dist/esm/pull.mjs.map +1 -1
  63. package/dist/esm/push.mjs +33 -27
  64. package/dist/esm/push.mjs.map +1 -1
  65. package/dist/esm/pushConfig.mjs +8 -15
  66. package/dist/esm/pushConfig.mjs.map +1 -1
  67. package/dist/esm/reviewDoc.mjs +53 -28
  68. package/dist/esm/reviewDoc.mjs.map +1 -1
  69. package/dist/esm/test/index.mjs +74 -0
  70. package/dist/esm/test/index.mjs.map +1 -0
  71. package/dist/esm/test/listMissingTranslations.mjs +41 -0
  72. package/dist/esm/test/listMissingTranslations.mjs.map +1 -0
  73. package/dist/esm/translateDoc.mjs +50 -27
  74. package/dist/esm/translateDoc.mjs.map +1 -1
  75. package/dist/esm/utils/checkAIAccess.mjs +5 -1
  76. package/dist/esm/utils/checkAIAccess.mjs.map +1 -1
  77. package/dist/types/IntlayerEventListener.d.ts +85 -0
  78. package/dist/types/IntlayerEventListener.d.ts.map +1 -0
  79. package/dist/types/cli.d.ts.map +1 -1
  80. package/dist/types/config.d.ts.map +1 -1
  81. package/dist/types/fill/autoFill.d.ts +4 -0
  82. package/dist/types/fill/autoFill.d.ts.map +1 -0
  83. package/dist/types/fill/formatAutoFillData.d.ts +9 -0
  84. package/dist/types/fill/formatAutoFillData.d.ts.map +1 -0
  85. package/dist/types/fill/formatAutoFilledFilePath.d.ts +3 -0
  86. package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -0
  87. package/dist/types/fill/getTargetDictionary.d.ts +4 -0
  88. package/dist/types/fill/getTargetDictionary.d.ts.map +1 -0
  89. package/dist/types/{fill.d.ts → fill/index.d.ts} +2 -5
  90. package/dist/types/fill/index.d.ts.map +1 -0
  91. package/dist/types/index.d.ts +1 -0
  92. package/dist/types/index.d.ts.map +1 -1
  93. package/dist/types/listContentDeclaration.d.ts +4 -5
  94. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  95. package/dist/types/liveSync.d.ts +6 -0
  96. package/dist/types/liveSync.d.ts.map +1 -0
  97. package/dist/types/pull.d.ts.map +1 -1
  98. package/dist/types/push.d.ts +1 -1
  99. package/dist/types/push.d.ts.map +1 -1
  100. package/dist/types/pushConfig.d.ts +0 -1
  101. package/dist/types/pushConfig.d.ts.map +1 -1
  102. package/dist/types/reviewDoc.d.ts.map +1 -1
  103. package/dist/types/test/index.d.ts +8 -0
  104. package/dist/types/test/index.d.ts.map +1 -0
  105. package/dist/types/test/listMissingTranslations.d.ts +12 -0
  106. package/dist/types/test/listMissingTranslations.d.ts.map +1 -0
  107. package/dist/types/translateDoc.d.ts.map +1 -1
  108. package/dist/types/utils/checkAIAccess.d.ts.map +1 -1
  109. package/package.json +17 -15
  110. package/dist/cjs/fill.cjs +0 -405
  111. package/dist/cjs/fill.cjs.map +0 -1
  112. package/dist/esm/fill.mjs +0 -385
  113. package/dist/esm/fill.mjs.map +0 -1
  114. package/dist/types/fill.d.ts.map +0 -1
@@ -0,0 +1,240 @@
1
+ import { getAiAPI, getOAuthAPI } from "@intlayer/api";
2
+ import {
3
+ formatLocale,
4
+ formatPath,
5
+ mergeDictionaries,
6
+ prepareIntlayer,
7
+ processPerLocaleDictionary,
8
+ reduceDictionaryContent,
9
+ writeContentDeclaration
10
+ } from "@intlayer/chokidar";
11
+ import {
12
+ colorizeKey,
13
+ colorizePath,
14
+ getAppLogger,
15
+ getConfiguration
16
+ } from "@intlayer/config";
17
+ import {
18
+ getFilterTranslationsOnlyContent,
19
+ getLocalisedContent,
20
+ getMissingLocalesContent
21
+ } from "@intlayer/core";
22
+ import dictionariesRecord from "@intlayer/dictionaries-entry";
23
+ import pLimit from "p-limit";
24
+ import { relative } from "path";
25
+ import { checkAIAccess } from "../utils/checkAIAccess.mjs";
26
+ import { autoFill } from "./autoFill.mjs";
27
+ import { ensureArray, getTargetDictionary } from "./getTargetDictionary.mjs";
28
+ const NB_CONCURRENT_TRANSLATIONS = 8;
29
+ const fill = async (options) => {
30
+ const configuration = getConfiguration(options.configOptions);
31
+ const appLogger = getAppLogger(configuration, {
32
+ config: {
33
+ prefix: ""
34
+ }
35
+ });
36
+ if (options.build) {
37
+ await prepareIntlayer(configuration);
38
+ }
39
+ const { defaultLocale, locales } = configuration.internationalization;
40
+ const mode = options.mode ?? "complete";
41
+ const baseLocale = options.sourceLocale ?? defaultLocale;
42
+ const outputLocales = (options.outputLocales ? ensureArray(options.outputLocales) : locales).filter((locale) => locale !== baseLocale);
43
+ checkAIAccess(configuration, options.aiOptions);
44
+ let oAuth2AccessToken;
45
+ if (configuration.editor.clientId) {
46
+ const intlayerAuthAPI = getOAuthAPI(configuration);
47
+ const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();
48
+ oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
49
+ }
50
+ appLogger("Starting fill function", {
51
+ level: "info"
52
+ });
53
+ const targetUnmergedDictionaries = await getTargetDictionary(options);
54
+ const affectedDictionaryKeys = /* @__PURE__ */ new Set();
55
+ targetUnmergedDictionaries.forEach((dict) => {
56
+ affectedDictionaryKeys.add(dict.key);
57
+ });
58
+ appLogger(
59
+ [
60
+ "Affected dictionary keys for processing:",
61
+ Array.from(affectedDictionaryKeys).map((key) => colorizeKey(key)).join(", ")
62
+ ],
63
+ {
64
+ isVerbose: true
65
+ }
66
+ );
67
+ for (const targetUnmergedDictionary of targetUnmergedDictionaries) {
68
+ const dictionaryKey = targetUnmergedDictionary.key;
69
+ const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];
70
+ const sourceLocale = targetUnmergedDictionary.locale ?? baseLocale;
71
+ if (!mainDictionaryToProcess) {
72
+ appLogger(
73
+ `Dictionary with key '${colorizeKey(dictionaryKey)}' not found in dictionariesRecord. Skipping.`,
74
+ {
75
+ level: "warn"
76
+ }
77
+ );
78
+ continue;
79
+ }
80
+ if (!targetUnmergedDictionary.filePath) {
81
+ appLogger(
82
+ `Dictionary with key '${colorizeKey(dictionaryKey)}' has no file path. Skipping.`,
83
+ {
84
+ level: "warn"
85
+ }
86
+ );
87
+ continue;
88
+ }
89
+ const relativePath = relative(
90
+ configuration.content.baseDir,
91
+ targetUnmergedDictionary.filePath
92
+ );
93
+ appLogger(`Processing content declaration: ${colorizePath(relativePath)}`, {
94
+ level: "info"
95
+ });
96
+ const sourceLocaleContent = getFilterTranslationsOnlyContent(
97
+ mainDictionaryToProcess,
98
+ sourceLocale,
99
+ { dictionaryKey, keyPath: [] }
100
+ );
101
+ if (Object.keys(sourceLocaleContent).length === 0) {
102
+ appLogger(
103
+ `No content found for dictionary '${colorizeKey(dictionaryKey)}' in source locale ${formatLocale(sourceLocale)}. Skipping translation for this dictionary.`,
104
+ {
105
+ level: "warn"
106
+ }
107
+ );
108
+ continue;
109
+ }
110
+ const result = [];
111
+ const limit = pLimit(
112
+ options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS
113
+ );
114
+ let outputLocalesList = outputLocales;
115
+ if (mode === "complete") {
116
+ const missingLocales = getMissingLocalesContent(
117
+ mainDictionaryToProcess,
118
+ outputLocales,
119
+ {
120
+ dictionaryKey: mainDictionaryToProcess.key,
121
+ keyPath: [],
122
+ plugins: []
123
+ }
124
+ );
125
+ outputLocalesList = missingLocales;
126
+ }
127
+ const translationPromises = outputLocalesList.map(
128
+ (targetLocale) => limit(async () => {
129
+ appLogger(
130
+ `Preparing translation for '${colorizeKey(dictionaryKey)}' dictionary from ${formatLocale(sourceLocale)} to ${formatLocale(targetLocale)}`,
131
+ {
132
+ level: "info"
133
+ }
134
+ );
135
+ const presetOutputContent = getLocalisedContent(
136
+ mainDictionaryToProcess,
137
+ targetLocale,
138
+ { dictionaryKey, keyPath: [] }
139
+ );
140
+ try {
141
+ const translationResult = await getAiAPI(
142
+ void 0,
143
+ configuration
144
+ ).translateJSON(
145
+ {
146
+ entryFileContent: sourceLocaleContent.content,
147
+ // Should be JSON, ensure getLocalisedContent provides this.
148
+ presetOutputContent: presetOutputContent.content,
149
+ // Should be JSON
150
+ dictionaryDescription: mainDictionaryToProcess.description,
151
+ entryLocale: sourceLocale,
152
+ outputLocale: targetLocale,
153
+ mode,
154
+ aiOptions: options.aiOptions
155
+ },
156
+ {
157
+ ...oAuth2AccessToken && {
158
+ headers: {
159
+ Authorization: `Bearer ${oAuth2AccessToken}`
160
+ }
161
+ }
162
+ }
163
+ );
164
+ if (!translationResult.data?.fileContent) {
165
+ appLogger(
166
+ `No content result found for '${colorizeKey(dictionaryKey)}' to ${formatLocale(targetLocale)}`,
167
+ {
168
+ level: "error"
169
+ }
170
+ );
171
+ return null;
172
+ }
173
+ const processedPerLocaleDictionary = processPerLocaleDictionary({
174
+ ...mainDictionaryToProcess,
175
+ content: translationResult.data?.fileContent,
176
+ locale: targetLocale
177
+ });
178
+ return processedPerLocaleDictionary;
179
+ } catch (error) {
180
+ appLogger(
181
+ `Error filling '${colorizeKey(dictionaryKey)}' to ${formatLocale(targetLocale)}:` + error,
182
+ {
183
+ level: "error"
184
+ }
185
+ );
186
+ return null;
187
+ }
188
+ })
189
+ );
190
+ const translationResults = await Promise.all(translationPromises);
191
+ translationResults.forEach((translationResult) => {
192
+ if (translationResult) {
193
+ result.push(translationResult);
194
+ }
195
+ });
196
+ const dictionaryToMerge = mode === "review" ? [...result, mainDictionaryToProcess] : [mainDictionaryToProcess, ...result];
197
+ const mergedResults = mergeDictionaries(dictionaryToMerge);
198
+ let formattedDict = targetUnmergedDictionary;
199
+ if (formattedDict.locale) {
200
+ const presetOutputContent = getLocalisedContent(
201
+ mainDictionaryToProcess,
202
+ formattedDict.locale,
203
+ { dictionaryKey, keyPath: [] }
204
+ );
205
+ formattedDict = {
206
+ ...formattedDict,
207
+ content: presetOutputContent.content
208
+ };
209
+ }
210
+ const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);
211
+ if (formattedDict.autoFill || configuration.content.autoFill) {
212
+ await autoFill(
213
+ mergedResults,
214
+ targetUnmergedDictionary,
215
+ formattedDict.autoFill ?? configuration.content.autoFill,
216
+ outputLocalesList,
217
+ [sourceLocale],
218
+ configuration
219
+ );
220
+ } else {
221
+ await writeContentDeclaration(
222
+ { ...formattedDict, content: reducedResult.content },
223
+ configuration,
224
+ formattedDict.filePath
225
+ );
226
+ if (formattedDict.filePath) {
227
+ appLogger(
228
+ `Content declaration for '${colorizeKey(dictionaryKey)}' written to ${formatPath(formattedDict.filePath)}`,
229
+ {
230
+ level: "info"
231
+ }
232
+ );
233
+ }
234
+ }
235
+ }
236
+ };
237
+ export {
238
+ fill
239
+ };
240
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/fill/index.ts"],"sourcesContent":["import { AIOptions, getAiAPI, getOAuthAPI } from '@intlayer/api'; // Importing only getAiAPI for now\nimport {\n formatLocale,\n formatPath,\n ListGitFilesOptions,\n mergeDictionaries,\n prepareIntlayer,\n processPerLocaleDictionary,\n reduceDictionaryContent,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n colorizeKey,\n colorizePath,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n Locales,\n} from '@intlayer/config';\nimport {\n type ContentNode,\n type Dictionary,\n getFilterTranslationsOnlyContent,\n getLocalisedContent,\n getMissingLocalesContent,\n} from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport pLimit from 'p-limit';\nimport { relative } from 'path';\nimport { checkAIAccess } from '../utils/checkAIAccess';\nimport { autoFill } from './autoFill';\nimport { ensureArray, getTargetDictionary } from './getTargetDictionary';\n\nconst NB_CONCURRENT_TRANSLATIONS = 8;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locales;\n outputLocales?: Locales | Locales[];\n file?: string | string[];\n mode?: 'complete' | 'review';\n keys?: string | string[];\n excludedKeys?: string | string[];\n filter?: (entry: Dictionary) => boolean; // DictionaryEntry needs to be defined\n pathFilter?: string | string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n build?: boolean;\n};\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n if (options.build) {\n await prepareIntlayer(configuration);\n }\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options.mode ?? 'complete';\n const baseLocale = options.sourceLocale ?? defaultLocale;\n const outputLocales = (\n options.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) => locale !== baseLocale);\n\n checkAIAccess(configuration, options.aiOptions);\n\n let oAuth2AccessToken: string | undefined;\n if (configuration.editor.clientId) {\n const intlayerAuthAPI = getOAuthAPI(configuration);\n const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();\n\n oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n }\n\n appLogger('Starting fill function', {\n level: 'info',\n });\n\n const targetUnmergedDictionaries = await getTargetDictionary(options);\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n appLogger(\n [\n 'Affected dictionary keys for processing:',\n Array.from(affectedDictionaryKeys)\n .map((key) => colorizeKey(key))\n .join(', '),\n ],\n {\n isVerbose: true,\n }\n );\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryKey = targetUnmergedDictionary.key;\n const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `Dictionary with key '${colorizeKey(dictionaryKey)}' not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n if (!targetUnmergedDictionary.filePath) {\n appLogger(\n `Dictionary with key '${colorizeKey(dictionaryKey)}' has no file path. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const relativePath = relative(\n configuration.content.baseDir,\n targetUnmergedDictionary.filePath\n );\n\n appLogger(`Processing content declaration: ${colorizePath(relativePath)}`, {\n level: 'info',\n });\n\n const sourceLocaleContent = getFilterTranslationsOnlyContent(\n mainDictionaryToProcess as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n if (Object.keys(sourceLocaleContent).length === 0) {\n appLogger(\n `No content found for dictionary '${colorizeKey(dictionaryKey)}' in source locale ${formatLocale(sourceLocale)}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n const result: Dictionary[] = [];\n\n // 5. for each locale to translate (exclude base locale) generate json translations\n // Limit concurrent translations to 5 at a time\n const limit = pLimit(\n options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS\n );\n\n // Determine output locales\n let outputLocalesList: Locales[] = outputLocales;\n\n // If mode is review, translate all locales\n // If mode is complete, translate only the locales that are not the source locale\n if (mode === 'complete') {\n const missingLocales = getMissingLocalesContent(\n mainDictionaryToProcess as unknown as ContentNode,\n outputLocales,\n {\n dictionaryKey: mainDictionaryToProcess.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n outputLocalesList = missingLocales;\n }\n\n const translationPromises = outputLocalesList.map((targetLocale) =>\n limit(async () => {\n appLogger(\n `Preparing translation for '${colorizeKey(dictionaryKey)}' dictionary from ${formatLocale(sourceLocale)} to ${formatLocale(targetLocale)}`,\n {\n level: 'info',\n }\n );\n\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n targetLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n try {\n const translationResult = await getAiAPI(\n undefined,\n configuration\n ).translateJSON(\n {\n entryFileContent: sourceLocaleContent.content, // Should be JSON, ensure getLocalisedContent provides this.\n presetOutputContent: presetOutputContent.content, // Should be JSON\n dictionaryDescription: mainDictionaryToProcess.description,\n entryLocale: sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions: options.aiOptions,\n },\n {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n }\n );\n\n if (!translationResult.data?.fileContent) {\n appLogger(\n `No content result found for '${colorizeKey(dictionaryKey)}' to ${formatLocale(targetLocale)}`,\n {\n level: 'error',\n }\n );\n return null;\n }\n\n const processedPerLocaleDictionary = processPerLocaleDictionary({\n ...mainDictionaryToProcess,\n content: translationResult.data?.fileContent,\n locale: targetLocale,\n });\n\n return processedPerLocaleDictionary;\n } catch (error) {\n appLogger(\n `Error filling '${colorizeKey(dictionaryKey)}' to ${formatLocale(targetLocale)}:` +\n error,\n {\n level: 'error',\n }\n );\n return null;\n }\n })\n );\n\n // Wait for all translations to complete\n const translationResults = await Promise.all(translationPromises);\n\n // Filter out null results and add to result array\n translationResults.forEach((translationResult) => {\n if (translationResult) {\n result.push(translationResult);\n }\n });\n\n const dictionaryToMerge =\n mode === 'review'\n ? [...result, mainDictionaryToProcess] // Mode review: generated content will override the base one\n : [mainDictionaryToProcess, ...result]; // Mode complete: base content will override the generated one\n\n const mergedResults = mergeDictionaries(dictionaryToMerge);\n\n let formattedDict = targetUnmergedDictionary;\n\n if (formattedDict.locale) {\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n formattedDict.locale,\n { dictionaryKey, keyPath: [] }\n );\n\n formattedDict = {\n ...formattedDict,\n content: presetOutputContent.content,\n };\n }\n\n const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);\n\n if (formattedDict.autoFill || configuration.content.autoFill) {\n await autoFill(\n mergedResults,\n targetUnmergedDictionary,\n formattedDict.autoFill ?? configuration.content.autoFill,\n outputLocalesList,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(\n { ...formattedDict, content: reducedResult.content },\n configuration,\n formattedDict.filePath\n );\n\n if (formattedDict.filePath) {\n appLogger(\n `Content declaration for '${colorizeKey(dictionaryKey)}' written to ${formatPath(formattedDict.filePath)}`,\n {\n level: 'info',\n }\n );\n }\n }\n }\n};\n"],"mappings":"AAAA,SAAoB,UAAU,mBAAmB;AACjD;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EAGE;AAAA,EACA;AA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AAO,KAAK,iBAAiB;AAAA,MAC/B;AAAA,IACF,CAAC;AAED,UAAM,oBACJ,SAAS,WACL,CAAC,GAAG,QAAQ,uBAAuB,IACnC,CAAC,yBAAyB,GAAG,MAAM;AAEzC,UAAM,gBAAgB,kBAAkB,iBAAiB;AAEzD,QAAI,gBAAgB;AAEpB,QAAI,cAAc,QAAQ;AACxB,YAAM,sBAAsB;AAAA,QAC1B;AAAA,QACA,cAAc;AAAA,QACd,EAAE,eAAe,SAAS,CAAC,EAAE;AAAA,MAC/B;AAEA,sBAAgB;AAAA,QACd,GAAG;AAAA,QACH,SAAS,oBAAoB;AAAA,MAC/B;AAAA,IACF;AAEA,UAAM,gBAAgB,wBAAwB,eAAe,aAAa;AAE1E,QAAI,cAAc,YAAY,cAAc,QAAQ,UAAU;AAC5D,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA,cAAc,YAAY,cAAc,QAAQ;AAAA,QAChD;AAAA,QACA,CAAC,YAAY;AAAA,QACb;AAAA,MACF;AAAA,IACF,OAAO;AACL,YAAM;AAAA,QACJ,EAAE,GAAG,eAAe,SAAS,cAAc,QAAQ;AAAA,QACnD;AAAA,QACA,cAAc;AAAA,MAChB;AAEA,UAAI,cAAc,UAAU;AAC1B;AAAA,UACE,4BAA4B,YAAY,aAAa,CAAC,gBAAgB,WAAW,cAAc,QAAQ,CAAC;AAAA,UACxG;AAAA,YACE,OAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,10 +1,11 @@
1
1
  export * from "./build.mjs";
2
2
  export * from "./cli.mjs";
3
- export * from "./fill.mjs";
3
+ export * from "./fill/index.mjs";
4
4
  export * from "./listContentDeclaration.mjs";
5
5
  export * from "./pull.mjs";
6
6
  export * from "./push.mjs";
7
7
  export * from "./pushConfig.mjs";
8
8
  export * from "./reviewDoc.mjs";
9
+ export * from "./test/index.mjs";
9
10
  export * from "./translateDoc.mjs";
10
11
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type * from '@intlayer/chokidar';\nexport * from './build';\nexport * from './cli';\nexport * from './fill';\nexport * from './listContentDeclaration';\nexport * from './pull';\nexport * from './push';\nexport * from './pushConfig';\nexport * from './reviewDoc';\nexport * from './translateDoc';\n"],"mappings":"AACA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type * from '@intlayer/chokidar';\nexport * from './build';\nexport * from './cli';\nexport * from './fill';\nexport * from './listContentDeclaration';\nexport * from './pull';\nexport * from './push';\nexport * from './pushConfig';\nexport * from './reviewDoc';\nexport * from './test';\nexport * from './translateDoc';\n"],"mappings":"AACA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1,28 +1,49 @@
1
+ import { formatPath } from "@intlayer/chokidar";
1
2
  import {
3
+ colon,
4
+ colorizeKey,
5
+ colorizeNumber,
2
6
  getAppLogger,
3
7
  getConfiguration
4
8
  } from "@intlayer/config";
5
- import fg from "fast-glob";
6
- const getContentDeclaration = (options) => {
7
- const {
8
- content: { watchedFilesPatternWithPath }
9
- } = getConfiguration(options?.configOptions);
10
- const contentDeclarationFilesPath = fg.sync(
11
- watchedFilesPatternWithPath,
12
- {
13
- ignore: options?.exclude
14
- }
15
- );
16
- return contentDeclarationFilesPath;
9
+ import unmergedDictionariesRecord from "@intlayer/unmerged-dictionaries-entry";
10
+ import { relative } from "path";
11
+ const listContentDeclarationRows = (options) => {
12
+ const config = getConfiguration(options?.configOptions);
13
+ const rows = Object.values(unmergedDictionariesRecord).flat().map((dictionary) => ({
14
+ key: dictionary.key ?? "",
15
+ path: relative(config.content.baseDir, dictionary.filePath ?? "Remote")
16
+ }));
17
+ return rows;
17
18
  };
18
19
  const listContentDeclaration = (options) => {
19
- const contentDeclarationFilesPath = getContentDeclaration(options);
20
20
  const config = getConfiguration(options?.configOptions);
21
- const appLogger = getAppLogger(config);
22
- appLogger([contentDeclarationFilesPath]);
21
+ const appLogger = getAppLogger(config, {
22
+ config: {
23
+ prefix: ""
24
+ }
25
+ });
26
+ const rows = listContentDeclarationRows(options);
27
+ const lines = rows.map(
28
+ (r) => [
29
+ colon(` - ${colorizeKey(r.key)}`, {
30
+ colSize: rows.map((r2) => r2.key.length),
31
+ maxSize: 60
32
+ }),
33
+ " - ",
34
+ formatPath(r.path)
35
+ ].join("")
36
+ );
37
+ appLogger(`Content declaration files:`);
38
+ lines.forEach((l) => {
39
+ appLogger(l, {
40
+ level: "info"
41
+ });
42
+ });
43
+ appLogger(`Total content declaration files: ${colorizeNumber(rows.length)}`);
23
44
  };
24
45
  export {
25
- getContentDeclaration,
26
- listContentDeclaration
46
+ listContentDeclaration,
47
+ listContentDeclarationRows
27
48
  };
28
49
  //# sourceMappingURL=listContentDeclaration.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/listContentDeclaration.ts"],"sourcesContent":["import {\n getAppLogger,\n getConfiguration,\n type GetConfigurationOptions,\n} from '@intlayer/config';\nimport fg from 'fast-glob';\n\ntype GetContentDeclarationOptions = {\n exclude?: string[];\n configOptions?: GetConfigurationOptions;\n};\n\nexport const getContentDeclaration = (\n options?: GetContentDeclarationOptions\n): string[] => {\n const {\n content: { watchedFilesPatternWithPath },\n } = getConfiguration(options?.configOptions);\n\n const contentDeclarationFilesPath: string[] = fg.sync(\n watchedFilesPatternWithPath,\n {\n ignore: options?.exclude,\n }\n );\n\n return contentDeclarationFilesPath;\n};\n\ntype ListContentDeclarationOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const listContentDeclaration = (\n options?: ListContentDeclarationOptions\n) => {\n const contentDeclarationFilesPath = getContentDeclaration(options);\n\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n appLogger([contentDeclarationFilesPath]);\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,OAAO,QAAQ;AAOR,MAAM,wBAAwB,CACnC,YACa;AACb,QAAM;AAAA,IACJ,SAAS,EAAE,4BAA4B;AAAA,EACzC,IAAI,iBAAiB,SAAS,aAAa;AAE3C,QAAM,8BAAwC,GAAG;AAAA,IAC/C;AAAA,IACA;AAAA,MACE,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF;AAEA,SAAO;AACT;AAMO,MAAM,yBAAyB,CACpC,YACG;AACH,QAAM,8BAA8B,sBAAsB,OAAO;AAEjE,QAAM,SAAS,iBAAiB,SAAS,aAAa;AACtD,QAAM,YAAY,aAAa,MAAM;AAErC,YAAU,CAAC,2BAA2B,CAAC;AACzC;","names":[]}
1
+ {"version":3,"sources":["../../src/listContentDeclaration.ts"],"sourcesContent":["import { formatPath } from '@intlayer/chokidar';\nimport {\n colon,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n type GetConfigurationOptions,\n} from '@intlayer/config';\nimport unmergedDictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\nimport { relative } from 'path';\n\ntype ListContentDeclarationOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const listContentDeclarationRows = (\n options?: ListContentDeclarationOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n\n const rows = Object.values(unmergedDictionariesRecord)\n .flat()\n .map((dictionary) => ({\n key: dictionary.key ?? '',\n path: relative(config.content.baseDir, dictionary.filePath ?? 'Remote'),\n }));\n return rows;\n};\n\nexport const listContentDeclaration = (\n options?: ListContentDeclarationOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n const rows = listContentDeclarationRows(options);\n\n const lines = rows.map((r) =>\n [\n colon(` - ${colorizeKey(r.key)}`, {\n colSize: rows.map((r) => r.key.length),\n maxSize: 60,\n }),\n ' - ',\n formatPath(r.path),\n ].join('')\n );\n\n appLogger(`Content declaration files:`);\n\n lines.forEach((l) => {\n appLogger(l, {\n level: 'info',\n });\n });\n\n appLogger(`Total content declaration files: ${colorizeNumber(rows.length)}`);\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,OAAO,gCAAgC;AACvC,SAAS,gBAAgB;AAMlB,MAAM,6BAA6B,CACxC,YACG;AACH,QAAM,SAAS,iBAAiB,SAAS,aAAa;AAEtD,QAAM,OAAO,OAAO,OAAO,0BAA0B,EAClD,KAAK,EACL,IAAI,CAAC,gBAAgB;AAAA,IACpB,KAAK,WAAW,OAAO;AAAA,IACvB,MAAM,SAAS,OAAO,QAAQ,SAAS,WAAW,YAAY,QAAQ;AAAA,EACxE,EAAE;AACJ,SAAO;AACT;AAEO,MAAM,yBAAyB,CACpC,YACG;AACH,QAAM,SAAS,iBAAiB,SAAS,aAAa;AACtD,QAAM,YAAY,aAAa,QAAQ;AAAA,IACrC,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,OAAO,2BAA2B,OAAO;AAE/C,QAAM,QAAQ,KAAK;AAAA,IAAI,CAAC,MACtB;AAAA,MACE,MAAM,MAAM,YAAY,EAAE,GAAG,CAAC,IAAI;AAAA,QAChC,SAAS,KAAK,IAAI,CAACA,OAAMA,GAAE,IAAI,MAAM;AAAA,QACrC,SAAS;AAAA,MACX,CAAC;AAAA,MACD;AAAA,MACA,WAAW,EAAE,IAAI;AAAA,IACnB,EAAE,KAAK,EAAE;AAAA,EACX;AAEA,YAAU,4BAA4B;AAEtC,QAAM,QAAQ,CAAC,MAAM;AACnB,cAAU,GAAG;AAAA,MACX,OAAO;AAAA,IACT,CAAC;AAAA,EACH,CAAC;AAED,YAAU,oCAAoC,eAAe,KAAK,MAAM,CAAC,EAAE;AAC7E;","names":["r"]}
@@ -0,0 +1,220 @@
1
+ import { IntlayerEventListener } from "./IntlayerEventListener.mjs";
2
+ import { buildDictionary } from "@intlayer/chokidar";
3
+ import { getAppLogger, getConfiguration } from "@intlayer/config";
4
+ import packageJson from "@intlayer/config/package.json";
5
+ import { getLocalisedContent } from "@intlayer/core";
6
+ import { getDictionaries } from "@intlayer/dictionaries-entry";
7
+ import { getUnmergedDictionaries } from "@intlayer/unmerged-dictionaries-entry";
8
+ import { spawn } from "child_process";
9
+ import { createServer } from "http";
10
+ const writeDictionary = async (dictionary, configuration) => {
11
+ const appLogger = getAppLogger(configuration);
12
+ appLogger(`Writing dictionary ${dictionary.key}`);
13
+ await buildDictionary([dictionary], configuration);
14
+ };
15
+ const liveSync = async (options) => {
16
+ const configuration = getConfiguration();
17
+ const appLogger = getAppLogger(configuration, {
18
+ config: {
19
+ prefix: ""
20
+ }
21
+ });
22
+ const { liveSyncPort, liveSyncURL } = configuration.editor;
23
+ let childProcess = null;
24
+ let eventListener = null;
25
+ let isHotReloadConnected = false;
26
+ let connectionStatus = "disconnected";
27
+ if (options?.process) {
28
+ const [command, ...args] = options.process.split(" ");
29
+ childProcess = spawn(command, args, {
30
+ stdio: "inherit",
31
+ shell: true
32
+ });
33
+ childProcess.on("error", (error) => {
34
+ appLogger(`Failed to start process '${options.process}':`, {
35
+ level: "error"
36
+ });
37
+ });
38
+ childProcess.on("exit", (code) => {
39
+ if (code !== 0) {
40
+ appLogger(`Process "${options.process}" exited with code ${code}`);
41
+ } else {
42
+ appLogger(`Process "${options.process}" exited successfully`);
43
+ }
44
+ });
45
+ }
46
+ if (configuration.editor.liveSync && configuration.editor.backendURL && configuration.editor.clientId && configuration.editor.clientSecret) {
47
+ eventListener = new IntlayerEventListener(configuration);
48
+ connectionStatus = "connecting";
49
+ eventListener.onConnectionOpen = () => {
50
+ connectionStatus = "connected";
51
+ isHotReloadConnected = true;
52
+ appLogger("Live sync connection established");
53
+ };
54
+ eventListener.onConnectionError = (error) => {
55
+ connectionStatus = "error";
56
+ isHotReloadConnected = false;
57
+ const errorEvent = error;
58
+ appLogger(
59
+ `Live sync connection error: ${errorEvent.message ?? "Unknown error"}`,
60
+ {
61
+ level: "warn"
62
+ }
63
+ );
64
+ if (errorEvent.message?.includes("terminated") || errorEvent.message?.includes("closed")) {
65
+ appLogger(
66
+ "Server connection was terminated, automatic reconnection will be attempted...",
67
+ {
68
+ level: "info"
69
+ }
70
+ );
71
+ connectionStatus = "reconnecting";
72
+ }
73
+ };
74
+ eventListener.onDictionaryAdded = (dictionary) => writeDictionary(dictionary, configuration);
75
+ eventListener.onDictionaryChange = (dictionary) => writeDictionary(dictionary, configuration);
76
+ eventListener.onDictionaryDeleted = (dictionary) => writeDictionary(dictionary, configuration);
77
+ try {
78
+ await eventListener.initialize();
79
+ } catch (error) {
80
+ connectionStatus = "error";
81
+ isHotReloadConnected = false;
82
+ appLogger("Failed to initialize IntlayerEventListener:", {
83
+ level: "error"
84
+ });
85
+ appLogger(
86
+ `Error: ${error instanceof Error ? error.message : String(error)}`,
87
+ {
88
+ level: "error"
89
+ }
90
+ );
91
+ }
92
+ } else if (!configuration.editor.liveSync) {
93
+ appLogger(
94
+ "Hot reload is disabled. Please enable it in the configuration (editor.liveSync)."
95
+ );
96
+ } else if (!configuration.editor.clientId || !configuration.editor.clientSecret) {
97
+ appLogger(
98
+ "Missing client credentials for hot reload. Please configure clientId and clientSecret"
99
+ );
100
+ }
101
+ const server = createServer(async (req, res) => {
102
+ if (req.method === "OPTIONS") {
103
+ res.writeHead(200, {
104
+ "Access-Control-Allow-Origin": "*",
105
+ "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
106
+ "Access-Control-Allow-Headers": "Content-Type, Authorization"
107
+ });
108
+ res.end();
109
+ return;
110
+ }
111
+ if (req.url?.startsWith("/dictionaries")) {
112
+ res.writeHead(200, {
113
+ "Content-Type": "application/json; charset=utf-8",
114
+ "Cache-Control": "no-store",
115
+ "Access-Control-Allow-Origin": "*",
116
+ "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
117
+ "Access-Control-Allow-Headers": "Content-Type, Authorization"
118
+ });
119
+ const dictionaries = getDictionaries();
120
+ const prefix = "/dictionaries/";
121
+ if (req.url.startsWith(prefix)) {
122
+ const [key, locale] = decodeURIComponent(req.url).slice(prefix.length).split("/");
123
+ const dictionary = dictionaries[key] ?? null;
124
+ if (locale) {
125
+ const sourceLocaleContent = getLocalisedContent(dictionary, locale, {
126
+ dictionaryKey: key,
127
+ keyPath: []
128
+ });
129
+ res.end(JSON.stringify(sourceLocaleContent));
130
+ return;
131
+ }
132
+ res.end(JSON.stringify(dictionary));
133
+ return;
134
+ }
135
+ res.end(JSON.stringify(dictionaries));
136
+ return;
137
+ }
138
+ if (req.url?.startsWith("/unmerged_dictionaries")) {
139
+ res.writeHead(200, {
140
+ "Content-Type": "application/json; charset=utf-8",
141
+ "Cache-Control": "no-store",
142
+ "Access-Control-Allow-Origin": "*",
143
+ "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
144
+ "Access-Control-Allow-Headers": "Content-Type, Authorization"
145
+ });
146
+ const unmergedDictionaries = getUnmergedDictionaries();
147
+ const prefix = "/unmerged_dictionaries/";
148
+ if (req.url.startsWith(prefix)) {
149
+ const key = decodeURIComponent(req.url.slice(prefix.length));
150
+ const one = unmergedDictionaries[key] ?? null;
151
+ res.end(JSON.stringify(one));
152
+ return;
153
+ }
154
+ res.end(JSON.stringify(unmergedDictionaries));
155
+ return;
156
+ }
157
+ if (req.url === "/configuration") {
158
+ res.writeHead(200, {
159
+ "Content-Type": "application/json; charset=utf-8",
160
+ "Cache-Control": "no-store",
161
+ "Access-Control-Allow-Origin": "*",
162
+ "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
163
+ "Access-Control-Allow-Headers": "Content-Type, Authorization"
164
+ });
165
+ res.end(JSON.stringify(configuration));
166
+ return;
167
+ }
168
+ if (req.url === "/health") {
169
+ res.writeHead(200, {
170
+ "Content-Type": "application/json; charset=utf-8"
171
+ });
172
+ res.end(JSON.stringify({ status: "ok" }));
173
+ return;
174
+ }
175
+ res.end("Not found");
176
+ return;
177
+ });
178
+ const getLiveSyncParam = () => {
179
+ if (!configuration.editor.liveSync) return "\x1B[31m\u2717 Disabled\x1B[0m";
180
+ return "\x1B[32m\u2713 Enabled\x1B[0m";
181
+ };
182
+ server.listen(liveSyncPort, () => {
183
+ console.log(`
184
+ \x1B[1;90mINTLAYER v${packageJson.version}\x1B[0m
185
+
186
+ Live server running at: \x1B[90m${liveSyncURL}\x1B[0m
187
+ - Backend URL: \x1B[90m${configuration.editor.backendURL ?? "-"}\x1B[0m
188
+ - Live sync: ${getLiveSyncParam()}
189
+ - Parallel process: ${options?.process === "" ? "-" : `\x1B[90m${options?.process}\x1B[0m`}
190
+ - Access key: ${configuration.editor.clientId ?? "-"}
191
+ `);
192
+ });
193
+ const cleanup = () => {
194
+ if (eventListener) {
195
+ appLogger("Closing SSE connection...");
196
+ eventListener.cleanup();
197
+ }
198
+ if (childProcess && !childProcess.killed) {
199
+ appLogger("Terminating parallel process...");
200
+ childProcess.kill("SIGTERM");
201
+ setTimeout(() => {
202
+ if (childProcess && !childProcess.killed) {
203
+ appLogger("Force killing parallel process...");
204
+ childProcess.kill("SIGKILL");
205
+ }
206
+ }, 5e3);
207
+ }
208
+ server.close(() => {
209
+ appLogger("Live sync server stopped");
210
+ process.exit(0);
211
+ });
212
+ };
213
+ process.on("SIGINT", cleanup);
214
+ process.on("SIGTERM", cleanup);
215
+ process.on("exit", cleanup);
216
+ };
217
+ export {
218
+ liveSync
219
+ };
220
+ //# sourceMappingURL=liveSync.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/liveSync.ts"],"sourcesContent":["import { IntlayerEventListener } from './IntlayerEventListener';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport { buildDictionary } from '@intlayer/chokidar';\nimport type { IntlayerConfig } from '@intlayer/config';\nimport { getAppLogger, getConfiguration } from '@intlayer/config';\nimport packageJson from '@intlayer/config/package.json';\nimport { getLocalisedContent } from '@intlayer/core';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport { ChildProcess, spawn } from 'child_process';\nimport { createServer } from 'http';\n\ntype LiveSyncOptions = {\n process?: string;\n};\n\nconst writeDictionary = async (\n dictionary: DictionaryAPI,\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n appLogger(`Writing dictionary ${dictionary.key}`);\n await buildDictionary([dictionary], configuration);\n};\n\nexport const liveSync = async (options?: LiveSyncOptions) => {\n const configuration = getConfiguration();\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const { liveSyncPort, liveSyncURL } = configuration.editor;\n\n let childProcess: ChildProcess | null = null;\n let eventListener: IntlayerEventListener | null = null;\n let isHotReloadConnected = false;\n let connectionStatus = 'disconnected'; // 'connected', 'connecting', 'reconnecting', 'disconnected', 'error'\n\n // Start the parallel process if provided\n if (options?.process) {\n const [command, ...args] = options.process.split(' ');\n\n childProcess = spawn(command, args, {\n stdio: 'inherit',\n shell: true,\n });\n\n childProcess.on('error', (error) => {\n appLogger(`Failed to start process '${options.process}':`, {\n level: 'error',\n });\n });\n\n childProcess.on('exit', (code) => {\n if (code !== 0) {\n appLogger(`Process \"${options.process}\" exited with code ${code}`);\n } else {\n appLogger(`Process \"${options.process}\" exited successfully`);\n }\n });\n }\n\n // Initialize the event listener for hot reload if configured\n if (\n configuration.editor.liveSync &&\n configuration.editor.backendURL &&\n configuration.editor.clientId &&\n configuration.editor.clientSecret\n ) {\n eventListener = new IntlayerEventListener(configuration);\n connectionStatus = 'connecting';\n\n // Set up connection callbacks\n eventListener.onConnectionOpen = () => {\n connectionStatus = 'connected';\n isHotReloadConnected = true;\n appLogger('Live sync connection established');\n };\n\n eventListener.onConnectionError = (error) => {\n connectionStatus = 'error';\n isHotReloadConnected = false;\n const errorEvent = error as any;\n appLogger(\n `Live sync connection error: ${errorEvent.message ?? 'Unknown error'}`,\n {\n level: 'warn',\n }\n );\n\n // If this is a \"terminated: other side closed\" error, it's likely a server restart\n if (\n errorEvent.message?.includes('terminated') ||\n errorEvent.message?.includes('closed')\n ) {\n appLogger(\n 'Server connection was terminated, automatic reconnection will be attempted...',\n {\n level: 'info',\n }\n );\n connectionStatus = 'reconnecting';\n }\n };\n\n // Set up dictionary change callbacks\n eventListener.onDictionaryAdded = (dictionary) =>\n writeDictionary(dictionary, configuration);\n eventListener.onDictionaryChange = (dictionary) =>\n writeDictionary(dictionary, configuration);\n eventListener.onDictionaryDeleted = (dictionary) =>\n writeDictionary(dictionary, configuration);\n\n try {\n await eventListener.initialize();\n } catch (error) {\n connectionStatus = 'error';\n isHotReloadConnected = false;\n appLogger('Failed to initialize IntlayerEventListener:', {\n level: 'error',\n });\n appLogger(\n `Error: ${error instanceof Error ? error.message : String(error)}`,\n {\n level: 'error',\n }\n );\n }\n } else if (!configuration.editor.liveSync) {\n appLogger(\n 'Hot reload is disabled. Please enable it in the configuration (editor.liveSync).'\n );\n } else if (\n !configuration.editor.clientId ||\n !configuration.editor.clientSecret\n ) {\n appLogger(\n 'Missing client credentials for hot reload. Please configure clientId and clientSecret'\n );\n }\n\n const server = createServer(async (req, res) => {\n // Handle CORS preflight requests\n if (req.method === 'OPTIONS') {\n res.writeHead(200, {\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n\n res.end();\n return;\n }\n\n if (req.url?.startsWith('/dictionaries')) {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Cache-Control': 'no-store',\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n const dictionaries = getDictionaries();\n\n const prefix = '/dictionaries/';\n if (req.url.startsWith(prefix)) {\n const [key, locale] = decodeURIComponent(req.url)\n .slice(prefix.length)\n .split('/');\n\n const dictionary = dictionaries[key] ?? null;\n\n if (locale) {\n const sourceLocaleContent = getLocalisedContent(dictionary, locale, {\n dictionaryKey: key,\n keyPath: [],\n });\n\n res.end(JSON.stringify(sourceLocaleContent));\n return;\n }\n\n res.end(JSON.stringify(dictionary));\n return;\n }\n\n res.end(JSON.stringify(dictionaries));\n return;\n }\n\n if (req.url?.startsWith('/unmerged_dictionaries')) {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Cache-Control': 'no-store',\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n const unmergedDictionaries = getUnmergedDictionaries();\n\n const prefix = '/unmerged_dictionaries/';\n if (req.url.startsWith(prefix)) {\n const key = decodeURIComponent(req.url.slice(prefix.length));\n const one = unmergedDictionaries[key] ?? null;\n\n res.end(JSON.stringify(one));\n return;\n }\n\n res.end(JSON.stringify(unmergedDictionaries));\n return;\n }\n\n if (req.url === '/configuration') {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Cache-Control': 'no-store',\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',\n 'Access-Control-Allow-Headers': 'Content-Type, Authorization',\n });\n res.end(JSON.stringify(configuration));\n return;\n }\n\n if (req.url === '/health') {\n res.writeHead(200, {\n 'Content-Type': 'application/json; charset=utf-8',\n });\n res.end(JSON.stringify({ status: 'ok' }));\n return;\n }\n\n res.end('Not found');\n return;\n });\n\n const getLiveSyncParam = () => {\n if (!configuration.editor.liveSync) return '\\x1b[31m✗ Disabled\\x1b[0m';\n\n return '\\x1b[32m✓ Enabled\\x1b[0m';\n };\n server.listen(liveSyncPort, () => {\n console.log(`\n \\x1b[1;90mINTLAYER v${packageJson.version}\\x1b[0m\n \n Live server running at: \\x1b[90m${liveSyncURL}\\x1b[0m\n - Backend URL: \\x1b[90m${configuration.editor.backendURL ?? '-'}\\x1b[0m\n - Live sync: ${getLiveSyncParam()}\n - Parallel process: ${options?.process === '' ? '-' : `\\x1b[90m${options?.process}\\x1b[0m`}\n - Access key: ${configuration.editor.clientId ?? '-'}\n `);\n });\n\n // Cleanup function to terminate child process and event listener when the main process exits\n const cleanup = () => {\n // Clean up event listener\n if (eventListener) {\n appLogger('Closing SSE connection...');\n eventListener.cleanup();\n }\n\n // Clean up child process\n if (childProcess && !childProcess.killed) {\n appLogger('Terminating parallel process...');\n childProcess.kill('SIGTERM');\n\n // Force kill after 5 seconds if process doesn't terminate gracefully\n setTimeout(() => {\n if (childProcess && !childProcess.killed) {\n appLogger('Force killing parallel process...');\n childProcess.kill('SIGKILL');\n }\n }, 5000);\n }\n\n server.close(() => {\n appLogger('Live sync server stopped');\n process.exit(0);\n });\n };\n\n // Handle process termination signals\n process.on('SIGINT', cleanup);\n process.on('SIGTERM', cleanup);\n process.on('exit', cleanup);\n};\n"],"mappings":"AAAA,SAAS,6BAA6B;AAGtC,SAAS,uBAAuB;AAEhC,SAAS,cAAc,wBAAwB;AAC/C,OAAO,iBAAiB;AACxB,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;AAChC,SAAS,+BAA+B;AACxC,SAAuB,aAAa;AACpC,SAAS,oBAAoB;AAM7B,MAAM,kBAAkB,OACtB,YACA,kBACG;AACH,QAAM,YAAY,aAAa,aAAa;AAC5C,YAAU,sBAAsB,WAAW,GAAG,EAAE;AAChD,QAAM,gBAAgB,CAAC,UAAU,GAAG,aAAa;AACnD;AAEO,MAAM,WAAW,OAAO,YAA8B;AAC3D,QAAM,gBAAgB,iBAAiB;AACvC,QAAM,YAAY,aAAa,eAAe;AAAA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