@itwin/perf-tools 5.3.0-dev.18 → 5.3.0-dev.21

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.
@@ -0,0 +1,12 @@
1
+ /** @beta */
2
+ export declare class CsvWriter {
3
+ private _entries;
4
+ addEntry(data: Record<string, any>): void;
5
+ clear(): void;
6
+ /**
7
+ * Create CSV file with report. Call after all test have run
8
+ * @param fileName Name of the CSV file with or without .csv
9
+ */
10
+ exportCSV(fileName: string): void;
11
+ }
12
+ //# sourceMappingURL=CsvWriter.d.ts.map
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CsvWriter = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const fs = require("fs-extra");
9
+ /** @beta */
10
+ class CsvWriter {
11
+ _entries = [];
12
+ addEntry(data) {
13
+ this._entries.push(data);
14
+ }
15
+ clear() {
16
+ this._entries = [];
17
+ }
18
+ /**
19
+ * Create CSV file with report. Call after all test have run
20
+ * @param fileName Name of the CSV file with or without .csv
21
+ */
22
+ exportCSV(fileName) {
23
+ if (!fileName.endsWith(".csv")) {
24
+ fileName = `${fileName}.csv`;
25
+ }
26
+ if (this._entries.length === 0) {
27
+ fs.writeFileSync(fileName, "");
28
+ return;
29
+ }
30
+ // Get headers from the first entry to preserve order
31
+ const headers = Object.keys(this._entries[0]);
32
+ // Create header row
33
+ let csvContent = `${headers.join(",")}\n`;
34
+ // Create data rows
35
+ for (const entry of this._entries) {
36
+ const row = headers.map(header => {
37
+ const value = entry[header];
38
+ if (value === undefined || value === null) {
39
+ return "";
40
+ }
41
+ // Convert to string and escape quotes
42
+ let stringValue = String(value);
43
+ if (stringValue.includes(",") || stringValue.includes('"') || stringValue.includes("\n")) {
44
+ stringValue = stringValue.replace(/"/g, '""');
45
+ stringValue = `"${stringValue}"`;
46
+ }
47
+ return stringValue;
48
+ });
49
+ csvContent += `${row.join(",")}\n`;
50
+ }
51
+ // Replace the entire file
52
+ fs.writeFileSync(fileName, csvContent);
53
+ }
54
+ }
55
+ exports.CsvWriter = CsvWriter;
56
+ //# sourceMappingURL=CsvWriter.js.map
@@ -1,2 +1,3 @@
1
1
  export * from "./Reporter";
2
+ export * from "./CsvWriter";
2
3
  //# sourceMappingURL=perf-tools.d.ts.map
@@ -19,4 +19,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  * See LICENSE.md in the project root for license terms and full copyright notice.
20
20
  *--------------------------------------------------------------------------------------------*/
21
21
  __exportStar(require("./Reporter"), exports);
22
+ __exportStar(require("./CsvWriter"), exports);
22
23
  //# sourceMappingURL=perf-tools.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/perf-tools",
3
- "version": "5.3.0-dev.18",
3
+ "version": "5.3.0-dev.21",
4
4
  "description": "Tools for collecting and reporting performance data",
5
5
  "main": "lib/cjs/perf-tools.js",
6
6
  "typings": "lib/cjs/perf-tools",
@@ -29,7 +29,7 @@
29
29
  "eslint": "^9.31.0",
30
30
  "rimraf": "^6.0.1",
31
31
  "typescript": "~5.6.2",
32
- "@itwin/build-tools": "5.3.0-dev.18"
32
+ "@itwin/build-tools": "5.3.0-dev.21"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "npm run -s build:cjs",