@cenk1cenk2/oclif-common 3.1.0-beta.1 → 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 +20 -5
- package/dist/index.js +46 -37
- 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>;
|
|
214
|
+
extend<T extends LockableData = LockableData>(paths: (string | Partial<T>)[], strategy?: MergeStrategy): Promise<T>;
|
|
207
215
|
merge<T extends LockableData = LockableData>(configs: Partial<T>[], strategy?: MergeStrategy): T;
|
|
208
|
-
env<T extends LockableData = LockableData>(definition: string, config: T): Promise<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) {
|
|
@@ -638,8 +638,8 @@ var ConfigService = class {
|
|
|
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,66 +647,75 @@ var ConfigService = class {
|
|
|
647
647
|
if (typeof value === "string") {
|
|
648
648
|
return [{ key: location, env: value }];
|
|
649
649
|
} else if (typeof value === "object") {
|
|
650
|
-
|
|
650
|
+
let extensions;
|
|
651
651
|
if ("__element" /* ELEMENT */ in value) {
|
|
652
|
-
|
|
652
|
+
this.logger.trace("Expanding location to elements: %s", location);
|
|
653
|
+
extensions = await iter(value["__element" /* ELEMENT */], [...location, "__element" /* ELEMENT */]);
|
|
653
654
|
}
|
|
654
655
|
if ("__name" /* NAME */ in value && "__format" /* PARSER */ in value) {
|
|
655
|
-
|
|
656
|
+
const variable = [
|
|
656
657
|
{
|
|
657
658
|
key: location,
|
|
658
659
|
env: value["__name" /* NAME */],
|
|
659
|
-
parser: value["__format" /* PARSER */]
|
|
660
|
-
|
|
661
|
-
|
|
660
|
+
parser: value["__format" /* PARSER */],
|
|
661
|
+
extensions
|
|
662
|
+
}
|
|
662
663
|
];
|
|
664
|
+
return variable;
|
|
663
665
|
} else {
|
|
664
666
|
return iter(value, location);
|
|
665
667
|
}
|
|
666
668
|
}
|
|
667
669
|
})
|
|
668
670
|
);
|
|
669
|
-
return data.flatMap((d) => d);
|
|
671
|
+
return data.flatMap((d) => d).filter(Boolean);
|
|
670
672
|
}, "iter");
|
|
671
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");
|
|
672
686
|
await Promise.all(
|
|
673
687
|
parsed.map(async (variable) => {
|
|
674
|
-
let data
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
if (variable.parser) {
|
|
679
|
-
try {
|
|
680
|
-
data = await this.parser.parse(variable.parser, data);
|
|
681
|
-
} catch (e) {
|
|
682
|
-
this.logger.trace("Can not parse environment variable for config: %s -> %s with %s", variable.key.join("."), variable.env, variable.parser);
|
|
683
|
-
throw e;
|
|
684
|
-
}
|
|
688
|
+
let data;
|
|
689
|
+
data = process.env[variable.env];
|
|
690
|
+
if (data) {
|
|
691
|
+
config = await cb(config, variable, data);
|
|
685
692
|
}
|
|
686
|
-
if (variable.
|
|
693
|
+
if (variable.extensions && variable.extensions.length > 0) {
|
|
687
694
|
const timeout = 6e4;
|
|
688
695
|
const startedAt = Date.now();
|
|
689
696
|
for (let i = 0; i < Infinity; i++) {
|
|
690
697
|
if (Date.now() - startedAt > timeout) {
|
|
691
698
|
throw new Error(`Timed-out in ${timeout}ms while looking for element environment variables.`);
|
|
692
699
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
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);
|
|
696
715
|
break;
|
|
697
716
|
}
|
|
698
|
-
|
|
699
|
-
clone[clone.findIndex("__element" /* ELEMENT */)] = i;
|
|
700
|
-
config = import_object_path_immutable.default.update(config, clone, () => {
|
|
701
|
-
this.logger.trace("Overwriting config with element environment variable: %s -> %s", clone.join("."), variable.env);
|
|
702
|
-
return data;
|
|
703
|
-
});
|
|
717
|
+
config = this.merge([config, ...extensions], "EXTEND" /* EXTEND */);
|
|
704
718
|
}
|
|
705
|
-
} else {
|
|
706
|
-
config = import_object_path_immutable.default.update(config, variable.key, () => {
|
|
707
|
-
this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
|
|
708
|
-
return data;
|
|
709
|
-
});
|
|
710
719
|
}
|
|
711
720
|
})
|
|
712
721
|
);
|
package/package.json
CHANGED