@intlayer/cli 5.8.1 → 6.0.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +241 -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 +119 -117
  24. package/dist/cjs/pull.cjs.map +1 -1
  25. package/dist/cjs/pullLog.cjs +146 -0
  26. package/dist/cjs/pullLog.cjs.map +1 -0
  27. package/dist/cjs/push.cjs +74 -88
  28. package/dist/cjs/push.cjs.map +1 -1
  29. package/dist/cjs/pushConfig.cjs +10 -25
  30. package/dist/cjs/pushConfig.cjs.map +1 -1
  31. package/dist/cjs/pushLog.cjs +130 -0
  32. package/dist/cjs/pushLog.cjs.map +1 -0
  33. package/dist/cjs/reviewDoc.cjs +45 -36
  34. package/dist/cjs/reviewDoc.cjs.map +1 -1
  35. package/dist/cjs/test/index.cjs +91 -0
  36. package/dist/cjs/test/index.cjs.map +1 -0
  37. package/dist/cjs/test/listMissingTranslations.cjs +73 -0
  38. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -0
  39. package/dist/cjs/translateDoc.cjs +42 -34
  40. package/dist/cjs/translateDoc.cjs.map +1 -1
  41. package/dist/cjs/utils/checkAIAccess.cjs +5 -1
  42. package/dist/cjs/utils/checkAIAccess.cjs.map +1 -1
  43. package/dist/cjs/utils/chunkInference.cjs +7 -14
  44. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  45. package/dist/esm/IntlayerEventListener.mjs +207 -0
  46. package/dist/esm/IntlayerEventListener.mjs.map +1 -0
  47. package/dist/esm/cli.mjs +26 -4
  48. package/dist/esm/cli.mjs.map +1 -1
  49. package/dist/esm/config.mjs +5 -1
  50. package/dist/esm/config.mjs.map +1 -1
  51. package/dist/esm/fill/autoFill.mjs +92 -0
  52. package/dist/esm/fill/autoFill.mjs.map +1 -0
  53. package/dist/esm/fill/formatAutoFillData.mjs +84 -0
  54. package/dist/esm/fill/formatAutoFillData.mjs.map +1 -0
  55. package/dist/esm/fill/formatAutoFilledFilePath.mjs +22 -0
  56. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -0
  57. package/dist/esm/fill/getTargetDictionary.mjs +51 -0
  58. package/dist/esm/fill/getTargetDictionary.mjs.map +1 -0
  59. package/dist/esm/fill/index.mjs +240 -0
  60. package/dist/esm/fill/index.mjs.map +1 -0
  61. package/dist/esm/index.mjs +2 -1
  62. package/dist/esm/index.mjs.map +1 -1
  63. package/dist/esm/listContentDeclaration.mjs +38 -17
  64. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  65. package/dist/esm/liveSync.mjs +220 -0
  66. package/dist/esm/liveSync.mjs.map +1 -0
  67. package/dist/esm/pull.mjs +123 -108
  68. package/dist/esm/pull.mjs.map +1 -1
  69. package/dist/esm/pullLog.mjs +127 -0
  70. package/dist/esm/pullLog.mjs.map +1 -0
  71. package/dist/esm/push.mjs +81 -90
  72. package/dist/esm/push.mjs.map +1 -1
  73. package/dist/esm/pushConfig.mjs +11 -26
  74. package/dist/esm/pushConfig.mjs.map +1 -1
  75. package/dist/esm/pushLog.mjs +111 -0
  76. package/dist/esm/pushLog.mjs.map +1 -0
  77. package/dist/esm/reviewDoc.mjs +55 -38
  78. package/dist/esm/reviewDoc.mjs.map +1 -1
  79. package/dist/esm/test/index.mjs +74 -0
  80. package/dist/esm/test/index.mjs.map +1 -0
  81. package/dist/esm/test/listMissingTranslations.mjs +41 -0
  82. package/dist/esm/test/listMissingTranslations.mjs.map +1 -0
  83. package/dist/esm/translateDoc.mjs +52 -37
  84. package/dist/esm/translateDoc.mjs.map +1 -1
  85. package/dist/esm/utils/checkAIAccess.mjs +5 -1
  86. package/dist/esm/utils/checkAIAccess.mjs.map +1 -1
  87. package/dist/esm/utils/chunkInference.mjs +14 -16
  88. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  89. package/dist/types/IntlayerEventListener.d.ts +85 -0
  90. package/dist/types/IntlayerEventListener.d.ts.map +1 -0
  91. package/dist/types/cli.d.ts.map +1 -1
  92. package/dist/types/config.d.ts.map +1 -1
  93. package/dist/types/fill/autoFill.d.ts +4 -0
  94. package/dist/types/fill/autoFill.d.ts.map +1 -0
  95. package/dist/types/fill/formatAutoFillData.d.ts +9 -0
  96. package/dist/types/fill/formatAutoFillData.d.ts.map +1 -0
  97. package/dist/types/fill/formatAutoFilledFilePath.d.ts +3 -0
  98. package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -0
  99. package/dist/types/fill/getTargetDictionary.d.ts +4 -0
  100. package/dist/types/fill/getTargetDictionary.d.ts.map +1 -0
  101. package/dist/types/{fill.d.ts → fill/index.d.ts} +2 -5
  102. package/dist/types/fill/index.d.ts.map +1 -0
  103. package/dist/types/index.d.ts +1 -0
  104. package/dist/types/index.d.ts.map +1 -1
  105. package/dist/types/listContentDeclaration.d.ts +4 -5
  106. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  107. package/dist/types/liveSync.d.ts +6 -0
  108. package/dist/types/liveSync.d.ts.map +1 -0
  109. package/dist/types/pull.d.ts.map +1 -1
  110. package/dist/types/pullLog.d.ts +24 -0
  111. package/dist/types/pullLog.d.ts.map +1 -0
  112. package/dist/types/push.d.ts +1 -1
  113. package/dist/types/push.d.ts.map +1 -1
  114. package/dist/types/pushConfig.d.ts +0 -1
  115. package/dist/types/pushConfig.d.ts.map +1 -1
  116. package/dist/types/pushLog.d.ts +23 -0
  117. package/dist/types/pushLog.d.ts.map +1 -0
  118. package/dist/types/reviewDoc.d.ts +1 -1
  119. package/dist/types/reviewDoc.d.ts.map +1 -1
  120. package/dist/types/test/index.d.ts +8 -0
  121. package/dist/types/test/index.d.ts.map +1 -0
  122. package/dist/types/test/listMissingTranslations.d.ts +12 -0
  123. package/dist/types/test/listMissingTranslations.d.ts.map +1 -0
  124. package/dist/types/translateDoc.d.ts +1 -1
  125. package/dist/types/translateDoc.d.ts.map +1 -1
  126. package/dist/types/utils/checkAIAccess.d.ts.map +1 -1
  127. package/dist/types/utils/chunkInference.d.ts +2 -1
  128. package/dist/types/utils/chunkInference.d.ts.map +1 -1
  129. package/package.json +19 -15
  130. package/dist/cjs/fill.cjs +0 -405
  131. package/dist/cjs/fill.cjs.map +0 -1
  132. package/dist/esm/fill.mjs +0 -385
  133. package/dist/esm/fill.mjs.map +0 -1
  134. package/dist/types/fill.d.ts.map +0 -1
package/dist/cjs/push.cjs CHANGED
@@ -36,19 +36,15 @@ var import_chokidar = require("@intlayer/chokidar");
36
36
  var import_config = require("@intlayer/config");
37
37
  var import_dictionaries_entry = __toESM(require("@intlayer/dictionaries-entry"));
38
38
  var fsPromises = __toESM(require("fs/promises"));
39
- var import_p_limit = __toESM(require("p-limit"));
40
- var import_path = require("path");
41
39
  var readline = __toESM(require("readline"));
42
- const spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
43
- const RESET = "\x1B[0m";
44
- const GREEN = "\x1B[32m";
45
- const RED = "\x1B[31m";
46
- const BLUE = "\x1B[34m";
47
- const GREY = "\x1B[90m";
48
- const GREY_DARK = "\x1B[90m";
40
+ var import_pushLog = require('./pushLog.cjs');
49
41
  const push = async (options) => {
50
42
  const config = (0, import_config.getConfiguration)(options?.configOptions);
51
- const appLogger = (0, import_config.getAppLogger)(config);
43
+ const appLogger = (0, import_config.getAppLogger)(config, {
44
+ config: {
45
+ prefix: ""
46
+ }
47
+ });
52
48
  const { clientId, clientSecret } = config.editor;
53
49
  try {
54
50
  if (!clientId || !clientSecret) {
@@ -56,9 +52,7 @@ const push = async (options) => {
56
52
  "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
57
53
  );
58
54
  }
59
- const intlayerAuthAPI = (0, import_api.getOAuthAPI)(config);
60
- const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();
61
- const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
55
+ const intlayerAPI = (0, import_api.getIntlayerAPIProxy)(void 0, config);
62
56
  let dictionaries = Object.values(import_dictionaries_entry.default);
63
57
  const existingDictionariesKeys = Object.keys(import_dictionaries_entry.default);
64
58
  if (options?.dictionaries) {
@@ -90,41 +84,42 @@ const push = async (options) => {
90
84
  }
91
85
  appLogger("Pushing dictionaries:", {});
92
86
  const dictionariesStatuses = dictionaries.map(
93
- (dictionary, index) => ({
87
+ (dictionary) => ({
94
88
  dictionary,
95
- icon: getStatusIcon("pending"),
96
- status: "pending",
97
- index,
98
- spinnerFrameIndex: 0
89
+ status: "pending"
99
90
  })
100
91
  );
101
- for (const statusObj of dictionariesStatuses) {
102
- process.stdout.write(getStatusLine(statusObj) + "\n");
103
- }
92
+ const logger = new import_pushLog.PushLogger();
93
+ logger.update(
94
+ dictionariesStatuses.map((s) => ({
95
+ dictionaryKey: s.dictionary.key,
96
+ status: "pending"
97
+ }))
98
+ );
104
99
  const successfullyPushedDictionaries = [];
105
- const spinnerTimer = setInterval(() => {
106
- updateAllStatusLines(dictionariesStatuses);
107
- }, 100);
108
100
  const processDictionary = async (statusObj) => {
109
101
  statusObj.status = "pushing";
102
+ logger.update([
103
+ { dictionaryKey: statusObj.dictionary.key, status: "pushing" }
104
+ ]);
110
105
  try {
111
- const intlayerDictionaryAPI = (0, import_api.getDictionaryAPI)(void 0, config);
112
- const pushResult = await intlayerDictionaryAPI.pushDictionaries(
113
- [statusObj.dictionary],
114
- {
115
- headers: {
116
- Authorization: `Bearer ${oAuth2AccessToken}`
117
- }
118
- }
119
- );
106
+ const pushResult = await intlayerAPI.dictionary.pushDictionaries([
107
+ statusObj.dictionary
108
+ ]);
120
109
  const updatedDictionaries = pushResult.data?.updatedDictionaries || [];
121
110
  const newDictionaries = pushResult.data?.newDictionaries || [];
122
111
  if (updatedDictionaries.includes(statusObj.dictionary.key)) {
123
112
  statusObj.status = "modified";
124
113
  successfullyPushedDictionaries.push(statusObj.dictionary);
114
+ logger.update([
115
+ { dictionaryKey: statusObj.dictionary.key, status: "modified" }
116
+ ]);
125
117
  } else if (newDictionaries.includes(statusObj.dictionary.key)) {
126
118
  statusObj.status = "pushed";
127
119
  successfullyPushedDictionaries.push(statusObj.dictionary);
120
+ logger.update([
121
+ { dictionaryKey: statusObj.dictionary.key, status: "pushed" }
122
+ ]);
128
123
  } else {
129
124
  statusObj.status = "unknown";
130
125
  }
@@ -132,15 +127,42 @@ const push = async (options) => {
132
127
  statusObj.status = "error";
133
128
  statusObj.error = error;
134
129
  statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;
130
+ logger.update([
131
+ { dictionaryKey: statusObj.dictionary.key, status: "error" }
132
+ ]);
135
133
  }
136
134
  };
137
- const limit = (0, import_p_limit.default)(5);
138
- const pushPromises = dictionariesStatuses.map(
139
- (statusObj) => limit(() => processDictionary(statusObj))
140
- );
141
- await Promise.all(pushPromises);
142
- clearInterval(spinnerTimer);
143
- updateAllStatusLines(dictionariesStatuses);
135
+ await (0, import_chokidar.parallelize)(dictionariesStatuses, processDictionary, 5);
136
+ logger.finish();
137
+ const iconFor = (status) => {
138
+ switch (status) {
139
+ case "pushed":
140
+ case "modified":
141
+ return "\u2714";
142
+ case "error":
143
+ return "\u2716";
144
+ default:
145
+ return "\u23F2";
146
+ }
147
+ };
148
+ const colorFor = (status) => {
149
+ switch (status) {
150
+ case "pushed":
151
+ case "modified":
152
+ return import_config.ANSIColors.GREEN;
153
+ case "error":
154
+ return import_config.ANSIColors.RED;
155
+ default:
156
+ return import_config.ANSIColors.BLUE;
157
+ }
158
+ };
159
+ for (const s of dictionariesStatuses) {
160
+ const icon = iconFor(s.status);
161
+ const color = colorFor(s.status);
162
+ appLogger(
163
+ ` - ${s.dictionary.key} ${import_config.ANSIColors.GREY}[${color}${icon} ${s.status}${import_config.ANSIColors.GREY}]${import_config.ANSIColors.RESET}`
164
+ );
165
+ }
144
166
  for (const statusObj of dictionariesStatuses) {
145
167
  if (statusObj.errorMessage) {
146
168
  appLogger(statusObj.errorMessage, {
@@ -186,8 +208,11 @@ const askUser = (question) => {
186
208
  };
187
209
  const deleteLocalDictionaries = async (dictionariesToDelete, options) => {
188
210
  const config = (0, import_config.getConfiguration)(options?.configOptions);
189
- const appLogger = (0, import_config.getAppLogger)(config);
190
- const { baseDir } = config.content;
211
+ const appLogger = (0, import_config.getAppLogger)(config, {
212
+ config: {
213
+ prefix: ""
214
+ }
215
+ });
191
216
  const filePathsSet = /* @__PURE__ */ new Set();
192
217
  for (const dictionary of dictionariesToDelete) {
193
218
  const { filePath } = dictionary;
@@ -200,65 +225,26 @@ const deleteLocalDictionaries = async (dictionariesToDelete, options) => {
200
225
  filePathsSet.add(filePath);
201
226
  }
202
227
  for (const filePath of filePathsSet) {
203
- const relativePath = (0, import_path.relative)(baseDir, filePath);
204
228
  try {
205
229
  const stats = await fsPromises.lstat(filePath);
206
230
  if (stats.isFile()) {
207
231
  await fsPromises.unlink(filePath);
208
- appLogger(`Deleted file ${relativePath}`, {});
232
+ appLogger(`Deleted file ${(0, import_chokidar.formatPath)(filePath)}`, {});
209
233
  } else if (stats.isDirectory()) {
210
- appLogger(`Path is a directory ${relativePath}, skipping.`, {});
234
+ appLogger(`Path is a directory ${(0, import_chokidar.formatPath)(filePath)}, skipping.`, {});
211
235
  } else {
212
- appLogger(`Unknown file type for ${relativePath}, skipping.`, {});
236
+ appLogger(
237
+ `Unknown file type for ${(0, import_chokidar.formatPath)(filePath)}, skipping.`,
238
+ {}
239
+ );
213
240
  }
214
241
  } catch (err) {
215
- appLogger(`Error deleting ${relativePath}: ${err}`, {
242
+ appLogger(`Error deleting ${(0, import_chokidar.formatPath)(filePath)}: ${err}`, {
216
243
  level: "error"
217
244
  });
218
245
  }
219
246
  }
220
247
  };
221
- const getStatusIcon = (status) => {
222
- const statusIcons = {
223
- pending: "\u23F2",
224
- pushing: "",
225
- // Spinner handled separately
226
- modified: "\u2714",
227
- pushed: "\u2714",
228
- error: "\u2716"
229
- };
230
- return statusIcons[status] || "";
231
- };
232
- const getStatusLine = (statusObj) => {
233
- let icon = getStatusIcon(statusObj.status);
234
- let colorStart = "";
235
- let colorEnd = "";
236
- if (statusObj.status === "pushing") {
237
- icon = spinnerFrames[statusObj.spinnerFrameIndex % spinnerFrames.length];
238
- colorStart = BLUE;
239
- colorEnd = RESET;
240
- } else if (statusObj.status === "error") {
241
- colorStart = RED;
242
- colorEnd = RESET;
243
- } else if (statusObj.status === "pushed" || statusObj.status === "modified") {
244
- colorStart = GREEN;
245
- colorEnd = RESET;
246
- } else {
247
- colorStart = GREY;
248
- colorEnd = RESET;
249
- }
250
- return `- ${statusObj.dictionary.key} ${GREY_DARK}[${colorStart}${icon}${statusObj.status}${GREY_DARK}]${colorEnd}`;
251
- };
252
- const updateAllStatusLines = (dictionariesStatuses) => {
253
- readline.moveCursor(process.stdout, 0, -dictionariesStatuses.length);
254
- for (const statusObj of dictionariesStatuses) {
255
- readline.clearLine(process.stdout, 0);
256
- if (statusObj.status === "pushing") {
257
- statusObj.spinnerFrameIndex = (statusObj.spinnerFrameIndex + 1) % spinnerFrames.length;
258
- }
259
- process.stdout.write(getStatusLine(statusObj) + "\n");
260
- }
261
- };
262
248
  // Annotate the CommonJS export names for ESM import in node:
263
249
  0 && (module.exports = {
264
250
  push
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/push.ts"],"sourcesContent":["import { getDictionaryAPI, getOAuthAPI } from '@intlayer/api';\nimport { listGitFiles, ListGitFilesOptions } from '@intlayer/chokidar';\nimport {\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport * as fsPromises from 'fs/promises';\nimport pLimit from 'p-limit';\nimport { relative } from 'path';\nimport * as readline from 'readline';\n\ntype PushOptions = {\n deleteLocaleDictionary?: boolean;\n keepLocaleDictionary?: boolean;\n dictionaries?: string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionary: Dictionary;\n status: 'pending' | 'pushing' | 'modified' | 'pushed' | 'unknown' | 'error';\n icon: string;\n index: number;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\nconst spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\nconst RESET = '\\x1b[0m';\nconst GREEN = '\\x1b[32m';\nconst RED = '\\x1b[31m';\nconst BLUE = '\\x1b[34m';\nconst GREY = '\\x1b[90m';\nconst GREY_DARK = '\\x1b[90m';\n\n/**\n * Get all locale dictionaries and push them simultaneously.\n */\nexport const push = async (options?: PushOptions): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n const { clientId, clientSecret } = config.editor;\n try {\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAuthAPI = getOAuthAPI(config);\n const oAuth2TokenResult = await intlayerAuthAPI.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n let dictionaries: Dictionary[] = Object.values(dictionariesRecord);\n const existingDictionariesKeys: string[] = Object.keys(dictionariesRecord);\n\n if (options?.dictionaries) {\n // Check if the provided dictionaries exist\n const noneExistingDictionariesOption = options.dictionaries.filter(\n (dictionaryId) => !existingDictionariesKeys.includes(dictionaryId)\n );\n\n if (noneExistingDictionariesOption.length > 0) {\n appLogger(\n `The following dictionaries do not exist: ${noneExistingDictionariesOption.join(\n ', '\n )} and have been ignored.`,\n {\n level: 'error',\n }\n );\n }\n\n // Filter the dictionaries from the provided list of IDs\n dictionaries = dictionaries.filter((dictionary) =>\n options.dictionaries!.includes(dictionary.key)\n );\n }\n\n if (options?.gitOptions) {\n const gitFiles = await listGitFiles(options.gitOptions);\n }\n\n // Check if the dictionaries list is empty\n if (dictionaries.length === 0) {\n appLogger('No local dictionaries found', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Pushing dictionaries:', {});\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = dictionaries.map(\n (dictionary, index) => ({\n dictionary,\n icon: getStatusIcon('pending'),\n status: 'pending',\n index,\n spinnerFrameIndex: 0,\n })\n );\n\n // Output initial statuses\n for (const statusObj of dictionariesStatuses) {\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n\n const successfullyPushedDictionaries: Dictionary[] = [];\n\n // Start spinner timer\n const spinnerTimer = setInterval(() => {\n updateAllStatusLines(dictionariesStatuses);\n }, 100); // Update every 100ms\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'pushing';\n\n try {\n const intlayerDictionaryAPI = getDictionaryAPI(undefined, config);\n const pushResult = await intlayerDictionaryAPI.pushDictionaries(\n [statusObj.dictionary],\n {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }\n );\n\n const updatedDictionaries = pushResult.data?.updatedDictionaries || [];\n const newDictionaries = pushResult.data?.newDictionaries || [];\n\n if (updatedDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'modified';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n } else if (newDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'pushed';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n } else {\n statusObj.status = 'unknown';\n }\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;\n }\n };\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Limit the number of concurrent requests\n const pushPromises = dictionariesStatuses.map((statusObj) =>\n limit(() => processDictionary(statusObj))\n );\n await Promise.all(pushPromises);\n\n // Stop the spinner timer\n clearInterval(spinnerTimer);\n\n // Update statuses one last time\n updateAllStatusLines(dictionariesStatuses);\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n\n // Handle delete or keep options\n const deleteOption = options?.deleteLocaleDictionary;\n const keepOption = options?.keepLocaleDictionary;\n\n if (deleteOption && keepOption) {\n throw new Error(\n 'Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.'\n );\n }\n\n if (deleteOption) {\n // Delete only the successfully pushed dictionaries\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n } else if (keepOption) {\n // Do nothing, keep the local dictionaries\n } else {\n // Ask the user\n const answer = await askUser(\n 'Do you want to delete the local dictionaries that were successfully pushed? (yes/no): '\n );\n if (answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y') {\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n\nconst askUser = (question: string): Promise<string> => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n return new Promise((resolve) => {\n rl.question(question, (answer: string) => {\n rl.close();\n resolve(answer);\n });\n });\n};\n\nconst deleteLocalDictionaries = async (\n dictionariesToDelete: Dictionary[],\n options?: PushOptions\n): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n const { baseDir } = config.content;\n\n // Use a Set to collect all unique file paths\n const filePathsSet: Set<string> = new Set();\n\n for (const dictionary of dictionariesToDelete) {\n const { filePath } = dictionary;\n\n if (!filePath) {\n appLogger(`Dictionary ${dictionary.key} does not have a file path`, {\n level: 'error',\n });\n continue;\n }\n\n filePathsSet.add(filePath);\n }\n\n for (const filePath of filePathsSet) {\n const relativePath = relative(baseDir, filePath);\n\n try {\n const stats = await fsPromises.lstat(filePath);\n\n if (stats.isFile()) {\n await fsPromises.unlink(filePath);\n appLogger(`Deleted file ${relativePath}`, {});\n } else if (stats.isDirectory()) {\n appLogger(`Path is a directory ${relativePath}, skipping.`, {});\n } else {\n appLogger(`Unknown file type for ${relativePath}, skipping.`, {});\n }\n } catch (err) {\n appLogger(`Error deleting ${relativePath}: ${err}`, {\n level: 'error',\n });\n }\n }\n};\n\nconst getStatusIcon = (status: string): string => {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n pushing: '', // Spinner handled separately\n modified: '✔',\n pushed: '✔',\n error: '✖',\n };\n return statusIcons[status] || '';\n};\n\nconst getStatusLine = (statusObj: DictionariesStatus): string => {\n let icon = getStatusIcon(statusObj.status);\n let colorStart = '';\n let colorEnd = '';\n\n if (statusObj.status === 'pushing') {\n // Use spinner frame\n icon = spinnerFrames[statusObj.spinnerFrameIndex! % spinnerFrames.length];\n colorStart = BLUE;\n colorEnd = RESET;\n } else if (statusObj.status === 'error') {\n colorStart = RED;\n colorEnd = RESET;\n } else if (statusObj.status === 'pushed' || statusObj.status === 'modified') {\n colorStart = GREEN;\n colorEnd = RESET;\n } else {\n colorStart = GREY;\n colorEnd = RESET;\n }\n\n return `- ${statusObj.dictionary.key} ${GREY_DARK}[${colorStart}${icon}${statusObj.status}${GREY_DARK}]${colorEnd}`;\n};\n\nconst updateAllStatusLines = (dictionariesStatuses: DictionariesStatus[]) => {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -dictionariesStatuses.length);\n for (const statusObj of dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (statusObj.status === 'pushing') {\n // Update spinner frame\n statusObj.spinnerFrameIndex =\n (statusObj.spinnerFrameIndex! + 1) % spinnerFrames.length;\n }\n\n // Write the status line\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA8C;AAC9C,sBAAkD;AAClD,oBAIO;AAEP,gCAA+B;AAC/B,iBAA4B;AAC5B,qBAAmB;AACnB,kBAAyB;AACzB,eAA0B;AAoB1B,MAAM,gBAAgB,CAAC,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,UAAK,QAAG;AAEvE,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,MAAM;AACZ,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,YAAY;AAKX,MAAM,OAAO,OAAO,YAAyC;AAClE,QAAM,aAAS,gCAAiB,SAAS,aAAa;AACtD,QAAM,gBAAY,4BAAa,MAAM;AACrC,QAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,MAAI;AACF,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,sBAAkB,wBAAY,MAAM;AAC1C,UAAM,oBAAoB,MAAM,gBAAgB,qBAAqB;AAErE,UAAM,oBAAoB,kBAAkB,MA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sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport dictionariesRecord from '@intlayer/dictionaries-entry';\nimport * as fsPromises from 'fs/promises';\nimport * as readline from 'readline';\nimport { PushLogger, type PushStatus } from './pushLog';\n\ntype PushOptions = {\n deleteLocaleDictionary?: boolean;\n keepLocaleDictionary?: boolean;\n dictionaries?: string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionary: Dictionary;\n status: 'pending' | 'pushing' | 'modified' | 'pushed' | 'unknown' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n/**\n * Get all local dictionaries and push them simultaneously.\n */\nexport const push = async (options?: PushOptions): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n const { clientId, clientSecret } = config.editor;\n try {\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n let dictionaries: Dictionary[] = Object.values(dictionariesRecord);\n const existingDictionariesKeys: string[] = Object.keys(dictionariesRecord);\n\n if (options?.dictionaries) {\n // Check if the provided dictionaries exist\n const noneExistingDictionariesOption = options.dictionaries.filter(\n (dictionaryId) => !existingDictionariesKeys.includes(dictionaryId)\n );\n\n if (noneExistingDictionariesOption.length > 0) {\n appLogger(\n `The following dictionaries do not exist: ${noneExistingDictionariesOption.join(\n ', '\n )} and have been ignored.`,\n {\n level: 'error',\n }\n );\n }\n\n // Filter the dictionaries from the provided list of IDs\n dictionaries = dictionaries.filter((dictionary) =>\n options.dictionaries!.includes(dictionary.key)\n );\n }\n\n if (options?.gitOptions) {\n const gitFiles = await listGitFiles(options.gitOptions);\n }\n\n // Check if the dictionaries list is empty\n if (dictionaries.length === 0) {\n appLogger('No local dictionaries found', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Pushing dictionaries:', {});\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = dictionaries.map(\n (dictionary) => ({\n dictionary,\n status: 'pending',\n })\n );\n\n // Initialize aggregated logger similar to loadDictionaries\n const logger = new PushLogger();\n logger.update(\n dictionariesStatuses.map<PushStatus>((s) => ({\n dictionaryKey: s.dictionary.key,\n status: 'pending',\n }))\n );\n\n const successfullyPushedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'pushing';\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'pushing' },\n ]);\n\n try {\n const pushResult = await intlayerAPI.dictionary.pushDictionaries([\n statusObj.dictionary,\n ]);\n\n const updatedDictionaries = pushResult.data?.updatedDictionaries || [];\n const newDictionaries = pushResult.data?.newDictionaries || [];\n\n if (updatedDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'modified';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'modified' },\n ]);\n } else if (newDictionaries.includes(statusObj.dictionary.key)) {\n statusObj.status = 'pushed';\n successfullyPushedDictionaries.push(statusObj.dictionary);\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'pushed' },\n ]);\n } else {\n statusObj.status = 'unknown';\n }\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error pushing dictionary ${statusObj.dictionary.key}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionary.key, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with a concurrency limit (reuse parallelize)\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n // Print per-dictionary summary similar to loadDictionaries\n const iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'pushed':\n case 'modified':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n };\n\n const colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'pushed':\n case 'modified':\n return ANSIColors.GREEN;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n };\n\n for (const s of dictionariesStatuses) {\n const icon = iconFor(s.status);\n const color = colorFor(s.status);\n appLogger(\n ` - ${s.dictionary.key} ${ANSIColors.GREY}[${color}${icon} ${s.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n\n // Handle delete or keep options\n const deleteOption = options?.deleteLocaleDictionary;\n const keepOption = options?.keepLocaleDictionary;\n\n if (deleteOption && keepOption) {\n throw new Error(\n 'Cannot specify both --deleteLocaleDictionary and --keepLocaleDictionary options.'\n );\n }\n\n if (deleteOption) {\n // Delete only the successfully pushed dictionaries\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n } else if (keepOption) {\n // Do nothing, keep the local dictionaries\n } else {\n // Ask the user\n const answer = await askUser(\n 'Do you want to delete the local dictionaries that were successfully pushed? (yes/no): '\n );\n if (answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y') {\n await deleteLocalDictionaries(successfullyPushedDictionaries, options);\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n\nconst askUser = (question: string): Promise<string> => {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n return new Promise((resolve) => {\n rl.question(question, (answer: string) => {\n rl.close();\n resolve(answer);\n });\n });\n};\n\nconst deleteLocalDictionaries = async (\n dictionariesToDelete: Dictionary[],\n options?: PushOptions\n): Promise<void> => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n // Use a Set to collect all unique file paths\n const filePathsSet: Set<string> = new Set();\n\n for (const dictionary of dictionariesToDelete) {\n const { filePath } = dictionary;\n\n if (!filePath) {\n appLogger(`Dictionary ${dictionary.key} does not have a file path`, {\n level: 'error',\n });\n continue;\n }\n\n filePathsSet.add(filePath);\n }\n\n for (const filePath of filePathsSet) {\n try {\n const stats = await fsPromises.lstat(filePath);\n\n if (stats.isFile()) {\n await fsPromises.unlink(filePath);\n appLogger(`Deleted file ${formatPath(filePath)}`, {});\n } else if (stats.isDirectory()) {\n appLogger(`Path is a directory ${formatPath(filePath)}, skipping.`, {});\n } else {\n appLogger(\n `Unknown file type for ${formatPath(filePath)}, skipping.`,\n {}\n );\n }\n } catch (err) {\n appLogger(`Error deleting ${formatPath(filePath)}: ${err}`, {\n level: 'error',\n });\n }\n }\n};\n\n// Legacy per-line spinner output removed in favor of aggregated PushLogger\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoC;AACpC,sBAKO;AACP,oBAKO;AAEP,gCAA+B;AAC/B,iBAA4B;AAC5B,eAA0B;AAC1B,qBAA4C;AAoBrC,MAAM,OAAO,OAAO,YAAyC;AAClE,QAAM,aAAS,gCAAiB,SAAS,aAAa;AACtD,QAAM,gBAAY,4BAAa,QAAQ;AAAA,IACrC,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AACD,QAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,MAAI;AACF,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,kBAAc,gCAAoB,QAAW,MAAM;AAEzD,QAAI,eAA6B,OAAO,OAAO,0BAAAA,OAAkB;AACjE,UAAM,2BAAqC,OAAO,KAAK,0BA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M,eAA4B,oBAAI,IAAI;AAE1C,aAAW,cAAc,sBAAsB;AAC7C,UAAM,EAAE,SAAS,IAAI;AAErB,QAAI,CAAC,UAAU;AACb,gBAAU,cAAc,WAAW,GAAG,8BAA8B;AAAA,QAClE,OAAO;AAAA,MACT,CAAC;AACD;AAAA,IACF;AAEA,iBAAa,IAAI,QAAQ;AAAA,EAC3B;AAEA,aAAW,YAAY,cAAc;AACnC,QAAI;AACF,YAAM,QAAQ,MAAM,WAAW,MAAM,QAAQ;AAE7C,UAAI,MAAM,OAAO,GAAG;AAClB,cAAM,WAAW,OAAO,QAAQ;AAChC,kBAAU,oBAAgB,4BAAW,QAAQ,CAAC,IAAI,CAAC,CAAC;AAAA,MACtD,WAAW,MAAM,YAAY,GAAG;AAC9B,kBAAU,2BAAuB,4BAAW,QAAQ,CAAC,eAAe,CAAC,CAAC;AAAA,MACxE,OAAO;AACL;AAAA,UACE,6BAAyB,4BAAW,QAAQ,CAAC;AAAA,UAC7C,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF,SAAS,KAAK;AACZ,gBAAU,sBAAkB,4BAAW,QAAQ,CAAC,KAAK,GAAG,IAAI;AAAA,QAC1D,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["dictionariesRecord"]}
@@ -25,43 +25,28 @@ var import_api = require("@intlayer/api");
25
25
  var import_config = require("@intlayer/config");
26
26
  const pushConfig = async (options) => {
27
27
  const config = (0, import_config.getConfiguration)(options?.configOptions);
28
- const appLogger = (0, import_config.getAppLogger)(config);
28
+ const appLogger = (0, import_config.getAppLogger)(config, {
29
+ config: {
30
+ prefix: ""
31
+ }
32
+ });
29
33
  const { clientId, clientSecret } = config.editor;
30
34
  if (!clientId || !clientSecret) {
31
35
  appLogger(
32
36
  "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.",
33
37
  {
34
- level: "error",
35
- config: {
36
- prefix: options?.logPrefix
37
- }
38
+ level: "error"
38
39
  }
39
40
  );
40
41
  return;
41
42
  }
42
- const intlayerAPI = (0, import_api.getIntlayerAPI)(void 0, config);
43
- const oAuth2TokenResult = await intlayerAPI.oAuth.getOAuth2AccessToken();
44
- const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
45
- const getDictionariesKeysResult = await intlayerAPI.project.pushProjectConfiguration(config, {
46
- ...oAuth2AccessToken && {
47
- headers: {
48
- Authorization: `Bearer ${oAuth2AccessToken}`
49
- }
50
- }
51
- });
43
+ const intlayerAPI = (0, import_api.getIntlayerAPIProxy)(void 0, config);
44
+ const getDictionariesKeysResult = await intlayerAPI.project.pushProjectConfiguration(config);
52
45
  if (!getDictionariesKeysResult.data) {
53
46
  throw new Error("Error pushing project configuration");
54
47
  }
55
- appLogger("Project configuration pushed successfully", {
56
- config: {
57
- prefix: options?.logPrefix
58
- }
59
- });
60
- appLogger(JSON.stringify(getDictionariesKeysResult.data, null, 2), {
61
- config: {
62
- prefix: options?.logPrefix
63
- }
64
- });
48
+ appLogger("Project configuration pushed successfully");
49
+ appLogger(JSON.stringify(getDictionariesKeysResult.data, null, 2));
65
50
  };
66
51
  // Annotate the CommonJS export names for ESM import in node:
67
52
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport {\n getAppLogger,\n getConfiguration,\n type GetConfigurationOptions,\n} from '@intlayer/config';\n\ntype PushOptions = {\n logPrefix?: string;\n configOptions?: GetConfigurationOptions;\n};\n\nexport const pushConfig = async (options?: PushOptions) => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n appLogger(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.',\n {\n level: 'error',\n config: {\n prefix: options?.logPrefix,\n },\n }\n );\n return;\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n const oAuth2TokenResult = await intlayerAPI.oAuth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.project.pushProjectConfiguration(config, {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('Error pushing project configuration');\n }\n\n appLogger('Project configuration pushed successfully', {\n config: {\n prefix: options?.logPrefix,\n },\n });\n\n appLogger(JSON.stringify(getDictionariesKeysResult.data, null, 2), {\n config: {\n prefix: options?.logPrefix,\n },\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAC/B,oBAIO;AAOA,MAAM,aAAa,OAAO,YAA0B;AACzD,QAAM,aAAS,gCAAiB,SAAS,aAAa;AACtD,QAAM,gBAAY,4BAAa,MAAM;AAErC,QAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO;AAAA,QACP,QAAQ;AAAA,UACN,QAAQ,SAAS;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AACA;AAAA,EACF;AAEA,QAAM,kBAAc,2BAAe,QAAW,MAAM;AAEpD,QAAM,oBAAoB,MAAM,YAAY,MAAM,qBAAqB;AAEvE,QAAM,oBAAoB,kBAAkB,MAAM;AAGlD,QAAM,4BACJ,MAAM,YAAY,QAAQ,yBAAyB,QAAQ;AAAA,IACzD,GAAI,qBAAqB;AAAA,MACvB,SAAS;AAAA,QACP,eAAe,UAAU,iBAAiB;AAAA,MAC5C;AAAA,IACF;AAAA,EACF,CAAC;AAEH,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,YAAU,6CAA6C;AAAA,IACrD,QAAQ;AAAA,MACN,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,CAAC;AAED,YAAU,KAAK,UAAU,0BAA0B,MAAM,MAAM,CAAC,GAAG;AAAA,IACjE,QAAQ;AAAA,MACN,QAAQ,SAAS;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/pushConfig.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n getAppLogger,\n getConfiguration,\n type GetConfigurationOptions,\n} from '@intlayer/config';\n\ntype PushOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const pushConfig = async (options?: PushOptions) => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n appLogger(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.',\n {\n level: 'error',\n }\n );\n return;\n }\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n // Push the project configuration\n const getDictionariesKeysResult =\n await intlayerAPI.project.pushProjectConfiguration(config);\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('Error pushing project configuration');\n }\n\n appLogger('Project configuration pushed successfully');\n\n appLogger(JSON.stringify(getDictionariesKeysResult.data, null, 2));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoC;AACpC,oBAIO;AAMA,MAAM,aAAa,OAAO,YAA0B;AACzD,QAAM,aAAS,gCAAiB,SAAS,aAAa;AACtD,QAAM,gBAAY,4BAAa,QAAQ;AAAA,IACrC,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,MAAI,CAAC,YAAY,CAAC,cAAc;AAC9B;AAAA,MACE;AAAA,MACA;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AACA;AAAA,EACF;AAEA,QAAM,kBAAc,gCAAoB,QAAW,MAAM;AAGzD,QAAM,4BACJ,MAAM,YAAY,QAAQ,yBAAyB,MAAM;AAE3D,MAAI,CAAC,0BAA0B,MAAM;AACnC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,YAAU,2CAA2C;AAErD,YAAU,KAAK,UAAU,0BAA0B,MAAM,MAAM,CAAC,CAAC;AACnE;","names":[]}
@@ -0,0 +1,130 @@
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 pushLog_exports = {};
20
+ __export(pushLog_exports, {
21
+ PushLogger: () => PushLogger
22
+ });
23
+ module.exports = __toCommonJS(pushLog_exports);
24
+ var import_config = require("@intlayer/config");
25
+ class PushLogger {
26
+ statuses = [];
27
+ spinnerTimer = null;
28
+ spinnerIndex = 0;
29
+ renderedLines = 0;
30
+ spinnerFrames = import_config.spinnerFrames;
31
+ isFinished = false;
32
+ prefix;
33
+ lastRenderedState = "";
34
+ constructor() {
35
+ const configuration = (0, import_config.getConfiguration)();
36
+ this.prefix = configuration.log.prefix;
37
+ }
38
+ update(newStatuses) {
39
+ if (this.isFinished) return;
40
+ for (const status of newStatuses) {
41
+ const index = this.statuses.findIndex(
42
+ (s) => s.dictionaryKey === status.dictionaryKey
43
+ );
44
+ if (index >= 0) {
45
+ this.statuses[index] = status;
46
+ } else {
47
+ this.statuses.push(status);
48
+ }
49
+ }
50
+ this.startSpinner();
51
+ this.render();
52
+ }
53
+ finish() {
54
+ this.isFinished = true;
55
+ this.stopSpinner();
56
+ this.render();
57
+ }
58
+ startSpinner() {
59
+ if (this.spinnerTimer || this.isFinished) return;
60
+ this.spinnerTimer = setInterval(() => {
61
+ this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
62
+ this.render();
63
+ }, 100);
64
+ }
65
+ stopSpinner() {
66
+ if (!this.spinnerTimer) return;
67
+ clearInterval(this.spinnerTimer);
68
+ this.spinnerTimer = null;
69
+ }
70
+ render() {
71
+ const { total, done, pushed, modified, errors } = this.computeProgress();
72
+ const frame = this.spinnerFrames[this.spinnerIndex];
73
+ const lines = [];
74
+ const isDone = done === total;
75
+ const progressLabel = `dictionaries: ${done}/${total}`;
76
+ const details = [];
77
+ if (pushed > 0) details.push(`new: ${pushed}`);
78
+ if (modified > 0) details.push(`modified: ${modified}`);
79
+ if (errors > 0) details.push((0, import_config.colorize)(`errors: ${errors}`, import_config.ANSIColors.RED));
80
+ const suffix = details.length > 0 ? ` (${details.join(", ")})` : "";
81
+ if (isDone) {
82
+ lines.push(
83
+ `${this.prefix} ${(0, import_config.colorize)("\u2714", import_config.ANSIColors.GREEN)} pushed ${progressLabel}${suffix}`
84
+ );
85
+ } else {
86
+ lines.push(
87
+ `${this.prefix} ${(0, import_config.colorize)(frame, import_config.ANSIColors.BLUE)} pushing ${progressLabel}${suffix}`
88
+ );
89
+ }
90
+ const currentState = lines.join("\n");
91
+ if (currentState === this.lastRenderedState) {
92
+ return;
93
+ }
94
+ this.lastRenderedState = currentState;
95
+ if (this.renderedLines > 0) {
96
+ process.stdout.write(`\x1B[${this.renderedLines}F`);
97
+ }
98
+ const totalLinesToClear = Math.max(this.renderedLines, lines.length);
99
+ for (let i = 0; i < totalLinesToClear; i++) {
100
+ process.stdout.write("\x1B[2K");
101
+ const line = lines[i];
102
+ if (line !== void 0) {
103
+ process.stdout.write(line);
104
+ }
105
+ process.stdout.write("\n");
106
+ }
107
+ this.renderedLines = lines.length;
108
+ }
109
+ computeProgress() {
110
+ const keys = new Set(this.statuses.map((s) => s.dictionaryKey));
111
+ const pushed = this.statuses.filter((s) => s.status === "pushed").length;
112
+ const modified = this.statuses.filter(
113
+ (s) => s.status === "modified"
114
+ ).length;
115
+ const errors = this.statuses.filter((s) => s.status === "error").length;
116
+ const done = pushed + modified + errors;
117
+ return {
118
+ total: keys.size,
119
+ done,
120
+ pushed,
121
+ modified,
122
+ errors
123
+ };
124
+ }
125
+ }
126
+ // Annotate the CommonJS export names for ESM import in node:
127
+ 0 && (module.exports = {
128
+ PushLogger
129
+ });
130
+ //# sourceMappingURL=pushLog.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/pushLog.ts"],"sourcesContent":["import {\n ANSIColors,\n colorize,\n getConfiguration,\n spinnerFrames,\n} from '@intlayer/config';\n\nexport type PushStatus = {\n dictionaryKey: string;\n status: 'pending' | 'pushing' | 'pushed' | 'modified' | 'error';\n errorMessage?: string;\n};\n\nexport class PushLogger {\n private statuses: PushStatus[] = [];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private spinnerIndex = 0;\n private renderedLines = 0;\n private readonly spinnerFrames = spinnerFrames;\n private isFinished = false;\n private readonly prefix: string;\n private lastRenderedState: string = '';\n\n constructor() {\n const configuration = getConfiguration();\n this.prefix = configuration.log.prefix;\n }\n\n update(newStatuses: PushStatus[]) {\n if (this.isFinished) return;\n for (const status of newStatuses) {\n const index = this.statuses.findIndex(\n (s) => s.dictionaryKey === status.dictionaryKey\n );\n if (index >= 0) {\n this.statuses[index] = status;\n } else {\n this.statuses.push(status);\n }\n }\n\n this.startSpinner();\n this.render();\n }\n\n finish() {\n this.isFinished = true;\n this.stopSpinner();\n this.render();\n }\n\n private startSpinner() {\n if (this.spinnerTimer || this.isFinished) return;\n this.spinnerTimer = setInterval(() => {\n this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;\n this.render();\n }, 100);\n }\n\n private stopSpinner() {\n if (!this.spinnerTimer) return;\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n\n private render() {\n const { total, done, pushed, modified, errors } = this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const lines: string[] = [];\n\n const isDone = done === total;\n\n const progressLabel = `dictionaries: ${done}/${total}`;\n const details: string[] = [];\n if (pushed > 0) details.push(`new: ${pushed}`);\n if (modified > 0) details.push(`modified: ${modified}`);\n if (errors > 0) details.push(colorize(`errors: ${errors}`, ANSIColors.RED));\n\n const suffix = details.length > 0 ? ` (${details.join(', ')})` : '';\n\n if (isDone) {\n lines.push(\n `${this.prefix} ${colorize('✔', ANSIColors.GREEN)} pushed ${progressLabel}${suffix}`\n );\n } else {\n lines.push(\n `${this.prefix} ${colorize(frame, ANSIColors.BLUE)} pushing ${progressLabel}${suffix}`\n );\n }\n\n const currentState = lines.join('\\n');\n if (currentState === this.lastRenderedState) {\n return;\n }\n this.lastRenderedState = currentState;\n\n if (this.renderedLines > 0) {\n process.stdout.write(`\\x1b[${this.renderedLines}F`);\n }\n\n const totalLinesToClear = Math.max(this.renderedLines, lines.length);\n for (let i = 0; i < totalLinesToClear; i++) {\n process.stdout.write('\\x1b[2K');\n const line = lines[i];\n if (line !== undefined) {\n process.stdout.write(line);\n }\n process.stdout.write('\\n');\n }\n\n this.renderedLines = lines.length;\n }\n\n private computeProgress() {\n const keys = new Set(this.statuses.map((s) => s.dictionaryKey));\n\n const pushed = this.statuses.filter((s) => s.status === 'pushed').length;\n const modified = this.statuses.filter(\n (s) => s.status === 'modified'\n ).length;\n const errors = this.statuses.filter((s) => s.status === 'error').length;\n const done = pushed + modified + errors;\n\n return {\n total: keys.size,\n done,\n pushed,\n modified,\n errors,\n } as const;\n }\n}\n"],"mapp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