@cenk1cenk2/oclif-common 3.0.0-beta.2 → 3.0.0-beta.5

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.
@@ -235,168 +235,32 @@ var updateNotifierHook = /* @__PURE__ */ __name(async (opts) => {
235
235
  // src/lib/config/config.service.ts
236
236
  var import_path2 = require("path");
237
237
 
238
- // src/lib/fs/filesystem.service.ts
239
- var import_fs_extra = __toESM(require("fs-extra"));
240
- var import_path = require("path");
241
- var FileSystemService = class {
238
+ // src/lib/parser/json-parser.service.ts
239
+ var _JsonParser = class {
242
240
  constructor() {
243
241
  this.logger = new Logger(this.constructor.name);
244
- if (FileSystemService.instance) {
245
- return FileSystemService.instance;
242
+ if (_JsonParser.instance) {
243
+ return _JsonParser.instance;
246
244
  } else {
247
- FileSystemService.instance = this;
245
+ _JsonParser.instance = this;
248
246
  this.logger.trace("Created a new instance.");
249
247
  }
250
248
  }
251
- exists(path) {
252
- return import_fs_extra.default.existsSync(path);
253
- }
254
- stats(path) {
255
- return import_fs_extra.default.statSync(path, { throwIfNoEntry: true });
256
- }
257
- dirname(path) {
258
- return (0, import_path.dirname)(path);
259
- }
260
- extname(path) {
261
- return (0, import_path.extname)(path);
262
- }
263
- async read(file) {
264
- try {
265
- const raw = await import_fs_extra.default.readFile(file, "utf-8");
266
- return raw;
267
- } catch (e) {
268
- throw new Error(`Error while reading file from "${file}": ${e.message}`);
269
- }
270
- }
271
- readSync(file) {
272
- try {
273
- const raw = import_fs_extra.default.readFileSync(file, "utf-8");
274
- return raw;
275
- } catch (e) {
276
- throw new Error(`Error while reading file from "${file}": ${e.message}`);
277
- }
278
- }
279
- async write(file, data, options = {}) {
280
- try {
281
- await import_fs_extra.default.writeFile(file, data, { encoding: "utf-8", ...options });
282
- } catch (e) {
283
- throw new Error(`Error while writing file to "${file}": ${e.message}`);
284
- }
285
- }
286
- writeSync(file, data, options = {}) {
287
- try {
288
- import_fs_extra.default.writeFileSync(file, data, { encoding: "utf-8", ...options });
289
- } catch (e) {
290
- throw new Error(`Error while writing file to "${file}": ${e.message}`);
291
- }
292
- }
293
- async append(file, data, options) {
294
- try {
295
- await import_fs_extra.default.appendFile(file, data, options);
296
- } catch (e) {
297
- throw new Error(`Error while appending to file "${file}": ${e.message}`);
298
- }
299
- }
300
- appendSync(file, data) {
301
- try {
302
- import_fs_extra.default.appendFileSync(file, data);
303
- } catch (e) {
304
- throw new Error(`Error while appending to file "${file}": ${e.message}`);
305
- }
306
- }
307
- async remove(file, options) {
308
- try {
309
- await import_fs_extra.default.rm(file, options);
310
- } catch (e) {
311
- throw new Error(`Error while deleting the file "${file}": ${e.message}`);
312
- }
313
- }
314
- removeSync(file, options) {
315
- try {
316
- import_fs_extra.default.rmSync(file, options);
317
- } catch (e) {
318
- throw new Error(`Error while deleting the file "${file}": ${e.message}`);
319
- }
320
- }
321
- async emptyDir(directory) {
322
- try {
323
- await import_fs_extra.default.emptyDir(directory);
324
- } catch (e) {
325
- throw new Error(`Error while deleting the directory "${directory}": ${e.message}`);
326
- }
327
- }
328
- emptyDirSync(directory) {
329
- try {
330
- import_fs_extra.default.emptyDirSync(directory);
331
- } catch (e) {
332
- throw new Error(`Error while deleting the directory "${directory}": ${e.message}`);
333
- }
334
- }
335
- async mkdir(directory) {
336
- try {
337
- await import_fs_extra.default.mkdirp(directory);
338
- } catch (e) {
339
- throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
340
- }
341
- }
342
- mkdirSync(directory) {
249
+ parse(data) {
343
250
  try {
344
- import_fs_extra.default.mkdirSync(directory);
251
+ return JSON.parse(data.toString());
345
252
  } catch (e) {
346
- throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
347
- }
348
- }
349
- };
350
- __name(FileSystemService, "FileSystemService");
351
-
352
- // src/lib/parser/parser.service.ts
353
- var _ParserService = class {
354
- constructor(parsers = []) {
355
- this.parsers = parsers;
356
- this.logger = new Logger(this.constructor.name);
357
- this.fs = new FileSystemService();
358
- if (_ParserService.instance) {
359
- return _ParserService.instance;
360
- } else {
361
- _ParserService.instance = this;
362
- this.logger.trace("Created a new instance.");
363
- }
364
- }
365
- getParser(file) {
366
- const ext = this.fs.extname(file);
367
- const Parser = this.parsers.find((parser) => parser.extensions.includes(ext.replace(/^\./, "")));
368
- if (!Parser) {
369
- throw new Error(`Parser for the extension is not configured: ${ext}`);
253
+ this.logger.fatal("Error during parsing JSON file: %s", e.message);
254
+ throw e;
370
255
  }
371
- return new Parser();
372
- }
373
- addParsers(...parsers) {
374
- this.parsers.push(...parsers);
375
- }
376
- async read(file) {
377
- const Parser = this.getParser(file);
378
- return this.parse(Parser, await this.fs.read(file));
379
- }
380
- async write(file, data) {
381
- const Parser = this.getParser(file);
382
- return this.fs.write(file, await this.stringify(Parser, data));
383
256
  }
384
- parse(parser, data) {
385
- return parser.parse(data);
386
- }
387
- stringify(parser, data) {
388
- return parser.stringify(data);
257
+ stringify(data) {
258
+ return JSON.stringify(data, null, 2);
389
259
  }
390
260
  };
391
- var ParserService = _ParserService;
392
- __name(ParserService, "ParserService");
393
- ParserService.extensions = [];
394
-
395
- // src/utils/merge.ts
396
- var import_deepmerge = __toESM(require("deepmerge"));
397
-
398
- // src/lib/locker/locker.service.ts
399
- var import_object_path_immutable = __toESM(require("object-path-immutable"));
261
+ var JsonParser = _JsonParser;
262
+ __name(JsonParser, "JsonParser");
263
+ JsonParser.extensions = ["json"];
400
264
 
401
265
  // src/lib/parser/yaml-parser.service.ts
402
266
  var import_yaml = require("yaml");
@@ -426,32 +290,15 @@ var YamlParser = _YamlParser;
426
290
  __name(YamlParser, "YamlParser");
427
291
  YamlParser.extensions = ["yaml", "yml"];
428
292
 
429
- // src/lib/parser/json-parser.service.ts
430
- var _JsonParser = class {
431
- constructor() {
432
- this.logger = new Logger(this.constructor.name);
433
- if (_JsonParser.instance) {
434
- return _JsonParser.instance;
435
- } else {
436
- _JsonParser.instance = this;
437
- this.logger.trace("Created a new instance.");
438
- }
439
- }
440
- parse(data) {
441
- try {
442
- return JSON.parse(data.toString());
443
- } catch (e) {
444
- this.logger.fatal("Error during parsing JSON file: %s", e.message);
445
- throw e;
446
- }
447
- }
448
- stringify(data) {
449
- return JSON.stringify(data, null, 2);
450
- }
451
- };
452
- var JsonParser = _JsonParser;
453
- __name(JsonParser, "JsonParser");
454
- JsonParser.extensions = ["json"];
293
+ // src/lib/fs/filesystem.service.ts
294
+ var import_fs_extra = __toESM(require("fs-extra"));
295
+ var import_path = require("path");
296
+
297
+ // src/utils/merge.ts
298
+ var import_deepmerge = __toESM(require("deepmerge"));
299
+
300
+ // src/lib/locker/locker.service.ts
301
+ var import_object_path_immutable = __toESM(require("object-path-immutable"));
455
302
 
456
303
  // src/lib/store/store.service.ts
457
304
  var StoreService = class {
@@ -33,10 +33,6 @@ module.exports = __toCommonJS(store_hook_exports);
33
33
  // src/lib/config/config.service.ts
34
34
  var import_path2 = require("path");
35
35
 
36
- // src/lib/fs/filesystem.service.ts
37
- var import_fs_extra = __toESM(require("fs-extra"));
38
- var import_path = require("path");
39
-
40
36
  // src/utils/logger/pipe/pipe-process-to-listr.ts
41
37
  var import_through = __toESM(require("through"));
42
38
 
@@ -218,166 +214,32 @@ var Logger = class {
218
214
  };
219
215
  __name(Logger, "Logger");
220
216
 
221
- // src/lib/fs/filesystem.service.ts
222
- var FileSystemService = class {
217
+ // src/lib/parser/json-parser.service.ts
218
+ var _JsonParser = class {
223
219
  constructor() {
224
220
  this.logger = new Logger(this.constructor.name);
225
- if (FileSystemService.instance) {
226
- return FileSystemService.instance;
221
+ if (_JsonParser.instance) {
222
+ return _JsonParser.instance;
227
223
  } else {
228
- FileSystemService.instance = this;
224
+ _JsonParser.instance = this;
229
225
  this.logger.trace("Created a new instance.");
230
226
  }
231
227
  }
232
- exists(path) {
233
- return import_fs_extra.default.existsSync(path);
234
- }
235
- stats(path) {
236
- return import_fs_extra.default.statSync(path, { throwIfNoEntry: true });
237
- }
238
- dirname(path) {
239
- return (0, import_path.dirname)(path);
240
- }
241
- extname(path) {
242
- return (0, import_path.extname)(path);
243
- }
244
- async read(file) {
245
- try {
246
- const raw = await import_fs_extra.default.readFile(file, "utf-8");
247
- return raw;
248
- } catch (e) {
249
- throw new Error(`Error while reading file from "${file}": ${e.message}`);
250
- }
251
- }
252
- readSync(file) {
253
- try {
254
- const raw = import_fs_extra.default.readFileSync(file, "utf-8");
255
- return raw;
256
- } catch (e) {
257
- throw new Error(`Error while reading file from "${file}": ${e.message}`);
258
- }
259
- }
260
- async write(file, data, options = {}) {
261
- try {
262
- await import_fs_extra.default.writeFile(file, data, { encoding: "utf-8", ...options });
263
- } catch (e) {
264
- throw new Error(`Error while writing file to "${file}": ${e.message}`);
265
- }
266
- }
267
- writeSync(file, data, options = {}) {
268
- try {
269
- import_fs_extra.default.writeFileSync(file, data, { encoding: "utf-8", ...options });
270
- } catch (e) {
271
- throw new Error(`Error while writing file to "${file}": ${e.message}`);
272
- }
273
- }
274
- async append(file, data, options) {
275
- try {
276
- await import_fs_extra.default.appendFile(file, data, options);
277
- } catch (e) {
278
- throw new Error(`Error while appending to file "${file}": ${e.message}`);
279
- }
280
- }
281
- appendSync(file, data) {
282
- try {
283
- import_fs_extra.default.appendFileSync(file, data);
284
- } catch (e) {
285
- throw new Error(`Error while appending to file "${file}": ${e.message}`);
286
- }
287
- }
288
- async remove(file, options) {
289
- try {
290
- await import_fs_extra.default.rm(file, options);
291
- } catch (e) {
292
- throw new Error(`Error while deleting the file "${file}": ${e.message}`);
293
- }
294
- }
295
- removeSync(file, options) {
296
- try {
297
- import_fs_extra.default.rmSync(file, options);
298
- } catch (e) {
299
- throw new Error(`Error while deleting the file "${file}": ${e.message}`);
300
- }
301
- }
302
- async emptyDir(directory) {
303
- try {
304
- await import_fs_extra.default.emptyDir(directory);
305
- } catch (e) {
306
- throw new Error(`Error while deleting the directory "${directory}": ${e.message}`);
307
- }
308
- }
309
- emptyDirSync(directory) {
310
- try {
311
- import_fs_extra.default.emptyDirSync(directory);
312
- } catch (e) {
313
- throw new Error(`Error while deleting the directory "${directory}": ${e.message}`);
314
- }
315
- }
316
- async mkdir(directory) {
317
- try {
318
- await import_fs_extra.default.mkdirp(directory);
319
- } catch (e) {
320
- throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
321
- }
322
- }
323
- mkdirSync(directory) {
228
+ parse(data) {
324
229
  try {
325
- import_fs_extra.default.mkdirSync(directory);
230
+ return JSON.parse(data.toString());
326
231
  } catch (e) {
327
- throw new Error(`Error while creating the directory "${directory}": ${e.message}`);
328
- }
329
- }
330
- };
331
- __name(FileSystemService, "FileSystemService");
332
-
333
- // src/lib/parser/parser.service.ts
334
- var _ParserService = class {
335
- constructor(parsers = []) {
336
- this.parsers = parsers;
337
- this.logger = new Logger(this.constructor.name);
338
- this.fs = new FileSystemService();
339
- if (_ParserService.instance) {
340
- return _ParserService.instance;
341
- } else {
342
- _ParserService.instance = this;
343
- this.logger.trace("Created a new instance.");
344
- }
345
- }
346
- getParser(file) {
347
- const ext = this.fs.extname(file);
348
- const Parser = this.parsers.find((parser) => parser.extensions.includes(ext.replace(/^\./, "")));
349
- if (!Parser) {
350
- throw new Error(`Parser for the extension is not configured: ${ext}`);
232
+ this.logger.fatal("Error during parsing JSON file: %s", e.message);
233
+ throw e;
351
234
  }
352
- return new Parser();
353
- }
354
- addParsers(...parsers) {
355
- this.parsers.push(...parsers);
356
- }
357
- async read(file) {
358
- const Parser = this.getParser(file);
359
- return this.parse(Parser, await this.fs.read(file));
360
235
  }
361
- async write(file, data) {
362
- const Parser = this.getParser(file);
363
- return this.fs.write(file, await this.stringify(Parser, data));
364
- }
365
- parse(parser, data) {
366
- return parser.parse(data);
367
- }
368
- stringify(parser, data) {
369
- return parser.stringify(data);
236
+ stringify(data) {
237
+ return JSON.stringify(data, null, 2);
370
238
  }
371
239
  };
372
- var ParserService = _ParserService;
373
- __name(ParserService, "ParserService");
374
- ParserService.extensions = [];
375
-
376
- // src/utils/merge.ts
377
- var import_deepmerge = __toESM(require("deepmerge"));
378
-
379
- // src/lib/locker/locker.service.ts
380
- var import_object_path_immutable = __toESM(require("object-path-immutable"));
240
+ var JsonParser = _JsonParser;
241
+ __name(JsonParser, "JsonParser");
242
+ JsonParser.extensions = ["json"];
381
243
 
382
244
  // src/lib/parser/yaml-parser.service.ts
383
245
  var import_yaml = require("yaml");
@@ -407,32 +269,15 @@ var YamlParser = _YamlParser;
407
269
  __name(YamlParser, "YamlParser");
408
270
  YamlParser.extensions = ["yaml", "yml"];
409
271
 
410
- // src/lib/parser/json-parser.service.ts
411
- var _JsonParser = class {
412
- constructor() {
413
- this.logger = new Logger(this.constructor.name);
414
- if (_JsonParser.instance) {
415
- return _JsonParser.instance;
416
- } else {
417
- _JsonParser.instance = this;
418
- this.logger.trace("Created a new instance.");
419
- }
420
- }
421
- parse(data) {
422
- try {
423
- return JSON.parse(data.toString());
424
- } catch (e) {
425
- this.logger.fatal("Error during parsing JSON file: %s", e.message);
426
- throw e;
427
- }
428
- }
429
- stringify(data) {
430
- return JSON.stringify(data, null, 2);
431
- }
432
- };
433
- var JsonParser = _JsonParser;
434
- __name(JsonParser, "JsonParser");
435
- JsonParser.extensions = ["json"];
272
+ // src/lib/fs/filesystem.service.ts
273
+ var import_fs_extra = __toESM(require("fs-extra"));
274
+ var import_path = require("path");
275
+
276
+ // src/utils/merge.ts
277
+ var import_deepmerge = __toESM(require("deepmerge"));
278
+
279
+ // src/lib/locker/locker.service.ts
280
+ var import_object_path_immutable = __toESM(require("object-path-immutable"));
436
281
 
437
282
  // src/lib/store/store.service.ts
438
283
  var StoreService = class {
package/dist/index.d.ts CHANGED
@@ -122,6 +122,14 @@ declare enum MergeStrategy {
122
122
  * Does not mutate the object */
123
123
  declare function merge<T extends Record<PropertyKey, any> | any[]>(strategy: MergeStrategy, target: T, ...source: Partial<T>[]): T;
124
124
 
125
+ declare type SetCtxDefaultsOptions<T extends ListrContext = ListrContext> = Partial<T>;
126
+ interface SetCtxAssignOptions<K = Record<PropertyKey, any>> {
127
+ from: K;
128
+ keys: (keyof K)[];
129
+ }
130
+ declare function setCtxDefaults<T extends ListrContext = ListrContext>(ctx: T, ...defaults: SetCtxDefaultsOptions<T>[]): void;
131
+ declare function setCtxAssign<T extends ListrContext = ListrContext, K = Record<PropertyKey, any>>(ctx: T, ...assigns: SetCtxAssignOptions<K>[]): void;
132
+
125
133
  interface CommonLockerData {
126
134
  path: string | string[];
127
135
  enabled?: boolean;
@@ -165,13 +173,13 @@ declare class LockerService<LockFile extends LockableData = LockableData> {
165
173
  }
166
174
 
167
175
  declare class ParserService {
168
- parsers: ClassType<GenericParser>[];
169
- static extensions: string[];
170
176
  static instance: ParserService;
177
+ parsers: ClassType<GenericParser>[];
171
178
  private readonly logger;
172
179
  private readonly fs;
173
180
  constructor(parsers?: ClassType<GenericParser>[]);
174
181
  getParser(file: string): GenericParser;
182
+ setParsers(...parsers: ClassType<GenericParser>[]): void;
175
183
  addParsers(...parsers: ClassType<GenericParser>[]): void;
176
184
  read<T = unknown>(file: string): Promise<T>;
177
185
  write<T = LockableData>(file: string, data: T): Promise<void>;
@@ -300,13 +308,8 @@ declare abstract class Command<Ctx extends ListrContext = ListrContext, Flags ex
300
308
  catch(e: Error): Promise<void>;
301
309
  /** Gets prompt from user. */
302
310
  prompt<T = any>(options: PromptOptions): Promise<T>;
303
- setDefaultsInCtx<T = Ctx, K = Record<string, any>>(options: {
304
- assign?: {
305
- from: K;
306
- keys: (keyof K)[];
307
- };
308
- default?: Partial<T>[];
309
- }): void;
311
+ setCtxDefaults(...defaults: SetCtxDefaultsOptions<Ctx>[]): void;
312
+ setCtxAssign<K = Record<PropertyKey, any>>(...assigns: SetCtxAssignOptions<K>[]): void;
310
313
  exit(code?: number): void;
311
314
  private greet;
312
315
  /** Every command needs to implement run for running the command itself. */
@@ -359,4 +362,4 @@ declare const _default: {
359
362
  };
360
363
  };
361
364
 
362
- export { ClassType, Command, CommonLockerData, ConfigCommand, ConfigCommandChoices, ConfigCommandSetup, ConfigService, FileConstants, FileSystemService, GenericParser, GlobalConfig, HelpGroups, InferArgs, InferFlags, JsonParser, LockData, LockableData, LockerService, LogFieldStatus, LogLevels, Logger, LoggerFormat, LoggerOptions, MergeStrategy, ParserService, PipeProcessToLoggerOptions, UnlockData, ValidatorService, ValidatorServiceOptions, Winston, YamlParser, color, _default as default, isDebug, isSilent, isVerbose, merge, pipeProcessThroughListr, pipeProcessToLogger, setup };
365
+ export { ClassType, Command, CommonLockerData, ConfigCommand, ConfigCommandChoices, ConfigCommandSetup, ConfigService, FileConstants, FileSystemService, GenericParser, GlobalConfig, HelpGroups, InferArgs, InferFlags, JsonParser, LockData, LockableData, LockerService, LogFieldStatus, LogLevels, Logger, LoggerFormat, LoggerOptions, MergeStrategy, ParserService, PipeProcessToLoggerOptions, SetCtxAssignOptions, SetCtxDefaultsOptions, UnlockData, ValidatorService, ValidatorServiceOptions, Winston, YamlParser, color, _default as default, isDebug, isSilent, isVerbose, merge, pipeProcessThroughListr, pipeProcessToLogger, setCtxAssign, setCtxDefaults, setup };
package/dist/index.js CHANGED
@@ -53,6 +53,8 @@ __export(src_exports, {
53
53
  notFoundHook: () => notFoundHook,
54
54
  pipeProcessThroughListr: () => pipeProcessThroughListr,
55
55
  pipeProcessToLogger: () => pipeProcessToLogger,
56
+ setCtxAssign: () => setCtxAssign,
57
+ setCtxDefaults: () => setCtxDefaults,
56
58
  setup: () => setup,
57
59
  storeHook: () => storeHook,
58
60
  updateNotifierHook: () => updateNotifierHook
@@ -81,10 +83,6 @@ var HelpGroups = /* @__PURE__ */ ((HelpGroups2) => {
81
83
  // src/lib/config/config.service.ts
82
84
  var import_path2 = require("path");
83
85
 
84
- // src/lib/fs/filesystem.service.ts
85
- var import_fs_extra = __toESM(require("fs-extra"));
86
- var import_path = require("path");
87
-
88
86
  // src/utils/logger/pipe/pipe-process-to-listr.ts
89
87
  var import_through = __toESM(require("through"));
90
88
  function pipeProcessThroughListr(task, instance) {
@@ -327,7 +325,64 @@ var Logger = class {
327
325
  };
328
326
  __name(Logger, "Logger");
329
327
 
328
+ // src/lib/parser/json-parser.service.ts
329
+ var _JsonParser = class {
330
+ constructor() {
331
+ this.logger = new Logger(this.constructor.name);
332
+ if (_JsonParser.instance) {
333
+ return _JsonParser.instance;
334
+ } else {
335
+ _JsonParser.instance = this;
336
+ this.logger.trace("Created a new instance.");
337
+ }
338
+ }
339
+ parse(data) {
340
+ try {
341
+ return JSON.parse(data.toString());
342
+ } catch (e) {
343
+ this.logger.fatal("Error during parsing JSON file: %s", e.message);
344
+ throw e;
345
+ }
346
+ }
347
+ stringify(data) {
348
+ return JSON.stringify(data, null, 2);
349
+ }
350
+ };
351
+ var JsonParser = _JsonParser;
352
+ __name(JsonParser, "JsonParser");
353
+ JsonParser.extensions = ["json"];
354
+
355
+ // src/lib/parser/yaml-parser.service.ts
356
+ var import_yaml = require("yaml");
357
+ var _YamlParser = class {
358
+ constructor() {
359
+ this.logger = new Logger(this.constructor.name);
360
+ if (_YamlParser.instance) {
361
+ return _YamlParser.instance;
362
+ } else {
363
+ _YamlParser.instance = this;
364
+ this.logger.trace("Created a new instance.");
365
+ }
366
+ }
367
+ parse(data) {
368
+ try {
369
+ return (0, import_yaml.parse)(data.toString());
370
+ } catch (e) {
371
+ this.logger.fatal("Error during parsing YAML file: %s", e.message);
372
+ throw e;
373
+ }
374
+ }
375
+ stringify(data) {
376
+ return (0, import_yaml.stringify)(data, { prettyErrors: true });
377
+ }
378
+ };
379
+ var YamlParser = _YamlParser;
380
+ __name(YamlParser, "YamlParser");
381
+ YamlParser.extensions = ["yaml", "yml"];
382
+
330
383
  // src/lib/fs/filesystem.service.ts
384
+ var import_fs_extra = __toESM(require("fs-extra"));
385
+ var import_path = require("path");
331
386
  var FileSystemService = class {
332
387
  constructor() {
333
388
  this.logger = new Logger(this.constructor.name);
@@ -440,15 +495,18 @@ var FileSystemService = class {
440
495
  __name(FileSystemService, "FileSystemService");
441
496
 
442
497
  // src/lib/parser/parser.service.ts
443
- var _ParserService = class {
444
- constructor(parsers = []) {
445
- this.parsers = parsers;
498
+ var ParserService = class {
499
+ constructor(parsers) {
500
+ this.parsers = [YamlParser, JsonParser];
446
501
  this.logger = new Logger(this.constructor.name);
447
502
  this.fs = new FileSystemService();
448
- if (_ParserService.instance) {
449
- return _ParserService.instance;
503
+ if (ParserService.instance) {
504
+ return ParserService.instance;
450
505
  } else {
451
- _ParserService.instance = this;
506
+ if (parsers) {
507
+ this.parsers = parsers;
508
+ }
509
+ ParserService.instance = this;
452
510
  this.logger.trace("Created a new instance.");
453
511
  }
454
512
  }
@@ -460,6 +518,9 @@ var _ParserService = class {
460
518
  }
461
519
  return new Parser();
462
520
  }
521
+ setParsers(...parsers) {
522
+ this.parsers = parsers;
523
+ }
463
524
  addParsers(...parsers) {
464
525
  this.parsers.push(...parsers);
465
526
  }
@@ -478,9 +539,7 @@ var _ParserService = class {
478
539
  return parser.stringify(data);
479
540
  }
480
541
  };
481
- var ParserService = _ParserService;
482
542
  __name(ParserService, "ParserService");
483
- ParserService.extensions = [];
484
543
 
485
544
  // src/utils/environment.ts
486
545
  function isVerbose(logLevel) {
@@ -514,6 +573,24 @@ function merge(strategy, target, ...source) {
514
573
  }
515
574
  __name(merge, "merge");
516
575
 
576
+ // src/utils/defaults.ts
577
+ function setCtxDefaults(ctx, ...defaults) {
578
+ defaults?.forEach((i) => {
579
+ Object.assign(ctx, i);
580
+ });
581
+ }
582
+ __name(setCtxDefaults, "setCtxDefaults");
583
+ function setCtxAssign(ctx, ...assigns) {
584
+ assigns.forEach((assign) => {
585
+ assign?.keys.forEach((i) => {
586
+ if (assign.from[i]) {
587
+ ctx[i] = assign.from[i];
588
+ }
589
+ });
590
+ });
591
+ }
592
+ __name(setCtxAssign, "setCtxAssign");
593
+
517
594
  // src/lib/config/config.service.ts
518
595
  var ConfigService = class {
519
596
  constructor(oclif, command, config) {
@@ -535,16 +612,19 @@ var ConfigService = class {
535
612
  }
536
613
  async read(path) {
537
614
  const config = await this.parser.read(path);
615
+ this.logger.trace("Read config from: %s", path);
538
616
  return config;
539
617
  }
540
618
  async extend(paths, strategy = "OVERWRITE" /* OVERWRITE */) {
619
+ this.logger.trace("Will generate config from: %s with %s", paths.join(", "), strategy);
541
620
  const configs = await Promise.all(
542
621
  paths.map(async (path) => {
543
622
  try {
544
623
  const config = await this.parser.read(path);
624
+ this.logger.trace("Extending config from: %s", path);
545
625
  return config;
546
626
  } catch (e) {
547
- this.logger.trace(e);
627
+ this.logger.trace("Failed to extend config from: %s", e);
548
628
  return {};
549
629
  }
550
630
  })
@@ -667,61 +747,6 @@ var LockerService = class {
667
747
  };
668
748
  __name(LockerService, "LockerService");
669
749
 
670
- // src/lib/parser/yaml-parser.service.ts
671
- var import_yaml = require("yaml");
672
- var _YamlParser = class {
673
- constructor() {
674
- this.logger = new Logger(this.constructor.name);
675
- if (_YamlParser.instance) {
676
- return _YamlParser.instance;
677
- } else {
678
- _YamlParser.instance = this;
679
- this.logger.trace("Created a new instance.");
680
- }
681
- }
682
- parse(data) {
683
- try {
684
- return (0, import_yaml.parse)(data.toString());
685
- } catch (e) {
686
- this.logger.fatal("Error during parsing YAML file: %s", e.message);
687
- throw e;
688
- }
689
- }
690
- stringify(data) {
691
- return (0, import_yaml.stringify)(data, { prettyErrors: true });
692
- }
693
- };
694
- var YamlParser = _YamlParser;
695
- __name(YamlParser, "YamlParser");
696
- YamlParser.extensions = ["yaml", "yml"];
697
-
698
- // src/lib/parser/json-parser.service.ts
699
- var _JsonParser = class {
700
- constructor() {
701
- this.logger = new Logger(this.constructor.name);
702
- if (_JsonParser.instance) {
703
- return _JsonParser.instance;
704
- } else {
705
- _JsonParser.instance = this;
706
- this.logger.trace("Created a new instance.");
707
- }
708
- }
709
- parse(data) {
710
- try {
711
- return JSON.parse(data.toString());
712
- } catch (e) {
713
- this.logger.fatal("Error during parsing JSON file: %s", e.message);
714
- throw e;
715
- }
716
- }
717
- stringify(data) {
718
- return JSON.stringify(data, null, 2);
719
- }
720
- };
721
- var JsonParser = _JsonParser;
722
- __name(JsonParser, "JsonParser");
723
- JsonParser.extensions = ["json"];
724
-
725
750
  // src/lib/store/store.service.ts
726
751
  var StoreService = class {
727
752
  constructor() {
@@ -859,7 +884,8 @@ var Command = class extends import_core.Command {
859
884
  this.tasks = new import_listr22.Manager({
860
885
  rendererFallback: this.cs.isDebug,
861
886
  rendererSilent: this.cs.isSilent,
862
- nonTTYRendererOptions: { logEmptyTitle: false, logTitleChange: false }
887
+ nonTTYRendererOptions: { logEmptyTitle: false, logTitleChange: false },
888
+ ctx: {}
863
889
  });
864
890
  if (this.cs.oclif.windows) {
865
891
  (0, import_readline.createInterface)({
@@ -912,15 +938,11 @@ var Command = class extends import_core.Command {
912
938
  throw e;
913
939
  }
914
940
  }
915
- setDefaultsInCtx(options) {
916
- options.assign?.keys.forEach((i) => {
917
- if (options.assign.from[i]) {
918
- this.tasks.ctx[i] = options.assign.from[i];
919
- }
920
- });
921
- options.default?.forEach((i) => {
922
- Object.assign(this.tasks.ctx, i);
923
- });
941
+ setCtxDefaults(...defaults) {
942
+ return setCtxDefaults(this.tasks.ctx, ...defaults);
943
+ }
944
+ setCtxAssign(...assigns) {
945
+ return setCtxAssign(this.tasks.ctx, ...assigns);
924
946
  }
925
947
  exit(code) {
926
948
  this.logger.trace("Exitting with code: %d", code);
@@ -1032,6 +1054,8 @@ var src_default = {
1032
1054
  notFoundHook,
1033
1055
  pipeProcessThroughListr,
1034
1056
  pipeProcessToLogger,
1057
+ setCtxAssign,
1058
+ setCtxDefaults,
1035
1059
  setup,
1036
1060
  storeHook,
1037
1061
  updateNotifierHook
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cenk1cenk2/oclif-common",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.5",
4
4
  "description": "Oclif common package for oclif2 projects.",
5
5
  "repository": "https://gitlab.kilic.dev/libraries/oclif-tools",
6
6
  "author": {