engine
engine copied to clipboard
Environment variables in the Feature type
After a discussion made with @nadavwix and @barak007 we need the environments variables infrastructure as a part of the feature declaration.
A new Entity will be defined: EnvironmentVariable
.
It will have a mandatory property of the default value, and optionally a serializer function, for cases we need to serialize the string value to a different one. it will have the following interface:
interface IEnvironmentVariable<T> {
default: T;
serializer?: (stringValue: string) => T;
}
And the usage will be as follows:
export default new Feature({
id: 'myFeature',
api: {
myVariable: new EnvironmentVariable({ default: 'value' }).defineEntity(processingEnv),
mySecondVariable: new EnvironmentVariable({ default: 5, serializer: (raw: string) => parseInt(stringArg) }).defineEntity(mainEnv)
},
dependencies: [],
})
These arguments could be used in the feature.environment setup file as follows:
MyFeature.setup(mainEnv, ({ mySecondVariable }) => {
document.body.innerText = JSON.stringify(mySecondVariable.getValue())
}
The appropriate cli call will look as follows:
yarn start -f my-feature --myFeature.mySecondVariable 8
@nadavwix @AviVahl @barak007 please share your thought on this
this looks great, i'd just add a description field so it can show up in help
After meeting conclusions:
- Config will be able to represent primitive value like string/number/...
- CLI tools (Application) can override config by passing cli arguments in this format:
- --MyFeature.configKey
- --MyFeature.configKey.configValue
Phase 2: Engine will expose auto cli application that is composed by Feature capabilities.