Created
May 27, 2024 21:06
-
-
Save azazellj/0e300ea7320ce9d916bf8cc0818727a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TaskAction | |
fun taskAction() { | |
val typeMap = mutableMapOf<String, T>() | |
// read file | |
val jsonObject = JSONObject(dsmFile.get().asFile.readText()) | |
// find all type tokens | |
searchTypeTokens(jsonObject.getJSONObject(rootDSMKey), rootDSMKey, typeMap) | |
val fileBuilder = FileSpec.builder( | |
packageName = `package`.get(), | |
fileName = generatedFileName, | |
) | |
val objectBuilder = TypeSpec | |
.objectBuilder( | |
name = generatedFileName, | |
) | |
.addModifiers(KModifier.INTERNAL) | |
// write all properties | |
for ((key, type) in typeMap) { | |
objectBuilder.addProperty( | |
PropertySpec.builder( | |
// some keys have dots in name as opacity | |
name = key.replace(".", "_"), | |
type = componentClassName, | |
modifiers = arrayOf(KModifier.INTERNAL), | |
) | |
.initializer(writeTypeToken(key, type)) | |
.build(), | |
) | |
} | |
fileBuilder.addType(objectBuilder.build()) | |
fileBuilder.build().writeTo(flavorDirectory.get().asFile) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment