@cenk1cenk2/oclif-common 3.0.3 → 3.1.0-beta.10
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 +21 -6
- package/dist/index.js +58 -23
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -98,13 +98,21 @@ interface PipeProcessToLoggerOptions {
|
|
|
98
98
|
*/
|
|
99
99
|
declare function pipeProcessToLogger(logger: Logger, instance: ExecaChildProcess, options?: PipeProcessToLoggerOptions): ExecaChildProcess;
|
|
100
100
|
|
|
101
|
-
interface
|
|
101
|
+
interface GlobalConfigInit {
|
|
102
102
|
logLevel: LogLevels;
|
|
103
103
|
ci: boolean;
|
|
104
|
+
json: boolean;
|
|
105
|
+
}
|
|
106
|
+
interface GlobalConfig extends GlobalConfigInit {
|
|
104
107
|
isVerbose: boolean;
|
|
105
108
|
isDebug: boolean;
|
|
106
109
|
isSilent: boolean;
|
|
107
|
-
|
|
110
|
+
}
|
|
111
|
+
interface ConfigIterator {
|
|
112
|
+
key: (string | number)[];
|
|
113
|
+
env: string;
|
|
114
|
+
parser?: string;
|
|
115
|
+
extensions?: ConfigIterator[];
|
|
108
116
|
}
|
|
109
117
|
|
|
110
118
|
declare const color: colorette.Colorette;
|
|
@@ -203,9 +211,9 @@ declare class ConfigService implements GlobalConfig {
|
|
|
203
211
|
private readonly logger;
|
|
204
212
|
constructor(oclif: Command['config'], command: Command['ctor'], config: Omit<GlobalConfig, 'isVerbose' | 'isDebug' | 'isSilent'>);
|
|
205
213
|
read<T extends LockableData = LockableData>(path: string): Promise<T>;
|
|
206
|
-
extend<T extends LockableData = LockableData>(paths: string[], strategy?: MergeStrategy): Promise<T>;
|
|
207
|
-
merge<T extends LockableData = LockableData>(configs: Partial<T>[], strategy?: MergeStrategy):
|
|
208
|
-
env<T extends LockableData = LockableData>(definition: string, config: T): Promise<T>;
|
|
214
|
+
extend<T extends LockableData = LockableData>(paths: (string | Partial<T>)[], strategy?: MergeStrategy): Promise<T>;
|
|
215
|
+
merge<T extends LockableData = LockableData>(configs: Partial<T>[], strategy?: MergeStrategy): T;
|
|
216
|
+
env<T extends LockableData = LockableData>(definition: string | Record<PropertyKey, any>, config: T): Promise<T>;
|
|
209
217
|
write<T extends LockableData = LockableData>(path: string, data: T): Promise<void>;
|
|
210
218
|
private recalculate;
|
|
211
219
|
}
|
|
@@ -275,6 +283,13 @@ interface ConfigCommandSetup<T extends string = string, LockFile = any> {
|
|
|
275
283
|
declare type InferFlags<T extends typeof Command$1> = InferredFlags<T['globalFlags'] & T['flags']>;
|
|
276
284
|
declare type InferArgs<T extends typeof Command$1> = Record<T['args'][number]['name'], string>;
|
|
277
285
|
|
|
286
|
+
/**
|
|
287
|
+
* Makes the object deep partial.
|
|
288
|
+
*/
|
|
289
|
+
declare type DeepPartial<T> = {
|
|
290
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
291
|
+
};
|
|
292
|
+
|
|
278
293
|
declare abstract 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 {
|
|
279
294
|
static globalFlags: {
|
|
280
295
|
"log-level": _oclif_core_lib_interfaces.OptionFlag<string>;
|
|
@@ -364,4 +379,4 @@ declare const _default: {
|
|
|
364
379
|
};
|
|
365
380
|
};
|
|
366
381
|
|
|
367
|
-
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 };
|
|
382
|
+
export { ClassType, Command, CommonLockerData, ConfigCommand, ConfigCommandChoices, ConfigCommandSetup, ConfigIterator, ConfigService, DeepPartial, FileConstants, FileSystemService, GenericParser, GlobalConfig, GlobalConfigInit, 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
|
@@ -617,11 +617,11 @@ var ConfigService = class {
|
|
|
617
617
|
return config;
|
|
618
618
|
}
|
|
619
619
|
async extend(paths, strategy = "OVERWRITE" /* OVERWRITE */) {
|
|
620
|
-
this.logger.trace("Will generate config from: %
|
|
620
|
+
this.logger.trace("Will generate config from: %o with %s", paths, strategy);
|
|
621
621
|
const configs = (await Promise.all(
|
|
622
622
|
paths.map(async (path) => {
|
|
623
623
|
try {
|
|
624
|
-
const config = await this.parser.read(path);
|
|
624
|
+
const config = typeof path === "string" ? await this.parser.read(path) : path;
|
|
625
625
|
this.logger.trace("Extending config from: %s", path);
|
|
626
626
|
return config;
|
|
627
627
|
} catch (e) {
|
|
@@ -631,15 +631,15 @@ var ConfigService = class {
|
|
|
631
631
|
)).filter(Boolean);
|
|
632
632
|
return this.merge(configs, strategy);
|
|
633
633
|
}
|
|
634
|
-
|
|
634
|
+
merge(configs, strategy = "OVERWRITE" /* OVERWRITE */) {
|
|
635
635
|
if (configs.length === 0) {
|
|
636
636
|
throw new Error("Nothing to merge, configuration files are empty.");
|
|
637
637
|
}
|
|
638
638
|
return merge(strategy, configs.some((config) => Array.isArray(config)) ? [] : {}, ...configs);
|
|
639
639
|
}
|
|
640
640
|
async env(definition, config) {
|
|
641
|
-
const env = await this.parser.read(definition);
|
|
642
|
-
this.logger.trace("Environment variable extensions read: %
|
|
641
|
+
const env = typeof definition === "string" ? await this.parser.read(definition) : definition;
|
|
642
|
+
this.logger.trace("Environment variable extensions read: %o", definition);
|
|
643
643
|
const iter = /* @__PURE__ */ __name(async (obj, parent) => {
|
|
644
644
|
const data = await Promise.all(
|
|
645
645
|
Object.entries(obj).map(async ([key, value]) => {
|
|
@@ -647,41 +647,76 @@ var ConfigService = class {
|
|
|
647
647
|
if (typeof value === "string") {
|
|
648
648
|
return [{ key: location, env: value }];
|
|
649
649
|
} else if (typeof value === "object") {
|
|
650
|
-
|
|
651
|
-
|
|
650
|
+
let extensions;
|
|
651
|
+
if ("__element" /* ELEMENT */ in value) {
|
|
652
|
+
this.logger.trace("Expanding location to elements: %s", location);
|
|
653
|
+
extensions = await iter(value["__element" /* ELEMENT */], [...location, "__element" /* ELEMENT */]);
|
|
654
|
+
}
|
|
655
|
+
if ("__name" /* NAME */ in value && "__format" /* PARSER */ in value) {
|
|
656
|
+
const variable = [
|
|
652
657
|
{
|
|
653
658
|
key: location,
|
|
654
|
-
env: value
|
|
655
|
-
parser: value
|
|
659
|
+
env: value["__name" /* NAME */],
|
|
660
|
+
parser: value["__format" /* PARSER */],
|
|
661
|
+
extensions
|
|
656
662
|
}
|
|
657
663
|
];
|
|
664
|
+
return variable;
|
|
658
665
|
} else {
|
|
659
666
|
return iter(value, location);
|
|
660
667
|
}
|
|
661
668
|
}
|
|
662
669
|
})
|
|
663
670
|
);
|
|
664
|
-
return data.flatMap((d) => d);
|
|
671
|
+
return data.flatMap((d) => d).filter(Boolean);
|
|
665
672
|
}, "iter");
|
|
666
673
|
const parsed = await iter(env);
|
|
674
|
+
const cb = /* @__PURE__ */ __name(async (config2, variable, data) => {
|
|
675
|
+
if (variable.parser) {
|
|
676
|
+
try {
|
|
677
|
+
data = await this.parser.parse(variable.parser, data);
|
|
678
|
+
} catch (e) {
|
|
679
|
+
this.logger.trace("Can not parse environment environment variable for config: %s -> %s with %s", variable.key.join("."), variable.env, variable.parser);
|
|
680
|
+
throw e;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
|
|
684
|
+
return import_object_path_immutable.default.set(config2, variable.key, data);
|
|
685
|
+
}, "cb");
|
|
667
686
|
await Promise.all(
|
|
668
687
|
parsed.map(async (variable) => {
|
|
669
|
-
let data
|
|
670
|
-
|
|
671
|
-
|
|
688
|
+
let data;
|
|
689
|
+
data = process.env[variable.env];
|
|
690
|
+
if (data) {
|
|
691
|
+
config = await cb(config, variable, data);
|
|
672
692
|
}
|
|
673
|
-
if (variable.
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
693
|
+
if (variable.extensions && variable.extensions.length > 0) {
|
|
694
|
+
const timeout = 6e4;
|
|
695
|
+
const startedAt = Date.now();
|
|
696
|
+
for (let i = 0; i < Infinity; i++) {
|
|
697
|
+
if (Date.now() - startedAt > timeout) {
|
|
698
|
+
throw new Error(`Timed-out in ${timeout}ms while looking for element environment variables.`);
|
|
699
|
+
}
|
|
700
|
+
const extensions = (await Promise.all(
|
|
701
|
+
variable.extensions.map(async (extension) => {
|
|
702
|
+
const clone = JSON.parse(JSON.stringify(extension));
|
|
703
|
+
clone.env = clone.env.replace("${i}" /* ELEMENT_REPLACER */, i.toString());
|
|
704
|
+
clone.key[clone.key.findIndex((value) => value === "__element" /* ELEMENT */)] = i;
|
|
705
|
+
data = process.env[clone.env];
|
|
706
|
+
if (!data) {
|
|
707
|
+
this.logger.trace("No extension for environment variable: %s -> %s", clone.key.join("."), clone.env);
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
return cb({}, clone, data);
|
|
711
|
+
})
|
|
712
|
+
)).filter(Boolean);
|
|
713
|
+
if (extensions.length === 0) {
|
|
714
|
+
this.logger.trace("No more extensions for environment variables: %s -> %d", variable.key.join("."), i);
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
config = this.merge([config, ...extensions], "EXTEND" /* EXTEND */);
|
|
679
718
|
}
|
|
680
719
|
}
|
|
681
|
-
config = import_object_path_immutable.default.update(config, variable.key, () => {
|
|
682
|
-
this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
|
|
683
|
-
return data;
|
|
684
|
-
});
|
|
685
720
|
})
|
|
686
721
|
);
|
|
687
722
|
return config;
|