gtx-cli 2.5.24 → 2.5.25
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.
- package/CHANGELOG.md +6 -0
- package/dist/formats/json/mergeJson.js +48 -19
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.5.25
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#876](https://github.com/generaltranslation/gt/pull/876) [`28bd6d5`](https://github.com/generaltranslation/gt/commit/28bd6d5f1ed50658da2e3adc5b59a40804b00b02) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Adding experimental alphabetical sort for JSONs with locales as keys
|
|
8
|
+
|
|
3
9
|
## 2.5.24
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -207,16 +207,10 @@ export function mergeJson(originalContent, inputPath, options, targets, defaultL
|
|
|
207
207
|
return [JSON.stringify(mergedJson, null, 2)];
|
|
208
208
|
}
|
|
209
209
|
function sortByLocaleOrder(items, sourceObjectOptions, localeOrder, sourceObjectPointer, defaultLocale) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
!sourceObjectOptions.key) {
|
|
210
|
+
const sortMode = sourceObjectOptions.experimentalSort;
|
|
211
|
+
if (!sortMode || !sourceObjectOptions.key) {
|
|
213
212
|
return items;
|
|
214
213
|
}
|
|
215
|
-
const orderedLocaleList = [
|
|
216
|
-
defaultLocale,
|
|
217
|
-
...localeOrder.filter((locale) => locale !== defaultLocale),
|
|
218
|
-
];
|
|
219
|
-
const localeOrderValues = orderedLocaleList.map((locale) => getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions));
|
|
220
214
|
const itemsWithLocale = items.map((item) => {
|
|
221
215
|
let localeValue;
|
|
222
216
|
try {
|
|
@@ -237,21 +231,56 @@ function sortByLocaleOrder(items, sourceObjectOptions, localeOrder, sourceObject
|
|
|
237
231
|
}
|
|
238
232
|
return { item, localeValue };
|
|
239
233
|
});
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
234
|
+
if (sortMode === 'locales') {
|
|
235
|
+
if (!localeOrder.length) {
|
|
236
|
+
return items;
|
|
237
|
+
}
|
|
238
|
+
const orderedLocaleList = [
|
|
239
|
+
defaultLocale,
|
|
240
|
+
...localeOrder.filter((locale) => locale !== defaultLocale),
|
|
241
|
+
];
|
|
242
|
+
const localeOrderValues = orderedLocaleList.map((locale) => getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions));
|
|
243
|
+
const orderedItems = [];
|
|
244
|
+
const remainingItems = [...itemsWithLocale];
|
|
245
|
+
for (const localeValue of localeOrderValues) {
|
|
246
|
+
for (let i = 0; i < remainingItems.length;) {
|
|
247
|
+
const entry = remainingItems[i];
|
|
248
|
+
if (entry.localeValue === localeValue) {
|
|
249
|
+
orderedItems.push(entry.item);
|
|
250
|
+
remainingItems.splice(i, 1);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
i += 1;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
remainingItems.forEach((entry) => orderedItems.push(entry.item));
|
|
257
|
+
return orderedItems;
|
|
258
|
+
}
|
|
259
|
+
if (sortMode === 'localesAlphabetical') {
|
|
260
|
+
const defaultLocaleValue = getIdentifyingLocaleProperty(defaultLocale, sourceObjectPointer, sourceObjectOptions);
|
|
261
|
+
const defaultItems = [];
|
|
262
|
+
const sortableItems = [];
|
|
263
|
+
const remainingItems = [];
|
|
264
|
+
for (const entry of itemsWithLocale) {
|
|
265
|
+
if (entry.localeValue === defaultLocaleValue) {
|
|
266
|
+
defaultItems.push(entry);
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (entry.localeValue) {
|
|
270
|
+
sortableItems.push(entry);
|
|
248
271
|
continue;
|
|
249
272
|
}
|
|
250
|
-
|
|
273
|
+
remainingItems.push(entry);
|
|
251
274
|
}
|
|
275
|
+
sortableItems.sort((a, b) => {
|
|
276
|
+
if (!a.localeValue || !b.localeValue) {
|
|
277
|
+
return 0;
|
|
278
|
+
}
|
|
279
|
+
return a.localeValue.localeCompare(b.localeValue);
|
|
280
|
+
});
|
|
281
|
+
return [...defaultItems, ...sortableItems, ...remainingItems].map((entry) => entry.item);
|
|
252
282
|
}
|
|
253
|
-
|
|
254
|
-
return orderedItems;
|
|
283
|
+
return items;
|
|
255
284
|
}
|
|
256
285
|
/**
|
|
257
286
|
* Apply transformations to the sourceItem in-place
|
package/dist/types/index.d.ts
CHANGED
|
@@ -208,7 +208,7 @@ export type SourceObjectOptions = {
|
|
|
208
208
|
key?: string;
|
|
209
209
|
localeProperty?: string;
|
|
210
210
|
transform?: TransformOptions;
|
|
211
|
-
experimentalSort?: 'locales';
|
|
211
|
+
experimentalSort?: 'locales' | 'localesAlphabetical';
|
|
212
212
|
};
|
|
213
213
|
export type TransformOptions = {
|
|
214
214
|
[transformPath: string]: TransformOption;
|