@cenk1cenk2/oclif-common 3.7.1 → 3.8.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/hooks/index.js +513 -130
- package/dist/hooks/not-found.hook.js +490 -6
- package/dist/hooks/store.hook.js +384 -1
- package/dist/index.d.ts +22 -11
- package/dist/index.js +626 -541
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(src_exports, {
|
|
|
31
31
|
Command: () => Command,
|
|
32
32
|
ConfigCommand: () => ConfigCommand,
|
|
33
33
|
ConfigService: () => ConfigService,
|
|
34
|
+
EnvironmentVariableParser: () => EnvironmentVariableParser,
|
|
34
35
|
FileConstants: () => FileConstants,
|
|
35
36
|
FileSystemService: () => FileSystemService,
|
|
36
37
|
Flags: () => import_core.Flags,
|
|
@@ -59,6 +60,7 @@ __export(src_exports, {
|
|
|
59
60
|
setCtxDefaults: () => setCtxDefaults,
|
|
60
61
|
setup: () => setup,
|
|
61
62
|
storeHook: () => storeHook,
|
|
63
|
+
uniqueFilter: () => uniqueFilter,
|
|
62
64
|
updateNotifierHook: () => updateNotifierHook
|
|
63
65
|
});
|
|
64
66
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -89,7 +91,7 @@ var import_listr22 = require("listr2");
|
|
|
89
91
|
|
|
90
92
|
// src/utils/logger/logger.ts
|
|
91
93
|
var import_listr2 = require("listr2");
|
|
92
|
-
var
|
|
94
|
+
var import_os2 = require("os");
|
|
93
95
|
var import_winston = __toESM(require("winston"));
|
|
94
96
|
|
|
95
97
|
// src/utils/logger/logger.constants.ts
|
|
@@ -114,372 +116,131 @@ var LogFieldStatus = /* @__PURE__ */ ((LogFieldStatus2) => {
|
|
|
114
116
|
return LogFieldStatus2;
|
|
115
117
|
})(LogFieldStatus || {});
|
|
116
118
|
|
|
117
|
-
// src/
|
|
118
|
-
var
|
|
119
|
-
var
|
|
119
|
+
// src/lib/config/config.service.ts
|
|
120
|
+
var import_object_path_immutable = __toESM(require("object-path-immutable"));
|
|
121
|
+
var import_path2 = require("path");
|
|
120
122
|
|
|
121
|
-
// src/
|
|
122
|
-
var
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.options = {
|
|
129
|
-
useIcons: true,
|
|
130
|
-
...options,
|
|
131
|
-
level
|
|
132
|
-
};
|
|
133
|
-
if (Logger.instance) {
|
|
134
|
-
this.logger = Logger.instance;
|
|
135
|
-
} else {
|
|
136
|
-
this.logger = this.initiateLogger();
|
|
137
|
-
Logger.instance = this.logger;
|
|
123
|
+
// src/lib/parser/env-parser.service.ts
|
|
124
|
+
var import_os = require("os");
|
|
125
|
+
var _EnvironmentVariableParser = class {
|
|
126
|
+
constructor() {
|
|
127
|
+
this.LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
128
|
+
if (_EnvironmentVariableParser.instance) {
|
|
129
|
+
return _EnvironmentVariableParser.instance;
|
|
138
130
|
}
|
|
131
|
+
_EnvironmentVariableParser.instance = this;
|
|
132
|
+
this.logger = new Logger(this.constructor.name);
|
|
133
|
+
this.logger.trace("Created a new instance.");
|
|
139
134
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
fatal(data, ...args) {
|
|
147
|
-
return this.parseMessage("FATAL" /* FATAL */, data, args);
|
|
148
|
-
}
|
|
149
|
-
error(data, ...args) {
|
|
150
|
-
return this.parseMessage("ERROR" /* ERROR */, data, args);
|
|
151
|
-
}
|
|
152
|
-
warn(data, ...args) {
|
|
153
|
-
return this.parseMessage("WARN" /* WARN */, data, args);
|
|
154
|
-
}
|
|
155
|
-
info(data, ...args) {
|
|
156
|
-
return this.parseMessage("INFO" /* INFO */, data, args);
|
|
157
|
-
}
|
|
158
|
-
debug(data, ...args) {
|
|
159
|
-
return this.parseMessage("DEBUG" /* DEBUG */, data, args);
|
|
160
|
-
}
|
|
161
|
-
verbose(data, ...args) {
|
|
162
|
-
return this.parseMessage("VERBOSE" /* VERBOSE */, data, args);
|
|
163
|
-
}
|
|
164
|
-
trace(data, ...args) {
|
|
165
|
-
return this.parseMessage("TRACE" /* TRACE */, data, args);
|
|
166
|
-
}
|
|
167
|
-
run(data, ...args) {
|
|
168
|
-
return this.parseMessage("INFO" /* INFO */, data, args, { status: "run" /* RUN */ });
|
|
169
|
-
}
|
|
170
|
-
end(data, ...args) {
|
|
171
|
-
return this.parseMessage("INFO" /* INFO */, data, args, { status: "end" /* END */ });
|
|
172
|
-
}
|
|
173
|
-
stage(data, ...args) {
|
|
174
|
-
return this.parseMessage("TRACE" /* TRACE */, data, args, { status: "stage" /* STAGE */ });
|
|
175
|
-
}
|
|
176
|
-
initiateLogger() {
|
|
177
|
-
const logFormat = import_winston.format.printf(({ level, message, context, status }) => {
|
|
178
|
-
let multiLineMessage;
|
|
179
|
-
multiLineMessage = message.split(import_os.EOL);
|
|
180
|
-
multiLineMessage = multiLineMessage.filter((msg) => msg.trim() !== "").filter(Boolean);
|
|
181
|
-
multiLineMessage = multiLineMessage.map((msg) => {
|
|
182
|
-
return this.logColoring({
|
|
183
|
-
level,
|
|
184
|
-
message: msg,
|
|
185
|
-
context,
|
|
186
|
-
status
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
return multiLineMessage.join(import_os.EOL);
|
|
190
|
-
});
|
|
191
|
-
const logger = import_winston.default.createLogger({
|
|
192
|
-
level: this.options.level,
|
|
193
|
-
format: import_winston.format.combine(import_winston.format.splat(), import_winston.format.json({ space: 2 }), import_winston.format.prettyPrint(), logFormat),
|
|
194
|
-
levels: Object.values(LogLevels).reduce((o, level, i) => {
|
|
135
|
+
parse(data) {
|
|
136
|
+
try {
|
|
137
|
+
return data.toString().split(import_os.EOL).reduce((o, line) => {
|
|
138
|
+
const match = this.LINE.exec(line);
|
|
139
|
+
const key = match[1];
|
|
140
|
+
const value = match[2] ?? "";
|
|
195
141
|
return {
|
|
196
142
|
...o,
|
|
197
|
-
[
|
|
143
|
+
[key]: value
|
|
198
144
|
};
|
|
199
|
-
}, {})
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
})
|
|
205
|
-
]
|
|
206
|
-
});
|
|
207
|
-
logger.log("TRACE" /* TRACE */, "Initiated new logger with level: %s", this.options.level, { context: this.constructor.name });
|
|
208
|
-
return logger;
|
|
145
|
+
}, {});
|
|
146
|
+
} catch (e) {
|
|
147
|
+
this.logger.trace("Error during parsing environment file: %s", e.message);
|
|
148
|
+
throw e;
|
|
149
|
+
}
|
|
209
150
|
}
|
|
210
|
-
|
|
211
|
-
|
|
151
|
+
stringify(data) {
|
|
152
|
+
return Object.entries(data).map(([k, v]) => `${k}=${v}`).join(import_os.EOL) + import_os.EOL;
|
|
212
153
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return message;
|
|
224
|
-
case "FATAL" /* FATAL */:
|
|
225
|
-
coloring = /* @__PURE__ */ __name((input) => color.red(input), "coloring");
|
|
226
|
-
if (this.options?.useIcons) {
|
|
227
|
-
icon = import_listr2.figures.checkboxOn;
|
|
228
|
-
}
|
|
229
|
-
break;
|
|
230
|
-
case "ERROR" /* ERROR */:
|
|
231
|
-
coloring = color.red;
|
|
232
|
-
if (this.options?.useIcons) {
|
|
233
|
-
icon = import_listr2.figures.cross;
|
|
234
|
-
}
|
|
235
|
-
break;
|
|
236
|
-
case "WARN" /* WARN */:
|
|
237
|
-
coloring = color.yellow;
|
|
238
|
-
if (this.options?.useIcons) {
|
|
239
|
-
icon = import_listr2.figures.warning;
|
|
240
|
-
}
|
|
241
|
-
break;
|
|
242
|
-
case "INFO" /* INFO */:
|
|
243
|
-
coloring = color.green;
|
|
244
|
-
if (this.options?.useIcons) {
|
|
245
|
-
icon = import_listr2.figures.pointerSmall;
|
|
246
|
-
}
|
|
247
|
-
break;
|
|
248
|
-
case "VERBOSE" /* VERBOSE */:
|
|
249
|
-
coloring = color.dim;
|
|
250
|
-
if (this.options?.useIcons) {
|
|
251
|
-
icon = "\u2607";
|
|
252
|
-
}
|
|
253
|
-
break;
|
|
254
|
-
case "DEBUG" /* DEBUG */:
|
|
255
|
-
coloring = color.cyan;
|
|
256
|
-
msgColoring = color.dim;
|
|
257
|
-
if (this.options?.useIcons) {
|
|
258
|
-
icon = "\uF188";
|
|
259
|
-
}
|
|
260
|
-
break;
|
|
261
|
-
case "TRACE" /* TRACE */:
|
|
262
|
-
coloring = color.magenta;
|
|
263
|
-
msgColoring = color.dim;
|
|
264
|
-
if (this.options?.useIcons) {
|
|
265
|
-
icon = "\u26B1";
|
|
266
|
-
}
|
|
267
|
-
break;
|
|
154
|
+
};
|
|
155
|
+
var EnvironmentVariableParser = _EnvironmentVariableParser;
|
|
156
|
+
__name(EnvironmentVariableParser, "EnvironmentVariableParser");
|
|
157
|
+
EnvironmentVariableParser.extensions = ["env"];
|
|
158
|
+
|
|
159
|
+
// src/lib/parser/json-parser.service.ts
|
|
160
|
+
var _JsonParser = class {
|
|
161
|
+
constructor() {
|
|
162
|
+
if (_JsonParser.instance) {
|
|
163
|
+
return _JsonParser.instance;
|
|
268
164
|
}
|
|
269
|
-
|
|
270
|
-
|
|
165
|
+
_JsonParser.instance = this;
|
|
166
|
+
this.logger = new Logger(this.constructor.name);
|
|
167
|
+
this.logger.trace("Created a new instance.");
|
|
168
|
+
}
|
|
169
|
+
parse(data) {
|
|
170
|
+
try {
|
|
171
|
+
return JSON.parse(data.toString());
|
|
172
|
+
} catch (e) {
|
|
173
|
+
this.logger.trace("Error during parsing JSON file: %s", e.message);
|
|
174
|
+
throw e;
|
|
271
175
|
}
|
|
272
|
-
|
|
176
|
+
}
|
|
177
|
+
stringify(data) {
|
|
178
|
+
return JSON.stringify(data, null, 2);
|
|
273
179
|
}
|
|
274
180
|
};
|
|
275
|
-
|
|
181
|
+
var JsonParser = _JsonParser;
|
|
182
|
+
__name(JsonParser, "JsonParser");
|
|
183
|
+
JsonParser.extensions = ["json"];
|
|
276
184
|
|
|
277
|
-
// src/
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
185
|
+
// src/lib/parser/yaml-parser.service.ts
|
|
186
|
+
var import_yaml = require("yaml");
|
|
187
|
+
var _YamlParser = class {
|
|
188
|
+
constructor() {
|
|
189
|
+
if (_YamlParser.instance) {
|
|
190
|
+
return _YamlParser.instance;
|
|
191
|
+
}
|
|
192
|
+
_YamlParser.instance = this;
|
|
193
|
+
this.logger = new Logger(this.constructor.name);
|
|
194
|
+
this.logger.trace("Created a new instance.");
|
|
282
195
|
}
|
|
283
|
-
|
|
284
|
-
|
|
196
|
+
parse(data) {
|
|
197
|
+
try {
|
|
198
|
+
return (0, import_yaml.parse)(data.toString());
|
|
199
|
+
} catch (e) {
|
|
200
|
+
this.logger.trace("Error during parsing YAML file: %s", e.message);
|
|
201
|
+
throw e;
|
|
202
|
+
}
|
|
285
203
|
}
|
|
286
|
-
|
|
287
|
-
|
|
204
|
+
stringify(data) {
|
|
205
|
+
return (0, import_yaml.stringify)(data, { prettyErrors: true });
|
|
288
206
|
}
|
|
289
|
-
|
|
290
|
-
|
|
207
|
+
};
|
|
208
|
+
var YamlParser = _YamlParser;
|
|
209
|
+
__name(YamlParser, "YamlParser");
|
|
210
|
+
YamlParser.extensions = ["yaml", "yml"];
|
|
211
|
+
|
|
212
|
+
// src/lib/fs/filesystem.service.ts
|
|
213
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
214
|
+
var import_path = require("path");
|
|
215
|
+
var FileSystemService = class {
|
|
216
|
+
constructor() {
|
|
217
|
+
if (FileSystemService.instance) {
|
|
218
|
+
return FileSystemService.instance;
|
|
219
|
+
} else {
|
|
220
|
+
FileSystemService.instance = this;
|
|
221
|
+
this.logger = new Logger(this.constructor.name);
|
|
222
|
+
this.logger.trace("Created a new instance.");
|
|
223
|
+
}
|
|
291
224
|
}
|
|
292
|
-
|
|
293
|
-
|
|
225
|
+
exists(path) {
|
|
226
|
+
return import_fs_extra.default.existsSync(path);
|
|
294
227
|
}
|
|
295
|
-
|
|
296
|
-
|
|
228
|
+
stats(path) {
|
|
229
|
+
return import_fs_extra.default.statSync(path, { throwIfNoEntry: true });
|
|
297
230
|
}
|
|
298
|
-
|
|
299
|
-
|
|
231
|
+
dirname(path) {
|
|
232
|
+
return (0, import_path.dirname)(path);
|
|
300
233
|
}
|
|
301
|
-
|
|
302
|
-
|
|
234
|
+
extname(path) {
|
|
235
|
+
return (0, import_path.extname)(path);
|
|
303
236
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
var import_through = __toESM(require("through"));
|
|
312
|
-
function pipeProcessThroughListr(task, instance) {
|
|
313
|
-
const logOut = (0, import_through.default)((chunk) => {
|
|
314
|
-
task.output = chunk?.toString("utf-8").trim();
|
|
315
|
-
});
|
|
316
|
-
instance.stdout.pipe(logOut);
|
|
317
|
-
instance.stderr.pipe(logOut);
|
|
318
|
-
return instance;
|
|
319
|
-
}
|
|
320
|
-
__name(pipeProcessThroughListr, "pipeProcessThroughListr");
|
|
321
|
-
|
|
322
|
-
// src/utils/logger/pipe/pipe-process-to-logger.ts
|
|
323
|
-
var import_through2 = __toESM(require("through"));
|
|
324
|
-
function pipeProcessToLogger(logger, instance, options) {
|
|
325
|
-
options = {
|
|
326
|
-
start: "INFO" /* INFO */,
|
|
327
|
-
end: "INFO" /* INFO */,
|
|
328
|
-
stdout: "INFO" /* INFO */,
|
|
329
|
-
stderr: "WARN" /* WARN */,
|
|
330
|
-
...options
|
|
331
|
-
};
|
|
332
|
-
if (options.start) {
|
|
333
|
-
logger.run(instance.spawnargs.join(" "), { level: options.start });
|
|
334
|
-
}
|
|
335
|
-
if (instance.stdout) {
|
|
336
|
-
instance.stdout.pipe(
|
|
337
|
-
(0, import_through2.default)((chunk) => {
|
|
338
|
-
logger.log(options.stdout, chunk);
|
|
339
|
-
})
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
if (instance.stderr) {
|
|
343
|
-
instance.stderr.pipe(
|
|
344
|
-
(0, import_through2.default)((chunk) => {
|
|
345
|
-
logger.log(options.stderr, chunk);
|
|
346
|
-
})
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
void instance.on("exit", (code, signal) => {
|
|
350
|
-
const message = `Process ended with code ${code}${signal ? ` and signal ${signal}` : ""}.`;
|
|
351
|
-
logger.debug(message);
|
|
352
|
-
if (options.end) {
|
|
353
|
-
logger.end(instance.spawnargs.join(" "), { level: options.end });
|
|
354
|
-
}
|
|
355
|
-
if (options?.callback) {
|
|
356
|
-
options.callback();
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
void instance.on("error", (error) => {
|
|
360
|
-
logger.fatal(error.message);
|
|
361
|
-
logger.debug(error.stack);
|
|
362
|
-
if (options?.callback) {
|
|
363
|
-
options.callback(error);
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
return instance;
|
|
367
|
-
}
|
|
368
|
-
__name(pipeProcessToLogger, "pipeProcessToLogger");
|
|
369
|
-
|
|
370
|
-
// src/constants/global-flags.constants.ts
|
|
371
|
-
var CLI_FLAGS = {
|
|
372
|
-
["log-level"]: import_core.Flags.enum({
|
|
373
|
-
default: "INFO" /* INFO */,
|
|
374
|
-
env: "LOG_LEVEL",
|
|
375
|
-
description: "Set the log level of the application.",
|
|
376
|
-
options: [...Object.values(LogLevels), ...Object.values(LogLevels).map((level) => level.toLowerCase())],
|
|
377
|
-
helpGroup: "CLI" /* CLI */,
|
|
378
|
-
parse: async (input) => input?.toUpperCase()
|
|
379
|
-
}),
|
|
380
|
-
ci: import_core.Flags.boolean({
|
|
381
|
-
default: false,
|
|
382
|
-
env: "CI",
|
|
383
|
-
description: "Instruct whether this is running the CI/CD configuration.",
|
|
384
|
-
helpGroup: "CLI" /* CLI */
|
|
385
|
-
}),
|
|
386
|
-
json: import_core.Flags.boolean({
|
|
387
|
-
default: false,
|
|
388
|
-
env: "JSON",
|
|
389
|
-
description: "Put the CLI to respond in JSON.",
|
|
390
|
-
helpGroup: "CLI" /* CLI */
|
|
391
|
-
})
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
// src/lib/config/config.service.ts
|
|
395
|
-
var import_object_path_immutable = __toESM(require("object-path-immutable"));
|
|
396
|
-
var import_path2 = require("path");
|
|
397
|
-
|
|
398
|
-
// src/lib/parser/json-parser.service.ts
|
|
399
|
-
var _JsonParser = class {
|
|
400
|
-
constructor() {
|
|
401
|
-
if (_JsonParser.instance) {
|
|
402
|
-
return _JsonParser.instance;
|
|
403
|
-
}
|
|
404
|
-
_JsonParser.instance = this;
|
|
405
|
-
this.logger = new Logger(this.constructor.name);
|
|
406
|
-
this.logger.trace("Created a new instance.");
|
|
407
|
-
}
|
|
408
|
-
parse(data) {
|
|
409
|
-
try {
|
|
410
|
-
return JSON.parse(data.toString());
|
|
411
|
-
} catch (e) {
|
|
412
|
-
this.logger.trace("Error during parsing JSON file: %s", e.message);
|
|
413
|
-
throw e;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
stringify(data) {
|
|
417
|
-
return JSON.stringify(data, null, 2);
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
var JsonParser = _JsonParser;
|
|
421
|
-
__name(JsonParser, "JsonParser");
|
|
422
|
-
JsonParser.extensions = ["json"];
|
|
423
|
-
|
|
424
|
-
// src/lib/parser/yaml-parser.service.ts
|
|
425
|
-
var import_yaml = require("yaml");
|
|
426
|
-
var _YamlParser = class {
|
|
427
|
-
constructor() {
|
|
428
|
-
if (_YamlParser.instance) {
|
|
429
|
-
return _YamlParser.instance;
|
|
430
|
-
}
|
|
431
|
-
_YamlParser.instance = this;
|
|
432
|
-
this.logger = new Logger(this.constructor.name);
|
|
433
|
-
this.logger.trace("Created a new instance.");
|
|
434
|
-
}
|
|
435
|
-
parse(data) {
|
|
436
|
-
try {
|
|
437
|
-
return (0, import_yaml.parse)(data.toString());
|
|
438
|
-
} catch (e) {
|
|
439
|
-
this.logger.trace("Error during parsing YAML file: %s", e.message);
|
|
440
|
-
throw e;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
stringify(data) {
|
|
444
|
-
return (0, import_yaml.stringify)(data, { prettyErrors: true });
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
var YamlParser = _YamlParser;
|
|
448
|
-
__name(YamlParser, "YamlParser");
|
|
449
|
-
YamlParser.extensions = ["yaml", "yml"];
|
|
450
|
-
|
|
451
|
-
// src/lib/fs/filesystem.service.ts
|
|
452
|
-
var import_fs_extra = __toESM(require("fs-extra"));
|
|
453
|
-
var import_path = require("path");
|
|
454
|
-
var FileSystemService = class {
|
|
455
|
-
constructor() {
|
|
456
|
-
if (FileSystemService.instance) {
|
|
457
|
-
return FileSystemService.instance;
|
|
458
|
-
} else {
|
|
459
|
-
FileSystemService.instance = this;
|
|
460
|
-
this.logger = new Logger(this.constructor.name);
|
|
461
|
-
this.logger.trace("Created a new instance.");
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
exists(path) {
|
|
465
|
-
return import_fs_extra.default.existsSync(path);
|
|
466
|
-
}
|
|
467
|
-
stats(path) {
|
|
468
|
-
return import_fs_extra.default.statSync(path, { throwIfNoEntry: true });
|
|
469
|
-
}
|
|
470
|
-
dirname(path) {
|
|
471
|
-
return (0, import_path.dirname)(path);
|
|
472
|
-
}
|
|
473
|
-
extname(path) {
|
|
474
|
-
return (0, import_path.extname)(path);
|
|
475
|
-
}
|
|
476
|
-
async read(file) {
|
|
477
|
-
try {
|
|
478
|
-
const raw = await import_fs_extra.default.readFile(file, "utf-8");
|
|
479
|
-
return raw;
|
|
480
|
-
} catch (e) {
|
|
481
|
-
throw new Error(`Error while reading file from "${file}": ${e.message}`);
|
|
482
|
-
}
|
|
237
|
+
async read(file) {
|
|
238
|
+
try {
|
|
239
|
+
const raw = await import_fs_extra.default.readFile(file, "utf-8");
|
|
240
|
+
return raw;
|
|
241
|
+
} catch (e) {
|
|
242
|
+
throw new Error(`Error while reading file from "${file}": ${e.message}`);
|
|
243
|
+
}
|
|
483
244
|
}
|
|
484
245
|
readSync(file) {
|
|
485
246
|
try {
|
|
@@ -535,14 +296,28 @@ var FileSystemService = class {
|
|
|
535
296
|
try {
|
|
536
297
|
await import_fs_extra.default.emptyDir(directory);
|
|
537
298
|
} catch (e) {
|
|
538
|
-
throw new Error(`Error while
|
|
299
|
+
throw new Error(`Error while emptying the directory "${directory}": ${e.message}`);
|
|
539
300
|
}
|
|
540
301
|
}
|
|
541
302
|
emptyDirSync(directory) {
|
|
542
303
|
try {
|
|
543
304
|
import_fs_extra.default.emptyDirSync(directory);
|
|
544
305
|
} catch (e) {
|
|
545
|
-
throw new Error(`Error while
|
|
306
|
+
throw new Error(`Error while emptying the directory "${directory}": ${e.message}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async removeDir(directory) {
|
|
310
|
+
try {
|
|
311
|
+
await import_fs_extra.default.rmdir(directory);
|
|
312
|
+
} catch (e) {
|
|
313
|
+
throw new Error(`Error while removing the directory "${directory}": ${e.message}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
removeDirSync(directory) {
|
|
317
|
+
try {
|
|
318
|
+
import_fs_extra.default.rmdirSync(directory);
|
|
319
|
+
} catch (e) {
|
|
320
|
+
throw new Error(`Error while removing the directory "${directory}": ${e.message}`);
|
|
546
321
|
}
|
|
547
322
|
}
|
|
548
323
|
async mkdir(directory) {
|
|
@@ -565,7 +340,7 @@ __name(FileSystemService, "FileSystemService");
|
|
|
565
340
|
// src/lib/parser/parser.service.ts
|
|
566
341
|
var ParserService = class {
|
|
567
342
|
constructor(parsers) {
|
|
568
|
-
this.parsers = [YamlParser, JsonParser];
|
|
343
|
+
this.parsers = [YamlParser, JsonParser, EnvironmentVariableParser];
|
|
569
344
|
if (ParserService.instance) {
|
|
570
345
|
return ParserService.instance;
|
|
571
346
|
} else {
|
|
@@ -579,8 +354,8 @@ var ParserService = class {
|
|
|
579
354
|
}
|
|
580
355
|
}
|
|
581
356
|
getParser(file) {
|
|
582
|
-
const ext = file.includes(".") ? this.fs.extname(file) : file;
|
|
583
|
-
const Parser = this.parsers.find((parser) => parser.extensions.includes(ext
|
|
357
|
+
const ext = (file.includes(".") ? this.fs.extname(file) : file).replace(/^\./, "");
|
|
358
|
+
const Parser = this.parsers.find((parser) => parser.extensions.includes(ext));
|
|
584
359
|
if (!Parser) {
|
|
585
360
|
throw new Error(`Parser for the extension is not configured: ${ext}`);
|
|
586
361
|
}
|
|
@@ -588,9 +363,17 @@ var ParserService = class {
|
|
|
588
363
|
}
|
|
589
364
|
setParsers(...parsers) {
|
|
590
365
|
this.parsers = parsers;
|
|
366
|
+
this.logger.trace(
|
|
367
|
+
"Set parsers: %s",
|
|
368
|
+
this.parsers.map((p) => p.name)
|
|
369
|
+
);
|
|
591
370
|
}
|
|
592
371
|
addParsers(...parsers) {
|
|
593
372
|
this.parsers.push(...parsers);
|
|
373
|
+
this.logger.trace(
|
|
374
|
+
"Added parser, current parsers: %s",
|
|
375
|
+
this.parsers.map((p) => p.name)
|
|
376
|
+
);
|
|
594
377
|
}
|
|
595
378
|
async read(file) {
|
|
596
379
|
return this.parse(file, await this.fs.read(file));
|
|
@@ -599,16 +382,22 @@ var ParserService = class {
|
|
|
599
382
|
return this.fs.write(file, await this.stringify(file, data));
|
|
600
383
|
}
|
|
601
384
|
parse(file, data) {
|
|
602
|
-
const
|
|
603
|
-
|
|
385
|
+
const parser = this.getParser(file);
|
|
386
|
+
this.logger.trace("Parsing file: %s -> %s", file, parser.constructor.name);
|
|
387
|
+
return parser.parse(data);
|
|
604
388
|
}
|
|
605
389
|
stringify(file, data) {
|
|
606
|
-
const
|
|
607
|
-
|
|
390
|
+
const parser = this.getParser(file);
|
|
391
|
+
this.logger.trace("Stringifying file: %s -> %s", file, parser.constructor.name);
|
|
392
|
+
return parser.stringify(data);
|
|
608
393
|
}
|
|
609
394
|
};
|
|
610
395
|
__name(ParserService, "ParserService");
|
|
611
396
|
|
|
397
|
+
// src/utils/color.ts
|
|
398
|
+
var colorette = __toESM(require("colorette"));
|
|
399
|
+
var color = colorette.createColors({ useColor: true });
|
|
400
|
+
|
|
612
401
|
// src/utils/environment.ts
|
|
613
402
|
function isVerbose(logLevel) {
|
|
614
403
|
return logLevel === "VERBOSE" /* VERBOSE */;
|
|
@@ -632,14 +421,16 @@ var MergeStrategy = /* @__PURE__ */ ((MergeStrategy2) => {
|
|
|
632
421
|
|
|
633
422
|
// src/utils/merge.ts
|
|
634
423
|
var import_deepmerge = __toESM(require("deepmerge"));
|
|
635
|
-
function merge(strategy,
|
|
636
|
-
return
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
});
|
|
640
|
-
}, target);
|
|
424
|
+
function merge(strategy, ...source) {
|
|
425
|
+
return import_deepmerge.default.all(source, {
|
|
426
|
+
arrayMerge: strategy === "EXTEND" /* EXTEND */ ? (dest, src) => [...dest, ...src].filter(uniqueFilter) : (_, src) => src
|
|
427
|
+
});
|
|
641
428
|
}
|
|
642
429
|
__name(merge, "merge");
|
|
430
|
+
function uniqueFilter(value, index, self) {
|
|
431
|
+
return self.indexOf(value) === index;
|
|
432
|
+
}
|
|
433
|
+
__name(uniqueFilter, "uniqueFilter");
|
|
643
434
|
|
|
644
435
|
// src/utils/defaults.ts
|
|
645
436
|
function setCtxDefaults(ctx, ...defaults) {
|
|
@@ -707,7 +498,7 @@ var ConfigService = class {
|
|
|
707
498
|
if (configs.length === 0) {
|
|
708
499
|
throw new Error("Nothing to merge, configuration files are empty.");
|
|
709
500
|
}
|
|
710
|
-
return merge(strategy,
|
|
501
|
+
return merge(strategy, ...configs);
|
|
711
502
|
}
|
|
712
503
|
async env(definition, config) {
|
|
713
504
|
const env = typeof definition === "string" ? await this.parser.read(definition) : definition;
|
|
@@ -809,8 +600,12 @@ var LockerService = class {
|
|
|
809
600
|
this.root = root;
|
|
810
601
|
this.toLock = [];
|
|
811
602
|
this.toUnlock = [];
|
|
812
|
-
this.logger = new Logger(context ?? this.constructor.name);
|
|
813
603
|
this.fs = new FileSystemService();
|
|
604
|
+
this.logger = new Logger(context ?? this.constructor.name);
|
|
605
|
+
if (!this.parser) {
|
|
606
|
+
const parser2 = new ParserService();
|
|
607
|
+
this.parser = parser2.getParser(file);
|
|
608
|
+
}
|
|
814
609
|
}
|
|
815
610
|
hasLock() {
|
|
816
611
|
return this.toLock.length > 0;
|
|
@@ -842,200 +637,487 @@ var LockerService = class {
|
|
|
842
637
|
}
|
|
843
638
|
async lock(...data) {
|
|
844
639
|
let lock = await this.tryRead() ?? {};
|
|
845
|
-
|
|
846
|
-
|
|
640
|
+
data.forEach((d) => {
|
|
641
|
+
if (d?.enabled === false) {
|
|
642
|
+
return;
|
|
643
|
+
} else if (!d?.data || Array.isArray(d?.data) && d.data.length === 0 || typeof d?.data === "object" && Object.keys(d.data).length === 0) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
const path = this.buildPath(d);
|
|
647
|
+
if (d?.merge) {
|
|
648
|
+
let parsed;
|
|
649
|
+
if (typeof d.data === "object") {
|
|
650
|
+
parsed = merge(d.merge, import_object_path_immutable2.default.get(lock, path, Array.isArray(d.data) ? [] : {}), d.data);
|
|
651
|
+
} else {
|
|
652
|
+
this.logger.warn('"%s" path with type "%s" is not mergeable.', path, typeof d.data);
|
|
653
|
+
parsed = d.data;
|
|
654
|
+
}
|
|
655
|
+
lock = import_object_path_immutable2.default.set(lock, path, parsed);
|
|
656
|
+
this.logger.verbose("Merge lock: %s -> %o", path, d.data);
|
|
657
|
+
} else {
|
|
658
|
+
lock = import_object_path_immutable2.default.set(lock, path, d.data);
|
|
659
|
+
this.logger.verbose("Override lock: %s -> %o", path, d.data);
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
await this.write(lock);
|
|
663
|
+
}
|
|
664
|
+
async unlock(...data) {
|
|
665
|
+
let lock = await this.tryRead();
|
|
666
|
+
if (!lock) {
|
|
667
|
+
this.logger.verbose("Lock file not found. Nothing to unlock.");
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
if (data.length > 0) {
|
|
671
|
+
data.forEach((d) => {
|
|
847
672
|
if (d?.enabled === false) {
|
|
848
673
|
return;
|
|
849
|
-
} else if (!d?.data || Array.isArray(d?.data) && d.data.length === 0 || typeof d?.data === "object" && Object.keys(d.data).length === 0) {
|
|
850
|
-
return;
|
|
851
674
|
}
|
|
852
675
|
const path = this.buildPath(d);
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
676
|
+
lock = import_object_path_immutable2.default.del(lock, path);
|
|
677
|
+
this.logger.verbose("Unlocked: %s", path);
|
|
678
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
679
|
+
const parentPath = path.slice(0, i);
|
|
680
|
+
const parent = import_object_path_immutable2.default.get(lock, parentPath);
|
|
681
|
+
if (!parent || Array.isArray(parent) && parent.length === 0 || typeof parent === "object" && Object.keys(parent).length === 0) {
|
|
682
|
+
this.logger.verbose("Unlocked parent: %s -> %s", path, parentPath);
|
|
683
|
+
lock = import_object_path_immutable2.default.del(lock, parentPath);
|
|
857
684
|
} else {
|
|
858
|
-
|
|
859
|
-
parsed = d.data;
|
|
685
|
+
break;
|
|
860
686
|
}
|
|
861
|
-
lock = import_object_path_immutable2.default.set(lock, path, parsed);
|
|
862
|
-
this.logger.verbose("Merge lock: %s -> %o", path, parsed);
|
|
863
|
-
} else {
|
|
864
|
-
lock = import_object_path_immutable2.default.set(lock, path, d.data);
|
|
865
|
-
this.logger.verbose("Override lock: %s -> %o", path, d.data);
|
|
866
687
|
}
|
|
867
|
-
})
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
);
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
return this.
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
return
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
688
|
+
});
|
|
689
|
+
} else {
|
|
690
|
+
lock = import_object_path_immutable2.default.del(lock, this.root);
|
|
691
|
+
this.logger.verbose("Unlocked module: %s", this.root);
|
|
692
|
+
}
|
|
693
|
+
await this.write(lock ?? {});
|
|
694
|
+
}
|
|
695
|
+
async read() {
|
|
696
|
+
return this.parser.parse(await this.fs.read(this.file));
|
|
697
|
+
}
|
|
698
|
+
async tryRead() {
|
|
699
|
+
try {
|
|
700
|
+
return this.parser.parse(await this.fs.read(this.file));
|
|
701
|
+
} catch {
|
|
702
|
+
this.logger.trace("Can not read lockfile: %s", this.file);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
async write(data) {
|
|
706
|
+
if (!data || Array.isArray(data) && data.length === 0 || typeof data === "object" && Object.keys(data).length === 0) {
|
|
707
|
+
this.logger.trace("Trying to write empty lock file, deleting it instead: %s", this.file);
|
|
708
|
+
return this.fs.remove(this.file);
|
|
709
|
+
}
|
|
710
|
+
return this.fs.write(this.file, this.parser.stringify(data));
|
|
711
|
+
}
|
|
712
|
+
buildPath(d) {
|
|
713
|
+
if (d?.root !== true && this.root?.length) {
|
|
714
|
+
return [...this.root, ...this.normalizePath(d.path)];
|
|
715
|
+
}
|
|
716
|
+
return this.normalizePath(d.path);
|
|
717
|
+
}
|
|
718
|
+
normalizePath(path) {
|
|
719
|
+
if (Array.isArray(path)) {
|
|
720
|
+
return path.map((p) => p.toString());
|
|
721
|
+
} else if (typeof path === "string") {
|
|
722
|
+
return path.split(".");
|
|
723
|
+
}
|
|
724
|
+
return [];
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
__name(LockerService, "LockerService");
|
|
728
|
+
|
|
729
|
+
// src/lib/store/store.service.ts
|
|
730
|
+
var StoreService = class {
|
|
731
|
+
constructor() {
|
|
732
|
+
this.store = {};
|
|
733
|
+
if (StoreService.instance) {
|
|
734
|
+
return StoreService.instance;
|
|
735
|
+
} else {
|
|
736
|
+
StoreService.instance = this;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
has(key) {
|
|
740
|
+
return !!this.store[key];
|
|
741
|
+
}
|
|
742
|
+
get(key) {
|
|
743
|
+
return this.store[key];
|
|
744
|
+
}
|
|
745
|
+
set(key, data) {
|
|
746
|
+
this.store[key] = data;
|
|
747
|
+
return data;
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
__name(StoreService, "StoreService");
|
|
751
|
+
|
|
752
|
+
// src/lib/validator/validator.service.ts
|
|
753
|
+
var import_class_transformer = require("class-transformer");
|
|
754
|
+
var import_class_validator = require("class-validator");
|
|
755
|
+
var ValidatorService = class {
|
|
756
|
+
constructor(options) {
|
|
757
|
+
this.options = options;
|
|
758
|
+
if (ValidatorService.instance) {
|
|
759
|
+
return ValidatorService.instance;
|
|
760
|
+
}
|
|
761
|
+
this.options = {
|
|
762
|
+
validator: {
|
|
763
|
+
skipMissingProperties: true,
|
|
764
|
+
whitelist: false,
|
|
765
|
+
always: true,
|
|
766
|
+
enableDebugMessages: true
|
|
767
|
+
},
|
|
768
|
+
transformer: { enableImplicitConversion: true },
|
|
769
|
+
...options ?? {}
|
|
770
|
+
};
|
|
771
|
+
this.logger = new Logger(this.constructor.name);
|
|
772
|
+
ValidatorService.instance = this;
|
|
773
|
+
this.logger.trace("Created a new instance.");
|
|
774
|
+
}
|
|
775
|
+
async validate(classType, object, options) {
|
|
776
|
+
const classObject = (0, import_class_transformer.plainToClass)(classType, object, { ...this.options.transformer, ...options.transformer ?? {} });
|
|
777
|
+
const errors = await (0, import_class_validator.validate)(classObject, { ...this.options.validator, ...options.validator ?? {} });
|
|
778
|
+
if (errors.length) {
|
|
779
|
+
errors.forEach((error) => {
|
|
780
|
+
this.logValidationError(error);
|
|
781
|
+
});
|
|
782
|
+
throw new Error("Validation failed.");
|
|
783
|
+
}
|
|
784
|
+
return classObject;
|
|
785
|
+
}
|
|
786
|
+
validateSync(classType, object, options) {
|
|
787
|
+
const classObject = (0, import_class_transformer.plainToClass)(classType, object, { ...this.options.transformer, ...options.transformer ?? {} });
|
|
788
|
+
const errors = (0, import_class_validator.validateSync)(classObject, { ...this.options.validator, ...options.validator ?? {} });
|
|
789
|
+
if (errors.length) {
|
|
790
|
+
errors.forEach((error) => {
|
|
791
|
+
this.logValidationError(error);
|
|
792
|
+
});
|
|
793
|
+
throw new Error("Validation failed.");
|
|
794
|
+
}
|
|
795
|
+
return classObject;
|
|
796
|
+
}
|
|
797
|
+
logValidationError(err) {
|
|
798
|
+
this.logger.error('Field "%s" failed validation with value "%s": %s', err.property, err.value, Object.values(err.constraints).join(", "));
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
__name(ValidatorService, "ValidatorService");
|
|
802
|
+
|
|
803
|
+
// src/lib/setup.ts
|
|
804
|
+
function setup() {
|
|
805
|
+
const inspect = process.argv.indexOf("--inspect");
|
|
806
|
+
if (inspect !== -1) {
|
|
807
|
+
require("inspector").open();
|
|
808
|
+
process.argv.splice(inspect, 1);
|
|
809
|
+
}
|
|
810
|
+
const verbose = process.argv.indexOf("--verbose");
|
|
811
|
+
if (verbose !== -1) {
|
|
812
|
+
process.env.LOG_LEVEL = "verbose";
|
|
813
|
+
process.argv.splice(verbose, 1);
|
|
814
|
+
}
|
|
815
|
+
const debug = process.argv.indexOf("--debug");
|
|
816
|
+
if (debug !== -1) {
|
|
817
|
+
process.env.LOG_LEVEL = "debug";
|
|
818
|
+
process.argv.splice(debug, 1);
|
|
819
|
+
}
|
|
820
|
+
const trace = process.argv.indexOf("--trace");
|
|
821
|
+
if (trace !== -1) {
|
|
822
|
+
process.env.LOG_LEVEL = "trace";
|
|
823
|
+
process.argv.splice(trace, 1);
|
|
824
|
+
}
|
|
825
|
+
const silent = process.argv.indexOf("--silent");
|
|
826
|
+
if (silent !== -1) {
|
|
827
|
+
process.env.LOG_LEVEL = "silent";
|
|
828
|
+
process.argv.splice(silent, 1);
|
|
829
|
+
}
|
|
830
|
+
const sourceMaps = process.argv.indexOf("--source-map");
|
|
831
|
+
if (sourceMaps !== -1) {
|
|
832
|
+
require("source-map-support").install();
|
|
833
|
+
process.argv.splice(sourceMaps, 1);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
__name(setup, "setup");
|
|
837
|
+
|
|
838
|
+
// src/utils/logger/logger.ts
|
|
839
|
+
var Logger = class {
|
|
840
|
+
constructor(context, options) {
|
|
841
|
+
this.context = context;
|
|
842
|
+
this.options = options;
|
|
843
|
+
const parsed = (process.env.LOG_LEVEL ?? options?.level ?? "INFO" /* INFO */).toUpperCase();
|
|
844
|
+
const level = Object.values(LogLevels).includes(parsed) ? parsed : "INFO" /* INFO */;
|
|
845
|
+
this.options = {
|
|
846
|
+
useIcons: true,
|
|
847
|
+
...options,
|
|
848
|
+
level
|
|
849
|
+
};
|
|
850
|
+
if (Logger.instance) {
|
|
851
|
+
this.logger = Logger.instance;
|
|
852
|
+
} else if (context === ConfigService.name) {
|
|
853
|
+
this.logger = this.initiateLogger();
|
|
854
|
+
this.trace("Logger singleton initiated from context: %s", context);
|
|
855
|
+
Logger.instance = this.logger;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
log(level, data, ...args) {
|
|
859
|
+
return this.parseMessage(level, data, args);
|
|
860
|
+
}
|
|
861
|
+
direct(data, ...args) {
|
|
862
|
+
return this.parseMessage("DIRECT" /* DIRECT */, data, args);
|
|
863
|
+
}
|
|
864
|
+
fatal(data, ...args) {
|
|
865
|
+
return this.parseMessage("FATAL" /* FATAL */, data, args);
|
|
866
|
+
}
|
|
867
|
+
error(data, ...args) {
|
|
868
|
+
return this.parseMessage("ERROR" /* ERROR */, data, args);
|
|
869
|
+
}
|
|
870
|
+
warn(data, ...args) {
|
|
871
|
+
return this.parseMessage("WARN" /* WARN */, data, args);
|
|
872
|
+
}
|
|
873
|
+
info(data, ...args) {
|
|
874
|
+
return this.parseMessage("INFO" /* INFO */, data, args);
|
|
875
|
+
}
|
|
876
|
+
debug(data, ...args) {
|
|
877
|
+
return this.parseMessage("DEBUG" /* DEBUG */, data, args);
|
|
878
|
+
}
|
|
879
|
+
verbose(data, ...args) {
|
|
880
|
+
return this.parseMessage("VERBOSE" /* VERBOSE */, data, args);
|
|
881
|
+
}
|
|
882
|
+
trace(data, ...args) {
|
|
883
|
+
return this.parseMessage("TRACE" /* TRACE */, data, args);
|
|
884
|
+
}
|
|
885
|
+
run(data, ...args) {
|
|
886
|
+
return this.parseMessage("INFO" /* INFO */, data, args, { status: "run" /* RUN */ });
|
|
887
|
+
}
|
|
888
|
+
end(data, ...args) {
|
|
889
|
+
return this.parseMessage("INFO" /* INFO */, data, args, { status: "end" /* END */ });
|
|
890
|
+
}
|
|
891
|
+
stage(data, ...args) {
|
|
892
|
+
return this.parseMessage("TRACE" /* TRACE */, data, args, { status: "stage" /* STAGE */ });
|
|
893
|
+
}
|
|
894
|
+
initiateLogger() {
|
|
895
|
+
const logFormat = import_winston.format.printf(({ level, message, context, status }) => {
|
|
896
|
+
let multiLineMessage;
|
|
897
|
+
multiLineMessage = message.split(import_os2.EOL);
|
|
898
|
+
multiLineMessage = multiLineMessage.filter((msg) => msg.trim() !== "").filter(Boolean);
|
|
899
|
+
multiLineMessage = multiLineMessage.map((msg) => {
|
|
900
|
+
return this.logColoring({
|
|
901
|
+
level,
|
|
902
|
+
message: msg,
|
|
903
|
+
context,
|
|
904
|
+
status
|
|
905
|
+
});
|
|
906
|
+
});
|
|
907
|
+
return multiLineMessage.join(import_os2.EOL);
|
|
908
|
+
});
|
|
909
|
+
const logger = import_winston.default.createLogger({
|
|
910
|
+
level: this.options.level,
|
|
911
|
+
format: import_winston.format.combine(import_winston.format.splat(), import_winston.format.json({ space: 2 }), import_winston.format.prettyPrint(), logFormat),
|
|
912
|
+
levels: Object.values(LogLevels).reduce((o, level, i) => {
|
|
913
|
+
return {
|
|
914
|
+
...o,
|
|
915
|
+
[level]: i
|
|
916
|
+
};
|
|
917
|
+
}, {}),
|
|
918
|
+
silent: this.options.level === "SILENT" /* SILENT */,
|
|
919
|
+
transports: [
|
|
920
|
+
new import_winston.transports.Console({
|
|
921
|
+
stderrLevels: ["FATAL" /* FATAL */, "ERROR" /* ERROR */]
|
|
922
|
+
})
|
|
923
|
+
]
|
|
924
|
+
});
|
|
925
|
+
logger.log("TRACE" /* TRACE */, "Initiated new logger with level: %s", this.options.level, { context: this.constructor.name });
|
|
926
|
+
return logger;
|
|
927
|
+
}
|
|
928
|
+
parseMessage(level, data, args, format2) {
|
|
929
|
+
if (!this.logger && !Logger.instance) {
|
|
930
|
+
return;
|
|
931
|
+
} else if (Logger.instance) {
|
|
932
|
+
this.logger = Logger.instance;
|
|
933
|
+
}
|
|
934
|
+
this.logger.log(level, data.toString(), ...args ?? [], { context: this.context, ...format2 ?? {} });
|
|
935
|
+
}
|
|
936
|
+
logColoring({ level, message, context, status }) {
|
|
937
|
+
let icon;
|
|
938
|
+
let coloring = /* @__PURE__ */ __name((input) => {
|
|
939
|
+
return input;
|
|
940
|
+
}, "coloring");
|
|
941
|
+
let msgColoring = /* @__PURE__ */ __name((input) => {
|
|
942
|
+
return input;
|
|
943
|
+
}, "msgColoring");
|
|
944
|
+
switch (level) {
|
|
945
|
+
case "DIRECT" /* DIRECT */:
|
|
946
|
+
return message;
|
|
947
|
+
case "FATAL" /* FATAL */:
|
|
948
|
+
coloring = /* @__PURE__ */ __name((input) => color.red(input), "coloring");
|
|
949
|
+
if (this.options?.useIcons) {
|
|
950
|
+
icon = import_listr2.figures.checkboxOn;
|
|
951
|
+
}
|
|
952
|
+
break;
|
|
953
|
+
case "ERROR" /* ERROR */:
|
|
954
|
+
coloring = color.red;
|
|
955
|
+
if (this.options?.useIcons) {
|
|
956
|
+
icon = import_listr2.figures.cross;
|
|
957
|
+
}
|
|
958
|
+
break;
|
|
959
|
+
case "WARN" /* WARN */:
|
|
960
|
+
coloring = color.yellow;
|
|
961
|
+
if (this.options?.useIcons) {
|
|
962
|
+
icon = import_listr2.figures.warning;
|
|
963
|
+
}
|
|
964
|
+
break;
|
|
965
|
+
case "INFO" /* INFO */:
|
|
966
|
+
coloring = color.green;
|
|
967
|
+
if (this.options?.useIcons) {
|
|
968
|
+
icon = import_listr2.figures.pointerSmall;
|
|
969
|
+
}
|
|
970
|
+
break;
|
|
971
|
+
case "VERBOSE" /* VERBOSE */:
|
|
972
|
+
coloring = color.dim;
|
|
973
|
+
if (this.options?.useIcons) {
|
|
974
|
+
icon = "\u2607";
|
|
975
|
+
}
|
|
976
|
+
break;
|
|
977
|
+
case "DEBUG" /* DEBUG */:
|
|
978
|
+
coloring = color.cyan;
|
|
979
|
+
msgColoring = color.dim;
|
|
980
|
+
if (this.options?.useIcons) {
|
|
981
|
+
icon = "\uF188";
|
|
982
|
+
}
|
|
983
|
+
break;
|
|
984
|
+
case "TRACE" /* TRACE */:
|
|
985
|
+
coloring = color.magenta;
|
|
986
|
+
msgColoring = color.dim;
|
|
987
|
+
if (this.options?.useIcons) {
|
|
988
|
+
icon = "\u26B1";
|
|
989
|
+
}
|
|
990
|
+
break;
|
|
910
991
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
normalizePath(path) {
|
|
914
|
-
if (Array.isArray(path)) {
|
|
915
|
-
return path;
|
|
916
|
-
} else if (typeof path === "string") {
|
|
917
|
-
return path.split(".");
|
|
992
|
+
if (!icon) {
|
|
993
|
+
icon = `[${level.at(0).toUpperCase()}]`;
|
|
918
994
|
}
|
|
919
|
-
return []
|
|
995
|
+
return `${coloring(icon)}${context ? " " + coloring(`[${context}]`) : ""}${status ? " " + coloring(`[${status}]`) : ""} ${msgColoring(message)}`;
|
|
920
996
|
}
|
|
921
997
|
};
|
|
922
|
-
__name(
|
|
998
|
+
__name(Logger, "Logger");
|
|
923
999
|
|
|
924
|
-
// src/
|
|
925
|
-
var
|
|
926
|
-
constructor() {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
return StoreService.instance;
|
|
930
|
-
} else {
|
|
931
|
-
StoreService.instance = this;
|
|
932
|
-
}
|
|
1000
|
+
// src/utils/logger/listr-logger.ts
|
|
1001
|
+
var ListrLogger = class extends import_listr22.Logger {
|
|
1002
|
+
constructor(context) {
|
|
1003
|
+
super();
|
|
1004
|
+
this.logger = new Logger(context);
|
|
933
1005
|
}
|
|
934
|
-
|
|
935
|
-
|
|
1006
|
+
fail(message) {
|
|
1007
|
+
this.logger.error(message);
|
|
936
1008
|
}
|
|
937
|
-
|
|
938
|
-
|
|
1009
|
+
skip(message) {
|
|
1010
|
+
this.logger.warn(message, { status: "skip" });
|
|
939
1011
|
}
|
|
940
|
-
|
|
941
|
-
this.
|
|
942
|
-
return data;
|
|
1012
|
+
success(message) {
|
|
1013
|
+
this.logger.info(message, { status: "end" });
|
|
943
1014
|
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
// src/lib/validator/validator.service.ts
|
|
948
|
-
var import_class_transformer = require("class-transformer");
|
|
949
|
-
var import_class_validator = require("class-validator");
|
|
950
|
-
var ValidatorService = class {
|
|
951
|
-
constructor(options) {
|
|
952
|
-
this.options = options;
|
|
953
|
-
if (ValidatorService.instance) {
|
|
954
|
-
return ValidatorService.instance;
|
|
955
|
-
}
|
|
956
|
-
this.options = {
|
|
957
|
-
validator: {
|
|
958
|
-
skipMissingProperties: true,
|
|
959
|
-
whitelist: false,
|
|
960
|
-
always: true,
|
|
961
|
-
enableDebugMessages: true
|
|
962
|
-
},
|
|
963
|
-
transformer: { enableImplicitConversion: true },
|
|
964
|
-
...options ?? {}
|
|
965
|
-
};
|
|
966
|
-
this.logger = new Logger(this.constructor.name);
|
|
967
|
-
ValidatorService.instance = this;
|
|
968
|
-
this.logger.trace("Created a new instance.");
|
|
1015
|
+
data(message) {
|
|
1016
|
+
this.logger.info(message);
|
|
969
1017
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
const errors = await (0, import_class_validator.validate)(classObject, { ...this.options.validator, ...options.validator ?? {} });
|
|
973
|
-
if (errors.length) {
|
|
974
|
-
errors.forEach((error) => {
|
|
975
|
-
this.logValidationError(error);
|
|
976
|
-
});
|
|
977
|
-
throw new Error("Validation failed.");
|
|
978
|
-
}
|
|
979
|
-
return classObject;
|
|
1018
|
+
start(message) {
|
|
1019
|
+
this.logger.info(message, { status: "run" });
|
|
980
1020
|
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
const errors = (0, import_class_validator.validateSync)(classObject, { ...this.options.validator, ...options.validator ?? {} });
|
|
984
|
-
if (errors.length) {
|
|
985
|
-
errors.forEach((error) => {
|
|
986
|
-
this.logValidationError(error);
|
|
987
|
-
});
|
|
988
|
-
throw new Error("Validation failed.");
|
|
989
|
-
}
|
|
990
|
-
return classObject;
|
|
1021
|
+
title(message) {
|
|
1022
|
+
this.logger.info(message);
|
|
991
1023
|
}
|
|
992
|
-
|
|
993
|
-
this.logger.
|
|
1024
|
+
retry(message) {
|
|
1025
|
+
this.logger.warn(message, { status: "retry" });
|
|
1026
|
+
}
|
|
1027
|
+
rollback(message) {
|
|
1028
|
+
this.logger.error(message, { status: "rollback" });
|
|
994
1029
|
}
|
|
995
1030
|
};
|
|
996
|
-
__name(
|
|
1031
|
+
__name(ListrLogger, "ListrLogger");
|
|
997
1032
|
|
|
998
|
-
// src/
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1033
|
+
// src/utils/logger/pipe/pipe-process-to-listr.ts
|
|
1034
|
+
var import_through = __toESM(require("through"));
|
|
1035
|
+
function pipeProcessThroughListr(task, instance) {
|
|
1036
|
+
const logOut = (0, import_through.default)((chunk) => {
|
|
1037
|
+
task.output = chunk?.toString("utf-8").trim();
|
|
1038
|
+
});
|
|
1039
|
+
instance.stdout.pipe(logOut);
|
|
1040
|
+
instance.stderr.pipe(logOut);
|
|
1041
|
+
return instance;
|
|
1042
|
+
}
|
|
1043
|
+
__name(pipeProcessThroughListr, "pipeProcessThroughListr");
|
|
1044
|
+
|
|
1045
|
+
// src/utils/logger/pipe/pipe-process-to-logger.ts
|
|
1046
|
+
var import_through2 = __toESM(require("through"));
|
|
1047
|
+
function pipeProcessToLogger(logger, instance, options) {
|
|
1048
|
+
options = {
|
|
1049
|
+
start: "INFO" /* INFO */,
|
|
1050
|
+
end: "INFO" /* INFO */,
|
|
1051
|
+
stdout: "INFO" /* INFO */,
|
|
1052
|
+
stderr: "WARN" /* WARN */,
|
|
1053
|
+
...options
|
|
1054
|
+
};
|
|
1055
|
+
if (options.start) {
|
|
1056
|
+
logger.run(instance.spawnargs.join(" "), { level: options.start });
|
|
1019
1057
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1058
|
+
if (instance.stdout) {
|
|
1059
|
+
instance.stdout.pipe(
|
|
1060
|
+
(0, import_through2.default)((chunk) => {
|
|
1061
|
+
logger.log(options.stdout, chunk);
|
|
1062
|
+
})
|
|
1063
|
+
);
|
|
1024
1064
|
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1065
|
+
if (instance.stderr) {
|
|
1066
|
+
instance.stderr.pipe(
|
|
1067
|
+
(0, import_through2.default)((chunk) => {
|
|
1068
|
+
logger.log(options.stderr, chunk);
|
|
1069
|
+
})
|
|
1070
|
+
);
|
|
1029
1071
|
}
|
|
1072
|
+
void instance.on("exit", (code, signal) => {
|
|
1073
|
+
const message = `Process ended with code ${code}${signal ? ` and signal ${signal}` : ""}.`;
|
|
1074
|
+
logger.debug(message);
|
|
1075
|
+
if (options.end) {
|
|
1076
|
+
logger.end(instance.spawnargs.join(" "), { level: options.end });
|
|
1077
|
+
}
|
|
1078
|
+
if (options?.callback) {
|
|
1079
|
+
options.callback();
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
void instance.on("error", (error) => {
|
|
1083
|
+
logger.fatal(error.message);
|
|
1084
|
+
logger.debug(error.stack);
|
|
1085
|
+
if (options?.callback) {
|
|
1086
|
+
options.callback(error);
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
return instance;
|
|
1030
1090
|
}
|
|
1031
|
-
__name(
|
|
1091
|
+
__name(pipeProcessToLogger, "pipeProcessToLogger");
|
|
1092
|
+
|
|
1093
|
+
// src/constants/global-flags.constants.ts
|
|
1094
|
+
var CLI_FLAGS = {
|
|
1095
|
+
["log-level"]: import_core.Flags.enum({
|
|
1096
|
+
default: "INFO" /* INFO */,
|
|
1097
|
+
env: "LOG_LEVEL",
|
|
1098
|
+
description: "Set the log level of the application.",
|
|
1099
|
+
options: [...Object.values(LogLevels), ...Object.values(LogLevels).map((level) => level.toLowerCase())],
|
|
1100
|
+
helpGroup: "CLI" /* CLI */,
|
|
1101
|
+
parse: async (input) => input?.toUpperCase()
|
|
1102
|
+
}),
|
|
1103
|
+
ci: import_core.Flags.boolean({
|
|
1104
|
+
default: false,
|
|
1105
|
+
env: "CI",
|
|
1106
|
+
description: "Instruct whether this is running the CI/CD configuration.",
|
|
1107
|
+
helpGroup: "CLI" /* CLI */
|
|
1108
|
+
}),
|
|
1109
|
+
json: import_core.Flags.boolean({
|
|
1110
|
+
default: false,
|
|
1111
|
+
env: "JSON",
|
|
1112
|
+
description: "Put the CLI to respond in JSON.",
|
|
1113
|
+
helpGroup: "CLI" /* CLI */
|
|
1114
|
+
})
|
|
1115
|
+
};
|
|
1032
1116
|
|
|
1033
1117
|
// src/commands/base.command.ts
|
|
1034
1118
|
var Command = class extends import_core3.Command {
|
|
1035
|
-
constructor(
|
|
1036
|
-
super(
|
|
1037
|
-
this.argv = argv;
|
|
1038
|
-
this.config = config;
|
|
1119
|
+
constructor() {
|
|
1120
|
+
super(...arguments);
|
|
1039
1121
|
this.flags = {};
|
|
1040
1122
|
this.args = {};
|
|
1041
1123
|
}
|
|
@@ -1059,10 +1141,9 @@ var Command = class extends import_core3.Command {
|
|
|
1059
1141
|
delete process.env[this.config.scopedEnvVarKey("REDIRECTED")];
|
|
1060
1142
|
await this.init();
|
|
1061
1143
|
result = await this.run();
|
|
1062
|
-
} catch (error) {
|
|
1063
|
-
await this.catch(error);
|
|
1064
|
-
} finally {
|
|
1065
1144
|
await this.finally();
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
await this.catch(error, 127);
|
|
1066
1147
|
}
|
|
1067
1148
|
if (result && this.jsonEnabled()) {
|
|
1068
1149
|
import_core2.CliUx.ux.styledJSON(this.toSuccessJson(result));
|
|
@@ -1078,19 +1159,17 @@ var Command = class extends import_core3.Command {
|
|
|
1078
1159
|
}
|
|
1079
1160
|
prompt(options) {
|
|
1080
1161
|
return (0, import_listr23.createPrompt)(options, {
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
throw new Error("Cancelled prompt.");
|
|
1084
|
-
}
|
|
1162
|
+
error: true,
|
|
1163
|
+
stdout: process.stdout
|
|
1085
1164
|
});
|
|
1086
1165
|
}
|
|
1087
1166
|
setCtxDefaults(...defaults) {
|
|
1088
1167
|
setCtxDefaults(this.tasks.options.ctx, ...defaults);
|
|
1089
|
-
this.logger.trace("
|
|
1168
|
+
this.logger.trace("Updated context with defaults: %o", this.tasks.options.ctx, { status: "ctx" });
|
|
1090
1169
|
}
|
|
1091
1170
|
setCtxAssign(...assigns) {
|
|
1092
1171
|
setCtxAssign(this.tasks.options.ctx, ...assigns);
|
|
1093
|
-
this.logger.trace("
|
|
1172
|
+
this.logger.trace("Updated context with assign: %o", this.tasks.options.ctx, { status: "ctx" });
|
|
1094
1173
|
}
|
|
1095
1174
|
async init() {
|
|
1096
1175
|
await super.init();
|
|
@@ -1137,10 +1216,12 @@ var Command = class extends import_core3.Command {
|
|
|
1137
1216
|
process.kill(process.pid, "SIGINT");
|
|
1138
1217
|
});
|
|
1139
1218
|
}
|
|
1140
|
-
|
|
1219
|
+
const terminate = /* @__PURE__ */ __name(() => {
|
|
1141
1220
|
this.logger.fatal("Caught terminate signal.", { status: "terminate" /* TERMINATE */ });
|
|
1142
1221
|
process.exit(1);
|
|
1143
|
-
});
|
|
1222
|
+
}, "terminate");
|
|
1223
|
+
process.on("SIGINT", terminate);
|
|
1224
|
+
process.on("SIGTERM", terminate);
|
|
1144
1225
|
this.logger.stage("Running shouldRunBefore.");
|
|
1145
1226
|
await this.shouldRunBefore();
|
|
1146
1227
|
this.logger.stage("Finished shouldRunBefore.");
|
|
@@ -1154,10 +1235,12 @@ var Command = class extends import_core3.Command {
|
|
|
1154
1235
|
this.logger.stage("Finished shouldRunAfter.");
|
|
1155
1236
|
return { ctx };
|
|
1156
1237
|
}
|
|
1157
|
-
catch(e) {
|
|
1238
|
+
catch(e, exit) {
|
|
1158
1239
|
this.logger.fatal(e.message);
|
|
1159
1240
|
this.logger.debug(e.stack, { context: "crash" });
|
|
1160
|
-
|
|
1241
|
+
if (exit > 0) {
|
|
1242
|
+
this.exit(exit);
|
|
1243
|
+
}
|
|
1161
1244
|
return;
|
|
1162
1245
|
}
|
|
1163
1246
|
greet() {
|
|
@@ -1234,6 +1317,7 @@ var storeHook = /* @__PURE__ */ __name((cb) => async (opts) => {
|
|
|
1234
1317
|
Command,
|
|
1235
1318
|
ConfigCommand,
|
|
1236
1319
|
ConfigService,
|
|
1320
|
+
EnvironmentVariableParser,
|
|
1237
1321
|
FileConstants,
|
|
1238
1322
|
FileSystemService,
|
|
1239
1323
|
Flags,
|
|
@@ -1262,5 +1346,6 @@ var storeHook = /* @__PURE__ */ __name((cb) => async (opts) => {
|
|
|
1262
1346
|
setCtxDefaults,
|
|
1263
1347
|
setup,
|
|
1264
1348
|
storeHook,
|
|
1349
|
+
uniqueFilter,
|
|
1265
1350
|
updateNotifierHook
|
|
1266
1351
|
});
|