langium-tools 0.1.0 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langium-tools",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A set of tools for Langium",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,5 +1,15 @@
1
1
  declare global {
2
2
  interface Array<T> {
3
+ /**
4
+ * Sorts an array in place.
5
+ * This method mutates the array and returns a reference to the same array.
6
+ * @param key Function used to determine the order of the elements. It is expected to return
7
+ * a comparable value for this item to sort upon.
8
+ * ```ts
9
+ * [{size: 11, name: 'John'}, {size: 22, name: 'Max'}].sortBy(obj => obj.name)
10
+ * ```
11
+ * @returns this
12
+ */
3
13
  sortBy<K extends keyof T, V>(key: K | ((item: T) => V)): this;
4
14
  }
5
15
  }
@@ -9,6 +19,16 @@ Array.prototype.sortBy = function <T, K extends keyof T, V>(key: K | ((item: T)
9
19
  };
10
20
 
11
21
 
22
+ /**
23
+ * Sorts an array in place.
24
+ * This method mutates the array and returns a reference to the same array.
25
+ * @param key Function used to determine the order of the elements. It is expected to return
26
+ * a comparable value for this item to sort upon.
27
+ * ```ts
28
+ * [{size: 11, name: 'John'}, {size: 22, name: 'Max'}].sortBy(obj => obj.name)
29
+ * ```
30
+ * @returns list (sorting in place)
31
+ */
12
32
  export function arraySortBy<T, K extends keyof T, V>(list: T[], key: K | ((item: T) => V)): T[] {
13
33
  const comparator = typeof key === 'function'
14
34
  ? key
@@ -6,6 +6,7 @@ import fs from 'fs';
6
6
  import { expect, test } from 'vitest';
7
7
  import { getDocumentIssueSummary } from '../base/document-issues.js';
8
8
  import { GeneratedContent, GeneratorManager, GeneratedContentManager, GeneratorTarget, DEFAULT_TARGET } from '../generator/generated-content-manager.js';
9
+ import "../base/arrays.js";
9
10
 
10
11
 
11
12
  type DslServices<SERVICES, SHARED_SERVICES> = { shared: LangiumSharedServices & SHARED_SERVICES } & SERVICES;
@@ -246,6 +247,7 @@ function writeMetaData(generatedContent: GeneratedContentManager, metadataJsonFi
246
247
  generatedContent.getGeneratedContent(target).forEach((contentData, fileName) => {
247
248
  metadata.generatedFiles.push({ filename: fileName, overwrite: contentData.overwrite });
248
249
  });
250
+ metadata.generatedFiles.sortBy(m => m.filename);
249
251
  fs.writeFileSync(metadataJsonFile, JSON.stringify(metadata, null, 2));
250
252
  }
251
253