1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.DebugLogger = void 0;
|
7 |
|
8 | function _fsExtra() {
|
9 | const data = require("fs-extra");
|
10 |
|
11 | _fsExtra = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _util() {
|
19 | const data = require("./util");
|
20 |
|
21 | _util = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | class DebugLogger {
|
29 | constructor(isEnabled = true) {
|
30 | this.isEnabled = isEnabled;
|
31 | this.data = {};
|
32 | }
|
33 |
|
34 | add(key, value) {
|
35 | if (!this.isEnabled) {
|
36 | return;
|
37 | }
|
38 |
|
39 | const dataPath = key.split(".");
|
40 | let o = this.data;
|
41 | let lastName = null;
|
42 |
|
43 | for (const p of dataPath) {
|
44 | if (p === dataPath[dataPath.length - 1]) {
|
45 | lastName = p;
|
46 | break;
|
47 | } else {
|
48 | if (o[p] == null) {
|
49 | o[p] = Object.create(null);
|
50 | } else if (typeof o[p] === "string") {
|
51 | o[p] = [o[p]];
|
52 | }
|
53 |
|
54 | o = o[p];
|
55 | }
|
56 | }
|
57 |
|
58 | if (Array.isArray(o[lastName])) {
|
59 | o[lastName].push(value);
|
60 | } else {
|
61 | o[lastName] = value;
|
62 | }
|
63 | }
|
64 |
|
65 | save(file) {
|
66 |
|
67 | if (this.isEnabled && Object.keys(this.data).length > 0) {
|
68 | return (0, _fsExtra().outputFile)(file, (0, _util().serializeToYaml)(this.data));
|
69 | } else {
|
70 | return Promise.resolve();
|
71 | }
|
72 | }
|
73 |
|
74 | } exports.DebugLogger = DebugLogger;
|
75 |
|
76 |
|
\ | No newline at end of file |