Skip to content

Commit a33ebf3

Browse files
authored
Merge pull request #348 from dansiegel/dev/ds/environment-analyzer
Update Environment Analyzer
2 parents 8e9e9ab + 027ded5 commit a33ebf3

File tree

9 files changed

+1232
-931
lines changed

9 files changed

+1232
-931
lines changed

docs/config/appsettings/configuration.md

+139
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Within the Project we can now provide any configuration values we need to either
3636
"delimiter": ";",
3737
"namespace": "Helpers",
3838
"rootNamespace": null,
39+
"prefix": "BuildTools_",
3940
"properties": [
4041
// Property Definitions
4142
]
@@ -128,3 +129,141 @@ Other times we may have non-sensitive values that we need to configure defaults
128129
}
129130
}
130131
```
132+
133+
#### Handling Duplicate Property Names
134+
135+
There may be times in which you have more than one project in your solution, or perhaps just more than one generated settings class that require duplicate property names. An example of this could be an API Settings class.
136+
137+
```json
138+
{
139+
"$schema": "https://mobilebuildtools.com/schemas/v2/buildtools.schema.json",
140+
"appSettings": {
141+
"AwesomeApp": [
142+
{
143+
"className": "FooApiSettings",
144+
"properties": [
145+
{
146+
"name": "BaseUri",
147+
"type": "Uri"
148+
}
149+
]
150+
},
151+
{
152+
"className": "BarApiSettings",
153+
"properties": [
154+
{
155+
"name": "BaseUri",
156+
"type": "Uri"
157+
}
158+
]
159+
}
160+
]
161+
}
162+
}
163+
```
164+
165+
In this sample we have 2 generated classes with the `BaseUri` property, this creates a few problems for us because we need to distinguish which Uri belongs to which class and ultimately our JSON would be invalid because it has a duplicated key
166+
167+
```json
168+
{
169+
"BaseUri": "https://api.foo.com",
170+
"BaseUri": "https://api.bar.com"
171+
}
172+
```
173+
174+
To solve this problem we can use the Prefix property on our generated class settings. In this way we can specify a unique variable prefix that will be used to identify which Base Uri property belongs to which generated class
175+
176+
```json
177+
{
178+
"$schema": "https://mobilebuildtools.com/schemas/v2/buildtools.schema.json",
179+
"appSettings": {
180+
"AwesomeApp": [
181+
{
182+
"className": "FooApiSettings",
183+
"prefix": "FooApi_",
184+
"properties": [
185+
{
186+
"name": "BaseUri",
187+
"type": "Uri"
188+
}
189+
]
190+
},
191+
{
192+
"className": "BarApiSettings",
193+
"prefix": "BarApi_",
194+
"properties": [
195+
{
196+
"name": "BaseUri",
197+
"type": "Uri"
198+
}
199+
]
200+
}
201+
]
202+
}
203+
}
204+
```
205+
206+
With the Prefix added we can now update our appsettings.json to be:
207+
208+
```json
209+
{
210+
"FooApi_BaseUri": "https://api.foo.com",
211+
"BarApi_BaseUri": "https://api.bar.com"
212+
}
213+
```
214+
215+
> [!NOTE]
216+
> If your prefix does not end with an underscore one will automatically be inserted. In the above example if we did not explicitly have the underscore, the Mobile.BuildTools would still be expecting the same values in our `appsettings.json` or as an Environment variable.
217+
218+
#### Setting Variables from the environment
219+
220+
The Mobile.BuildTools allows us to "Fake" environment variables. There may be times such as the previous sample with our previous example where the values aren't particularly sensitive but simply something that may change based on our Build...
221+
222+
```json
223+
{
224+
"$schema": "https://mobilebuildtools.com/schemas/v2/buildtools.schema.json",
225+
"environment": {
226+
"defaults": {
227+
"FooApi_BaseUri": "https://dev.api.foo.com",
228+
"BarApi_BaseUri": "https://dev.api.bar.com"
229+
},
230+
}
231+
}
232+
```
233+
234+
It's also possible that we may want to further customize this without the need to update a CI Build environment for variables that aren't particularly sensitive. In this case we can provide Build Configuration specific settings:
235+
236+
```json
237+
{
238+
"$schema": "https://mobilebuildtools.com/schemas/v2/buildtools.schema.json",
239+
"environment": {
240+
"configuration": {
241+
"Debug": {
242+
"FooApi_BaseUri": "https://dev.api.foo.com",
243+
"BarApi_BaseUri": "https://dev.api.bar.com"
244+
},
245+
"QA": {
246+
"FooApi_BaseUri": "https://qa.api.foo.com",
247+
"BarApi_BaseUri": "https://qa.api.bar.com"
248+
},
249+
"Release": {
250+
"FooApi_BaseUri": "https://api.foo.com",
251+
"BarApi_BaseUri": "https://api.bar.com"
252+
}
253+
},
254+
}
255+
}
256+
```
257+
258+
#### Fuzzy Matching
259+
260+
From time to time you may want to make use of Fuzzy Matching. Fuzzy Matching allows you to provide configurations that aren't tied to a specific Build Configuration name. For example we might have an `appsettings.QA.json` with a `DebugQA` build configuration. We might also have a `ReleaseQA` build configuration. In the case we build with either of these build configurations we might want it to pick up the QA build configuration. We can pick these configurations up by enabling Fuzzy Matching in our environment.
261+
262+
```json
263+
{
264+
"$schema": "https://mobilebuildtools.com/schemas/v2/buildtools.schema.json",
265+
"environment": {
266+
"enableFuzzyMatching": true
267+
}
268+
}
269+
```

docs/schemas/v2/buildtools.schema.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@
8585
"null"
8686
],
8787
"properties": {
88+
"enableFuzzyMatching": {
89+
"type": "boolean",
90+
"description": "This will allow fuzzy matching for environment variables and appsettings."
91+
},
8892
"defaults": {
93+
"description": "This expects a dictionary of key value pairs to use as defaults for the environment.",
8994
"type": [
9095
"object",
9196
"null"
@@ -98,6 +103,7 @@
98103
}
99104
},
100105
"configuration": {
106+
"description": "This expects a key which may be explicitly for the Build Configuration, the Platform (Android, iOS, etc), or a combination of the Platform and Build Configuration separated by an underscore (iOS_Debug), with a value of a dictionary of key value pairs to use as defaults for the environment.",
101107
"type": [
102108
"object",
103109
"null"
@@ -535,4 +541,4 @@
535541
"type": "boolean"
536542
}
537543
}
538-
}
544+
}

0 commit comments

Comments
 (0)