@cenk1cenk2/oclif-common 4.0.2 → 5.0.0
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/dist/index.d.ts +19 -32
- package/dist/index.js +428 -286
- package/package.json +10 -11
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
4
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
5
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -7,6 +8,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
7
8
|
return require.apply(this, arguments);
|
|
8
9
|
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
9
10
|
});
|
|
11
|
+
var __publicField = (obj, key, value) => {
|
|
12
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
10
15
|
|
|
11
16
|
// src/commands/base.command.ts
|
|
12
17
|
var _core = require('@oclif/core');
|
|
@@ -15,30 +20,34 @@ var _readline = require('readline');
|
|
|
15
20
|
require('reflect-metadata');
|
|
16
21
|
|
|
17
22
|
// src/constants/file.constants.ts
|
|
18
|
-
var FileConstants
|
|
23
|
+
var FileConstants;
|
|
24
|
+
(function(FileConstants2) {
|
|
19
25
|
FileConstants2["CONFIG_SERVICE_DEFAULTS_DIR"] = "config";
|
|
20
|
-
|
|
21
|
-
})(FileConstants || {});
|
|
26
|
+
})(FileConstants || (FileConstants = exports.FileConstants = {}));
|
|
22
27
|
|
|
23
28
|
// src/constants/help-groups.constants.ts
|
|
24
|
-
var HelpGroups
|
|
29
|
+
var HelpGroups;
|
|
30
|
+
(function(HelpGroups2) {
|
|
25
31
|
HelpGroups2["CLI"] = "CLI";
|
|
26
|
-
|
|
27
|
-
})(HelpGroups || {});
|
|
32
|
+
})(HelpGroups || (HelpGroups = exports.HelpGroups = {}));
|
|
28
33
|
|
|
29
34
|
// src/interfaces/oclif.interface.ts
|
|
30
35
|
|
|
31
36
|
|
|
32
|
-
// src/utils/logger/listr
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
// src/utils/logger/pipe/pipe-process-to-listr.ts
|
|
38
|
+
function pipeProcessThroughListr(task, instance) {
|
|
39
|
+
instance.stdout.pipe(task.stdout());
|
|
40
|
+
instance.stderr.pipe(task.stdout());
|
|
41
|
+
return instance;
|
|
42
|
+
}
|
|
43
|
+
__name(pipeProcessThroughListr, "pipeProcessThroughListr");
|
|
36
44
|
|
|
37
|
-
|
|
38
|
-
var
|
|
45
|
+
// src/utils/logger/pipe/pipe-process-to-logger.ts
|
|
46
|
+
var _stream = require('stream');
|
|
39
47
|
|
|
40
48
|
// src/utils/logger/logger.constants.ts
|
|
41
|
-
var LogLevels
|
|
49
|
+
var LogLevels;
|
|
50
|
+
(function(LogLevels2) {
|
|
42
51
|
LogLevels2["SILENT"] = "SILENT";
|
|
43
52
|
LogLevels2["DIRECT"] = "DIRECT";
|
|
44
53
|
LogLevels2["FATAL"] = "FATAL";
|
|
@@ -48,26 +57,105 @@ var LogLevels = /* @__PURE__ */ ((LogLevels2) => {
|
|
|
48
57
|
LogLevels2["VERBOSE"] = "VERBOSE";
|
|
49
58
|
LogLevels2["DEBUG"] = "DEBUG";
|
|
50
59
|
LogLevels2["TRACE"] = "TRACE";
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
})(LogLevels || (LogLevels = exports.LogLevels = {}));
|
|
61
|
+
var LogFieldStatus;
|
|
62
|
+
(function(LogFieldStatus2) {
|
|
54
63
|
LogFieldStatus2["RUN"] = "run";
|
|
55
64
|
LogFieldStatus2["END"] = "end";
|
|
56
65
|
LogFieldStatus2["STAGE"] = "stage";
|
|
57
66
|
LogFieldStatus2["EXIT"] = "exit";
|
|
58
67
|
LogFieldStatus2["TERMINATE"] = "terminate";
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
})(LogFieldStatus || (LogFieldStatus = exports.LogFieldStatus = {}));
|
|
69
|
+
|
|
70
|
+
// src/utils/logger/pipe/pipe-process-to-logger.ts
|
|
71
|
+
function pipeProcessToLogger(logger, instance, options) {
|
|
72
|
+
options = {
|
|
73
|
+
start: LogLevels.INFO,
|
|
74
|
+
end: LogLevels.INFO,
|
|
75
|
+
stdout: LogLevels.INFO,
|
|
76
|
+
stderr: LogLevels.WARN,
|
|
77
|
+
...options
|
|
78
|
+
};
|
|
79
|
+
if (options.start) {
|
|
80
|
+
logger.run(instance.spawnargs.join(" "), {
|
|
81
|
+
level: options.start,
|
|
82
|
+
context: options.context
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (instance.stdout) {
|
|
86
|
+
const writable = new (0, _stream.Writable)();
|
|
87
|
+
writable.write = (chunk) => {
|
|
88
|
+
logger.log(options.stdout, chunk, {
|
|
89
|
+
context: options.context
|
|
90
|
+
});
|
|
91
|
+
return true;
|
|
92
|
+
};
|
|
93
|
+
instance.stdout.pipe(writable);
|
|
94
|
+
}
|
|
95
|
+
if (instance.stderr) {
|
|
96
|
+
const writable = new (0, _stream.Writable)();
|
|
97
|
+
writable.write = (chunk) => {
|
|
98
|
+
logger.log(options.stderr, chunk, {
|
|
99
|
+
context: options.context
|
|
100
|
+
});
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
103
|
+
instance.stderr.pipe(writable);
|
|
104
|
+
}
|
|
105
|
+
void instance.on("exit", (code, signal) => {
|
|
106
|
+
const message = `Process ended with code ${code}${signal ? ` and signal ${signal}` : ""}.`;
|
|
107
|
+
logger.debug(message, {
|
|
108
|
+
context: options.context
|
|
109
|
+
});
|
|
110
|
+
if (options.end) {
|
|
111
|
+
logger.end(instance.spawnargs.join(" "), {
|
|
112
|
+
level: options.end,
|
|
113
|
+
context: options.context
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (_optionalChain([options, 'optionalAccess', _2 => _2.callback])) {
|
|
117
|
+
options.callback();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
void instance.on("error", (error) => {
|
|
121
|
+
logger.fatal(error.message, {
|
|
122
|
+
context: options.context
|
|
123
|
+
});
|
|
124
|
+
logger.debug(error.stack, {
|
|
125
|
+
context: options.context
|
|
126
|
+
});
|
|
127
|
+
if (_optionalChain([options, 'optionalAccess', _3 => _3.callback])) {
|
|
128
|
+
options.callback(error);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return instance;
|
|
132
|
+
}
|
|
133
|
+
__name(pipeProcessToLogger, "pipeProcessToLogger");
|
|
134
|
+
|
|
135
|
+
// src/utils/logger/logger.ts
|
|
136
|
+
|
|
137
|
+
var _os = require('os');
|
|
138
|
+
var _winston = require('winston'); var _winston2 = _interopRequireDefault(_winston);
|
|
61
139
|
|
|
62
140
|
// src/lib/config/config.service.ts
|
|
63
141
|
var _objectpathimmutable = require('object-path-immutable'); var _objectpathimmutable2 = _interopRequireDefault(_objectpathimmutable);
|
|
64
142
|
var _path = require('path');
|
|
65
143
|
|
|
144
|
+
// src/lib/config/config.constants.ts
|
|
145
|
+
var ConfigEnvKeys;
|
|
146
|
+
(function(ConfigEnvKeys2) {
|
|
147
|
+
ConfigEnvKeys2["NAME"] = "__name";
|
|
148
|
+
ConfigEnvKeys2["PARSER"] = "__format";
|
|
149
|
+
ConfigEnvKeys2["ELEMENT"] = "__element";
|
|
150
|
+
ConfigEnvKeys2["ELEMENT_REPLACER"] = "${i}";
|
|
151
|
+
})(ConfigEnvKeys || (ConfigEnvKeys = {}));
|
|
152
|
+
|
|
66
153
|
// src/lib/parser/env-parser.service.ts
|
|
67
154
|
|
|
68
155
|
var _EnvironmentVariableParser = class {
|
|
69
156
|
constructor() {
|
|
70
|
-
this
|
|
157
|
+
__publicField(this, "logger");
|
|
158
|
+
__publicField(this, "LINE", /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm);
|
|
71
159
|
if (_EnvironmentVariableParser.instance) {
|
|
72
160
|
return _EnvironmentVariableParser.instance;
|
|
73
161
|
}
|
|
@@ -97,11 +185,15 @@ var _EnvironmentVariableParser = class {
|
|
|
97
185
|
};
|
|
98
186
|
var EnvironmentVariableParser = _EnvironmentVariableParser;
|
|
99
187
|
__name(EnvironmentVariableParser, "EnvironmentVariableParser");
|
|
100
|
-
EnvironmentVariableParser
|
|
188
|
+
__publicField(EnvironmentVariableParser, "extensions", [
|
|
189
|
+
"env"
|
|
190
|
+
]);
|
|
191
|
+
__publicField(EnvironmentVariableParser, "instance");
|
|
101
192
|
|
|
102
193
|
// src/lib/parser/json-parser.service.ts
|
|
103
194
|
var _JsonParser = class {
|
|
104
195
|
constructor() {
|
|
196
|
+
__publicField(this, "logger");
|
|
105
197
|
if (_JsonParser.instance) {
|
|
106
198
|
return _JsonParser.instance;
|
|
107
199
|
}
|
|
@@ -123,12 +215,16 @@ var _JsonParser = class {
|
|
|
123
215
|
};
|
|
124
216
|
var JsonParser = _JsonParser;
|
|
125
217
|
__name(JsonParser, "JsonParser");
|
|
126
|
-
JsonParser
|
|
218
|
+
__publicField(JsonParser, "extensions", [
|
|
219
|
+
"json"
|
|
220
|
+
]);
|
|
221
|
+
__publicField(JsonParser, "instance");
|
|
127
222
|
|
|
128
223
|
// src/lib/parser/yaml-parser.service.ts
|
|
129
224
|
var _yaml = require('yaml');
|
|
130
225
|
var _YamlParser = class {
|
|
131
226
|
constructor() {
|
|
227
|
+
__publicField(this, "logger");
|
|
132
228
|
if (_YamlParser.instance) {
|
|
133
229
|
return _YamlParser.instance;
|
|
134
230
|
}
|
|
@@ -145,22 +241,29 @@ var _YamlParser = class {
|
|
|
145
241
|
}
|
|
146
242
|
}
|
|
147
243
|
stringify(data) {
|
|
148
|
-
return _yaml.stringify.call(void 0, data, {
|
|
244
|
+
return _yaml.stringify.call(void 0, data, {
|
|
245
|
+
prettyErrors: true
|
|
246
|
+
});
|
|
149
247
|
}
|
|
150
248
|
};
|
|
151
249
|
var YamlParser = _YamlParser;
|
|
152
250
|
__name(YamlParser, "YamlParser");
|
|
153
|
-
YamlParser
|
|
251
|
+
__publicField(YamlParser, "extensions", [
|
|
252
|
+
"yaml",
|
|
253
|
+
"yml"
|
|
254
|
+
]);
|
|
255
|
+
__publicField(YamlParser, "instance");
|
|
154
256
|
|
|
155
257
|
// src/lib/fs/filesystem.service.ts
|
|
156
258
|
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
157
259
|
|
|
158
|
-
var
|
|
260
|
+
var _FileSystemService = class {
|
|
159
261
|
constructor() {
|
|
160
|
-
|
|
161
|
-
|
|
262
|
+
__publicField(this, "logger");
|
|
263
|
+
if (_FileSystemService.instance) {
|
|
264
|
+
return _FileSystemService.instance;
|
|
162
265
|
} else {
|
|
163
|
-
|
|
266
|
+
_FileSystemService.instance = this;
|
|
164
267
|
this.logger = new Logger(this.constructor.name);
|
|
165
268
|
this.logger.trace("Created a new instance.");
|
|
166
269
|
}
|
|
@@ -169,7 +272,9 @@ var FileSystemService = class {
|
|
|
169
272
|
return _fsextra2.default.existsSync(path);
|
|
170
273
|
}
|
|
171
274
|
stats(path) {
|
|
172
|
-
return _fsextra2.default.statSync(path, {
|
|
275
|
+
return _fsextra2.default.statSync(path, {
|
|
276
|
+
throwIfNoEntry: true
|
|
277
|
+
});
|
|
173
278
|
}
|
|
174
279
|
dirname(path) {
|
|
175
280
|
return _path.dirname.call(void 0, path);
|
|
@@ -195,14 +300,20 @@ var FileSystemService = class {
|
|
|
195
300
|
}
|
|
196
301
|
async write(file, data, options = {}) {
|
|
197
302
|
try {
|
|
198
|
-
await _fsextra2.default.writeFile(file, data, typeof options === "object" ? {
|
|
303
|
+
await _fsextra2.default.writeFile(file, data, typeof options === "object" ? {
|
|
304
|
+
encoding: "utf-8",
|
|
305
|
+
...options
|
|
306
|
+
} : options);
|
|
199
307
|
} catch (e) {
|
|
200
308
|
throw new Error(`Error while writing file to "${file}": ${e.message}`);
|
|
201
309
|
}
|
|
202
310
|
}
|
|
203
311
|
writeSync(file, data, options = {}) {
|
|
204
312
|
try {
|
|
205
|
-
_fsextra2.default.writeFileSync(file, data, typeof options === "object" ? {
|
|
313
|
+
_fsextra2.default.writeFileSync(file, data, typeof options === "object" ? {
|
|
314
|
+
encoding: "utf-8",
|
|
315
|
+
...options
|
|
316
|
+
} : options);
|
|
206
317
|
} catch (e) {
|
|
207
318
|
throw new Error(`Error while writing file to "${file}": ${e.message}`);
|
|
208
319
|
}
|
|
@@ -278,21 +389,29 @@ var FileSystemService = class {
|
|
|
278
389
|
}
|
|
279
390
|
}
|
|
280
391
|
};
|
|
392
|
+
var FileSystemService = _FileSystemService;
|
|
281
393
|
__name(FileSystemService, "FileSystemService");
|
|
394
|
+
__publicField(FileSystemService, "instance");
|
|
282
395
|
|
|
283
396
|
// src/lib/parser/parser.service.ts
|
|
284
|
-
var
|
|
397
|
+
var _ParserService = class {
|
|
285
398
|
constructor(parsers) {
|
|
286
|
-
this
|
|
287
|
-
|
|
288
|
-
|
|
399
|
+
__publicField(this, "parsers", [
|
|
400
|
+
YamlParser,
|
|
401
|
+
JsonParser,
|
|
402
|
+
EnvironmentVariableParser
|
|
403
|
+
]);
|
|
404
|
+
__publicField(this, "logger");
|
|
405
|
+
__publicField(this, "fs");
|
|
406
|
+
if (_ParserService.instance) {
|
|
407
|
+
return _ParserService.instance;
|
|
289
408
|
} else {
|
|
290
409
|
if (parsers) {
|
|
291
410
|
this.parsers = parsers;
|
|
292
411
|
}
|
|
293
412
|
this.logger = new Logger(this.constructor.name);
|
|
294
413
|
this.fs = new FileSystemService();
|
|
295
|
-
|
|
414
|
+
_ParserService.instance = this;
|
|
296
415
|
this.logger.trace("Created a new instance.");
|
|
297
416
|
}
|
|
298
417
|
}
|
|
@@ -306,17 +425,11 @@ var ParserService = class {
|
|
|
306
425
|
}
|
|
307
426
|
setParsers(...parsers) {
|
|
308
427
|
this.parsers = parsers;
|
|
309
|
-
this.logger.trace(
|
|
310
|
-
"Set parsers: %s",
|
|
311
|
-
this.parsers.map((p) => p.name)
|
|
312
|
-
);
|
|
428
|
+
this.logger.trace("Set parsers: %s", this.parsers.map((p) => p.name));
|
|
313
429
|
}
|
|
314
430
|
addParsers(...parsers) {
|
|
315
431
|
this.parsers.push(...parsers);
|
|
316
|
-
this.logger.trace(
|
|
317
|
-
"Added parser, current parsers: %s",
|
|
318
|
-
this.parsers.map((p) => p.name)
|
|
319
|
-
);
|
|
432
|
+
this.logger.trace("Added parser, current parsers: %s", this.parsers.map((p) => p.name));
|
|
320
433
|
}
|
|
321
434
|
async read(file) {
|
|
322
435
|
return this.parse(file, await this.fs.read(file));
|
|
@@ -335,38 +448,48 @@ var ParserService = class {
|
|
|
335
448
|
return parser.stringify(data);
|
|
336
449
|
}
|
|
337
450
|
};
|
|
451
|
+
var ParserService = _ParserService;
|
|
338
452
|
__name(ParserService, "ParserService");
|
|
453
|
+
__publicField(ParserService, "instance");
|
|
339
454
|
|
|
340
455
|
// src/utils/color.ts
|
|
341
456
|
var _colorette = require('colorette'); var colorette = _interopRequireWildcard(_colorette);
|
|
342
|
-
var color = colorette.createColors({
|
|
457
|
+
var color = colorette.createColors({
|
|
458
|
+
useColor: true
|
|
459
|
+
});
|
|
343
460
|
|
|
344
461
|
// src/utils/environment.ts
|
|
345
462
|
function isVerbose(logLevel) {
|
|
346
|
-
return logLevel ===
|
|
463
|
+
return logLevel === LogLevels.VERBOSE;
|
|
347
464
|
}
|
|
348
465
|
__name(isVerbose, "isVerbose");
|
|
349
466
|
function isDebug(logLevel) {
|
|
350
|
-
return [
|
|
467
|
+
return [
|
|
468
|
+
LogLevels.DEBUG,
|
|
469
|
+
LogLevels.TRACE
|
|
470
|
+
].includes(logLevel);
|
|
351
471
|
}
|
|
352
472
|
__name(isDebug, "isDebug");
|
|
353
473
|
function isSilent(logLevel) {
|
|
354
|
-
return logLevel ===
|
|
474
|
+
return logLevel === LogLevels.SILENT;
|
|
355
475
|
}
|
|
356
476
|
__name(isSilent, "isSilent");
|
|
357
477
|
|
|
358
478
|
// src/utils/merge.constants.ts
|
|
359
|
-
var MergeStrategy
|
|
479
|
+
var MergeStrategy;
|
|
480
|
+
(function(MergeStrategy2) {
|
|
360
481
|
MergeStrategy2["OVERWRITE"] = "OVERWRITE";
|
|
361
482
|
MergeStrategy2["EXTEND"] = "EXTEND";
|
|
362
|
-
|
|
363
|
-
})(MergeStrategy || {});
|
|
483
|
+
})(MergeStrategy || (MergeStrategy = exports.MergeStrategy = {}));
|
|
364
484
|
|
|
365
485
|
// src/utils/merge.ts
|
|
366
486
|
var _deepmerge = require('deepmerge'); var _deepmerge2 = _interopRequireDefault(_deepmerge);
|
|
367
487
|
function merge(strategy, ...source) {
|
|
368
488
|
return _deepmerge2.default.all(source, {
|
|
369
|
-
arrayMerge: strategy ===
|
|
489
|
+
arrayMerge: strategy === MergeStrategy.EXTEND ? (dest, src) => [
|
|
490
|
+
...dest,
|
|
491
|
+
...src
|
|
492
|
+
].filter(uniqueFilter) : (_, src) => src
|
|
370
493
|
});
|
|
371
494
|
}
|
|
372
495
|
__name(merge, "merge");
|
|
@@ -377,7 +500,7 @@ __name(uniqueFilter, "uniqueFilter");
|
|
|
377
500
|
|
|
378
501
|
// src/utils/defaults.ts
|
|
379
502
|
function setCtxDefaults(ctx, ...defaults) {
|
|
380
|
-
_optionalChain([defaults, 'optionalAccess',
|
|
503
|
+
_optionalChain([defaults, 'optionalAccess', _4 => _4.forEach, 'call', _5 => _5((i) => {
|
|
381
504
|
if (typeof i === "object" && !Array.isArray(i)) {
|
|
382
505
|
Object.assign(ctx, i);
|
|
383
506
|
}
|
|
@@ -386,7 +509,7 @@ function setCtxDefaults(ctx, ...defaults) {
|
|
|
386
509
|
__name(setCtxDefaults, "setCtxDefaults");
|
|
387
510
|
function setCtxAssign(ctx, ...assigns) {
|
|
388
511
|
assigns.forEach((assign) => {
|
|
389
|
-
_optionalChain([assign, 'optionalAccess',
|
|
512
|
+
_optionalChain([assign, 'optionalAccess', _6 => _6.keys, 'access', _7 => _7.forEach, 'call', _8 => _8((i) => {
|
|
390
513
|
if (assign.from[i]) {
|
|
391
514
|
ctx[i] = assign.from[i];
|
|
392
515
|
}
|
|
@@ -399,20 +522,34 @@ __name(setCtxAssign, "setCtxAssign");
|
|
|
399
522
|
|
|
400
523
|
|
|
401
524
|
// src/lib/config/config.service.ts
|
|
402
|
-
var
|
|
525
|
+
var _ConfigService = class {
|
|
403
526
|
constructor(oclif, command, config) {
|
|
527
|
+
__publicField(this, "oclif");
|
|
528
|
+
__publicField(this, "command");
|
|
529
|
+
__publicField(this, "defaults");
|
|
530
|
+
__publicField(this, "root");
|
|
531
|
+
__publicField(this, "parser");
|
|
532
|
+
__publicField(this, "logLevel");
|
|
533
|
+
__publicField(this, "isVerbose");
|
|
534
|
+
__publicField(this, "isDebug");
|
|
535
|
+
__publicField(this, "isSilent");
|
|
536
|
+
__publicField(this, "ci");
|
|
537
|
+
__publicField(this, "json");
|
|
538
|
+
__publicField(this, "logger");
|
|
404
539
|
this.oclif = oclif;
|
|
405
540
|
this.command = command;
|
|
406
|
-
if (
|
|
407
|
-
return
|
|
541
|
+
if (_ConfigService.instance) {
|
|
542
|
+
return _ConfigService.instance;
|
|
408
543
|
}
|
|
409
544
|
this.root = this.oclif.root;
|
|
410
|
-
this.defaults = _path.join.call(void 0, this.oclif.root,
|
|
411
|
-
this.logger = new Logger(this.constructor.name, {
|
|
545
|
+
this.defaults = _path.join.call(void 0, this.oclif.root, FileConstants.CONFIG_SERVICE_DEFAULTS_DIR);
|
|
546
|
+
this.logger = new Logger(this.constructor.name, {
|
|
547
|
+
level: config.logLevel
|
|
548
|
+
});
|
|
412
549
|
Object.assign(this, config);
|
|
413
550
|
this.recalculate();
|
|
414
551
|
this.parser = new ParserService();
|
|
415
|
-
|
|
552
|
+
_ConfigService.instance = this;
|
|
416
553
|
this.logger.trace("Created a new instance.");
|
|
417
554
|
}
|
|
418
555
|
async read(path) {
|
|
@@ -420,22 +557,20 @@ var ConfigService = class {
|
|
|
420
557
|
this.logger.trace("Read config from: %s", path);
|
|
421
558
|
return config;
|
|
422
559
|
}
|
|
423
|
-
async extend(paths, strategy =
|
|
560
|
+
async extend(paths, strategy = MergeStrategy.OVERWRITE) {
|
|
424
561
|
this.logger.trace("Will generate config from: %o with %s", paths, strategy);
|
|
425
|
-
const configs = (await Promise.all(
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
})
|
|
435
|
-
)).filter(Boolean);
|
|
562
|
+
const configs = (await Promise.all(paths.map(async (path) => {
|
|
563
|
+
try {
|
|
564
|
+
const config = typeof path === "string" ? await this.parser.read(path) : path;
|
|
565
|
+
this.logger.trace("Extending config from: %s", path);
|
|
566
|
+
return config;
|
|
567
|
+
} catch (e) {
|
|
568
|
+
this.logger.trace("Failed to extend config from: %s", e.message);
|
|
569
|
+
}
|
|
570
|
+
}))).filter(Boolean);
|
|
436
571
|
return this.merge(configs, strategy);
|
|
437
572
|
}
|
|
438
|
-
merge(configs, strategy =
|
|
573
|
+
merge(configs, strategy = MergeStrategy.OVERWRITE) {
|
|
439
574
|
if (configs.length === 0) {
|
|
440
575
|
throw new Error("Nothing to merge, configuration files are empty.");
|
|
441
576
|
}
|
|
@@ -445,35 +580,44 @@ var ConfigService = class {
|
|
|
445
580
|
const env = typeof definition === "string" ? await this.parser.read(definition) : definition;
|
|
446
581
|
this.logger.trace("Environment variable extensions read: %o", definition);
|
|
447
582
|
const iter = /* @__PURE__ */ __name(async (obj, parent) => {
|
|
448
|
-
const data = await Promise.all(
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
if ("__name" /* NAME */ in value && "__format" /* PARSER */ in value) {
|
|
460
|
-
const variable = [
|
|
461
|
-
{
|
|
462
|
-
key: location,
|
|
463
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
464
|
-
env: value["__name" /* NAME */],
|
|
465
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
466
|
-
parser: value["__format" /* PARSER */],
|
|
467
|
-
extensions
|
|
468
|
-
}
|
|
469
|
-
];
|
|
470
|
-
return variable;
|
|
471
|
-
} else {
|
|
472
|
-
return iter(value, location);
|
|
583
|
+
const data = await Promise.all(Object.entries(obj).map(async ([key, value]) => {
|
|
584
|
+
const location = [
|
|
585
|
+
..._nullishCoalesce(parent, () => ( [])),
|
|
586
|
+
key
|
|
587
|
+
];
|
|
588
|
+
if (typeof value === "string") {
|
|
589
|
+
return [
|
|
590
|
+
{
|
|
591
|
+
key: location,
|
|
592
|
+
env: value
|
|
473
593
|
}
|
|
594
|
+
];
|
|
595
|
+
} else if (typeof value === "object") {
|
|
596
|
+
let extensions;
|
|
597
|
+
if (ConfigEnvKeys.ELEMENT in value) {
|
|
598
|
+
extensions = await iter(value[ConfigEnvKeys.ELEMENT], [
|
|
599
|
+
...location,
|
|
600
|
+
ConfigEnvKeys.ELEMENT
|
|
601
|
+
]);
|
|
602
|
+
this.logger.trace("Expanding location to elements: %s -> %s", location, extensions.map((extension) => extension.key.join(".")).join(", "));
|
|
474
603
|
}
|
|
475
|
-
|
|
476
|
-
|
|
604
|
+
if (ConfigEnvKeys.NAME in value && ConfigEnvKeys.PARSER in value) {
|
|
605
|
+
const variable = [
|
|
606
|
+
{
|
|
607
|
+
key: location,
|
|
608
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
609
|
+
env: value[ConfigEnvKeys.NAME],
|
|
610
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
611
|
+
parser: value[ConfigEnvKeys.PARSER],
|
|
612
|
+
extensions
|
|
613
|
+
}
|
|
614
|
+
];
|
|
615
|
+
return variable;
|
|
616
|
+
} else {
|
|
617
|
+
return iter(value, location);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}));
|
|
477
621
|
return data.flatMap((d) => d).filter(Boolean);
|
|
478
622
|
}, "iter");
|
|
479
623
|
const parsed = await iter(env);
|
|
@@ -504,8 +648,8 @@ var ConfigService = class {
|
|
|
504
648
|
}
|
|
505
649
|
const extensions = variable.extensions.map((extension) => {
|
|
506
650
|
const clone = JSON.parse(JSON.stringify(extension));
|
|
507
|
-
clone.env = clone.env.replace(
|
|
508
|
-
clone.key[clone.key.findIndex((value) => value ===
|
|
651
|
+
clone.env = clone.env.replace(ConfigEnvKeys.ELEMENT_REPLACER, i.toString());
|
|
652
|
+
clone.key[clone.key.findIndex((value) => value === ConfigEnvKeys.ELEMENT)] = i.toString();
|
|
509
653
|
data = process.env[clone.env];
|
|
510
654
|
if (!data) {
|
|
511
655
|
this.logger.trace("No extension for environment variable: %s -> %s", clone.key.join("."), clone.env);
|
|
@@ -532,12 +676,21 @@ var ConfigService = class {
|
|
|
532
676
|
this.isSilent = isSilent(this.logLevel);
|
|
533
677
|
}
|
|
534
678
|
};
|
|
679
|
+
var ConfigService = _ConfigService;
|
|
535
680
|
__name(ConfigService, "ConfigService");
|
|
681
|
+
__publicField(ConfigService, "instance");
|
|
536
682
|
|
|
537
683
|
// src/lib/locker/locker.service.ts
|
|
538
684
|
|
|
539
685
|
var LockerService = class {
|
|
540
686
|
constructor(file, parser, root, context) {
|
|
687
|
+
__publicField(this, "file");
|
|
688
|
+
__publicField(this, "parser");
|
|
689
|
+
__publicField(this, "root");
|
|
690
|
+
__publicField(this, "toLock");
|
|
691
|
+
__publicField(this, "toUnlock");
|
|
692
|
+
__publicField(this, "logger");
|
|
693
|
+
__publicField(this, "fs");
|
|
541
694
|
this.file = file;
|
|
542
695
|
this.parser = parser;
|
|
543
696
|
this.root = root;
|
|
@@ -557,10 +710,16 @@ var LockerService = class {
|
|
|
557
710
|
return this.toUnlock.length > 0;
|
|
558
711
|
}
|
|
559
712
|
addLock(...data) {
|
|
560
|
-
this.toLock = [
|
|
713
|
+
this.toLock = [
|
|
714
|
+
...this.toLock,
|
|
715
|
+
...data
|
|
716
|
+
];
|
|
561
717
|
}
|
|
562
718
|
addUnlock(...data) {
|
|
563
|
-
this.toUnlock = [
|
|
719
|
+
this.toUnlock = [
|
|
720
|
+
...this.toUnlock,
|
|
721
|
+
...data
|
|
722
|
+
];
|
|
564
723
|
}
|
|
565
724
|
async lockAll() {
|
|
566
725
|
if (this.hasLock()) {
|
|
@@ -581,13 +740,13 @@ var LockerService = class {
|
|
|
581
740
|
async lock(...data) {
|
|
582
741
|
let lock = await _asyncNullishCoalesce(await this.tryRead(), async () => ( {}));
|
|
583
742
|
data.forEach((d) => {
|
|
584
|
-
if (_optionalChain([d, 'optionalAccess',
|
|
743
|
+
if (_optionalChain([d, 'optionalAccess', _9 => _9.enabled]) === false) {
|
|
585
744
|
return;
|
|
586
|
-
} else if (!_optionalChain([d, 'optionalAccess',
|
|
745
|
+
} else if (!_optionalChain([d, 'optionalAccess', _10 => _10.data]) || Array.isArray(_optionalChain([d, 'optionalAccess', _11 => _11.data])) && d.data.length === 0 || typeof _optionalChain([d, 'optionalAccess', _12 => _12.data]) === "object" && Object.keys(d.data).length === 0) {
|
|
587
746
|
return;
|
|
588
747
|
}
|
|
589
748
|
const path = this.buildPath(d);
|
|
590
|
-
if (_optionalChain([d, 'optionalAccess',
|
|
749
|
+
if (_optionalChain([d, 'optionalAccess', _13 => _13.merge])) {
|
|
591
750
|
let parsed;
|
|
592
751
|
if (typeof d.data === "object") {
|
|
593
752
|
parsed = merge(d.merge, _objectpathimmutable2.default.get(lock, path, Array.isArray(d.data) ? [] : {}), d.data);
|
|
@@ -612,7 +771,7 @@ var LockerService = class {
|
|
|
612
771
|
}
|
|
613
772
|
if (data.length > 0) {
|
|
614
773
|
data.forEach((d) => {
|
|
615
|
-
if (_optionalChain([d, 'optionalAccess',
|
|
774
|
+
if (_optionalChain([d, 'optionalAccess', _14 => _14.enabled]) === false) {
|
|
616
775
|
return;
|
|
617
776
|
}
|
|
618
777
|
const path = this.buildPath(d);
|
|
@@ -653,8 +812,11 @@ var LockerService = class {
|
|
|
653
812
|
return this.fs.write(this.file, this.parser.stringify(data));
|
|
654
813
|
}
|
|
655
814
|
buildPath(d) {
|
|
656
|
-
if (_optionalChain([d, 'optionalAccess',
|
|
657
|
-
return [
|
|
815
|
+
if (_optionalChain([d, 'optionalAccess', _15 => _15.root]) !== true && _optionalChain([this, 'access', _16 => _16.root, 'optionalAccess', _17 => _17.length])) {
|
|
816
|
+
return [
|
|
817
|
+
...this.root,
|
|
818
|
+
...this.normalizePath(d.path)
|
|
819
|
+
];
|
|
658
820
|
}
|
|
659
821
|
return this.normalizePath(d.path);
|
|
660
822
|
}
|
|
@@ -670,13 +832,13 @@ var LockerService = class {
|
|
|
670
832
|
__name(LockerService, "LockerService");
|
|
671
833
|
|
|
672
834
|
// src/lib/store/store.service.ts
|
|
673
|
-
var
|
|
835
|
+
var _StoreService = class {
|
|
674
836
|
constructor() {
|
|
675
|
-
this
|
|
676
|
-
if (
|
|
677
|
-
return
|
|
837
|
+
__publicField(this, "store", {});
|
|
838
|
+
if (_StoreService.instance) {
|
|
839
|
+
return _StoreService.instance;
|
|
678
840
|
} else {
|
|
679
|
-
|
|
841
|
+
_StoreService.instance = this;
|
|
680
842
|
}
|
|
681
843
|
}
|
|
682
844
|
has(key) {
|
|
@@ -690,16 +852,20 @@ var StoreService = class {
|
|
|
690
852
|
return data;
|
|
691
853
|
}
|
|
692
854
|
};
|
|
855
|
+
var StoreService = _StoreService;
|
|
693
856
|
__name(StoreService, "StoreService");
|
|
857
|
+
__publicField(StoreService, "instance");
|
|
694
858
|
|
|
695
859
|
// src/lib/validator/validator.service.ts
|
|
696
860
|
var _classtransformer = require('class-transformer');
|
|
697
861
|
var _classvalidator = require('class-validator');
|
|
698
|
-
var
|
|
862
|
+
var _ValidatorService = class {
|
|
699
863
|
constructor(options) {
|
|
864
|
+
__publicField(this, "options");
|
|
865
|
+
__publicField(this, "logger");
|
|
700
866
|
this.options = options;
|
|
701
|
-
if (
|
|
702
|
-
return
|
|
867
|
+
if (_ValidatorService.instance) {
|
|
868
|
+
return _ValidatorService.instance;
|
|
703
869
|
}
|
|
704
870
|
this.options = {
|
|
705
871
|
validator: {
|
|
@@ -708,16 +874,24 @@ var ValidatorService = class {
|
|
|
708
874
|
always: true,
|
|
709
875
|
enableDebugMessages: true
|
|
710
876
|
},
|
|
711
|
-
transformer: {
|
|
877
|
+
transformer: {
|
|
878
|
+
enableImplicitConversion: true
|
|
879
|
+
},
|
|
712
880
|
..._nullishCoalesce(options, () => ( {}))
|
|
713
881
|
};
|
|
714
882
|
this.logger = new Logger(this.constructor.name);
|
|
715
|
-
|
|
883
|
+
_ValidatorService.instance = this;
|
|
716
884
|
this.logger.trace("Created a new instance.");
|
|
717
885
|
}
|
|
718
886
|
async validate(classType, object, options) {
|
|
719
|
-
const classObject = _classtransformer.plainToClass.call(void 0, classType, object, {
|
|
720
|
-
|
|
887
|
+
const classObject = _classtransformer.plainToClass.call(void 0, classType, object, {
|
|
888
|
+
...this.options.transformer,
|
|
889
|
+
..._nullishCoalesce(_optionalChain([options, 'optionalAccess', _18 => _18.transformer]), () => ( {}))
|
|
890
|
+
});
|
|
891
|
+
const errors = await _classvalidator.validate.call(void 0, classObject, {
|
|
892
|
+
...this.options.validator,
|
|
893
|
+
..._nullishCoalesce(_optionalChain([options, 'optionalAccess', _19 => _19.validator]), () => ( {}))
|
|
894
|
+
});
|
|
721
895
|
if (errors.length) {
|
|
722
896
|
errors.forEach((error) => {
|
|
723
897
|
this.logValidationError(error);
|
|
@@ -727,8 +901,14 @@ var ValidatorService = class {
|
|
|
727
901
|
return classObject;
|
|
728
902
|
}
|
|
729
903
|
validateSync(classType, object, options) {
|
|
730
|
-
const classObject = _classtransformer.plainToClass.call(void 0, classType, object, {
|
|
731
|
-
|
|
904
|
+
const classObject = _classtransformer.plainToClass.call(void 0, classType, object, {
|
|
905
|
+
...this.options.transformer,
|
|
906
|
+
..._nullishCoalesce(_optionalChain([options, 'optionalAccess', _20 => _20.transformer]), () => ( {}))
|
|
907
|
+
});
|
|
908
|
+
const errors = _classvalidator.validateSync.call(void 0, classObject, {
|
|
909
|
+
...this.options.validator,
|
|
910
|
+
..._nullishCoalesce(_optionalChain([options, 'optionalAccess', _21 => _21.validator]), () => ( {}))
|
|
911
|
+
});
|
|
732
912
|
if (errors.length) {
|
|
733
913
|
errors.forEach((error) => {
|
|
734
914
|
this.logValidationError(error);
|
|
@@ -741,7 +921,9 @@ var ValidatorService = class {
|
|
|
741
921
|
this.logger.error('Field "%s" failed validation with value "%s": %o', err.property, err.value, err.constraints);
|
|
742
922
|
}
|
|
743
923
|
};
|
|
924
|
+
var ValidatorService = _ValidatorService;
|
|
744
925
|
__name(ValidatorService, "ValidatorService");
|
|
926
|
+
__publicField(ValidatorService, "instance");
|
|
745
927
|
|
|
746
928
|
// src/lib/setup.ts
|
|
747
929
|
function setup() {
|
|
@@ -779,14 +961,17 @@ function setup() {
|
|
|
779
961
|
__name(setup, "setup");
|
|
780
962
|
|
|
781
963
|
// src/utils/logger/logger.ts
|
|
782
|
-
var
|
|
964
|
+
var _Logger = class {
|
|
783
965
|
constructor(context, options) {
|
|
966
|
+
__publicField(this, "context");
|
|
967
|
+
__publicField(this, "options");
|
|
968
|
+
__publicField(this, "logger");
|
|
784
969
|
this.context = context;
|
|
785
970
|
this.options = options;
|
|
786
|
-
if (
|
|
787
|
-
this.logger =
|
|
971
|
+
if (_Logger.instance) {
|
|
972
|
+
this.logger = _Logger.instance;
|
|
788
973
|
} else if (context === ConfigService.name) {
|
|
789
|
-
const level = Object.values(LogLevels).includes(_optionalChain([options, 'optionalAccess',
|
|
974
|
+
const level = Object.values(LogLevels).includes(_optionalChain([options, 'optionalAccess', _22 => _22.level])) ? options.level : LogLevels.INFO;
|
|
790
975
|
this.options = {
|
|
791
976
|
useIcons: true,
|
|
792
977
|
...options,
|
|
@@ -794,7 +979,7 @@ var Logger = class {
|
|
|
794
979
|
};
|
|
795
980
|
this.logger = this.initiateLogger();
|
|
796
981
|
this.trace("Logger singleton initiated from context: %s", context);
|
|
797
|
-
|
|
982
|
+
_Logger.instance = this.logger;
|
|
798
983
|
} else {
|
|
799
984
|
throw new Error("Logger can only be initiated inside the config service context!");
|
|
800
985
|
}
|
|
@@ -803,38 +988,44 @@ var Logger = class {
|
|
|
803
988
|
return this.parseMessage(level, data, args);
|
|
804
989
|
}
|
|
805
990
|
direct(data, ...args) {
|
|
806
|
-
return this.parseMessage(
|
|
991
|
+
return this.parseMessage(LogLevels.DIRECT, data, args);
|
|
807
992
|
}
|
|
808
993
|
fatal(data, ...args) {
|
|
809
|
-
return this.parseMessage(
|
|
994
|
+
return this.parseMessage(LogLevels.FATAL, data, args);
|
|
810
995
|
}
|
|
811
996
|
error(data, ...args) {
|
|
812
|
-
return this.parseMessage(
|
|
997
|
+
return this.parseMessage(LogLevels.ERROR, data, args);
|
|
813
998
|
}
|
|
814
999
|
warn(data, ...args) {
|
|
815
|
-
return this.parseMessage(
|
|
1000
|
+
return this.parseMessage(LogLevels.WARN, data, args);
|
|
816
1001
|
}
|
|
817
1002
|
info(data, ...args) {
|
|
818
|
-
return this.parseMessage(
|
|
1003
|
+
return this.parseMessage(LogLevels.INFO, data, args);
|
|
819
1004
|
}
|
|
820
1005
|
debug(data, ...args) {
|
|
821
|
-
return this.parseMessage(
|
|
1006
|
+
return this.parseMessage(LogLevels.DEBUG, data, args);
|
|
822
1007
|
}
|
|
823
1008
|
verbose(data, ...args) {
|
|
824
|
-
return this.parseMessage(
|
|
1009
|
+
return this.parseMessage(LogLevels.VERBOSE, data, args);
|
|
825
1010
|
}
|
|
826
1011
|
trace(data, ...args) {
|
|
827
|
-
return this.parseMessage(
|
|
1012
|
+
return this.parseMessage(LogLevels.TRACE, data, args);
|
|
828
1013
|
}
|
|
829
1014
|
// status levels
|
|
830
1015
|
run(data, ...args) {
|
|
831
|
-
return this.parseMessage(
|
|
1016
|
+
return this.parseMessage(LogLevels.INFO, data, args, {
|
|
1017
|
+
status: LogFieldStatus.RUN
|
|
1018
|
+
});
|
|
832
1019
|
}
|
|
833
1020
|
end(data, ...args) {
|
|
834
|
-
return this.parseMessage(
|
|
1021
|
+
return this.parseMessage(LogLevels.INFO, data, args, {
|
|
1022
|
+
status: LogFieldStatus.END
|
|
1023
|
+
});
|
|
835
1024
|
}
|
|
836
1025
|
stage(data, ...args) {
|
|
837
|
-
return this.parseMessage(
|
|
1026
|
+
return this.parseMessage(LogLevels.TRACE, data, args, {
|
|
1027
|
+
status: LogFieldStatus.STAGE
|
|
1028
|
+
});
|
|
838
1029
|
}
|
|
839
1030
|
initiateLogger() {
|
|
840
1031
|
const logFormat = _winston.format.printf(({ level, message, context, status }) => {
|
|
@@ -853,30 +1044,40 @@ var Logger = class {
|
|
|
853
1044
|
});
|
|
854
1045
|
const logger = _winston2.default.createLogger({
|
|
855
1046
|
level: this.options.level,
|
|
856
|
-
format: _winston.format.combine(_winston.format.splat(), _winston.format.json({
|
|
1047
|
+
format: _winston.format.combine(_winston.format.splat(), _winston.format.json({
|
|
1048
|
+
space: 2
|
|
1049
|
+
}), _winston.format.prettyPrint(), logFormat),
|
|
857
1050
|
levels: Object.values(LogLevels).reduce((o, level, i) => {
|
|
858
1051
|
return {
|
|
859
1052
|
...o,
|
|
860
1053
|
[level]: i
|
|
861
1054
|
};
|
|
862
1055
|
}, {}),
|
|
863
|
-
silent: this.options.level ===
|
|
1056
|
+
silent: this.options.level === LogLevels.SILENT,
|
|
864
1057
|
transports: [
|
|
865
1058
|
new _winston.transports.Console({
|
|
866
|
-
stderrLevels: [
|
|
1059
|
+
stderrLevels: [
|
|
1060
|
+
LogLevels.FATAL,
|
|
1061
|
+
LogLevels.ERROR
|
|
1062
|
+
]
|
|
867
1063
|
})
|
|
868
1064
|
]
|
|
869
1065
|
});
|
|
870
|
-
logger.log(
|
|
1066
|
+
logger.log(LogLevels.TRACE, "Initiated new logger with level: %s", this.options.level, {
|
|
1067
|
+
context: this.constructor.name
|
|
1068
|
+
});
|
|
871
1069
|
return logger;
|
|
872
1070
|
}
|
|
873
1071
|
parseMessage(level, data, args, format2) {
|
|
874
|
-
if (!this.logger && !
|
|
1072
|
+
if (!this.logger && !_Logger.instance) {
|
|
875
1073
|
return;
|
|
876
|
-
} else if (
|
|
877
|
-
this.logger =
|
|
1074
|
+
} else if (_Logger.instance) {
|
|
1075
|
+
this.logger = _Logger.instance;
|
|
878
1076
|
}
|
|
879
|
-
this.logger.log(level, data.toString(), ..._nullishCoalesce(args, () => ( [])), {
|
|
1077
|
+
this.logger.log(level, data.toString(), ..._nullishCoalesce(args, () => ( [])), {
|
|
1078
|
+
context: this.context,
|
|
1079
|
+
..._nullishCoalesce(format2, () => ( {}))
|
|
1080
|
+
});
|
|
880
1081
|
}
|
|
881
1082
|
logColoring({ level, message, context, status }) {
|
|
882
1083
|
let icon;
|
|
@@ -887,49 +1088,49 @@ var Logger = class {
|
|
|
887
1088
|
return input;
|
|
888
1089
|
}, "msgColoring");
|
|
889
1090
|
switch (level) {
|
|
890
|
-
case
|
|
1091
|
+
case LogLevels.DIRECT:
|
|
891
1092
|
return message;
|
|
892
|
-
case
|
|
1093
|
+
case LogLevels.FATAL:
|
|
893
1094
|
coloring = /* @__PURE__ */ __name((input) => color.red(input), "coloring");
|
|
894
|
-
if (_optionalChain([this, 'access',
|
|
1095
|
+
if (_optionalChain([this, 'access', _23 => _23.options, 'optionalAccess', _24 => _24.useIcons])) {
|
|
895
1096
|
icon = _listr2.figures.checkboxOn;
|
|
896
1097
|
}
|
|
897
1098
|
break;
|
|
898
|
-
case
|
|
1099
|
+
case LogLevels.ERROR:
|
|
899
1100
|
coloring = color.red;
|
|
900
|
-
if (_optionalChain([this, 'access',
|
|
1101
|
+
if (_optionalChain([this, 'access', _25 => _25.options, 'optionalAccess', _26 => _26.useIcons])) {
|
|
901
1102
|
icon = _listr2.figures.cross;
|
|
902
1103
|
}
|
|
903
1104
|
break;
|
|
904
|
-
case
|
|
1105
|
+
case LogLevels.WARN:
|
|
905
1106
|
coloring = color.yellow;
|
|
906
|
-
if (_optionalChain([this, 'access',
|
|
1107
|
+
if (_optionalChain([this, 'access', _27 => _27.options, 'optionalAccess', _28 => _28.useIcons])) {
|
|
907
1108
|
icon = _listr2.figures.warning;
|
|
908
1109
|
}
|
|
909
1110
|
break;
|
|
910
|
-
case
|
|
1111
|
+
case LogLevels.INFO:
|
|
911
1112
|
coloring = color.green;
|
|
912
|
-
if (_optionalChain([this, 'access',
|
|
1113
|
+
if (_optionalChain([this, 'access', _29 => _29.options, 'optionalAccess', _30 => _30.useIcons])) {
|
|
913
1114
|
icon = _listr2.figures.pointerSmall;
|
|
914
1115
|
}
|
|
915
1116
|
break;
|
|
916
|
-
case
|
|
1117
|
+
case LogLevels.VERBOSE:
|
|
917
1118
|
coloring = color.dim;
|
|
918
|
-
if (_optionalChain([this, 'access',
|
|
1119
|
+
if (_optionalChain([this, 'access', _31 => _31.options, 'optionalAccess', _32 => _32.useIcons])) {
|
|
919
1120
|
icon = "\u2607";
|
|
920
1121
|
}
|
|
921
1122
|
break;
|
|
922
|
-
case
|
|
1123
|
+
case LogLevels.DEBUG:
|
|
923
1124
|
coloring = color.cyan;
|
|
924
1125
|
msgColoring = color.dim;
|
|
925
|
-
if (_optionalChain([this, 'access',
|
|
1126
|
+
if (_optionalChain([this, 'access', _33 => _33.options, 'optionalAccess', _34 => _34.useIcons])) {
|
|
926
1127
|
icon = "\uF188";
|
|
927
1128
|
}
|
|
928
1129
|
break;
|
|
929
|
-
case
|
|
1130
|
+
case LogLevels.TRACE:
|
|
930
1131
|
coloring = color.magenta;
|
|
931
1132
|
msgColoring = color.dim;
|
|
932
|
-
if (_optionalChain([this, 'access',
|
|
1133
|
+
if (_optionalChain([this, 'access', _35 => _35.options, 'optionalAccess', _36 => _36.useIcons])) {
|
|
933
1134
|
icon = "\u26B1";
|
|
934
1135
|
}
|
|
935
1136
|
break;
|
|
@@ -940,124 +1141,33 @@ var Logger = class {
|
|
|
940
1141
|
return `${coloring(icon)}${context ? " " + coloring(`[${context}]`) : ""}${status ? " " + coloring(`[${status}]`) : ""} ${msgColoring(message)}`;
|
|
941
1142
|
}
|
|
942
1143
|
};
|
|
1144
|
+
var Logger = _Logger;
|
|
943
1145
|
__name(Logger, "Logger");
|
|
944
|
-
|
|
945
|
-
// src/utils/logger/listr-logger.ts
|
|
946
|
-
var ListrLogger = class extends _listr2.Logger {
|
|
947
|
-
constructor(context) {
|
|
948
|
-
super();
|
|
949
|
-
this.logger = new Logger(context);
|
|
950
|
-
}
|
|
951
|
-
fail(message) {
|
|
952
|
-
this.logger.error(message);
|
|
953
|
-
}
|
|
954
|
-
skip(message) {
|
|
955
|
-
this.logger.warn(message, { status: "skip" });
|
|
956
|
-
}
|
|
957
|
-
success(message) {
|
|
958
|
-
this.logger.info(message, { status: "end" });
|
|
959
|
-
}
|
|
960
|
-
data(message) {
|
|
961
|
-
this.logger.info(message);
|
|
962
|
-
}
|
|
963
|
-
start(message) {
|
|
964
|
-
this.logger.info(message, { status: "run" });
|
|
965
|
-
}
|
|
966
|
-
title(message) {
|
|
967
|
-
this.logger.info(message);
|
|
968
|
-
}
|
|
969
|
-
retry(message) {
|
|
970
|
-
this.logger.warn(message, { status: "retry" });
|
|
971
|
-
}
|
|
972
|
-
rollback(message) {
|
|
973
|
-
this.logger.error(message, { status: "rollback" });
|
|
974
|
-
}
|
|
975
|
-
};
|
|
976
|
-
__name(ListrLogger, "ListrLogger");
|
|
977
|
-
|
|
978
|
-
// src/utils/logger/pipe/pipe-process-to-listr.ts
|
|
979
|
-
var _through = require('through'); var _through2 = _interopRequireDefault(_through);
|
|
980
|
-
function pipeProcessThroughListr(task, instance) {
|
|
981
|
-
const logOut = _through2.default.call(void 0, (chunk) => {
|
|
982
|
-
task.output = _optionalChain([chunk, 'optionalAccess', _35 => _35.toString, 'call', _36 => _36("utf-8"), 'access', _37 => _37.trim, 'call', _38 => _38()]);
|
|
983
|
-
});
|
|
984
|
-
instance.stdout.pipe(logOut);
|
|
985
|
-
instance.stderr.pipe(logOut);
|
|
986
|
-
return instance;
|
|
987
|
-
}
|
|
988
|
-
__name(pipeProcessThroughListr, "pipeProcessThroughListr");
|
|
989
|
-
|
|
990
|
-
// src/utils/logger/pipe/pipe-process-to-logger.ts
|
|
991
|
-
|
|
992
|
-
function pipeProcessToLogger(logger, instance, options) {
|
|
993
|
-
options = {
|
|
994
|
-
start: "INFO" /* INFO */,
|
|
995
|
-
end: "INFO" /* INFO */,
|
|
996
|
-
stdout: "INFO" /* INFO */,
|
|
997
|
-
stderr: "WARN" /* WARN */,
|
|
998
|
-
...options
|
|
999
|
-
};
|
|
1000
|
-
if (options.start) {
|
|
1001
|
-
logger.run(instance.spawnargs.join(" "), { level: options.start, context: options.context });
|
|
1002
|
-
}
|
|
1003
|
-
if (instance.stdout) {
|
|
1004
|
-
instance.stdout.pipe(
|
|
1005
|
-
_through2.default.call(void 0, (chunk) => {
|
|
1006
|
-
logger.log(options.stdout, chunk, { context: options.context });
|
|
1007
|
-
})
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1010
|
-
if (instance.stderr) {
|
|
1011
|
-
instance.stderr.pipe(
|
|
1012
|
-
_through2.default.call(void 0, (chunk) => {
|
|
1013
|
-
logger.log(options.stderr, chunk, { context: options.context });
|
|
1014
|
-
})
|
|
1015
|
-
);
|
|
1016
|
-
}
|
|
1017
|
-
void instance.on("exit", (code, signal) => {
|
|
1018
|
-
const message = `Process ended with code ${code}${signal ? ` and signal ${signal}` : ""}.`;
|
|
1019
|
-
logger.debug(message, { context: options.context });
|
|
1020
|
-
if (options.end) {
|
|
1021
|
-
logger.end(instance.spawnargs.join(" "), { level: options.end, context: options.context });
|
|
1022
|
-
}
|
|
1023
|
-
if (_optionalChain([options, 'optionalAccess', _39 => _39.callback])) {
|
|
1024
|
-
options.callback();
|
|
1025
|
-
}
|
|
1026
|
-
});
|
|
1027
|
-
void instance.on("error", (error) => {
|
|
1028
|
-
logger.fatal(error.message, { context: options.context });
|
|
1029
|
-
logger.debug(error.stack, { context: options.context });
|
|
1030
|
-
if (_optionalChain([options, 'optionalAccess', _40 => _40.callback])) {
|
|
1031
|
-
options.callback(error);
|
|
1032
|
-
}
|
|
1033
|
-
});
|
|
1034
|
-
return instance;
|
|
1035
|
-
}
|
|
1036
|
-
__name(pipeProcessToLogger, "pipeProcessToLogger");
|
|
1146
|
+
__publicField(Logger, "instance");
|
|
1037
1147
|
|
|
1038
1148
|
// src/constants/global-flags.constants.ts
|
|
1039
1149
|
var CLI_FLAGS = {
|
|
1040
1150
|
["log-level"]: _core.Flags.string({
|
|
1041
|
-
default:
|
|
1151
|
+
default: LogLevels.INFO,
|
|
1042
1152
|
env: "LOG_LEVEL",
|
|
1043
1153
|
description: "Set the log level of the application.",
|
|
1044
1154
|
options: Object.values(LogLevels).map((level) => level.toLowerCase()),
|
|
1045
|
-
helpGroup:
|
|
1046
|
-
parse: async (input) => _optionalChain([input, 'optionalAccess',
|
|
1155
|
+
helpGroup: HelpGroups.CLI,
|
|
1156
|
+
parse: async (input) => _optionalChain([input, 'optionalAccess', _37 => _37.toUpperCase, 'call', _38 => _38()])
|
|
1047
1157
|
}),
|
|
1048
1158
|
ci: _core.Flags.boolean({
|
|
1049
1159
|
default: false,
|
|
1050
1160
|
hidden: true,
|
|
1051
1161
|
env: "CI",
|
|
1052
1162
|
description: "Instruct whether this is running the CI/CD configuration.",
|
|
1053
|
-
helpGroup:
|
|
1163
|
+
helpGroup: HelpGroups.CLI
|
|
1054
1164
|
}),
|
|
1055
1165
|
json: _core.Flags.boolean({
|
|
1056
1166
|
default: false,
|
|
1057
1167
|
hidden: true,
|
|
1058
1168
|
env: "JSON",
|
|
1059
1169
|
description: "Put the CLI to respond in JSON.",
|
|
1060
|
-
helpGroup:
|
|
1170
|
+
helpGroup: HelpGroups.CLI
|
|
1061
1171
|
})
|
|
1062
1172
|
};
|
|
1063
1173
|
|
|
@@ -1065,8 +1175,16 @@ var CLI_FLAGS = {
|
|
|
1065
1175
|
var Command = class extends _core.Command {
|
|
1066
1176
|
constructor() {
|
|
1067
1177
|
super(...arguments);
|
|
1068
|
-
this
|
|
1069
|
-
this
|
|
1178
|
+
__publicField(this, "context");
|
|
1179
|
+
__publicField(this, "logger");
|
|
1180
|
+
__publicField(this, "tasks");
|
|
1181
|
+
__publicField(this, "validator");
|
|
1182
|
+
__publicField(this, "cs");
|
|
1183
|
+
__publicField(this, "parser");
|
|
1184
|
+
__publicField(this, "fs");
|
|
1185
|
+
__publicField(this, "store");
|
|
1186
|
+
__publicField(this, "flags", {});
|
|
1187
|
+
__publicField(this, "args", {});
|
|
1070
1188
|
}
|
|
1071
1189
|
static get baseFlags() {
|
|
1072
1190
|
return this._baseFlags;
|
|
@@ -1076,14 +1194,14 @@ var Command = class extends _core.Command {
|
|
|
1076
1194
|
this.flags = {};
|
|
1077
1195
|
}
|
|
1078
1196
|
/**
|
|
1079
|
-
|
|
1080
|
-
|
|
1197
|
+
* Construct the class if you dont want to extend init or constructor.
|
|
1198
|
+
*/
|
|
1081
1199
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1082
1200
|
shouldRunBefore() {
|
|
1083
1201
|
}
|
|
1084
1202
|
/**
|
|
1085
|
-
|
|
1086
|
-
|
|
1203
|
+
* Deconstruct the class if you dont want to extend finally or catch.
|
|
1204
|
+
*/
|
|
1087
1205
|
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
|
|
1088
1206
|
shouldRunAfter(_ctx) {
|
|
1089
1207
|
}
|
|
@@ -1108,7 +1226,9 @@ var Command = class extends _core.Command {
|
|
|
1108
1226
|
return result;
|
|
1109
1227
|
}
|
|
1110
1228
|
exit(code) {
|
|
1111
|
-
this.logger.trace("Code -> %d", code, {
|
|
1229
|
+
this.logger.trace("Code -> %d", code, {
|
|
1230
|
+
status: LogFieldStatus.EXIT
|
|
1231
|
+
});
|
|
1112
1232
|
process.exit(_nullishCoalesce(code, () => ( 0)));
|
|
1113
1233
|
}
|
|
1114
1234
|
/** Run all tasks from task manager. */
|
|
@@ -1124,11 +1244,15 @@ var Command = class extends _core.Command {
|
|
|
1124
1244
|
}
|
|
1125
1245
|
setCtxDefaults(...defaults) {
|
|
1126
1246
|
setCtxDefaults(this.tasks.options.ctx, ...defaults);
|
|
1127
|
-
this.logger.trace("Updated context with defaults: %o", this.tasks.options.ctx, {
|
|
1247
|
+
this.logger.trace("Updated context with defaults: %o", this.tasks.options.ctx, {
|
|
1248
|
+
status: "ctx"
|
|
1249
|
+
});
|
|
1128
1250
|
}
|
|
1129
1251
|
setCtxAssign(...assigns) {
|
|
1130
1252
|
setCtxAssign(this.tasks.options.ctx, ...assigns);
|
|
1131
|
-
this.logger.trace("Updated context with assign: %o", this.tasks.options.ctx, {
|
|
1253
|
+
this.logger.trace("Updated context with assign: %o", this.tasks.options.ctx, {
|
|
1254
|
+
status: "ctx"
|
|
1255
|
+
});
|
|
1132
1256
|
}
|
|
1133
1257
|
pipeProcessToLogger(instance, options) {
|
|
1134
1258
|
return pipeProcessToLogger(this.logger, instance, options);
|
|
@@ -1155,7 +1279,9 @@ var Command = class extends _core.Command {
|
|
|
1155
1279
|
json: this.flags.json
|
|
1156
1280
|
});
|
|
1157
1281
|
this.context = this.cs.command.id ? this.cs.command.id : this.cs.command.name;
|
|
1158
|
-
this.logger = new Logger(null, {
|
|
1282
|
+
this.logger = new Logger(null, {
|
|
1283
|
+
level: this.cs.logLevel
|
|
1284
|
+
});
|
|
1159
1285
|
this.store = new StoreService();
|
|
1160
1286
|
this.greet();
|
|
1161
1287
|
if (err) {
|
|
@@ -1166,13 +1292,8 @@ var Command = class extends _core.Command {
|
|
|
1166
1292
|
this.fs = new FileSystemService();
|
|
1167
1293
|
this.validator = new ValidatorService();
|
|
1168
1294
|
this.tasks = new (0, _listr2.Manager)({
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
nonTTYRendererOptions: {
|
|
1172
|
-
logEmptyTitle: false,
|
|
1173
|
-
logTitleChange: false,
|
|
1174
|
-
logger: ListrLogger
|
|
1175
|
-
},
|
|
1295
|
+
fallbackRendererCondition: this.cs.isDebug,
|
|
1296
|
+
silentRendererCondition: this.cs.isSilent,
|
|
1176
1297
|
ctx: {}
|
|
1177
1298
|
});
|
|
1178
1299
|
if (this.cs.oclif.windows) {
|
|
@@ -1184,7 +1305,9 @@ var Command = class extends _core.Command {
|
|
|
1184
1305
|
});
|
|
1185
1306
|
}
|
|
1186
1307
|
const terminate = /* @__PURE__ */ __name(() => {
|
|
1187
|
-
this.logger.fatal("Caught terminate signal.", {
|
|
1308
|
+
this.logger.fatal("Caught terminate signal.", {
|
|
1309
|
+
status: LogFieldStatus.TERMINATE
|
|
1310
|
+
});
|
|
1188
1311
|
process.exit(1);
|
|
1189
1312
|
}, "terminate");
|
|
1190
1313
|
process.on("SIGINT", terminate);
|
|
@@ -1201,7 +1324,9 @@ var Command = class extends _core.Command {
|
|
|
1201
1324
|
this.logger.stage("Running shouldRunAfter.");
|
|
1202
1325
|
await this.shouldRunAfter(ctx);
|
|
1203
1326
|
this.logger.stage("Finished shouldRunAfter.");
|
|
1204
|
-
return {
|
|
1327
|
+
return {
|
|
1328
|
+
ctx
|
|
1329
|
+
};
|
|
1205
1330
|
}
|
|
1206
1331
|
/** Catch any error occurred during command. */
|
|
1207
1332
|
// catch all those errors, not verbose
|
|
@@ -1212,7 +1337,9 @@ var Command = class extends _core.Command {
|
|
|
1212
1337
|
console.debug(e.stack);
|
|
1213
1338
|
}
|
|
1214
1339
|
this.logger.fatal(e.message);
|
|
1215
|
-
this.logger.debug(e.stack, {
|
|
1340
|
+
this.logger.debug(e.stack, {
|
|
1341
|
+
context: "crash"
|
|
1342
|
+
});
|
|
1216
1343
|
if (exit > 0) {
|
|
1217
1344
|
this.exit(exit);
|
|
1218
1345
|
}
|
|
@@ -1233,6 +1360,11 @@ __name(Command, "Command");
|
|
|
1233
1360
|
|
|
1234
1361
|
// src/commands/config.command.ts
|
|
1235
1362
|
var ConfigCommand = class extends Command {
|
|
1363
|
+
constructor() {
|
|
1364
|
+
super(...arguments);
|
|
1365
|
+
__publicField(this, "choices");
|
|
1366
|
+
__publicField(this, "locker");
|
|
1367
|
+
}
|
|
1236
1368
|
async run() {
|
|
1237
1369
|
this.logger.stage("Setting up config command.");
|
|
1238
1370
|
const setup2 = await this.setup();
|
|
@@ -1264,17 +1396,28 @@ __name(ConfigCommand, "ConfigCommand");
|
|
|
1264
1396
|
|
|
1265
1397
|
var notFoundHook = /* @__PURE__ */ __name(async (opts) => {
|
|
1266
1398
|
const logger = new Logger(opts.config.name);
|
|
1267
|
-
logger.fatal("Command not found. Take a look at help. You can also use --[h]elp flag for subcommands.", {
|
|
1399
|
+
logger.fatal("Command not found. Take a look at help. You can also use --[h]elp flag for subcommands.", {
|
|
1400
|
+
custom: opts.config.name
|
|
1401
|
+
});
|
|
1268
1402
|
logger.direct("");
|
|
1269
1403
|
const help = new (0, _core.Help)(opts.config);
|
|
1270
|
-
await help.showHelp([
|
|
1404
|
+
await help.showHelp([
|
|
1405
|
+
"--all"
|
|
1406
|
+
]);
|
|
1271
1407
|
process.exit(127);
|
|
1272
1408
|
}, "notFoundHook");
|
|
1273
1409
|
|
|
1274
1410
|
// src/hooks/update-notifier.hook.ts
|
|
1275
|
-
var _updatenotifier = require('update-notifier'); var _updatenotifier2 = _interopRequireDefault(_updatenotifier);
|
|
1276
1411
|
var updateNotifierHook = /* @__PURE__ */ __name(async (opts) => {
|
|
1277
|
-
|
|
1412
|
+
const { default: notifier } = await Promise.resolve().then(() => _interopRequireWildcard(require("update-notifier")));
|
|
1413
|
+
notifier({
|
|
1414
|
+
pkg: {
|
|
1415
|
+
name: opts.config.name,
|
|
1416
|
+
version: opts.config.version
|
|
1417
|
+
}
|
|
1418
|
+
}).notify({
|
|
1419
|
+
isGlobal: true
|
|
1420
|
+
});
|
|
1278
1421
|
}, "updateNotifierHook");
|
|
1279
1422
|
|
|
1280
1423
|
// src/hooks/store.hook.ts
|
|
@@ -1317,5 +1460,4 @@ var storeHook = /* @__PURE__ */ __name((cb) => async (opts) => {
|
|
|
1317
1460
|
|
|
1318
1461
|
|
|
1319
1462
|
|
|
1320
|
-
|
|
1321
|
-
exports.CLI_FLAGS = CLI_FLAGS; exports.Command = Command; exports.ConfigCommand = ConfigCommand; exports.ConfigService = ConfigService; exports.EnvironmentVariableParser = EnvironmentVariableParser; exports.FileConstants = FileConstants; exports.FileSystemService = FileSystemService; exports.Flags = _core.Flags; exports.HelpGroups = HelpGroups; exports.JsonParser = JsonParser; exports.ListrLogger = ListrLogger; exports.LockerService = LockerService; exports.LogFieldStatus = LogFieldStatus; exports.LogLevels = LogLevels; exports.Logger = Logger; exports.MergeStrategy = MergeStrategy; exports.ParserService = ParserService; exports.StoreService = StoreService; exports.ValidatorService = ValidatorService; exports.YamlParser = YamlParser; exports.color = color; exports.fs = _fsextra2.default; exports.isDebug = isDebug; exports.isSilent = isSilent; exports.isVerbose = isVerbose; exports.merge = merge; exports.notFoundHook = notFoundHook; exports.pipeProcessThroughListr = pipeProcessThroughListr; exports.pipeProcessToLogger = pipeProcessToLogger; exports.setCtxAssign = setCtxAssign; exports.setCtxDefaults = setCtxDefaults; exports.setup = setup; exports.storeHook = storeHook; exports.uniqueFilter = uniqueFilter; exports.updateNotifierHook = updateNotifierHook; exports.ux = _core.ux;
|
|
1463
|
+
exports.CLI_FLAGS = CLI_FLAGS; exports.Command = Command; exports.ConfigCommand = ConfigCommand; exports.ConfigService = ConfigService; exports.EnvironmentVariableParser = EnvironmentVariableParser; exports.FileConstants = FileConstants; exports.FileSystemService = FileSystemService; exports.Flags = _core.Flags; exports.HelpGroups = HelpGroups; exports.JsonParser = JsonParser; exports.LockerService = LockerService; exports.LogFieldStatus = LogFieldStatus; exports.LogLevels = LogLevels; exports.Logger = Logger; exports.MergeStrategy = MergeStrategy; exports.ParserService = ParserService; exports.StoreService = StoreService; exports.ValidatorService = ValidatorService; exports.YamlParser = YamlParser; exports.color = color; exports.fs = _fsextra2.default; exports.isDebug = isDebug; exports.isSilent = isSilent; exports.isVerbose = isVerbose; exports.merge = merge; exports.notFoundHook = notFoundHook; exports.pipeProcessThroughListr = pipeProcessThroughListr; exports.pipeProcessToLogger = pipeProcessToLogger; exports.setCtxAssign = setCtxAssign; exports.setCtxDefaults = setCtxDefaults; exports.setup = setup; exports.storeHook = storeHook; exports.uniqueFilter = uniqueFilter; exports.updateNotifierHook = updateNotifierHook; exports.ux = _core.ux;
|