@cenk1cenk2/oclif-common 3.9.4 → 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,18 +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
- Object.assign(ConfigService.instance, config);
407
- ConfigService.instance.recalculate();
408
- }
409
407
  return ConfigService.instance;
410
408
  }
411
409
  this.root = this.oclif.root;
412
410
  this.defaults = (0, import_path2.join)(this.oclif.root, "config" /* CONFIG_SERVICE_DEFAULTS_DIR */);
413
411
  this.logger = new Logger(this.constructor.name, { level: config.logLevel });
414
- this.parser = new ParserService();
415
412
  Object.assign(this, config);
416
413
  this.recalculate();
414
+ this.parser = new ParserService();
417
415
  ConfigService.instance = this;
418
416
  this.logger.trace("Created a new instance.");
419
417
  }
@@ -569,19 +567,20 @@ var Logger = class {
569
567
  constructor(context, options) {
570
568
  this.context = context;
571
569
  this.options = options;
572
- const parsed = (process.env.LOG_LEVEL ?? options?.level ?? "INFO" /* INFO */).toUpperCase();
573
- const level = Object.values(LogLevels).includes(parsed) ? parsed : "INFO" /* INFO */;
574
- this.options = {
575
- useIcons: true,
576
- ...options,
577
- level
578
- };
579
570
  if (Logger.instance) {
580
571
  this.logger = Logger.instance;
581
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
+ };
582
579
  this.logger = this.initiateLogger();
583
580
  this.trace("Logger singleton initiated from context: %s", context);
584
581
  Logger.instance = this.logger;
582
+ } else {
583
+ throw new Error("Logger can only be initiated inside the config service context!");
585
584
  }
586
585
  }
587
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,18 +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
- Object.assign(ConfigService.instance, config);
403
- ConfigService.instance.recalculate();
404
- }
405
403
  return ConfigService.instance;
406
404
  }
407
405
  this.root = this.oclif.root;
408
406
  this.defaults = (0, import_path2.join)(this.oclif.root, "config" /* CONFIG_SERVICE_DEFAULTS_DIR */);
409
407
  this.logger = new Logger(this.constructor.name, { level: config.logLevel });
410
- this.parser = new ParserService();
411
408
  Object.assign(this, config);
412
409
  this.recalculate();
410
+ this.parser = new ParserService();
413
411
  ConfigService.instance = this;
414
412
  this.logger.trace("Created a new instance.");
415
413
  }
@@ -542,19 +540,20 @@ var Logger = class {
542
540
  constructor(context, options) {
543
541
  this.context = context;
544
542
  this.options = options;
545
- const parsed = (process.env.LOG_LEVEL ?? options?.level ?? "INFO" /* INFO */).toUpperCase();
546
- const level = Object.values(LogLevels).includes(parsed) ? parsed : "INFO" /* INFO */;
547
- this.options = {
548
- useIcons: true,
549
- ...options,
550
- level
551
- };
552
543
  if (Logger.instance) {
553
544
  this.logger = Logger.instance;
554
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
+ };
555
552
  this.logger = this.initiateLogger();
556
553
  this.trace("Logger singleton initiated from context: %s", context);
557
554
  Logger.instance = this.logger;
555
+ } else {
556
+ throw new Error("Logger can only be initiated inside the config service context!");
558
557
  }
559
558
  }
560
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,18 +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
- Object.assign(ConfigService.instance, config);
570
- ConfigService.instance.recalculate();
571
- }
572
571
  return ConfigService.instance;
573
572
  }
574
573
  this.root = this.oclif.root;
575
574
  this.defaults = (0, import_path2.join)(this.oclif.root, "config" /* CONFIG_SERVICE_DEFAULTS_DIR */);
576
575
  this.logger = new Logger(this.constructor.name, { level: config.logLevel });
577
- this.parser = new ParserService();
578
576
  Object.assign(this, config);
579
577
  this.recalculate();
578
+ this.parser = new ParserService();
580
579
  ConfigService.instance = this;
581
580
  this.logger.trace("Created a new instance.");
582
581
  }
package/dist/index.d.ts CHANGED
@@ -114,16 +114,11 @@ interface PipeProcessToLoggerOptions {
114
114
  */
115
115
  declare function pipeProcessToLogger(logger: Logger, instance: ExecaChildProcess, options?: PipeProcessToLoggerOptions): ExecaChildProcess;
116
116
 
117
- interface GlobalConfigInit {
117
+ interface GlobalConfig {
118
118
  logLevel: LogLevels;
119
119
  ci: boolean;
120
120
  json: boolean;
121
121
  }
122
- interface GlobalConfig extends GlobalConfigInit {
123
- isVerbose: boolean;
124
- isDebug: boolean;
125
- isSilent: boolean;
126
- }
127
122
  interface ConfigIterator {
128
123
  key: (string | number)[];
129
124
  env: string;
@@ -229,7 +224,7 @@ declare class ConfigService implements GlobalConfig {
229
224
  ci: boolean;
230
225
  json: boolean;
231
226
  private logger;
232
- constructor(oclif: Command['config'], command: Command['ctor'], config: Omit<GlobalConfig, 'isVerbose' | 'isDebug' | 'isSilent'>);
227
+ constructor(oclif: Command['config'], command: Command['ctor'], config: GlobalConfig);
233
228
  read<T extends LockableData = LockableData>(path: string): Promise<T>;
234
229
  extend<T extends LockableData = LockableData>(paths: (string | Partial<T>)[], strategy?: MergeStrategy): Promise<T>;
235
230
  merge<T extends LockableData = LockableData>(configs: Partial<T>[], strategy?: MergeStrategy): T;
@@ -324,8 +319,7 @@ declare type DeepPartial<T> = {
324
319
  };
325
320
 
326
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 {
327
- static get globalFlags(): FlagInput;
328
- static set globalFlags(flags: FlagInput);
322
+ context: string;
329
323
  logger: Logger;
330
324
  tasks: Manager<Ctx, 'default' | 'verbose' | 'silent' | 'simple'>;
331
325
  validator: ValidatorService;
@@ -409,4 +403,4 @@ declare enum HelpGroups {
409
403
  CLI = "CLI"
410
404
  }
411
405
 
412
- export { CLI_FLAGS, ClassType, Command, CommonLockerData, ConfigCommand, ConfigCommandChoices, ConfigCommandSetup, ConfigIterator, ConfigService, DeepPartial, EnvironmentVariableParser, FileConstants, FileSystemService, GenericParser, GlobalConfig, GlobalConfigInit, HelpGroups, InferArgs, InferFlags, JsonParser, ListrLogger, LockData, LockableData, LockerService, LogFieldStatus, LogLevels, Logger, LoggerFormat, LoggerOptions, MergeStrategy, ParserService, PipeProcessToLoggerOptions, SetCtxAssignOptions, SetCtxDefaultsOptions, UnlockData, ValidatorService, ValidatorServiceOptions, Winston, YamlParser, color, isDebug, isSilent, isVerbose, merge, pipeProcessThroughListr, pipeProcessToLogger, setCtxAssign, setCtxDefaults, setup, uniqueFilter };
406
+ export { CLI_FLAGS, ClassType, Command, CommonLockerData, ConfigCommand, ConfigCommandChoices, ConfigCommandSetup, ConfigIterator, ConfigService, DeepPartial, EnvironmentVariableParser, FileConstants, FileSystemService, GenericParser, GlobalConfig, HelpGroups, InferArgs, InferFlags, JsonParser, ListrLogger, LockData, LockableData, LockerService, LogFieldStatus, LogLevels, Logger, LoggerFormat, LoggerOptions, MergeStrategy, ParserService, PipeProcessToLoggerOptions, SetCtxAssignOptions, SetCtxDefaultsOptions, UnlockData, ValidatorService, ValidatorServiceOptions, Winston, YamlParser, color, isDebug, isSilent, isVerbose, merge, pipeProcessThroughListr, pipeProcessToLogger, setCtxAssign, setCtxDefaults, setup, uniqueFilter };
package/dist/index.js CHANGED
@@ -461,18 +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
- Object.assign(ConfigService.instance, config);
466
- ConfigService.instance.recalculate();
467
- }
468
464
  return ConfigService.instance;
469
465
  }
470
466
  this.root = this.oclif.root;
471
467
  this.defaults = (0, import_path2.join)(this.oclif.root, "config" /* CONFIG_SERVICE_DEFAULTS_DIR */);
472
468
  this.logger = new Logger(this.constructor.name, { level: config.logLevel });
473
- this.parser = new ParserService();
474
469
  Object.assign(this, config);
475
470
  this.recalculate();
471
+ this.parser = new ParserService();
476
472
  ConfigService.instance = this;
477
473
  this.logger.trace("Created a new instance.");
478
474
  }
@@ -842,19 +838,20 @@ var Logger = class {
842
838
  constructor(context, options) {
843
839
  this.context = context;
844
840
  this.options = options;
845
- const parsed = (process.env.LOG_LEVEL ?? options?.level ?? "INFO" /* INFO */).toUpperCase();
846
- const level = Object.values(LogLevels).includes(parsed) ? parsed : "INFO" /* INFO */;
847
- this.options = {
848
- useIcons: true,
849
- ...options,
850
- level
851
- };
852
841
  if (Logger.instance) {
853
842
  this.logger = Logger.instance;
854
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
+ };
855
850
  this.logger = this.initiateLogger();
856
851
  this.trace("Logger singleton initiated from context: %s", context);
857
852
  Logger.instance = this.logger;
853
+ } else {
854
+ throw new Error("Logger can only be initiated inside the config service context!");
858
855
  }
859
856
  }
860
857
  log(level, data, ...args) {
@@ -1098,18 +1095,20 @@ var CLI_FLAGS = {
1098
1095
  default: "INFO" /* INFO */,
1099
1096
  env: "LOG_LEVEL",
1100
1097
  description: "Set the log level of the application.",
1101
- options: [...Object.values(LogLevels), ...Object.values(LogLevels).map((level) => level.toLowerCase())],
1098
+ options: [...Object.values(LogLevels).map((level) => level.toLowerCase())],
1102
1099
  helpGroup: "CLI" /* CLI */,
1103
1100
  parse: async (input) => input?.toUpperCase()
1104
1101
  }),
1105
1102
  ci: import_core.Flags.boolean({
1106
1103
  default: false,
1104
+ hidden: true,
1107
1105
  env: "CI",
1108
1106
  description: "Instruct whether this is running the CI/CD configuration.",
1109
1107
  helpGroup: "CLI" /* CLI */
1110
1108
  }),
1111
1109
  json: import_core.Flags.boolean({
1112
1110
  default: false,
1111
+ hidden: true,
1113
1112
  env: "JSON",
1114
1113
  description: "Put the CLI to respond in JSON.",
1115
1114
  helpGroup: "CLI" /* CLI */
@@ -1123,13 +1122,6 @@ var Command = class extends import_core3.Command {
1123
1122
  this.flags = {};
1124
1123
  this.args = {};
1125
1124
  }
1126
- static get globalFlags() {
1127
- return { ...CLI_FLAGS, ...this._globalFlags };
1128
- }
1129
- static set globalFlags(flags) {
1130
- this._globalFlags = Object.assign({}, this.globalFlags, flags);
1131
- this.flags = {};
1132
- }
1133
1125
  shouldRunBefore() {
1134
1126
  }
1135
1127
  shouldRunAfter(_ctx) {
@@ -1174,6 +1166,7 @@ var Command = class extends import_core3.Command {
1174
1166
  this.logger.trace("Updated context with assign: %o", this.tasks.options.ctx, { status: "ctx" });
1175
1167
  }
1176
1168
  async init() {
1169
+ this.constructor.flags = Object.assign({}, CLI_FLAGS, this.constructor.flags);
1177
1170
  await super.init();
1178
1171
  let err;
1179
1172
  try {
@@ -1188,7 +1181,7 @@ var Command = class extends import_core3.Command {
1188
1181
  ci: this.flags.ci,
1189
1182
  json: this.flags.json
1190
1183
  });
1191
- 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;
1192
1185
  this.logger = new Logger(null, { level: this.cs.logLevel });
1193
1186
  this.store = new StoreService();
1194
1187
  this.greet();
@@ -1205,8 +1198,7 @@ var Command = class extends import_core3.Command {
1205
1198
  nonTTYRendererOptions: {
1206
1199
  logEmptyTitle: false,
1207
1200
  logTitleChange: false,
1208
- logger: ListrLogger,
1209
- options: [context]
1201
+ logger: ListrLogger
1210
1202
  },
1211
1203
  ctx: {}
1212
1204
  });
@@ -1238,6 +1230,11 @@ var Command = class extends import_core3.Command {
1238
1230
  return { ctx };
1239
1231
  }
1240
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
+ }
1241
1238
  this.logger.fatal(e.message);
1242
1239
  this.logger.debug(e.stack, { context: "crash" });
1243
1240
  if (exit > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cenk1cenk2/oclif-common",
3
- "version": "3.9.4",
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",