@cenk1cenk2/oclif-common 2.2.0 → 2.3.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +264 -14
- package/dist/hooks/not-found.hook.js +9 -14
- package/dist/hooks/store.hook.d.ts +2 -0
- package/dist/hooks/store.hook.js +471 -0
- package/dist/index.d.ts +106 -48
- package/dist/index.js +400 -451
- package/dist/store.hook-06894aa2.d.ts +18 -0
- package/package.json +10 -9
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -27,6 +27,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
27
27
|
var hooks_exports = {};
|
|
28
28
|
__export(hooks_exports, {
|
|
29
29
|
notFoundHook: () => notFoundHook,
|
|
30
|
+
storeHook: () => storeHook,
|
|
30
31
|
updateNotifierHook: () => updateNotifierHook
|
|
31
32
|
});
|
|
32
33
|
module.exports = __toCommonJS(hooks_exports);
|
|
@@ -54,10 +55,8 @@ var LogLevels = /* @__PURE__ */ ((LogLevels2) => {
|
|
|
54
55
|
return LogLevels2;
|
|
55
56
|
})(LogLevels || {});
|
|
56
57
|
|
|
57
|
-
// src/utils/logger/logger.interface.ts
|
|
58
|
-
var WINSTON_INSTANCE = "WINSTON_DEFAULT_LOGGER";
|
|
59
|
-
|
|
60
58
|
// src/utils/logger/logger.ts
|
|
59
|
+
var import_listr2 = require("listr2");
|
|
61
60
|
var import_os = require("os");
|
|
62
61
|
var import_winston = __toESM(require("winston"));
|
|
63
62
|
|
|
@@ -65,15 +64,12 @@ var import_winston = __toESM(require("winston"));
|
|
|
65
64
|
var colorette = __toESM(require("colorette"));
|
|
66
65
|
var color = colorette.createColors({ useColor: true });
|
|
67
66
|
|
|
68
|
-
// src/utils/figures.ts
|
|
69
|
-
var import_figures = __toESM(require("figures"));
|
|
70
|
-
|
|
71
67
|
// src/utils/logger/logger.ts
|
|
72
68
|
var Logger = class {
|
|
73
69
|
constructor(context, options) {
|
|
74
70
|
this.context = context;
|
|
75
71
|
this.options = options;
|
|
76
|
-
const level = options?.level
|
|
72
|
+
const level = options?.level?.toUpperCase();
|
|
77
73
|
this.options = {
|
|
78
74
|
useIcons: true,
|
|
79
75
|
...options,
|
|
@@ -134,7 +130,7 @@ var Logger = class {
|
|
|
134
130
|
});
|
|
135
131
|
return multiLineMessage.join(import_os.EOL);
|
|
136
132
|
});
|
|
137
|
-
const logger = import_winston.default.
|
|
133
|
+
const logger = import_winston.default.createLogger({
|
|
138
134
|
level: this.options.level,
|
|
139
135
|
format: import_winston.format.combine(import_winston.format.splat(), import_winston.format.json({ space: 2 }), import_winston.format.prettyPrint(), logFormat),
|
|
140
136
|
levels: Object.values(LogLevels).reduce((o, level, i) => {
|
|
@@ -168,33 +164,33 @@ var Logger = class {
|
|
|
168
164
|
case "DIRECT" /* DIRECT */:
|
|
169
165
|
return message;
|
|
170
166
|
case "FATAL" /* FATAL */:
|
|
171
|
-
coloring = /* @__PURE__ */ __name((input) => color.
|
|
167
|
+
coloring = /* @__PURE__ */ __name((input) => color.red(input), "coloring");
|
|
172
168
|
if (this.options?.useIcons) {
|
|
173
|
-
icon =
|
|
169
|
+
icon = import_listr2.figures.checkboxOn;
|
|
174
170
|
}
|
|
175
171
|
break;
|
|
176
172
|
case "ERROR" /* ERROR */:
|
|
177
173
|
coloring = color.red;
|
|
178
174
|
if (this.options?.useIcons) {
|
|
179
|
-
icon =
|
|
175
|
+
icon = import_listr2.figures.cross;
|
|
180
176
|
}
|
|
181
177
|
break;
|
|
182
178
|
case "WARN" /* WARN */:
|
|
183
179
|
coloring = color.yellow;
|
|
184
180
|
if (this.options?.useIcons) {
|
|
185
|
-
icon =
|
|
181
|
+
icon = import_listr2.figures.warning;
|
|
186
182
|
}
|
|
187
183
|
break;
|
|
188
184
|
case "INFO" /* INFO */:
|
|
189
185
|
coloring = color.green;
|
|
190
186
|
if (this.options?.useIcons) {
|
|
191
|
-
icon =
|
|
187
|
+
icon = import_listr2.figures.pointerSmall;
|
|
192
188
|
}
|
|
193
189
|
break;
|
|
194
190
|
case "VERBOSE" /* VERBOSE */:
|
|
195
191
|
coloring = color.dim;
|
|
196
192
|
if (this.options?.useIcons) {
|
|
197
|
-
icon =
|
|
193
|
+
icon = import_listr2.figures.squareSmallFilled;
|
|
198
194
|
}
|
|
199
195
|
break;
|
|
200
196
|
case "DEBUG" /* DEBUG */:
|
|
@@ -235,8 +231,262 @@ var import_update_notifier = __toESM(require("update-notifier"));
|
|
|
235
231
|
var updateNotifierHook = /* @__PURE__ */ __name(async (opts) => {
|
|
236
232
|
(0, import_update_notifier.default)({ pkg: { name: opts.config.name, version: opts.config.version } }).notify({ isGlobal: true });
|
|
237
233
|
}, "updateNotifierHook");
|
|
234
|
+
|
|
235
|
+
// src/lib/config/config.service.ts
|
|
236
|
+
var import_path2 = require("path");
|
|
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 {
|
|
242
|
+
constructor() {
|
|
243
|
+
this.logger = new Logger(this.constructor.name);
|
|
244
|
+
if (FileSystemService.instance) {
|
|
245
|
+
return FileSystemService.instance;
|
|
246
|
+
} else {
|
|
247
|
+
FileSystemService.instance = this;
|
|
248
|
+
this.logger.trace("Created a new instance.");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
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) {
|
|
343
|
+
try {
|
|
344
|
+
import_fs_extra.default.mkdirSync(directory);
|
|
345
|
+
} 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}`);
|
|
370
|
+
}
|
|
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
|
+
}
|
|
384
|
+
parse(parser, data) {
|
|
385
|
+
return parser.parse(data);
|
|
386
|
+
}
|
|
387
|
+
stringify(parser, data) {
|
|
388
|
+
return parser.stringify(data);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
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"));
|
|
400
|
+
|
|
401
|
+
// src/lib/parser/yaml-parser.service.ts
|
|
402
|
+
var import_yaml = require("yaml");
|
|
403
|
+
var _YamlParser = class {
|
|
404
|
+
constructor() {
|
|
405
|
+
this.logger = new Logger(this.constructor.name);
|
|
406
|
+
if (_YamlParser.instance) {
|
|
407
|
+
return _YamlParser.instance;
|
|
408
|
+
} else {
|
|
409
|
+
_YamlParser.instance = this;
|
|
410
|
+
this.logger.trace("Created a new instance.");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
parse(data) {
|
|
414
|
+
try {
|
|
415
|
+
return (0, import_yaml.parse)(data.toString());
|
|
416
|
+
} catch (e) {
|
|
417
|
+
this.logger.fatal("Error during parsing YAML file: %s", e.message);
|
|
418
|
+
throw e;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
stringify(data) {
|
|
422
|
+
return (0, import_yaml.stringify)(data, { prettyErrors: true });
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
var YamlParser = _YamlParser;
|
|
426
|
+
__name(YamlParser, "YamlParser");
|
|
427
|
+
YamlParser.extensions = ["yaml", "yml"];
|
|
428
|
+
|
|
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"];
|
|
455
|
+
|
|
456
|
+
// src/lib/store/store.service.ts
|
|
457
|
+
var StoreService = class {
|
|
458
|
+
constructor() {
|
|
459
|
+
this.store = {};
|
|
460
|
+
if (StoreService.instance) {
|
|
461
|
+
return StoreService.instance;
|
|
462
|
+
} else {
|
|
463
|
+
StoreService.instance = this;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
has(key) {
|
|
467
|
+
return !!this.store[key];
|
|
468
|
+
}
|
|
469
|
+
get(key) {
|
|
470
|
+
return this.store[key];
|
|
471
|
+
}
|
|
472
|
+
set(key, data) {
|
|
473
|
+
this.store[key] = data;
|
|
474
|
+
return data;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
__name(StoreService, "StoreService");
|
|
478
|
+
|
|
479
|
+
// src/lib/validator/validator.service.ts
|
|
480
|
+
var import_class_transformer = require("class-transformer");
|
|
481
|
+
var import_class_validator = require("class-validator");
|
|
482
|
+
|
|
483
|
+
// src/hooks/store.hook.ts
|
|
484
|
+
var storeHook = /* @__PURE__ */ __name((cb) => async (opts) => {
|
|
485
|
+
cb(opts, new StoreService());
|
|
486
|
+
}, "storeHook");
|
|
238
487
|
// Annotate the CommonJS export names for ESM import in node:
|
|
239
488
|
0 && (module.exports = {
|
|
240
489
|
notFoundHook,
|
|
490
|
+
storeHook,
|
|
241
491
|
updateNotifierHook
|
|
242
492
|
});
|
|
@@ -51,10 +51,8 @@ var LogLevels = /* @__PURE__ */ ((LogLevels2) => {
|
|
|
51
51
|
return LogLevels2;
|
|
52
52
|
})(LogLevels || {});
|
|
53
53
|
|
|
54
|
-
// src/utils/logger/logger.interface.ts
|
|
55
|
-
var WINSTON_INSTANCE = "WINSTON_DEFAULT_LOGGER";
|
|
56
|
-
|
|
57
54
|
// src/utils/logger/logger.ts
|
|
55
|
+
var import_listr2 = require("listr2");
|
|
58
56
|
var import_os = require("os");
|
|
59
57
|
var import_winston = __toESM(require("winston"));
|
|
60
58
|
|
|
@@ -62,15 +60,12 @@ var import_winston = __toESM(require("winston"));
|
|
|
62
60
|
var colorette = __toESM(require("colorette"));
|
|
63
61
|
var color = colorette.createColors({ useColor: true });
|
|
64
62
|
|
|
65
|
-
// src/utils/figures.ts
|
|
66
|
-
var import_figures = __toESM(require("figures"));
|
|
67
|
-
|
|
68
63
|
// src/utils/logger/logger.ts
|
|
69
64
|
var Logger = class {
|
|
70
65
|
constructor(context, options) {
|
|
71
66
|
this.context = context;
|
|
72
67
|
this.options = options;
|
|
73
|
-
const level = options?.level
|
|
68
|
+
const level = options?.level?.toUpperCase();
|
|
74
69
|
this.options = {
|
|
75
70
|
useIcons: true,
|
|
76
71
|
...options,
|
|
@@ -131,7 +126,7 @@ var Logger = class {
|
|
|
131
126
|
});
|
|
132
127
|
return multiLineMessage.join(import_os.EOL);
|
|
133
128
|
});
|
|
134
|
-
const logger = import_winston.default.
|
|
129
|
+
const logger = import_winston.default.createLogger({
|
|
135
130
|
level: this.options.level,
|
|
136
131
|
format: import_winston.format.combine(import_winston.format.splat(), import_winston.format.json({ space: 2 }), import_winston.format.prettyPrint(), logFormat),
|
|
137
132
|
levels: Object.values(LogLevels).reduce((o, level, i) => {
|
|
@@ -165,33 +160,33 @@ var Logger = class {
|
|
|
165
160
|
case "DIRECT" /* DIRECT */:
|
|
166
161
|
return message;
|
|
167
162
|
case "FATAL" /* FATAL */:
|
|
168
|
-
coloring = /* @__PURE__ */ __name((input) => color.
|
|
163
|
+
coloring = /* @__PURE__ */ __name((input) => color.red(input), "coloring");
|
|
169
164
|
if (this.options?.useIcons) {
|
|
170
|
-
icon =
|
|
165
|
+
icon = import_listr2.figures.checkboxOn;
|
|
171
166
|
}
|
|
172
167
|
break;
|
|
173
168
|
case "ERROR" /* ERROR */:
|
|
174
169
|
coloring = color.red;
|
|
175
170
|
if (this.options?.useIcons) {
|
|
176
|
-
icon =
|
|
171
|
+
icon = import_listr2.figures.cross;
|
|
177
172
|
}
|
|
178
173
|
break;
|
|
179
174
|
case "WARN" /* WARN */:
|
|
180
175
|
coloring = color.yellow;
|
|
181
176
|
if (this.options?.useIcons) {
|
|
182
|
-
icon =
|
|
177
|
+
icon = import_listr2.figures.warning;
|
|
183
178
|
}
|
|
184
179
|
break;
|
|
185
180
|
case "INFO" /* INFO */:
|
|
186
181
|
coloring = color.green;
|
|
187
182
|
if (this.options?.useIcons) {
|
|
188
|
-
icon =
|
|
183
|
+
icon = import_listr2.figures.pointerSmall;
|
|
189
184
|
}
|
|
190
185
|
break;
|
|
191
186
|
case "VERBOSE" /* VERBOSE */:
|
|
192
187
|
coloring = color.dim;
|
|
193
188
|
if (this.options?.useIcons) {
|
|
194
|
-
icon =
|
|
189
|
+
icon = import_listr2.figures.squareSmallFilled;
|
|
195
190
|
}
|
|
196
191
|
break;
|
|
197
192
|
case "DEBUG" /* DEBUG */:
|