@cenk1cenk2/oclif-common 3.9.5 → 3.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,18 +70,20 @@ var CLI_FLAGS = {
70
70
  default: "INFO" /* INFO */,
71
71
  env: "LOG_LEVEL",
72
72
  description: "Set the log level of the application.",
73
- options: [...Object.values(LogLevels), ...Object.values(LogLevels).map((level) => level.toLowerCase())],
73
+ options: [...Object.values(LogLevels).map((level) => level.toLowerCase())],
74
74
  helpGroup: "CLI" /* CLI */,
75
75
  parse: async (input) => input?.toUpperCase()
76
76
  }),
77
77
  ci: import_core.Flags.boolean({
78
78
  default: false,
79
+ hidden: true,
79
80
  env: "CI",
80
81
  description: "Instruct whether this is running the CI/CD configuration.",
81
82
  helpGroup: "CLI" /* CLI */
82
83
  }),
83
84
  json: import_core.Flags.boolean({
84
85
  default: false,
86
+ hidden: true,
85
87
  env: "JSON",
86
88
  description: "Put the CLI to respond in JSON.",
87
89
  helpGroup: "CLI" /* CLI */
@@ -402,16 +404,14 @@ var ConfigService = class {
402
404
  this.oclif = oclif;
403
405
  this.command = command;
404
406
  if (ConfigService.instance) {
405
- if (Object.entries(config).some(([key, value]) => value !== ConfigService.instance[key])) {
406
- ConfigService.instance.recalculate(config);
407
- }
408
407
  return ConfigService.instance;
409
408
  }
410
409
  this.root = this.oclif.root;
411
410
  this.defaults = (0, import_path2.join)(this.oclif.root, "config" /* CONFIG_SERVICE_DEFAULTS_DIR */);
412
411
  this.logger = new Logger(this.constructor.name, { level: config.logLevel });
412
+ Object.assign(this, config);
413
+ this.recalculate();
413
414
  this.parser = new ParserService();
414
- this.recalculate(config);
415
415
  ConfigService.instance = this;
416
416
  this.logger.trace("Created a new instance.");
417
417
  }
@@ -524,13 +524,10 @@ var ConfigService = class {
524
524
  async write(path, data) {
525
525
  return this.parser.write(path, data);
526
526
  }
527
- recalculate(config) {
528
- this.ci = config.ci;
529
- this.json = config.json;
530
- this.logLevel = config.logLevel;
531
- this.isVerbose = isVerbose(config.logLevel);
532
- this.isDebug = isDebug(config.logLevel);
533
- this.isSilent = isSilent(config.logLevel);
527
+ recalculate() {
528
+ this.isVerbose = isVerbose(this.logLevel);
529
+ this.isDebug = isDebug(this.logLevel);
530
+ this.isSilent = isSilent(this.logLevel);
534
531
  }
535
532
  };
536
533
  __name(ConfigService, "ConfigService");
@@ -570,19 +567,20 @@ var Logger = class {
570
567
  constructor(context, options) {
571
568
  this.context = context;
572
569
  this.options = options;
573
- const parsed = (process.env.LOG_LEVEL ?? options?.level ?? "INFO" /* INFO */).toUpperCase();
574
- const level = Object.values(LogLevels).includes(parsed) ? parsed : "INFO" /* INFO */;
575
- this.options = {
576
- useIcons: true,
577
- ...options,
578
- level
579
- };
580
570
  if (Logger.instance) {
581
571
  this.logger = Logger.instance;
582
572
  } else if (context === ConfigService.name) {
573
+ const level = Object.values(LogLevels).includes(options?.level) ? options.level : "INFO" /* INFO */;
574
+ this.options = {
575
+ useIcons: true,
576
+ ...options,
577
+ level
578
+ };
583
579
  this.logger = this.initiateLogger();
584
580
  this.trace("Logger singleton initiated from context: %s", context);
585
581
  Logger.instance = this.logger;
582
+ } else {
583
+ throw new Error("Logger can only be initiated inside the config service context!");
586
584
  }
587
585
  }
588
586
  log(level, data, ...args) {
@@ -66,18 +66,20 @@ var CLI_FLAGS = {
66
66
  default: "INFO" /* INFO */,
67
67
  env: "LOG_LEVEL",
68
68
  description: "Set the log level of the application.",
69
- options: [...Object.values(LogLevels), ...Object.values(LogLevels).map((level) => level.toLowerCase())],
69
+ options: [...Object.values(LogLevels).map((level) => level.toLowerCase())],
70
70
  helpGroup: "CLI" /* CLI */,
71
71
  parse: async (input) => input?.toUpperCase()
72
72
  }),
73
73
  ci: import_core.Flags.boolean({
74
74
  default: false,
75
+ hidden: true,
75
76
  env: "CI",
76
77
  description: "Instruct whether this is running the CI/CD configuration.",
77
78
  helpGroup: "CLI" /* CLI */
78
79
  }),
79
80
  json: import_core.Flags.boolean({
80
81
  default: false,
82
+ hidden: true,
81
83
  env: "JSON",
82
84
  description: "Put the CLI to respond in JSON.",
83
85
  helpGroup: "CLI" /* CLI */
@@ -398,16 +400,14 @@ var ConfigService = class {
398
400
  this.oclif = oclif;
399
401
  this.command = command;
400
402
  if (ConfigService.instance) {
401
- if (Object.entries(config).some(([key, value]) => value !== ConfigService.instance[key])) {
402
- ConfigService.instance.recalculate(config);
403
- }
404
403
  return ConfigService.instance;
405
404
  }
406
405
  this.root = this.oclif.root;
407
406
  this.defaults = (0, import_path2.join)(this.oclif.root, "config" /* CONFIG_SERVICE_DEFAULTS_DIR */);
408
407
  this.logger = new Logger(this.constructor.name, { level: config.logLevel });
408
+ Object.assign(this, config);
409
+ this.recalculate();
409
410
  this.parser = new ParserService();
410
- this.recalculate(config);
411
411
  ConfigService.instance = this;
412
412
  this.logger.trace("Created a new instance.");
413
413
  }
@@ -520,13 +520,10 @@ var ConfigService = class {
520
520
  async write(path, data) {
521
521
  return this.parser.write(path, data);
522
522
  }
523
- recalculate(config) {
524
- this.ci = config.ci;
525
- this.json = config.json;
526
- this.logLevel = config.logLevel;
527
- this.isVerbose = isVerbose(config.logLevel);
528
- this.isDebug = isDebug(config.logLevel);
529
- this.isSilent = isSilent(config.logLevel);
523
+ recalculate() {
524
+ this.isVerbose = isVerbose(this.logLevel);
525
+ this.isDebug = isDebug(this.logLevel);
526
+ this.isSilent = isSilent(this.logLevel);
530
527
  }
531
528
  };
532
529
  __name(ConfigService, "ConfigService");
@@ -543,19 +540,20 @@ var Logger = class {
543
540
  constructor(context, options) {
544
541
  this.context = context;
545
542
  this.options = options;
546
- const parsed = (process.env.LOG_LEVEL ?? options?.level ?? "INFO" /* INFO */).toUpperCase();
547
- const level = Object.values(LogLevels).includes(parsed) ? parsed : "INFO" /* INFO */;
548
- this.options = {
549
- useIcons: true,
550
- ...options,
551
- level
552
- };
553
543
  if (Logger.instance) {
554
544
  this.logger = Logger.instance;
555
545
  } else if (context === ConfigService.name) {
546
+ const level = Object.values(LogLevels).includes(options?.level) ? options.level : "INFO" /* INFO */;
547
+ this.options = {
548
+ useIcons: true,
549
+ ...options,
550
+ level
551
+ };
556
552
  this.logger = this.initiateLogger();
557
553
  this.trace("Logger singleton initiated from context: %s", context);
558
554
  Logger.instance = this.logger;
555
+ } else {
556
+ throw new Error("Logger can only be initiated inside the config service context!");
559
557
  }
560
558
  }
561
559
  log(level, data, ...args) {
@@ -68,19 +68,20 @@ var Logger = class {
68
68
  constructor(context, options) {
69
69
  this.context = context;
70
70
  this.options = options;
71
- const parsed = (process.env.LOG_LEVEL ?? options?.level ?? "INFO" /* INFO */).toUpperCase();
72
- const level = Object.values(LogLevels).includes(parsed) ? parsed : "INFO" /* INFO */;
73
- this.options = {
74
- useIcons: true,
75
- ...options,
76
- level
77
- };
78
71
  if (Logger.instance) {
79
72
  this.logger = Logger.instance;
80
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
+ };
81
80
  this.logger = this.initiateLogger();
82
81
  this.trace("Logger singleton initiated from context: %s", context);
83
82
  Logger.instance = this.logger;
83
+ } else {
84
+ throw new Error("Logger can only be initiated inside the config service context!");
84
85
  }
85
86
  }
86
87
  log(level, data, ...args) {
@@ -237,18 +238,20 @@ var CLI_FLAGS = {
237
238
  default: "INFO" /* INFO */,
238
239
  env: "LOG_LEVEL",
239
240
  description: "Set the log level of the application.",
240
- options: [...Object.values(LogLevels), ...Object.values(LogLevels).map((level) => level.toLowerCase())],
241
+ options: [...Object.values(LogLevels).map((level) => level.toLowerCase())],
241
242
  helpGroup: "CLI" /* CLI */,
242
243
  parse: async (input) => input?.toUpperCase()
243
244
  }),
244
245
  ci: import_core.Flags.boolean({
245
246
  default: false,
247
+ hidden: true,
246
248
  env: "CI",
247
249
  description: "Instruct whether this is running the CI/CD configuration.",
248
250
  helpGroup: "CLI" /* CLI */
249
251
  }),
250
252
  json: import_core.Flags.boolean({
251
253
  default: false,
254
+ hidden: true,
252
255
  env: "JSON",
253
256
  description: "Put the CLI to respond in JSON.",
254
257
  helpGroup: "CLI" /* CLI */
@@ -565,16 +568,14 @@ var ConfigService = class {
565
568
  this.oclif = oclif;
566
569
  this.command = command;
567
570
  if (ConfigService.instance) {
568
- if (Object.entries(config).some(([key, value]) => value !== ConfigService.instance[key])) {
569
- ConfigService.instance.recalculate(config);
570
- }
571
571
  return ConfigService.instance;
572
572
  }
573
573
  this.root = this.oclif.root;
574
574
  this.defaults = (0, import_path2.join)(this.oclif.root, "config" /* CONFIG_SERVICE_DEFAULTS_DIR */);
575
575
  this.logger = new Logger(this.constructor.name, { level: config.logLevel });
576
+ Object.assign(this, config);
577
+ this.recalculate();
576
578
  this.parser = new ParserService();
577
- this.recalculate(config);
578
579
  ConfigService.instance = this;
579
580
  this.logger.trace("Created a new instance.");
580
581
  }
@@ -687,13 +688,10 @@ var ConfigService = class {
687
688
  async write(path, data) {
688
689
  return this.parser.write(path, data);
689
690
  }
690
- recalculate(config) {
691
- this.ci = config.ci;
692
- this.json = config.json;
693
- this.logLevel = config.logLevel;
694
- this.isVerbose = isVerbose(config.logLevel);
695
- this.isDebug = isDebug(config.logLevel);
696
- this.isSilent = isSilent(config.logLevel);
691
+ recalculate() {
692
+ this.isVerbose = isVerbose(this.logLevel);
693
+ this.isDebug = isDebug(this.logLevel);
694
+ this.isSilent = isSilent(this.logLevel);
697
695
  }
698
696
  };
699
697
  __name(ConfigService, "ConfigService");
package/dist/index.d.ts CHANGED
@@ -319,8 +319,7 @@ declare type DeepPartial<T> = {
319
319
  };
320
320
 
321
321
  declare class Command<Ctx extends ListrContext = ListrContext, Flags extends Record<PropertyKey, any> = InferFlags<typeof Command>, Args extends Record<PropertyKey, any> = InferArgs<typeof Command>, Store extends Record<PropertyKey, any> = Record<PropertyKey, any>> extends Command$1 {
322
- static get globalFlags(): FlagInput;
323
- static set globalFlags(flags: FlagInput);
322
+ context: string;
324
323
  logger: Logger;
325
324
  tasks: Manager<Ctx, 'default' | 'verbose' | 'silent' | 'simple'>;
326
325
  validator: ValidatorService;
package/dist/index.js CHANGED
@@ -461,16 +461,14 @@ var ConfigService = class {
461
461
  this.oclif = oclif;
462
462
  this.command = command;
463
463
  if (ConfigService.instance) {
464
- if (Object.entries(config).some(([key, value]) => value !== ConfigService.instance[key])) {
465
- ConfigService.instance.recalculate(config);
466
- }
467
464
  return ConfigService.instance;
468
465
  }
469
466
  this.root = this.oclif.root;
470
467
  this.defaults = (0, import_path2.join)(this.oclif.root, "config" /* CONFIG_SERVICE_DEFAULTS_DIR */);
471
468
  this.logger = new Logger(this.constructor.name, { level: config.logLevel });
469
+ Object.assign(this, config);
470
+ this.recalculate();
472
471
  this.parser = new ParserService();
473
- this.recalculate(config);
474
472
  ConfigService.instance = this;
475
473
  this.logger.trace("Created a new instance.");
476
474
  }
@@ -583,13 +581,10 @@ var ConfigService = class {
583
581
  async write(path, data) {
584
582
  return this.parser.write(path, data);
585
583
  }
586
- recalculate(config) {
587
- this.ci = config.ci;
588
- this.json = config.json;
589
- this.logLevel = config.logLevel;
590
- this.isVerbose = isVerbose(config.logLevel);
591
- this.isDebug = isDebug(config.logLevel);
592
- this.isSilent = isSilent(config.logLevel);
584
+ recalculate() {
585
+ this.isVerbose = isVerbose(this.logLevel);
586
+ this.isDebug = isDebug(this.logLevel);
587
+ this.isSilent = isSilent(this.logLevel);
593
588
  }
594
589
  };
595
590
  __name(ConfigService, "ConfigService");
@@ -843,19 +838,20 @@ var Logger = class {
843
838
  constructor(context, options) {
844
839
  this.context = context;
845
840
  this.options = options;
846
- const parsed = (process.env.LOG_LEVEL ?? options?.level ?? "INFO" /* INFO */).toUpperCase();
847
- const level = Object.values(LogLevels).includes(parsed) ? parsed : "INFO" /* INFO */;
848
- this.options = {
849
- useIcons: true,
850
- ...options,
851
- level
852
- };
853
841
  if (Logger.instance) {
854
842
  this.logger = Logger.instance;
855
843
  } else if (context === ConfigService.name) {
844
+ const level = Object.values(LogLevels).includes(options?.level) ? options.level : "INFO" /* INFO */;
845
+ this.options = {
846
+ useIcons: true,
847
+ ...options,
848
+ level
849
+ };
856
850
  this.logger = this.initiateLogger();
857
851
  this.trace("Logger singleton initiated from context: %s", context);
858
852
  Logger.instance = this.logger;
853
+ } else {
854
+ throw new Error("Logger can only be initiated inside the config service context!");
859
855
  }
860
856
  }
861
857
  log(level, data, ...args) {
@@ -1099,18 +1095,20 @@ var CLI_FLAGS = {
1099
1095
  default: "INFO" /* INFO */,
1100
1096
  env: "LOG_LEVEL",
1101
1097
  description: "Set the log level of the application.",
1102
- options: [...Object.values(LogLevels), ...Object.values(LogLevels).map((level) => level.toLowerCase())],
1098
+ options: [...Object.values(LogLevels).map((level) => level.toLowerCase())],
1103
1099
  helpGroup: "CLI" /* CLI */,
1104
1100
  parse: async (input) => input?.toUpperCase()
1105
1101
  }),
1106
1102
  ci: import_core.Flags.boolean({
1107
1103
  default: false,
1104
+ hidden: true,
1108
1105
  env: "CI",
1109
1106
  description: "Instruct whether this is running the CI/CD configuration.",
1110
1107
  helpGroup: "CLI" /* CLI */
1111
1108
  }),
1112
1109
  json: import_core.Flags.boolean({
1113
1110
  default: false,
1111
+ hidden: true,
1114
1112
  env: "JSON",
1115
1113
  description: "Put the CLI to respond in JSON.",
1116
1114
  helpGroup: "CLI" /* CLI */
@@ -1124,13 +1122,6 @@ var Command = class extends import_core3.Command {
1124
1122
  this.flags = {};
1125
1123
  this.args = {};
1126
1124
  }
1127
- static get globalFlags() {
1128
- return { ...CLI_FLAGS, ...this._globalFlags };
1129
- }
1130
- static set globalFlags(flags) {
1131
- this._globalFlags = Object.assign({}, this.globalFlags, flags);
1132
- this.flags = {};
1133
- }
1134
1125
  shouldRunBefore() {
1135
1126
  }
1136
1127
  shouldRunAfter(_ctx) {
@@ -1175,6 +1166,7 @@ var Command = class extends import_core3.Command {
1175
1166
  this.logger.trace("Updated context with assign: %o", this.tasks.options.ctx, { status: "ctx" });
1176
1167
  }
1177
1168
  async init() {
1169
+ this.constructor.flags = Object.assign({}, CLI_FLAGS, this.constructor.flags);
1178
1170
  await super.init();
1179
1171
  let err;
1180
1172
  try {
@@ -1189,7 +1181,7 @@ var Command = class extends import_core3.Command {
1189
1181
  ci: this.flags.ci,
1190
1182
  json: this.flags.json
1191
1183
  });
1192
- const context = this.cs.command.id ? this.cs.command.id : this.cs.command.name;
1184
+ this.context = this.cs.command.id ? this.cs.command.id : this.cs.command.name;
1193
1185
  this.logger = new Logger(null, { level: this.cs.logLevel });
1194
1186
  this.store = new StoreService();
1195
1187
  this.greet();
@@ -1206,8 +1198,7 @@ var Command = class extends import_core3.Command {
1206
1198
  nonTTYRendererOptions: {
1207
1199
  logEmptyTitle: false,
1208
1200
  logTitleChange: false,
1209
- logger: ListrLogger,
1210
- options: [context]
1201
+ logger: ListrLogger
1211
1202
  },
1212
1203
  ctx: {}
1213
1204
  });
@@ -1239,6 +1230,11 @@ var Command = class extends import_core3.Command {
1239
1230
  return { ctx };
1240
1231
  }
1241
1232
  catch(e, exit) {
1233
+ if (!this.logger) {
1234
+ console.error("Logger has not been initiated yet!");
1235
+ console.error(e.message);
1236
+ console.debug(e.stack);
1237
+ }
1242
1238
  this.logger.fatal(e.message);
1243
1239
  this.logger.debug(e.stack, { context: "crash" });
1244
1240
  if (exit > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cenk1cenk2/oclif-common",
3
- "version": "3.9.5",
3
+ "version": "3.9.6",
4
4
  "description": "Oclif common package for oclif2 projects.",
5
5
  "repository": "https://gitlab.kilic.dev/libraries/oclif-tools",
6
6
  "author": {
@@ -69,7 +69,7 @@
69
69
  "@oclif/core": "^1.20.4",
70
70
  "@types/fs-extra": "^9.0.13",
71
71
  "@types/through": "^0.0.30",
72
- "@types/update-notifier": "^5",
72
+ "@types/update-notifier": "^6",
73
73
  "class-transformer": "^0.5.1",
74
74
  "class-validator": "^0.13.2",
75
75
  "enquirer": "^2.3.6",