@cenk1cenk2/oclif-common 2.1.2 → 2.3.0
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.js +1 -4
- package/dist/hooks/not-found.hook.js +1 -4
- package/dist/index.d.ts +23 -16
- package/dist/index.js +31 -32
- package/package.json +1 -1
package/dist/hooks/index.js
CHANGED
|
@@ -54,9 +54,6 @@ var LogLevels = /* @__PURE__ */ ((LogLevels2) => {
|
|
|
54
54
|
return LogLevels2;
|
|
55
55
|
})(LogLevels || {});
|
|
56
56
|
|
|
57
|
-
// src/utils/logger/logger.interface.ts
|
|
58
|
-
var WINSTON_INSTANCE = "WINSTON_DEFAULT_LOGGER";
|
|
59
|
-
|
|
60
57
|
// src/utils/logger/logger.ts
|
|
61
58
|
var import_os = require("os");
|
|
62
59
|
var import_winston = __toESM(require("winston"));
|
|
@@ -134,7 +131,7 @@ var Logger = class {
|
|
|
134
131
|
});
|
|
135
132
|
return multiLineMessage.join(import_os.EOL);
|
|
136
133
|
});
|
|
137
|
-
const logger = import_winston.default.
|
|
134
|
+
const logger = import_winston.default.createLogger({
|
|
138
135
|
level: this.options.level,
|
|
139
136
|
format: import_winston.format.combine(import_winston.format.splat(), import_winston.format.json({ space: 2 }), import_winston.format.prettyPrint(), logFormat),
|
|
140
137
|
levels: Object.values(LogLevels).reduce((o, level, i) => {
|
|
@@ -51,9 +51,6 @@ 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
|
|
58
55
|
var import_os = require("os");
|
|
59
56
|
var import_winston = __toESM(require("winston"));
|
|
@@ -131,7 +128,7 @@ var Logger = class {
|
|
|
131
128
|
});
|
|
132
129
|
return multiLineMessage.join(import_os.EOL);
|
|
133
130
|
});
|
|
134
|
-
const logger = import_winston.default.
|
|
131
|
+
const logger = import_winston.default.createLogger({
|
|
135
132
|
level: this.options.level,
|
|
136
133
|
format: import_winston.format.combine(import_winston.format.splat(), import_winston.format.json({ space: 2 }), import_winston.format.prettyPrint(), logFormat),
|
|
137
134
|
levels: Object.values(LogLevels).reduce((o, level, i) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,6 @@ interface LoggerFormat {
|
|
|
41
41
|
status: string;
|
|
42
42
|
}
|
|
43
43
|
declare type Winston = Logger$1 & Record<keyof typeof LogLevels, LeveledLogMethod>;
|
|
44
|
-
declare const WINSTON_INSTANCE = "WINSTON_DEFAULT_LOGGER";
|
|
45
44
|
|
|
46
45
|
/**
|
|
47
46
|
* A general logger for the the CLI applications.
|
|
@@ -134,15 +133,6 @@ declare class GenericParser {
|
|
|
134
133
|
stringify<T = any>(data: T): string | Promise<string>;
|
|
135
134
|
}
|
|
136
135
|
|
|
137
|
-
declare class YamlParser implements GenericParser {
|
|
138
|
-
static extensions: string[];
|
|
139
|
-
static instance: YamlParser;
|
|
140
|
-
private readonly logger;
|
|
141
|
-
constructor();
|
|
142
|
-
parse<T = unknown>(data: string | Buffer): T;
|
|
143
|
-
stringify<T = any>(data: T): string;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
136
|
declare class LockerService<LockFile extends LockableData = LockableData> {
|
|
147
137
|
private file;
|
|
148
138
|
private parser;
|
|
@@ -154,12 +144,12 @@ declare class LockerService<LockFile extends LockableData = LockableData> {
|
|
|
154
144
|
constructor(file: string, parser: GenericParser, root?: string);
|
|
155
145
|
hasLock(): boolean;
|
|
156
146
|
hasUnlock(): boolean;
|
|
157
|
-
addLock<T extends LockableData>(data: LockData<T>
|
|
158
|
-
addUnlock(data
|
|
147
|
+
addLock<T extends LockableData = LockableData>(...data: LockData<T>[]): void;
|
|
148
|
+
addUnlock(...data: UnlockData[]): void;
|
|
159
149
|
lockAll(): Promise<void>;
|
|
160
150
|
unlockAll(): Promise<void>;
|
|
161
|
-
lock<T extends LockableData = LockableData>(data: LockData<T>
|
|
162
|
-
unlock(data
|
|
151
|
+
lock<T extends LockableData = LockableData>(...data: LockData<T>[]): Promise<void>;
|
|
152
|
+
unlock(...data: UnlockData[]): Promise<void>;
|
|
163
153
|
read(): Promise<LockFile>;
|
|
164
154
|
write(data: LockFile): Promise<void>;
|
|
165
155
|
private buildPath;
|
|
@@ -190,7 +180,8 @@ declare class ConfigService<Config extends BaseConfig = BaseConfig> {
|
|
|
190
180
|
parser: ParserService;
|
|
191
181
|
private readonly logger;
|
|
192
182
|
constructor(command: Command<any, Config>);
|
|
193
|
-
read<T extends LockableData = LockableData>(
|
|
183
|
+
read<T extends LockableData = LockableData>(path: string): Promise<T>;
|
|
184
|
+
extend<T extends LockableData = LockableData>(strategy: MergeStrategy, ...paths: string[]): Promise<T>;
|
|
194
185
|
write<T extends LockableData = LockableData>(path: string, data: T): Promise<void>;
|
|
195
186
|
}
|
|
196
187
|
|
|
@@ -216,6 +207,15 @@ declare class FileSystemService {
|
|
|
216
207
|
mkdirSync(directory: string): void;
|
|
217
208
|
}
|
|
218
209
|
|
|
210
|
+
declare class YamlParser implements GenericParser {
|
|
211
|
+
static extensions: string[];
|
|
212
|
+
static instance: YamlParser;
|
|
213
|
+
private readonly logger;
|
|
214
|
+
constructor();
|
|
215
|
+
parse<T = unknown>(data: string | Buffer): T;
|
|
216
|
+
stringify<T = any>(data: T): string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
219
|
interface ValidatorServiceOptions {
|
|
220
220
|
validator?: ValidatorOptions;
|
|
221
221
|
transformer?: ClassTransformOptions;
|
|
@@ -266,6 +266,13 @@ declare class Command<Ctx extends ListrContext = ListrContext, Config extends Ba
|
|
|
266
266
|
catch(e: Error): Promise<void>;
|
|
267
267
|
/** Gets prompt from user. */
|
|
268
268
|
prompt<T = any>(options: PromptOptions): Promise<T>;
|
|
269
|
+
setDefaultsInCtx<T = Ctx, K = Record<string, any>>(options: {
|
|
270
|
+
assign?: {
|
|
271
|
+
from: K;
|
|
272
|
+
keys: (keyof K)[];
|
|
273
|
+
};
|
|
274
|
+
default?: Partial<T>[];
|
|
275
|
+
}): void;
|
|
269
276
|
exit(code?: number): void;
|
|
270
277
|
private greet;
|
|
271
278
|
}
|
|
@@ -288,4 +295,4 @@ declare enum FileConstants {
|
|
|
288
295
|
CONFIG_SERVICE_DEFAULTS_DIR = "defaults"
|
|
289
296
|
}
|
|
290
297
|
|
|
291
|
-
export { BaseConfig, ClassType, Command, CommonLockerData, ConfigCommand, ConfigCommandChoices, ConfigCommandSetup, ConfigService, FileConstants, FileSystemService, GenericParser, LockData, LockableData, LockerService, LogFieldStatus, LogLevels, Logger, LoggerFormat, LoggerOptions, MergeStrategy, PipeProcessToLoggerOptions, UnlockData, ValidatorService, ValidatorServiceOptions,
|
|
298
|
+
export { BaseConfig, ClassType, Command, CommonLockerData, ConfigCommand, ConfigCommandChoices, ConfigCommandSetup, ConfigService, FileConstants, FileSystemService, GenericParser, LockData, LockableData, LockerService, LogFieldStatus, LogLevels, Logger, LoggerFormat, LoggerOptions, MergeStrategy, PipeProcessToLoggerOptions, UnlockData, ValidatorService, ValidatorServiceOptions, Winston, YamlParser, color, isDebug, isSilent, isVerbose, merge, pipeProcessThroughListr, pipeProcessToLogger, setup };
|
package/dist/index.js
CHANGED
|
@@ -141,10 +141,8 @@ var init_pipe = __esm({
|
|
|
141
141
|
});
|
|
142
142
|
|
|
143
143
|
// src/utils/logger/logger.interface.ts
|
|
144
|
-
var WINSTON_INSTANCE;
|
|
145
144
|
var init_logger_interface = __esm({
|
|
146
145
|
"src/utils/logger/logger.interface.ts"() {
|
|
147
|
-
WINSTON_INSTANCE = "WINSTON_DEFAULT_LOGGER";
|
|
148
146
|
}
|
|
149
147
|
});
|
|
150
148
|
|
|
@@ -172,7 +170,6 @@ var init_logger = __esm({
|
|
|
172
170
|
import_os = require("os");
|
|
173
171
|
import_winston = __toESM(require("winston"));
|
|
174
172
|
init_logger_constants();
|
|
175
|
-
init_logger_interface();
|
|
176
173
|
init_color();
|
|
177
174
|
init_figures();
|
|
178
175
|
Logger = class {
|
|
@@ -240,7 +237,7 @@ var init_logger = __esm({
|
|
|
240
237
|
});
|
|
241
238
|
return multiLineMessage.join(import_os.EOL);
|
|
242
239
|
});
|
|
243
|
-
const logger = import_winston.default.
|
|
240
|
+
const logger = import_winston.default.createLogger({
|
|
244
241
|
level: this.options.level,
|
|
245
242
|
format: import_winston.format.combine(import_winston.format.splat(), import_winston.format.json({ space: 2 }), import_winston.format.prettyPrint(), logFormat),
|
|
246
243
|
levels: Object.values(LogLevels).reduce((o, level, i) => {
|
|
@@ -334,7 +331,6 @@ __export(logger_exports, {
|
|
|
334
331
|
LogFieldStatus: () => LogFieldStatus,
|
|
335
332
|
LogLevels: () => LogLevels,
|
|
336
333
|
Logger: () => Logger,
|
|
337
|
-
WINSTON_INSTANCE: () => WINSTON_INSTANCE,
|
|
338
334
|
pipeProcessThroughListr: () => pipeProcessThroughListr,
|
|
339
335
|
pipeProcessToLogger: () => pipeProcessToLogger
|
|
340
336
|
});
|
|
@@ -397,7 +393,6 @@ __export(src_exports, {
|
|
|
397
393
|
Logger: () => Logger,
|
|
398
394
|
MergeStrategy: () => MergeStrategy,
|
|
399
395
|
ValidatorService: () => ValidatorService,
|
|
400
|
-
WINSTON_INSTANCE: () => WINSTON_INSTANCE,
|
|
401
396
|
YamlParser: () => YamlParser,
|
|
402
397
|
color: () => color,
|
|
403
398
|
config: () => import_config.util,
|
|
@@ -614,7 +609,7 @@ var _ParserService = class {
|
|
|
614
609
|
}
|
|
615
610
|
getParser(file) {
|
|
616
611
|
const ext = this.fs.extname(file);
|
|
617
|
-
const Parser = this.parsers.find((parser) => parser.extensions.includes(ext.
|
|
612
|
+
const Parser = this.parsers.find((parser) => parser.extensions.includes(ext.replace(/^\./, "")));
|
|
618
613
|
if (!Parser) {
|
|
619
614
|
throw new Error(`Parser for the extension is not configured: ${ext}`);
|
|
620
615
|
}
|
|
@@ -697,10 +692,11 @@ var ConfigService = class {
|
|
|
697
692
|
this.parser = new ParserService();
|
|
698
693
|
this.logger.trace("Created a new instance.");
|
|
699
694
|
}
|
|
700
|
-
async read(
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
695
|
+
async read(path) {
|
|
696
|
+
const config2 = await this.parser.read(path);
|
|
697
|
+
return config2;
|
|
698
|
+
}
|
|
699
|
+
async extend(strategy, ...paths) {
|
|
704
700
|
const configs = await Promise.all(
|
|
705
701
|
paths.map(async (path) => {
|
|
706
702
|
try {
|
|
@@ -712,7 +708,7 @@ var ConfigService = class {
|
|
|
712
708
|
}
|
|
713
709
|
})
|
|
714
710
|
);
|
|
715
|
-
return merge(strategy
|
|
711
|
+
return merge(strategy, {}, ...configs);
|
|
716
712
|
}
|
|
717
713
|
async write(path, data) {
|
|
718
714
|
return this.parser.write(path, data);
|
|
@@ -742,28 +738,25 @@ var LockerService = class {
|
|
|
742
738
|
hasUnlock() {
|
|
743
739
|
return this.toUnlock.length > 0;
|
|
744
740
|
}
|
|
745
|
-
addLock(data) {
|
|
746
|
-
this.toLock = [...this.toLock, ...
|
|
741
|
+
addLock(...data) {
|
|
742
|
+
this.toLock = [...this.toLock, ...data];
|
|
747
743
|
}
|
|
748
|
-
addUnlock(data) {
|
|
749
|
-
this.toUnlock = [...this.toUnlock, ...
|
|
744
|
+
addUnlock(...data) {
|
|
745
|
+
this.toUnlock = [...this.toUnlock, ...data];
|
|
750
746
|
}
|
|
751
747
|
async lockAll() {
|
|
752
748
|
if (this.hasLock()) {
|
|
753
|
-
await this.lock(this.toLock);
|
|
749
|
+
await this.lock(...this.toLock);
|
|
754
750
|
this.toLock = [];
|
|
755
751
|
}
|
|
756
752
|
}
|
|
757
753
|
async unlockAll() {
|
|
758
754
|
if (this.toUnlock.length > 0) {
|
|
759
|
-
await this.unlock(this.toUnlock);
|
|
755
|
+
await this.unlock(...this.toUnlock);
|
|
760
756
|
this.toUnlock = [];
|
|
761
757
|
}
|
|
762
758
|
}
|
|
763
|
-
async lock(data) {
|
|
764
|
-
if (!Array.isArray(data)) {
|
|
765
|
-
data = [data];
|
|
766
|
-
}
|
|
759
|
+
async lock(...data) {
|
|
767
760
|
let lock = await this.read() ?? {};
|
|
768
761
|
await Promise.all(
|
|
769
762
|
data.map(async (d) => {
|
|
@@ -782,25 +775,22 @@ var LockerService = class {
|
|
|
782
775
|
parsed = d.data;
|
|
783
776
|
}
|
|
784
777
|
lock = import_object_path_immutable.default.set(lock, path, parsed);
|
|
785
|
-
this.logger.verbose(
|
|
778
|
+
this.logger.verbose("Merge lock: %s", path);
|
|
786
779
|
} else {
|
|
787
780
|
lock = import_object_path_immutable.default.set(lock, path, d.data);
|
|
788
|
-
this.logger.verbose(
|
|
781
|
+
this.logger.verbose("Override lock: %s", path);
|
|
789
782
|
}
|
|
790
783
|
})
|
|
791
784
|
);
|
|
792
785
|
await this.write(lock);
|
|
793
786
|
}
|
|
794
|
-
async unlock(data) {
|
|
795
|
-
if (data && !Array.isArray(data)) {
|
|
796
|
-
data = [data];
|
|
797
|
-
}
|
|
787
|
+
async unlock(...data) {
|
|
798
788
|
let lock = await this.read();
|
|
799
789
|
if (!lock) {
|
|
800
790
|
this.logger.verbose("Lock file not found. Nothing to unlock.");
|
|
801
791
|
return;
|
|
802
792
|
}
|
|
803
|
-
if (
|
|
793
|
+
if (data.length > 0) {
|
|
804
794
|
await Promise.all(
|
|
805
795
|
data.map(async (d) => {
|
|
806
796
|
if (d?.enabled === false) {
|
|
@@ -808,12 +798,12 @@ var LockerService = class {
|
|
|
808
798
|
}
|
|
809
799
|
const path = this.buildPath(d);
|
|
810
800
|
lock = import_object_path_immutable.default.del(lock, path);
|
|
811
|
-
this.logger.verbose(
|
|
801
|
+
this.logger.verbose("Unlocked: %s", path, { custom: "locker" });
|
|
812
802
|
})
|
|
813
803
|
);
|
|
814
804
|
} else {
|
|
815
805
|
lock = import_object_path_immutable.default.del(lock, this.root);
|
|
816
|
-
this.logger.verbose(
|
|
806
|
+
this.logger.verbose("Unlocked module: %s", this.root, { custom: "locker" });
|
|
817
807
|
}
|
|
818
808
|
await this.write(lock);
|
|
819
809
|
}
|
|
@@ -992,6 +982,16 @@ var Command = class extends import_core.Command {
|
|
|
992
982
|
throw e;
|
|
993
983
|
}
|
|
994
984
|
}
|
|
985
|
+
setDefaultsInCtx(options) {
|
|
986
|
+
options.assign?.keys.forEach((i) => {
|
|
987
|
+
if (options.assign.from[i]) {
|
|
988
|
+
this.tasks.ctx[i] = options.assign.from[i];
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
options.default?.forEach((i) => {
|
|
992
|
+
Object.assign(this.tasks.ctx, i);
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
995
|
exit(code) {
|
|
996
996
|
this.logger.trace("Exitting with code: %d", code);
|
|
997
997
|
process.exit(code ?? 0);
|
|
@@ -1059,7 +1059,6 @@ __reExport(src_exports, lib_exports, module.exports);
|
|
|
1059
1059
|
Logger,
|
|
1060
1060
|
MergeStrategy,
|
|
1061
1061
|
ValidatorService,
|
|
1062
|
-
WINSTON_INSTANCE,
|
|
1063
1062
|
YamlParser,
|
|
1064
1063
|
color,
|
|
1065
1064
|
config,
|