@cenk1cenk2/oclif-common 3.0.4 → 3.1.0-beta.3
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 +19 -5
- package/dist/index.js +43 -13
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -98,13 +98,20 @@ 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;
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
declare const color: colorette.Colorette;
|
|
@@ -203,9 +210,9 @@ declare class ConfigService implements GlobalConfig {
|
|
|
203
210
|
private readonly logger;
|
|
204
211
|
constructor(oclif: Command['config'], command: Command['ctor'], config: Omit<GlobalConfig, 'isVerbose' | 'isDebug' | 'isSilent'>);
|
|
205
212
|
read<T extends LockableData = LockableData>(path: string): Promise<T>;
|
|
206
|
-
extend<T extends LockableData = LockableData>(paths: string[], strategy?: MergeStrategy): Promise<T>;
|
|
213
|
+
extend<T extends LockableData = LockableData>(paths: (string | Partial<T>)[], strategy?: MergeStrategy): Promise<T>;
|
|
207
214
|
merge<T extends LockableData = LockableData>(configs: Partial<T>[], strategy?: MergeStrategy): T;
|
|
208
|
-
env<T extends LockableData = LockableData>(definition: string, config: T): Promise<T>;
|
|
215
|
+
env<T extends LockableData = LockableData>(definition: string | T, config: T): Promise<T>;
|
|
209
216
|
write<T extends LockableData = LockableData>(path: string, data: T): Promise<void>;
|
|
210
217
|
private recalculate;
|
|
211
218
|
}
|
|
@@ -275,6 +282,13 @@ interface ConfigCommandSetup<T extends string = string, LockFile = any> {
|
|
|
275
282
|
declare type InferFlags<T extends typeof Command$1> = InferredFlags<T['globalFlags'] & T['flags']>;
|
|
276
283
|
declare type InferArgs<T extends typeof Command$1> = Record<T['args'][number]['name'], string>;
|
|
277
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Makes the object deep partial.
|
|
287
|
+
*/
|
|
288
|
+
declare type DeepPartial<T> = {
|
|
289
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
290
|
+
};
|
|
291
|
+
|
|
278
292
|
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
293
|
static globalFlags: {
|
|
280
294
|
"log-level": _oclif_core_lib_interfaces.OptionFlag<string>;
|
|
@@ -364,4 +378,4 @@ declare const _default: {
|
|
|
364
378
|
};
|
|
365
379
|
};
|
|
366
380
|
|
|
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 };
|
|
381
|
+
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,14 +647,22 @@ 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
|
+
const extras = [];
|
|
651
|
+
if ("__element" /* ELEMENT */ in value) {
|
|
652
|
+
this.logger.trace("Expanding location to elements: %s", location);
|
|
653
|
+
extras.push(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
|
|
656
|
-
}
|
|
659
|
+
env: value["__name" /* NAME */],
|
|
660
|
+
parser: value["__format" /* PARSER */]
|
|
661
|
+
},
|
|
662
|
+
...extras
|
|
657
663
|
];
|
|
664
|
+
this.logger.trace("Added to search for environment variables: %o", variable);
|
|
665
|
+
return variable;
|
|
658
666
|
} else {
|
|
659
667
|
return iter(value, location);
|
|
660
668
|
}
|
|
@@ -678,10 +686,32 @@ var ConfigService = class {
|
|
|
678
686
|
throw e;
|
|
679
687
|
}
|
|
680
688
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
689
|
+
if (variable.key.includes("__element" /* ELEMENT */)) {
|
|
690
|
+
const timeout = 6e4;
|
|
691
|
+
const startedAt = Date.now();
|
|
692
|
+
for (let i = 0; i < Infinity; i++) {
|
|
693
|
+
if (Date.now() - startedAt > timeout) {
|
|
694
|
+
throw new Error(`Timed-out in ${timeout}ms while looking for element environment variables.`);
|
|
695
|
+
}
|
|
696
|
+
const clone = JSON.parse(JSON.stringify(variable));
|
|
697
|
+
this.logger.trace("Looking for environment variable element: %o", clone);
|
|
698
|
+
data = process.env[clone.env.replace("${i}" /* ELEMENT_REPLACER */, i.toString())];
|
|
699
|
+
if (!data) {
|
|
700
|
+
this.logger.trace("No more variable available: %s -> %d", variable.env, i);
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
clone.key[clone.key.findIndex((value) => value === "__element" /* ELEMENT */)] = i;
|
|
704
|
+
config = import_object_path_immutable.default.update(config, clone.key, () => {
|
|
705
|
+
this.logger.trace("Overwriting config with element environment variable: %s -> %s", clone.key.join("."), variable.env);
|
|
706
|
+
return data;
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
} else {
|
|
710
|
+
config = import_object_path_immutable.default.update(config, variable.key, () => {
|
|
711
|
+
this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
|
|
712
|
+
return data;
|
|
713
|
+
});
|
|
714
|
+
}
|
|
685
715
|
})
|
|
686
716
|
);
|
|
687
717
|
return config;
|