@cenk1cenk2/oclif-common 3.9.6 → 3.9.8

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.
Files changed (111) hide show
  1. package/dist/base.command-d3038122.d.ts +77 -0
  2. package/dist/commands/base.command.d.ts +24 -0
  3. package/dist/commands/base.command.js +174 -0
  4. package/dist/commands/config.command.d.ts +71 -0
  5. package/dist/commands/config.command.js +60 -0
  6. package/dist/commands/index.d.ts +34 -0
  7. package/dist/commands/index.js +18 -0
  8. package/dist/constants/file.constants.d.ts +5 -0
  9. package/dist/constants/file.constants.js +30 -0
  10. package/dist/constants/global-flags.constants.d.ts +5 -0
  11. package/dist/constants/global-flags.constants.js +53 -0
  12. package/dist/constants/help-groups.constants.d.ts +5 -0
  13. package/dist/constants/help-groups.constants.js +30 -0
  14. package/dist/constants/index.d.ts +4 -0
  15. package/dist/constants/index.js +19 -0
  16. package/dist/hooks/index.d.ts +3 -1
  17. package/dist/hooks/index.js +4 -744
  18. package/dist/hooks/not-found.hook.js +4 -686
  19. package/dist/hooks/store.hook.d.ts +7 -2
  20. package/dist/hooks/store.hook.js +3 -708
  21. package/dist/hooks/update-notifier.hook.js +1 -3
  22. package/dist/index.d.ts +52 -404
  23. package/dist/index.js +7 -1335
  24. package/dist/interfaces/class.interface.d.ts +3 -0
  25. package/dist/interfaces/class.interface.js +15 -0
  26. package/dist/interfaces/config-command.interface.d.ts +12 -0
  27. package/dist/interfaces/config-command.interface.js +15 -0
  28. package/dist/interfaces/index.d.ts +10 -0
  29. package/dist/interfaces/index.js +20 -0
  30. package/dist/interfaces/oclif.interface.d.ts +9 -0
  31. package/dist/interfaces/oclif.interface.js +27 -0
  32. package/dist/interfaces/type-helper.interface.d.ts +8 -0
  33. package/dist/interfaces/type-helper.interface.js +15 -0
  34. package/dist/lib/config/config.constants.d.ts +8 -0
  35. package/dist/lib/config/config.constants.js +33 -0
  36. package/dist/lib/config/config.interface.d.ts +15 -0
  37. package/dist/lib/config/config.interface.js +15 -0
  38. package/dist/lib/config/config.service.d.ts +24 -0
  39. package/dist/lib/config/config.service.js +172 -0
  40. package/dist/lib/config/index.d.ts +24 -0
  41. package/dist/lib/config/index.js +18 -0
  42. package/dist/lib/fs/filesystem.service.d.ts +28 -0
  43. package/dist/lib/fs/filesystem.service.js +162 -0
  44. package/dist/lib/fs/index.d.ts +2 -0
  45. package/dist/lib/fs/index.js +17 -0
  46. package/dist/lib/index.d.ts +29 -0
  47. package/dist/lib/index.js +23 -0
  48. package/dist/lib/locker/index.d.ts +4 -0
  49. package/dist/lib/locker/index.js +18 -0
  50. package/dist/lib/locker/locker.interface.d.ts +17 -0
  51. package/dist/lib/locker/locker.interface.js +15 -0
  52. package/dist/lib/locker/locker.service.d.ts +30 -0
  53. package/dist/lib/locker/locker.service.js +170 -0
  54. package/dist/lib/parser/env-parser.service.d.ts +13 -0
  55. package/dist/lib/parser/env-parser.service.js +62 -0
  56. package/dist/lib/parser/index.d.ts +8 -0
  57. package/dist/lib/parser/index.js +21 -0
  58. package/dist/lib/parser/json-parser.service.d.ts +12 -0
  59. package/dist/lib/parser/json-parser.service.js +52 -0
  60. package/dist/lib/parser/parser.interface.d.ts +7 -0
  61. package/dist/lib/parser/parser.interface.js +15 -0
  62. package/dist/lib/parser/parser.service.d.ts +21 -0
  63. package/dist/lib/parser/parser.service.js +87 -0
  64. package/dist/lib/parser/yaml-parser.service.d.ts +12 -0
  65. package/dist/lib/parser/yaml-parser.service.js +53 -0
  66. package/dist/lib/setup.d.ts +3 -0
  67. package/dist/lib/setup.js +60 -0
  68. package/dist/lib/store/index.d.ts +2 -0
  69. package/dist/lib/store/index.js +18 -0
  70. package/dist/lib/store/store.interface.d.ts +5 -0
  71. package/dist/lib/store/store.interface.js +15 -0
  72. package/dist/lib/store/store.service.d.ts +12 -0
  73. package/dist/lib/store/store.service.js +48 -0
  74. package/dist/lib/validator/index.d.ts +5 -0
  75. package/dist/lib/validator/index.js +18 -0
  76. package/dist/lib/validator/validator.interface.d.ts +9 -0
  77. package/dist/lib/validator/validator.interface.js +15 -0
  78. package/dist/lib/validator/validator.service.d.ts +16 -0
  79. package/dist/lib/validator/validator.service.js +77 -0
  80. package/dist/utils/color.d.ts +5 -0
  81. package/dist/utils/color.js +34 -0
  82. package/dist/utils/defaults.d.ts +11 -0
  83. package/dist/utils/defaults.js +47 -0
  84. package/dist/utils/environment.d.ts +7 -0
  85. package/dist/utils/environment.js +44 -0
  86. package/dist/utils/index.d.ts +17 -0
  87. package/dist/utils/index.js +34 -0
  88. package/dist/utils/logger/index.d.ts +10 -0
  89. package/dist/utils/logger/index.js +21 -0
  90. package/dist/utils/logger/listr-logger.d.ts +20 -0
  91. package/dist/utils/logger/listr-logger.js +60 -0
  92. package/dist/utils/logger/logger.constants.d.ts +20 -0
  93. package/dist/utils/logger/logger.constants.js +48 -0
  94. package/dist/utils/logger/logger.d.ts +31 -0
  95. package/dist/utils/logger/logger.interface.d.ts +16 -0
  96. package/dist/utils/logger/logger.interface.js +15 -0
  97. package/dist/utils/logger/logger.js +200 -0
  98. package/dist/utils/logger/pipe/index.d.ts +9 -0
  99. package/dist/utils/logger/pipe/index.js +19 -0
  100. package/dist/utils/logger/pipe/pipe-process-to-listr.d.ts +6 -0
  101. package/dist/utils/logger/pipe/pipe-process-to-listr.js +43 -0
  102. package/dist/utils/logger/pipe/pipe-process-to-logger.d.ts +13 -0
  103. package/dist/utils/logger/pipe/pipe-process-to-logger.interface.d.ts +16 -0
  104. package/dist/utils/logger/pipe/pipe-process-to-logger.interface.js +15 -0
  105. package/dist/utils/logger/pipe/pipe-process-to-logger.js +80 -0
  106. package/dist/utils/merge.constants.d.ts +6 -0
  107. package/dist/utils/merge.constants.js +31 -0
  108. package/dist/utils/merge.d.ts +8 -0
  109. package/dist/utils/merge.js +47 -0
  110. package/package.json +6 -6
  111. package/dist/store.hook-519df5f8.d.ts +0 -18
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
6
  var __export = (target, all) => {
@@ -17,718 +15,15 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
-
26
- // src/hooks/store.hook.ts
27
19
  var store_hook_exports = {};
28
20
  __export(store_hook_exports, {
29
21
  storeHook: () => storeHook
30
22
  });
31
23
  module.exports = __toCommonJS(store_hook_exports);
32
-
33
- // src/lib/config/config.service.ts
34
- var import_object_path_immutable = __toESM(require("object-path-immutable"));
35
- var import_path2 = require("path");
36
-
37
- // src/interfaces/oclif.interface.ts
38
- var import_core = require("@oclif/core");
39
-
40
- // src/utils/logger/listr-logger.ts
41
- var import_listr22 = require("listr2");
42
-
43
- // src/utils/logger/logger.ts
44
- var import_listr2 = require("listr2");
45
- var import_os = require("os");
46
- var import_winston = __toESM(require("winston"));
47
-
48
- // src/utils/logger/logger.constants.ts
49
- var LogLevels = /* @__PURE__ */ ((LogLevels2) => {
50
- LogLevels2["SILENT"] = "SILENT";
51
- LogLevels2["DIRECT"] = "DIRECT";
52
- LogLevels2["FATAL"] = "FATAL";
53
- LogLevels2["ERROR"] = "ERROR";
54
- LogLevels2["WARN"] = "WARN";
55
- LogLevels2["INFO"] = "INFO";
56
- LogLevels2["VERBOSE"] = "VERBOSE";
57
- LogLevels2["DEBUG"] = "DEBUG";
58
- LogLevels2["TRACE"] = "TRACE";
59
- return LogLevels2;
60
- })(LogLevels || {});
61
-
62
- // src/utils/color.ts
63
- var colorette = __toESM(require("colorette"));
64
- var color = colorette.createColors({ useColor: true });
65
-
66
- // src/utils/logger/logger.ts
67
- var Logger = class {
68
- constructor(context, options) {
69
- this.context = context;
70
- this.options = options;
71
- if (Logger.instance) {
72
- this.logger = Logger.instance;
73
- } else if (context === ConfigService.name) {
74
- const level = Object.values(LogLevels).includes(options?.level) ? options.level : "INFO" /* INFO */;
75
- this.options = {
76
- useIcons: true,
77
- ...options,
78
- level
79
- };
80
- this.logger = this.initiateLogger();
81
- this.trace("Logger singleton initiated from context: %s", context);
82
- Logger.instance = this.logger;
83
- } else {
84
- throw new Error("Logger can only be initiated inside the config service context!");
85
- }
86
- }
87
- log(level, data, ...args) {
88
- return this.parseMessage(level, data, args);
89
- }
90
- direct(data, ...args) {
91
- return this.parseMessage("DIRECT" /* DIRECT */, data, args);
92
- }
93
- fatal(data, ...args) {
94
- return this.parseMessage("FATAL" /* FATAL */, data, args);
95
- }
96
- error(data, ...args) {
97
- return this.parseMessage("ERROR" /* ERROR */, data, args);
98
- }
99
- warn(data, ...args) {
100
- return this.parseMessage("WARN" /* WARN */, data, args);
101
- }
102
- info(data, ...args) {
103
- return this.parseMessage("INFO" /* INFO */, data, args);
104
- }
105
- debug(data, ...args) {
106
- return this.parseMessage("DEBUG" /* DEBUG */, data, args);
107
- }
108
- verbose(data, ...args) {
109
- return this.parseMessage("VERBOSE" /* VERBOSE */, data, args);
110
- }
111
- trace(data, ...args) {
112
- return this.parseMessage("TRACE" /* TRACE */, data, args);
113
- }
114
- run(data, ...args) {
115
- return this.parseMessage("INFO" /* INFO */, data, args, { status: "run" /* RUN */ });
116
- }
117
- end(data, ...args) {
118
- return this.parseMessage("INFO" /* INFO */, data, args, { status: "end" /* END */ });
119
- }
120
- stage(data, ...args) {
121
- return this.parseMessage("TRACE" /* TRACE */, data, args, { status: "stage" /* STAGE */ });
122
- }
123
- initiateLogger() {
124
- const logFormat = import_winston.format.printf(({ level, message, context, status }) => {
125
- let multiLineMessage;
126
- multiLineMessage = message.split(import_os.EOL);
127
- multiLineMessage = multiLineMessage.filter((msg) => msg.trim() !== "").filter(Boolean);
128
- multiLineMessage = multiLineMessage.map((msg) => {
129
- return this.logColoring({
130
- level,
131
- message: msg,
132
- context,
133
- status
134
- });
135
- });
136
- return multiLineMessage.join(import_os.EOL);
137
- });
138
- const logger = import_winston.default.createLogger({
139
- level: this.options.level,
140
- format: import_winston.format.combine(import_winston.format.splat(), import_winston.format.json({ space: 2 }), import_winston.format.prettyPrint(), logFormat),
141
- levels: Object.values(LogLevels).reduce((o, level, i) => {
142
- return {
143
- ...o,
144
- [level]: i
145
- };
146
- }, {}),
147
- silent: this.options.level === "SILENT" /* SILENT */,
148
- transports: [
149
- new import_winston.transports.Console({
150
- stderrLevels: ["FATAL" /* FATAL */, "ERROR" /* ERROR */]
151
- })
152
- ]
153
- });
154
- logger.log("TRACE" /* TRACE */, "Initiated new logger with level: %s", this.options.level, { context: this.constructor.name });
155
- return logger;
156
- }
157
- parseMessage(level, data, args, format2) {
158
- if (!this.logger && !Logger.instance) {
159
- return;
160
- } else if (Logger.instance) {
161
- this.logger = Logger.instance;
162
- }
163
- this.logger.log(level, data.toString(), ...args ?? [], { context: this.context, ...format2 ?? {} });
164
- }
165
- logColoring({ level, message, context, status }) {
166
- let icon;
167
- let coloring = /* @__PURE__ */ __name((input) => {
168
- return input;
169
- }, "coloring");
170
- let msgColoring = /* @__PURE__ */ __name((input) => {
171
- return input;
172
- }, "msgColoring");
173
- switch (level) {
174
- case "DIRECT" /* DIRECT */:
175
- return message;
176
- case "FATAL" /* FATAL */:
177
- coloring = /* @__PURE__ */ __name((input) => color.red(input), "coloring");
178
- if (this.options?.useIcons) {
179
- icon = import_listr2.figures.checkboxOn;
180
- }
181
- break;
182
- case "ERROR" /* ERROR */:
183
- coloring = color.red;
184
- if (this.options?.useIcons) {
185
- icon = import_listr2.figures.cross;
186
- }
187
- break;
188
- case "WARN" /* WARN */:
189
- coloring = color.yellow;
190
- if (this.options?.useIcons) {
191
- icon = import_listr2.figures.warning;
192
- }
193
- break;
194
- case "INFO" /* INFO */:
195
- coloring = color.green;
196
- if (this.options?.useIcons) {
197
- icon = import_listr2.figures.pointerSmall;
198
- }
199
- break;
200
- case "VERBOSE" /* VERBOSE */:
201
- coloring = color.dim;
202
- if (this.options?.useIcons) {
203
- icon = "\u2607";
204
- }
205
- break;
206
- case "DEBUG" /* DEBUG */:
207
- coloring = color.cyan;
208
- msgColoring = color.dim;
209
- if (this.options?.useIcons) {
210
- icon = "\uF188";
211
- }
212
- break;
213
- case "TRACE" /* TRACE */:
214
- coloring = color.magenta;
215
- msgColoring = color.dim;
216
- if (this.options?.useIcons) {
217
- icon = "\u26B1";
218
- }
219
- break;
220
- }
221
- if (!icon) {
222
- icon = `[${level.at(0).toUpperCase()}]`;
223
- }
224
- return `${coloring(icon)}${context ? " " + coloring(`[${context}]`) : ""}${status ? " " + coloring(`[${status}]`) : ""} ${msgColoring(message)}`;
225
- }
226
- };
227
- __name(Logger, "Logger");
228
-
229
- // src/utils/logger/pipe/pipe-process-to-listr.ts
230
- var import_through = __toESM(require("through"));
231
-
232
- // src/utils/logger/pipe/pipe-process-to-logger.ts
233
- var import_through2 = __toESM(require("through"));
234
-
235
- // src/constants/global-flags.constants.ts
236
- var CLI_FLAGS = {
237
- ["log-level"]: import_core.Flags.enum({
238
- default: "INFO" /* INFO */,
239
- env: "LOG_LEVEL",
240
- description: "Set the log level of the application.",
241
- options: [...Object.values(LogLevels).map((level) => level.toLowerCase())],
242
- helpGroup: "CLI" /* CLI */,
243
- parse: async (input) => input?.toUpperCase()
244
- }),
245
- ci: import_core.Flags.boolean({
246
- default: false,
247
- hidden: true,
248
- env: "CI",
249
- description: "Instruct whether this is running the CI/CD configuration.",
250
- helpGroup: "CLI" /* CLI */
251
- }),
252
- json: import_core.Flags.boolean({
253
- default: false,
254
- hidden: true,
255
- env: "JSON",
256
- description: "Put the CLI to respond in JSON.",
257
- helpGroup: "CLI" /* CLI */
258
- })
259
- };
260
-
261
- // src/lib/parser/env-parser.service.ts
262
- var import_os2 = require("os");
263
- var _EnvironmentVariableParser = class {
264
- constructor() {
265
- this.LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
266
- if (_EnvironmentVariableParser.instance) {
267
- return _EnvironmentVariableParser.instance;
268
- }
269
- _EnvironmentVariableParser.instance = this;
270
- this.logger = new Logger(this.constructor.name);
271
- this.logger.trace("Created a new instance.");
272
- }
273
- parse(data) {
274
- try {
275
- return data.toString().split(import_os2.EOL).reduce((o, line) => {
276
- const match = this.LINE.exec(line);
277
- const key = match[1];
278
- const value = match[2] ?? "";
279
- return {
280
- ...o,
281
- [key]: value
282
- };
283
- }, {});
284
- } catch (e) {
285
- this.logger.trace("Error during parsing environment file: %s", e.message);
286
- throw e;
287
- }
288
- }
289
- stringify(data) {
290
- return Object.entries(data).map(([k, v]) => `${k}=${v}`).join(import_os2.EOL) + import_os2.EOL;
291
- }
292
- };
293
- var EnvironmentVariableParser = _EnvironmentVariableParser;
294
- __name(EnvironmentVariableParser, "EnvironmentVariableParser");
295
- EnvironmentVariableParser.extensions = ["env"];
296
-
297
- // src/lib/parser/json-parser.service.ts
298
- var _JsonParser = class {
299
- constructor() {
300
- if (_JsonParser.instance) {
301
- return _JsonParser.instance;
302
- }
303
- _JsonParser.instance = this;
304
- this.logger = new Logger(this.constructor.name);
305
- this.logger.trace("Created a new instance.");
306
- }
307
- parse(data) {
308
- try {
309
- return JSON.parse(data.toString());
310
- } catch (e) {
311
- this.logger.trace("Error during parsing JSON file: %s", e.message);
312
- throw e;
313
- }
314
- }
315
- stringify(data) {
316
- return JSON.stringify(data, null, 2);
317
- }
318
- };
319
- var JsonParser = _JsonParser;
320
- __name(JsonParser, "JsonParser");
321
- JsonParser.extensions = ["json"];
322
-
323
- // src/lib/parser/yaml-parser.service.ts
324
- var import_yaml = require("yaml");
325
- var _YamlParser = class {
326
- constructor() {
327
- if (_YamlParser.instance) {
328
- return _YamlParser.instance;
329
- }
330
- _YamlParser.instance = this;
331
- this.logger = new Logger(this.constructor.name);
332
- this.logger.trace("Created a new instance.");
333
- }
334
- parse(data) {
335
- try {
336
- return (0, import_yaml.parse)(data.toString());
337
- } catch (e) {
338
- this.logger.trace("Error during parsing YAML file: %s", e.message);
339
- throw e;
340
- }
341
- }
342
- stringify(data) {
343
- return (0, import_yaml.stringify)(data, { prettyErrors: true });
344
- }
345
- };
346
- var YamlParser = _YamlParser;
347
- __name(YamlParser, "YamlParser");
348
- YamlParser.extensions = ["yaml", "yml"];
349
-
350
- // src/lib/fs/filesystem.service.ts
351
- var import_fs_extra = __toESM(require("fs-extra"));
352
- var import_path = require("path");
353
- var FileSystemService = class {
354
- constructor() {
355
- if (FileSystemService.instance) {
356
- return FileSystemService.instance;
357
- } else {
358
- FileSystemService.instance = this;
359
- this.logger = new Logger(this.constructor.name);
360
- this.logger.trace("Created a new instance.");
361
- }
362
- }
363
- exists(path) {
364
- return import_fs_extra.default.existsSync(path);
365
- }
366
- stats(path) {
367
- return import_fs_extra.default.statSync(path, { throwIfNoEntry: true });
368
- }
369
- dirname(path) {
370
- return (0, import_path.dirname)(path);
371
- }
372
- extname(path) {
373
- return (0, import_path.extname)(path);
374
- }
375
- async read(file) {
376
- try {
377
- const raw = await import_fs_extra.default.readFile(file, "utf-8");
378
- return raw;
379
- } catch (e) {
380
- throw new Error(`Error while reading file from "${file}": ${e.message}`);
381
- }
382
- }
383
- readSync(file) {
384
- try {
385
- const raw = import_fs_extra.default.readFileSync(file, "utf-8");
386
- return raw;
387
- } catch (e) {
388
- throw new Error(`Error while reading file from "${file}": ${e.message}`);
389
- }
390
- }
391
- async write(file, data, options = {}) {
392
- try {
393
- await import_fs_extra.default.writeFile(file, data, { encoding: "utf-8", ...options });
394
- } catch (e) {
395
- throw new Error(`Error while writing file to "${file}": ${e.message}`);
396
- }
397
- }
398
- writeSync(file, data, options = {}) {
399
- try {
400
- import_fs_extra.default.writeFileSync(file, data, { encoding: "utf-8", ...options });
401
- } catch (e) {
402
- throw new Error(`Error while writing file to "${file}": ${e.message}`);
403
- }
404
- }
405
- async append(file, data, options) {
406
- try {
407
- await import_fs_extra.default.appendFile(file, data, options);
408
- } catch (e) {
409
- throw new Error(`Error while appending to file "${file}": ${e.message}`);
410
- }
411
- }
412
- appendSync(file, data) {
413
- try {
414
- import_fs_extra.default.appendFileSync(file, data);
415
- } catch (e) {
416
- throw new Error(`Error while appending to file "${file}": ${e.message}`);
417
- }
418
- }
419
- async remove(file, options) {
420
- try {
421
- await import_fs_extra.default.rm(file, options);
422
- } catch (e) {
423
- throw new Error(`Error while deleting the file "${file}": ${e.message}`);
424
- }
425
- }
426
- removeSync(file, options) {
427
- try {
428
- import_fs_extra.default.rmSync(file, options);
429
- } catch (e) {
430
- throw new Error(`Error while deleting the file "${file}": ${e.message}`);
431
- }
432
- }
433
- async emptyDir(directory) {
434
- try {
435
- await import_fs_extra.default.emptyDir(directory);
436
- } catch (e) {
437
- throw new Error(`Error while emptying the directory "${directory}": ${e.message}`);
438
- }
439
- }
440
- emptyDirSync(directory) {
441
- try {
442
- import_fs_extra.default.emptyDirSync(directory);
443
- } catch (e) {
444
- throw new Error(`Error while emptying the directory "${directory}": ${e.message}`);
445
- }
446
- }
447
- async removeDir(directory) {
448
- try {
449
- await import_fs_extra.default.rmdir(directory);
450
- } catch (e) {
451
- throw new Error(`Error while removing the directory "${directory}": ${e.message}`);
452
- }
453
- }
454
- removeDirSync(directory) {
455
- try {
456
- import_fs_extra.default.rmdirSync(directory);
457
- } catch (e) {
458
- throw new Error(`Error while removing the directory "${directory}": ${e.message}`);
459
- }
460
- }
461
- async mkdir(directory) {
462
- try {
463
- await import_fs_extra.default.mkdirp(directory);
464
- } catch (e) {
465
- throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
466
- }
467
- }
468
- mkdirSync(directory) {
469
- try {
470
- import_fs_extra.default.mkdirSync(directory);
471
- } catch (e) {
472
- throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
473
- }
474
- }
475
- };
476
- __name(FileSystemService, "FileSystemService");
477
-
478
- // src/lib/parser/parser.service.ts
479
- var ParserService = class {
480
- constructor(parsers) {
481
- this.parsers = [YamlParser, JsonParser, EnvironmentVariableParser];
482
- if (ParserService.instance) {
483
- return ParserService.instance;
484
- } else {
485
- if (parsers) {
486
- this.parsers = parsers;
487
- }
488
- this.logger = new Logger(this.constructor.name);
489
- this.fs = new FileSystemService();
490
- ParserService.instance = this;
491
- this.logger.trace("Created a new instance.");
492
- }
493
- }
494
- getParser(file) {
495
- const ext = (file.includes(".") ? this.fs.extname(file) : file).replace(/^\./, "");
496
- const Parser = this.parsers.find((parser) => parser.extensions.includes(ext));
497
- if (!Parser) {
498
- throw new Error(`Parser for the extension is not configured: ${ext}`);
499
- }
500
- return new Parser();
501
- }
502
- setParsers(...parsers) {
503
- this.parsers = parsers;
504
- this.logger.trace(
505
- "Set parsers: %s",
506
- this.parsers.map((p) => p.name)
507
- );
508
- }
509
- addParsers(...parsers) {
510
- this.parsers.push(...parsers);
511
- this.logger.trace(
512
- "Added parser, current parsers: %s",
513
- this.parsers.map((p) => p.name)
514
- );
515
- }
516
- async read(file) {
517
- return this.parse(file, await this.fs.read(file));
518
- }
519
- async write(file, data) {
520
- return this.fs.write(file, await this.stringify(file, data));
521
- }
522
- parse(file, data) {
523
- const parser = this.getParser(file);
524
- this.logger.trace("Parsing file: %s -> %s", file, parser.constructor.name);
525
- return parser.parse(data);
526
- }
527
- stringify(file, data) {
528
- const parser = this.getParser(file);
529
- this.logger.trace("Stringifying file: %s -> %s", file, parser.constructor.name);
530
- return parser.stringify(data);
531
- }
532
- };
533
- __name(ParserService, "ParserService");
534
-
535
- // src/utils/environment.ts
536
- function isVerbose(logLevel) {
537
- return logLevel === "VERBOSE" /* VERBOSE */;
538
- }
539
- __name(isVerbose, "isVerbose");
540
- function isDebug(logLevel) {
541
- return ["DEBUG" /* DEBUG */, "TRACE" /* TRACE */].includes(logLevel);
542
- }
543
- __name(isDebug, "isDebug");
544
- function isSilent(logLevel) {
545
- return logLevel === "SILENT" /* SILENT */;
546
- }
547
- __name(isSilent, "isSilent");
548
-
549
- // src/utils/merge.ts
550
- var import_deepmerge = __toESM(require("deepmerge"));
551
- function merge(strategy, ...source) {
552
- return import_deepmerge.default.all(source, {
553
- arrayMerge: strategy === "EXTEND" /* EXTEND */ ? (dest, src) => [...dest, ...src].filter(uniqueFilter) : (_, src) => src
554
- });
555
- }
556
- __name(merge, "merge");
557
- function uniqueFilter(value, index, self) {
558
- return self.indexOf(value) === index;
559
- }
560
- __name(uniqueFilter, "uniqueFilter");
561
-
562
- // src/utils/index.ts
563
- var import_core2 = require("@oclif/core");
564
-
565
- // src/lib/config/config.service.ts
566
- var ConfigService = class {
567
- constructor(oclif, command, config) {
568
- this.oclif = oclif;
569
- this.command = command;
570
- if (ConfigService.instance) {
571
- return ConfigService.instance;
572
- }
573
- this.root = this.oclif.root;
574
- this.defaults = (0, import_path2.join)(this.oclif.root, "config" /* CONFIG_SERVICE_DEFAULTS_DIR */);
575
- this.logger = new Logger(this.constructor.name, { level: config.logLevel });
576
- Object.assign(this, config);
577
- this.recalculate();
578
- this.parser = new ParserService();
579
- ConfigService.instance = this;
580
- this.logger.trace("Created a new instance.");
581
- }
582
- async read(path) {
583
- const config = await this.parser.read(path);
584
- this.logger.trace("Read config from: %s", path);
585
- return config;
586
- }
587
- async extend(paths, strategy = "OVERWRITE" /* OVERWRITE */) {
588
- this.logger.trace("Will generate config from: %o with %s", paths, strategy);
589
- const configs = (await Promise.all(
590
- paths.map(async (path) => {
591
- try {
592
- const config = typeof path === "string" ? await this.parser.read(path) : path;
593
- this.logger.trace("Extending config from: %s", path);
594
- return config;
595
- } catch (e) {
596
- this.logger.trace("Failed to extend config from: %s", e.message);
597
- }
598
- })
599
- )).filter(Boolean);
600
- return this.merge(configs, strategy);
601
- }
602
- merge(configs, strategy = "OVERWRITE" /* OVERWRITE */) {
603
- if (configs.length === 0) {
604
- throw new Error("Nothing to merge, configuration files are empty.");
605
- }
606
- return merge(strategy, ...configs);
607
- }
608
- async env(definition, config) {
609
- const env = typeof definition === "string" ? await this.parser.read(definition) : definition;
610
- this.logger.trace("Environment variable extensions read: %o", definition);
611
- const iter = /* @__PURE__ */ __name(async (obj, parent) => {
612
- const data = await Promise.all(
613
- Object.entries(obj).map(async ([key, value]) => {
614
- const location = [...parent ?? [], key];
615
- if (typeof value === "string") {
616
- return [{ key: location, env: value }];
617
- } else if (typeof value === "object") {
618
- let extensions;
619
- if ("__element" /* ELEMENT */ in value) {
620
- extensions = await iter(value["__element" /* ELEMENT */], [...location, "__element" /* ELEMENT */]);
621
- this.logger.trace("Expanding location to elements: %s -> %s", location, extensions.map((extension) => extension.key.join(".")).join(", "));
622
- }
623
- if ("__name" /* NAME */ in value && "__format" /* PARSER */ in value) {
624
- const variable = [
625
- {
626
- key: location,
627
- env: value["__name" /* NAME */],
628
- parser: value["__format" /* PARSER */],
629
- extensions
630
- }
631
- ];
632
- return variable;
633
- } else {
634
- return iter(value, location);
635
- }
636
- }
637
- })
638
- );
639
- return data.flatMap((d) => d).filter(Boolean);
640
- }, "iter");
641
- const parsed = await iter(env);
642
- const cb = /* @__PURE__ */ __name((config2, variable, data) => {
643
- if (variable.parser) {
644
- try {
645
- data = this.parser.parse(variable.parser, data);
646
- } catch (e) {
647
- this.logger.trace("Can not parse environment environment variable for config: %s -> %s with %s", variable.key.join("."), variable.env, variable.parser);
648
- throw e;
649
- }
650
- }
651
- this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
652
- return import_object_path_immutable.default.set(config2, variable.key, data);
653
- }, "cb");
654
- parsed.forEach((variable) => {
655
- let data;
656
- data = process.env[variable.env];
657
- if (data) {
658
- config = cb(config, variable, data);
659
- }
660
- if (variable.extensions && variable.extensions.length > 0) {
661
- const timeout = 6e4;
662
- const startedAt = Date.now();
663
- for (let i = 0; i < Infinity; i++) {
664
- if (Date.now() - startedAt > timeout) {
665
- throw new Error(`Timed-out in ${timeout}ms while looking for element environment variables.`);
666
- }
667
- const extensions = variable.extensions.map((extension) => {
668
- const clone = JSON.parse(JSON.stringify(extension));
669
- clone.env = clone.env.replace("${i}" /* ELEMENT_REPLACER */, i.toString());
670
- clone.key[clone.key.findIndex((value) => value === "__element" /* ELEMENT */)] = i.toString();
671
- data = process.env[clone.env];
672
- if (!data) {
673
- this.logger.trace("No extension for environment variable: %s -> %s", clone.key.join("."), clone.env);
674
- return;
675
- }
676
- config = cb(config, clone, data);
677
- return true;
678
- }).filter(Boolean);
679
- if (extensions.length === 0) {
680
- this.logger.trace("No more extensions for environment variables: %s -> %d", variable.key.join("."), i);
681
- break;
682
- }
683
- }
684
- }
685
- });
686
- return config;
687
- }
688
- async write(path, data) {
689
- return this.parser.write(path, data);
690
- }
691
- recalculate() {
692
- this.isVerbose = isVerbose(this.logLevel);
693
- this.isDebug = isDebug(this.logLevel);
694
- this.isSilent = isSilent(this.logLevel);
695
- }
696
- };
697
- __name(ConfigService, "ConfigService");
698
-
699
- // src/lib/locker/locker.service.ts
700
- var import_object_path_immutable2 = __toESM(require("object-path-immutable"));
701
-
702
- // src/lib/store/store.service.ts
703
- var StoreService = class {
704
- constructor() {
705
- this.store = {};
706
- if (StoreService.instance) {
707
- return StoreService.instance;
708
- } else {
709
- StoreService.instance = this;
710
- }
711
- }
712
- has(key) {
713
- return !!this.store[key];
714
- }
715
- get(key) {
716
- return this.store[key];
717
- }
718
- set(key, data) {
719
- this.store[key] = data;
720
- return data;
721
- }
722
- };
723
- __name(StoreService, "StoreService");
724
-
725
- // src/lib/validator/validator.service.ts
726
- var import_class_transformer = require("class-transformer");
727
- var import_class_validator = require("class-validator");
728
-
729
- // src/hooks/store.hook.ts
730
- var storeHook = /* @__PURE__ */ __name((cb) => async (opts) => {
731
- cb(opts, new StoreService());
24
+ var import_lib = require("../lib");
25
+ const storeHook = /* @__PURE__ */ __name((cb) => async (opts) => {
26
+ cb(opts, new import_lib.StoreService());
732
27
  }, "storeHook");
733
28
  // Annotate the CommonJS export names for ESM import in node:
734
29
  0 && (module.exports = {