@cenk1cenk2/oclif-common 3.1.0-beta.1 → 3.1.0-beta.4
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 +35 -30
- 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]) => {
|
|
@@ -649,10 +649,11 @@ var ConfigService = class {
|
|
|
649
649
|
} else if (typeof value === "object") {
|
|
650
650
|
const extras = [];
|
|
651
651
|
if ("__element" /* ELEMENT */ in value) {
|
|
652
|
-
|
|
652
|
+
this.logger.trace("Expanding location to elements: %s", location);
|
|
653
|
+
extras.push(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 */],
|
|
@@ -660,6 +661,7 @@ var ConfigService = class {
|
|
|
660
661
|
},
|
|
661
662
|
...extras
|
|
662
663
|
];
|
|
664
|
+
return variable;
|
|
663
665
|
} else {
|
|
664
666
|
return iter(value, location);
|
|
665
667
|
}
|
|
@@ -669,20 +671,23 @@ var ConfigService = class {
|
|
|
669
671
|
return data.flatMap((d) => d);
|
|
670
672
|
}, "iter");
|
|
671
673
|
const parsed = await iter(env);
|
|
674
|
+
const cb = /* @__PURE__ */ __name(async (variable, data) => {
|
|
675
|
+
if (variable.parser) {
|
|
676
|
+
try {
|
|
677
|
+
variable = 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
|
+
return import_object_path_immutable.default.update(config, variable.key, () => {
|
|
684
|
+
this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
|
|
685
|
+
return variable;
|
|
686
|
+
});
|
|
687
|
+
}, "cb");
|
|
672
688
|
await Promise.all(
|
|
673
689
|
parsed.map(async (variable) => {
|
|
674
|
-
let data
|
|
675
|
-
if (!data) {
|
|
676
|
-
return;
|
|
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
|
-
}
|
|
685
|
-
}
|
|
690
|
+
let data;
|
|
686
691
|
if (variable.key.includes("__element" /* ELEMENT */)) {
|
|
687
692
|
const timeout = 6e4;
|
|
688
693
|
const startedAt = Date.now();
|
|
@@ -690,24 +695,24 @@ var ConfigService = class {
|
|
|
690
695
|
if (Date.now() - startedAt > timeout) {
|
|
691
696
|
throw new Error(`Timed-out in ${timeout}ms while looking for element environment variables.`);
|
|
692
697
|
}
|
|
693
|
-
|
|
698
|
+
const clone = JSON.parse(JSON.stringify(variable));
|
|
699
|
+
clone.env = clone.env.replace("${i}" /* ELEMENT_REPLACER */, i.toString());
|
|
700
|
+
this.logger.trace("Looking for environment variable element: %o", clone);
|
|
701
|
+
data = process.env[clone.env];
|
|
694
702
|
if (!data) {
|
|
695
703
|
this.logger.trace("No more variable available: %s -> %d", variable.env, i);
|
|
696
704
|
break;
|
|
697
705
|
}
|
|
698
|
-
|
|
699
|
-
|
|
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
|
-
});
|
|
706
|
+
clone.key[clone.key.findIndex((value) => value === "__element" /* ELEMENT */)] = i;
|
|
707
|
+
config = await cb(clone, data);
|
|
704
708
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
data = process.env[variable.env];
|
|
712
|
+
if (!data) {
|
|
713
|
+
return;
|
|
710
714
|
}
|
|
715
|
+
config = await cb(variable, data);
|
|
711
716
|
})
|
|
712
717
|
);
|
|
713
718
|
return config;
|
package/package.json
CHANGED