mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-12 22:39:15 +08:00
68 lines
2.0 KiB
Groovy
68 lines
2.0 KiB
Groovy
import groovy.json.JsonOutput
|
|
import groovy.json.JsonSlurper
|
|
|
|
String fileName = "firebase.json"
|
|
String jsonRoot = "react-native"
|
|
|
|
File jsonFile = null
|
|
File parentDir = rootProject.projectDir
|
|
|
|
for (int i = 0; i <= 3; i++) {
|
|
if (parentDir == null) break
|
|
parentDir = parentDir.parentFile
|
|
if (parentDir != null) {
|
|
jsonFile = new File(parentDir, fileName)
|
|
if (jsonFile.exists()) break
|
|
}
|
|
}
|
|
|
|
if (jsonFile != null && jsonFile.exists()) {
|
|
rootProject.logger.info ":${project.name} firebase.json found at ${jsonFile.toString()}"
|
|
Object json = null
|
|
|
|
try {
|
|
json = new JsonSlurper().parseText(jsonFile.text)
|
|
} catch (Exception ignored) {
|
|
rootProject.logger.warn ":${project.name} failed to parse firebase.json found at ${jsonFile.toString()}."
|
|
rootProject.logger.warn ignored.toString()
|
|
}
|
|
|
|
if (json && json[jsonRoot]) {
|
|
String jsonStr = JsonOutput.toJson(JsonOutput.toJson(json[jsonRoot]))
|
|
|
|
rootProject.ext.firebaseJson = [
|
|
raw: json[jsonRoot],
|
|
isFlagEnabled: { key ->
|
|
return json[jsonRoot] != null && json[jsonRoot][key] == true
|
|
},
|
|
getStringValue: { key, defaultValue ->
|
|
if (json[jsonRoot] == null) return defaultValue
|
|
return json[jsonRoot][key] ? json[jsonRoot][key] : defaultValue
|
|
}
|
|
]
|
|
|
|
rootProject.logger.info ":${project.name} found react-native json root in firebase.json, creating firebase build config"
|
|
android {
|
|
defaultConfig {
|
|
buildConfigField "String", "FIREBASE_JSON_RAW", jsonStr
|
|
}
|
|
}
|
|
} else {
|
|
rootProject.ext.firebaseJson = false
|
|
rootProject.logger.info ":${project.name} firebase.json found with no react-native config, skipping"
|
|
android {
|
|
defaultConfig {
|
|
buildConfigField "String", "FIREBASE_JSON_RAW", '"{}"'
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
rootProject.ext.firebaseJson = false
|
|
rootProject.logger.info ":${project.name} no firebase.json found, skipping"
|
|
android {
|
|
defaultConfig {
|
|
buildConfigField "String", "FIREBASE_JSON_RAW", '"{}"'
|
|
}
|
|
}
|
|
}
|