genlayer 0.18.3 → 0.18.4
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/index.js +7 -12
- package/package.json +1 -1
- package/src/lib/actions/BaseAction.ts +8 -15
- package/tests/libs/baseAction.test.ts +44 -53
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.18.4 (2025-06-27)
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* refactor log output formatting and address spinner display ([#228](https://github.com/yeagerai/genlayer-cli/issues/228)) ([ea0ac10](https://github.com/yeagerai/genlayer-cli/commit/ea0ac100cdbed0cf184ae1eaf1d9c0fd580fc92c))
|
|
8
|
+
|
|
3
9
|
## 0.18.3 (2025-05-29)
|
|
4
10
|
|
|
5
11
|
## 0.18.2 (2025-05-29)
|
package/dist/index.js
CHANGED
|
@@ -17723,7 +17723,7 @@ var require_semver2 = __commonJS({
|
|
|
17723
17723
|
import { program } from "commander";
|
|
17724
17724
|
|
|
17725
17725
|
// package.json
|
|
17726
|
-
var version = "0.18.
|
|
17726
|
+
var version = "0.18.4";
|
|
17727
17727
|
var package_default = {
|
|
17728
17728
|
name: "genlayer",
|
|
17729
17729
|
version,
|
|
@@ -20658,6 +20658,7 @@ function ora(options) {
|
|
|
20658
20658
|
|
|
20659
20659
|
// src/lib/actions/BaseAction.ts
|
|
20660
20660
|
import inquirer from "inquirer";
|
|
20661
|
+
import { inspect } from "util";
|
|
20661
20662
|
|
|
20662
20663
|
// src/lib/accounts/KeypairManager.ts
|
|
20663
20664
|
import { writeFileSync, existsSync, readFileSync } from "fs";
|
|
@@ -40979,18 +40980,10 @@ var BaseAction = class extends ConfigFileManager {
|
|
|
40979
40980
|
}
|
|
40980
40981
|
}
|
|
40981
40982
|
formatOutput(data) {
|
|
40982
|
-
if (data
|
|
40983
|
-
|
|
40984
|
-
name: data.name,
|
|
40985
|
-
message: data.message,
|
|
40986
|
-
...Object.keys(data).length ? data : {}
|
|
40987
|
-
};
|
|
40988
|
-
return JSON.stringify(errorDetails, null, 2);
|
|
40989
|
-
}
|
|
40990
|
-
if (data instanceof Map) {
|
|
40991
|
-
data = Object.fromEntries(data);
|
|
40983
|
+
if (typeof data === "string") {
|
|
40984
|
+
return data;
|
|
40992
40985
|
}
|
|
40993
|
-
return
|
|
40986
|
+
return inspect(data, { depth: null, colors: false });
|
|
40994
40987
|
}
|
|
40995
40988
|
log(message, data) {
|
|
40996
40989
|
console.log(source_default.white(`
|
|
@@ -41023,10 +41016,12 @@ ${message}`));
|
|
|
41023
41016
|
}
|
|
41024
41017
|
succeedSpinner(message, data) {
|
|
41025
41018
|
if (data !== void 0) this.log("Result:", data);
|
|
41019
|
+
console.log("");
|
|
41026
41020
|
this.spinner.succeed(source_default.green(message));
|
|
41027
41021
|
}
|
|
41028
41022
|
failSpinner(message, error) {
|
|
41029
41023
|
if (error) this.log("Error:", error);
|
|
41024
|
+
console.log("");
|
|
41030
41025
|
this.spinner.fail(source_default.red(message));
|
|
41031
41026
|
}
|
|
41032
41027
|
stopSpinner() {
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import {ConfigFileManager} from "../../lib/config/ConfigFileManager";
|
|
|
2
2
|
import ora, {Ora} from "ora";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import inquirer from "inquirer";
|
|
5
|
+
import { inspect } from "util";
|
|
5
6
|
import {KeypairManager} from "../accounts/KeypairManager";
|
|
6
7
|
import {createClient, createAccount} from "genlayer-js";
|
|
7
8
|
import {localnet} from "genlayer-js/chains";
|
|
@@ -58,20 +59,10 @@ export class BaseAction extends ConfigFileManager {
|
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
private formatOutput(data: any): string {
|
|
61
|
-
if (data
|
|
62
|
-
|
|
63
|
-
name: data.name,
|
|
64
|
-
message: data.message,
|
|
65
|
-
...(Object.keys(data).length ? data : {}),
|
|
66
|
-
};
|
|
67
|
-
return JSON.stringify(errorDetails, null, 2);
|
|
62
|
+
if (typeof data === "string") {
|
|
63
|
+
return data;
|
|
68
64
|
}
|
|
69
|
-
|
|
70
|
-
if (data instanceof Map) {
|
|
71
|
-
data = Object.fromEntries(data);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return typeof data === "object" ? JSON.stringify(data, null, 2) : String(data);
|
|
65
|
+
return inspect(data, { depth: null, colors: false });
|
|
75
66
|
}
|
|
76
67
|
|
|
77
68
|
protected log(message: string, data?: any): void {
|
|
@@ -106,11 +97,13 @@ export class BaseAction extends ConfigFileManager {
|
|
|
106
97
|
|
|
107
98
|
protected succeedSpinner(message: string, data?: any): void {
|
|
108
99
|
if (data !== undefined) this.log("Result:", data);
|
|
100
|
+
console.log('');
|
|
109
101
|
this.spinner.succeed(chalk.green(message));
|
|
110
102
|
}
|
|
111
103
|
|
|
112
|
-
protected failSpinner(message: string, error?:
|
|
104
|
+
protected failSpinner(message: string, error?:any): void {
|
|
113
105
|
if (error) this.log("Error:", error);
|
|
106
|
+
console.log('');
|
|
114
107
|
this.spinner.fail(chalk.red(message));
|
|
115
108
|
}
|
|
116
109
|
|
|
@@ -121,4 +114,4 @@ export class BaseAction extends ConfigFileManager {
|
|
|
121
114
|
protected setSpinnerText(message: string): void {
|
|
122
115
|
this.spinner.text = chalk.blue(message);
|
|
123
116
|
}
|
|
124
|
-
}
|
|
117
|
+
}
|
|
@@ -3,6 +3,7 @@ import {BaseAction} from "../../src/lib/actions/BaseAction";
|
|
|
3
3
|
import inquirer from "inquirer";
|
|
4
4
|
import ora, {Ora} from "ora";
|
|
5
5
|
import chalk from "chalk";
|
|
6
|
+
import {inspect} from "util";
|
|
6
7
|
|
|
7
8
|
vi.mock("inquirer");
|
|
8
9
|
vi.mock("ora");
|
|
@@ -42,11 +43,17 @@ describe("BaseAction", () => {
|
|
|
42
43
|
|
|
43
44
|
test("should succeed the spinner with a message", () => {
|
|
44
45
|
baseAction["succeedSpinner"]("Success");
|
|
46
|
+
expect(consoleSpy).toHaveBeenCalledWith("");
|
|
45
47
|
expect(mockSpinner.succeed).toHaveBeenCalledWith(expect.stringContaining("Success"));
|
|
46
48
|
});
|
|
47
49
|
|
|
48
50
|
test("should fail the spinner with an error message", () => {
|
|
49
|
-
|
|
51
|
+
const error = new Error("Something went wrong");
|
|
52
|
+
baseAction["failSpinner"]("Failure", error);
|
|
53
|
+
|
|
54
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("Error:"));
|
|
55
|
+
expect(consoleSpy).toHaveBeenCalledWith(inspect(error, {depth: null, colors: false}));
|
|
56
|
+
expect(consoleSpy).toHaveBeenCalledWith("");
|
|
50
57
|
expect(mockSpinner.fail).toHaveBeenCalledWith(expect.stringContaining("Failure"));
|
|
51
58
|
});
|
|
52
59
|
|
|
@@ -108,7 +115,7 @@ describe("BaseAction", () => {
|
|
|
108
115
|
baseAction["logSuccess"]("Success message", data);
|
|
109
116
|
|
|
110
117
|
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("✔ Success message"));
|
|
111
|
-
expect(consoleSpy).toHaveBeenCalledWith(chalk.green(
|
|
118
|
+
expect(consoleSpy).toHaveBeenCalledWith(chalk.green(inspect(data, {depth: null, colors: false})));
|
|
112
119
|
});
|
|
113
120
|
|
|
114
121
|
test("should log an error message with error details", () => {
|
|
@@ -117,18 +124,7 @@ describe("BaseAction", () => {
|
|
|
117
124
|
baseAction["logError"]("Error message", error);
|
|
118
125
|
|
|
119
126
|
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("✖ Error message"));
|
|
120
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
121
|
-
chalk.red(
|
|
122
|
-
JSON.stringify(
|
|
123
|
-
{
|
|
124
|
-
name: error.name,
|
|
125
|
-
message: error.message,
|
|
126
|
-
},
|
|
127
|
-
null,
|
|
128
|
-
2,
|
|
129
|
-
),
|
|
130
|
-
),
|
|
131
|
-
);
|
|
127
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(chalk.red(inspect(error, {depth: null, colors: false})));
|
|
132
128
|
});
|
|
133
129
|
|
|
134
130
|
test("should log an info message with data", () => {
|
|
@@ -137,7 +133,7 @@ describe("BaseAction", () => {
|
|
|
137
133
|
baseAction["logInfo"]("Info message", data);
|
|
138
134
|
|
|
139
135
|
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("ℹ Info message"));
|
|
140
|
-
expect(consoleSpy).toHaveBeenCalledWith(chalk.blue(
|
|
136
|
+
expect(consoleSpy).toHaveBeenCalledWith(chalk.blue(inspect(data, {depth: null, colors: false})));
|
|
141
137
|
});
|
|
142
138
|
|
|
143
139
|
test("should log a warning message with data", () => {
|
|
@@ -146,7 +142,7 @@ describe("BaseAction", () => {
|
|
|
146
142
|
baseAction["logWarning"]("Warning message", data);
|
|
147
143
|
|
|
148
144
|
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("⚠ Warning message"));
|
|
149
|
-
expect(consoleSpy).toHaveBeenCalledWith(chalk.yellow(
|
|
145
|
+
expect(consoleSpy).toHaveBeenCalledWith(chalk.yellow(inspect(data, {depth: null, colors: false})));
|
|
150
146
|
});
|
|
151
147
|
|
|
152
148
|
test("should succeed the spinner with a message and log result if data is provided", () => {
|
|
@@ -155,52 +151,17 @@ describe("BaseAction", () => {
|
|
|
155
151
|
baseAction["succeedSpinner"]("Success", mockData);
|
|
156
152
|
|
|
157
153
|
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining("Result:"));
|
|
158
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
154
|
+
expect(consoleSpy).toHaveBeenCalledWith(inspect(mockData, {depth: null, colors: false}));
|
|
155
|
+
expect(consoleSpy).toHaveBeenCalledWith("");
|
|
159
156
|
expect(mockSpinner.succeed).toHaveBeenCalledWith(expect.stringContaining("Success"));
|
|
160
157
|
});
|
|
161
158
|
|
|
162
|
-
test("should format an Error instance with name, message, and additional properties", () => {
|
|
163
|
-
const error = new Error("Something went wrong");
|
|
164
|
-
(error as any).code = 500;
|
|
165
|
-
|
|
166
|
-
const result = (baseAction as any).formatOutput(error);
|
|
167
|
-
expect(result).toBe(JSON.stringify({name: "Error", message: "Something went wrong", code: 500}, null, 2));
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
test("should format an object as JSON string", () => {
|
|
171
|
-
const data = {key: "value", num: 42};
|
|
172
|
-
const result = (baseAction as any).formatOutput(data);
|
|
173
|
-
|
|
174
|
-
expect(result).toBe(JSON.stringify(data, null, 2));
|
|
175
|
-
});
|
|
176
|
-
|
|
177
159
|
test("should return a string representation of a primitive", () => {
|
|
178
160
|
expect((baseAction as any).formatOutput("Hello")).toBe("Hello");
|
|
179
161
|
expect((baseAction as any).formatOutput(42)).toBe("42");
|
|
180
162
|
expect((baseAction as any).formatOutput(true)).toBe("true");
|
|
181
163
|
});
|
|
182
164
|
|
|
183
|
-
test("should format a Map object correctly", () => {
|
|
184
|
-
const testMap = new Map<string, any>([
|
|
185
|
-
["key1", "value1"],
|
|
186
|
-
["key2", 42],
|
|
187
|
-
["key3", {nested: "object"}],
|
|
188
|
-
]);
|
|
189
|
-
|
|
190
|
-
const result = (baseAction as any).formatOutput(testMap);
|
|
191
|
-
const expected = JSON.stringify(
|
|
192
|
-
{
|
|
193
|
-
key1: "value1",
|
|
194
|
-
key2: 42,
|
|
195
|
-
key3: {nested: "object"},
|
|
196
|
-
},
|
|
197
|
-
null,
|
|
198
|
-
2,
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
expect(result).toBe(expected);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
165
|
const mockPrivateKey = "mocked_private_key";
|
|
205
166
|
|
|
206
167
|
beforeEach(() => {
|
|
@@ -240,4 +201,34 @@ describe("BaseAction", () => {
|
|
|
240
201
|
|
|
241
202
|
await expect(baseAction["getPrivateKey"]()).rejects.toThrow("process exited");
|
|
242
203
|
});
|
|
204
|
+
|
|
205
|
+
describe("formatOutput", () => {
|
|
206
|
+
test("should return string as is", () => {
|
|
207
|
+
expect((baseAction as any).formatOutput("Hello")).toBe("Hello");
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("should format an object", () => {
|
|
211
|
+
const data = {key: "value", num: 42};
|
|
212
|
+
const result = (baseAction as any).formatOutput(data);
|
|
213
|
+
expect(result).toBe("{ key: 'value', num: 42 }");
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("should format an error object", () => {
|
|
217
|
+
const error = new Error("Test Error");
|
|
218
|
+
const result = (baseAction as any).formatOutput(error);
|
|
219
|
+
expect(result).toContain("Error: Test Error");
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test("should format a Map object", () => {
|
|
223
|
+
const testMap = new Map([["key1", "value1"]]);
|
|
224
|
+
const result = (baseAction as any).formatOutput(testMap);
|
|
225
|
+
expect(result).toBe("Map(1) { 'key1' => 'value1' }");
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("should format a BigInt object", () => {
|
|
229
|
+
const bigIntValue = BigInt(9007199254740991);
|
|
230
|
+
const result = (baseAction as any).formatOutput(bigIntValue);
|
|
231
|
+
expect(result).toBe("9007199254740991n");
|
|
232
|
+
});
|
|
233
|
+
});
|
|
243
234
|
});
|