@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,108 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var formatAutoFillData_exports = {};
20
+ __export(formatAutoFillData_exports, {
21
+ formatAutoFillData: () => formatAutoFillData
22
+ });
23
+ module.exports = __toCommonJS(formatAutoFillData_exports);
24
+ var import_path = require("path");
25
+ var import_formatAutoFilledFilePath = require('./formatAutoFilledFilePath.cjs');
26
+ const formatAutoFillData = (autoFillField, localeList, filePath, dictionaryKey, configuration) => {
27
+ const outputContentDeclarationFile = [];
28
+ const baseDir = configuration.content.baseDir;
29
+ if (!Boolean(autoFillField)) return outputContentDeclarationFile;
30
+ if (autoFillField === true) {
31
+ let jsonFilePath = filePath.replace((0, import_path.extname)(filePath), ".json");
32
+ if (filePath === jsonFilePath) {
33
+ jsonFilePath = jsonFilePath.replace((0, import_path.extname)(jsonFilePath), ".fill.json");
34
+ }
35
+ outputContentDeclarationFile.push({
36
+ localeList,
37
+ filePath: jsonFilePath,
38
+ isPerLocale: false
39
+ });
40
+ }
41
+ if (typeof autoFillField === "string") {
42
+ if (autoFillField.includes("{{locale}}")) {
43
+ const output = localeList.map((locale) => {
44
+ const formattedFilePath = (0, import_formatAutoFilledFilePath.formatAutoFilledFilePath)(
45
+ autoFillField,
46
+ dictionaryKey,
47
+ filePath,
48
+ baseDir,
49
+ locale
50
+ );
51
+ return {
52
+ localeList: [locale],
53
+ filePath: formattedFilePath,
54
+ isPerLocale: true
55
+ };
56
+ });
57
+ outputContentDeclarationFile.push(...output);
58
+ } else {
59
+ const formattedFilePath = (0, import_formatAutoFilledFilePath.formatAutoFilledFilePath)(
60
+ autoFillField,
61
+ dictionaryKey,
62
+ filePath,
63
+ baseDir
64
+ );
65
+ outputContentDeclarationFile.push({
66
+ localeList,
67
+ filePath: formattedFilePath,
68
+ isPerLocale: false
69
+ });
70
+ }
71
+ return outputContentDeclarationFile;
72
+ }
73
+ if (typeof autoFillField === "object") {
74
+ const localeList2 = Object.keys(autoFillField).filter(
75
+ (locale) => typeof autoFillField[locale] === "string"
76
+ );
77
+ const output = localeList2.filter((locale) => Boolean(autoFillField[locale])).map((locale) => {
78
+ const formattedFilePath = (0, import_formatAutoFilledFilePath.formatAutoFilledFilePath)(
79
+ autoFillField[locale],
80
+ dictionaryKey,
81
+ filePath,
82
+ baseDir,
83
+ locale
84
+ );
85
+ return {
86
+ localeList: [locale],
87
+ filePath: formattedFilePath,
88
+ isPerLocale: true
89
+ };
90
+ });
91
+ const groupedByFilePath = output.reduce((acc, curr) => {
92
+ const existing = acc.find((item) => item.filePath === curr.filePath);
93
+ if (existing) {
94
+ existing.localeList.push(...curr.localeList);
95
+ } else {
96
+ acc.push(curr);
97
+ }
98
+ return acc;
99
+ }, []);
100
+ outputContentDeclarationFile.push(...groupedByFilePath);
101
+ }
102
+ return outputContentDeclarationFile;
103
+ };
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ formatAutoFillData
107
+ });
108
+ //# sourceMappingURL=formatAutoFillData.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/fill/formatAutoFillData.ts"],"sourcesContent":["import { type IntlayerConfig, Locales } from '@intlayer/config';\nimport { type AutoFill } from '@intlayer/core';\nimport { extname } from 'path';\nimport { formatAutoFilledFilePath } from './formatAutoFilledFilePath';\n\nexport type AutoFillData = {\n localeList: Locales[];\n filePath: string;\n isPerLocale: boolean;\n};\n\nexport const formatAutoFillData = (\n autoFillField: AutoFill,\n localeList: Locales[],\n filePath: string,\n dictionaryKey: string,\n configuration: IntlayerConfig\n): AutoFillData[] => {\n const outputContentDeclarationFile: AutoFillData[] = [];\n\n const baseDir = configuration.content.baseDir;\n\n if (!Boolean(autoFillField)) return outputContentDeclarationFile;\n\n if (autoFillField === true) {\n // wanted jsonFilePath: /..../src/components/home/index.content.json\n // replace file extension in json\n let jsonFilePath = filePath.replace(extname(filePath), '.json');\n\n // if both filePath jsonFilePath are same path, change it as : /..../src/components/home/index.fill.content.json\n if (filePath === jsonFilePath) {\n jsonFilePath = jsonFilePath.replace(extname(jsonFilePath), '.fill.json');\n }\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: jsonFilePath,\n isPerLocale: false,\n });\n }\n\n if (typeof autoFillField === 'string') {\n if (autoFillField.includes('{{locale}}')) {\n const output = localeList.map((locale) => {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField,\n dictionaryKey,\n filePath,\n baseDir,\n locale\n );\n\n return {\n localeList: [locale],\n filePath: formattedFilePath,\n isPerLocale: true,\n };\n });\n\n outputContentDeclarationFile.push(...output);\n } else {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField,\n dictionaryKey,\n filePath,\n baseDir\n );\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: formattedFilePath,\n isPerLocale: false,\n });\n }\n\n return outputContentDeclarationFile;\n }\n\n if (typeof autoFillField === 'object') {\n const localeList = Object.keys(autoFillField).filter(\n (locale) => typeof autoFillField[locale] === 'string'\n ) as Locales[];\n\n const output: AutoFillData[] = localeList\n .filter((locale) => Boolean(autoFillField[locale]))\n .map((locale) => {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField[locale],\n dictionaryKey,\n filePath,\n baseDir,\n locale\n );\n\n return {\n localeList: [locale],\n filePath: formattedFilePath,\n isPerLocale: true,\n };\n });\n\n // Group by filePath and merge localeList\n const groupedByFilePath = output.reduce((acc, curr) => {\n const existing = acc.find((item) => item.filePath === curr.filePath);\n if (existing) {\n existing.localeList.push(...curr.localeList);\n } else {\n acc.push(curr);\n }\n return acc;\n }, [] as AutoFillData[]);\n\n outputContentDeclarationFile.push(...groupedByFilePath);\n }\n\n return outputContentDeclarationFile;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAwB;AACxB,sCAAyC;AAQlC,MAAM,qBAAqB,CAChC,eACA,YACA,UACA,eACA,kBACmB;AACnB,QAAM,+BAA+C,CAAC;AAEtD,QAAM,UAAU,cAAc,QAAQ;AAEtC,MAAI,CAAC,QAAQ,aAAa,EAAG,QAAO;AAEpC,MAAI,kBAAkB,MAAM;AAG1B,QAAI,eAAe,SAAS,YAAQ,qBAAQ,QAAQ,GAAG,OAAO;AAG9D,QAAI,aAAa,cAAc;AAC7B,qBAAe,aAAa,YAAQ,qBAAQ,YAAY,GAAG,YAAY;AAAA,IACzE;AAEA,iCAA6B,KAAK;AAAA,MAChC;AAAA,MACA,UAAU;AAAA,MACV,aAAa;AAAA,IACf,CAAC;AAAA,EACH;AAEA,MAAI,OAAO,kBAAkB,UAAU;AACrC,QAAI,cAAc,SAAS,YAAY,GAAG;AACxC,YAAM,SAAS,WAAW,IAAI,CAAC,WAAW;AACxC,cAAM,wBA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 "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var formatAutoFilledFilePath_exports = {};
20
+ __export(formatAutoFilledFilePath_exports, {
21
+ formatAutoFilledFilePath: () => formatAutoFilledFilePath
22
+ });
23
+ module.exports = __toCommonJS(formatAutoFilledFilePath_exports);
24
+ var import_path = require("path");
25
+ const transformUriToAbsolutePath = (uri, filePath, baseDir) => {
26
+ if (uri.startsWith("/")) {
27
+ return (0, import_path.join)(baseDir, uri);
28
+ }
29
+ if (uri.startsWith("./")) {
30
+ return (0, import_path.join)((0, import_path.dirname)(filePath), uri);
31
+ }
32
+ return filePath;
33
+ };
34
+ const formatAutoFilledFilePath = (autoFillField, dictionaryKey, dictionaryFilePath, baseDir, locale) => {
35
+ const fileName = (0, import_path.basename)(dictionaryFilePath).split(".").slice(0, -2).join(".");
36
+ let result = autoFillField.replace("{{key}}", dictionaryKey).replace("{{fileName}}", fileName);
37
+ if (locale) {
38
+ result = result.replace("{{locale}}", locale);
39
+ }
40
+ return transformUriToAbsolutePath(result, dictionaryFilePath, baseDir);
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ formatAutoFilledFilePath
45
+ });
46
+ //# sourceMappingURL=formatAutoFilledFilePath.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/fill/formatAutoFilledFilePath.ts"],"sourcesContent":["import { Locales } from '@intlayer/config';\nimport { basename, dirname, join } from 'path';\n\nconst transformUriToAbsolutePath = (\n uri: string,\n filePath: string,\n baseDir: string\n) => {\n if (uri.startsWith('/')) {\n return join(baseDir, uri);\n }\n\n if (uri.startsWith('./')) {\n return join(dirname(filePath), uri);\n }\n\n return filePath;\n};\n\nexport const formatAutoFilledFilePath = (\n autoFillField: string,\n dictionaryKey: string,\n dictionaryFilePath: string,\n baseDir: string,\n locale?: Locales\n) => {\n // transform `/src/components/home/index.content.json` to `index`\n // transform `./test.content.tsx` to `test`\n const fileName = basename(dictionaryFilePath)\n .split('.')\n .slice(0, -2) // Remove last 2 extensions (.content.tsx)\n .join('.');\n\n let result: string = autoFillField\n .replace('{{key}}', dictionaryKey)\n .replace('{{fileName}}', fileName);\n\n if (locale) {\n result = result.replace('{{locale}}', locale);\n }\n\n return transformUriToAbsolutePath(result, dictionaryFilePath, baseDir);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAwC;AAExC,MAAM,6BAA6B,CACjC,KACA,UACA,YACG;AACH,MAAI,IAAI,WAAW,GAAG,GAAG;AACvB,eAAO,kBAAK,SAAS,GAAG;AAAA,EAC1B;AAEA,MAAI,IAAI,WAAW,IAAI,GAAG;AACxB,eAAO,sBAAK,qBAAQ,QAAQ,GAAG,GAAG;AAAA,EACpC;AAEA,SAAO;AACT;AAEO,MAAM,2BAA2B,CACtC,eACA,eACA,oBACA,SACA,WACG;AAGH,QAAM,eAAW,sBAAS,kBAAkB,EACzC,MAAM,GAAG,EACT,MAAM,GAAG,EAAE,EACX,KAAK,GAAG;AAEX,MAAI,SAAiB,cAClB,QAAQ,WAAW,aAAa,EAChC,QAAQ,gBAAgB,QAAQ;AAEnC,MAAI,QAAQ;AACV,aAAS,OAAO,QAAQ,cAAc,MAAM;AAAA,EAC9C;AAEA,SAAO,2BAA2B,QAAQ,oBAAoB,OAAO;AACvE;","names":[]}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var getTargetDictionary_exports = {};
30
+ __export(getTargetDictionary_exports, {
31
+ ensureArray: () => ensureArray,
32
+ getTargetDictionary: () => getTargetDictionary
33
+ });
34
+ module.exports = __toCommonJS(getTargetDictionary_exports);
35
+ var import_chokidar = require("@intlayer/chokidar");
36
+ var import_config = require("@intlayer/config");
37
+ var import_unmerged_dictionaries_entry = __toESM(require("@intlayer/unmerged-dictionaries-entry"));
38
+ var import_path = require("path");
39
+ const ensureArray = (value) => [value].flat();
40
+ const getTargetDictionary = async (options) => {
41
+ const configuration = (0, import_config.getConfiguration)(options.configOptions);
42
+ const { baseDir } = configuration.content;
43
+ let result = Object.values(import_unmerged_dictionaries_entry.default).flat();
44
+ if (typeof options.file !== "undefined") {
45
+ const fileArray = ensureArray(options.file);
46
+ const absoluteFilePaths = fileArray.map((file) => (0, import_path.join)(baseDir, file));
47
+ result = result.filter(
48
+ (dict) => dict.filePath && (absoluteFilePaths.includes(dict.filePath) || absoluteFilePaths.includes((0, import_path.join)(baseDir, dict.filePath)))
49
+ );
50
+ }
51
+ if (typeof options.keys !== "undefined") {
52
+ result = result.filter(
53
+ (dict) => ensureArray(options.keys)?.includes(dict.key)
54
+ );
55
+ }
56
+ if (typeof options.excludedKeys !== "undefined") {
57
+ result = result.filter(
58
+ (dict) => !ensureArray(options.excludedKeys)?.includes(dict.key)
59
+ );
60
+ }
61
+ if (typeof options.pathFilter !== "undefined") {
62
+ result = result.filter(
63
+ (dict) => ensureArray(options.pathFilter)?.includes(dict.filePath ?? "")
64
+ );
65
+ }
66
+ if (typeof options.filter !== "undefined") {
67
+ result = result.filter(options.filter);
68
+ }
69
+ const gitOptions = options.gitOptions;
70
+ if (gitOptions) {
71
+ const gitChangedFiles = await (0, import_chokidar.listGitFiles)(gitOptions);
72
+ if (gitChangedFiles) {
73
+ result = result.filter((dict) => {
74
+ if (!dict.filePath) return false;
75
+ return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);
76
+ });
77
+ }
78
+ }
79
+ return result.filter((dict) => !dict.autoFilled);
80
+ };
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ ensureArray,
84
+ getTargetDictionary
85
+ });
86
+ //# sourceMappingURL=getTargetDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/fill/getTargetDictionary.ts"],"sourcesContent":["import { listGitFiles } from '@intlayer/chokidar';\nimport { getConfiguration } from '@intlayer/config';\nimport unmergedDictionariesRecord from '@intlayer/unmerged-dictionaries-entry';\nimport { join } from 'path';\nimport type { FillOptions } from './index';\n\nexport const ensureArray = <T>(value: T | T[]): T[] => [value].flat() as T[];\n\nexport const getTargetDictionary = async (options: FillOptions) => {\n const configuration = getConfiguration(options.configOptions);\n\n const { baseDir } = configuration.content;\n\n let result = Object.values(unmergedDictionariesRecord).flat();\n\n // 1. if filePath not defined, list all content declaration files based on unmerged dictionaries list\n if (typeof options.file !== 'undefined') {\n const fileArray = ensureArray(options.file);\n const absoluteFilePaths = fileArray.map((file) => join(baseDir, file));\n\n result = result.filter(\n (dict) =>\n dict.filePath &&\n (absoluteFilePaths.includes(dict.filePath) ||\n absoluteFilePaths.includes(join(baseDir, dict.filePath)))\n );\n }\n\n if (typeof options.keys !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.keys)?.includes(dict.key)\n );\n }\n\n if (typeof options.excludedKeys !== 'undefined') {\n result = result.filter(\n (dict) => !ensureArray(options.excludedKeys)?.includes(dict.key)\n );\n }\n\n if (typeof options.pathFilter !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options.pathFilter)?.includes(dict.filePath ?? '')\n );\n }\n\n if (typeof options.filter !== 'undefined') {\n result = result.filter(options.filter);\n }\n\n const gitOptions = options.gitOptions;\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n result = result.filter((dict) => {\n if (!dict.filePath) return false;\n\n return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);\n });\n }\n }\n\n return result.filter((dict) => !dict.autoFilled);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA6B;AAC7B,oBAAiC;AACjC,yCAAuC;AACvC,kBAAqB;AAGd,MAAM,cAAc,CAAI,UAAwB,CAAC,KAAK,EAAE,KAAK;AAE7D,MAAM,sBAAsB,OAAO,YAAyB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AAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO,OAAO,OAAO,CAAC,SAAS,CAAC,KAAK,UAAU;AACjD;","names":["unmergedDictionariesRecord"]}
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var fill_exports = {};
30
+ __export(fill_exports, {
31
+ fill: () => fill
32
+ });
33
+ module.exports = __toCommonJS(fill_exports);
34
+ var import_api = require("@intlayer/api");
35
+ var import_chokidar = require("@intlayer/chokidar");
36
+ var import_config = require("@intlayer/config");
37
+ var import_core = require("@intlayer/core");
38
+ var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
39
+ var import_p_limit = __toESM(require("p-limit"));
40
+ var import_path = require("path");
41
+ var import_checkAIAccess = require('../utils/checkAIAccess.cjs');
42
+ var import_autoFill = require('./autoFill.cjs');
43
+ var import_getTargetDictionary = require('./getTargetDictionary.cjs');
44
+ const NB_CONCURRENT_TRANSLATIONS = 8;
45
+ const fill = async (options) => {
46
+ const configuration = (0, import_config.getConfiguration)(options.configOptions);
47
+ const appLogger = (0, import_config.getAppLogger)(configuration, {
48
+ config: {
49
+ prefix: ""
50
+ }
51
+ });
52
+ if (options.build) {
53
+ await (0, import_chokidar.prepareIntlayer)(configuration);
54
+ }
55
+ const { defaultLocale, locales } = configuration.internationalization;
56
+ const mode = options.mode ?? "complete";
57
+ const baseLocale = options.sourceLocale ?? defaultLocale;
58
+ const outputLocales = (options.outputLocales ? (0, import_getTargetDictionary.ensureArray)(options.outputLocales) : locales).filter((locale) => locale !== baseLocale);
59
+ (0, import_checkAIAccess.checkAIAccess)(configuration, options.aiOptions);
60
+ let oAuth2AccessToken;
61
+ if (configuration.editor.clientId) {
62
+ const intlayerAuthAPI = (0, import_api.getOAuthAPI)(configuration);
63
+ const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();
64
+ oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
65
+ }
66
+ appLogger("Starting fill function", {
67
+ level: "info"
68
+ });
69
+ const targetUnmergedDictionaries = await (0, import_getTargetDictionary.getTargetDictionary)(options);
70
+ const affectedDictionaryKeys = /* @__PURE__ */ new Set();
71
+ targetUnmergedDictionaries.forEach((dict) => {
72
+ affectedDictionaryKeys.add(dict.key);
73
+ });
74
+ appLogger(
75
+ [
76
+ "Affected dictionary keys for processing:",
77
+ Array.from(affectedDictionaryKeys).map((key) => (0, import_config.colorizeKey)(key)).join(", ")
78
+ ],
79
+ {
80
+ isVerbose: true
81
+ }
82
+ );
83
+ for (const targetUnmergedDictionary of targetUnmergedDictionaries) {
84
+ const dictionaryKey = targetUnmergedDictionary.key;
85
+ const mainDictionaryToProcess = import_dictionaries_entry.default[dictionaryKey];
86
+ const sourceLocale = targetUnmergedDictionary.locale ?? baseLocale;
87
+ if (!mainDictionaryToProcess) {
88
+ appLogger(
89
+ `Dictionary with key '${(0, import_config.colorizeKey)(dictionaryKey)}' not found in dictionariesRecord. Skipping.`,
90
+ {
91
+ level: "warn"
92
+ }
93
+ );
94
+ continue;
95
+ }
96
+ if (!targetUnmergedDictionary.filePath) {
97
+ appLogger(
98
+ `Dictionary with key '${(0, import_config.colorizeKey)(dictionaryKey)}' has no file path. Skipping.`,
99
+ {
100
+ level: "warn"
101
+ }
102
+ );
103
+ continue;
104
+ }
105
+ const relativePath = (0, import_path.relative)(
106
+ configuration.content.baseDir,
107
+ targetUnmergedDictionary.filePath
108
+ );
109
+ appLogger(`Processing content declaration: ${(0, import_config.colorizePath)(relativePath)}`, {
110
+ level: "info"
111
+ });
112
+ const sourceLocaleContent = (0, import_core.getFilterTranslationsOnlyContent)(
113
+ mainDictionaryToProcess,
114
+ sourceLocale,
115
+ { dictionaryKey, keyPath: [] }
116
+ );
117
+ if (Object.keys(sourceLocaleContent).length === 0) {
118
+ appLogger(
119
+ `No content found for dictionary '${(0, import_config.colorizeKey)(dictionaryKey)}' in source locale ${(0, import_chokidar.formatLocale)(sourceLocale)}. Skipping translation for this dictionary.`,
120
+ {
121
+ level: "warn"
122
+ }
123
+ );
124
+ continue;
125
+ }
126
+ const result = [];
127
+ const limit = (0, import_p_limit.default)(
128
+ options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS
129
+ );
130
+ let outputLocalesList = outputLocales;
131
+ if (mode === "complete") {
132
+ const missingLocales = (0, import_core.getMissingLocalesContent)(
133
+ mainDictionaryToProcess,
134
+ outputLocales,
135
+ {
136
+ dictionaryKey: mainDictionaryToProcess.key,
137
+ keyPath: [],
138
+ plugins: []
139
+ }
140
+ );
141
+ outputLocalesList = missingLocales;
142
+ }
143
+ const translationPromises = outputLocalesList.map(
144
+ (targetLocale) => limit(async () => {
145
+ appLogger(
146
+ `Preparing translation for '${(0, import_config.colorizeKey)(dictionaryKey)}' dictionary from ${(0, import_chokidar.formatLocale)(sourceLocale)} to ${(0, import_chokidar.formatLocale)(targetLocale)}`,
147
+ {
148
+ level: "info"
149
+ }
150
+ );
151
+ const presetOutputContent = (0, import_core.getLocalisedContent)(
152
+ mainDictionaryToProcess,
153
+ targetLocale,
154
+ { dictionaryKey, keyPath: [] }
155
+ );
156
+ try {
157
+ const translationResult = await (0, import_api.getAiAPI)(
158
+ void 0,
159
+ configuration
160
+ ).translateJSON(
161
+ {
162
+ entryFileContent: sourceLocaleContent.content,
163
+ // Should be JSON, ensure getLocalisedContent provides this.
164
+ presetOutputContent: presetOutputContent.content,
165
+ // Should be JSON
166
+ dictionaryDescription: mainDictionaryToProcess.description,
167
+ entryLocale: sourceLocale,
168
+ outputLocale: targetLocale,
169
+ mode,
170
+ aiOptions: options.aiOptions
171
+ },
172
+ {
173
+ ...oAuth2AccessToken && {
174
+ headers: {
175
+ Authorization: `Bearer ${oAuth2AccessToken}`
176
+ }
177
+ }
178
+ }
179
+ );
180
+ if (!translationResult.data?.fileContent) {
181
+ appLogger(
182
+ `No content result found for '${(0, import_config.colorizeKey)(dictionaryKey)}' to ${(0, import_chokidar.formatLocale)(targetLocale)}`,
183
+ {
184
+ level: "error"
185
+ }
186
+ );
187
+ return null;
188
+ }
189
+ const processedPerLocaleDictionary = (0, import_chokidar.processPerLocaleDictionary)({
190
+ ...mainDictionaryToProcess,
191
+ content: translationResult.data?.fileContent,
192
+ locale: targetLocale
193
+ });
194
+ return processedPerLocaleDictionary;
195
+ } catch (error) {
196
+ appLogger(
197
+ `Error filling '${(0, import_config.colorizeKey)(dictionaryKey)}' to ${(0, import_chokidar.formatLocale)(targetLocale)}:` + error,
198
+ {
199
+ level: "error"
200
+ }
201
+ );
202
+ return null;
203
+ }
204
+ })
205
+ );
206
+ const translationResults = await Promise.all(translationPromises);
207
+ translationResults.forEach((translationResult) => {
208
+ if (translationResult) {
209
+ result.push(translationResult);
210
+ }
211
+ });
212
+ const dictionaryToMerge = mode === "review" ? [...result, mainDictionaryToProcess] : [mainDictionaryToProcess, ...result];
213
+ const mergedResults = (0, import_chokidar.mergeDictionaries)(dictionaryToMerge);
214
+ let formattedDict = targetUnmergedDictionary;
215
+ if (formattedDict.locale) {
216
+ const presetOutputContent = (0, import_core.getLocalisedContent)(
217
+ mainDictionaryToProcess,
218
+ formattedDict.locale,
219
+ { dictionaryKey, keyPath: [] }
220
+ );
221
+ formattedDict = {
222
+ ...formattedDict,
223
+ content: presetOutputContent.content
224
+ };
225
+ }
226
+ const reducedResult = (0, import_chokidar.reduceDictionaryContent)(mergedResults, formattedDict);
227
+ if (formattedDict.autoFill || configuration.content.autoFill) {
228
+ await (0, import_autoFill.autoFill)(
229
+ mergedResults,
230
+ targetUnmergedDictionary,
231
+ formattedDict.autoFill ?? configuration.content.autoFill,
232
+ outputLocalesList,
233
+ [sourceLocale],
234
+ configuration
235
+ );
236
+ } else {
237
+ await (0, import_chokidar.writeContentDeclaration)(
238
+ { ...formattedDict, content: reducedResult.content },
239
+ configuration,
240
+ formattedDict.filePath
241
+ );
242
+ if (formattedDict.filePath) {
243
+ appLogger(
244
+ `Content declaration for '${(0, import_config.colorizeKey)(dictionaryKey)}' written to ${(0, import_chokidar.formatPath)(formattedDict.filePath)}`,
245
+ {
246
+ level: "info"
247
+ }
248
+ );
249
+ }
250
+ }
251
+ }
252
+ };
253
+ // Annotate the CommonJS export names for ESM import in node:
254
+ 0 && (module.exports = {
255
+ fill
256
+ });
257
+ //# sourceMappingURL=index.cjs.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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAiD;AACjD,sBASO;AACP,oBAOO;AACP,kBAMO;AACP,gCAA+B;AAC/B,qBAAmB;AACnB,kBAAyB;AACzB,2BAA8B;AAC9B,sBAAyB;AACzB,iCAAiD;AAEjD,MAAM,6BAA6B;AAuB5B,MAAM,OAAO,OAAO,YAAwC;AACjE,QAAM,oBAAgB,gCAAiB,QAAQ,aAAa;AAC5D,QAAM,gBAAY,4BAAa,eAAe;AAAA,IAC5C,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,MAAI,QAAQ,OAAO;AACjB,cAAM,iCAAgB,aAAa;AAAA,EACrC;AAEA,QAAM,EAAE,eAAe,QAAQ,IAAI,cAAc;AACjD,QAAM,OAAO,QAAQ,QA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Ae,aAAa;AAE1E,QAAI,cAAc,YAAY,cAAc,QAAQ,UAAU;AAC5D,gBAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA,cAAc,YAAY,cAAc,QAAQ;AAAA,QAChD;AAAA,QACA,CAAC,YAAY;AAAA,QACb;AAAA,MACF;AAAA,IACF,OAAO;AACL,gBAAM;AAAA,QACJ,EAAE,GAAG,eAAe,SAAS,cAAc,QAAQ;AAAA,QACnD;AAAA,QACA,cAAc;AAAA,MAChB;AAEA,UAAI,cAAc,UAAU;AAC1B;AAAA,UACE,gCAA4B,2BAAY,aAAa,CAAC,oBAAgB,4BAAW,cAAc,QAAQ,CAAC;AAAA,UACxG;AAAA,YACE,OAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["dictionariesRecord","pLimit"]}
@@ -17,23 +17,25 @@ var index_exports = {};
17
17
  module.exports = __toCommonJS(index_exports);
18
18
  __reExport(index_exports, require('./build.cjs'), module.exports);
19
19
  __reExport(index_exports, require('./cli.cjs'), module.exports);
20
- __reExport(index_exports, require('./fill.cjs'), module.exports);
20
+ __reExport(index_exports, require('./fill/index.cjs'), module.exports);
21
21
  __reExport(index_exports, require('./listContentDeclaration.cjs'), module.exports);
22
22
  __reExport(index_exports, require('./pull.cjs'), module.exports);
23
23
  __reExport(index_exports, require('./push.cjs'), module.exports);
24
24
  __reExport(index_exports, require('./pushConfig.cjs'), module.exports);
25
25
  __reExport(index_exports, require('./reviewDoc.cjs'), module.exports);
26
+ __reExport(index_exports, require('./test/index.cjs'), module.exports);
26
27
  __reExport(index_exports, require('./translateDoc.cjs'), module.exports);
27
28
  // Annotate the CommonJS export names for ESM import in node:
28
29
  0 && (module.exports = {
29
30
  ...require('./build.cjs'),
30
31
  ...require('./cli.cjs'),
31
- ...require('./fill.cjs'),
32
+ ...require('./fill/index.cjs'),
32
33
  ...require('./listContentDeclaration.cjs'),
33
34
  ...require('./pull.cjs'),
34
35
  ...require('./push.cjs'),
35
36
  ...require('./pushConfig.cjs'),
36
37
  ...require('./reviewDoc.cjs'),
38
+ ...require('./test/index.cjs'),
37
39
  ...require('./translateDoc.cjs')
38
40
  });
39
41
  //# sourceMappingURL=index.cjs.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":";;;;;;;;;;;;;;;AAAA;AAAA;AACA,0BAAc,oBADd;AAEA,0BAAc,kBAFd;AAGA,0BAAc,mBAHd;AAIA,0BAAc,qCAJd;AAKA,0BAAc,mBALd;AAMA,0BAAc,mBANd;AAOA,0BAAc,yBAPd;AAQA,0BAAc,wBARd;AASA,0BAAc,2BATd;","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":";;;;;;;;;;;;;;;AAAA;AAAA;AACA,0BAAc,oBADd;AAEA,0BAAc,kBAFd;AAGA,0BAAc,mBAHd;AAIA,0BAAc,qCAJd;AAKA,0BAAc,mBALd;AAMA,0BAAc,mBANd;AAOA,0BAAc,yBAPd;AAQA,0BAAc,wBARd;AASA,0BAAc,mBATd;AAUA,0BAAc,2BAVd;","names":[]}