engine icon indicating copy to clipboard operation
engine copied to clipboard

Environment variables in the Feature type

Open RomanYarik opened this issue 5 years ago • 2 comments

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

RomanYarik avatar Dec 18 '19 16:12 RomanYarik

this looks great, i'd just add a description field so it can show up in help

nadavwix avatar Dec 22 '19 08:12 nadavwix

After meeting conclusions:

  1. Config will be able to represent primitive value like string/number/...
  2. 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.

barak007 avatar Dec 22 '19 12:12 barak007