@cenk1cenk2/oclif-common 2.1.2 → 2.2.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/index.d.ts +22 -14
- package/dist/index.js +29 -24
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -134,15 +134,6 @@ declare class GenericParser {
|
|
|
134
134
|
stringify<T = any>(data: T): string | Promise<string>;
|
|
135
135
|
}
|
|
136
136
|
|
|
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
137
|
declare class LockerService<LockFile extends LockableData = LockableData> {
|
|
147
138
|
private file;
|
|
148
139
|
private parser;
|
|
@@ -154,12 +145,12 @@ declare class LockerService<LockFile extends LockableData = LockableData> {
|
|
|
154
145
|
constructor(file: string, parser: GenericParser, root?: string);
|
|
155
146
|
hasLock(): boolean;
|
|
156
147
|
hasUnlock(): boolean;
|
|
157
|
-
addLock<T extends LockableData>(data: LockData<T>
|
|
158
|
-
addUnlock(data?: UnlockData
|
|
148
|
+
addLock<T extends LockableData = LockableData>(...data: LockData<T>[]): void;
|
|
149
|
+
addUnlock(data?: UnlockData[]): void;
|
|
159
150
|
lockAll(): Promise<void>;
|
|
160
151
|
unlockAll(): Promise<void>;
|
|
161
|
-
lock<T extends LockableData = LockableData>(data: LockData<T>
|
|
162
|
-
unlock(data
|
|
152
|
+
lock<T extends LockableData = LockableData>(...data: LockData<T>[]): Promise<void>;
|
|
153
|
+
unlock(...data: UnlockData[]): Promise<void>;
|
|
163
154
|
read(): Promise<LockFile>;
|
|
164
155
|
write(data: LockFile): Promise<void>;
|
|
165
156
|
private buildPath;
|
|
@@ -190,7 +181,8 @@ declare class ConfigService<Config extends BaseConfig = BaseConfig> {
|
|
|
190
181
|
parser: ParserService;
|
|
191
182
|
private readonly logger;
|
|
192
183
|
constructor(command: Command<any, Config>);
|
|
193
|
-
read<T extends LockableData = LockableData>(
|
|
184
|
+
read<T extends LockableData = LockableData>(path: string): Promise<T>;
|
|
185
|
+
extend<T extends LockableData = LockableData>(strategy: MergeStrategy, ...paths: string[]): Promise<T>;
|
|
194
186
|
write<T extends LockableData = LockableData>(path: string, data: T): Promise<void>;
|
|
195
187
|
}
|
|
196
188
|
|
|
@@ -216,6 +208,15 @@ declare class FileSystemService {
|
|
|
216
208
|
mkdirSync(directory: string): void;
|
|
217
209
|
}
|
|
218
210
|
|
|
211
|
+
declare class YamlParser implements GenericParser {
|
|
212
|
+
static extensions: string[];
|
|
213
|
+
static instance: YamlParser;
|
|
214
|
+
private readonly logger;
|
|
215
|
+
constructor();
|
|
216
|
+
parse<T = unknown>(data: string | Buffer): T;
|
|
217
|
+
stringify<T = any>(data: T): string;
|
|
218
|
+
}
|
|
219
|
+
|
|
219
220
|
interface ValidatorServiceOptions {
|
|
220
221
|
validator?: ValidatorOptions;
|
|
221
222
|
transformer?: ClassTransformOptions;
|
|
@@ -266,6 +267,13 @@ declare class Command<Ctx extends ListrContext = ListrContext, Config extends Ba
|
|
|
266
267
|
catch(e: Error): Promise<void>;
|
|
267
268
|
/** Gets prompt from user. */
|
|
268
269
|
prompt<T = any>(options: PromptOptions): Promise<T>;
|
|
270
|
+
setDefaultsInCtx<T = Ctx, K = Record<string, any>>(options: {
|
|
271
|
+
assign?: {
|
|
272
|
+
from: K;
|
|
273
|
+
keys: (keyof K)[];
|
|
274
|
+
};
|
|
275
|
+
default?: Partial<T>[];
|
|
276
|
+
}): void;
|
|
269
277
|
exit(code?: number): void;
|
|
270
278
|
private greet;
|
|
271
279
|
}
|
package/dist/index.js
CHANGED
|
@@ -614,7 +614,7 @@ var _ParserService = class {
|
|
|
614
614
|
}
|
|
615
615
|
getParser(file) {
|
|
616
616
|
const ext = this.fs.extname(file);
|
|
617
|
-
const Parser = this.parsers.find((parser) => parser.extensions.includes(ext.
|
|
617
|
+
const Parser = this.parsers.find((parser) => parser.extensions.includes(ext.replace(/^\./, "")));
|
|
618
618
|
if (!Parser) {
|
|
619
619
|
throw new Error(`Parser for the extension is not configured: ${ext}`);
|
|
620
620
|
}
|
|
@@ -697,10 +697,11 @@ var ConfigService = class {
|
|
|
697
697
|
this.parser = new ParserService();
|
|
698
698
|
this.logger.trace("Created a new instance.");
|
|
699
699
|
}
|
|
700
|
-
async read(
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
700
|
+
async read(path) {
|
|
701
|
+
const config2 = await this.parser.read(path);
|
|
702
|
+
return config2;
|
|
703
|
+
}
|
|
704
|
+
async extend(strategy, ...paths) {
|
|
704
705
|
const configs = await Promise.all(
|
|
705
706
|
paths.map(async (path) => {
|
|
706
707
|
try {
|
|
@@ -712,7 +713,7 @@ var ConfigService = class {
|
|
|
712
713
|
}
|
|
713
714
|
})
|
|
714
715
|
);
|
|
715
|
-
return merge(strategy
|
|
716
|
+
return merge(strategy, {}, ...configs);
|
|
716
717
|
}
|
|
717
718
|
async write(path, data) {
|
|
718
719
|
return this.parser.write(path, data);
|
|
@@ -742,28 +743,25 @@ var LockerService = class {
|
|
|
742
743
|
hasUnlock() {
|
|
743
744
|
return this.toUnlock.length > 0;
|
|
744
745
|
}
|
|
745
|
-
addLock(data) {
|
|
746
|
-
this.toLock = [...this.toLock, ...
|
|
746
|
+
addLock(...data) {
|
|
747
|
+
this.toLock = [...this.toLock, ...data];
|
|
747
748
|
}
|
|
748
749
|
addUnlock(data) {
|
|
749
|
-
this.toUnlock = [...this.toUnlock, ...
|
|
750
|
+
this.toUnlock = [...this.toUnlock, ...data];
|
|
750
751
|
}
|
|
751
752
|
async lockAll() {
|
|
752
753
|
if (this.hasLock()) {
|
|
753
|
-
await this.lock(this.toLock);
|
|
754
|
+
await this.lock(...this.toLock);
|
|
754
755
|
this.toLock = [];
|
|
755
756
|
}
|
|
756
757
|
}
|
|
757
758
|
async unlockAll() {
|
|
758
759
|
if (this.toUnlock.length > 0) {
|
|
759
|
-
await this.unlock(this.toUnlock);
|
|
760
|
+
await this.unlock(...this.toUnlock);
|
|
760
761
|
this.toUnlock = [];
|
|
761
762
|
}
|
|
762
763
|
}
|
|
763
|
-
async lock(data) {
|
|
764
|
-
if (!Array.isArray(data)) {
|
|
765
|
-
data = [data];
|
|
766
|
-
}
|
|
764
|
+
async lock(...data) {
|
|
767
765
|
let lock = await this.read() ?? {};
|
|
768
766
|
await Promise.all(
|
|
769
767
|
data.map(async (d) => {
|
|
@@ -782,25 +780,22 @@ var LockerService = class {
|
|
|
782
780
|
parsed = d.data;
|
|
783
781
|
}
|
|
784
782
|
lock = import_object_path_immutable.default.set(lock, path, parsed);
|
|
785
|
-
this.logger.verbose(
|
|
783
|
+
this.logger.verbose("Merge lock: %s", path);
|
|
786
784
|
} else {
|
|
787
785
|
lock = import_object_path_immutable.default.set(lock, path, d.data);
|
|
788
|
-
this.logger.verbose(
|
|
786
|
+
this.logger.verbose("Override lock: %s", path);
|
|
789
787
|
}
|
|
790
788
|
})
|
|
791
789
|
);
|
|
792
790
|
await this.write(lock);
|
|
793
791
|
}
|
|
794
|
-
async unlock(data) {
|
|
795
|
-
if (data && !Array.isArray(data)) {
|
|
796
|
-
data = [data];
|
|
797
|
-
}
|
|
792
|
+
async unlock(...data) {
|
|
798
793
|
let lock = await this.read();
|
|
799
794
|
if (!lock) {
|
|
800
795
|
this.logger.verbose("Lock file not found. Nothing to unlock.");
|
|
801
796
|
return;
|
|
802
797
|
}
|
|
803
|
-
if (
|
|
798
|
+
if (data.length > 0) {
|
|
804
799
|
await Promise.all(
|
|
805
800
|
data.map(async (d) => {
|
|
806
801
|
if (d?.enabled === false) {
|
|
@@ -808,12 +803,12 @@ var LockerService = class {
|
|
|
808
803
|
}
|
|
809
804
|
const path = this.buildPath(d);
|
|
810
805
|
lock = import_object_path_immutable.default.del(lock, path);
|
|
811
|
-
this.logger.verbose(
|
|
806
|
+
this.logger.verbose("Unlocked: %s", path, { custom: "locker" });
|
|
812
807
|
})
|
|
813
808
|
);
|
|
814
809
|
} else {
|
|
815
810
|
lock = import_object_path_immutable.default.del(lock, this.root);
|
|
816
|
-
this.logger.verbose(
|
|
811
|
+
this.logger.verbose("Unlocked module: %s", this.root, { custom: "locker" });
|
|
817
812
|
}
|
|
818
813
|
await this.write(lock);
|
|
819
814
|
}
|
|
@@ -992,6 +987,16 @@ var Command = class extends import_core.Command {
|
|
|
992
987
|
throw e;
|
|
993
988
|
}
|
|
994
989
|
}
|
|
990
|
+
setDefaultsInCtx(options) {
|
|
991
|
+
options.assign?.keys.forEach((i) => {
|
|
992
|
+
if (options.assign.from[i]) {
|
|
993
|
+
this.tasks.ctx[i] = options.assign.from[i];
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
options.default?.forEach((i) => {
|
|
997
|
+
Object.assign(this.tasks.ctx, i);
|
|
998
|
+
});
|
|
999
|
+
}
|
|
995
1000
|
exit(code) {
|
|
996
1001
|
this.logger.trace("Exitting with code: %d", code);
|
|
997
1002
|
process.exit(code ?? 0);
|