gtx-cli 2.5.24 → 2.5.26

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.5.26
4
+
5
+ ### Patch Changes
6
+
7
+ - [#878](https://github.com/generaltranslation/gt/pull/878) [`5624f1c`](https://github.com/generaltranslation/gt/commit/5624f1c074ff9cb2065ed85dbb30fae24939f53e) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Updating Mintlify preset to include `experimentalSort`
8
+
9
+ ## 2.5.25
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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
14
+
3
15
  ## 2.5.24
4
16
 
5
17
  ### Patch Changes
@@ -8,6 +8,7 @@ export function generatePreset(preset, type) {
8
8
  '$.navigation.languages': {
9
9
  type: 'array',
10
10
  key: '$.language',
11
+ experimentalSort: 'localesAlphabetical',
11
12
  include: [
12
13
  '$..group',
13
14
  '$..tab',
@@ -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
- if (sourceObjectOptions.experimentalSort !== 'locales' ||
211
- !localeOrder.length ||
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
- const orderedItems = [];
241
- const remainingItems = [...itemsWithLocale];
242
- for (const localeValue of localeOrderValues) {
243
- for (let i = 0; i < remainingItems.length;) {
244
- const entry = remainingItems[i];
245
- if (entry.localeValue === localeValue) {
246
- orderedItems.push(entry.item);
247
- remainingItems.splice(i, 1);
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
- i += 1;
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
- remainingItems.forEach((entry) => orderedItems.push(entry.item));
254
- return orderedItems;
283
+ return items;
255
284
  }
256
285
  /**
257
286
  * Apply transformations to the sourceItem in-place
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.5.24",
3
+ "version": "2.5.26",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [