Skip to content

Commit efbeb07

Browse files
Merge pull request #237 from transifex/TX-16599_1
TX-16599: Native push --verbose command group created, updated, skipped, failed strings
2 parents 9061d28 + c606827 commit efbeb07

File tree

2 files changed

+80
-15
lines changed

2 files changed

+80
-15
lines changed

packages/cli/src/api/utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ function mergeArrays(array1, array2) {
2323
return _.uniq(_.concat(array1 || [], array2 || []));
2424
}
2525

26+
/**
27+
* Normalize input to array format
28+
*
29+
* @param {*} value - Input that might be an array, string, or other type
30+
* @returns {Array} Normalized array
31+
*/
32+
function normalizeArray(value) {
33+
if (!value) return [];
34+
if (Array.isArray(value)) return value;
35+
if (typeof value === 'string') {
36+
try {
37+
const parsed = JSON.parse(value);
38+
return Array.isArray(parsed) ? parsed : [];
39+
} catch (_e) {
40+
return [];
41+
}
42+
}
43+
return [];
44+
}
45+
2646
/**
2747
* Async/await sleep
2848
*
@@ -40,5 +60,6 @@ function sleep(msec) {
4060
module.exports = {
4161
stringToArray,
4262
mergeArrays,
63+
normalizeArray,
4364
sleep,
4465
};

packages/cli/src/commands/push.js

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { CliUx } = require('@oclif/core');
1111
const { extractPhrases } = require('../api/extract');
1212
const { uploadPhrases, pollJob } = require('../api/upload');
1313
const { mergePayload } = require('../api/merge');
14-
const { stringToArray } = require('../api/utils');
14+
const { stringToArray, normalizeArray } = require('../api/utils');
1515

1616
/**
1717
* Test if path is folder
@@ -161,6 +161,41 @@ class PushCommand extends Command {
161161
: 'Uploading content to Transifex';
162162

163163
this.log('');
164+
165+
/**
166+
* Print detailed verbose output for a group of items
167+
*
168+
* @param {String} label - Label for the group
169+
* @param {Array} items - Items to display
170+
* @param {String} groupColor - Color for the group label
171+
*/
172+
const printVerboseGroup = (label, items, groupColor = 'white') => {
173+
const arr = normalizeArray(items);
174+
if (!arr.length) return;
175+
this.log(` ${label}: ${arr.length}`[groupColor]);
176+
arr.forEach((item) => {
177+
const {
178+
key = '',
179+
string = '',
180+
context = [],
181+
occurrences = [],
182+
} = item;
183+
if (string) {
184+
if (key !== string) {
185+
this.log(` └─ ${key}: ${string.underline}`);
186+
} else {
187+
this.log(` └─ ${string.underline}`);
188+
}
189+
if (occurrences.length) {
190+
this.log(` └─ occurrences: ${occurrences.join(', ')}`.gray);
191+
}
192+
if (context.length) {
193+
this.log(` └─ context: ${context}`.gray);
194+
}
195+
}
196+
});
197+
};
198+
164199
CliUx.ux.action.start(uploadMessage, '', { stdout: true });
165200
try {
166201
let res = await uploadPhrases(payload, {
@@ -207,20 +242,29 @@ class PushCommand extends Command {
207242
if (status === 'completed') {
208243
CliUx.ux.action.stop('Success'.green);
209244
this.log(`${'✓'.green} Successfully pushed strings to Transifex:`);
210-
if (res.created > 0) {
211-
this.log(` Created strings: ${res.created.toString().green}`);
212-
}
213-
if (res.updated > 0) {
214-
this.log(` Updated strings: ${res.updated.toString().green}`);
215-
}
216-
if (res.skipped > 0) {
217-
this.log(` Skipped strings: ${res.skipped.toString().green}`);
218-
}
219-
if (res.deleted > 0) {
220-
this.log(` Deleted strings: ${res.deleted.toString().green}`);
221-
}
222-
if (res.failed > 0) {
223-
this.log(` Failed strings: ${res.failed.toString().red}`);
245+
246+
if (res.verbose && flags.verbose) {
247+
printVerboseGroup('Created strings', res.verbose.created, 'green');
248+
printVerboseGroup('Updated strings', res.verbose.updated, 'yellow');
249+
printVerboseGroup('Deleted strings', res.verbose.deleted, 'red');
250+
printVerboseGroup('Skipped strings', res.verbose.skipped, 'green');
251+
printVerboseGroup('Failed strings', res.verbose.failed, 'red');
252+
} else {
253+
if (res.created > 0) {
254+
this.log(` Created strings: ${res.created}`.green);
255+
}
256+
if (res.updated > 0) {
257+
this.log(` Updated strings: ${res.updated}`.yellow);
258+
}
259+
if (res.deleted > 0) {
260+
this.log(` Deleted strings: ${res.deleted}`.red);
261+
}
262+
if (res.skipped > 0) {
263+
this.log(` Skipped strings: ${res.skipped}`.green);
264+
}
265+
if (res.failed > 0) {
266+
this.log(` Failed strings: ${res.failed}`.red);
267+
}
224268
}
225269
} else {
226270
CliUx.ux.action.stop('Failed'.red);

0 commit comments

Comments
 (0)