@ui5/logger 5.0.0-alpha.4 → 5.0.0-alpha.6
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 +19 -0
- package/lib/loggers/ProjectBuild.js +4 -2
- package/lib/loggers/Serve.js +81 -0
- package/lib/writers/Console.js +49 -23
- package/lib/writers/InteractiveConsole.js +529 -0
- package/lib/writers/interactiveConsole/format.js +31 -0
- package/lib/writers/interactiveConsole/remoteConnectionsWarning.js +19 -0
- package/lib/writers/interactiveConsole/render.js +198 -0
- package/lib/writers/interactiveConsole/state/build.js +103 -0
- package/lib/writers/interactiveConsole/state/header.js +10 -0
- package/lib/writers/interactiveConsole/state/project.js +20 -0
- package/lib/writers/interactiveConsole/state/server.js +23 -0
- package/lib/writers/internal/levelPrefix.js +25 -0
- package/package.json +10 -7
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,25 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
|
|
|
4
4
|
|
|
5
5
|
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-logger/compare/v4.0.2...HEAD).
|
|
6
6
|
|
|
7
|
+
## [5.0.0-alpha.6](https://github.com/UI5/cli/compare/logger-v5.0.0-alpha.5...logger-v5.0.0-alpha.6) (2026-07-10)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* Add live status banner to ui5 serve ([#1439](https://github.com/UI5/cli/issues/1439)) ([2a46c8b](https://github.com/UI5/cli/commit/2a46c8b97f3613314cd61507417f97b079943bce))
|
|
13
|
+
|
|
14
|
+
## [5.0.0-alpha.5](https://github.com/UI5/cli/compare/logger-v5.0.0-alpha.4...logger-v5.0.0-alpha.5) (2026-06-24)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **logger:** Add differential build logging support ([0c06880](https://github.com/UI5/cli/commit/0c0688047e699330b1a98a5845dc04b25db3db6c))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Dependencies
|
|
23
|
+
|
|
24
|
+
* Update npm dependencies ([0ac8ebb](https://github.com/UI5/cli/commit/0ac8ebbb5ffe9fc6e4455244cf5da50e4c540c5c))
|
|
25
|
+
|
|
7
26
|
## [5.0.0-alpha.4](https://github.com/UI5/cli/compare/logger-v5.0.0-alpha.3...logger-v5.0.0-alpha.4) (2026-03-24)
|
|
8
27
|
|
|
9
28
|
|
|
@@ -48,7 +48,7 @@ class ProjectBuild extends Logger {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
startTask(taskName) {
|
|
51
|
+
startTask(taskName, isDifferentialBuild) {
|
|
52
52
|
if (!this.#tasksToRun || !this.#tasksToRun.includes(taskName)) {
|
|
53
53
|
throw new Error(`loggers/ProjectBuild#startTask: Unknown task ${taskName}`);
|
|
54
54
|
}
|
|
@@ -59,6 +59,7 @@ class ProjectBuild extends Logger {
|
|
|
59
59
|
projectType: this.#projectType,
|
|
60
60
|
taskName,
|
|
61
61
|
status: "task-start",
|
|
62
|
+
isDifferentialBuild,
|
|
62
63
|
});
|
|
63
64
|
|
|
64
65
|
if (!hasListeners) {
|
|
@@ -66,7 +67,7 @@ class ProjectBuild extends Logger {
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
endTask(taskName) {
|
|
70
|
+
endTask(taskName, isDifferentialBuild) {
|
|
70
71
|
if (!this.#tasksToRun || !this.#tasksToRun.includes(taskName)) {
|
|
71
72
|
throw new Error(`loggers/ProjectBuild#endTask: Unknown task ${taskName}`);
|
|
72
73
|
}
|
|
@@ -77,6 +78,7 @@ class ProjectBuild extends Logger {
|
|
|
77
78
|
projectType: this.#projectType,
|
|
78
79
|
taskName,
|
|
79
80
|
status: "task-end",
|
|
81
|
+
isDifferentialBuild,
|
|
80
82
|
});
|
|
81
83
|
|
|
82
84
|
if (!hasListeners) {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import prettyHrtime from "pretty-hrtime";
|
|
2
|
+
import Logger from "./Logger.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Logger for emitting status events on the lifecycle of a UI5 development server
|
|
6
|
+
* (idle / stale / building / build-done / error).
|
|
7
|
+
* <br><br>
|
|
8
|
+
* Emits <code>ui5.log</code> and <code>ui5.serve-status</code> events on the
|
|
9
|
+
* [<code>process</code>]{@link https://nodejs.org/api/process.html} object, which can be handled
|
|
10
|
+
* by dedicated writers, like [@ui5/logger/writers/Console]{@link @ui5/logger/writers/Console}
|
|
11
|
+
* or the live banner shipped by <code>@ui5/cli</code>.
|
|
12
|
+
* <br><br>
|
|
13
|
+
* If no listener is attached to the event, messages are written directly to the <code>process.stderr</code> stream.
|
|
14
|
+
*
|
|
15
|
+
* @private
|
|
16
|
+
* @class
|
|
17
|
+
* @alias @ui5/logger/loggers/Serve
|
|
18
|
+
*/
|
|
19
|
+
class Serve extends Logger {
|
|
20
|
+
static SERVE_STATUS_EVENT_NAME = "ui5.serve-status";
|
|
21
|
+
|
|
22
|
+
// Emit a `ui5.serve-status` event; if no listener is attached, fall back to
|
|
23
|
+
// a plain log line at the same level. All public status methods route
|
|
24
|
+
// through here so the event payload shape (`{level, status, ...}`) and the
|
|
25
|
+
// no-listener fallback stay in sync across states.
|
|
26
|
+
#emitStatus(status, payload, fallbackMessage, {level = "info"} = {}) {
|
|
27
|
+
const hasListeners = this._emit(Serve.SERVE_STATUS_EVENT_NAME, {
|
|
28
|
+
level,
|
|
29
|
+
status,
|
|
30
|
+
...payload,
|
|
31
|
+
});
|
|
32
|
+
if (!hasListeners) {
|
|
33
|
+
this._log(level, fallbackMessage);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ready() {
|
|
38
|
+
this.#emitStatus("serve-ready", {}, `Server ready`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
stale(changedProjects) {
|
|
42
|
+
if (!changedProjects || !Array.isArray(changedProjects)) {
|
|
43
|
+
throw new Error("loggers/Serve#stale: Missing or incorrect changedProjects parameter");
|
|
44
|
+
}
|
|
45
|
+
this.#emitStatus("serve-stale", {changedProjects},
|
|
46
|
+
`Sources changed in: ${changedProjects.join(", ")}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
validating(validatingProjects) {
|
|
50
|
+
if (!validatingProjects || !Array.isArray(validatingProjects)) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"loggers/Serve#validating: Missing or incorrect validatingProjects parameter");
|
|
53
|
+
}
|
|
54
|
+
this.#emitStatus("serve-validating", {validatingProjects},
|
|
55
|
+
`Validating caches for: ${validatingProjects.join(", ")}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
building() {
|
|
59
|
+
this.#emitStatus("serve-building", {}, `Building...`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
buildDone(hrtime) {
|
|
63
|
+
if (!Array.isArray(hrtime) || hrtime.length !== 2 ||
|
|
64
|
+
typeof hrtime[0] !== "number" || typeof hrtime[1] !== "number") {
|
|
65
|
+
throw new Error("loggers/Serve#buildDone: Missing or incorrect hrtime parameter");
|
|
66
|
+
}
|
|
67
|
+
this.#emitStatus("serve-build-done", {hrtime},
|
|
68
|
+
`Build finished in ${prettyHrtime(hrtime)}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Named serveError rather than error to avoid shadowing Logger.prototype.error
|
|
72
|
+
serveError(error) {
|
|
73
|
+
if (!error) {
|
|
74
|
+
throw new Error("loggers/Serve#serveError: Missing error parameter");
|
|
75
|
+
}
|
|
76
|
+
this.#emitStatus("serve-error", {error},
|
|
77
|
+
`Server error: ${error.message || error}`, {level: "error"});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default Serve;
|
package/lib/writers/Console.js
CHANGED
|
@@ -3,6 +3,8 @@ import {chalkStderr as chalk} from "chalk";
|
|
|
3
3
|
import figures from "figures";
|
|
4
4
|
import {MultiBar} from "cli-progress";
|
|
5
5
|
import Logger from "../loggers/Logger.js";
|
|
6
|
+
import {getLevelPrefix} from "./internal/levelPrefix.js";
|
|
7
|
+
import {REMOTE_CONNECTIONS_WARNING_LINES} from "./interactiveConsole/remoteConnectionsWarning.js";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Standard handler for events emitted by @ui5/logger modules. Writes messages to
|
|
@@ -29,6 +31,8 @@ class Console {
|
|
|
29
31
|
this._handleProjectBuildStatusEvent = this.#handleProjectBuildStatusEvent.bind(this);
|
|
30
32
|
this._handleBuildMetadataEvent = this.#handleBuildMetadataEvent.bind(this);
|
|
31
33
|
this._handleProjectBuildMetadataEvent = this.#handleProjectBuildMetadataEvent.bind(this);
|
|
34
|
+
this._handleProjectResolvedEvent = this.#handleProjectResolvedEvent.bind(this);
|
|
35
|
+
this._handleServerListeningEvent = this.#handleServerListeningEvent.bind(this);
|
|
32
36
|
this._handleStop = this.disable.bind(this);
|
|
33
37
|
this.#initFiters();
|
|
34
38
|
}
|
|
@@ -109,6 +113,8 @@ class Console {
|
|
|
109
113
|
process.on("ui5.project-build-metadata", this._handleProjectBuildMetadataEvent);
|
|
110
114
|
process.on("ui5.build-status", this._handleBuildStatusEvent);
|
|
111
115
|
process.on("ui5.project-build-status", this._handleProjectBuildStatusEvent);
|
|
116
|
+
process.on("ui5.project-resolved", this._handleProjectResolvedEvent);
|
|
117
|
+
process.on("ui5.server-listening", this._handleServerListeningEvent);
|
|
112
118
|
process.on("ui5.log.stop-console", this._handleStop);
|
|
113
119
|
}
|
|
114
120
|
|
|
@@ -123,6 +129,8 @@ class Console {
|
|
|
123
129
|
process.off("ui5.project-build-metadata", this._handleProjectBuildMetadataEvent);
|
|
124
130
|
process.off("ui5.build-status", this._handleBuildStatusEvent);
|
|
125
131
|
process.off("ui5.project-build-status", this._handleProjectBuildStatusEvent);
|
|
132
|
+
process.off("ui5.project-resolved", this._handleProjectResolvedEvent);
|
|
133
|
+
process.off("ui5.server-listening", this._handleServerListeningEvent);
|
|
126
134
|
process.off("ui5.log.stop-console", this._handleStop);
|
|
127
135
|
if (this.#progressBarContainer) {
|
|
128
136
|
this.#progressBar.stop();
|
|
@@ -191,7 +199,7 @@ class Console {
|
|
|
191
199
|
if (!Logger.isLevelEnabled(level)) {
|
|
192
200
|
return;
|
|
193
201
|
}
|
|
194
|
-
const levelPrefix =
|
|
202
|
+
const levelPrefix = getLevelPrefix(level);
|
|
195
203
|
const msg = `${levelPrefix} ${message}\n`;
|
|
196
204
|
|
|
197
205
|
if (this.#progressBarContainer) {
|
|
@@ -334,7 +342,7 @@ class Console {
|
|
|
334
342
|
}
|
|
335
343
|
projectMetadata.buildSkipped = true;
|
|
336
344
|
message = `${chalk.yellow(figures.tick)} ` +
|
|
337
|
-
`Skipping build of ${projectType} project ${chalk.bold(projectName)}
|
|
345
|
+
chalk.grey(`Skipping build of ${projectType} project ${chalk.bold(projectName)}`);
|
|
338
346
|
|
|
339
347
|
// Update progress bar (if used)
|
|
340
348
|
// All tasks of this projects are completed
|
|
@@ -349,7 +357,7 @@ class Console {
|
|
|
349
357
|
this.#writeMessage(level, `${chalk.grey(buildIndex)}: ${message}`);
|
|
350
358
|
}
|
|
351
359
|
|
|
352
|
-
#handleProjectBuildStatusEvent({level, projectName, projectType, taskName, status}) {
|
|
360
|
+
#handleProjectBuildStatusEvent({level, projectName, projectType, taskName, status, isDifferentialBuild}) {
|
|
353
361
|
const {projectTasks} = this.#getProjectMetadata(projectName);
|
|
354
362
|
const taskMetadata = projectTasks.get(taskName);
|
|
355
363
|
if (!taskMetadata) {
|
|
@@ -382,7 +390,8 @@ class Console {
|
|
|
382
390
|
`for project ${projectName}, task ${taskName}`);
|
|
383
391
|
}
|
|
384
392
|
taskMetadata.executionStarted = true;
|
|
385
|
-
message =
|
|
393
|
+
message = (isDifferentialBuild ? chalk.grey(figures.lozengeOutline) : chalk.blue(figures.pointerSmall)) +
|
|
394
|
+
` Running task ${chalk.bold(taskName)}...`;
|
|
386
395
|
break;
|
|
387
396
|
case "task-end":
|
|
388
397
|
if (taskMetadata.executionEnded) {
|
|
@@ -412,7 +421,7 @@ class Console {
|
|
|
412
421
|
`Task execution already started`);
|
|
413
422
|
}
|
|
414
423
|
taskMetadata.executionEnded = true;
|
|
415
|
-
message =
|
|
424
|
+
message = chalk.yellow(figures.tick) + chalk.grey(` Skipping task ${chalk.bold(taskName)}`);
|
|
416
425
|
|
|
417
426
|
// Update progress bar (if used)
|
|
418
427
|
this._getProgressBar()?.increment(1);
|
|
@@ -426,32 +435,49 @@ class Console {
|
|
|
426
435
|
this.#writeMessage(level, `${chalk.blue(`${(projectName)}`)} ${taskIndex}${message}`);
|
|
427
436
|
}
|
|
428
437
|
|
|
429
|
-
#
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
438
|
+
#handleProjectResolvedEvent({name, type, version}) {
|
|
439
|
+
// One-line summary of the root project, mirroring the header region of
|
|
440
|
+
// the interactive writer. Kept as an info line so `ui5 build` and
|
|
441
|
+
// non-TTY `ui5 serve` still record the project identity in scrollback.
|
|
442
|
+
const versionSuffix = version ? ` (${version})` : "";
|
|
443
|
+
const typeLabel = type ? `${type} project ` : "";
|
|
444
|
+
this.#writeMessage("info", `Root project: ${typeLabel}${chalk.bold(name)}${chalk.dim(versionSuffix)}`);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
#handleServerListeningEvent({urls, acceptRemoteConnections}) {
|
|
448
|
+
if (acceptRemoteConnections) {
|
|
449
|
+
// Emit the warning as chalk-formatted lines on stderr, surrounded
|
|
450
|
+
// by blank lines and without a `warn` level prefix. The interactive
|
|
451
|
+
// writer renders the same lines inside its server region.
|
|
452
|
+
process.stderr.write("\n");
|
|
453
|
+
for (const line of REMOTE_CONNECTIONS_WARNING_LINES) {
|
|
454
|
+
process.stderr.write(line);
|
|
455
|
+
process.stderr.write("\n");
|
|
456
|
+
}
|
|
457
|
+
process.stderr.write("\n");
|
|
458
|
+
}
|
|
459
|
+
// Emit `Server started` and the local URL on stdout without a level
|
|
460
|
+
// prefix — this exact shape is a contract for scripts and users
|
|
461
|
+
// parsing the non-interactive log lines. Network URLs listed under
|
|
462
|
+
// `--accept-remote-connections` are intentionally omitted; the
|
|
463
|
+
// interactive writer is responsible for showing them.
|
|
464
|
+
if (Array.isArray(urls)) {
|
|
465
|
+
const localEntry = urls.find((entry) => entry?.label === "Local") ?? urls[0];
|
|
466
|
+
if (localEntry?.url) {
|
|
467
|
+
process.stdout.write(`Server started\nURL: ${localEntry.url}\n`);
|
|
468
|
+
}
|
|
446
469
|
}
|
|
447
470
|
}
|
|
448
471
|
|
|
449
472
|
/**
|
|
450
|
-
* Creates a new instance and subscribes it to all events
|
|
473
|
+
* Creates a new instance and subscribes it to all events. Any currently-
|
|
474
|
+
* active console-writing writer is displaced by the `ui5.log.stop-console`
|
|
475
|
+
* event emitted here.
|
|
451
476
|
*
|
|
452
477
|
* @public
|
|
453
478
|
*/
|
|
454
479
|
static init() {
|
|
480
|
+
process.emit("ui5.log.stop-console");
|
|
455
481
|
const cH = new Console();
|
|
456
482
|
cH.enable();
|
|
457
483
|
return cH;
|
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import {createLogUpdate} from "log-update";
|
|
3
|
+
import sliceAnsi from "slice-ansi";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import Logger from "../loggers/Logger.js";
|
|
6
|
+
import {getLevelPrefix} from "./internal/levelPrefix.js";
|
|
7
|
+
import {createHeaderState, setTool} from "./interactiveConsole/state/header.js";
|
|
8
|
+
import {createProjectState, setProject, enableProjectPlaceholders} from "./interactiveConsole/state/project.js";
|
|
9
|
+
import {createServerState, setListening, enableServerPlaceholders} from "./interactiveConsole/state/server.js";
|
|
10
|
+
import {
|
|
11
|
+
createBuildState, beginBuild, advanceToProject, setTask, transitionTo, setError, STATES,
|
|
12
|
+
SPINNING_STATES, enableBuildPlaceholders,
|
|
13
|
+
} from "./interactiveConsole/state/build.js";
|
|
14
|
+
import {
|
|
15
|
+
renderHeaderRegion, renderProjectRegion, renderServerRegion, renderBuildRegion,
|
|
16
|
+
} from "./interactiveConsole/render.js";
|
|
17
|
+
|
|
18
|
+
// Spinner tick interval while in `building` or `validating` state.
|
|
19
|
+
const BUILDING_TICK_MS = 120;
|
|
20
|
+
|
|
21
|
+
// Decode the tail of `stream.write(chunk[, encoding][, callback])`. `encoding`
|
|
22
|
+
// falls back to "utf8" (Node's default) when not supplied.
|
|
23
|
+
function parseWriteArgs(encodingOrCallback, maybeCallback) {
|
|
24
|
+
if (typeof encodingOrCallback === "function") {
|
|
25
|
+
return {encoding: "utf8", callback: encodingOrCallback};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
encoding: typeof encodingOrCallback === "string" ? encodingOrCallback : "utf8",
|
|
29
|
+
callback: typeof maybeCallback === "function" ? maybeCallback : undefined,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Interactive console writer for `ui5 serve` — a live, region-based status
|
|
35
|
+
* display rendered in a persistent bottom region. Owns process.stderr while
|
|
36
|
+
* active. Sibling of {@link module:@ui5/logger/writers/Console|writers/Console};
|
|
37
|
+
* exactly one console-writing writer may be active at a time.
|
|
38
|
+
* <br><br>
|
|
39
|
+
* The writer is universal: it renders whichever regions have received data.
|
|
40
|
+
* No command knowledge. Regions render top-to-bottom in a fixed order —
|
|
41
|
+
* header, root project, server, build status — and hidden regions collapse.
|
|
42
|
+
* <br><br>
|
|
43
|
+
* All state is event-driven. See the design at
|
|
44
|
+
* <code>docs/interactive-console-writer.md</code> and the public event API
|
|
45
|
+
* exposed by <code>@ui5/logger</code>.
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
* @class
|
|
49
|
+
* @alias @ui5/logger/writers/InteractiveConsole
|
|
50
|
+
*/
|
|
51
|
+
class InteractiveConsole {
|
|
52
|
+
#stderr;
|
|
53
|
+
#stopped = false;
|
|
54
|
+
|
|
55
|
+
#headerState;
|
|
56
|
+
#projectState;
|
|
57
|
+
#serverState;
|
|
58
|
+
#buildState;
|
|
59
|
+
|
|
60
|
+
#tickTimer = null;
|
|
61
|
+
#columns;
|
|
62
|
+
// `log-update` instance bound to `#stderr`. Owns the live region: every
|
|
63
|
+
// `#render()` call hands it the full multi-line frame and it diffs against
|
|
64
|
+
// the previous one, erasing wrap-correctly.
|
|
65
|
+
#logUpdate;
|
|
66
|
+
|
|
67
|
+
// True while a live-region render (or explicit persist/done) is in flight,
|
|
68
|
+
// so #interceptWrite lets log-update's own bytes through to the real
|
|
69
|
+
// stream. Any *other* write hits the interception path.
|
|
70
|
+
#renderingLiveRegion = false;
|
|
71
|
+
// Per-stream interception bookkeeping. Keyed by "stdout"/"stderr", each
|
|
72
|
+
// entry holds the saved original write method (or `null` when this stream
|
|
73
|
+
// is not being intercepted) and any partial (non-newline-terminated) bytes
|
|
74
|
+
// that arrived without a newline yet.
|
|
75
|
+
#streams = {
|
|
76
|
+
stdout: {orig: null, partial: ""},
|
|
77
|
+
stderr: {orig: null, partial: ""},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
#seenProjectResolved = false;
|
|
81
|
+
|
|
82
|
+
// Bound listeners so we can `process.off` them on stop().
|
|
83
|
+
#onLog;
|
|
84
|
+
#onBuildMetadata;
|
|
85
|
+
#onBuildStatus;
|
|
86
|
+
#onProjectBuildStatus;
|
|
87
|
+
#onServeStatus;
|
|
88
|
+
#onToolInfo;
|
|
89
|
+
#onToolMode;
|
|
90
|
+
#onProjectResolved;
|
|
91
|
+
#onServerListening;
|
|
92
|
+
#onStopConsole;
|
|
93
|
+
#onResize;
|
|
94
|
+
|
|
95
|
+
constructor({stderr = process.stderr} = {}) {
|
|
96
|
+
this.#stderr = stderr;
|
|
97
|
+
this.#headerState = createHeaderState();
|
|
98
|
+
this.#projectState = createProjectState();
|
|
99
|
+
this.#serverState = createServerState();
|
|
100
|
+
this.#buildState = createBuildState();
|
|
101
|
+
this.#columns = stderr.columns;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Attaches all event listeners and starts writing to the output stream.
|
|
106
|
+
* Emits `ui5.log.stop-console` first so any currently-active console-
|
|
107
|
+
* writing writer detaches before this one takes over.
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
enable() {
|
|
112
|
+
process.emit("ui5.log.stop-console");
|
|
113
|
+
this.#stopped = false;
|
|
114
|
+
this.#attachListeners();
|
|
115
|
+
if (!this.#logUpdate) {
|
|
116
|
+
this.#logUpdate = createLogUpdate(this.#stderr);
|
|
117
|
+
}
|
|
118
|
+
const wantsIntercept = this.#stderr === process.stderr;
|
|
119
|
+
if (wantsIntercept) {
|
|
120
|
+
this.#installWriteInterceptors();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Detaches all event listeners and stops writing to the output stream.
|
|
126
|
+
*
|
|
127
|
+
* @public
|
|
128
|
+
*/
|
|
129
|
+
disable() {
|
|
130
|
+
if (this.#stopped) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this.#stopped = true;
|
|
134
|
+
this.#clearTick();
|
|
135
|
+
this.#detachListeners();
|
|
136
|
+
// Flush any partial (non-newline-terminated) buffered writes before
|
|
137
|
+
// we tear down the live region, then restore the process.* originals.
|
|
138
|
+
// Flushing first while the live region is still on-screen keeps the
|
|
139
|
+
// trailing fragment above the final frame instead of after it.
|
|
140
|
+
this.#flushPartialBuffers();
|
|
141
|
+
this.#uninstallWriteInterceptors();
|
|
142
|
+
// `done` restores the cursor (which log-update hid on first render)
|
|
143
|
+
// and resets state. End on a clean newline so the prompt lands
|
|
144
|
+
// below the final frame.
|
|
145
|
+
this.#withRenderingGuard(() => this.#logUpdate?.done());
|
|
146
|
+
this.#stderr.write("\n");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Compose the full live region as a single string. One block per region,
|
|
150
|
+
// separated by their own leading blank line. `log-update` handles wrapping
|
|
151
|
+
// and erase of the previous frame, so we just hand it the full text.
|
|
152
|
+
#composeLiveRegion() {
|
|
153
|
+
const lines = [
|
|
154
|
+
...renderHeaderRegion(this.#headerState),
|
|
155
|
+
...renderProjectRegion(this.#projectState),
|
|
156
|
+
...renderServerRegion(this.#serverState),
|
|
157
|
+
...renderBuildRegion(this.#buildState),
|
|
158
|
+
];
|
|
159
|
+
if (lines.length === 0) {
|
|
160
|
+
return "";
|
|
161
|
+
}
|
|
162
|
+
// `log-update` wraps long lines onto additional rows; the last line is
|
|
163
|
+
// designed to fit on a single row when it's a status line, so clip it
|
|
164
|
+
// to the terminal width. `this.#columns` is undefined when stderr isn't
|
|
165
|
+
// a TTY — sliceAnsi treats that as "no limit" and returns unchanged.
|
|
166
|
+
if (this.#buildState.state !== STATES.INITIAL) {
|
|
167
|
+
lines[lines.length - 1] = sliceAnsi(lines[lines.length - 1], 0, this.#columns);
|
|
168
|
+
}
|
|
169
|
+
return lines.join("\n");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
#render() {
|
|
173
|
+
/* istanbul ignore if — defensive: #render is only called from event
|
|
174
|
+
handlers (detached on disable) and the tick timer (cleared on
|
|
175
|
+
disable), so this branch is unreachable in practice. */
|
|
176
|
+
if (this.#stopped) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
this.#withRenderingGuard(() => {
|
|
180
|
+
this.#logUpdate(this.#composeLiveRegion());
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Write a log line ABOVE the live region so it persists in scrollback.
|
|
186
|
+
*
|
|
187
|
+
* Delegates to `log-update`'s `persist()` (which erases the live region,
|
|
188
|
+
* writes the line in its place, and accounts for wrapped lines correctly)
|
|
189
|
+
* followed by a fresh render of the live region below it. Pass a string
|
|
190
|
+
* with embedded newlines to persist multiple lines in a single frame.
|
|
191
|
+
*
|
|
192
|
+
* @param {string} line The log line to write above the live region.
|
|
193
|
+
*/
|
|
194
|
+
logAbove(line) {
|
|
195
|
+
if (this.#stopped) {
|
|
196
|
+
this.#stderr.write(line + "\n");
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
this.#withRenderingGuard(() => {
|
|
200
|
+
this.#logUpdate.persist(line);
|
|
201
|
+
this.#logUpdate(this.#composeLiveRegion());
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Run `fn` with the re-render flag set so log-update's own writes to
|
|
206
|
+
// the intercepted process streams pass through untouched. Any nested
|
|
207
|
+
// stdout/stderr write inside `fn` will bypass the line-buffering path.
|
|
208
|
+
#withRenderingGuard(fn) {
|
|
209
|
+
this.#renderingLiveRegion = true;
|
|
210
|
+
try {
|
|
211
|
+
return fn();
|
|
212
|
+
} finally {
|
|
213
|
+
this.#renderingLiveRegion = false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// ---- Event subscriptions --------------------------------------------------
|
|
218
|
+
|
|
219
|
+
#attachListeners() {
|
|
220
|
+
this.#onLog = (evt) => this.#handleLog(evt);
|
|
221
|
+
this.#onBuildMetadata = (evt) => this.#handleBuildMetadata(evt);
|
|
222
|
+
this.#onBuildStatus = (evt) => this.#handleBuildStatus(evt);
|
|
223
|
+
this.#onProjectBuildStatus = (evt) => this.#handleProjectBuildStatus(evt);
|
|
224
|
+
this.#onServeStatus = (evt) => this.#handleServeStatus(evt);
|
|
225
|
+
this.#onToolInfo = (evt) => this.#handleToolInfo(evt);
|
|
226
|
+
this.#onToolMode = (evt) => this.#handleToolMode(evt);
|
|
227
|
+
this.#onProjectResolved = (evt) => this.#handleProjectResolved(evt);
|
|
228
|
+
this.#onServerListening = (evt) => this.#handleServerListening(evt);
|
|
229
|
+
this.#onStopConsole = () => this.disable();
|
|
230
|
+
this.#onResize = () => this.#handleResize();
|
|
231
|
+
|
|
232
|
+
process.on("ui5.log", this.#onLog);
|
|
233
|
+
process.on("ui5.build-metadata", this.#onBuildMetadata);
|
|
234
|
+
process.on("ui5.build-status", this.#onBuildStatus);
|
|
235
|
+
process.on("ui5.project-build-status", this.#onProjectBuildStatus);
|
|
236
|
+
process.on("ui5.serve-status", this.#onServeStatus);
|
|
237
|
+
process.on("ui5.tool-info", this.#onToolInfo);
|
|
238
|
+
process.on("ui5.tool-mode", this.#onToolMode);
|
|
239
|
+
process.on("ui5.project-resolved", this.#onProjectResolved);
|
|
240
|
+
process.on("ui5.server-listening", this.#onServerListening);
|
|
241
|
+
process.on("ui5.log.stop-console", this.#onStopConsole);
|
|
242
|
+
if (typeof this.#stderr.on === "function") {
|
|
243
|
+
this.#stderr.on("resize", this.#onResize);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
#detachListeners() {
|
|
248
|
+
process.off("ui5.log", this.#onLog);
|
|
249
|
+
process.off("ui5.build-metadata", this.#onBuildMetadata);
|
|
250
|
+
process.off("ui5.build-status", this.#onBuildStatus);
|
|
251
|
+
process.off("ui5.project-build-status", this.#onProjectBuildStatus);
|
|
252
|
+
process.off("ui5.serve-status", this.#onServeStatus);
|
|
253
|
+
process.off("ui5.tool-info", this.#onToolInfo);
|
|
254
|
+
process.off("ui5.tool-mode", this.#onToolMode);
|
|
255
|
+
process.off("ui5.project-resolved", this.#onProjectResolved);
|
|
256
|
+
process.off("ui5.server-listening", this.#onServerListening);
|
|
257
|
+
process.off("ui5.log.stop-console", this.#onStopConsole);
|
|
258
|
+
if (typeof this.#stderr.off === "function") {
|
|
259
|
+
this.#stderr.off("resize", this.#onResize);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
#handleLog({level, message, moduleName}) {
|
|
264
|
+
// The banner curates `info` away (the status line already represents
|
|
265
|
+
// the build's state). Verbose / perf / silly users hit the fallback
|
|
266
|
+
// path before the writer ever activates. Warnings and errors persist —
|
|
267
|
+
// but only if the configured log level lets them through. The standard
|
|
268
|
+
// ConsoleWriter does this filtering implicitly via its `#writeMessage`;
|
|
269
|
+
// this writer acts as its own sink here, so it has to check too.
|
|
270
|
+
if (level !== "warn" && level !== "error") {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (!Logger.isLevelEnabled(level)) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const levelPrefix = getLevelPrefix(level);
|
|
277
|
+
const formatted = moduleName ?
|
|
278
|
+
`${levelPrefix} ${chalk.blue(moduleName)} ${message}` :
|
|
279
|
+
`${levelPrefix} ${message}`;
|
|
280
|
+
this.logAbove(formatted);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
#handleToolInfo(evt) {
|
|
284
|
+
setTool(this.#headerState, evt);
|
|
285
|
+
this.#render();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Optional up-front hint from the CLI: "I'm about to run <mode>". The writer
|
|
289
|
+
// pre-populates placeholders for the sections that <mode> is expected to
|
|
290
|
+
// fill in, so the full frame is visible from the first paint and subsequent
|
|
291
|
+
// events replace placeholders in place rather than growing the layout.
|
|
292
|
+
// Currently only `mode: "serve"` is understood; unknown modes are ignored,
|
|
293
|
+
// keeping the writer forgiving as new modes are added.
|
|
294
|
+
#handleToolMode(evt) {
|
|
295
|
+
if (evt?.mode === "serve") {
|
|
296
|
+
enableProjectPlaceholders(this.#projectState);
|
|
297
|
+
enableServerPlaceholders(this.#serverState, {
|
|
298
|
+
acceptRemoteConnections: evt.acceptRemoteConnections,
|
|
299
|
+
});
|
|
300
|
+
enableBuildPlaceholders(this.#buildState);
|
|
301
|
+
this.#render();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
#handleProjectResolved(evt) {
|
|
306
|
+
if (this.#seenProjectResolved) {
|
|
307
|
+
// See docs/interactive-console-writer.md § Ordering rules: the
|
|
308
|
+
// writer's model is single-root-project. Two events means the
|
|
309
|
+
// caller's invariant is violated and any subsequent event
|
|
310
|
+
// attribution is ambiguous.
|
|
311
|
+
throw new Error(
|
|
312
|
+
`writers/InteractiveConsole: Received duplicate ui5.project-resolved event`);
|
|
313
|
+
}
|
|
314
|
+
this.#seenProjectResolved = true;
|
|
315
|
+
setProject(this.#projectState, evt);
|
|
316
|
+
this.#render();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
#handleServerListening(evt) {
|
|
320
|
+
setListening(this.#serverState, evt);
|
|
321
|
+
this.#render();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
#handleBuildMetadata({projectsToBuild}) {
|
|
325
|
+
beginBuild(this.#buildState, projectsToBuild);
|
|
326
|
+
this.#render();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
#handleBuildStatus({projectName, status}) {
|
|
330
|
+
if (status === "project-build-start" || status === "project-build-skip") {
|
|
331
|
+
advanceToProject(this.#buildState, projectName);
|
|
332
|
+
this.#render();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
#handleProjectBuildStatus({taskName, status}) {
|
|
337
|
+
if (status === "task-start") {
|
|
338
|
+
setTask(this.#buildState, taskName);
|
|
339
|
+
this.#render();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
#handleServeStatus(evt) {
|
|
344
|
+
// validatingProjects is a VALIDATING-only payload; clear it on any other
|
|
345
|
+
// transition so a stale list doesn't linger in the banner state.
|
|
346
|
+
if (evt.status !== "serve-validating") {
|
|
347
|
+
this.#buildState.validatingProjects = [];
|
|
348
|
+
}
|
|
349
|
+
switch (evt.status) {
|
|
350
|
+
case "serve-ready":
|
|
351
|
+
this.#transitionTo(STATES.READY);
|
|
352
|
+
break;
|
|
353
|
+
case "serve-stale":
|
|
354
|
+
this.#buildState.changedProjects = evt.changedProjects || [];
|
|
355
|
+
this.#transitionTo(STATES.STALE);
|
|
356
|
+
break;
|
|
357
|
+
case "serve-building":
|
|
358
|
+
beginBuild(this.#buildState, this.#buildState.projectOrder);
|
|
359
|
+
this.#transitionTo(STATES.BUILDING);
|
|
360
|
+
break;
|
|
361
|
+
case "serve-validating":
|
|
362
|
+
this.#buildState.validatingProjects = evt.validatingProjects || [];
|
|
363
|
+
this.#buildState.spinFrame = 0;
|
|
364
|
+
this.#transitionTo(STATES.VALIDATING);
|
|
365
|
+
break;
|
|
366
|
+
case "serve-build-done":
|
|
367
|
+
this.#buildState.lastBuildHrtime = Array.isArray(evt.hrtime) ? evt.hrtime : null;
|
|
368
|
+
this.#transitionTo(STATES.READY);
|
|
369
|
+
break;
|
|
370
|
+
case "serve-error":
|
|
371
|
+
setError(this.#buildState, evt.error?.message || String(evt.error));
|
|
372
|
+
this.#clearTick();
|
|
373
|
+
this.#render();
|
|
374
|
+
// Don't echo the error via logAbove — BuildServer already logs
|
|
375
|
+
// the same message at `error` level (which #handleLog scrolls
|
|
376
|
+
// above the banner), and the yargs fail-handler renders the full
|
|
377
|
+
// stack trace once the handler promise rejects. A third copy here
|
|
378
|
+
// would just be noise.
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
#handleResize() {
|
|
384
|
+
this.#columns = this.#stderr.columns;
|
|
385
|
+
this.#render();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
#transitionTo(newState) {
|
|
389
|
+
if (this.#buildState.state === newState) {
|
|
390
|
+
this.#render();
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
transitionTo(this.#buildState, newState);
|
|
394
|
+
this.#clearTick();
|
|
395
|
+
this.#scheduleTick();
|
|
396
|
+
this.#render();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
#scheduleTick() {
|
|
400
|
+
/* istanbul ignore if — defensive: #scheduleTick is only reached from
|
|
401
|
+
event handlers (detached on disable), so #stopped is always false
|
|
402
|
+
here in practice. */
|
|
403
|
+
if (this.#stopped) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (!SPINNING_STATES.has(this.#buildState.state)) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
this.#tickTimer = setInterval(() => {
|
|
410
|
+
this.#buildState.spinFrame++;
|
|
411
|
+
this.#render();
|
|
412
|
+
}, BUILDING_TICK_MS);
|
|
413
|
+
// Don't keep the event loop alive purely for the banner spinner.
|
|
414
|
+
if (typeof this.#tickTimer.unref === "function") {
|
|
415
|
+
this.#tickTimer.unref();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
#clearTick() {
|
|
420
|
+
if (this.#tickTimer) {
|
|
421
|
+
clearInterval(this.#tickTimer);
|
|
422
|
+
this.#tickTimer = null;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// ---- process.stdout / process.stderr interception -------------------------
|
|
427
|
+
// Custom tasks and third-party libraries sometimes bypass @ui5/logger and
|
|
428
|
+
// write straight to the process streams. Any such write between frames
|
|
429
|
+
// throws off log-update's line-count accounting (it counts only the bytes
|
|
430
|
+
// it emitted itself) and the next render corrupts — typically by
|
|
431
|
+
// duplicating the header. To keep the live region intact we replace
|
|
432
|
+
// process.stdout.write / process.stderr.write while the writer is active
|
|
433
|
+
// and route incoming bytes through logAbove() line by line. log-update's
|
|
434
|
+
// own writes bypass the interception via the #renderingLiveRegion flag.
|
|
435
|
+
|
|
436
|
+
#installWriteInterceptors() {
|
|
437
|
+
for (const which of ["stdout", "stderr"]) {
|
|
438
|
+
const entry = this.#streams[which];
|
|
439
|
+
entry.orig = process[which].write;
|
|
440
|
+
process[which].write = this.#makeInterceptor(process[which], entry.orig, which);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
#uninstallWriteInterceptors() {
|
|
445
|
+
for (const which of ["stdout", "stderr"]) {
|
|
446
|
+
const entry = this.#streams[which];
|
|
447
|
+
if (entry.orig) {
|
|
448
|
+
process[which].write = entry.orig;
|
|
449
|
+
entry.orig = null;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
#makeInterceptor(stream, original, which) {
|
|
455
|
+
// The returned function mirrors WriteStream#write's overloads:
|
|
456
|
+
// write(chunk[, encoding][, callback]) -> boolean
|
|
457
|
+
return (chunk, encodingOrCallback, maybeCallback) => {
|
|
458
|
+
if (this.#renderingLiveRegion || this.#stopped) {
|
|
459
|
+
return original.call(stream, chunk, encodingOrCallback, maybeCallback);
|
|
460
|
+
}
|
|
461
|
+
const {encoding, callback} = parseWriteArgs(encodingOrCallback, maybeCallback);
|
|
462
|
+
const text = typeof chunk === "string" ?
|
|
463
|
+
chunk :
|
|
464
|
+
(Buffer.isBuffer(chunk) ? chunk.toString(encoding) : Buffer.from(chunk).toString(encoding));
|
|
465
|
+
this.#absorbInterceptedText(text, which);
|
|
466
|
+
if (callback) {
|
|
467
|
+
process.nextTick(callback);
|
|
468
|
+
}
|
|
469
|
+
return true;
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
#absorbInterceptedText(text, which) {
|
|
474
|
+
const entry = this.#streams[which];
|
|
475
|
+
const combined = entry.partial + text;
|
|
476
|
+
const lastNewline = combined.lastIndexOf("\n");
|
|
477
|
+
if (lastNewline === -1) {
|
|
478
|
+
entry.partial = combined;
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
entry.partial = combined.slice(lastNewline + 1);
|
|
482
|
+
this.logAbove(combined.slice(0, lastNewline));
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
#flushPartialBuffers() {
|
|
486
|
+
for (const which of ["stdout", "stderr"]) {
|
|
487
|
+
const entry = this.#streams[which];
|
|
488
|
+
if (entry.partial) {
|
|
489
|
+
const line = entry.partial;
|
|
490
|
+
entry.partial = "";
|
|
491
|
+
this.logAbove(line);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Creates a new instance and subscribes it to all events. Any currently-
|
|
498
|
+
* active console-writing writer is displaced by the `ui5.log.stop-console`
|
|
499
|
+
* event that `enable()` emits.
|
|
500
|
+
*
|
|
501
|
+
* @public
|
|
502
|
+
*/
|
|
503
|
+
static init() {
|
|
504
|
+
const w = new InteractiveConsole();
|
|
505
|
+
w.enable();
|
|
506
|
+
return w;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
static stop() {
|
|
510
|
+
process.emit("ui5.log.stop-console");
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// ---- Test helpers ---------------------------------------------------------
|
|
514
|
+
|
|
515
|
+
/* istanbul ignore next */
|
|
516
|
+
_getStateForTest() {
|
|
517
|
+
return {
|
|
518
|
+
header: this.#headerState,
|
|
519
|
+
project: this.#projectState,
|
|
520
|
+
server: this.#serverState,
|
|
521
|
+
build: this.#buildState,
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Split from the constructor so the `log-update` factory is imported lazily
|
|
527
|
+
// and can be swapped out by tests that pass a stubbed stderr. `createLogUpdate`
|
|
528
|
+
// is a synchronous factory; the async import is not warranted.
|
|
529
|
+
export default InteractiveConsole;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import figures from "figures";
|
|
3
|
+
|
|
4
|
+
// Low-level formatting primitives — the theme (brand and accent colors, the
|
|
5
|
+
// pointer arrow, placeholder styling) shared by all region renderers.
|
|
6
|
+
|
|
7
|
+
// COLORFGBG is set by many terminals (xterm, konsole, rxvt, iTerm2, …) as
|
|
8
|
+
// "<fg>;<bg>" with ANSI color indices. Indices 0-6 and 8 are conventionally
|
|
9
|
+
// dark backgrounds. Apple Terminal, VS Code, and Windows Terminal don't set
|
|
10
|
+
// this — we fall back to the light-background palette in that case.
|
|
11
|
+
function isDarkTerminalBackground() {
|
|
12
|
+
const v = process.env.COLORFGBG;
|
|
13
|
+
if (!v) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const bg = parseInt(v.split(";").pop(), 10);
|
|
17
|
+
if (Number.isNaN(bg)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return bg < 7 || bg === 8;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const DARK_MODE = isDarkTerminalBackground();
|
|
24
|
+
const BRAND_HEX = DARK_MODE ? "#FF5A37" : "#1873B4";
|
|
25
|
+
const ACCENT_HEX = DARK_MODE ? "#FFA42C" : "#53B8DE";
|
|
26
|
+
|
|
27
|
+
export const brand = (text) => chalk.bold.hex(BRAND_HEX)(text);
|
|
28
|
+
export const accent = (text) => chalk.hex(ACCENT_HEX)(text);
|
|
29
|
+
export const accentBold = (text) => chalk.bold.hex(ACCENT_HEX)(text);
|
|
30
|
+
export const arrow = accent(figures.pointer);
|
|
31
|
+
export const placeholder = (text) => chalk.dim.italic(text);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import figures from "figures";
|
|
3
|
+
|
|
4
|
+
// Shared content for the "accepting remote connections" warning, rendered
|
|
5
|
+
// both by the interactive writer's server region and by Console.js's non-TTY
|
|
6
|
+
// fallback. Each entry is a fully chalk-formatted string; consumers just
|
|
7
|
+
// print them line by line.
|
|
8
|
+
export const REMOTE_CONNECTIONS_WARNING_LINES = Object.freeze([
|
|
9
|
+
chalk.bold.yellow(
|
|
10
|
+
`${figures.warning} This server is accepting connections from all hosts on your network`),
|
|
11
|
+
chalk.dim.underline("Please Note:"),
|
|
12
|
+
chalk.dim(`${figures.pointerSmall} `) +
|
|
13
|
+
chalk.dim.bold("This server is intended for development purposes only. Do not use it in production."),
|
|
14
|
+
chalk.dim(`${figures.pointerSmall} ` +
|
|
15
|
+
"Vulnerable (custom-)middleware can pose a threat to your system when exposed to the network."),
|
|
16
|
+
chalk.dim(`${figures.pointerSmall} ` +
|
|
17
|
+
"The use of proxy-middleware with preconfigured credentials might enable unauthorized access"),
|
|
18
|
+
chalk.dim(" to a target system for third parties on your network."),
|
|
19
|
+
]);
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import figures from "figures";
|
|
3
|
+
import prettyHrtime from "pretty-hrtime";
|
|
4
|
+
import {STATES} from "./state/build.js";
|
|
5
|
+
import {brand, accent, accentBold, arrow, placeholder} from "./format.js";
|
|
6
|
+
import {REMOTE_CONNECTIONS_WARNING_LINES} from "./remoteConnectionsWarning.js";
|
|
7
|
+
|
|
8
|
+
const SPINNER_FRAMES = ["◐", "◓", "◑", "◒"];
|
|
9
|
+
const STATE_LABEL_WIDTH = "building".length;
|
|
10
|
+
const pad = (s) => s.padEnd(STATE_LABEL_WIDTH);
|
|
11
|
+
|
|
12
|
+
// Align continuation lines (additional network URLs / extra placeholders)
|
|
13
|
+
// under the first URL slot. The arrow, single space, and "Network: " label
|
|
14
|
+
// are all fixed-width.
|
|
15
|
+
const NETWORK_INDENT = " ".repeat(`${figures.pointer} ${"Network:"} `.length);
|
|
16
|
+
|
|
17
|
+
// Order matters: header → project → server → build → status → log-above (log
|
|
18
|
+
// scrolls outside the live region). Each region emits an array of lines and
|
|
19
|
+
// is skipped entirely when it has no content, giving a stable layout that
|
|
20
|
+
// grows top-to-bottom as data arrives. Placeholders (activated by
|
|
21
|
+
// `ui5.tool-mode`) let a region occupy its final row count from the first
|
|
22
|
+
// frame — the layout stops growing once every region is present.
|
|
23
|
+
//
|
|
24
|
+
// Region blocks include a leading blank line, so joining them produces a
|
|
25
|
+
// blank separator between regions.
|
|
26
|
+
|
|
27
|
+
export function renderHeaderRegion(headerState) {
|
|
28
|
+
if (!headerState.tool) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const version = headerState.tool.version ? chalk.dim("v" + headerState.tool.version) : "";
|
|
32
|
+
return [
|
|
33
|
+
"",
|
|
34
|
+
`${brand(headerState.tool.name || "UI5 CLI")} ${version}`,
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function renderProjectRegion(projectState) {
|
|
39
|
+
if (!projectState.project && !projectState.showPlaceholders) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
const lines = [""];
|
|
43
|
+
if (projectState.project) {
|
|
44
|
+
const project = projectState.project;
|
|
45
|
+
const framework = projectState.framework;
|
|
46
|
+
const projectType = project.type ? chalk.dim(`(${project.type})`) : "";
|
|
47
|
+
const projectVersion = project.version ? chalk.dim("v" + project.version) : "";
|
|
48
|
+
lines.push(`${chalk.dim("Project")} ${chalk.bold(project.name)}` +
|
|
49
|
+
(projectType ? ` ${projectType}` : "") +
|
|
50
|
+
(projectVersion ? ` ${projectVersion}` : ""));
|
|
51
|
+
// Only emit a Framework row when the project actually declares one.
|
|
52
|
+
// For UI5 apps that get their framework from a runtime middleware
|
|
53
|
+
// (e.g. fiori-tools-proxy) the ui5.yaml has no framework config,
|
|
54
|
+
// making "(none)" misleading; omitting the row also avoids a stale
|
|
55
|
+
// "Framework resolving…" placeholder flashing before it disappears.
|
|
56
|
+
if (framework?.name) {
|
|
57
|
+
const frameworkVersion = framework.version ? ` ${framework.version}` : "";
|
|
58
|
+
lines.push(`${chalk.dim("Framework")} ${chalk.bold(framework.name + frameworkVersion)}`);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
// Placeholder mode: reserve only the Project row. The Framework row is
|
|
62
|
+
// deferred until project-resolved reveals a real framework name.
|
|
63
|
+
lines.push(`${chalk.dim("Project")} ${placeholder("resolving…")}`);
|
|
64
|
+
}
|
|
65
|
+
return lines;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function renderServerRegion(serverState) {
|
|
69
|
+
if (!serverState.urls && !serverState.showPlaceholders) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const lines = [""];
|
|
73
|
+
|
|
74
|
+
if (serverState.urls) {
|
|
75
|
+
// The event's `urls` list carries labels ("Local"/"Network") shaped by
|
|
76
|
+
// the server. Preserve the current two-line "Local" / "Network" layout
|
|
77
|
+
// by splitting labels here.
|
|
78
|
+
const local = [];
|
|
79
|
+
const network = [];
|
|
80
|
+
const other = [];
|
|
81
|
+
for (const entry of serverState.urls) {
|
|
82
|
+
if (entry.label === "Local") {
|
|
83
|
+
local.push(entry);
|
|
84
|
+
} else if (entry.label === "Network") {
|
|
85
|
+
network.push(entry);
|
|
86
|
+
} else {
|
|
87
|
+
other.push(entry);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (local.length > 0) {
|
|
92
|
+
lines.push(`${arrow} ${accentBold("Local:")} ${accent(local[0].url)}`);
|
|
93
|
+
}
|
|
94
|
+
if (network.length > 0) {
|
|
95
|
+
lines.push(`${arrow} ${accentBold("Network:")} ${accent(network[0].url)}`);
|
|
96
|
+
for (let i = 1; i < network.length; i++) {
|
|
97
|
+
lines.push(`${NETWORK_INDENT}${accent(network[i].url)}`);
|
|
98
|
+
}
|
|
99
|
+
} else if (!serverState.acceptRemoteConnections && local.length > 0) {
|
|
100
|
+
lines.push(`${arrow} ${accentBold("Network:")} ` +
|
|
101
|
+
chalk.dim("use --accept-remote-connections to expose"));
|
|
102
|
+
}
|
|
103
|
+
for (const entry of other) {
|
|
104
|
+
lines.push(`${arrow} ${accentBold(entry.label + ":")} ${accent(entry.url)}`);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
// Placeholder mode: reserve one "Local:" row plus either the
|
|
108
|
+
// remote-connections hint (when the flag isn't set) or a single
|
|
109
|
+
// "Network:" placeholder. The frame may grow by additional rows once
|
|
110
|
+
// the real URL list arrives; that's acceptable for this uncommon case.
|
|
111
|
+
lines.push(`${arrow} ${accentBold("Local:")} ${placeholder("binding…")}`);
|
|
112
|
+
if (serverState.acceptRemoteConnections) {
|
|
113
|
+
lines.push(`${arrow} ${accentBold("Network:")} ${placeholder("binding…")}`);
|
|
114
|
+
} else {
|
|
115
|
+
lines.push(`${arrow} ${accentBold("Network:")} ` +
|
|
116
|
+
chalk.dim("use --accept-remote-connections to expose"));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// `acceptRemoteConnections` reflects user intent, so the warning appears
|
|
121
|
+
// from the first frame even while URLs are still placeholders.
|
|
122
|
+
if (serverState.acceptRemoteConnections) {
|
|
123
|
+
lines.push("");
|
|
124
|
+
for (const line of REMOTE_CONNECTIONS_WARNING_LINES) {
|
|
125
|
+
lines.push(line);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return lines;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function renderBuildRegion(buildState) {
|
|
132
|
+
if (buildState.state === STATES.INITIAL) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
return ["", renderStatusLine(buildState)];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function renderStatusLine(state) {
|
|
139
|
+
const label = `${chalk.dim("Status")} `;
|
|
140
|
+
switch (state.state) {
|
|
141
|
+
case STATES.STARTING:
|
|
142
|
+
return `${label}${chalk.dim(figures.circle)} ${chalk.dim(pad("starting"))}`;
|
|
143
|
+
case STATES.READY: {
|
|
144
|
+
let suffix = "";
|
|
145
|
+
if (state.lastBuildHrtime) {
|
|
146
|
+
suffix = ` ${chalk.dim("·")} ${chalk.dim("Time elapsed: " + prettyHrtime(state.lastBuildHrtime))}`;
|
|
147
|
+
}
|
|
148
|
+
return `${label}${chalk.green(figures.bullet)} ${chalk.green(pad("ready"))}${suffix}`;
|
|
149
|
+
}
|
|
150
|
+
case STATES.STALE:
|
|
151
|
+
return `${label}${chalk.yellow(figures.circle)} ${chalk.yellow(pad("stale"))} ` +
|
|
152
|
+
`${chalk.dim("· files changed, rebuild on next request")}`;
|
|
153
|
+
case STATES.VALIDATING: {
|
|
154
|
+
const frame = SPINNER_FRAMES[state.spinFrame % SPINNER_FRAMES.length];
|
|
155
|
+
const parts = [
|
|
156
|
+
`${chalk.cyan(frame)} ${chalk.cyan(pad("validating cache"))}`,
|
|
157
|
+
chalk.dim("·"),
|
|
158
|
+
chalk.dim("checking dependency caches"),
|
|
159
|
+
];
|
|
160
|
+
const count = state.validatingProjects.length;
|
|
161
|
+
if (count > 0) {
|
|
162
|
+
parts.push(chalk.dim("·"), chalk.dim(`${count} project${count === 1 ? "" : "s"}`));
|
|
163
|
+
}
|
|
164
|
+
return `${label}${parts.join(" ")}`;
|
|
165
|
+
}
|
|
166
|
+
case STATES.BUILDING: {
|
|
167
|
+
const frame = SPINNER_FRAMES[state.spinFrame % SPINNER_FRAMES.length];
|
|
168
|
+
const parts = [
|
|
169
|
+
`${chalk.yellow(frame)} ${chalk.yellow(pad("building"))}`,
|
|
170
|
+
];
|
|
171
|
+
if (state.totalProjects > 0 && state.currentProjectIndex > 0) {
|
|
172
|
+
const counterWidth = String(state.totalProjects).length;
|
|
173
|
+
const counter = `${String(state.currentProjectIndex).padStart(counterWidth)}` +
|
|
174
|
+
`/${state.totalProjects} projects`;
|
|
175
|
+
parts.push(chalk.dim("·"), chalk.dim(counter));
|
|
176
|
+
}
|
|
177
|
+
if (state.currentProjectName) {
|
|
178
|
+
const padded = state.projectNameWidth ?
|
|
179
|
+
state.currentProjectName.padEnd(state.projectNameWidth) :
|
|
180
|
+
state.currentProjectName;
|
|
181
|
+
parts.push(chalk.dim("·"), chalk.bold(padded));
|
|
182
|
+
}
|
|
183
|
+
if (state.currentTaskName) {
|
|
184
|
+
const padded = state.taskNameWidth ?
|
|
185
|
+
state.currentTaskName.padEnd(state.taskNameWidth) :
|
|
186
|
+
state.currentTaskName;
|
|
187
|
+
parts.push(chalk.dim("·"), chalk.dim(padded));
|
|
188
|
+
}
|
|
189
|
+
return `${label}${parts.join(" ")}`;
|
|
190
|
+
}
|
|
191
|
+
case STATES.ERROR: {
|
|
192
|
+
const msg = state.errorMessage ? ` · ${state.errorMessage}` : "";
|
|
193
|
+
return `${label}${chalk.red(figures.cross)} ${chalk.red(pad("error"))}${chalk.dim(msg)}`;
|
|
194
|
+
}
|
|
195
|
+
default:
|
|
196
|
+
return label;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Region 5 — build. Populated by `ui5.build-metadata`, `ui5.build-status`,
|
|
2
|
+
// `ui5.project-build-metadata`, `ui5.project-build-status`, `ui5.serve-status`.
|
|
3
|
+
|
|
4
|
+
export const STATES = Object.freeze({
|
|
5
|
+
INITIAL: "initial",
|
|
6
|
+
STARTING: "starting", // pre-populated placeholder before the first real state arrives
|
|
7
|
+
READY: "ready",
|
|
8
|
+
STALE: "stale",
|
|
9
|
+
BUILDING: "building",
|
|
10
|
+
VALIDATING: "validating",
|
|
11
|
+
ERROR: "error",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// States that animate a spinner. Consulted by both the tick scheduler in the
|
|
15
|
+
// interactive console writer and the status-line renderer, so a state either
|
|
16
|
+
// spins in both places or in neither.
|
|
17
|
+
export const SPINNING_STATES = new Set([STATES.BUILDING, STATES.VALIDATING]);
|
|
18
|
+
|
|
19
|
+
export function createBuildState() {
|
|
20
|
+
return {
|
|
21
|
+
state: STATES.INITIAL,
|
|
22
|
+
// During `building`: current project counter (1-based) and total projects.
|
|
23
|
+
// Both are reset by `ui5.build-metadata` and by `serve-building`.
|
|
24
|
+
currentProjectIndex: 0,
|
|
25
|
+
totalProjects: 0,
|
|
26
|
+
currentProjectName: "",
|
|
27
|
+
currentTaskName: "",
|
|
28
|
+
// Names of projects collected via `serve-stale` payloads — used to label
|
|
29
|
+
// the stale state if/when the renderer wants to.
|
|
30
|
+
changedProjects: [],
|
|
31
|
+
// Names of projects collected via `serve-validating` payloads — used to
|
|
32
|
+
// label the validating state if/when the renderer wants to.
|
|
33
|
+
validatingProjects: [],
|
|
34
|
+
// Frame counter for the spinner (incremented by the tick loop).
|
|
35
|
+
spinFrame: 0,
|
|
36
|
+
// Most recent error captured by `serve-error`.
|
|
37
|
+
errorMessage: "",
|
|
38
|
+
// Duration of the most recent successful build, captured from the
|
|
39
|
+
// `serve-build-done` event as a [seconds, nanoseconds] tuple — the same
|
|
40
|
+
// shape that pretty-hrtime consumes, so the renderer can hand it
|
|
41
|
+
// straight through.
|
|
42
|
+
lastBuildHrtime: null,
|
|
43
|
+
// Layout hints derived from build-metadata: pad the project/task columns
|
|
44
|
+
// so status-line updates don't reflow.
|
|
45
|
+
projectNameWidth: 0,
|
|
46
|
+
taskNameWidth: 0,
|
|
47
|
+
// Ordered list of projects announced by build-metadata. Used to compute
|
|
48
|
+
// a stable 1-based `currentProjectIndex` when build-status events arrive.
|
|
49
|
+
projectOrder: [],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Zero the transient counters for a fresh build. Shared by `build-metadata`
|
|
54
|
+
// and the `serve-building` branch of `serve-status`; see doc item #7.
|
|
55
|
+
function resetBuildProgress(state) {
|
|
56
|
+
state.currentProjectIndex = 0;
|
|
57
|
+
state.currentProjectName = "";
|
|
58
|
+
state.currentTaskName = "";
|
|
59
|
+
state.spinFrame = 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function beginBuild(state, projectOrder) {
|
|
63
|
+
state.projectOrder = Array.from(projectOrder);
|
|
64
|
+
state.totalProjects = state.projectOrder.length;
|
|
65
|
+
state.projectNameWidth = state.projectOrder.reduce(
|
|
66
|
+
(max, name) => Math.max(max, name.length), 0);
|
|
67
|
+
resetBuildProgress(state);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function advanceToProject(state, projectName) {
|
|
71
|
+
const idx = state.projectOrder.indexOf(projectName);
|
|
72
|
+
state.currentProjectIndex = idx >= 0 ?
|
|
73
|
+
idx + 1 :
|
|
74
|
+
state.currentProjectIndex + 1;
|
|
75
|
+
state.currentProjectName = projectName;
|
|
76
|
+
state.currentTaskName = "";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function setTask(state, taskName) {
|
|
80
|
+
state.currentTaskName = taskName;
|
|
81
|
+
if (taskName.length > state.taskNameWidth) {
|
|
82
|
+
state.taskNameWidth = taskName.length;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function transitionTo(state, newState) {
|
|
87
|
+
state.state = newState;
|
|
88
|
+
state.spinFrame = 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function setError(state, message) {
|
|
92
|
+
state.errorMessage = message || "";
|
|
93
|
+
transitionTo(state, STATES.ERROR);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Advance the region into a "starting" placeholder state so the Status row is
|
|
97
|
+
// visible from the first frame. Called from `ui5.tool-mode`. Real state
|
|
98
|
+
// transitions (READY/BUILDING/…) replace it.
|
|
99
|
+
export function enableBuildPlaceholders(state) {
|
|
100
|
+
if (state.state === STATES.INITIAL) {
|
|
101
|
+
state.state = STATES.STARTING;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Region 1 — header. Populated by `ui5.tool-info`. Set once, never changes.
|
|
2
|
+
export function createHeaderState() {
|
|
3
|
+
return {
|
|
4
|
+
tool: null, // {name, version} — null while unknown
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function setTool(state, tool) {
|
|
9
|
+
state.tool = tool ? {name: tool.name, version: tool.version} : null;
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Region 2 — root project. Populated by `ui5.project-resolved`.
|
|
2
|
+
export function createProjectState() {
|
|
3
|
+
return {
|
|
4
|
+
project: null, // {name, type, version}
|
|
5
|
+
framework: null, // {name, version} | null
|
|
6
|
+
// When true, the region renders dim "resolving…" placeholders in place
|
|
7
|
+
// of real data. Enabled by `ui5.tool-mode` before the graph is built so
|
|
8
|
+
// the layout is stable from the very first frame.
|
|
9
|
+
showPlaceholders: false,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function setProject(state, evt) {
|
|
14
|
+
state.project = {name: evt.name, type: evt.type, version: evt.version};
|
|
15
|
+
state.framework = evt.framework ? {name: evt.framework.name, version: evt.framework.version} : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function enableProjectPlaceholders(state) {
|
|
19
|
+
state.showPlaceholders = true;
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Region 4 — server. Populated by `ui5.server-listening`.
|
|
2
|
+
export function createServerState() {
|
|
3
|
+
return {
|
|
4
|
+
urls: null, // Array<{label, url}> | null
|
|
5
|
+
acceptRemoteConnections: false,
|
|
6
|
+
// When true, the region renders "binding…" placeholders in place of real
|
|
7
|
+
// URLs. Enabled by `ui5.tool-mode` so the section is visible from the
|
|
8
|
+
// first frame; `acceptRemoteConnections` fine-tunes what gets reserved.
|
|
9
|
+
showPlaceholders: false,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function setListening(state, evt) {
|
|
14
|
+
state.urls = Array.isArray(evt.urls) ? evt.urls.map((u) => ({label: u.label, url: u.url})) : [];
|
|
15
|
+
state.acceptRemoteConnections = !!evt.acceptRemoteConnections;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function enableServerPlaceholders(state, {acceptRemoteConnections} = {}) {
|
|
19
|
+
state.showPlaceholders = true;
|
|
20
|
+
if (typeof acceptRemoteConnections === "boolean") {
|
|
21
|
+
state.acceptRemoteConnections = acceptRemoteConnections;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {chalkStderr as chalk} from "chalk";
|
|
2
|
+
|
|
3
|
+
// Shared level-prefix renderer used by every console-writing writer so scrolled
|
|
4
|
+
// log lines look identical regardless of which writer produced them. Kept as
|
|
5
|
+
// an internal helper module rather than a public export — the exact styling is
|
|
6
|
+
// an implementation detail of `writers/Console` and its siblings.
|
|
7
|
+
export function getLevelPrefix(level) {
|
|
8
|
+
switch (level) {
|
|
9
|
+
case "silly":
|
|
10
|
+
return chalk.inverse(level);
|
|
11
|
+
case "verbose":
|
|
12
|
+
return chalk.cyan("verb");
|
|
13
|
+
case "perf":
|
|
14
|
+
return chalk.bgYellow.red(level);
|
|
15
|
+
case "info":
|
|
16
|
+
return chalk.green(level);
|
|
17
|
+
case "warn":
|
|
18
|
+
return chalk.yellow(level);
|
|
19
|
+
case "error":
|
|
20
|
+
return chalk.bgRed.white(level);
|
|
21
|
+
default:
|
|
22
|
+
// Log level silent does not produce messages
|
|
23
|
+
throw new Error(`writers/internal/levelPrefix: Invalid message log level "${level}"`);
|
|
24
|
+
}
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui5/logger",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.6",
|
|
4
4
|
"description": "UI5 CLI - Internal Logger",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SAP SE",
|
|
@@ -50,16 +50,19 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"chalk": "^5.6.2",
|
|
52
52
|
"cli-progress": "^3.12.0",
|
|
53
|
-
"figures": "^6.1.0"
|
|
53
|
+
"figures": "^6.1.0",
|
|
54
|
+
"log-update": "^8.0.0",
|
|
55
|
+
"pretty-hrtime": "^1.0.3",
|
|
56
|
+
"slice-ansi": "^5.0.0"
|
|
54
57
|
},
|
|
55
58
|
"devDependencies": {
|
|
56
59
|
"@istanbuljs/esm-loader-hook": "^0.3.0",
|
|
57
60
|
"ava": "^6.4.1",
|
|
58
61
|
"cross-env": "^10.1.0",
|
|
59
|
-
"eslint": "^
|
|
60
|
-
"nyc": "^
|
|
61
|
-
"rimraf": "^6.
|
|
62
|
-
"sinon": "^21.
|
|
63
|
-
"strip-ansi": "^7.
|
|
62
|
+
"eslint": "^10.5.0",
|
|
63
|
+
"nyc": "^18.0.0",
|
|
64
|
+
"rimraf": "^6.1.3",
|
|
65
|
+
"sinon": "^21.1.2",
|
|
66
|
+
"strip-ansi": "^7.2.0"
|
|
64
67
|
}
|
|
65
68
|
}
|